This commit is contained in:
Oscar 2017-03-09 18:50:35 -08:00
parent d0803c45bb
commit 188f570f9f
12 changed files with 52 additions and 38 deletions

View File

@ -40,7 +40,11 @@ extern void KABI hal_set_timer_timeout(uint64_t millis);
extern void KABI hal_halt_cpu(); extern void KABI hal_halt_cpu();
extern uint32_t KABI hal_get_current_core(); extern int32_t KABI hal_get_current_core();
extern void KABI hal_set_irql(irql_t irql);
extern irql_t KABI hal_get_irql();
extern void KABI hal_issue_interrupt(uint32_t core_id, uint32_t vector); extern void KABI hal_issue_interrupt(uint32_t core_id, uint32_t vector);

View File

@ -2,7 +2,7 @@
; Distributed under GPL license ; Distributed under GPL license
; See COPYING under root for details ; See COPYING under root for details
%include "hal_addr.inc" %include "addr.inc"
MULTIBOOT_TAG_ALIGNMENT equ 8 MULTIBOOT_TAG_ALIGNMENT equ 8
MULTIBOOT_HEADER_ALIGNMENT equ 8 MULTIBOOT_HEADER_ALIGNMENT equ 8

View File

@ -1,5 +1,5 @@
#include "intr.h" #include "intr.h"
#include "hal_arch.h" #include "arch.h"
#include "s_atomic.h" #include "s_atomic.h"
#include "s_boot.h" #include "s_boot.h"
#include "s_context.h" #include "s_context.h"
@ -28,11 +28,6 @@ irql_t KABI ke_set_irql(irql_t irql)
return old_irql; return old_irql;
} }
irql_t KABI ke_get_irql()
{
return (irql_t)hal_read_cr8();
}
void KABI ke_halt_cpu() void KABI ke_halt_cpu()
{ {
hal_halt_cpu(); hal_halt_cpu();

View File

@ -6,14 +6,14 @@
#include "print.h" #include "print.h"
#include "mem.h" #include "mem.h"
#include "intr.h" #include "intr.h"
#include "hal_arch.h" #include "arch.h"
#include "sxtdlib.h" #include "sxtdlib.h"
#include "s_boot.h" #include "s_boot.h"
extern char HAL_KERNEL_START_VADDR[]; extern char HAL_KERNEL_START_VADDR[];
extern char HAL_KERNEL_END_VADDR[]; extern char HAL_KERNEL_END_VADDR[];
static void KABI _hal_obtain_cpu_info(boot_info_t *hal_info) static void KABI halp_obtain_cpu_info(boot_info_t *hal_info)
{ {
if(hal_info == NULL) if(hal_info == NULL)
return; return;
@ -42,7 +42,7 @@ void KABI hal_main(void *m_info)
boot_info->krnl_end = (uint64_t)HAL_KERNEL_END_VADDR; boot_info->krnl_end = (uint64_t)HAL_KERNEL_END_VADDR;
// obtain cpu info // obtain cpu info
_hal_obtain_cpu_info(boot_info); halp_obtain_cpu_info(boot_info);
// init interrupt // init interrupt
if(hal_interrupt_init() != 0) if(hal_interrupt_init() != 0)

View File

@ -3,7 +3,7 @@
* See COPYING under root for details * See COPYING under root for details
*/ */
#include "hal_arch.h" #include "arch.h"
#include "intr.h" #include "intr.h"
#include "print.h" #include "print.h"
#include "mem.h" #include "mem.h"
@ -135,7 +135,7 @@ void KABI hal_exception_dispatcher(uint64_t exc_vec, hal_intr_context_t* context
return; return;
} }
static void KABI _hal_populate_idt() static void KABI halp_populate_idt()
{ {
hal_set_interrupt_handler(0, hal_interrupt_handler_0); hal_set_interrupt_handler(0, hal_interrupt_handler_0);
hal_set_interrupt_handler(1, hal_interrupt_handler_1); hal_set_interrupt_handler(1, hal_interrupt_handler_1);
@ -426,7 +426,7 @@ int32_t KABI hal_interrupt_init(void)
} }
// hook asm interrupt handlers // hook asm interrupt handlers
_hal_populate_idt(); halp_populate_idt();
hal_flush_idt(&_idt_ptrs[coreid]); hal_flush_idt(&_idt_ptrs[coreid]);

View File

@ -6,7 +6,7 @@
#include "g_type.h" #include "g_type.h"
#include "mem.h" #include "mem.h"
#include "salloc.h" #include "salloc.h"
#include "hal_arch.h" #include "arch.h"
#include "intr.h" #include "intr.h"
static uint8_t _gdts[HAL_CORE_COUNT][GDT_ENTRY_NUM * GDT_ENTRY_SIZE]; static uint8_t _gdts[HAL_CORE_COUNT][GDT_ENTRY_NUM * GDT_ENTRY_SIZE];

View File

@ -9,18 +9,18 @@
static uint64_t text_pos; static uint64_t text_pos;
void KABI hal_print_init() static void KABI hal_print_init()
{ {
text_pos = 0; text_pos = 0;
} }
void KABI _hal_print_scroll() static void KABI halp_print_scroll()
{ {
lb_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2); lb_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2);
return; return;
} }
void KABI _hal_print_str(char const *str) static void KABI halp_print_str(char const *str)
{ {
if(str == NULL) if(str == NULL)
return; return;
@ -32,7 +32,7 @@ void KABI _hal_print_str(char const *str)
if(text_pos > 80 * 25 - 1) if(text_pos > 80 * 25 - 1)
{ {
//can't hold //can't hold
_hal_print_scroll(); halp_print_scroll();
lb_mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row lb_mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row
text_pos = 80 * 24; text_pos = 80 * 24;
} }
@ -43,7 +43,7 @@ void KABI _hal_print_str(char const *str)
if (text_pos > 80 * 25 - 1) if (text_pos > 80 * 25 - 1)
{ {
//can't hold //can't hold
_hal_print_scroll(); halp_print_scroll();
text_pos = 80 * 24; text_pos = 80 * 24;
} }
*((char*)(0xb8000) + text_pos*2) = *str; *((char*)(0xb8000) + text_pos*2) = *str;
@ -55,7 +55,7 @@ void KABI _hal_print_str(char const *str)
return; return;
} }
void KABI _hal_print_uint(uint64_t number) static void KABI halp_print_uint(uint64_t number)
{ {
char arr[21]; // do not need to initialize char arr[21]; // do not need to initialize
arr[20] = 0; //zero-terminated arr[20] = 0; //zero-terminated
@ -70,11 +70,11 @@ void KABI _hal_print_uint(uint64_t number)
if (number == 0) if (number == 0)
break; break;
} }
_hal_print_str(&(arr[index + 1])); halp_print_str(&(arr[index + 1]));
return; return;
} }
void KABI _hal_print_int(int64_t number) static void KABI halp_print_int(int64_t number)
{ {
char arr[21]; // do not need to initialize char arr[21]; // do not need to initialize
arr[20] = 0; //zero-terminated arr[20] = 0; //zero-terminated
@ -99,11 +99,11 @@ void KABI _hal_print_int(int64_t number)
{ {
arr[index--] = '-'; arr[index--] = '-';
} }
_hal_print_str(&(arr[index + 1])); halp_print_str(&(arr[index + 1]));
return; return;
} }
void KABI _hal_print_hex(uint64_t number, uint64_t capital) static void KABI halp_print_hex(uint64_t number, uint64_t capital)
{ {
char const lookup_table_cap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char const lookup_table_cap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char const lookup_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; char const lookup_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
@ -121,7 +121,7 @@ void KABI _hal_print_hex(uint64_t number, uint64_t capital)
if (number == 0) if (number == 0)
break; break;
} }
_hal_print_str(&(arr[index + 1])); halp_print_str(&(arr[index + 1]));
return; return;
} }
@ -146,7 +146,7 @@ void KABI hal_printf(char const *format, ...)
if (*format != '%') if (*format != '%')
{ {
buf[0] = *format; buf[0] = *format;
_hal_print_str(buf); halp_print_str(buf);
continue; continue;
} }
format++; format++;
@ -154,36 +154,36 @@ void KABI hal_printf(char const *format, ...)
{ {
case 'd': case 'd':
d = va_arg(args, int64_t); d = va_arg(args, int64_t);
_hal_print_int(d); halp_print_int(d);
break; break;
case 'u': case 'u':
u = va_arg(args, uint64_t); u = va_arg(args, uint64_t);
_hal_print_uint(u); halp_print_uint(u);
break; break;
case 's': case 's':
s = va_arg(args, char *); s = va_arg(args, char *);
_hal_print_str(s); halp_print_str(s);
break; break;
case 'c': case 'c':
c = va_arg(args, int64_t); c = va_arg(args, int64_t);
buf[0] = c; buf[0] = c;
_hal_print_str(buf); halp_print_str(buf);
break; break;
case 'x': case 'x':
u = va_arg(args, uint64_t); u = va_arg(args, uint64_t);
_hal_print_hex(u, 0); halp_print_hex(u, 0);
break; break;
case 'X': case 'X':
u = va_arg(args, uint64_t); u = va_arg(args, uint64_t);
_hal_print_hex(u, 1); halp_print_hex(u, 1);
break; break;
case '%': case '%':
buf[0] = '%'; buf[0] = '%';
_hal_print_str(buf); halp_print_str(buf);
break; break;
default: default:
buf[0] = '%'; buf[0] = '%';
_hal_print_str(buf); halp_print_str(buf);
format--; format--;
break; break;
} }

View File

@ -9,4 +9,8 @@ irql_t KABI ke_raise_irql(irql_t irql);
irql_t KABI ke_lower_irql(irql_t irql); irql_t KABI ke_lower_irql(irql_t irql);
int KABI ke_get_current_core();
irql_t KABI ke_get_irql();
#endif #endif

View File

@ -4,11 +4,22 @@
irql_t KABI ke_raise_irql(irql_t irql) irql_t KABI ke_raise_irql(irql_t irql)
{ {
ke_assert(ke_get_irql() <= irql); ke_assert(ke_get_irql() <= irql);
return ke_set_irql(irql); return hal_set_irql(irql);
} }
irql_t KABI ke_lower_irql(irql_t irql) irql_t KABI ke_lower_irql(irql_t irql)
{ {
ke_assert(ke_get_irql() >= irql); irql_t old_irql = ke_get_irql();
return ke_set_irql(irql); ke_assert(old_irql >= irql);
return hal_set_irql(irql);
}
irql_t KABI ke_get_irql()
{
return hal_get_irql();
}
int KABI ke_get_current_core()
{
return hal_get_current_core();
} }