Debian Codegraph @

ports/qemu/mcu/rv32/entrypoint.s

raw
1 /*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2023 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 .section .start
28 .option norvc /* Do not emit compressed instructions. */
29 .type start, @function
30 .global start
31
32 start:
33 .cfi_startproc
34
35 .option push
36 .option norelax
37 la gp, _global_pointer /* Load global pointer register. */
38 .option pop
39
40 csrw satp, zero /* Disable supervisor mode. */
41
42 /* Fill stack with a canary value. */
43
44 li t0, 0xBBBBBBBB /* Load canary value. */
45 la t1, _sstack /* Load stack area start address. */
46 la t2, _estack /* Load stack area end address. */
47 1:
48 sw t0, (t1) /* Write canary. */
49 addi t1, t1, 4 /* Next word. */
50 bltu t1, t2, 1b /* Loop until stack is filled. */
51
52 la sp, _estack /* Load stack pointer. */
53
54 /* Clear BSS area. */
55
56 la t1, _sbss /* Load BSS area start address. */
57 la t2, _ebss /* Load BSS area end address. */
58 1:
59 sw zero, (t1) /* Clear word. */
60 addi t1, t1, 4 /* Next word. */
61 bltu t1, t2, 1b /* Loop until BSS is cleared. */
62
63 /* Set program counter. */
64
65 la t0, _entry_point /* Load program counter address. */
66 csrw mepc, t0 /* Store it into machine exception PC. */
67 tail _entry_point /* Jump to entry point. */
68
69 .cfi_endproc
70 .end