Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [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) 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 | |
| 27 | #if defined(__xtensa__) |
| 28 | |
| 29 | /* |
| 30 | calling conventions: |
| 31 | a0 = return address |
| 32 | a1 = stack pointer |
| 33 | a2 = first arg, return value |
| 34 | a3-a7 = rest of args |
| 35 | */ |
| 36 | |
Damien George | b4b10fd | 2015-01-01 23:30:53 +0000 | [diff] [blame] | 37 | // the offset of nlr_top within mp_state_ctx_t |
| 38 | #define NLR_TOP_OFFSET (2 * 4) |
| 39 | |
| 40 | #define NLR_TOP (mp_state_ctx + NLR_TOP_OFFSET) |
| 41 | |
Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [diff] [blame] | 42 | .file "nlr.s" |
| 43 | .text |
| 44 | |
| 45 | .literal_position |
Damien George | b4b10fd | 2015-01-01 23:30:53 +0000 | [diff] [blame] | 46 | .literal .LC0, NLR_TOP |
Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [diff] [blame] | 47 | .align 4 |
| 48 | .global nlr_push |
| 49 | .type nlr_push, @function |
| 50 | nlr_push: |
| 51 | // save regs |
| 52 | s32i.n a0, a2, 8 |
| 53 | s32i.n a1, a2, 12 |
| 54 | s32i.n a8, a2, 16 |
| 55 | s32i.n a9, a2, 20 |
| 56 | s32i.n a10, a2, 24 |
| 57 | s32i.n a11, a2, 28 |
| 58 | s32i.n a12, a2, 32 |
| 59 | s32i.n a13, a2, 36 |
| 60 | s32i.n a14, a2, 40 |
| 61 | s32i.n a15, a2, 44 |
| 62 | |
| 63 | l32r a3, .LC0 |
| 64 | l32i.n a4, a3, 0 |
| 65 | s32i.n a2, a3, 0 |
| 66 | s32i.n a4, a2, 0 |
| 67 | movi.n a2, 0 |
| 68 | ret.n |
| 69 | .size nlr_push, .-nlr_push |
| 70 | |
| 71 | .literal_position |
Damien George | b4b10fd | 2015-01-01 23:30:53 +0000 | [diff] [blame] | 72 | .literal .LC1, NLR_TOP |
Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [diff] [blame] | 73 | .align 4 |
| 74 | .global nlr_pop |
| 75 | .type nlr_pop, @function |
| 76 | nlr_pop: |
| 77 | l32r a2, .LC1 |
| 78 | l32i.n a3, a2, 0 |
| 79 | l32i.n a3, a3, 0 |
| 80 | s32i.n a3, a2, 0 |
| 81 | ret.n |
| 82 | .size nlr_pop, .-nlr_pop |
| 83 | |
| 84 | .literal_position |
Damien George | b4b10fd | 2015-01-01 23:30:53 +0000 | [diff] [blame] | 85 | .literal .LC2, NLR_TOP |
Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [diff] [blame] | 86 | .align 4 |
| 87 | .global nlr_jump |
| 88 | .type nlr_jump, @function |
| 89 | nlr_jump: |
| 90 | l32r a3, .LC2 |
| 91 | l32i.n a3, a3, 0 // a3 = nlr_top |
| 92 | bnez.n a3, .L4 |
| 93 | call0 nlr_jump_fail |
| 94 | .L4: |
| 95 | s32i.n a2, a3, 4 // nlr_top->ret_val = val |
| 96 | |
| 97 | // restore regs |
| 98 | l32i.n a0, a3, 8 |
| 99 | l32i.n a1, a3, 12 |
| 100 | l32i.n a8, a3, 16 |
| 101 | l32i.n a9, a3, 20 |
| 102 | l32i.n a10, a3, 24 |
| 103 | l32i.n a11, a3, 28 |
| 104 | l32i.n a12, a3, 32 |
| 105 | l32i.n a13, a3, 36 |
| 106 | l32i.n a14, a3, 40 |
| 107 | l32i.n a15, a3, 44 |
| 108 | |
| 109 | l32i.n a3, a3, 0 // a3 = nlr_top->prev |
| 110 | l32r a2, .LC2 |
| 111 | s32i.n a3, a2, 0 // nlr_top = a3 |
| 112 | movi.n a2, 1 // return 1 |
| 113 | ret.n |
| 114 | .size nlr_jump, .-nlr_jump |
| 115 | |
Damien George | 2399aa0 | 2014-11-27 20:29:33 +0000 | [diff] [blame] | 116 | #endif // defined(__xtensa__) |