Numworks Epsilon  1.4.1
Graphing Calculator Operating System
nlrxtensa.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2014-2017 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 #include "py/mpstate.h"
28 
29 #if !MICROPY_NLR_SETJMP && defined(__xtensa__)
30 
31 #undef nlr_push
32 
33 // Xtensa calling conventions:
34 // a0 = return address
35 // a1 = stack pointer
36 // a2 = first arg, return value
37 // a3-a7 = rest of args
38 
39 unsigned int nlr_push(nlr_buf_t *nlr) {
40 
41  __asm volatile (
42  "s32i.n a0, a2, 8 \n" // save regs...
43  "s32i.n a1, a2, 12 \n"
44  "s32i.n a8, a2, 16 \n"
45  "s32i.n a9, a2, 20 \n"
46  "s32i.n a10, a2, 24 \n"
47  "s32i.n a11, a2, 28 \n"
48  "s32i.n a12, a2, 32 \n"
49  "s32i.n a13, a2, 36 \n"
50  "s32i.n a14, a2, 40 \n"
51  "s32i.n a15, a2, 44 \n"
52  "j nlr_push_tail \n" // do the rest in C
53  );
54 
55  return 0; // needed to silence compiler warning
56 }
57 
58 __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) {
59  nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
60  nlr->prev = *top;
61  *top = nlr;
62  return 0; // normal return
63 }
64 
65 void nlr_pop(void) {
66  nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
67  *top = (*top)->prev;
68 }
69 
70 NORETURN void nlr_jump(void *val) {
71  nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
72  nlr_buf_t *top = *top_ptr;
73  if (top == NULL) {
74  nlr_jump_fail(val);
75  }
76 
77  top->ret_val = val;
78  *top_ptr = top->prev;
79 
80  __asm volatile (
81  "mov.n a2, %0 \n" // a2 points to nlr_buf
82  "l32i.n a0, a2, 8 \n" // restore regs...
83  "l32i.n a1, a2, 12 \n"
84  "l32i.n a8, a2, 16 \n"
85  "l32i.n a9, a2, 20 \n"
86  "l32i.n a10, a2, 24 \n"
87  "l32i.n a11, a2, 28 \n"
88  "l32i.n a12, a2, 32 \n"
89  "l32i.n a13, a2, 36 \n"
90  "l32i.n a14, a2, 40 \n"
91  "l32i.n a15, a2, 44 \n"
92  "movi.n a2, 1 \n" // return 1, non-local return
93  "ret.n \n" // return
94  : // output operands
95  : "r"(top) // input operands
96  : // clobbered registers
97  );
98 
99  for (;;); // needed to silence compiler warning
100 }
101 
102 #endif // !MICROPY_NLR_SETJMP && defined(__xtensa__)
#define nlr_push(buf)
Definition: nlr.h:73
#define MP_STATE_THREAD(x)
Definition: mpstate.h:248
#define NULL
Definition: stddef.h:4
nlr_buf_t * prev
Definition: nlr.h:41
#define NORETURN
Definition: mpconfig.h:1268
#define nlr_pop()
Definition: nlr.h:74
void * ret_val
Definition: nlr.h:42
void nlr_jump_fail(void *val)
Definition: port.cpp:142
Definition: nlr.h:39
ISR InitialisationVector [INITIALISATION_VECTOR_SIZE] __attribute__((section(".isr_vector_table")))
#define nlr_jump(val)
Definition: nlr.h:75