8000 shared/runtime/gchelper: Add RISC-V RV32I native gchelper. · davidgiven/micropython@de0e13a · GitHub
[go: up one dir, main page]

Skip to content

Commit de0e13a

Browse files
agattidpgeorge
authored andcommitted
shared/runtime/gchelper: Add RISC-V RV32I native gchelper.
Add native gchelper support for 32 bits RISC-V RV32I targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent e6ae699 commit de0e13a

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

shared/runtime/gchelper.h

Lines changed: 2 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef uintptr_t gc_helper_regs_t[4];
4141
typedef uintptr_t gc_helper_regs_t[10];
4242
#elif defined(__aarch64__)
4343
typedef uintptr_t gc_helper_regs_t[11]; // x19-x29
44+
#elif defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen == 32)
45+
typedef uintptr_t gc_helper_regs_t[12]; // S0-S11
4446
#endif
4547

4648
#endif

shared/runtime/gchelper_generic.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,37 @@ static void gc_helper_get_regs(gc_helper_regs_t arr) {
150150
arr[10] = x29;
151151
}
152152

153+
#elif defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen == 32)
154+
155+
// Fallback implementation for RV32I, prefer gchelper_rv32i.s
156+
157+
static void gc_helper_get_regs(gc_helper_regs_t arr) {
158+
register long s0 asm ("x8");
159+
register long s1 asm ("x9");
160+
register long s2 asm ("x18");
161+
register long s3 asm ("x19");
162+
register long s4 asm ("x20");
163+
register long s5 asm ("x21");
164+
register long s6 asm ("x22");
165+
register long s7 asm ("x23");
166+
register long s8 asm ("x24");
167+
register long s9 asm ("x25");
168+
register long s10 asm ("x26");
169+
register long s11 asm ("x27");
170+
arr[0] = s0;
171+
arr[1] = s1;
172+
arr[2] = s2;
173+
arr[3] = s3;
174+
arr[4] = s4;
175+
arr[5] = s5;
176+
arr[6] = s6;
177+
arr[7] = s7;
178+
arr[8] = s8;
179+
arr[9] = s9;
180+
arr[10] = s10;
181+
arr[11] = s11;
182+
}
183+
153184
#else
154185

155186
#error "Architecture not supported for gc_helper_get_regs. Set MICROPY_GCREGS_SETJMP to use the fallback implementation."

shared/runtime/gchelper_rv32i.s

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Alessandro Gatti
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+
.global gc_helper_get_regs_and_sp
28+
.type gc_helper_get_regs_and_sp, @function
29+
30+
gc_helper_get_regs_and_sp:
31+
32+
/* Store registers into the given array. */
33+
34+
sw x8, 0(x10) /* Save S0. */
35+
sw x9, 4(x10) /* Save S1. */
36+
sw x18, 8(x10) /* Save S2. */
37+
sw x19, 12(x10) /* Save S3. */
38+
sw x20, 16(x10) /* Save S4. */
39+
sw x21, 20(x10) /* Save S5. */
40+
sw x22, 24(x10) /* Save S6. */
41+
sw x23, 28(x10) /* Save S7. */
42+
sw x24, 32(x10) /* Save S8. */
43+
sw x25, 36(x10) /* Save S9. */
44+
sw x26, 40(x10) /* Save S10. */
45+
sw x27, 44(x10) /* Save S11. */
46+
47+
/* Return the stack pointer. */
48+
49+
add x10, x0, x2
50+
jalr x0, x1, 0
51+
52+
.size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp

0 commit comments

Comments
 (0)
0