Initial revision
[ssr] / StraySrc / Libraries / Sapphire / csapph / s / csetjmp
1 ;
2 ; csetjmp.s
3 ;
4 ; Support for setjmp and longjmp
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 GET libs:stream
15
16 ;----- Main code ------------------------------------------------------------
17
18 AREA |Sapphire$$Code|,CODE,READONLY
19
20 ; --- setjmp ---
21 ;
22 ; On entry: R0 == pointer to setjmp block
23 ;
24 ; On exit: R0 == 0
25 ;
26 ; Use: Fills a jmp_buf with useful information
27
28 EXPORT setjmp
29 setjmp ROUT
30
31 SWI XFPEmulator_Version ;Do we have FP available?
32 MOVVS R12,#0 ;No -- remember this
33 STRVS R12,[R0,#84] ;Store the value away
34 STFVCE F4,[R0],#12 ;Store FP registers
35 STFVCE F5,[R0],#12
36 STFVCE F6,[R0],#12
37 STFVCE F7,[R0],#12
38 STMIA R0,{R4-R11,R13,R14} ;Store lots of stuff
39 MOV R0,#0 ;Return zero
40 MOVS PC,R14 ;And return to caller
41
42 LTORG
43
44 ; --- longjmp ---
45 ;
46 ; On entry: R0 == pointer to jmp_buf block
47 ; R1 == return value
48 ;
49 ; On exit: R0 == R1 on entry, or 1 if R1 was 0
50 ;
51 ; Use: Returns to a setjmp position.
52
53 EXPORT longjmp
54 longjmp ROUT
55
56 LDR R14,[R0,#84] ;Load the final word out
57 CMP R14,#0 ;Is it defined there?
58 LDFNEE F4,[R0],#12 ;Load FP registers back
59 LDFNEE F5,[R0],#12
60 LDFNEE F6,[R0],#12
61 LDFNEE F7,[R0],#12
62 LDMIA R0,{R4-R14} ;Restore old registers
63 MOVS R0,R1 ;Get the return value
64 MOVEQ R0,#1 ;If it was zero, fiddle it
65 MOVS PC,R14 ;And return to `caller'
66
67 LTORG
68
69 ;----- That's all, folks ----------------------------------------------------
70
71 END