Skip to content

Commit

Permalink
py: Clean up nlr*.S to make it easier to read; fix clang .bss error.
Browse files Browse the repository at this point in the history
It seems that newer versions of clang don't like the .bss directive, so
we don't use it for OSX.

Addressing issues #865 and #875.
  • Loading branch information
dpgeorge committed Sep 26, 2014
1 parent b766e79 commit 133b083
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 24 deletions.
26 changes: 20 additions & 6 deletions py/nlrthumb.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@
*/

#if !MICROPY_NLR_SETJMP && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
/* arm callee save: bx, bp, sp, r12, r14, r14, r15 */

// We only need the functions here if we are on arm/thumb, and we are not
// using setjmp/longjmp.
//
// For reference, arm/thumb callee save regs are:
// r4-r11, r13=sp

.syntax unified
/*.cpu cortex-m4*/
/*.thumb*/
.text
.align 2

/* uint nlr_push(r0=nlr_buf_t *nlr) */
/**************************************/
// mp_uint_t nlr_push(r0=nlr_buf_t *nlr)

.global nlr_push
#if defined(__thumb2__)
.thumb
Expand Down Expand Up @@ -64,7 +71,9 @@ nlr_push:
.word .LANCHOR0
.size nlr_push, .-nlr_push

@ void nlr_pop()
/**************************************/
// void nlr_pop()

.global nlr_pop
#if defined(__thumb2__)
.thumb
Expand All @@ -82,7 +91,9 @@ nlr_pop:
.word .LANCHOR0
.size nlr_pop, .-nlr_pop

/* void nlr_jump(r0=uint val) */
/**************************************/
// void nlr_jump(r0=mp_uint_t val)

.global nlr_jump
#if defined(__thumb2__)
.thumb
Expand Down Expand Up @@ -116,12 +127,15 @@ nlr_jump:
.word .LANCHOR0
.size nlr_jump, .-nlr_jump

/* local variable nlr_top */
/**************************************/
// local variable nlr_top

.bss
.align 2
.set .LANCHOR0,. + 0
.type nlr_top, %object
.size nlr_top, 4
nlr_top:
.space 4
#endif

#endif // !MICROPY_NLR_SETJMP && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
60 changes: 47 additions & 13 deletions py/nlrx64.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,28 @@
*/

#if defined(__x86_64__) && !MICROPY_NLR_SETJMP
/* x64 callee save: bx, bp, sp, r12, r13, r14, r15 */

// We only need the functions here if we are on x86-64, and we are not
// using setjmp/longjmp.
//
// For reference, x86-64 callee save regs are:
// rbx, rbp, rsp, r12, r13, r14, r15

.file "nlr.s"
.text

#if !defined(__CYGWIN__)

#if (defined(__APPLE__) && defined(__MACH__))
#define nlr_jump_fail _nlr_jump_fail
#endif // (defined(__APPLE__) && defined(__MACH__))
/******************************************************************************/
//
// Functions for *nix and OSX.
// OSX needs _ prefix for binding to C, and doesn't support some directives.
//
/******************************************************************************/

/**************************************/
// mp_uint_t nlr_push(rdi=nlr_buf_t *nlr)

/* uint nlr_push(rdi=nlr_buf_t *nlr) */
#if !(defined(__APPLE__) && defined(__MACH__))
.globl nlr_push
.type nlr_push, @function
Expand All @@ -63,7 +73,9 @@ _nlr_push:
.size nlr_push, .-nlr_push
#endif

/* void nlr_pop() */
/**************************************/
// void nlr_pop()

#if !(defined(__APPLE__) && defined(__MACH__))
.globl nlr_pop
.type nlr_pop, @function
Expand All @@ -80,7 +92,9 @@ _nlr_pop:
.size nlr_pop, .-nlr_pop
#endif

/* void nlr_jump(rdi=uint val) */
/**************************************/
// void nlr_jump(rdi=mp_uint_t val)

