This commit is contained in:
jyy 2018-03-23 22:41:20 +08:00
parent 823f072594
commit 3308a9f340
5 changed files with 48 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}
}

View File

@ -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},
};

View File

@ -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;
}