setos

拙OS
Log | Files | Refs | LICENSE

commit 225a1bb8b4bec34f1f82e4db35f867ca5109db55
parent 9dcd228c2728fd9550a52a2755ec373a6ab19a5d
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat,  6 Apr 2024 15:39:12 +0900

add assembly langage file to use pci

Diffstat:
Msys/src/Makefile | 18++++++++++++++----
Asys/src/kernel/amd64/machine.s | 16++++++++++++++++
Asys/src/kernel/amd64/pci.c | 11+++++++++++
Asys/src/kernel/amd64/pci.h | 6++++++
Msys/src/kernel/main.c | 43+++++++++++++++++++++----------------------
5 files changed, 68 insertions(+), 26 deletions(-)

diff --git a/sys/src/Makefile b/sys/src/Makefile @@ -28,20 +28,30 @@ boot/boot.efi: boot/boot.dll boot/boot.dll: boot/boot.c boot/utils.c $(BOOTCC) $(BOOTCFLAGS) -o $@ boot/boot.c boot/utils.c -kernel/main.elf: kernel/$(ARCH)/start.o kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o kernel/memmap.ld ../lib/libc.a +kernel/main.elf: kernel/$(ARCH)/start.o kernel/main.o kernel/memmap.ld \ + ../lib/libc.a \ + kernel/alloc.o kernel/console.o kernel/draw.o \ + kernel/$(ARCH)/machine.o kernel/$(ARCH)/pci.o $(LD) $(LDFLAGS) -e kernel_start -T kernel/memmap.ld -o $@ \ - kernel/$(ARCH)/start.o kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o \ + kernel/$(ARCH)/start.o kernel/main.o \ + kernel/alloc.o kernel/console.o kernel/draw.o kernel/$(ARCH)/pci.o \ + kernel/$(ARCH)/machine.o \ -lc kernel/$(ARCH)/start.o: kernel/$(ARCH)/start.s $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/start.s kernel/main.o: kernel/main.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h $(CC) $(CFLAGS) -c -o $@ kernel/main.c -kernel/draw.o: kernel/draw.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h - $(CC) $(CFLAGS) -c -o $@ kernel/draw.c kernel/alloc.o: kernel/alloc.c ../include/libc.h $(CC) $(CFLAGS) -c -o $@ kernel/alloc.c kernel/console.o: kernel/console.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h $(CC) $(CFLAGS) -c -o $@ kernel/console.c +kernel/draw.o: kernel/draw.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h + $(CC) $(CFLAGS) -c -o $@ kernel/draw.c +kernel/$(ARCH)/pci.o: kernel/$(ARCH)/pci.c kernel/$(ARCH)/pci.h ../include/libc.h + $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/pci.c +kernel/$(ARCH)/machine.o: kernel/$(ARCH)/machine.s + $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/machine.s + ../lib/libc.a: libc/strcpy.o libc/memset.o ../lib ar rcs $@ libc/strcpy.o libc/memset.o diff --git a/sys/src/kernel/amd64/machine.s b/sys/src/kernel/amd64/machine.s @@ -0,0 +1,16 @@ +// #include <libc.h> +.section .text + +// void io_out32(uint16 addr, uint32 data); + .global io_out32 +io_out32: + mov %di, %dx + mov %esi, %eax + out %eax, %dx + ret + +// uint32 io_in32(uint16 addr); +io_in32: + mov %di, %dx + in %dx, %eax + ret diff --git a/sys/src/kernel/amd64/pci.c b/sys/src/kernel/amd64/pci.c @@ -0,0 +1,11 @@ +#include <libc.h> + +uint32 +pci_address(uint8 bus, uint8 dev, uint8 func, uint8 reg_off) +{ + return 1 << 31 | // enable bit. + bus << 16 | + (dev&0x1f) << 11 | + (func&3) << 8 | + (reg_off&0xfc); // the least 2 bits should be 0. +} diff --git a/sys/src/kernel/amd64/pci.h b/sys/src/kernel/amd64/pci.h @@ -0,0 +1,5 @@ +// #include <libc.h> + +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 diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c @@ -5,6 +5,7 @@ error err; uint8 kernel_main_stack[1024]; +RGBA32 m_img[16*16]; // initialized at the bottom of this file. void kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) @@ -34,7 +35,24 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) .pos = (Point){0, 0} }; Point p = {0, 0}; - RGBA32 m_hidden[16*16], m_img[16*16] = { + RGBA32 m_hidden[16*16]; + Mouse m = { + .size = (Point) {16, 16}, + .pos = (Point) {143, 150}, + .hidden = m_hidden, + .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); + +halt: + for(;;) { __asm__("hlt"); } +} + +RGBA32 m_img[16*16] = { 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff, 0xffffffff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff, 0xffffffff, 0xffffffff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -50,24 +68,4 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}; - Mouse m = { - .size = (Point) {16, 16}, - .pos = (Point) {143, 150}, - .hidden = m_hidden, - .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)); - for (;;) { - m.pos.x = (m.pos.x + 1) % root_window.size.x; - draw_mouse(&root_window, &m); - for (int i = 0; i < 0x100000; i++) { - } - clear_mouse(&root_window, &m); - } - -halt: - for(;;) { __asm__("hlt"); } -} + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}; +\ No newline at end of file