|
| 1 | +#include "platform.h" |
| 2 | + |
| 3 | + # size of each hart's stack is 1024 bytes |
| 4 | + .equ STACK_SIZE, 1024 |
| 5 | + |
| 6 | + .global _start |
| 7 | + |
| 8 | + .text |
| 9 | +_start: # <- asm program start from the 1st instructions |
| 10 | + # park harts with id != 0 |
| 11 | + # csrr (csr read), csrr rd, csr |
| 12 | + # csrw (csr write), csrw csr, rs |
| 13 | + # m-hard-id |
| 14 | + csrr t0, mhartid # read current m-hart-id to t0 |
| 15 | + mv tp, t0 # keep CPU's hartid in its tp for later usage. |
| 16 | + bnez t0, park # branch to park if t0 not equal to zero |
| 17 | + |
| 18 | + # Setup stacks, the stack grows from bottom to top, so we put the |
| 19 | + # stack pointer to the very end of the stack range. |
| 20 | + # slli (shift left logical immediate): slli rd, rs, imm: rd = rs1 << imm |
| 21 | + slli t0, t0, 10 # shift left the hart id by 1024 |
| 22 | + # la (load address): la rd, label |
| 23 | + la sp, stacks + STACK_SIZE # set the initial stack pointer |
| 24 | + # to the end of the first stack space |
| 25 | + # add rd, rs1, rs2: rd = rs1 + rs2 |
| 26 | + add sp, sp, t0 # move the current hart stack pointer |
| 27 | + # to its place in the stack space |
| 28 | + # jump |
| 29 | + j start_kernel # hart 0 jump to kernal.c |
| 30 | + |
| 31 | +park: |
| 32 | + wfi # wait for interrupt |
| 33 | + j park # jump to park (dead loops) |
| 34 | + |
| 35 | + # In the standard RISC-V calling convention, the stack pointer sp |
| 36 | + # is always 16-byte aligned. |
| 37 | +.balign 16 |
| 38 | +stacks: |
| 39 | + .skip STACK_SIZE * MAXNUM_CPU # allocate space for all the harts stacks |
| 40 | + |
| 41 | + .end # End of file |
0 commit comments