From 3308a9f34005431057b24b2fba05d183bc1d718b Mon Sep 17 00:00:00 2001 From: jyy Date: Fri, 23 Mar 2018 22:41:20 +0800 Subject: [PATCH] fixes --- DEVICES.md | 27 +++++++++++++++++++++++++++ SPEC.md | 2 +- am/arch/x86-qemu/src/asye.cpp | 13 +++++++------ am/arch/x86-qemu/src/ioe.cpp | 25 ++++++++++++------------- libs/klib/src/io.c | 2 +- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/DEVICES.md b/DEVICES.md index 90b39ad6..992e7308 100644 --- a/DEVICES.md +++ b/DEVICES.md @@ -4,6 +4,8 @@ 设备相关的宏定义在`dev.h`。设备id为32位十六进制数。 +**对于读/写寄存器是结构体的,size必须与结构体一致,否则行为未定义**。 + | 设备ID | 设备功能 | 设备描述 | | --------- | ---------------------------------------- | ------- | | 0000 ac01 | 若干32位寄存器,编号从0开始 | AM性能计数器 | @@ -16,8 +18,33 @@ ## 0000 ac01 - AM PerfCnt ## 0000 ac02 - AM Input + +从`_DEV_INPUT_REG_KBD` (#1)中读出32位整数,其中,`_KEY_XXX`为keyup事件;`_KEY_XXX | 0x8000`为keydown事件。 + ## 0000 ac03 - AM Timer + +从`_DEV_TIMER_REG_UPTIME` (#1)中读出如下结构体: +``` +typedef struct _Dev_Timer_Uptime { + uint32_t hi, lo; +} _Dev_Timer_Uptime; +``` + ## 0000 ac04 - AM Video + +从 `_DEV_VIDEO_REG_INFO` (#1)中读出如下结构体,其中`width`为屏幕宽度、`height`为屏幕高度。假设AM运行过程中屏幕大小不发生变化: +``` +typedef struct _Dev_Video_Info { + int32_t width, height; +} _Dev_Video_Info; +``` + +向`_DEV_VIDEO_REG_FBCTL` (#2)中写入如下结构体,向(`x`,`y`)坐标处绘制`w`*`h`的矩形图案,像素按行优先存储在`pixels`。每个32位整数以`00RRGGBB`描述颜色: +typedef struct _Dev_Video_FBCtl { + int x, y, w, h, sync; + uint32_t *pixels; +} _Dev_Video_FBCtl; + ## 0000 0080 - PCI Configuration space ## 0000 0dd0 - ATA0 ## 0000 0dd1 - ATA1 diff --git a/SPEC.md b/SPEC.md index 3bbc490b..ebdb93d0 100644 --- a/SPEC.md +++ b/SPEC.md @@ -42,7 +42,7 @@ * `size_t (*read)(intptr_t reg, void *buf, size_t size)`: 从设备控制寄存器`reg`读取`size`字节; * `size_t (*write)(intptr_t reg, void *buf, size_t size)`: 向设备控制寄存器`reg`写入`size`字节。 -每个设备的数据格式不同,请参考AM设备手册。不支持读/写的设备相应`read`/`write`为`NULL`。 +每个设备支持的读/写规范不同,请参考AM设备手册。不支持读/写的设备相应`read`/`write`为`NULL`。 ### IOE API diff --git a/am/arch/x86-qemu/src/asye.cpp b/am/arch/x86-qemu/src/asye.cpp index 43618126..a6541bde 100644 --- a/am/arch/x86-qemu/src/asye.cpp +++ b/am/arch/x86-qemu/src/asye.cpp @@ -236,17 +236,18 @@ _RegSet *_make(_Area stack, void *entry, void *arg) { return regs; } -void _trap() { +void _yield() { asm volatile("int $0x80" : : "a"(-1)); } -int _istatus(int enable) { - int ret = (get_efl() & FL_IF) != 0; +int _get_intr() { + return (get_efl() & FL_IF) != 0; +} + +void _set_intr(int enable) { if (enable) { sti(); } else { cli(); } - return ret; -} - +} \ No newline at end of file diff --git a/am/arch/x86-qemu/src/ioe.cpp b/am/arch/x86-qemu/src/ioe.cpp index 735c2a29..ded9d923 100644 --- a/am/arch/x86-qemu/src/ioe.cpp +++ b/am/arch/x86-qemu/src/ioe.cpp @@ -82,26 +82,25 @@ static void port_write(int port, size_t nmemb, uintptr_t data) { } } -/* -static uintptr_t pciconf_read(uintptr_t reg, size_t size) { +static size_t pciconf_read(uintptr_t reg, void *buf, size_t size) { outl(0xcf8, reg); switch (size) { - case 1: return inb(0xcfc + (reg & 3)); - case 2: return inw(0xcfc + (reg & 2)); - case 4: return inl(0xcfc); + case 1: *(uint8_t *) buf = inb(0xcfc + (reg & 3)); + case 2: *(uint16_t *)buf = inw(0xcfc + (reg & 2)); + case 4: *(uint32_t *)buf = inl(0xcfc); } - return 0; + return size; } -static void pciconf_write(uintptr_t reg, size_t nmemb, uintptr_t data) { +static size_t pciconf_write(uintptr_t reg, void *buf, size_t size) { outl(0xcf8, reg); - switch (nmemb) { - case 1: outb(0xcfc + (reg & 3), data); - case 2: outw(0xcfc + (reg & 2), data); - case 4: outl(0xcfc, data); + switch (size) { + case 1: outb(0xcfc + (reg & 3), *(uint8_t *) buf); + case 2: outw(0xcfc + (reg & 2), *(uint16_t *)buf); + case 4: outl(0xcfc , *(uint32_t *)buf); } + return size; } -*/ static inline int keydown(int e) { return (e & 0x8000) != 0; } static inline int upevent(int e) { return e; } @@ -208,7 +207,7 @@ static _Device x86_dev[] = { {_DEV_INPUT, "8279 Keyboard Controller", input_read, nullptr}, {_DEV_TIMER, "Dummy Timer", timer_read, nullptr}, {_DEV_VIDEO, "Standard VGA Controller", video_read, video_write}, - //{_DEV_PCICONF, "PCI Configuration", pciconf_read, pciconf_write}, + {_DEV_PCICONF, "PCI Configuration", pciconf_read, pciconf_write}, {_DEV_ATA0, "Primary Parallel ATA Hard Disk Controller", hd_read, hd_write}, }; diff --git a/libs/klib/src/io.c b/libs/klib/src/io.c index 47f7cbdf..16a8ddf0 100644 --- a/libs/klib/src/io.c +++ b/libs/klib/src/io.c @@ -65,6 +65,6 @@ int screen_height() { _Device *dev = getdev(&video_dev, _DEV_VIDEO); _Dev_Video_Info info; dev->read(_DEV_VIDEO_REG_INFO, &info, sizeof(info)); - return info.width; + return info.height; }