#if !(defined(__APPLE__) && defined(__MACH__))
.globl nlr_jump
.type nlr_jump, @function
Expand Down Expand Up @@ -110,20 +124,33 @@ nlr_jump:
ret # return
.fail:
movq %rax, %rdi # put argument back in first-arg register
je nlr_jump_fail # transfer control to nlr_jump_fail
#if !(defined(__APPLE__) && defined(__MACH__))
je nlr_jump_fail # transfer control to nlr_jump_fail
.size nlr_jump, .-nlr_jump
#else
je _nlr_jump_fail # transfer control to nlr_jump_fail
#endif

.bss
/**************************************/
// local variable nlr_top

#if !(defined(__APPLE__) && defined(__MACH__))
.bss
.local nlr_top
#endif
.comm nlr_top,8,8

#else // !defined(__CYGWIN__)

/* uint nlr_push(rcx=nlr_buf_t *nlr) */
/******************************************************************************/
//
// Functions for Cygwin
//
/******************************************************************************/

/**************************************/
// mp_uint_t nlr_push(rcx=nlr_buf_t *nlr)

.globl nlr_push
nlr_push:
movq (%rsp), %rax # load return %rip
Expand All @@ -143,15 +170,19 @@ nlr_push:
xorq %rax, %rax # return 0, normal return
ret # return

/* void nlr_pop() */
/**************************************/
// void nlr_pop()

.globl nlr_pop
nlr_pop:
movq nlr_top(%rip), %rax # get nlr_top into %rax
movq (%rax), %rax # load prev nlr_buf
movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list)
ret # return

/* void nlr_jump(rcx=uint val) */
/**************************************/
// void nlr_jump(rcx=mp_uint_t val)

.globl nlr_jump
nlr_jump:
movq %rcx, %rax # put return value in %rax
Expand Down Expand Up @@ -179,9 +210,12 @@ nlr_jump:
movq %rax, %rcx # put argument back in first-arg register
je nlr_jump_fail # transfer control to nlr_jump_fail

/**************************************/
// local variable nlr_top

.bss
.comm nlr_top,8,8

#endif // !defined(__CYGWIN__)

#endif // __x86_64__
#endif // defined(__x86_64__) && !MICROPY_NLR_SETJMP
24 changes: 19 additions & 5 deletions py/nlrx86.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@
*/

#if defined(__i386__) && !MICROPY_NLR_SETJMP
/* x86 callee save: bx, di, si, bp, sp */

// We only need the functions here if we are on x86, and we are not
// using setjmp/longjmp.
//
// For reference, x86 callee save regs are:
// ebx, esi, edi, ebp, esp, eip

.file "nlr.s"
.text

/* uint nlr_push(4(%esp)=nlr_buf_t *nlr) */
/**************************************/
// mp_uint_t nlr_push(4(%esp)=nlr_buf_t *nlr)

#ifdef _WIN32
.globl _nlr_push
.def _nlr_push; .scl 2; .type 32; .endef
Expand All @@ -57,7 +64,9 @@ nlr_push:
.size nlr_push, .-nlr_push
#endif

/* void nlr_pop() */
/**************************************/
// void nlr_pop()

#ifdef _WIN32
.globl _nlr_pop
.def _nlr_pop; .scl 2; .type 32; .endef
Expand All @@ -75,7 +84,9 @@ nlr_pop:
.size nlr_pop, .-nlr_pop
#endif

/* void nlr_jump(4(%esp)=uint val) */
/**************************************/
// void nlr_jump(4(%esp)=mp_uint_t val)

#ifdef _WIN32
.globl _nlr_jump
.def _nlr_jump; .scl 2; .type 32; .endef
Expand Down Expand Up @@ -110,10 +121,13 @@ nlr_jump:
.size nlr_jump, .-nlr_jump
#endif

/**************************************/
// local variable nlr_top

.bss
#ifndef _WIN32
.local nlr_top
#endif
.comm nlr_top,4,4

#endif /* __i386__ */
#endif // defined(__i386__) && !MICROPY_NLR_SETJMP

0 comments on commit 133b083

Please sign in to comment.