Commit 8a234772 authored by Damien George's avatar Damien George
Browse files

py: Move global variable nlr_top to one place, in a .c file.

This reduces dependency on assembler, and allows to consolidate global
variables in the future.
parent 0b2a60ac
...@@ -64,13 +64,14 @@ struct _nlr_buf_t { ...@@ -64,13 +64,14 @@ struct _nlr_buf_t {
#endif #endif
}; };
extern nlr_buf_t *nlr_top;
#if MICROPY_NLR_SETJMP #if MICROPY_NLR_SETJMP
extern nlr_buf_t *nlr_setjmp_top;
NORETURN void nlr_setjmp_jump(void *val); NORETURN void nlr_setjmp_jump(void *val);
// nlr_push() must be defined as a macro, because "The stack context will be // nlr_push() must be defined as a macro, because "The stack context will be
// invalidated if the function which called setjmp() returns." // invalidated if the function which called setjmp() returns."
#define nlr_push(buf) ((buf)->prev = nlr_setjmp_top, nlr_setjmp_top = (buf), setjmp((buf)->jmpbuf)) #define nlr_push(buf) ((buf)->prev = nlr_top, nlr_top = (buf), setjmp((buf)->jmpbuf))
#define nlr_pop() { nlr_setjmp_top = nlr_setjmp_top->prev; } #define nlr_pop() { nlr_top = nlr_top->prev; }
#define nlr_jump(val) nlr_setjmp_jump(val) #define nlr_jump(val) nlr_setjmp_jump(val)
#else #else
unsigned int nlr_push(nlr_buf_t *); unsigned int nlr_push(nlr_buf_t *);
......
...@@ -26,13 +26,14 @@ ...@@ -26,13 +26,14 @@
#include "py/nlr.h" #include "py/nlr.h"
#if MICROPY_NLR_SETJMP // this global variable is used for all nlr implementations
nlr_buf_t *nlr_top;
nlr_buf_t *nlr_setjmp_top; #if MICROPY_NLR_SETJMP
void nlr_setjmp_jump(void *val) { void nlr_setjmp_jump(void *val) {
nlr_buf_t *buf = nlr_setjmp_top; nlr_buf_t *buf = nlr_top;
nlr_setjmp_top = buf->prev; nlr_top = buf->prev;
buf->ret_val = val; buf->ret_val = val;
longjmp(buf->jmpbuf, 1); longjmp(buf->jmpbuf, 1);
} }
......
...@@ -59,7 +59,7 @@ nlr_push: ...@@ -59,7 +59,7 @@ nlr_push:
str r11, [r0, #40] @ store r11 into nlr_buf str r11, [r0, #40] @ store r11 into nlr_buf
str r13, [r0, #44] @ store r13=sp into nlr_buf str r13, [r0, #44] @ store r13=sp into nlr_buf
ldr r3, .L2 @ load addr of nlr_top ldr r3, nlr_top_addr @ load addr of nlr_top
ldr r2, [r3] @ load nlr_top ldr r2, [r3] @ load nlr_top
str r2, [r0] @ store nlr_top into nlr_buf str r2, [r0] @ store nlr_top into nlr_buf
str r0, [r3] @ store nlr_buf into nlr_top (to link list) str r0, [r3] @ store nlr_buf into nlr_top (to link list)
...@@ -67,8 +67,8 @@ nlr_push: ...@@ -67,8 +67,8 @@ nlr_push:
movs r0, #0 @ return 0, normal return movs r0, #0 @ return 0, normal return
bx lr @ return bx lr @ return
.align 2 .align 2
.L2: nlr_top_addr:
.word .LANCHOR0 .word nlr_top
.size nlr_push, .-nlr_push .size nlr_push, .-nlr_push
/**************************************/ /**************************************/
...@@ -81,14 +81,11 @@ nlr_push: ...@@ -81,14 +81,11 @@ nlr_push:
#endif #endif
.type nlr_pop, %function .type nlr_pop, %function
nlr_pop: nlr_pop:
ldr r3, .L5 @ load addr of nlr_top ldr r3, nlr_top_addr @ load addr of nlr_top
ldr r2, [r3] @ load nlr_top ldr r2, [r3] @ load nlr_top
ldr r2, [r2] @ load prev nlr_buf ldr r2, [r2] @ load prev nlr_buf
str r2, [r3] @ store prev nlr_buf to nlr_top (to unlink list) str r2, [r3] @ store prev nlr_buf to nlr_top (to unlink list)
bx lr @ return bx lr @ return
.align 2
.L5:
.word .LANCHOR0
.size nlr_pop, .-nlr_pop .size nlr_pop, .-nlr_pop
/**************************************/ /**************************************/
...@@ -101,7 +98,7 @@ nlr_pop: ...@@ -101,7 +98,7 @@ nlr_pop:
#endif #endif
.type nlr_jump, %function .type nlr_jump, %function
nlr_jump: nlr_jump:
ldr r3, .L2 @ load addr of nlr_top ldr r3, nlr_top_addr @ load addr of nlr_top
ldr r2, [r3] @ load nlr_top ldr r2, [r3] @ load nlr_top
cmp r2, #0 @ test if nlr_top is NULL cmp r2, #0 @ test if nlr_top is NULL
beq nlr_jump_fail @ if nlr_top is NULL, transfer control to nlr_jump_fail beq nlr_jump_fail @ if nlr_top is NULL, transfer control to nlr_jump_fail
...@@ -122,20 +119,6 @@ nlr_jump: ...@@ -122,20 +119,6 @@ nlr_jump:
movs r0, #1 @ return 1, non-local return movs r0, #1 @ return 1, non-local return
bx lr @ return bx lr @ return
.align 2
.L6:
.word .LANCHOR0
.size nlr_jump, .-nlr_jump .size nlr_jump, .-nlr_jump
/**************************************/
// local variable nlr_top
.bss
.align 2
.set .LANCHOR0,. + 0
.type nlr_top, %object
.size nlr_top, 4
nlr_top:
.space 4
#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__)) #endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
...@@ -131,15 +131,6 @@ nlr_jump: ...@@ -131,15 +131,6 @@ nlr_jump:
je _nlr_jump_fail # transfer control to nlr_jump_fail je _nlr_jump_fail # transfer control to nlr_jump_fail
#endif #endif
/**************************************/
// local variable nlr_top
#if !(defined(__APPLE__) && defined(__MACH__))
.bss
.local nlr_top
#endif
.comm nlr_top,8,8
#else // !defined(__CYGWIN__) #else // !defined(__CYGWIN__)
/******************************************************************************/ /******************************************************************************/
...@@ -210,12 +201,6 @@ nlr_jump: ...@@ -210,12 +201,6 @@ nlr_jump:
movq %rax, %rcx # put argument back in first-arg register movq %rax, %rcx # put argument back in first-arg register
je nlr_jump_fail # transfer control to nlr_jump_fail je nlr_jump_fail # transfer control to nlr_jump_fail
/**************************************/
// local variable nlr_top
.bss
.comm nlr_top,8,8
#endif // !defined(__CYGWIN__) #endif // !defined(__CYGWIN__)
#endif // defined(__x86_64__) && !MICROPY_NLR_SETJMP #endif // defined(__x86_64__) && !MICROPY_NLR_SETJMP
...@@ -121,13 +121,4 @@ nlr_jump: ...@@ -121,13 +121,4 @@ nlr_jump:
.size nlr_jump, .-nlr_jump .size nlr_jump, .-nlr_jump
#endif #endif
/**************************************/
// local variable nlr_top
.bss
#ifndef _WIN32
.local nlr_top
#endif
.comm nlr_top,4,4
#endif // defined(__i386__) && !MICROPY_NLR_SETJMP #endif // defined(__i386__) && !MICROPY_NLR_SETJMP
...@@ -108,7 +108,4 @@ nlr_jump: ...@@ -108,7 +108,4 @@ nlr_jump:
ret.n ret.n
.size nlr_jump, .-nlr_jump .size nlr_jump, .-nlr_jump
.local nlr_top
.comm nlr_top,4,4
#endif // defined(__xtensa__) #endif // defined(__xtensa__)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment