Skip to content

Commit 40a3aa7

Browse files
janwillekedpgeorge
authored andcommitted
py/nlrmips: Add native NLR support for MIPS architecture.
This can be tested using ports/minimal and qemu: make CC=mips-linux-gnu-gcc-8 Then run with qemu-mips: stty raw opost -echo; QEMU_LD_PREFIX=/usr/mips-linux-gnu/ qemu-mips build/firmware.elf; sleep 1; reset Signed-off-by: Jan Willeke <[email protected]>
1 parent 043dc4d commit 40a3aa7

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

py/nlr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define MICROPY_NLR_NUM_REGS_ARM_THUMB (10)
4141
#define MICROPY_NLR_NUM_REGS_ARM_THUMB_FP (10 + 6)
4242
#define MICROPY_NLR_NUM_REGS_AARCH64 (13)
43+
#define MICROPY_NLR_NUM_REGS_MIPS (13)
4344
#define MICROPY_NLR_NUM_REGS_XTENSA (10)
4445
#define MICROPY_NLR_NUM_REGS_XTENSAWIN (17)
4546

@@ -83,6 +84,9 @@
8384
#define MICROPY_NLR_POWERPC (1)
8485
// this could be less but using 128 for safety
8586
#define MICROPY_NLR_NUM_REGS (128)
87+
#elif defined(__mips__)
88+
#define MICROPY_NLR_MIPS (1)
89+
#define MICROPY_NLR_NUM_REGS (MICROPY_NLR_NUM_REGS_MIPS)
8690
#else
8791
#define MICROPY_NLR_SETJMP (1)
8892
//#warning "No native NLR support for this arch, using setjmp implementation"

py/nlrmips.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-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_MIPS
30+
31+
__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr);
32+
33+
__asm(
34+
".globl nlr_push \n"
35+
"nlr_push: \n"
36+
".ent nlr_push \n"
37+
".frame $29, 0, $31 \n"
38+
".set noreorder \n"
39+
".cpload $25 \n"
40+
".set reorder \n"
41+
"sw $31, 8($4) \n" /* is the offset of regs in nlr_buf_t */
42+
"sw $30, 12($4) \n"
43+
"sw $29, 16($4) \n"
44+
"sw $28, 20($4) \n"
45+
"sw $23, 24($4) \n"
46+
"sw $22, 28($4) \n"
47+
"sw $21, 32($4) \n"
48+
"sw $20, 36($4) \n"
49+
"sw $19, 40($4) \n"
50+
"sw $18, 44($4) \n"
51+
"sw $17, 48($4) \n"
52+
"sw $16, 52($4) \n"
53+
#ifdef __pic__
54+
"la $25, nlr_push_tail \n"
55+
#endif
56+
"j nlr_push_tail \n"
57+
".end nlr_push \n"
58+
);
59+
60+
NORETURN void nlr_jump(void *val) {
61+
MP_NLR_JUMP_HEAD(val, top)
62+
__asm(
63+
"move $4, %0 \n"
64+
"lw $31, 8($4) \n"
65+
"lw $30, 12($4) \n"
66+
"lw $29, 16($4) \n"
67+
"lw $28, 20($4) \n"
68+
"lw $23, 24($4) \n"
69+
"lw $22, 28($4) \n"
70+
"lw $21, 32($4) \n"
71+
"lw $20, 36($4) \n"
72+
"lw $19, 40($4) \n"
73+
"lw $18, 44($4) \n"
74+
"lw $17, 48($4) \n"
75+
"lw $16, 52($4) \n"
76+
"lui $2,1 \n" // set return value 1
77+
"j $31 \n"
78+
"nop \n"
79+
:
80+
: "r" (top)
81+
:
82+
);
83+
MP_UNREACHABLE
84+
}
85+
86+
#endif // MICROPY_NLR_MIPS

py/py.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ set(MICROPY_SOURCE_PY
5353
${MICROPY_PY_DIR}/mpz.c
5454
${MICROPY_PY_DIR}/nativeglue.c
5555
${MICROPY_PY_DIR}/nlr.c
56+
${MICROPY_PY_DIR}/nlrmips.c
5657
${MICROPY_PY_DIR}/nlrpowerpc.c
5758
${MICROPY_PY_DIR}/nlrsetjmp.c
5859
${MICROPY_PY_DIR}/nlrthumb.c

py/py.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ PY_CORE_O_BASENAME = $(addprefix py/,\
8080
nlrx64.o \
8181
nlrthumb.o \
8282
nlraarch64.o \
83+
nlrmips.o \
8384
nlrpowerpc.o \
8485
nlrxtensa.o \
8586
nlrsetjmp.o \

0 commit comments

Comments
 (0)