summaryrefslogtreecommitdiff
path: root/arm9/asm/OS_exception.s
blob: 85b378d404ff48576e1f28e0a9a84769bdcf1240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    .include "asm/macros.inc"
    .include "global.inc"

	.section .bss

	.global OSi_UserExceptionHandler
OSi_UserExceptionHandler: ; 0x021D371C
	.space 0x4

	.global OSi_UserExceptionHandlerArg
OSi_UserExceptionHandlerArg: ; 0x021D3720
	.space 0x4

	.global OSi_DebuggerHandler
OSi_DebuggerHandler: ; 0x021D3724
	.space 0x4

	.global OSi_ExContext
OSi_ExContext: ; 0x021D3728
	.space 0x80

    .text

	arm_func_start OSi_ExceptionHandler
OSi_ExceptionHandler: ; 0x020CC9FC
	ldr ip, _020CCA68 ; =OSi_DebuggerHandler
	ldr r12, [r12, #0x0]
	cmp r12, #0x0
	movne lr, pc
	bxne r12
	ldr ip, _020CCA6C ; =0x02000000
	stmdb r12!, {r0-r3,sp-lr}
	and r0, sp, #0x1
	mov sp, r12
	mrs r1, cpsr
	and r1, r1, #0x1f
	teq r1, #0x17
	bne _020CCA38
	bl OSi_GetAndDisplayContext
	b _020CCA44
_020CCA38:
	teq r1, #0x1b
	bne _020CCA44
	bl OSi_GetAndDisplayContext
_020CCA44:
	ldr ip, _020CCA68 ; =OSi_DebuggerHandler
	ldr r12, [r12, #0x0]
	cmp r12, #0x0
_020CCA50:
	beq _020CCA50
_020CCA54:
	mov r0, r0
	b _020CCA54
_020CCA5C:
	ldmia sp!, {r0-r3,ip,lr}
	mov sp, ip
	bx lr
_020CCA68: .word OSi_DebuggerHandler
_020CCA6C: .word 0x02000000

	arm_func_start OSi_GetAndDisplayContext
OSi_GetAndDisplayContext: ; 0x020CCA70
	stmdb sp!, {r0,lr}
	bl OSi_SetExContext
	bl OSi_DisplayExContext
	ldmia sp!, {r0,lr}
	bx lr

	arm_func_start OSi_SetExContext
OSi_SetExContext: ; 0x020CCA84
	ldr r1, _020CCB10 ; =OSi_ExContext
	mrs r2, cpsr
	str r2, [r1, #0x74]
	str r0, [r1, #0x6c]
	ldr r0, [r12, #0x0]
	str r0, [r1, #0x4]
	ldr r0, [r12, #0x4]
	str r0, [r1, #0x8]
	ldr r0, [r12, #0x8]
	str r0, [r1, #0xc]
	ldr r0, [r12, #0xc]
	str r0, [r1, #0x10]
	ldr r2, [r12, #0x10]
	bic r2, r2, #0x1
	add r0, r1, #0x14
	stmia r0, {r4-r11}
	str r12, [r1, #0x70]
	ldr r0, [r2, #0x0]
	str r0, [r1, #0x64]
	ldr r3, [r2, #0x4]
	str r3, [r1, #0x0]
	ldr r0, [r2, #0x8]
	str r0, [r1, #0x34]
	ldr r0, [r2, #0xc]
	str r0, [r1, #0x40]
	mrs r0, cpsr
	orr r3, r3, #0x80
	bic r3, r3, #0x20
	msr cpsr_fsxc, r3
	str sp, [r1, #0x38]
	str lr, [r1, #0x3c]
	mrs r2, spsr
	str r2, [r1, #0x7c]
	msr cpsr_fsxc, r0
	bx lr
	.balign 4
_020CCB10: .word OSi_ExContext

	arm_func_start OSi_DisplayExContext
OSi_DisplayExContext: ; 0x020CCB14
	stmdb sp!, {lr}
	sub sp, sp, #0x4
	ldr r0, _020CCB70 ; =OSi_UserExceptionHandler
	ldr r0, [r0, #0x0]
	cmp r0, #0x0
	addeq sp, sp, #0x4
	ldmeqia sp!, {lr}
	bxeq lr
	mov r0, sp
	ldr r1, _020CCB74 ; =0x0000009F
	msr cpsr_fsxc, r1
	mov sp, r0
	bl OS_EnableProtectionUnit
	ldr r1, _020CCB78 ; =OSi_UserExceptionHandlerArg
	ldr r0, _020CCB70 ; =OSi_UserExceptionHandler
	ldr r1, [r1, #0x0]
	ldr r2, [r0, #0x0]
	ldr r0, _020CCB7C ; =OSi_ExContext
	blx r2
	bl OS_DisableProtectionUnit
	add sp, sp, #0x4
	ldmia sp!, {lr}
	bx lr
	.balign 4
_020CCB70: .word OSi_UserExceptionHandler
_020CCB74: .word 0x0000009F
_020CCB78: .word OSi_UserExceptionHandlerArg
_020CCB7C: .word OSi_ExContext

	arm_func_start OS_InitException
OS_InitException: ; 0x020CCB80
	ldr r0, _020CCBDC ; =0x027FFD9C
	ldr r1, [r0, #0x0]
	cmp r1, #0x2600000
	blo _020CCBA0
	cmp r1, #0x2800000
	ldrlo r0, _020CCBE0 ; =OSi_DebuggerHandler
	strcc r1, [r0, #0x0]
	blo _020CCBAC
_020CCBA0:
	ldr r0, _020CCBE0 ; =OSi_DebuggerHandler
	mov r1, #0x0
	str r1, [r0, #0x0]
_020CCBAC:
	ldr r0, _020CCBE0 ; =OSi_DebuggerHandler
	ldr r0, [r0, #0x0]
	cmp r0, #0x0
	ldreq r2, _020CCBE4 ; =OSi_ExceptionHandler
	ldreq r1, _020CCBDC ; =0x027FFD9C
	ldreq r0, _020CCBE8 ; =0x027E3000
	streq r2, [r1, #0x0]
	streq r2, [r0, #0xfdc]
	ldr r0, _020CCBEC ; =OSi_UserExceptionHandler
	mov r1, #0x0
	str r1, [r0, #0x0]
	bx lr
	.balign 4
_020CCBDC: .word 0x027FFD9C
_020CCBE0: .word OSi_DebuggerHandler
_020CCBE4: .word OSi_ExceptionHandler
_020CCBE8: .word 0x027E3000
_020CCBEC: .word OSi_UserExceptionHandler