From d7f72e3aa937a1604572de593661866607c7662e Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 21 Aug 2022 19:03:17 +0200 Subject: [PATCH] ZealBooter: Misc cleanup, SMP working --- build/build-temp-vm-uefi-1.sh | 2 +- src/Kernel/KStart16.ZC | 2 - src/Kernel/KStart32.ZC | 2 + src/Kernel/MultiProc.ZC | 4 +- zealbooter/zealbooter.c | 76 +++++++++++++++++++---------------- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/build/build-temp-vm-uefi-1.sh b/build/build-temp-vm-uefi-1.sh index 03c8de10..8515eae7 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 -smp 4 echo "Deleting temp folder..." rm -rf $TMPDIR diff --git a/src/Kernel/KStart16.ZC b/src/Kernel/KStart16.ZC index 66b89559..0c365d1b 100755 --- a/src/Kernel/KStart16.ZC +++ b/src/Kernel/KStart16.ZC @@ -55,8 +55,6 @@ 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 2ffb36ba..bfcc0b01 100755 --- a/src/Kernel/KStart32.ZC +++ b/src/Kernel/KStart32.ZC @@ -82,6 +82,8 @@ SYS_SEMAS:: DU8 SEMA_SEMAS_NUM * DEFAULT_CACHE_LINE_WIDTH DUP(0); DU64 0xf6ceba7d4b74179a; CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$. + CLD + PUSH U32 RFLAGG_START POPFD MOV EAX, SYS_START_CR0 diff --git a/src/Kernel/MultiProc.ZC b/src/Kernel/MultiProc.ZC index 528fd988..2b4f2e44 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 = (0x80d8)(U8 *) + tss->tr; + d = (&sys_gdt)(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 = (0x80d8)(U8 *) + tss->tr_ring3; + d = (&sys_gdt)(U8 *) + tss->tr_ring3; d1 = d(U8 *) + 4; *d = 0x0000FFFF; *d1 = 0x008FE900; diff --git a/zealbooter/zealbooter.c b/zealbooter/zealbooter.c index 6b4d0f19..0a7ed164 100644 --- a/zealbooter/zealbooter.c +++ b/zealbooter/zealbooter.c @@ -36,12 +36,12 @@ struct CZXE { int64_t org; int64_t patch_table_offset; int64_t file_size; -}; +} __attribute__((packed)); struct CDate { uint32_t time; int32_t date; -}; +} __attribute__((packed)); #define MEM_E820_ENTRIES_NUM 48 @@ -56,11 +56,11 @@ struct CMemE820 { uint8_t *base; int64_t len; uint8_t type, pad[3]; -}; +} __attribute__((packed)); struct CGDTEntry { uint64_t lo, hi; -}; +} __attribute__((packed)); #define MP_PROCESSORS_NUM 128 @@ -75,7 +75,32 @@ struct CGDT { struct CGDTEntry ds_ring3; struct CGDTEntry tr[MP_PROCESSORS_NUM]; struct CGDTEntry tr_ring3[MP_PROCESSORS_NUM]; -}; +} __attribute__((packed)); + +struct CVBEInfo { + uint8_t signature[4]; + uint16_t version; + uint32_t oem, capabilities, video_modes; + uint16_t total_memory, software_revision; + uint32_t vendor, product_name, product_revision; + uint8_t reserved[222], oem_data[256]; +} __attribute__((packed)); + +struct CVBEModeShort { + uint16_t width, height, mode_num; + uint32_t max_pixel_clock; +} __attribute__((packed)); + +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)); + +#define VBE_MODES_NUM 32 struct CKernel { struct CZXE h; @@ -95,15 +120,19 @@ struct CKernel { uint8_t *base; } __attribute__((packed)) sys_gdt_ptr; uint16_t sys_pci_buses; - struct CGDT sys_gdt; + struct CGDT sys_gdt __attribute__((aligned(16))); uint32_t sys_font_ptr; + struct CVBEInfo sys_vbe_info; + struct CVBEModeShort sys_vbe_modes[VBE_MODES_NUM]; + struct CVBEMode sys_vbe_mode; + uint16_t sys_vbe_mode_num; } __attribute__((packed)); #define BOOT_SRC_RAM 2 #define RLF_16BIT 0b01 #define RLF_VESA 0b10 -extern char trampoline[], trampoline_end[]; +extern symbol trampoline, trampoline_end; struct E801 { size_t lowermem; @@ -133,41 +162,18 @@ 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 = kernel->address; uintptr_t final_address = 0x7c00; - 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; + CKernel->sys_vbe_mode.pitch = fb->pitch; + CKernel->sys_vbe_mode.width = fb->width; + CKernel->sys_vbe_mode.height = fb->height; + CKernel->sys_vbe_mode.bpp = fb->bpp; + CKernel->sys_vbe_mode.framebuffer = (uintptr_t)fb->address - hhdm_request.response->offset; void *CORE0_32BIT_INIT; for (uint64_t *p = (uint64_t *)CKernel; ; p++) {