exceptions round-trip

except for FDP offsets (which suck)
This commit is contained in:
Elliot Nunn 2018-07-08 17:57:30 +08:00
parent d65818e89e
commit bdc296adef
8 changed files with 539 additions and 919 deletions

View File

@ -83,41 +83,59 @@ BootstrapVersion ds.b 16 ; f00:f10 ; Bootstrap loader version info, from Config
; Lives in EDP. Keeping a separate record to EDP makes the code nicer.
; Gets called the "system context"
ContextBlock record 0,INCR
; Move this!
CB record 0,INCR
Flags ds.l 1 ; 000 ; (SPAC) copied from kdp by CreateTask
Enables ds.l 1 ; 004
org 0x40
SavedFlags ds.l 1 ; 040 ; from before exception
org 0x44
SavedEnables ds.l 1 ; 044 ; from before exception
org 0x4c
ds.l 1 ; 008
ds.l 1 ; 00c
ds.l 1 ; 010
ds.l 1 ; 014
ds.l 1 ; 018
ds.l 1 ; 01c
ds.l 1 ; 020
LowSave17 ds.l 1 ; 024
LowSave20 ds.l 1 ; 028
LowSave21 ds.l 1 ; 02c
ds.l 1 ; 030
LowSave19 ds.l 1 ; 034
ds.l 1 ; 038
LowSave18 ds.l 1 ; 03c
ExceptionOriginFlags ds.l 1 ; 040 ; from before exception
ExceptionOriginEnables ds.l 1 ; 044 ; from before exception
ds.l 1 ; 048
ExceptionHandler ds.l 1 ; 04c
org 0x5c
LA_EmulatorKernelTrapTable ds.l 1
org 0x74
SRR0 ds.l 1 ; 074
org 0x84
LA_EmulatorEntry ds.l 1 ; 084 ; Entry pt of emulator; set by NK Init.s
org 0x94
LA_EmulatorData ds.l 1
org 0x9c
LA_DispatchTable ds.l 1
org 0xa4
ds.l 1 ; 050
ExceptionHandlerR4 ds.l 1 ; 054
ds.l 1 ; 058
ExceptionHandlerRetAddr ds.l 1 ; 05c
ds.l 1 ; 060
PropagateR17 ds.l 1 ; 064
PropagateR20 ds.l 1 ; 068
PropagateR21 ds.l 1 ; 06c
ds.l 1 ; 070
PropagateR19 ds.l 1 ; 074
ds.l 1 ; 078
PropagateR18 ds.l 1 ; 07c
ds.l 1 ; 080
ExceptionOriginAddr ds.l 1 ; 084 ; Entry pt of emulator; set by NK Init.s
ds.l 1 ; 088
ExceptionOriginLR ds.l 1 ; 08c
ds.l 1 ; 090
ExceptionOriginR3 ds.l 1 ; 094
ds.l 1 ; 098
ExceptionOriginR4 ds.l 1 ; 09c
ds.l 1 ; 0a0
MSR ds.l 1 ; 0a4 ; (SPAC) copied from kdp by CreateTask
org 0xc4
ds.l 1 ; 0a8
ds.l 1 ; 0ac
ds.l 1 ; 0b0
ds.l 1 ; 0b4
ds.l 1 ; 0b8
ds.l 1 ; 0bc
ds.l 1 ; 0c0
MQ ds.l 1 ; 0c4 ; 601 only
EDPOffsetSWIRelated ds.l 1 ; 0c8
PriorityShifty ds.l 1 ; 0cc ; if low nybble is empty, SchInit sets this to 2
@ -131,11 +149,8 @@ FE000000 ds.l 1 ; 0e8 ; also LR?
LR ds.l 1 ; 0ec
CTR ds.l 1 ; 0f0
KernelCTR ds.l 1 ; 0f4
org 0xfc
ds.l 1 ; 0f8
CodePtr ds.l 1 ; 0fc ; probably goes in SRR0?
org 0x100
ds.l 1
r0 ds.l 1 ; 104
ds.l 1
@ -200,7 +215,5 @@ r29 ds.l 1 ; 1ec
r30 ds.l 1 ; 1f4
ds.l 1
r31 ds.l 1 ; 1fc
FloatRegisters ds.d 32 ; 200:300
endr

View File

