summaryrefslogtreecommitdiffstats
path: root/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/SWI/HANDLE.S
blob: 60560353a2bae39e74a0c65fdf90351fa29f789a (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
	AREA 	TopSwiHandler, CODE 	; name this block of code

	EXPORT	SWIHandler
	EXPORT  MakeChain
	IMPORT  C_SWI_Handler	
	IMPORT 	Dswivec
SWIHandler
	SUB r13, r13, #4		; leave space to store spsr
	STMFD r13!, {r0-r12,r14}	; store registers
	MOV r1, r13			; second parameter to C routine
					; is register values.
	LDR r0,[r14,#-4]		; Calculate address of SWI instruction
					; and load it into r0
	BIC r0,r0,#0xff000000		; mask off top 8 bits of instruction
	MRS r2, spsr
	STR r2,[r13,#14*4]		; store spsr on stack at original r13
	BL  C_SWI_Handler		; Call C routine to handle SWI
	CMP r0, #0			; Has C routine handled SWI ?
					;  0 = no, 1 = yes
	LDR r2, [r13,#14*4]		; extract spsr from stack
	MSR spsr,r2			; and restore it
	LDMFD r13!, {r0-r12,lr}		; Restore original registers
	ADD r13,r13,#4
	; Now need to decide whether to return from handler or to call
	; the next handler in the chain (the debugger's).
	MOVNES pc,lr			; return from handler if SWI handled
	LDR pc, swichain		; else jump to address containing
					; instruction to branch to address of
					; debugger's SWI handler.

swichain
	DCD 0

MakeChain
	LDR r0, =swichain
	LDR r1, =Dswivec
	LDR r2, [r1]
	STR r2, [r0]
	MOV pc,lr

	END			; mark end of this file