From bcb830e88058491a57bb574baf9edc97de1203ca Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 21 Aug 2022 10:27:19 +0200 Subject: [PATCH 1/2] ZealBooter: Misc progress --- build/build-temp-vm-uefi-1.sh | 2 +- src/Kernel/KStart16.ZC | 3 ++ src/Kernel/KStart32.ZC | 7 +++-- src/Kernel/MultiProc.ZC | 5 +-- zealbooter/zealbooter.c | 59 ++++++++++++++++++++++++++++++----- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/build/build-temp-vm-uefi-1.sh b/build/build-temp-vm-uefi-1.sh index 03c8de10..5cf4ec13 100755 --- a/build/build-temp-vm-uefi-1.sh +++ b/build/build-temp-vm-uefi-1.sh @@ -70,7 +70,7 @@ if [ ! -d "ovmf" ]; then fi echo "Testing..." -qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd +qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -no-reboot -no-shutdown echo "Deleting temp folder..." rm -rf $TMPDIR diff --git a/src/Kernel/KStart16.ZC b/src/Kernel/KStart16.ZC index 32b47e61..a675b075 100755 --- a/src/Kernel/KStart16.ZC +++ b/src/Kernel/KStart16.ZC @@ -54,6 +54,9 @@ SYS_FONT_PTR:: DU32 0; SYS_VBE_INFO:: DU8 sizeof(CVBEInfo) DUP(0); SYS_VBE_MODES:: DU8 sizeof(CVBEModeShort) * VBE_MODES_NUM DUP(0); + +ALIGN 16, OC_NOP +DU64 0x5439581381193aaf, 0x2a8a30e69ec9f845; SYS_VBE_FINAL_MODE:: DU8 sizeof(CVBEMode) DUP(0); SYS_VBE_FINAL_MODE_NUM::DU16 0; //mode number of final mode set #assert $$ - SYS_KERNEL == sizeof(CKernel) - sizeof(CZXE) diff --git a/src/Kernel/KStart32.ZC b/src/Kernel/KStart32.ZC index fb18d040..2ffb36ba 100755 --- a/src/Kernel/KStart32.ZC +++ b/src/Kernel/KStart32.ZC @@ -89,9 +89,8 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$. MOV AX, CGDT.boot_ds //LOAD DS SELECTOR MOV DS, AX - BTS U32 [SYS_RUN_LEVEL], RLf_32BIT - MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE] - MOV EDI, U32 [MEM_BOOT_BASE] + //MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE] + //MOV EDI, U32 [MEM_BOOT_BASE] MOV AX, CGDT.ds MOV DS, AX @@ -104,6 +103,7 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$. //Patch abs addresses MOV ECX, U32 CPatchTableAbsAddr.abs_address_count[ESI] LEA ESI, U32 CPatchTableAbsAddr.abs_address[ESI] + @@05: LODSD ADD EAX, EDI ADD U32 [EAX], EDI @@ -114,6 +114,7 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$. DU16 CGDT.cs32; @@10: BTS U32 [SYS_RUN_LEVEL], RLf_PATCHED + BTS U32 [SYS_RUN_LEVEL], RLf_32BIT CALL SYS_FIND_PCIBIOS_SERVICE_DIR CALL SYS_FIND_PCI_SERVICES diff --git a/src/Kernel/MultiProc.ZC b/src/Kernel/MultiProc.ZC index 9a7c7cf3..528fd988 100755 --- a/src/Kernel/MultiProc.ZC +++ b/src/Kernel/MultiProc.ZC @@ -96,7 +96,7 @@ CTSS *TSSNew(I64 cpu_num) tss->tr = offset(CGDT.tr) + cpu_num * 16; tss->tr_ring3= offset(CGDT.tr_ring3) + cpu_num * 16; - d = (&sys_gdt)(U8 *) + tss->tr; + d = (0x80d8)(U8 *) + tss->tr; d1 = d(U8 *) + 4; *d = 0x0000FFFF; *d1 = 0x008F8900; @@ -106,7 +106,7 @@ CTSS *TSSNew(I64 cpu_num) *d1++ = tss >> 32; *d1 = 0; - d = (&sys_gdt)(U8 *) + tss->tr_ring3; + d = (0x80d8)(U8 *) + tss->tr_ring3; d1 = d(U8 *) + 4; *d = 0x0000FFFF; *d1 = 0x008FE900; @@ -193,6 +193,7 @@ U0 MPAPICInit() RAXSet(Gs->tss->tr); LTR AX + if (Gs->num) { IntInit1; diff --git a/zealbooter/zealbooter.c b/zealbooter/zealbooter.c index d3f3ec78..f0832933 100644 --- a/zealbooter/zealbooter.c +++ b/zealbooter/zealbooter.c @@ -13,11 +13,21 @@ static volatile struct limine_kernel_address_request kernel_address_request = { .revision = 0 }; +static volatile struct limine_hhdm_request hhdm_request = { + .id = LIMINE_HHDM_REQUEST, + .revision = 0 +}; + static volatile struct limine_memmap_request memmap_request = { .id = LIMINE_MEMMAP_REQUEST, .revision = 0 }; +static volatile struct limine_framebuffer_request framebuffer_request = { + .id = LIMINE_FRAMEBUFFER_REQUEST, + .revision = 0 +}; + struct CZXE { uint16_t jmp; uint8_t module_align_bits; @@ -123,11 +133,41 @@ struct E801 get_E801(void) { return E801; } +struct CVBEMode { + uint16_t attributes, pad0[7], pitch, width, height; + uint8_t pad1[3], bpp, pad2, memory_model, pad[12]; + uint32_t framebuffer; + uint16_t pad3[9]; + uint32_t max_pixel_clock; + uint8_t reserved[190]; +} __attribute__((packed)); + void _start(void) { struct limine_file *kernel = module_request.response->modules[0]; struct CKernel *CKernel = (void *)0x7c00; memcpy(CKernel, kernel->address, kernel->size); + struct CVBEMode *sys_vbe_mode; + for (uint64_t *p = (uint64_t *)CKernel; ; p++) { + if (*p != 0x5439581381193aaf) { + continue; + } + p++; + if (*p != 0x2a8a30e69ec9f845) { + continue; + } + p++; + sys_vbe_mode = (void *)p; + break; + } + + struct limine_framebuffer *fb = framebuffer_request.response->framebuffers[0]; + sys_vbe_mode->pitch = fb->pitch; + sys_vbe_mode->width = fb->width; + sys_vbe_mode->height = fb->height; + sys_vbe_mode->bpp = fb->bpp; + sys_vbe_mode->framebuffer = (uintptr_t)fb->address - hhdm_request.response->offset; + void *CORE0_32BIT_INIT; for (uint64_t *p = (uint64_t *)CKernel; ; p++) { if (*p != 0xaa23c08ed10bd4d7) { @@ -145,17 +185,20 @@ void _start(void) { CKernel->boot_src = BOOT_SRC_RAM; CKernel->boot_blk = 0; CKernel->boot_patch_table_base = (uintptr_t)CKernel + CKernel->h.patch_table_offset; + +// asm volatile ("jmp ." ::"a"(CKernel->boot_patch_table_base)); + CKernel->sys_run_level = RLF_VESA | RLF_16BIT; CKernel->boot_base = (uintptr_t)&CKernel->jmp; - CKernel->sys_gdt.boot_ds.lo = 0x000093000000ffff; - CKernel->sys_gdt.boot_cs.lo = 0x00009a000000ffff; - CKernel->sys_gdt.cs32.lo = 0x00cf9a000000ffff; - CKernel->sys_gdt.cs64.lo = 0x00af9b000000ffff; - CKernel->sys_gdt.cs64_ring3.lo = 0x00affb000000ffff; - CKernel->sys_gdt.ds.lo = 0x00af93000000ffff; - CKernel->sys_gdt.ds_ring3.lo = 0x00aff3000000ffff; + CKernel->sys_gdt.boot_ds.lo = 0x00CF92000000FFFF; + CKernel->sys_gdt.boot_cs.lo = 0x00CF9A000000FFFF; + CKernel->sys_gdt.cs32.lo = 0x00CF9A000000FFFF; + CKernel->sys_gdt.cs64.lo = 0x00209A0000000000; + CKernel->sys_gdt.cs64_ring3.lo = 0x0020FA0000000000; + CKernel->sys_gdt.ds.lo = 0x00CF92000000FFFF; + CKernel->sys_gdt.ds_ring3.lo = 0x00CFF2000000FFFF; CKernel->sys_gdt_ptr.limit = sizeof(CKernel->sys_gdt) - 1; CKernel->sys_gdt_ptr.base = (void *)&CKernel->sys_gdt; @@ -192,7 +235,7 @@ void _start(void) { void *target_addr = (void *)lower - kernel_address_request.response->virtual_base; target_addr += kernel_address_request.response->physical_base; - asm volatile ("jmp *%0" :: "a"(target_addr), "b"(CORE0_32BIT_INIT), "c"(&CKernel->sys_gdt_ptr) : "memory"); + asm volatile ("jmp *%0" :: "a"(target_addr), "b"(CORE0_32BIT_INIT), "c"(&CKernel->sys_gdt_ptr), "S"(CKernel->boot_patch_table_base), "D"(CKernel->boot_base) : "memory"); __builtin_unreachable(); } From 5f3bdc637b88a578798eadd843c324f3edc26a0a Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 21 Aug 2022 10:36:14 +0200 Subject: [PATCH 2/2] Set sys_pci_buses to 256 by default --- src/Kernel/KStart16.ZC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KStart16.ZC b/src/Kernel/KStart16.ZC index a675b075..66b89559 100755 --- a/src/Kernel/KStart16.ZC +++ b/src/Kernel/KStart16.ZC @@ -33,7 +33,7 @@ MEM_E820:: DU8 MEM_E820_ENTRIES_NUM * sizeof(CMemE820) DUP (0); MEM_PHYSICAL_SPACE:: DU64 0; SYS_GDT_PTR:: DU16 sizeof(CGDT) - 1; DU64 0; -SYS_PCI_BUSES:: DU16 0; +SYS_PCI_BUSES:: DU16 256; ALIGN 16, OC_NOP