Refactoring started
This commit is contained in:
parent
813bc3de69
commit
d0803c45bb
@ -13,10 +13,14 @@
|
||||
|
||||
typedef int32_t (*callback_func_t)(void *kernel_args, void *user_args);
|
||||
|
||||
typedef uint32_t handle_t;
|
||||
|
||||
#define STRUCT_PACKED __attribute__((packed))
|
||||
|
||||
#define UNREFERENCED(x) {(x) = (x);}
|
||||
|
||||
#define _OUT
|
||||
#define _IN
|
||||
#define _IN_OUT
|
||||
#define _IN_OPT
|
||||
#define _OUT_OPT
|
||||
|
||||
#endif
|
12
x64/src/common/inc/kernel/ke/s_atomic.h
Normal file
12
x64/src/common/inc/kernel/ke/s_atomic.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _S_ATOMIC_H_
|
||||
#define _S_ATOMIC_H_
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
|
||||
extern int32_t KABI hal_interlocked_exchange_32(int32_t *target, int32_t val);
|
||||
|
||||
extern int32_t KABI hal_interlocked_increment_32(int32_t *target, int32_t increment);
|
||||
|
||||
extern int32_t KABI hal_interlocked_compare_exchange_32(int32_t *target, int32_t compare, int32_t val);
|
||||
|
||||
#endif
|
@ -4,6 +4,7 @@
|
||||
#include "g_abi.h"
|
||||
#include "s_pmm.h"
|
||||
#include "s_intr.h"
|
||||
#include "g_status.h"
|
||||
|
||||
//
|
||||
// HAL Boot Info
|
||||
@ -17,6 +18,7 @@ typedef struct
|
||||
char cpu_vd_str[13];
|
||||
} boot_info_t;
|
||||
|
||||
extern void KABI ke_main(boot_info_t *info);
|
||||
extern status_t KABI hal_init (_IN void* multiboot_info,
|
||||
_OUT boot_info_t** boot_info);
|
||||
|
||||
#endif
|
20
x64/src/common/inc/kernel/ke/s_context.h
Normal file
20
x64/src/common/inc/kernel/ke/s_context.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _S_CONTEXT_H_
|
||||
#define _S_CONTEXT_H_
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "s_vmm.h"
|
||||
#include "s_intr.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 KABI hal_context_switch(void *intr_stack,
|
||||
void *cur_context, void *next_context,
|
||||
physical_addr_t old_addr_space,
|
||||
physical_addr_t next_addr_space);
|
||||
|
||||
extern void KABI hal_create_context(void *context, void *pc, void *sp, void *ksp, irql_t irql, void *arg);
|
||||
|
||||
extern void KABI hal_destroy_context(void *context);
|
||||
|
||||
#endif
|
@ -24,33 +24,41 @@ typedef enum
|
||||
|
||||
// IRQL APIs
|
||||
typedef uint32_t irql_t;
|
||||
#define K_IRQL_DISABLED_LEVEL 15
|
||||
#define K_IRQL_DPC_LEVEL 4
|
||||
#define K_IRQL_APC_LEVEL 2
|
||||
#define K_IRQL_PASSIVE_LEVEL 0
|
||||
#define K_IRQL_DISABLED_LEVEL (1 << 3)
|
||||
#define K_IRQL_DPC_LEVEL (1 << 2)
|
||||
#define K_IRQL_APC_LEVEL (1 << 1)
|
||||
#define K_IRQL_PASSIVE_LEVEL (1 << 0)
|
||||
|
||||
extern irql_t KABI ke_set_irql(irql_t irql);
|
||||
//
|
||||
// interrupt functions
|
||||
//
|
||||
extern void KABI hal_disable_interrupt(uint32_t interrupts);
|
||||
|
||||
extern irql_t KABI ke_get_irql();
|
||||
extern void KABI hal_enable_interrupt(uint32_t interrupts);
|
||||
|
||||
extern void KABI ke_halt_cpu();
|
||||
extern void KABI hal_set_timer_timeout(uint64_t millis);
|
||||
|
||||
extern void KABI ke_set_timer_timeout(uint64_t timeout);
|
||||
extern void KABI hal_halt_cpu();
|
||||
|
||||
extern int32_t KABI ke_get_core_id();
|
||||
extern uint32_t KABI hal_get_current_core();
|
||||
|
||||
extern int32_t KABI ke_issue_interrupt(int32_t core_id, uint32_t vector);
|
||||
extern void KABI hal_issue_interrupt(uint32_t core_id, uint32_t vector);
|
||||
|
||||
//
|
||||
// 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 ( KABI *k_intr_handler_t)(void *context, void *intr_stack);
|
||||
|
||||
extern void KABI ke_register_intr_handler(uint32_t index, k_intr_handler_t handler, void *context);
|
||||
extern void KABI hal_register_intr_handler(uint32_t index, k_intr_handler_t handler, void *context);
|
||||
|
||||
extern k_intr_handler_t KABI ke_deregister_intr_handler(uint32_t index);
|
||||
extern k_intr_handler_t KABI hal_deregister_intr_handler(uint32_t index);
|
||||
|
||||
//
|
||||
// Exception handler registration
|
||||
//
|
||||
typedef void ( KABI *k_exc_handler_t)(uint64_t exc_addr, uint64_t exc_stack, uint64_t error_code);
|
||||
|
||||
extern void KABI ke_register_exc_handler(exc_type_t type, k_exc_handler_t handler);
|
9
x64/src/common/inc/kernel/ke/s_print.h
Normal file
9
x64/src/common/inc/kernel/ke/s_print.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _S_PRINT_H_
|
||||
#define _S_PRINT_H_
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
|
||||
extern void hal_printf(const char* str, ...);
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#ifndef _S_ATOMIC_H_
|
||||
#define _S_ATOMIC_H_
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
|
||||
extern int32_t KABI ke_interlocked_exchange_32(int32_t *target, int32_t val);
|
||||
|
||||
extern int32_t KABI ke_interlocked_increment_32(int32_t *target, int32_t increment);
|
||||
|
||||
extern int32_t KABI ke_interlocked_compare_exchange_32(int32_t *target, int32_t compare, int32_t val);
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
#ifndef _S_CONTEXT_H_
|
||||
#define _S_CONTEXT_H_
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "s_vmm.h"
|
||||
#include "s_intr.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 KABI ke_context_switch(void *intr_stack,
|
||||
void *cur_context, void *next_context,
|
||||
physical_addr_t old_addr_space,
|
||||
physical_addr_t next_addr_space);
|
||||
|
||||
extern void KABI ke_create_context(void *context, void *pc, void *sp, void *ksp, irql_t irql, void *arg);
|
||||
|
||||
extern void KABI ke_destroy_context(void *context);
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#ifndef _S_PRINT_H_
|
||||
#define _S_PRINT_H_
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
|
||||
//TODO: Get rid of this
|
||||
#include "hal_print.h"
|
||||
|
||||
#define ke_printf(x, ...) hal_printf(x, __VA_ARGS__)
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "hal_intr.h"
|
||||
#include "intr.h"
|
||||
#include "hal_arch.h"
|
||||
#include "s_atomic.h"
|
||||
#include "s_boot.h"
|
||||
|
@ -3,9 +3,9 @@
|
||||
* See COPYING under root for details
|
||||
*/
|
||||
|
||||
#include "hal_print.h"
|
||||
#include "hal_mem.h"
|
||||
#include "hal_intr.h"
|
||||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "intr.h"
|
||||
#include "hal_arch.h"
|
||||
#include "sxtdlib.h"
|
||||
#include "s_boot.h"
|
@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
#include "hal_arch.h"
|
||||
#include "hal_intr.h"
|
||||
#include "hal_print.h"
|
||||
#include "hal_mem.h"
|
||||
#include "intr.h"
|
||||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "sxtdlib.h"
|
||||
|
||||
static uint8_t _idts[HAL_CORE_COUNT][IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
|
@ -4,10 +4,10 @@
|
||||
*/
|
||||
#include "g_abi.h"
|
||||
#include "g_type.h"
|
||||
#include "hal_mem.h"
|
||||
#include "mem.h"
|
||||
#include "salloc.h"
|
||||
#include "hal_arch.h"
|
||||
#include "hal_intr.h"
|
||||
#include "intr.h"
|
||||
|
||||
static uint8_t _gdts[HAL_CORE_COUNT][GDT_ENTRY_NUM * GDT_ENTRY_SIZE];
|
||||
static hal_gdt_ptr_t _gdt_ptrs[HAL_CORE_COUNT];
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "g_abi.h"
|
||||
#include "sxtdlib.h"
|
||||
#include "hal_print.h"
|
||||
#include "print.h"
|
||||
|
||||
static uint64_t text_pos;
|
||||
|
17
x64/src/kernel/ke/atomic.c
Normal file
17
x64/src/kernel/ke/atomic.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "atomic.h"
|
||||
#include "s_atomic.h"
|
||||
|
||||
int32_t KABI ke_interlocked_exchange_32(int32_t *target, int32_t val)
|
||||
{
|
||||
return hal_interlocked_exchange_32(target, val);
|
||||
}
|
||||
|
||||
int32_t KABI ke_interlocked_increment_32(int32_t *target, int32_t increment)
|
||||
{
|
||||
return hal_interlocked_increment_32(target, increment);
|
||||
}
|
||||
|
||||
int32_t KABI ke_interlocked_compare_exchange_32(int32_t *target, int32_t compare, int32_t val)
|
||||
{
|
||||
return hal_interlocked_compare_exchange_32(target, compare, val);
|
||||
}
|
@ -3,15 +3,15 @@
|
||||
* See COPYING under root for details
|
||||
*/
|
||||
|
||||
#include "s_boot.h"
|
||||
#include "pmm.h"
|
||||
#include "boot.h"
|
||||
#include "alloc.h"
|
||||
#include "k_lib_test.h"
|
||||
|
||||
extern void KABI hal_printf(char const *, ...);
|
||||
|
||||
// returning from this function results in halting the cpu
|
||||
void KABI ke_main(boot_info_t *boot_info)
|
||||
void KABI ke_system_startup(void *boot_info)
|
||||
{
|
||||
if (boot_info == NULL)
|
||||
{
|
||||
|
@ -1,6 +1,13 @@
|
||||
#ifndef _ATOMIC_H_
|
||||
#define _ATOMIC_H_
|
||||
|
||||
#include "s_atomic.h"
|
||||
#include "g_type.h"
|
||||
#include "g_abi.h"
|
||||
|
||||
int32_t KABI ke_interlocked_exchange_32(int32_t *target, int32_t val);
|
||||
|
||||
int32_t KABI ke_interlocked_increment_32(int32_t *target, int32_t increment);
|
||||
|
||||
int32_t KABI ke_interlocked_compare_exchange_32(int32_t *target, int32_t compare, int32_t val);
|
||||
|
||||
#endif
|
@ -1,4 +0,0 @@
|
||||
#ifndef _BOOT_H_
|
||||
#define _BOOT_H_
|
||||
#include "s_boot.h"
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
#include "g_abi.h"
|
||||
#include "s_pmm.h"
|
||||
#include "atomic.h"
|
||||
#include "status.h"
|
||||
#include "g_status.h"
|
||||
|
||||
//#define PMM_PAGE_ATTR_FREE_BIT 0
|
||||
//#define PMM_PAGE_ATTR_PAGED_BIT 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "assert.h"
|
||||
#include "rwwlock.h"
|
||||
#include "status.h"
|
||||
#include "g_status.h"
|
||||
#include "alloc.h"
|
||||
#include "pmm.h"
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
#define _K_REF_H_
|
||||
|
||||
#include "g_type.h"
|
||||
#include "status.h"
|
||||
#include "g_status.h"
|
||||
|
||||
typedef uint32_t handle_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "hal_print.h"
|
||||
#include "print.h"
|
||||
#include "k_test_driver.h"
|
||||
#include "hal_mem.h"
|
||||
#include "mem.h"
|
||||
|
||||
#define GAT_SIZE 256
|
||||
#define CASE_NUM 32
|
||||
|
Loading…
x
Reference in New Issue
Block a user