@ -2,27 +2,6 @@
; Data structures internal to the NanoKernel
;_______________________________________________________________________
;_______________________________________________________________________
; NOTE: DECLARING BIT FIELDS
;
; Bit fields get defined inside a record only in order to give them a
; namespace (e.g. MSR_IP). The _bitEqu macro is used to produce three
; equates per bit:
; (name) = the bit's place value
; (name)bit = the bit's PowerPC index (0 is leftmost)
; (name)shift = the bit's 68k index (0 is rightmost)
;_______________________________________________________________________
macro
_bitEqu &name, &bit
&name equ 1 << (31-&bit)
&name.bit equ &bit
&name.shift equ 31 - &bit
endm
;_______________________________________________________________________
; INFORECORD PAGE
;
@ -131,7 +110,7 @@ NominalReadyQ ds.l 8 ; -9b0:-990 ; unblocked tasks with priority 2
IdleReadyQ ds.l 8 ; -990:-970 ; unblocked tasks with priority 3
PriorityFlags ds.l 1 ; -970 ; bit 0 is 0, bit 1 is 1, etc...
ScrambledMPCallTime ds.l 1 ; -96c ; by MP call return
FlagsTemplate ds.l 1 ; -968 ; typically just EWA.kFlagVec
FlagsTemplate ds.l 1 ; -968 ; typically just bitFlagVec
UserModeMSR ds.l 1 ; -964
ThudBuffer ds.b 96 ; -960:-900 ; that's the kernel debugger
NoIdeaR23 ds.l 1 ; -900 ; r23 copies here... replated to RTAS?
@ -505,45 +484,6 @@ r31 ds.l 1 ; 07c, cpu+3bc
; Fun fact: offsets past here contain the main kernel globals
; ("Kernel Data Page"), but only on CPU-0.
kFlag0 equ 0
kFlag1 equ 1
kFlag2 equ 2
kFlag3 equ 3
kFlag4 equ 4
kFlag5 equ 5
kFlag6 equ 6
kFlag7 equ 7
; PER-TASK FLAGS
kFlagEmu equ 8 ; emulator is running
kFlag9 equ 9 ; * = preserved on alt>sys switch
kFlagBlue equ 10 ; *
kFlag11 equ 11 ; *
kFlagVec equ 12 ; *
kFlagHasMQ equ 13 ; *
kFlag14 equ 14 ; *
kFlag15 equ 15 ; *
kFlagSIGP equ 16 ; *
; PER-CONTEXT FLAGS
kFlag17 equ 17
kFlag18 equ 18
kFlag19 equ 19
kFlagFE0 equ 20 ; these correspond with MSR bits
kFlagSE equ 21
kFlagBE equ 22
kFlagFE1 equ 23
kFlag24 equ 24
kFlag25 equ 25
kFlag26 equ 26 ; can be copied from kFlagSE
kFlagLowSaves equ 27
kFlag28 equ 28
kFlag29 equ 29
kFlag30 equ 30
kFlag31 equ 31
endr
@ -616,7 +556,7 @@ PA_ECB ds.l 1 ; 658 ; gets called "system context"
PA_ContextBlock ds.l 1 ; 65c ; moved to EWA (per-CPU) in NKv2
Flags ds.l 1 ; 660 ; moved to EWA (per-CPU) in NKv2
Enables ds.l 1 ; 664 ; moved to EWA (per-CPU) in NKv2
ds.l 1 ; 668
ContextClock ds.l 1 ; 668
PA_PageMapEnd ds.l 1 ; 66c ; Set at the same time as PA_PageMapStart below...
TestIntMaskInit ds.l 1 ; 670 ; These are all copied from ConfigInfo...
PostIntMaskInit ds.l 1 ; 674

View File

