From 0c238b72e5286c448b02838ac3269a98b1c5742a Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 26 Nov 2016 18:33:15 +0000 Subject: [PATCH] + set/longjmp implementation for avr git-svn-id: trunk@34971 - --- rtl/avr/setjump.inc | 80 ++++++++++++++++++++++++++++++++++++++++++-- rtl/avr/setjumph.inc | 5 +-- rtl/inc/compproc.inc | 4 +-- 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/rtl/avr/setjump.inc b/rtl/avr/setjump.inc index 8ca0cfa24e..acb6b8db55 100644 --- a/rtl/avr/setjump.inc +++ b/rtl/avr/setjump.inc @@ -14,13 +14,89 @@ **********************************************************************} -function fpc_setjmp(var S : jmp_buf) : smallint;assembler;[Public, alias : 'FPC_SETJMP'];nostackframe;compilerproc; +function fpc_setjmp(var S : jmp_buf) : shortint;assembler;[Public, alias : 'FPC_SETJMP'];nostackframe;compilerproc; asm + mov r26,r24 + mov r27,r25 + st x+,r1 + st x+,r2 + st x+,r3 + st x+,r4 + st x+,r5 + st x+,r6 + st x+,r7 + st x+,r8 + st x+,r9 + st x+,r10 + st x+,r11 + st x+,r12 + st x+,r13 + st x+,r14 + st x+,r15 + st x+,r16 + st x+,r17 + st x+,r28 + st x+,r29 + + // store stack pointer + in r18,61 + in r19,62 + st x+,r18 + st x+,r19 + + // store return address + pop r18 + pop r19 + st x+,r18 + st x+,r19 + push r19 + push r18 + + clr r24 end; -procedure fpc_longjmp(var S : jmp_buf;value : smallint);assembler;[Public, alias : 'FPC_LONGJMP'];compilerproc; +procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias : 'FPC_LONGJMP'];compilerproc; asm + mov r26,r24 + mov r27,r25 + ld r1,x+ + ld r2,x+ + ld r3,x+ + ld r4,x+ + ld r5,x+ + ld r6,x+ + ld r7,x+ + ld r8,x+ + ld r9,x+ + ld r10,x+ + ld r11,x+ + ld r12,x+ + ld r13,x+ + ld r14,x+ + ld r15,x+ + ld r16,x+ + ld r17,x+ + ld r28,x+ + ld r29,x+ + + // restore stack pointer + ld r18,x+ + ld r19,x+ + in r0,63 + cli + out 62,r19 + out 63,r0 + out 61,r18 + + // restore return address + pop r18 + pop r19 + ld r18,x+ + ld r19,x+ + push r19 + push r18 + mov r24,r22 end; diff --git a/rtl/avr/setjumph.inc b/rtl/avr/setjumph.inc index f27b3c9cbc..b1838d69b2 100644 --- a/rtl/avr/setjumph.inc +++ b/rtl/avr/setjumph.inc @@ -16,10 +16,11 @@ type jmp_buf = packed record + r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r28,r29,splo,sphi,pclo,pchi : byte; end; pjmp_buf = ^jmp_buf; -function setjmp(var S : jmp_buf) : longint;[external name 'FPC_SETJMP']; -procedure longjmp(var S : jmp_buf;value : longint);[external name 'FPC_LONGJMP']; +function setjmp(var S : jmp_buf) : shortint;[external name 'FPC_SETJMP']; +procedure longjmp(var S : jmp_buf;value : shortint);[external name 'FPC_LONGJMP']; diff --git a/rtl/inc/compproc.inc b/rtl/inc/compproc.inc index 0cab5b1f38..b6d79437ea 100644 --- a/rtl/inc/compproc.inc +++ b/rtl/inc/compproc.inc @@ -776,8 +776,8 @@ function fpc_qword_to_double(q: qword): double; compilerproc; function fpc_longword_to_double(i: longword): double; compilerproc; {$endif FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE} -function fpc_setjmp(var s : jmp_buf) : {$ifdef CPU16}smallint{$else}longint{$endif}; compilerproc; -procedure fpc_longjmp(var s : jmp_buf; value : {$ifdef CPU16}smallint{$else}longint{$endif}); compilerproc; +function fpc_setjmp(var s : jmp_buf) : {$if defined(CPUINT8)}shortint{$elseif defined(CPUINT16)}smallint{$else}longint{$endif}; compilerproc; +procedure fpc_longjmp(var s : jmp_buf; value : {$if defined(CPUINT8)}shortint{$elseif defined(CPUINT16)}smallint{$else}longint{$endif}); compilerproc; {$ifdef cpui8086} { i8086 stack checking }