blob: dabf57cf85702c48fb6a34609d3d8e9056d68eb3 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
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 Sokolovskya96cc822014-06-22 01:14:28 +030027#if !MICROPY_NLR_SETJMP && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
28/* arm callee save: bx, bp, sp, r12, r14, r14, r15 */
Damien152568b2013-10-16 00:46:39 +010029
30 .syntax unified
Paul Sokolovsky9c7e9842014-02-27 18:03:37 +020031 /*.cpu cortex-m4*/
Paul Sokolovskya96cc822014-06-22 01:14:28 +030032 /*.thumb*/
Damien152568b2013-10-16 00:46:39 +010033 .text
34 .align 2
35
Paul Sokolovskye85c3892013-12-30 03:38:32 +020036/* uint nlr_push(r0=nlr_buf_t *nlr) */
Damien152568b2013-10-16 00:46:39 +010037 .global nlr_push
Paul Sokolovskya96cc822014-06-22 01:14:28 +030038#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010039 .thumb
40 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +030041#endif
Damien152568b2013-10-16 00:46:39 +010042 .type nlr_push, %function
43nlr_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 Sokolovskya96cc822014-06-22 01:14:28 +030069#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010070 .thumb
71 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +030072#endif
Damien152568b2013-10-16 00:46:39 +010073 .type nlr_pop, %function
74nlr_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 Sokolovskye85c3892013-12-30 03:38:32 +020085/* void nlr_jump(r0=uint val) */
Damien152568b2013-10-16 00:46:39 +010086 .global nlr_jump
Paul Sokolovskya96cc822014-06-22 01:14:28 +030087#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010088 .thumb
89 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +030090#endif
Damien152568b2013-10-16 00:46:39 +010091 .type nlr_jump, %function
92nlr_jump:
93 ldr r3, .L2 @ load addr of nlr_top
94 ldr r2, [r3] @ load nlr_top
Damien George26cf55a2014-04-08 14:08:14 +000095 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
Damien152568b2013-10-16 00:46:39 +010097 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 Sokolovskye85c3892013-12-30 03:38:32 +0200119/* local variable nlr_top */
Damien152568b2013-10-16 00:46:39 +0100120 .bss
121 .align 2
122 .set .LANCHOR0,. + 0
123 .type nlr_top, %object
124 .size nlr_top, 4
125nlr_top:
126 .space 4
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200127#endif