Assertion and Kernel Modules
This commit is contained in:
parent
17d1b499bd
commit
d84ceb592d
|
@ -21,8 +21,22 @@ typedef struct {
|
|||
uint64_t mem_available;
|
||||
} mem_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t base_addr;
|
||||
uint64_t size;
|
||||
char* name;
|
||||
linked_list_node_t list_node;
|
||||
} module_descriptor_node_t;
|
||||
|
||||
typedef struct {
|
||||
linked_list_t* module_list;
|
||||
uint64_t module_count;
|
||||
} module_info_t;
|
||||
|
||||
typedef struct {
|
||||
mem_info_t* mem_info; // all available memory info
|
||||
module_info_t* module_info; // all kernel modules loaded
|
||||
} boot_info_t;
|
||||
|
||||
#endif
|
|
@ -3,9 +3,8 @@
|
|||
#include "mem.h"
|
||||
#include "io.h"
|
||||
#include "var.h"
|
||||
#include "../common/util/util.h"
|
||||
#include "../common/sys/sys_info.h"
|
||||
#include "../common/util/list/linked_list/linked_list.h"
|
||||
#include "../common/lib/str.h"
|
||||
#include "../common/lib/mem.h"
|
||||
|
||||
boot_info_t* NATIVE64 hal_init(multiboot_info_t* m_info)
|
||||
{
|
||||
|
@ -33,16 +32,16 @@ boot_info_t* NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
|
||||
|
||||
boot_info_t* boot_info = (boot_info_t*)hal_halloc(sizeof(boot_info_t));
|
||||
hal_assert(boot_info != NULL, "Unable to allocate memory for boot_info.");
|
||||
// obtain boot information
|
||||
// memory info
|
||||
boot_info->mem_info = (mem_info_t*)hal_halloc(sizeof(mem_info_t));
|
||||
hal_assert(boot_info->mem_info != NULL, "Unable to allocate memory for mem_info.");
|
||||
boot_info->mem_info->mem_available = 0;
|
||||
boot_info->mem_info->mem_reserved = 0;
|
||||
boot_info->mem_info->mem_seg_list = (linked_list_t*)hal_halloc((sizeof(linked_list_t)));
|
||||
boot_info->mem_info->mem_seg_list->head = NULL;
|
||||
boot_info->mem_info->mem_seg_list->size = 0;
|
||||
|
||||
// obtain boot information
|
||||
|
||||
// memory info
|
||||
hal_assert(boot_info->mem_info->mem_seg_list != NULL, "Unable to allocate memory for mem_seg_list.");
|
||||
linked_list_init(boot_info->mem_info->mem_seg_list);
|
||||
if(m_info->flags & (1 << 6))
|
||||
{
|
||||
multiboot_memory_map_t const *mem_map = (multiboot_memory_map_t *) m_info->mmap_addr;
|
||||
|
@ -50,6 +49,7 @@ boot_info_t* NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
for (int i = 0; i < mem_map_size; i++)
|
||||
{
|
||||
memory_descriptor_node_t* each_desc = (memory_descriptor_node_t*)hal_halloc(sizeof(memory_descriptor_node_t));
|
||||
hal_assert(each_desc != NULL, "Unable to allocate memory for memory_descriptor.");
|
||||
each_desc->base_addr = (mem_map + i)->addr;
|
||||
each_desc->size = (mem_map + i)->len;
|
||||
if((mem_map + i)->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
|
@ -72,6 +72,36 @@ boot_info_t* NATIVE64 hal_init(multiboot_info_t* m_info)
|
|||
hal_halt_cpu();
|
||||
}
|
||||
|
||||
// loaded kernel modules
|
||||
boot_info->module_info = (module_info_t*)hal_halloc(sizeof(module_info_t));
|
||||
hal_assert(boot_info->module_info != NULL, "Unable to allocate memory for module_info.");
|
||||
boot_info->module_info->module_count = 0;
|
||||
boot_info->module_info->module_list = (linked_list_t*)hal_halloc(sizeof(linked_list_t));
|
||||
hal_assert(boot_info->module_info->module_list != NULL, "Unable to allocate memory for module_list.");
|
||||
linked_list_init(boot_info->module_info->module_list);
|
||||
if(m_info->flags & (1 << 3))
|
||||
{
|
||||
multiboot_module_t const * mods_list = (multiboot_module_t *)m_info->mods_addr;
|
||||
boot_info->module_info->module_count = m_info->mods_count;
|
||||
for (uint64_t i = 0; i < boot_info->module_info->module_count; i++)
|
||||
{
|
||||
module_descriptor_node_t* each_module = (module_descriptor_node_t*)hal_halloc(sizeof(module_descriptor_node_t));
|
||||
hal_assert(each_module != NULL, "Unable to allocate memory for module_descriptor.");
|
||||
each_module->base_addr = (mods_list + i)->mod_start;
|
||||
each_module->size = (mods_list + i)->mod_end - (mods_list + i)->mod_start;
|
||||
each_module->name = (char*)hal_halloc((size_t)str_len((char *) (mods_list + i)->cmdline) + 1);
|
||||
hal_assert(each_module->name != NULL, "Unable to allocate memory for module name string.");
|
||||
mem_copy((void*)(mods_list + i)->cmdline, each_module->name, str_len((char *) (mods_list + i)->cmdline) + 1);
|
||||
linked_list_add(boot_info->module_info->module_list, &each_module->list_node);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// halt machine
|
||||
hal_printf("HAL: Cannot detect kernel modules.");
|
||||
hal_halt_cpu();
|
||||
}
|
||||
|
||||
// detect APIC
|
||||
cpuid_t cpuid_info;
|
||||
cpuid_info.eax = 1;
|
||||
|
|
|
@ -34,4 +34,14 @@ void NATIVE64 hal_set_interrupt_handler(uint64_t index, void (*handler)(void))
|
|||
{
|
||||
hal_write_gate(g_idt + 16*index, (uint64_t)handler, SEG_SELECTOR(1,0), GATE_DPL_0 | GATE_PRESENT | GATE_TYPE_INTERRUPT);
|
||||
return;
|
||||
}
|
||||
|
||||
void NATIVE64 hal_assert(int64_t expression, char* message)
|
||||
{
|
||||
if(!expression)
|
||||
{
|
||||
hal_printf("HAL: Assertion failed. Detail: %s", message == NULL ? "NULL" : message);
|
||||
}
|
||||
hal_halt_cpu();
|
||||
return;
|
||||
}
|
|
@ -24,5 +24,8 @@ extern void NATIVE64 hal_halt_cpu();
|
|||
|
||||
void NATIVE64 hal_write_gate(void *const gate, uint64_t const offset, uint32_t const selector, uint32_t const attr);
|
||||
|
||||
//assert
|
||||
void NATIVE64 hal_assert(int64_t exp, char* message);
|
||||
|
||||
extern uint8_t g_idt[];
|
||||
#endif
|
Loading…
Reference in New Issue