|
@@ -1,6 +1,5 @@
|
|
|
#include "kernel_main.h"
|
|
|
|
|
|
-#include <types/types.h>
|
|
|
#include <asm/boot.h>
|
|
|
#include <asm/port_io.h>
|
|
|
#include <asm/sys.h>
|
|
@@ -14,7 +13,10 @@
|
|
|
#include <kernel/task.h>
|
|
|
#include <kernel/tty.h>
|
|
|
#include <kernel/vga.h>
|
|
|
+#include <types/assert.h>
|
|
|
#include <types/bitmap.h>
|
|
|
+#include <types/status.h>
|
|
|
+#include <types/types.h>
|
|
|
|
|
|
#define KERNEL_MAIN_BUF_SIZE (128)
|
|
|
|
|
@@ -28,26 +30,6 @@ struct tty* console = NULL;
|
|
|
#define INIT_OK() printkf("ok\n")
|
|
|
#define INIT_FAILED() printkf("failed\n")
|
|
|
|
|
|
-static inline void check_a20_status(void)
|
|
|
-{
|
|
|
- uint32_t result;
|
|
|
- result = check_a20_on();
|
|
|
-
|
|
|
- if (result) {
|
|
|
- tty_print(console, "a20 is on");
|
|
|
- } else {
|
|
|
- tty_print(console, "a20 is NOT on");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static inline void halt_on_init_error(void)
|
|
|
-{
|
|
|
- MAKE_BREAK_POINT();
|
|
|
- asm_cli();
|
|
|
- while (1)
|
|
|
- asm_hlt();
|
|
|
-}
|
|
|
-
|
|
|
typedef void (*constructor)(void);
|
|
|
extern constructor start_ctors;
|
|
|
extern constructor end_ctors;
|
|
@@ -148,7 +130,8 @@ extern void NORETURN init_scheduler();
|
|
|
|
|
|
void NORETURN kernel_main(void)
|
|
|
{
|
|
|
- // MAKE_BREAK_POINT();
|
|
|
+ assert(check_a20_on());
|
|
|
+
|
|
|
asm_enable_sse();
|
|
|
|
|
|
init_bss_section();
|
|
@@ -157,13 +140,10 @@ void NORETURN kernel_main(void)
|
|
|
|
|
|
load_new_gdt();
|
|
|
|
|
|
- char buf[KERNEL_MAIN_BUF_SIZE];
|
|
|
-
|
|
|
- init_serial_port(PORT_SERIAL0);
|
|
|
+ char buf[KERNEL_MAIN_BUF_SIZE] = { 0 };
|
|
|
|
|
|
- if (make_serial_tty(&early_console, PORT_SERIAL0) != GB_OK) {
|
|
|
- halt_on_init_error();
|
|
|
- }
|
|
|
+ assert(init_serial_port(PORT_SERIAL0) == GB_OK);
|
|
|
+ assert(make_serial_tty(&early_console, PORT_SERIAL0) == GB_OK);
|
|
|
console = &early_console;
|
|
|
|
|
|
show_mem_info(buf);
|
|
@@ -194,8 +174,6 @@ void NORETURN kernel_main(void)
|
|
|
tty_print(console, k_malloc_buf);
|
|
|
k_free(k_malloc_buf);
|
|
|
|
|
|
- k_malloc_buf[4096] = '\x89';
|
|
|
-
|
|
|
init_vfs();
|
|
|
|
|
|
printkf("switching execution to the scheduler...\n");
|
|
@@ -204,9 +182,21 @@ void NORETURN kernel_main(void)
|
|
|
|
|
|
void NORETURN __stack_chk_fail(void)
|
|
|
{
|
|
|
- tty_print(console, "***** stack smashing detected! *****\nhalting\n");
|
|
|
- for (;;) {
|
|
|
- asm_cli();
|
|
|
- asm_hlt();
|
|
|
- }
|
|
|
+ tty_print(console, "***** stack smashing detected! *****\n");
|
|
|
+ for (;;)
|
|
|
+ assert(0);
|
|
|
+}
|
|
|
+
|
|
|
+void crash(void)
|
|
|
+{
|
|
|
+ asm volatile("ud2");
|
|
|
+}
|
|
|
+
|
|
|
+void _debugger_breakpoint(void)
|
|
|
+{
|
|
|
+#ifdef __BOCHS_SYSTEM__
|
|
|
+ asm volatile("xchgw %%bx, %%bx");
|
|
|
+#else
|
|
|
+ asm volatile("nop");
|
|
|
+#endif
|
|
|
}
|