]> pd.if.org Git - mmurtl/commitdiff
autocommit for file dated 1995-01-17 09:35:42
authorRichard Burgess <>
Tue, 17 Jan 1995 09:35:42 +0000 (09:35 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 17 Oct 2016 14:03:47 +0000 (14:03 +0000)
ossource/except.asm [new file with mode: 0644]

diff --git a/ossource/except.asm b/ossource/except.asm
new file mode 100644 (file)
index 0000000..d1d822d
--- /dev/null
@@ -0,0 +1,238 @@
+;   MMURTL Operating System Source Code\r
+;   Copyright 1991,1992,1993,1994 Richard A. Burgess\r
+;   ALL RIGHTS RESERVED\r
+;   Version 1.0\r
+.DATA\r
+.INCLUDE MOSEDF.INC\r
+.INCLUDE TSS.INC\r
+.INCLUDE JOB.INC\r
+\r
+EXTRN DbgpTSSSave DD\r
+EXTRN dbgFAULT   DD\r
+EXTRN dbgFltErc          DD\r
+EXTRN dbgOldEIP          DD\r
+EXTRN dbgOldCS   DD\r
+EXTRN dbgOldEFlgs DD\r
+\r
+EXTRN DbgTSS     DB\r
+EXTRN pRunTSS    DD\r
+\r
+.CODE\r
+\r
+;This file contains Exception Handlers and Debugger Entry\r
+;and Exit code.\r
+\r
+;=============================================================================\r
+; Procedure jumped to by interrupt procedures to enter debugger\r
+;=============================================================================\r
+;EnterDebug\r
+;\r
+; This piece of code sets up to enter the debugger.  If we get here,\r
+; one of the exceptions has activated and has done a little work based\r
+; on which exception is was, then it jumped here to enter the debugger.\r
+; This code effectively replaces the interrupted task with the debugger\r
+; task (without going through the kernel).  First we copy the Page Dir\r
+; entry from the current job into the debuggers job, then copy the CR3\r
+; register from the current TSS into the debugger's TSS.  This makes the\r
+; debugger operate in the current tasks memory space.  All of the debugger's\r
+; code and data are in OS protected pages (which are shared with all tasks),\r
+; so this is OK to do even if the offending task referenced a bogus address.\r
+; Next, we save the current pRunTSS and place the debugger's TSS in\r
+; pRunTSS, then jump to the debugger's selector.  This switches tasks.\r
+;\r
+EnterDebug:\r
+               PUSH EAX                                        ;we MUST save caller's registers\r
+               PUSH EBX                                        ; and restore them before the\r
+               PUSH EDX                                        ; task switch into the debugger\r
+\r
+               MOV EAX, pRunTSS                        ;pRunTSS -> EAX\r
+               MOV EBX, [EAX+TSS_CR3]          ;current CR3 -> EBX\r
+               MOV EDX, OFFSET DbgTSS          ;pDebuggerTSS -> EDX\r
+               MOV [EDX+TSS_CR3], EBX          ;CR3 -> DebuggerTSS\r
+\r
+               MOV EAX, [EAX+TSS_pJCB]         ;pCrntJCB -> EAX\r
+               MOV EDX, [EDX+TSS_pJCB]         ;pDebuggerJCB -> EDX\r
+               MOV EBX, [EAX+JcbPD]            ;CrntJob Page Dir -> EBX\r
+               MOV [EDX+JcbPD], EBX            ;Page Dir -> Debugger JCB\r
+\r
+               MOV EAX, pRunTSS                        ;Save the current pRunTSS\r
+               MOV DbgpTSSSave, EAX\r
+               MOV EAX, OFFSET DbgTSS          ;Install Debugger's as current\r
+               MOV pRunTSS, EAX                        ;Set Dbgr as running task\r
+\r
+               MOV BX, [EAX+Tid]\r
+        MOV TSS_Sel, BX                                ;Set up debugger selector\r
+\r
+               POP EDX                                         ;make his registers right!\r
+               POP EBX\r
+               POP EAX\r
+\r
+        JMP FWORD PTR [TSS]                    ;Switch tasks to debugger\r
+\r
+               ;When the debugger exits, we come here\r
+\r
+               PUSH dbgOldEFlgs                        ;Put the stack back the way it was\r
+               PUSH dbgOldCS                           ;\r
+               PUSH dbgOldEIP                          ;\r
+               IRETD                                           ;Go back to the caller\r
+\r
+;=============================================================================\r
+; INTERRUPT PROCEDURES FOR FAULTS\r
+;=============================================================================\r
+; This is the general purpose "We didn't expect this interrupt" interrupt\r
+; This will place "99" in the upper left corner of the screen so we\r
+; can see there are SPURIOUS interrupts!!!!!\r
+\r
+PUBLIC INTQ:\r
+               PUSH EAX\r
+               MOV EAX,07390739h       ;99 - All unassigned ints come here\r
+               MOV DS:VGATextBase+00h,EAX\r
+               POP EAX\r
+               IRETD\r
+\r
+;===================== Divide By ZERO (Int 0) ============================\r
+\r
+PUBLIC IntDivBy0:\r
+;              MOV EAX,07300730h       ;00\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              CLI\r
+;              HLT\r
+\r
+               MOV dbgFAULT,00h        ; Divide By Zero\r
+               POP dbgOldEIP                   ; Get EIP of offender for debugger\r
+               POP dbgOldCS                    ;\r
+               POP dbgOldEFlgs                 ;\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;===================== Debugger Single Step (Int 1) ======================\r
+\r
+PUBLIC IntDbgSS:\r
+\r
+               POP dbgOldEIP                   ; Get EIP of offender for debugger\r
+               POP dbgOldCS                    ;\r
+               POP dbgOldEFlgs                 ;\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;===================== Debugger Entry (Int 3) ===========================\r
+\r
+PUBLIC IntDebug:\r
+\r
+               POP dbgOldEIP                   ; Get EIP of offender for debugger\r
+               POP dbgOldCS                    ; Get CS\r
+               POP dbgOldEFlgs                 ; Get Flags\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;===================== OverFlow (Int 4) ==================================\r
+\r
+PUBLIC IntOverFlow:\r
+               PUSH EAX\r
+               MOV EAX,07340730h       ;04\r
+               MOV DS:VGATextBase+00h,EAX\r
+               CLI\r
+               HLT\r
+\r
+;========================== Bad Opcode (Int 6) ================================\r
+PUBLIC INTOpCode:\r
+;              MOV EAX,07360730h       ;06\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              HLT\r
+\r
+               MOV dbgFAULT,06h        ; Invalid Opcode\r
+               POP dbgOldEIP                   ; Get EIP of offender for debugger\r
+               POP dbgOldCS                    ;\r
+               POP dbgOldEFlgs                 ;\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;========================== Dbl Exception (Int 08)============================\r
+PUBLIC IntDblExc:\r
+;              MOV EAX,07380730h       ;08\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              CLI\r
+;              HLT\r
+\r
+               MOV dbgFAULT,08h        ; Double Exception\r
+               POP dbgFltErc                   ; Error Code pushed last by processor\r
+               POP dbgOldEIP\r
+               POP dbgOldCS\r
+               POP dbgOldEFlgs\r
+               POP dbgOldEFlgs                 ;\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;========================= Invalid TSS 10 ====================================\r
+PUBLIC INTInvTss:\r
+               MOV EAX,07300731h       ;10\r
+               MOV DS:VGATextBase+00h,EAX\r
+               CLI\r
+               HLT\r
+\r
+               MOV dbgFAULT,0Ah        ; Invalid TSS\r
+               POP dbgFltErc                   ; Error code pushed last by processor\r
+               POP dbgOldEIP\r
+               POP dbgOldCS\r
+               POP dbgOldEFlgs\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;========================== Seg Not Present 11 ===============================\r
+\r
+PUBLIC INTNoSeg:\r
+               MOV EAX,07310731h       ;11\r
+               MOV DS:VGATextBase+00h,EAX\r
+               CLI\r
+               HLT\r
+\r
+;========================== Stack Overflow 12 ================================\r
+PUBLIC INTStkOvr:\r
+;              MOV EAX,07320731h       ;12\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              CLI\r
+;              HLT\r
+\r
+               MOV dbgFAULT,0Ch        ; Stack overflow\r
+               POP dbgFltErc\r
+               POP dbgOldEIP\r
+               POP dbgOldCS\r
+               POP dbgOldEFlgs\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;========================== GP 13  ===========================================\r
+PUBLIC IntGP:\r
+;              MOV EAX,07330731h       ;13\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              CLI\r
+;              HLT\r
+\r
+               MOV dbgFAULT,0Dh        ; GP Fault\r
+               POP dbgFltErc\r
+               POP dbgOldEIP\r
+               POP dbgOldCS\r
+               POP dbgOldEFlgs\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;========================== Page Fault 14 ====================================\r
+PUBLIC INTPgFlt:\r
+;              MOV EAX,07340731h       ;14\r
+;              MOV DS:VGATextBase+00h,EAX\r
+;              CLI\r
+;              HLT\r
+\r
+               MOV dbgFAULT,0Eh        ; Page Fault\r
+               POP dbgFltErc\r
+               POP dbgOldEIP\r
+               POP dbgOldCS\r
+               POP dbgOldEFlgs\r
+               JMP EnterDebug                  ;Enter debugger\r
+\r
+;=============================================================================\r
+; ISR for interrupt on PICU1 from Slave\r
+;=============================================================================\r
+\r
+PUBLIC IntPICU2:                           ; IRQ Line 2 from Slave 8259 (Int22)\r
+               PUSH EAX\r
+               MOV EAX,07320750h               ; From PICU#2 (P2)\r
+               MOV DS:VGATextBase+100h,EAX\r
+               PUSH 2\r
+               CALL FWORD PTR _EndOfIRQ\r
+               POP EAX\r
+               IRETD\r
+\r
+;=============== end of module ==================\r