@ -3,27 +3,38 @@
;_______________________________________________________________________
; Helps with making equates
; X = 0x00008000, Xbit=16, Xshift=15
macro
_bitEqu &bit, &name
&name equ 1 << (31-&bit)
bit&name equ &bit
shift&name equ 31 - &bit
endm
kNanoKernelVersion equ $0228
; PowerPC Machine Status Register (MSR) bits
; (borrowing the _bitEqu macro from NKInfoRecordsPriv.s)
_bitEqu MSR_POW, 13
_bitEqu MSR_ILE, 15
_bitEqu MSR_EE, 16
_bitEqu MSR_PR, 17
_bitEqu MSR_FP, 18
_bitEqu MSR_ME, 19
_bitEqu MSR_FE0, 20
_bitEqu MSR_SE, 21
_bitEqu MSR_BE, 22
_bitEqu MSR_FE1, 23
_bitEqu MSR_IP, 25
_bitEqu MSR_IR, 26
_bitEqu MSR_DR, 27
_bitEqu MSR_RI, 30
_bitEqu MSR_LE, 31
_bitEqu 13, MsrPOW
_bitEqu 15, MsrILE
_bitEqu 16, MsrEE
_bitEqu 17, MsrPR
_bitEqu 18, MsrFP
_bitEqu 19, MsrME
_bitEqu 20, MsrFE0
_bitEqu 21, MsrSE
_bitEqu 22, MsrBE
_bitEqu 23, MsrFE1
_bitEqu 25, MsrIP
_bitEqu 26, MsrIR
_bitEqu 27, MsrDR
_bitEqu 30, MsrRI
_bitEqu 31, MsrLE
; Special Purpose Registers (SPRs) not understood by MPW
@ -92,3 +103,38 @@ ecDataWriteViolation equ 21 ; ExceptionMemRetried
ecDataSupAccessViolation equ 22 ; ExceptionMemRetried
ecDataSupWriteViolation equ 23 ; ?
ecUnknown24 equ 24 ; ExceptionMemRetried
; Runtime Flag equates
_bitEqu 0, Flag0
_bitEqu 1, Flag1
_bitEqu 2, Flag2
_bitEqu 3, Flag3
_bitEqu 4, Flag4
_bitEqu 5, Flag5
_bitEqu 6, Flag6
_bitEqu 7, Flag7
_bitEqu 8, FlagEmu
_bitEqu 9, Flag9
_bitEqu 10, FlagBlue
_bitEqu 11, Flag11
_bitEqu 12, FlagVec
_bitEqu 13, FlagHasMQ
_bitEqu 14, Flag14
_bitEqu 15, Flag15
_bitEqu 16, FlagSIGP
_bitEqu 17, Flag17
_bitEqu 18, Flag18
_bitEqu 19, Flag19
_bitEqu 20, FlagFE0
_bitEqu 21, FlagSE
_bitEqu 22, FlagBE
_bitEqu 23, FlagFE1
_bitEqu 24, Flag24
_bitEqu 25, Flag25
_bitEqu 26, Flag26
_bitEqu 27, FlagLowSaves
_bitEqu 28, Flag28
_bitEqu 29, Flag29
_bitEqu 30, Flag30
_bitEqu 31, Flag31

File diff suppressed because it is too large Load Diff

View File

@ -14,11 +14,11 @@ IntFPUnavail
stw r11, KDP.NanoKernelInfo + NKNanoKernelInfo.FPUReloadCount(r1)
mfsrr1 r11
_bset r11, r11, MSR_FPbit
_bset r11, r11, bitMsrFP
mtsrr1 r11
mfmsr r11 ; need this to access float registers
_bset r11, r11, MSR_FPbit
_bset r11, r11, bitMsrFP
lwz r6, KDP.PA_ContextBlock(r1)
mtmsr r11
@ -35,18 +35,20 @@ IntFPUnavail
########################################################################
major_0x03e18
EnableFPU
rlwinm. r8, r11, 0, 18, 18
bnelr
IntHandleSpecialFPException
lwz r8, 0xe4(r6)
ReloadFPU
lwz r8, 0xe4(r6) ; ???
rlwinm. r8, r8, 1, 0, 0
mfmsr r8
_bset r8, r8, MSR_FPbit
_bset r8, r8, bitMsrFP
beqlr
mtmsr r8
_bset r11, r11, MSR_FPbit
_bset r11, r11, bitMsrFP
########################################################################
@ -92,10 +94,10 @@ LoadFloats
DisableFPU
mfmsr r8
_bset r8, r8, MSR_FPbit
_bset r8, r8, bitMsrFP
mtmsr r8
_bclr r11, r11, MSR_FPbit
_bclr r11, r11, bitMsrFP
stfd f0, 0x200(r6)
stfd f1, 0x208(r6)

View File

@ -268,7 +268,7 @@ _bclr_lbit set 31
MACRO
_FloatRangeToContextBlock &first, &last
stfd &first, ContextBlock.FloatRegisters+8*(&first)(r6)
stfd &first, CB.FloatRegisters+8*(&first)(r6)
IF &first != &last
_FloatRangeToContextBlock &first+1, &last
@ -280,7 +280,7 @@ _bclr_lbit set 31
MACRO
_FloatRangeFromContextBlock &first, &last
lfd &first, ContextBlock.FloatRegisters+8*(&first)(r6)
lfd &first, CB.FloatRegisters+8*(&first)(r6)
IF &first != &last
_FloatRangeFromContextBlock &first+1, &last

View File

