Implementing H-K interface according to the wiki.

This commit is contained in:
secXsQuared 2016-06-22 21:50:29 -07:00
parent 59bac9bf2c
commit 6a971cc650
7 changed files with 106 additions and 22 deletions

View File

@ -2,20 +2,14 @@
#define _S_BOOT_H_
#include "s_def.h"
//
// Boot Info
// HAL Boot Info
//
typedef struct
{
uint32_t priority_low;
uint32_t priority_high;
} k_boot_intr_info_t;
typedef struct
{
uint64_t krnl_start;
uint64_t krnl_end;
k_boot_intr_info_t intr_info;
k_hal_intr_info_t intr_info;
char cpu_vd_str[13];
} k_boot_info_t;
} k_hal_boot_info_t;
#endif

View File

@ -0,0 +1,11 @@
#ifndef _S_CONTEXT_H_
#define _S_CONTEXT_H_
#include "s_def.h"
// This function should never return and directly context switches to the target
// on x86, it should save the context, switch stack, build exc frame and iret
// This function always assumes interrupt context
extern void KAPI k_context_switch(void* intr_stack, void* cur_context, void* next_context);
#endif

View File

@ -1,16 +1,41 @@
#ifndef _S_INTR_H_
#define _S_INTR_H_
typedef enum
#include "s_def.h"
typedef struct
{
K_INTR_TIMER,
K_INTR_IO,
K_INTR_SOFTWARE,
K_INTR_NMI,
K_EXC_DIV_BY_ZERO,
K_EXC_MEM_ACCESS,
K_EXC_INV_OP,
K_EXC_GP
} k_handler_type_t;
uint32_t timer_intr_vec;
uint32_t apc_intr_vec;
uint32_t dpc_intr_vec;
uint32_t div_by_zero_exc_vec;
uint32_t general_protection_exc_vec;
uint32_t invalid_op_exc_vec;
uint32_t page_fault_exc_vec;
} k_hal_intr_info_t;
// IRQL APIs
typedef uint64_t k_irql_t;
#define K_IRQL_HIGH 4
#define K_IRQL_IO 3
#define K_IRQL_DPC 2
#define K_IRQL_APC 1
#define K_IRQL_LOW 0
extern KAPI k_irql_t k_raise_irql(k_irql_t irql);
extern KAPI k_irql_t k_lower_irql(k_irql_t irql);
extern KAPI k_irql_t k_get_irql();
// Interrupt handler registration
// context is a parameter passed by the kernel. HAL must pass back.
// intr_stack is a parameter passed by the HAL. Used by some HAL interrupt context functions.
typedef void (*k_intr_handler_t)(void* context, void* intr_stack);
extern void KAPI k_register_intr_handler(uint32_t index, k_intr_handler_t handler);
extern k_intr_handler_t KAPI k_deregister_intr_handler(uint32_t index);
// Exception handler registration
typedef void (*k_exc_handler_t)(uint64_t exc_addr, uint64_t exc_stack, uint64_t error_code);
extern void KAPI k_register_exc_handler(uint64_t index, k_exc_handler_t handler);
extern k_exc_handler_t KAPI k_deregister_exc_handler(uint64_t index);
#endif

View File

@ -0,0 +1,31 @@
#ifndef _S_MEM_H_
#define _S_MEM_H_
#include "s_def.h"
#define K_PAGE_SIZE 4096
typedef struct
{
// the kernel always reserves this much virtual space from the highest vaddr
// this is mainly used for recursive page tables
uint64_t reserved_v_addr_space;
} k_hal_vmm_info;
typedef void*(*k_map_virtual_addr_alloc)();
typedef uint64_t k_address_space_t;
// the alloc function returns the physical address of a page
// NULL = no available physical page
void k_map_virtual_addr(k_address_space_t addr_space, uint64_t v_addr, uint64_t p_addr, k_map_virtual_addr_alloc alloc);
// this function always returns the physical address (x86) or whatever makes sense to the HAL
// the whole virtual address should be unmapped except for the reserved virtual space.
// HAL maps it however it wants
k_address_space_t k_create_virtual_addr_space();
void k_destroy_virtual_addr_space(k_address_space_t addr_space);
// this function gives the context of a process and the HAL returns its address space
k_address_space_t k_get_addr_space(void* context);
#endif

View File

@ -54,10 +54,10 @@ static void KAPI _hal_init_gdt()
hal_flush_gdt(&g_gdt_ptr, seg_selector(1, 0), seg_selector(2, 0));
};
int32_t KAPI hal_init(void *m_info, k_boot_info_t* boot_info)
void KAPI hal_init(void *m_info)
{
if (m_info == NULL || boot_info == NULL || (uint64_t) m_info & bit_field_mask_64(0, 2))
return 1;
if (m_info == NULL || (uint64_t) m_info & bit_field_mask(0, 2))
return;
text_pos = get_pos(0, 0);
@ -67,6 +67,8 @@ int32_t KAPI hal_init(void *m_info, k_boot_info_t* boot_info)
// set up HAL heap;
hal_alloc_init();
k_boot_info_t* boot_info = halloc(sizeof(k_boot_info_t));
// set up HAL def
boot_info->krnl_start = (uint64_t)kernel_start;
boot_info->krnl_end = (uint64_t)kernel_end;

View File

@ -0,0 +1 @@
#include "s_def.h"

20
x64/src/kernel/k_pmm.c Normal file
View File

@ -0,0 +1,20 @@
#include "k_pmm.h"
static uint64_t top_of_stack;
static _Bool _PMM_INITIALZIED = false;
void KAPI k_pmm_init()
{
}
uint64_t KAPI k_alloc_page()
{
}
uint64_t KAPI k_free_page()
{
}