commit 85208a549346593962617a7a739c28f3cb084aeb
parent 225a1bb8b4bec34f1f82e4db35f867ca5109db55
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 6 Apr 2024 17:30:14 +0900
try to read vendor id
Diffstat:
6 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/sys/include/libc.h b/sys/include/libc.h
@@ -1,6 +1,7 @@
#define NULL 0L
typedef unsigned char uint8;
+typedef unsigned short int uint16;
typedef unsigned int uint32;
typedef unsigned long long int uint64;
typedef long long int int64;
diff --git a/sys/src/kernel/amd64/machine.s b/sys/src/kernel/amd64/machine.s
@@ -10,6 +10,7 @@ io_out32:
ret
// uint32 io_in32(uint16 addr);
+ .global io_in32
io_in32:
mov %di, %dx
in %dx, %eax
diff --git a/sys/src/kernel/amd64/pci.c b/sys/src/kernel/amd64/pci.c
@@ -1,4 +1,5 @@
#include <libc.h>
+#include "pci.h"
uint32
pci_address(uint8 bus, uint8 dev, uint8 func, uint8 reg_off)
@@ -9,3 +10,28 @@ pci_address(uint8 bus, uint8 dev, uint8 func, uint8 reg_off)
(func&3) << 8 |
(reg_off&0xfc); // the least 2 bits should be 0.
}
+
+void
+write_pci_address(uint32 addr)
+{
+ io_out32(pci_config_address, addr);
+}
+
+void
+write_pci_data(uint32 value)
+{
+ io_out32(pci_config_data, value);
+}
+
+uint32
+read_pci_data()
+{
+ return io_in32(pci_config_data);
+}
+
+uint16
+read_pci_vendor_id(uint8 bus, uint8 device, uint8 func)
+{
+ write_pci_address(pci_address(bus, device, func, 0x00));
+ return read_pci_data() & 0xffff;
+}
diff --git a/sys/src/kernel/amd64/pci.h b/sys/src/kernel/amd64/pci.h
@@ -1,5 +1,13 @@
// #include <libc.h>
+const uint16 pci_config_address = 0xcf8;
+const uint16 pci_config_data = 0xcfc;
+
uint32 pci_address(uint8 bus, uint8 device, uint8 function, uint8 reg_addr);
void io_out32(uint16 addr, uint32 data);
-uint32(uint16 addr);
-\ No newline at end of file
+uint32 io_in32(uint16 addr);
+
+void write_pci_address(uint32 addr);
+void write_pci_data(uint32 value);
+uint32 read_pci_data();
+uint16 read_pci_vendor_id(uint8 bus, uint8 device, uint8 func);
+\ No newline at end of file
diff --git a/sys/src/kernel/draw.c b/sys/src/kernel/draw.c
@@ -27,7 +27,7 @@ init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIX
return -1;
}
root_window.fb = fb_base;
- root_window.fg = 0x0;
+ root_window.fg = 0x000000ff;
root_window.bg = 0x555555ff;
root_window.ppsl = ppsl;
root_window.parent = &root_window;
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -26,7 +26,7 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
root_window.children = root_children;
Window win0;
- make_window(&root_window, &win0, (Point){150, 100}, (Point){400, 300}, 0x0, 0xb9d08bff);
+ make_window(&root_window, &win0, (Point){150, 100}, (Point){400, 300}, 0xff, 0xb9d08bff);
Console con0 = {
.win = &win0,
.font = &asciifont,
@@ -43,10 +43,11 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
.img = m_img,
};
- cons_printf(&con0, "hello world!\n");
- cons_printf(&con0, "pixel at {%d, %d}: %x\n", p.x, p.y, get_pixel(&root_window, p));
m.pos.x = (m.pos.x + 1) % root_window.size.x;
draw_mouse(&root_window, &m);
+ cons_printf(&con0, "hello world!\n");
+ cons_printf(&con0, "pixel at {%d, %d}: %x\n", p.x, p.y, get_pixel(&root_window, p));
+// cons_printf(&con0, "bus 0 vendor id: %d\n", read_pci_vendor_id(0, 0, 0));
halt:
for(;;) { __asm__("hlt"); }