setos

拙OS
Log | Files | Refs | LICENSE

commit bdd7e90acee1f048946782373b1a2a3df5046d8b
parent 91aeb2203d61ae581eb08d1bab781de528b7d5d5
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 30 Mar 2024 09:38:17 +0900

interconnect abi

Diffstat:
MMakefile | 8++++++--
Mkernel.c | 10++++++++--
Mloader.c | 17++++++++++-------
Muefi.h | 18++++++++++--------
Mutils.c | 14++++++++------
Mutils.h | 2--
6 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/Makefile b/Makefile @@ -35,6 +35,11 @@ run: disk.img qemu-system-x86_64 \ -bios /usr/share/edk2/x64/OVMF.fd \ -drive format=raw,file=disk.img \ + +gdb: disk.img + qemu-system-x86_64 \ + -bios /usr/share/edk2/x64/OVMF.fd \ + -drive format=raw,file=disk.img \ -gdb tcp::1234 -S test: test/* $(SRC) $(HDR) @@ -42,4 +47,4 @@ test: test/* $(SRC) $(HDR) clean: rm -rf *.o *.efi *.elf *.dll disk.img image - (cd test && make clean) -\ No newline at end of file + (cd test && make clean) diff --git a/kernel.c b/kernel.c @@ -1,6 +1,12 @@ +typedef unsigned char uint8_t; +typedef unsigned long long int uint64_t; + +// Argument order is to interface to the MS-ABI void -kernel_main(void) +kernel_main(void *dummy0, void *dummy1, uint64_t fb_size, uint8_t *fb_base) { - for(int x = 0;; x++) { + for(int i = 0; i < fb_size; i++) { + fb_base[i] = i % 0xff; } + for(;;); } \ No newline at end of file diff --git a/loader.c b/loader.c @@ -1,6 +1,5 @@ #include "uefi.h" #include "utils.h" - EFI_SYSTEM_TABLE *SystemTable; EFI_STATUS @@ -15,6 +14,7 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) // Output firmware bender. SystemTable->ConOut->ClearScreen(SystemTable->ConOut); efi_printf("vendor: %s\n", wstr2str(SystemTable->FirmwareVendor, s8)); + efi_printf("EfiMain: 0x%x\n", EfiMain); // Output memory map information. UINTN mmsize = 8196; @@ -49,6 +49,8 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) for (UINTN i = 0; i < gop->Mode->FrameBufferSize; i++) { frame_buffer[i] = 0xFF; } + efi_printf("frame buffer: base: %x, size: %x\n", frame_buffer, + gop->Mode->FrameBufferSize); EFI_FILE_PROTOCOL *root, *kernel; stat = open_root(ImageHandle, &root); @@ -96,6 +98,10 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) return stat; } + efi_printf("frame buffer: base: %x, %x, size: %x\n", frame_buffer, + gop->Mode->FrameBufferBase, + gop->Mode->FrameBufferSize); + mmsize = 8196; stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver); if (stat != EFI_SUCCESS) { @@ -108,12 +114,9 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) return stat; } - for (UINTN i = 0; i < gop->Mode->FrameBufferSize / 2; i+=3) { - frame_buffer[i] = 0x0; - } - - typedef void (* Kernel) (void); - ((Kernel) kernel_ehdr.entry)(); + typedef void (* Kernel) (UINT8 *fb_base, UINT64 fb_size); + ((Kernel) kernel_ehdr.entry)( + (UINT8 *)gop->Mode->FrameBufferBase, gop->Mode->FrameBufferSize); return EFI_SUCCESS; } diff --git a/uefi.h b/uefi.h @@ -4,6 +4,8 @@ #define CONST #define EFIAPI +#define NULL 0L + typedef unsigned short CHAR16; typedef unsigned long long UINTN; typedef unsigned char UINT8; @@ -24,17 +26,17 @@ typedef struct EFI_GUID { } EFI_GUID; #define EFI_LOADED_IMAGE_PROTOCOL_GUID \ - ((EFI_GUID) {0x5b1b31a1, 0x9562, 0x11d2, \ - {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) + {0x5b1b31a1, 0x9562, 0x11d2, \ + {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ - ((EFI_GUID) {0x9042a9de, 0x23dc, 0x4a38, \ - {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}}) + {0x9042a9de, 0x23dc, 0x4a38, \ + {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}} #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - ((EFI_GUID) {0x964e5b22, 0x6459, 0x11d2, \ - {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) + {0x964e5b22, 0x6459, 0x11d2, \ + {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} #define EFI_FILE_INFO_ID \ - ((EFI_GUID) {0x9576e92, 0x6d3f, 0x11d2, \ - {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) + {0x9576e92, 0x6d3f, 0x11d2, \ + {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} // EFI_STATUS enum { diff --git a/utils.c b/utils.c @@ -132,7 +132,7 @@ open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root) EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; stat = SystemTable->BootServices->OpenProtocol( - ImageHandle, &EFI_LOADED_IMAGE_PROTOCOL_GUID, + ImageHandle, &(EFI_GUID)EFI_LOADED_IMAGE_PROTOCOL_GUID, (VOID **) &li, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); if (stat != EFI_SUCCESS) { @@ -140,7 +140,7 @@ open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root) } stat = SystemTable->BootServices->OpenProtocol( - li->DeviceHandle, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, + li->DeviceHandle, &(EFI_GUID)EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, (VOID **) &fs, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); if (stat != EFI_SUCCESS) { @@ -158,7 +158,7 @@ open_gop(EFI_HANDLE ImageHandle, EFI_GRAPHICS_OUTPUT_PROTOCOL **gop) UINTN n = 0; EFI_HANDLE *_gop; stat = SystemTable->BootServices->LocateHandleBuffer( - ByProtocol, &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, + ByProtocol, &(EFI_GUID)EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, &n, &_gop ); if (stat != EFI_SUCCESS) { @@ -166,7 +166,7 @@ open_gop(EFI_HANDLE ImageHandle, EFI_GRAPHICS_OUTPUT_PROTOCOL **gop) return stat; } stat = SystemTable->BootServices->OpenProtocol( - _gop[0], &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + _gop[0], &(EFI_GUID)EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, (VOID **) gop, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); if (stat != EFI_SUCCESS) { @@ -235,8 +235,9 @@ load_elf(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr phdr[]) if (phdr[i].type != PT_LOAD) { continue; } - efi_printf("load_elf: allocate %d pages at %x\n", - (phdr[i].memsz + 0xfff) / 0x1000, &phdr[i].vaddr +/* + efi_printf("load_elf: allocate %d at %x\n", + phdr[i].memsz, phdr[i].vaddr ); stat = SystemTable->BootServices->AllocatePages( AllocateAddress, EfiLoaderData, @@ -246,6 +247,7 @@ load_elf(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr phdr[]) efi_printf("allocate pages: %d\n", stat); return stat; } +*/ efi_printf("load_elf: phdr[i].vaddr: %x\n", phdr[i].vaddr); stat = elf->SetPosition(elf, phdr[i].offset); if (stat != EFI_SUCCESS) { diff --git a/utils.h b/utils.h @@ -2,8 +2,6 @@ extern EFI_SYSTEM_TABLE *SystemTable; -#define NULL 0L - // Printh converts the integer into a string of hex representation. // It returns the second argument. // The second argument should have length of 19 ("0x" + "0123456789abcdef" + "\0").