Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013, 2014 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 27 | #if !MICROPY_NLR_SETJMP && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__)) |
| 28 | /* arm callee save: bx, bp, sp, r12, r14, r14, r15 */ |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 29 | |
| 30 | .syntax unified |
Paul Sokolovsky | 9c7e984 | 2014-02-27 18:03:37 +0200 | [diff] [blame] | 31 | /*.cpu cortex-m4*/ |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 32 | /*.thumb*/ |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 33 | .text |
| 34 | .align 2 |
| 35 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 36 | /* uint nlr_push(r0=nlr_buf_t *nlr) */ |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 37 | .global nlr_push |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 38 | #if defined(__thumb2__) |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 39 | .thumb |
| 40 | .thumb_func |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 41 | #endif |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 42 | .type nlr_push, %function |
| 43 | nlr_push: |
| 44 | str lr, [r0, #8] @ store lr into nlr_buf |
| 45 | str r4, [r0, #12] @ store r4 into nlr_buf |
| 46 | str r5, [r0, #16] @ store r5 into nlr_buf |
| 47 | str r6, [r0, #20] @ store r6 into nlr_buf |
| 48 | str r7, [r0, #24] @ store r7 into nlr_buf |
| 49 | str r8, [r0, #28] @ store r8 into nlr_buf |
| 50 | str r9, [r0, #32] @ store r9 into nlr_buf |
| 51 | str r10, [r0, #36] @ store r10 into nlr_buf |
| 52 | str r11, [r0, #40] @ store r11 into nlr_buf |
| 53 | str r13, [r0, #44] @ store r13=sp into nlr_buf |
| 54 | |
| 55 | ldr r3, .L2 @ load addr of nlr_top |
| 56 | ldr r2, [r3] @ load nlr_top |
| 57 | str r2, [r0] @ store nlr_top into nlr_buf |
| 58 | str r0, [r3] @ store nlr_buf into nlr_top (to link list) |
| 59 | |
| 60 | movs r0, #0 @ return 0, normal return |
| 61 | bx lr @ return |
| 62 | .align 2 |
| 63 | .L2: |
| 64 | .word .LANCHOR0 |
| 65 | .size nlr_push, .-nlr_push |
| 66 | |
| 67 | @ void nlr_pop() |
| 68 | .global nlr_pop |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 69 | #if defined(__thumb2__) |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 70 | .thumb |
| 71 | .thumb_func |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 72 | #endif |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 73 | .type nlr_pop, %function |
| 74 | nlr_pop: |
| 75 | ldr r3, .L5 @ load addr of nlr_top |
| 76 | ldr r2, [r3] @ load nlr_top |
| 77 | ldr r2, [r2] @ load prev nlr_buf |
| 78 | str r2, [r3] @ store prev nlr_buf to nlr_top (to unlink list) |
| 79 | bx lr @ return |
| 80 | .align 2 |
| 81 | .L5: |
| 82 | .word .LANCHOR0 |
| 83 | .size nlr_pop, .-nlr_pop |
| 84 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 85 | /* void nlr_jump(r0=uint val) */ |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 86 | .global nlr_jump |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 87 | #if defined(__thumb2__) |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 88 | .thumb |
| 89 | .thumb_func |
Paul Sokolovsky | a96cc82 | 2014-06-22 01:14:28 +0300 | [diff] [blame] | 90 | #endif |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 91 | .type nlr_jump, %function |
| 92 | nlr_jump: |
| 93 | ldr r3, .L2 @ load addr of nlr_top |
| 94 | ldr r2, [r3] @ load nlr_top |
Damien George | 26cf55a | 2014-04-08 14:08:14 +0000 | [diff] [blame] | 95 | cmp r2, #0 @ test if nlr_top is NULL |
| 96 | beq nlr_jump_fail @ if nlr_top is NULL, transfer control to nlr_jump_fail |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 97 | str r0, [r2, #4] @ store return value |
| 98 | ldr r0, [r2] @ load prev nlr_buf |
| 99 | str r0, [r3] @ store prev nol_buf into nlr_top (to unlink list) |
| 100 | |
| 101 | ldr lr, [r2, #8] @ load lr from nlr_buf |
| 102 | ldr r4, [r2, #12] @ load r4 from nlr_buf |
| 103 | ldr r5, [r2, #16] @ load r5 from nlr_buf |
| 104 | ldr r6, [r2, #20] @ load r6 from nlr_buf |
| 105 | ldr r7, [r2, #24] @ load r7 from nlr_buf |
| 106 | ldr r8, [r2, #28] @ load r8 from nlr_buf |
| 107 | ldr r9, [r2, #32] @ load r9 from nlr_buf |
| 108 | ldr r10, [r2, #36] @ load r10 from nlr_buf |
| 109 | ldr r11, [r2, #40] @ load r11 from nlr_buf |
| 110 | ldr r13, [r2, #44] @ load r13=sp from nlr_buf |
| 111 | |
| 112 | movs r0, #1 @ return 1, non-local return |
| 113 | bx lr @ return |
| 114 | .align 2 |
| 115 | .L6: |
| 116 | .word .LANCHOR0 |
| 117 | .size nlr_jump, .-nlr_jump |
| 118 | |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 119 | /* local variable nlr_top */ |
Damien | 152568b | 2013-10-16 00:46:39 +0100 | [diff] [blame] | 120 | .bss |
| 121 | .align 2 |
| 122 | .set .LANCHOR0,. + 0 |
| 123 | .type nlr_top, %object |
| 124 | .size nlr_top, 4 |
| 125 | nlr_top: |
| 126 | .space 4 |
Paul Sokolovsky | e85c389 | 2013-12-30 03:38:32 +0200 | [diff] [blame] | 127 | #endif |