From 2114741766f1c13f40d86d1c845627e033a837d0 Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Thu, 2 Feb 2023 18:15:14 -0600 Subject: [PATCH] Might? have fixed one race condition bug. Still crashing for unknown reasons on my laptop rarely --- fault.nasm | 21 +++++++++++++++++++-- kernel.c | 26 ++++++++++++++++++-------- usermode.nasm | 3 +++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/fault.nasm b/fault.nasm index 4f580ce..ee8fd84 100644 --- a/fault.nasm +++ b/fault.nasm @@ -6,8 +6,8 @@ _fault_coda: xchg bx,bx mov ax, 0x10 mov es, ax -; move to TOP OF kernel stack -mov ebp, 0x400000 +; move to 'safe' location +mov ebp, 0x318000 mov esp, ebp call error_environment .hlt: @@ -17,13 +17,30 @@ jmp .hlt extern gpf_handler_v86 global gpfHandler gpfHandler: +cli ; make sure we're in a 'friendly' env push eax push ebx +push ecx +; save old ds mov bx, ds mov ax, 0x10 mov ds, ax mov word [_gpf_old_ds], bx +; relocate stack so other interrupts don't fuck us over +; not sure if this is necessary, it doesn't seem to fix our race conditions... +mov ebx, esp +sub esp, 0x1000 +xor ecx, ecx +.l: +mov eax, [ebx] +mov [esp+ecx], eax +add ebx, 4 +add ecx, 4 +cmp ebx, 0x320000 ; tss esp0 +jl .l +pop ecx pop ebx +sti ; we shouldn't crash now? mov eax, dword [esp+16] ; EFLAGS and eax, 1 << 17 ; VM flag test eax, eax diff --git a/kernel.c b/kernel.c index b884222..5e3f6d1 100644 --- a/kernel.c +++ b/kernel.c @@ -112,7 +112,7 @@ void error_environment() { for (int i = 0; i < 80*50; i++) vga_text[i] = error_screen[i]; uint8_t key; - for (key = get_key(); key != 'e' && key != 'E'; key = get_key()); + while (key = get_key(), key != 'e' && key != 'E'); v86_entry = i386LinearToFp(v86TransFlag); enter_v86(0x8000, 0xFF00, FP_SEG(v86_entry), FP_OFF(v86_entry), ®s); } @@ -311,12 +311,22 @@ void start() { kbd_wait(); vga_text = &((uint16_t*)0xB8000)[80*16]; - vga_text += printStr("Press ` for a flagrant system error... ", vga_text); - while ((key = get_key()) != '`') { - *vga_text = (*vga_text & 0xFF00) | key; - vga_text++; - } - // flagrant system error - *((uint8_t*)0x1000000) = 0; + vga_text += printStr("Press E for a flagrant system error. Press C to continue... ", vga_text); + for (char l = 1;l;) { switch (key = get_key()) { + case 'e': + case 'E': + // flagrant system error + *((uint8_t*)0x1000000) = 0; + break; + case 'c': + case 'C': + // continue + l = 0; + break; + default: + *vga_text = (*vga_text & 0xFF00) | key; + vga_text++; + break; + }} } diff --git a/usermode.nasm b/usermode.nasm index 00a6b64..72316c3 100644 --- a/usermode.nasm +++ b/usermode.nasm @@ -26,6 +26,9 @@ inc al cmp eax, 200 jl .loop mov eax, 0xA0000 +;mov ecx, 1000000000 +;.dbg: +;loop .dbg int 0x30 ; Exit mov edx, 0x105000 ; somewhere in kernel mem mov edx, [edx] ; should page fault