This commit is contained in:
julianb0 2019-08-06 23:21:37 +02:00
parent 59fbf66cfe
commit b890d67ff4
No known key found for this signature in database
GPG Key ID: 9C7ACF0C053FB8A1
7 changed files with 66 additions and 16 deletions

View File

@ -239,6 +239,7 @@ def parse():
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
escape_dict = { escape_dict = {
'0': '\0',
'n': '\n', 'n': '\n',
't': '\t', 't': '\t',
'r': '\r', 'r': '\r',

View File

@ -40,9 +40,10 @@ include "sys/drv/cpudev.k"
include "sys/drv/memdev.k" include "sys/drv/memdev.k"
include "sys/drv/diskdev.k" include "sys/drv/diskdev.k"
include "sys/intr/excepts.k"
include "sys/intr/common.k" include "sys/intr/common.k"
include "sys/intr/trap0.k" include "sys/intr/trap0.k"
include "sys/main.k"
include "sys/dumprf.k" include "sys/dumprf.k"
include "sys/main.k"

View File

@ -2,7 +2,7 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
TrapHandlers.prolog: TrapHandlers.prolog:
mov rbp, rsp mov rbp, zero
; rax = caller's cr2 ; rax = caller's cr2
call RFS.LoadReg, r14, $cr2 call RFS.LoadReg, r14, $cr2
@ -34,7 +34,9 @@ ScreenOfDeath:
prn PRN_CLEAR prn PRN_CLEAR
prn PRN_FLUSH prn PRN_FLUSH
call print, .scr1 push ax1
call printf, .scr1
pop zero
b.nz r14, zero, .not_con b.nz r14, zero, .not_con
push .scr2_con push .scr2_con
@ -66,15 +68,15 @@ ScreenOfDeath:
scan rax scan rax
jmp.axz .loop jmp.axz .loop
b.z rax, 0x0A, trap0_handler.handle_Exit b.z rax, 0x0A, DefaultTrapHandler.handle_Exit
b.z rax, 0x1B, trap0_handler.handle_Shutdown b.z rax, 0x1B, DefaultTrapHandler.handle_Shutdown
jmp .loop jmp .loop
crash crash
.scr1 = "-------- Unhandled EXCEPTION, TRAP/SYSCALL or INTERRUPT\n" .scr1 = "-------- Unhandled EXCEPTION, TRAP/SYSCALL or INTERRUPT (code %d)\n"
.scr2 = "Offense description: %s\nOffending frame: %d (%s)\n\n" .scr2 = "Description: %s\nFrame: %d (%s)\n\n"
.scr3 = "Press:\n ENTER to procede to COMMAND.COM\n ESCAPE to shutdown machine\n\n" .scr3 = "Press:\n ENTER to procede to COMMAND.COM\n ESCAPE to shutdown machine\n\n"
.scr2_con = "dedicated command.com frame" .scr2_con = "dedicated command.com frame"

29
ka/sys/intr/excepts.k Normal file
View File

@ -0,0 +1,29 @@
; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
DefaultExceptionHandler:
mov rsp, EXCT0_STACK
mov ax1, r12
b.z r12, zero, DefaultTrapHandler.handle_Shutdown
b.a r12, 11, .unknown
mov rsi, .err_ukn
lea ax0, b[rsi + r12 * 32]
call ScreenOfDeath
.unknown:
call ScreenOfDeath, .err_ukn
crash
.err_ukn = "Unknown exception number\0\0\0\0\0\0\0"
.err_udf = "Undefined behaviour exception\0\0"
.err_ill = "Ill-formed exception exception\0"
.err_acc = "Invalid memory access exception"
.err_sys = "Supervisor-only exception used\0"
.err_dbf = "Double fault exception~~~~~~~~\0"
.err_imp = "Feat. not implemented exception"
.err_ali = "Misalignmed address exception\0\0"
.err_brk = "BREAK key (Ctrl+C) exception\0\0\0"
.err_ovf = "Overflow flag raised exception\0"
.err_div = "Division by zero exception\0\0\0\0\0"

View File

@ -1,7 +1,7 @@
; The OS/K Team licenses this file to you under the MIT license. ; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
trap0_handler: DefaultTrapHandler:
.init: .init:
mov rcx, .text mov rcx, .text
@ -23,7 +23,7 @@ trap0_handler:
b.z rax, Sys.FindFirst, .handle_FindFirst b.z rax, Sys.FindFirst, .handle_FindFirst
b.z rax, Sys.EnterHaltMode, .handle_HaltMode b.z rax, Sys.EnterHaltMode, .handle_HaltMode
call ScreenOfDeath, .badsyscall call ScreenOfDeath, .badsyscall, r13
.fini.savecx: .fini.savecx:
mov ax2, rcx mov ax2, rcx
@ -83,7 +83,7 @@ trap0_handler:
call RFS.StoreReg, zero, $cr2 call RFS.StoreReg, zero, $cr2
; Return frame ; Return frame
mov q[rbp-16], zero mov r14, zero
jmp .fini jmp .fini
@ -130,6 +130,9 @@ trap0_handler:
; Misc. ; Misc.
; ;
.handle_Shutdown: .handle_Shutdown:
mov ax0, zero
call IDT.DelHandler
stop stop
.handle_HaltMode: .handle_HaltMode:

View File

@ -12,20 +12,30 @@ PrintBootMsg:
; ;
InitSyscalls: InitSyscalls:
mov ax0, 1 mov ax0, 1
.prepare_next:
call RFS.ActivateFrame call RFS.ActivateFrame
mov ax1, $rip mov ax1, $rip
mov ax2, trap0_handler mov ax2, DefaultTrapHandler
call RFS.StoreReg call RFS.StoreReg
mov ax1, ax0 mov ax0, 256
inc ax0, 255 # TRAP no. (ax0 - 1) mov ax1, 1
call IDT.AddHandler call IDT.AddHandler
ret ret
InitExcepts:
mov ax0, 2
call RFS.ActivateFrame
mov ax1, $rip
mov ax2, DefaultExceptionHandler
call RFS.StoreReg
mov ax0, zero
mov ax1, 2
call IDT.AddHandler
SwitchToCMD: SwitchToCMD:
mov rax, Sys.Exit mov rax, Sys.Exit
trap 0 trap 0
@ -36,6 +46,7 @@ SwitchToCMD:
main: main:
call PrintBootMsg call PrintBootMsg
call InitSyscalls call InitSyscalls
call InitExcepts
call SwitchToCMD call SwitchToCMD
ret ret

View File

@ -40,6 +40,9 @@ main:
scan rax scan rax
jmp.axz .input_loop jmp.axz .input_loop
; ESC key pressed?
b.z rax, 0x1B, .handle_EXIT
; backspace character? ; backspace character?
b.nz rax, 8, .handle_input b.nz rax, 8, .handle_input