Skip to content

Commit 76e71a6

Browse files
committed
TASK-194142 added support for longjmp/setjump for aarch64
1 parent 0c95905 commit 76e71a6

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ if ARCH_I386
4747
libthrlua_la_SOURCES += src/i386/setjmp.S
4848
CPPFLAGS += -DLUA_ARCH_I386=1
4949
endif
50+
if ARCH_AARCH64
51+
libthrlua_la_SOURCES += src/aarch64/setjmp.S
52+
CPPFLAGS += -DLUA_ARCH_AARCH64=1
53+
endif
5054
if ARCH_SPARCV9
5155
CPPFLAGS += -DLUA_ARCH_SPARCV9=1
5256
endif

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ case $host in
1818
i*86*linux*)
1919
arch=i386
2020
;;
21+
aarch64*linux*|arm64*linux*)
22+
arch=aarch64
23+
;;
2124
*darwin*)
2225
arch=x86_64
2326
;;
2427
esac
2528
AM_CONDITIONAL(ARCH_X86_64, test "$arch" = x86_64)
2629
AM_CONDITIONAL(ARCH_I386, test "$arch" = i386)
30+
AM_CONDITIONAL(ARCH_AARCH64, test "$arch" = aarch64)
2731
AM_CONDITIONAL(ARCH_SPARCV9, test "$arch" = sparcv9)
2832

2933
case $host in

src/aarch64/setjmp.S

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* This file is derived from the state-threads md.S file, which has no
2+
* specific license. It does claim the following, but does not indicate
3+
* which portions were contributed by SGI.
4+
*
5+
* Portions created by SGI are Copyright (C) 2000 Silicon Graphics, Inc.
6+
* All Rights Reserved.
7+
*/
8+
9+
/*
10+
* Internal __jmp_buf layout for AArch64
11+
*
12+
* Callee-saved general-purpose registers: x19-x28, x29 (FP), x30 (LR)
13+
* Stack pointer: SP
14+
* Callee-saved SIMD/FP registers: d8-d15
15+
*/
16+
#define JB_X19 0
17+
#define JB_X20 1
18+
#define JB_X21 2
19+
#define JB_X22 3
20+
#define JB_X23 4
21+
#define JB_X24 5
22+
#define JB_X25 6
23+
#define JB_X26 7
24+
#define JB_X27 8
25+
#define JB_X28 9
26+
#define JB_X29 10
27+
#define JB_LR 11
28+
#define JB_SP 12
29+
#define JB_D8 13
30+
#define JB_D9 14
31+
#define JB_D10 15
32+
#define JB_D11 16
33+
#define JB_D12 17
34+
#define JB_D13 18
35+
#define JB_D14 19
36+
#define JB_D15 20
37+
38+
.text
39+
40+
/* _lua_setjmp_aarch64(__jmp_buf env) */
41+
.globl _lua_setjmp_aarch64
42+
.align 4
43+
_lua_setjmp_aarch64:
44+
/*
45+
* Save callee-saved general-purpose registers.
46+
*/
47+
stp x19, x20, [x0, #(JB_X19*8)]
48+
stp x21, x22, [x0, #(JB_X21*8)]
49+
stp x23, x24, [x0, #(JB_X23*8)]
50+
stp x25, x26, [x0, #(JB_X25*8)]
51+
stp x27, x28, [x0, #(JB_X27*8)]
52+
stp x29, x30, [x0, #(JB_X29*8)]
53+
/* Save SP */
54+
mov x2, sp
55+
str x2, [x0, #(JB_SP*8)]
56+
/*
57+
* Save callee-saved SIMD/FP registers.
58+
*/
59+
stp d8, d9, [x0, #(JB_D8*8)]
60+
stp d10, d11, [x0, #(JB_D10*8)]
61+
stp d12, d13, [x0, #(JB_D12*8)]
62+
stp d14, d15, [x0, #(JB_D14*8)]
63+
/* Return 0 */
64+
mov w0, #0
65+
ret
66+
67+
/****************************************************************/
68+
69+
/* _lua_longjmp_aarch64(__jmp_buf env, int val) */
70+
.globl _lua_longjmp_aarch64
71+
.align 4
72+
_lua_longjmp_aarch64:
73+
/*
74+
* Restore callee-saved general-purpose registers.
75+
*/
76+
ldp x19, x20, [x0, #(JB_X19*8)]
77+
ldp x21, x22, [x0, #(JB_X21*8)]
78+
ldp x23, x24, [x0, #(JB_X23*8)]
79+
ldp x25, x26, [x0, #(JB_X25*8)]
80+
ldp x27, x28, [x0, #(JB_X27*8)]
81+
ldp x29, x30, [x0, #(JB_X29*8)]
82+
/* Restore SP */
83+
ldr x2, [x0, #(JB_SP*8)]
84+
mov sp, x2
85+
/*
86+
* Restore callee-saved SIMD/FP registers.
87+
*/
88+
ldp d8, d9, [x0, #(JB_D8*8)]
89+
ldp d10, d11, [x0, #(JB_D10*8)]
90+
ldp d12, d13, [x0, #(JB_D12*8)]
91+
ldp d14, d15, [x0, #(JB_D14*8)]
92+
/* Set return value: if val == 0, return 1 instead */
93+
cmp w1, #0
94+
csinc w0, w1, wzr, ne
95+
/* Jump to saved PC (LR was restored into x30 above) */
96+
ret
97+
98+
/****************************************************************/

src/thrlua.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ struct lua_longjmp {
224224
#elif LUA_ARCH_I386
225225
# define lua_do_setjmp LUA_ASMNAME(lua_setjmp_i386)
226226
# define lua_do_longjmp LUA_ASMNAME(lua_longjmp_i386)
227+
#elif LUA_ARCH_AARCH64
228+
# define lua_do_setjmp LUA_ASMNAME(lua_setjmp_aarch64)
229+
# define lua_do_longjmp LUA_ASMNAME(lua_longjmp_aarch64)
227230
#endif
228231
#ifdef lua_do_setjmp
229232
extern int lua_do_setjmp(luai_jmpbuf env);

0 commit comments

Comments
 (0)