Keep it up
This commit is contained in:
parent
86c042c927
commit
af7401a7ed
7
x64/src/common/inc/kernel/s_atomic.h
Normal file
7
x64/src/common/inc/kernel/s_atomic.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _S_ATOMIC_H_
|
||||
#define _S_ATOMIC_H_
|
||||
#include "s_def.h"
|
||||
|
||||
extern uint64_t KAPI k_interlocked_exchange(uint64_t* target, uint64_t val);
|
||||
|
||||
#endif
|
@ -2,10 +2,17 @@
|
||||
#define _S_CONTEXT_H_
|
||||
|
||||
#include "s_def.h"
|
||||
#include "s_vmm.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);
|
||||
extern void KAPI k_context_switch(void *intr_stack,
|
||||
void *cur_context, void *next_context,
|
||||
k_address_space_t old_addr_space, k_address_space_t next_addr_space);
|
||||
|
||||
extern void KAPI k_create_context(void *context, void *pc, void *sp);
|
||||
|
||||
extern void KAPI k_destroy_context(void* context);
|
||||
|
||||
#endif
|
@ -1,63 +0,0 @@
|
||||
/* Copyright 2016 secXsQuared
|
||||
* Distributed under GPL license
|
||||
* See COPYING under root for details
|
||||
*/
|
||||
|
||||
|
||||
/* This file should be only be included by kernel c source files
|
||||
* and never any other files
|
||||
*/
|
||||
|
||||
#ifndef _S_HAL_H_
|
||||
#define _S_HAL_H_
|
||||
|
||||
#include "s_def.h"
|
||||
#include "s_type.h"
|
||||
#include "linked_list.h"
|
||||
#include "s_intr.h"
|
||||
#include "s_boot.h"
|
||||
|
||||
//
|
||||
// HAL Initialization API
|
||||
//
|
||||
extern int32_t KAPI hal_init(void *multiboot_info, k_boot_info_t *boot_info);
|
||||
|
||||
//
|
||||
// Interrupt APIs
|
||||
//
|
||||
extern void KAPI hal_enable_interrupt();
|
||||
|
||||
extern void KAPI hal_disable_interrupt();
|
||||
|
||||
extern void KAPI hal_set_interrupt_priority(uint64_t priority);
|
||||
|
||||
extern uint64_t KAPI hal_read_interrupt_priority();
|
||||
|
||||
extern int32_t KAPI hal_register_interrupt_handler(k_handler_type_t type,
|
||||
uint64_t priority,
|
||||
void (*handler)(uint64_t pc,
|
||||
uint64_t sp,
|
||||
uint64_t error));
|
||||
|
||||
extern void KAPI hal_deregister_interrupt_handler(int32_t index);
|
||||
|
||||
|
||||
extern void KAPI hal_issue_interrupt(uint32_t target_core, uint32_t vector);
|
||||
|
||||
//
|
||||
// HAL Atomic
|
||||
//
|
||||
extern uint64_t KAPI hal_interlocked_exchange(uint64_t *dst, uint64_t val);
|
||||
|
||||
//
|
||||
// HAL Arch API
|
||||
//
|
||||
extern void KAPI hal_halt_cpu(void);
|
||||
|
||||
//
|
||||
// HAL Print
|
||||
//
|
||||
extern void KAPI hal_clear_screen(void);
|
||||
extern void KAPI hal_printf(char const *format, ...);
|
||||
|
||||
#endif
|
@ -37,12 +37,12 @@ void KAPI hal_write_gate(void *const gate,
|
||||
|
||||
void KAPI hal_set_interrupt_priority(uint64_t priority)
|
||||
{
|
||||
hal_write_cr8(priority & bit_field_mask_32(0,3));
|
||||
hal_write_cr8(priority & bit_field_mask(0,3));
|
||||
}
|
||||
|
||||
uint64_t KAPI hal_read_interrupt_priority()
|
||||
{
|
||||
return (uint64_t)hal_read_cr8() & bit_field_mask_32(0,3);
|
||||
return (uint64_t)hal_read_cr8() & bit_field_mask(0,3);
|
||||
}
|
||||
|
||||
void KAPI hal_set_interrupt_handler(uint64_t index,
|
||||
@ -61,21 +61,17 @@ void KAPI hal_issue_interrupt(uint32_t target_core, uint32_t vector)
|
||||
// TODO
|
||||
}
|
||||
|
||||
int32_t KAPI hal_register_interrupt_handler(k_handler_type_t type,
|
||||
uint32_t priority,
|
||||
void (*handler)(uint64_t pc,
|
||||
uint64_t sp,
|
||||
uint64_t error))
|
||||
void KAPI hal_register_interrupt_handler(uint32_t index, k_intr_handler_t handler, void* context)
|
||||
{
|
||||
if (type == K_INTR_SOFTWARE)
|
||||
if (index < IDT_ENTRY_NUM && index >= 0)
|
||||
{
|
||||
// TODO
|
||||
g_intr_handler_table[0] = handler;
|
||||
g_intr_handler_table[index] = handler;
|
||||
g_intr_handler_context_table[index] = handler;
|
||||
}
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void KAPI hal_deregister_interrupt_handler(int32_t index)
|
||||
void KAPI hal_deregister_interrupt_handler(uint32_t index)
|
||||
{
|
||||
if (index < IDT_ENTRY_NUM && index >= 0)
|
||||
{
|
||||
@ -84,6 +80,24 @@ void KAPI hal_deregister_interrupt_handler(int32_t index)
|
||||
return;
|
||||
}
|
||||
|
||||
void KAPI hal_register_exception_handler(uint32_t index, k_exc_handler_t handler)
|
||||
{
|
||||
if (index < IDT_ENTRY_NUM && index >= 0)
|
||||
{
|
||||
g_exc_handler_table[index] = handler;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void KAPI hal_deregister_exception_handler(uint32_t index)
|
||||
{
|
||||
if (index < IDT_ENTRY_NUM && index >= 0)
|
||||
{
|
||||
g_exc_handler_table[index] = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void KAPI hal_assert(int64_t expression,
|
||||
char *message)
|
||||
{
|
||||
|
11
x64/src/hal/hal_k_impl.c
Normal file
11
x64/src/hal/hal_k_impl.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include "hal_arch.h"
|
||||
#include "s_atomic.h"
|
||||
#include "s_boot.h"
|
||||
#include "s_context.h"
|
||||
#include "s_intr.h"
|
||||
#include "s_vmm.h"
|
||||
|
||||
uint64_t KAPI k_interlocked_exchange(uint64_t* target, uint64_t val)
|
||||
{
|
||||
return hal_interlocked_exchange(target, val);
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
|
||||
uint8_t g_gdt[GDT_ENTRY_NUM*GDT_ENTRY_SIZE];
|
||||
uint8_t g_idt[IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
|
||||
void (*g_intr_handler_table[IDT_ENTRY_NUM])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
k_intr_handler_t g_intr_handler_table[IDT_ENTRY_NUM];
|
||||
k_exc_handler_t g_exc_handler_table[IDT_ENTRY_NUM];
|
||||
hal_gdt_ptr_t g_gdt_ptr;
|
||||
hal_idt_ptr_t g_idt_ptr;
|
||||
uint64_t text_pos;
|
@ -17,6 +17,8 @@ typedef struct
|
||||
|
||||
extern uint64_t KAPI hal_interlocked_exchange(uint64_t *dst, uint64_t val);
|
||||
|
||||
extern uint64_t KAPI hal_interlocked_compare_exchange(uint64_t *dst, uint64_t val, uint64_t compare);
|
||||
|
||||
extern void KAPI hal_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
|
||||
|
||||
#define MSR_IA32_APIC_BASE 0x1B
|
||||
|
@ -554,13 +554,9 @@ extern void KAPI hal_interrupt_handler_254(void);
|
||||
|
||||
extern void KAPI hal_interrupt_handler_255(void);
|
||||
|
||||
int32_t KAPI hal_register_interrupt_handler(k_handler_type_t type,
|
||||
uint32_t priority,
|
||||
void (*handler)(uint64_t pc,
|
||||
uint64_t sp,
|
||||
uint64_t error));
|
||||
void KAPI hal_register_interrupt_handler(uint32_t index, k_intr_handler_t handler, void* context);
|
||||
|
||||
void KAPI hal_deregister_interrupt_handler(int32_t index);
|
||||
void KAPI hal_deregister_interrupt_handler(uint32_t index);
|
||||
|
||||
void KAPI hal_issue_interrupt(uint32_t target_core, uint32_t vector);
|
||||
|
||||
|
@ -13,7 +13,9 @@
|
||||
|
||||
extern uint8_t g_gdt[GDT_ENTRY_NUM*GDT_ENTRY_SIZE];
|
||||
extern uint8_t g_idt[IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
|
||||
extern void (*g_intr_handler_table[IDT_ENTRY_NUM])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
extern k_intr_handler_t g_intr_handler_table[IDT_ENTRY_NUM];
|
||||
extern void* g_intr_handler_context_table[IDT_ENTRY_NUM];
|
||||
extern k_exc_handler_t g_exc_handler_table[IDT_ENTRY_NUM];
|
||||
extern hal_gdt_ptr_t g_gdt_ptr;
|
||||
extern hal_idt_ptr_t g_idt_ptr;
|
||||
extern uint64_t text_pos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user