1/* 2Copyright (c) 2009 Nick Clifton <nickc@redhat.com> 3 */ 4# setjmp/longjmp for Renesas RX. 5# 6# The jmpbuf looks like this: 7# 8# Register jmpbuf offset 9# R0 0x0 10# R1 0x4 11# R2 0x8 12# R3 0xc 13# R4 0x10 14# R5 0x14 15# R6 0x18 16# R7 0x1c 17# R8 0x20 18# R9 0x24 19# R10 0x28 20# R11 0x2c 21# R12 0x30 22# R13 0x34 23# R14 0x38 24# R15 0x3c 25# PC 0x40 26# 27# R1 contains the pointer to jmpbuf: 28# 29# int R1 = setjmp (jmp_buf R1) 30# void longjmp (jmp_buf R1, int R2) 31# 32# The ABI allows for R1-R5 to be clobbered by functions. We must be 33# careful to always leave the stack in a usable state in case an 34# interrupt happens. 35 36 .text 37 .global _setjmp 38 .type _setjmp, @function 39_setjmp: 40 mov.l r0, [r1] ; save all the general registers 41 mov.l r1, 0x4[r1] ; longjmp won't use this, but someone else might. 42 mov.l r2, 0x8[r1] 43 mov.l r3, 0xc[r1] 44 mov.l r4, 0x10[r1] 45 mov.l r5, 0x14[r1] 46 mov.l r6, 0x18[r1] 47 mov.l r7, 0x1c[r1] 48 mov.l r8, 0x20[r1] 49 mov.l r9, 0x24[r1] 50 mov.l r10, 0x28[r1] 51 mov.l r11, 0x2c[r1] 52 mov.l r12, 0x30[r1] 53 mov.l r13, 0x34[r1] 54 mov.l r14, 0x38[r1] 55 mov.l r15, 0x3c[r1] 56 mov.l [r0], r2 ; get return address off the stack 57 mov.l r2, 0x40[r1] ; PC 58 mov #0, r1 ; Return 0. 59 rts 60.Lend1: 61 .size _setjmp, .Lend1 - _setjmp 62 63 64 .global _longjmp 65 .type _longjmp, @function 66_longjmp: 67 tst r2, r2 ; Set the Z flag if r2 is 0. 68 stz #1, r2 ; If the Z flag was set put 1 into the return register. 69 mov r2, 4[r1] ; Put r2 (our return value) into the setjmp buffer as r1. 70 71 mov.l [r1], r0 ; Restore the stack - there's a slot for PC 72 mov.l 0x40[r1], r2 ; Get the saved PC 73 mov.l r2, [r0] ; Overwrite the old return address 74 75 mov.l 0x3c[r1], r15 76 mov.l 0x38[r1], r14 77 mov.l 0x34[r1], r13 78 mov.l 0x30[r1], r12 79 mov.l 0x2c[r1], r11 80 mov.l 0x28[r1], r10 81 mov.l 0x24[r1], r9 82 mov.l 0x20[r1], r8 83 mov.l 0x1c[r1], r7 84 mov.l 0x18[r1], r6 85 mov.l 0x14[r1], r5 86 mov.l 0x10[r1], r4 87 mov.l 0xc[r1], r3 88 mov.l 0x8[r1], r2 89 mov.l 0x4[r1], r1 ; This sets up the new return value 90 rts 91.Lend2: 92 .size _longjmp, .Lend2 - _longjmp 93