@ -5,7 +5,7 @@
IllegalInstruction
mfmsr r9
_bset r8, r9, MSR_DRbit
_bset r8, r9, bitMsrDR
mtmsr r8
lwz r8, 0(r10)
mtmsr r9
@ -15,19 +15,19 @@ IllegalInstruction
stw r3, EWA.r3(r1)
stw r4, EWA.r4(r1)
stw r5, EWA.r5(r1)
lwz r9, ContextBlock.r7(r6)
lwz r9, CB.r7(r6)
stw r9, EWA.r7(r1)
lwz r9, ContextBlock.r8(r6)
lwz r9, CB.r8(r6)
stw r9, EWA.r8(r1)
lwz r9, ContextBlock.r9(r6)
lwz r9, CB.r9(r6)
stw r9, EWA.r9(r1)
lwz r9, ContextBlock.r10(r6)
lwz r9, CB.r10(r6)
stw r9, EWA.r10(r1)
lwz r9, ContextBlock.r11(r6)
lwz r9, CB.r11(r6)
stw r9, EWA.r11(r1)
lwz r9, ContextBlock.r12(r6)
lwz r9, CB.r12(r6)
stw r9, EWA.r12(r1)
lwz r9, ContextBlock.r13(r6)
lwz r9, CB.r13(r6)
stw r9, EWA.r13(r1)
stmw r14, EWA.r14(r1)
@ -89,7 +89,7 @@ IllegalInstruction
addi r23, r23, 1
stw r23, KDP.NanoKernelInfo + NKNanoKernelInfo.EmulatedUnimpInstCount(r1)
mfmsr r14
_bset r15, r14, MSR_DRbit
_bset r15, r14, bitMsrDR
b loc_A38
########################################################################
@ -119,11 +119,11 @@ KCallRunAlternateContext
lwz r8, KDP.LA_EmulatorKernelTrapTable(r1)
mtcrf 0x3f, r7
clrlwi r7, r7, 8
stw r8, ContextBlock.LA_EmulatorKernelTrapTable(r9)
stw r8, CB.ExceptionHandlerRetAddr(r9)
stw r9, KDP.PA_ContextBlock(r1)
b IntReturnToOtherBlueContext
b SwitchContext ; OldCB *r6, NewCB *r9
@search_cache
@ -255,7 +255,7 @@ KCallResetSystem
; Gary Davidian skeleton key: r5/D0 = MSR bits to unset, r7/D2 = MSR bits to set
andc r11, r11, r5
lwz r8, ContextBlock.r7(r6)
lwz r8, CB.r7(r6)
or r11, r11, r8
b IntReturn
@ -275,18 +275,18 @@ KCallPrioritizeInterrupts
mtsrr0 r10
mtsrr1 r11
mtcr r13
lwz r10, ContextBlock.r10(r6)
lwz r11, ContextBlock.r11(r6)
lwz r12, ContextBlock.r12(r6)
lwz r13, ContextBlock.r13(r6)
lwz r7, ContextBlock.r7(r6)
lwz r10, CB.r10(r6)
lwz r11, CB.r11(r6)
lwz r12, CB.r12(r6)
lwz r13, CB.r13(r6)
lwz r7, CB.r7(r6)
lwz r8, EWA.r1(r1)
mfsprg r9, 3
lwz r9, VecTable.ExternalIntVector(r9)
mtsprg 1, r8
mtlr r9
lwz r8, ContextBlock.r8(r6)
lwz r9, ContextBlock.r9(r6)
lwz r8, CB.r8(r6)
lwz r9, CB.r9(r6)
lwz r6, EWA.r6(r1)
blrl ; (could this ever fall though to KCallSystemCrash?)
@ -300,22 +300,22 @@ KCallSystemCrash
stw r4, EWA.r4(r1)
stw r5, EWA.r5(r1)
lwz r8, ContextBlock.r7(r6)
lwz r9, ContextBlock.r8(r6)
lwz r8, CB.r7(r6)
lwz r9, CB.r8(r6)
stw r8, EWA.r7(r1)
stw r9, EWA.r8(r1)
lwz r8, ContextBlock.r9(r6)
lwz r9, ContextBlock.r10(r6)
lwz r8, CB.r9(r6)
lwz r9, CB.r10(r6)
stw r8, EWA.r9(r1)
stw r9, EWA.r10(r1)
lwz r8, ContextBlock.r11(r6)
lwz r9, ContextBlock.r12(r6)
lwz r8, CB.r11(r6)
lwz r9, CB.r12(r6)
stw r8, EWA.r11(r1)
stw r9, EWA.r12(r1)
lwz r8, ContextBlock.r13(r6)
lwz r8, CB.r13(r6)
stw r8, EWA.r13(r1)
stmw r14, EWA.r14(r1)
@ -334,13 +334,13 @@ IntProgram
mfsprg r6, 1
stw r6, EWA.r1(r1)
lwz r6, KDP.PA_ContextBlock(r1)
stw r7, ContextBlock.r7(r6)
stw r8, ContextBlock.r8(r6)
stw r9, ContextBlock.r9(r6)
stw r10, ContextBlock.r10(r6)
stw r11, ContextBlock.r11(r6)
stw r12, ContextBlock.r12(r6)
stw r13, ContextBlock.r13(r6)
stw r7, CB.r7(r6)
stw r8, CB.r8(r6)
stw r9, CB.r9(r6)
stw r10, CB.r10(r6)
stw r11, CB.r11(r6)
stw r12, CB.r12(r6)
stw r13, CB.r13(r6)
; Compare SRR0 with address of Emulator's KCall trap table
lwz r8, KDP.LA_EmulatorKernelTrapTable(r1)
@ -349,11 +349,11 @@ IntProgram
xor. r8, r10, r8
lwz r7, KDP.Flags(r1)
mfsprg r12, 2
beq ReturnFromExceptionFastPath ; KCall in Emulator table => fast path
rlwimi. r7, r7, EWA.kFlagEmu, 0, 0
beq KCallReturnFromExceptionFastPath ; KCall in Emulator table => fast path
rlwimi. r7, r7, bitFlagEmu, 0, 0
cmplwi cr7, r8, 16 * 4
bge cr0, @fromAltContext ; Alt Context cannot make KCalls; this might be an External Int
bge cr7, @notFromEmulatorTrapTable ; from Emulator but not from its KCall table => do more checks
bge cr0, @fromAltContext ; Alt Context cannot make KCalls; this might be an External Int
bge cr7, @notFromEmulatorTrapTable ; from Emulator but not from its KCall table => do more checks
; SUCCESSFUL TRAP from emulator KCall table
; => Service call then return to link register
@ -373,14 +373,14 @@ IntProgram
mtcrf 0x70, r11
bc BO_IF_NOT, 14, @notTrap
mfmsr r9 ; fetch the instruction to get the "trap number"
_bset r8, r9, MSR_DRbit
mfmsr r9 ; fetch the instruction to get the "trap number"
_bset r8, r9, bitMsrDR
mtmsr r8
lwz r8, 0(r10)
mtmsr r9
xoris r8, r8, 0xfff
cmplwi cr7, r8, 16 ; only traps 0-15 are allowed
slwi r8, r8, 2 ; (for "success" case below)
cmplwi cr7, r8, 16 ; only traps 0-15 are allowed
slwi r8, r8, 2 ; (for "success" case below)
bge cr7, @illegalTrap
; SUCCESSFUL TRAP from outside emulator KCall table
@ -396,17 +396,17 @@ IntProgram
blr
; Cannot service with a KCall => throw Exception
@fromAltContext ; external interrupt, or a (forbidden) KCall attempt
@fromAltContext ; external interrupt, or a (forbidden) KCall attempt
mfsrr1 r11
mtcrf 0x70, r11
@notTrap ; then it was some other software exception
@notTrap ; then it was some other software exception
bc BO_IF, 12, IllegalInstruction
bc BO_IF, 11, @floatingPointException
@illegalTrap ; because we only allow traps 0-15
@illegalTrap ; because we only allow traps 0-15
rlwinm r8, r11, 17, 28, 29
addi r8, r8, 0x4b3
rlwnm r8, r8, r8, 28, 31
b Exception ; CLEVER BIT HACKING described below
b Exception ; CLEVER BIT HACKING described below
; SRR1[13] SRR[14] Exception
; 0 0 ecNoException

View File

@ -50,6 +50,8 @@ FDP
FDP_003C
org 0xA38
loc_A38
org 0xD18
FDP_011C
org 0xD50
loc_D50
FDP_0DA0
@ -76,27 +78,8 @@ PagingL2PWithoutBATs
org 0x1F98
PagingFlushTLB
org 0x1FB8
ExceptionMemRetried
org 0x2034
LetBlueHandleOwnException
org 0x20C0
ReturnFromExceptionFastPath
org 0x20D8
KCallReturnFromException
org 0x2194
LoadInterruptRegisters
org 0x21DC
Exception
org 0x2204
IntReturnToSystemContext
org 0x2214
IntReturnToOtherBlueContext
org 0x23AC
IntReturn
org 0x23F0
major_0x02ccc
org 0x2500
include 'NKExceptions.s'
include 'NKFloatingPt.s'
include 'NKSoftInt.s'
include 'NKLegacyVM.s'