blob: c6db844f8752f51235cf412e73b32a5acdc63a8c [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
Damien George7860c2a2014-11-05 21:16:41 +000027#if (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
Damien George133b0832014-09-26 13:07:26 +000028
29// We only need the functions here if we are on arm/thumb, and we are not
30// using setjmp/longjmp.
31//
32// For reference, arm/thumb callee save regs are:
33// r4-r11, r13=sp
Damien152568b2013-10-16 00:46:39 +010034
Damien Georgeb4b10fd2015-01-01 23:30:53 +000035// the offset of nlr_top within mp_state_ctx_t
36#define NLR_TOP_OFFSET (2 * 4)
37
Damien152568b2013-10-16 00:46:39 +010038 .syntax unified
Paul Sokolovsky9c7e9842014-02-27 18:03:37 +020039 /*.cpu cortex-m4*/
Paul Sokolovskya96cc822014-06-22 01:14:28 +030040 /*.thumb*/
Damien152568b2013-10-16 00:46:39 +010041 .text
42 .align 2
43
Damien George133b0832014-09-26 13:07:26 +000044/**************************************/
45// mp_uint_t nlr_push(r0=nlr_buf_t *nlr)
46
Damien152568b2013-10-16 00:46:39 +010047 .global nlr_push
Paul Sokolovskya96cc822014-06-22 01:14:28 +030048#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010049 .thumb
50 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +030051#endif
Damien152568b2013-10-16 00:46:39 +010052 .type nlr_push, %function
53nlr_push:
54 str lr, [r0, #8] @ store lr into nlr_buf
55 str r4, [r0, #12] @ store r4 into nlr_buf
56 str r5, [r0, #16] @ store r5 into nlr_buf
57 str r6, [r0, #20] @ store r6 into nlr_buf
58 str r7, [r0, #24] @ store r7 into nlr_buf
59 str r8, [r0, #28] @ store r8 into nlr_buf
60 str r9, [r0, #32] @ store r9 into nlr_buf
61 str r10, [r0, #36] @ store r10 into nlr_buf
62 str r11, [r0, #40] @ store r11 into nlr_buf
63 str r13, [r0, #44] @ store r13=sp into nlr_buf
64
Damien George8a234772015-01-01 21:47:58 +000065 ldr r3, nlr_top_addr @ load addr of nlr_top
Damien152568b2013-10-16 00:46:39 +010066 ldr r2, [r3] @ load nlr_top
67 str r2, [r0] @ store nlr_top into nlr_buf
68 str r0, [r3] @ store nlr_buf into nlr_top (to link list)
69
70 movs r0, #0 @ return 0, normal return
71 bx lr @ return
72 .align 2
Damien George8a234772015-01-01 21:47:58 +000073nlr_top_addr:
Damien Georgeb4b10fd2015-01-01 23:30:53 +000074 .word mp_state_ctx + NLR_TOP_OFFSET
Damien152568b2013-10-16 00:46:39 +010075 .size nlr_push, .-nlr_push
76
Damien George133b0832014-09-26 13:07:26 +000077/**************************************/
78// void nlr_pop()
79
Damien152568b2013-10-16 00:46:39 +010080 .global nlr_pop
Paul Sokolovskya96cc822014-06-22 01:14:28 +030081#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010082 .thumb
83 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +030084#endif
Damien152568b2013-10-16 00:46:39 +010085 .type nlr_pop, %function
86nlr_pop:
Damien George8a234772015-01-01 21:47:58 +000087 ldr r3, nlr_top_addr @ load addr of nlr_top
Damien152568b2013-10-16 00:46:39 +010088 ldr r2, [r3] @ load nlr_top
89 ldr r2, [r2] @ load prev nlr_buf
90 str r2, [r3] @ store prev nlr_buf to nlr_top (to unlink list)
91 bx lr @ return
Damien152568b2013-10-16 00:46:39 +010092 .size nlr_pop, .-nlr_pop
93
Damien George133b0832014-09-26 13:07:26 +000094/**************************************/
95// void nlr_jump(r0=mp_uint_t val)
96
Damien152568b2013-10-16 00:46:39 +010097 .global nlr_jump
Paul Sokolovskya96cc822014-06-22 01:14:28 +030098#if defined(__thumb2__)
Damien152568b2013-10-16 00:46:39 +010099 .thumb
100 .thumb_func
Paul Sokolovskya96cc822014-06-22 01:14:28 +0300101#endif
Damien152568b2013-10-16 00:46:39 +0100102 .type nlr_jump, %function
103nlr_jump:
Damien George8a234772015-01-01 21:47:58 +0000104 ldr r3, nlr_top_addr @ load addr of nlr_top
Damien152568b2013-10-16 00:46:39 +0100105 ldr r2, [r3] @ load nlr_top
Damien George26cf55a2014-04-08 14:08:14 +0000106 cmp r2, #0 @ test if nlr_top is NULL
107 beq nlr_jump_fail @ if nlr_top is NULL, transfer control to nlr_jump_fail
Damien152568b2013-10-16 00:46:39 +0100108 str r0, [r2, #4] @ store return value
109 ldr r0, [r2] @ load prev nlr_buf
110 str r0, [r3] @ store prev nol_buf into nlr_top (to unlink list)
111
112 ldr lr, [r2, #8] @ load lr from nlr_buf
113 ldr r4, [r2, #12] @ load r4 from nlr_buf
114 ldr r5, [r2, #16] @ load r5 from nlr_buf
115 ldr r6, [r2, #20] @ load r6 from nlr_buf
116 ldr r7, [r2, #24] @ load r7 from nlr_buf
117 ldr r8, [r2, #28] @ load r8 from nlr_buf
118 ldr r9, [r2, #32] @ load r9 from nlr_buf
119 ldr r10, [r2, #36] @ load r10 from nlr_buf
120 ldr r11, [r2, #40] @ load r11 from nlr_buf
121 ldr r13, [r2, #44] @ load r13=sp from nlr_buf
122
123 movs r0, #1 @ return 1, non-local return
124 bx lr @ return
Damien152568b2013-10-16 00:46:39 +0100125 .size nlr_jump, .-nlr_jump
126
Damien George7860c2a2014-11-05 21:16:41 +0000127#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))