+ Parse multiboot_info
+ Fix multiboot_info NULL in hmain() bug - Time to read some papers and rethink the desig
This commit is contained in:
parent
34949452db
commit
807ac4de22
@ -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
|
3
gdbw
Normal file
3
gdbw
Normal file
@ -0,0 +1,3 @@
|
||||
disconnect
|
||||
set arch i386:x86-64:intel
|
||||
target remote localhost:1234
|
@ -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
|
||||
|
44
hal/boot.c
44
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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
16
hal/mem.c
16
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -1,3 +1,6 @@
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "secX" {
|
||||
multiboot2 /secX/secxkrnl.elf
|
||||
}
|
Loading…
Reference in New Issue
Block a user