diff --git a/dbgq b/gdbq similarity index 50% rename from dbgq rename to gdbq index 9be1584..5ca3e04 100644 --- a/dbgq +++ b/gdbq @@ -1,4 +1,4 @@ file out/secxkrnl.elf -set arch i386:x86-64:intel +set arch i386:x86-64 target remote localhost:1234 -break sys_entry_64.high +break hmain \ No newline at end of file diff --git a/gdbw b/gdbw new file mode 100644 index 0000000..e5e8d74 --- /dev/null +++ b/gdbw @@ -0,0 +1,3 @@ +disconnect +set arch i386:x86-64:intel +target remote localhost:1234 \ No newline at end of file diff --git a/hal/boot.asm.in b/hal/boot.asm.in index 5336eb5..be17e82 100644 --- a/hal/boot.asm.in +++ b/hal/boot.asm.in @@ -141,9 +141,8 @@ sys_entry_64: mov ss,ax mov rsp, init_stack - xor edi, edi + xor rdi, rdi mov edi, dword [multiboot_info_ptr] - mov rdi, rsi call hmain .end: hlt diff --git a/hal/boot.c b/hal/boot.c index 4e61021..d5f3736 100644 --- a/hal/boot.c +++ b/hal/boot.c @@ -4,6 +4,7 @@ #include "cpu.h" #include "kernel.h" #include "hal.h" +#include "multiboot2.h" //static void //halp_obtain_cpu_info(struct boot_info *hal_info) @@ -21,17 +22,46 @@ //} void HABI -hmain(void *m_info) +hmain(struct multiboot_tag *mb_info) { - if (m_info == NULL || (uint64) m_info & bit_field_mask(0, 2)) + if (mb_info == NULL) { - hal_halt_cpu(); + goto err; } - // init HAL infrastructures - hal_print_init(); - hal_mem_init(); + char *cur_ptr = (char *) mb_info + 8; + char *bootloader_name = NULL; + while (1) + { + struct multiboot_tag *cur_tag = (struct multiboot_tag *) cur_ptr; + switch (cur_tag->type) + { + case MULTIBOOT_TAG_TYPE_MMAP: + hal_mem_init((struct multiboot_tag_mmap*) cur_ptr); + break; + case MULTIBOOT_TAG_TYPE_FRAMEBUFFER: + hal_print_init((struct multiboot_tag_framebuffer *) cur_ptr); + break; + case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: + bootloader_name = ((struct multiboot_tag_string*)cur_ptr)->string; + break; + case MULTIBOOT_TAG_TYPE_ACPI_NEW: + default: + break; + } + + if (cur_tag->type == MULTIBOOT_TAG_TYPE_END) + { + break; + } + + cur_ptr += cur_tag->size; + cur_ptr = (char *) ALIGN(uintptr, cur_ptr, 8); + } + hal_halt_cpu(); + + hal_printf("Boot loader:%d\n", bootloader_name); struct boot_info *boot_info = halloc(sizeof(struct boot_info)); @@ -45,4 +75,6 @@ hmain(void *m_info) } kmain(boot_info); +err: + hal_halt_cpu(); } diff --git a/hal/inc/mem.h b/hal/inc/mem.h index ff6749b..bb1e8b3 100644 --- a/hal/inc/mem.h +++ b/hal/inc/mem.h @@ -2,6 +2,7 @@ #include "cdef.h" #include "mem.h" +#include "multiboot2.h" /** Global Descriptors Table Definitions @@ -106,5 +107,5 @@ void hfree(void *ptr); void -hal_mem_init(void); +hal_mem_init(struct multiboot_tag_mmap *info); diff --git a/hal/inc/multiboot2.h b/hal/inc/multiboot2.h index 3691fe5..12e09cc 100644 --- a/hal/inc/multiboot2.h +++ b/hal/inc/multiboot2.h @@ -110,7 +110,7 @@ struct multiboot_header_tag_information_request multiboot_uint16_t type; multiboot_uint16_t flags; multiboot_uint32_t size; - multiboot_uint32_t requests[0]; + multiboot_uint32_t requests[]; }; struct multiboot_header_tag_address @@ -188,7 +188,7 @@ struct multiboot_tag_string { multiboot_uint32_t type; multiboot_uint32_t size; - char string[0]; + char string[]; }; struct multiboot_tag_module @@ -197,7 +197,7 @@ struct multiboot_tag_module multiboot_uint32_t size; multiboot_uint32_t mod_start; multiboot_uint32_t mod_end; - char cmdline[0]; + char cmdline[]; }; struct multiboot_tag_basic_meminfo @@ -223,7 +223,7 @@ struct multiboot_tag_mmap multiboot_uint32_t size; multiboot_uint32_t entry_size; multiboot_uint32_t entry_version; - struct multiboot_mmap_entry entries[0]; + struct multiboot_mmap_entry entries[]; }; struct multiboot_vbe_info_block @@ -276,7 +276,7 @@ struct multiboot_tag_framebuffer struct { multiboot_uint16_t framebuffer_palette_num_colors; - struct multiboot_color framebuffer_palette[0]; + struct multiboot_color framebuffer_palette[]; }; struct { @@ -297,7 +297,7 @@ struct multiboot_tag_elf_sections multiboot_uint32_t num; multiboot_uint32_t entsize; multiboot_uint32_t shndx; - char sections[0]; + char sections[]; }; struct multiboot_tag_apm @@ -336,28 +336,28 @@ struct multiboot_tag_smbios multiboot_uint8_t major; multiboot_uint8_t minor; multiboot_uint8_t reserved[6]; - multiboot_uint8_t tables[0]; + multiboot_uint8_t tables[]; }; struct multiboot_tag_old_acpi { multiboot_uint32_t type; multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; + multiboot_uint8_t rsdp[]; }; struct multiboot_tag_new_acpi { multiboot_uint32_t type; multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; + multiboot_uint8_t rsdp[]; }; struct multiboot_tag_network { multiboot_uint32_t type; multiboot_uint32_t size; - multiboot_uint8_t dhcpack[0]; + multiboot_uint8_t dhcpack[]; }; struct multiboot_tag_efi_mmap @@ -366,7 +366,7 @@ struct multiboot_tag_efi_mmap multiboot_uint32_t size; multiboot_uint32_t descr_size; multiboot_uint32_t descr_vers; - multiboot_uint8_t efi_mmap[0]; + multiboot_uint8_t efi_mmap[]; }; #endif /* ! ASM_FILE */ diff --git a/hal/inc/print.h b/hal/inc/print.h index 0a73d08..6392261 100644 --- a/hal/inc/print.h +++ b/hal/inc/print.h @@ -1,6 +1,7 @@ #pragma once #include "cdef.h" #include "print.h" +#include "multiboot2.h" void hal_assert(uint32 expression, char *message); @@ -12,4 +13,4 @@ void hal_clear_screen(void); void -hal_print_init(void); +hal_print_init(struct multiboot_tag_framebuffer* info); diff --git a/hal/mb_hdr.asm.in b/hal/mb_hdr.asm.in index f4df5cc..542a0d2 100644 --- a/hal/mb_hdr.asm.in +++ b/hal/mb_hdr.asm.in @@ -21,11 +21,10 @@ start_hdr: align MULTIBOOT_INFO_ALIGN dw MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST dw 0 ; flag - dd (8+4*4) ; size + dd (8+4*3) ; size dd MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME dd MULTIBOOT_TAG_TYPE_MMAP dd MULTIBOOT_TAG_TYPE_ACPI_NEW - dd MULTIBOOT_TAG_TYPE_BOOTDEV ;==================== align MULTIBOOT_INFO_ALIGN dw MULTIBOOT_HEADER_TAG_FRAMEBUFFER; type=5 diff --git a/hal/mem.c b/hal/mem.c index f6b1bc8..2bd98d4 100644 --- a/hal/mem.c +++ b/hal/mem.c @@ -148,8 +148,7 @@ hal_write_segment_descriptor(void *const gdt, uint32 const base, uint32 const li ((uint8 *) gdt)[7] = (uint8) ((seg_desc >> 56) & 0xFF); } -static -void _hal_init_gdt(void) +void hal_init_gdt(void) { uint32 coreid = hal_get_core_id(); // get gdt ready @@ -181,20 +180,19 @@ void _hal_init_gdt(void) } void -hal_mem_init() +hal_mem_init(struct multiboot_tag_mmap *info) { - _hal_init_gdt(); - hal_heap_used = 0; + UNREFERENCED(info); } void * halloc(uint32 size) { - void* ret; + void *ret; ret = NULL; - if(hal_heap_used + size < HAL_HEAP_SIZE) + if (hal_heap_used + size < HAL_HEAP_SIZE) { - ret = (void*)((uintptr)hal_heap + hal_heap_used); + ret = (void *) ((uintptr) hal_heap + hal_heap_used); hal_heap_used += size; } return ret; @@ -206,5 +204,5 @@ hfree(void *ptr) /** * Do nothing for now since salloc not available in HAL */ - UNREFERENCED(ptr); + UNREFERENCED(ptr); } diff --git a/hal/print.c b/hal/print.c index 5c43c4e..224c5a9 100644 --- a/hal/print.c +++ b/hal/print.c @@ -10,9 +10,9 @@ static uint64 text_pos; void -hal_print_init(void) +hal_print_init(struct multiboot_tag_framebuffer* info) { - text_pos = 0; + UNREFERENCED(info); } static void diff --git a/inc/cdef.h b/inc/cdef.h index 1a415d7..9687987 100644 --- a/inc/cdef.h +++ b/inc/cdef.h @@ -24,6 +24,8 @@ typedef _Bool bool; #define PRAGMA_ALIGN(x) __attribute__ ((aligned(x))) +#define ALIGN(type, num, align) (((type)(num) + ((type)align - 1)) & ~((type)align - 1)) + #define UNREFERENCED(x) {(x) = (x);} #define KABI __attribute__((sysv_abi)) diff --git a/mk/grub.cfg b/mk/grub.cfg index 73fa1c8..b27672b 100644 --- a/mk/grub.cfg +++ b/mk/grub.cfg @@ -1,3 +1,6 @@ +set timeout=0 +set default=0 + menuentry "secX" { multiboot2 /secX/secxkrnl.elf } \ No newline at end of file diff --git a/runq.sh b/runq.sh index 9391862..003a80a 100644 --- a/runq.sh +++ b/runq.sh @@ -1,4 +1,4 @@ #!/bin/bash -qemu-system-x86_64 -bios qemu_bios.bin -vnc :10 -monitor stdio -cdrom out/secxkrnl.iso -s -S -no_reboot +qemu-system-x86_64 -bios qemu_bios.bin -vnc :10 -monitor stdio -cdrom out/secxkrnl.iso -s -S -no-reboot