Last active
September 17, 2018 10:01
-
-
Save ilebedev/2d50c5603fec9d711318afe3fb24a0ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.global reset_vector | |
reset_vector: | |
la sp, m_stack_ptr # sp for hart 0 (to be adjusted for other harts) | |
csrr a0, mhartid # a0 <-- mhartid | |
# 2. All but hart 0 wait for a signal via IPI. Hart 0 proceeds, and will wake other harts. | |
bne a0, zero, .hart_non_zero # hart 0 | |
# 2. Erase DRAM (if applicable) | |
#ifdef ERASE_DRAM | |
li t0, DRAM_BASE | |
li t1, DRAM_SIZE | |
add t1, t1, t0 # t1 <-- top of DRAM | |
.dram_erase_loop: | |
sd x0, -8(t1) | |
sd x0, -16(t1) | |
sd x0, -24(t1) | |
sd x0, -32(t1) | |
sd x0, -40(t1) | |
sd x0, -48(t1) | |
sd x0, -56(t1) | |
sd x0, -64(t1) | |
addi t1, t1, -64 | |
blt t0, t1, .dram_erase_loop | |
#endif | |
# 3. Ask host to load ELF into DRAM | |
# request elf from host | |
li t0, MEM_LOADER_BASE | |
li t1, DRAM_BASE | |
sw t1, 0(t0) # NOTE this may differ from system to system | |
fence # make sure the requet goes out | |
# wait for host to finish | |
.wait_on_elf: | |
ld t1, 8(t0) | |
bnez t1, .wait_on_elf | |
# 4. Run bootloader C routines | |
call rot_bootloader # performs steps 5,6,7,8 as described below | |
# ... additional instructions shown in a later section | |
.hart_non_zero: | |
# Adjust stack pointer for this hart | |
li t0, M_STACK_SIZE | |
mul t0, t0, a0 # offset = mhartid * M_STACK_SIZE | |
sub sp, sp, t0 # sp -= offset | |
# Enable IPI to wait on | |
la t0, .rot_wake_on_ipi | |
csrw mtvec, t0 | |
csrsi mie, 8 | |
csrsi mstatus, 8 | |
# Wait for an IPI from core 0 | |
.wait_on_ipi: | |
wfi | |
j .wait_on_ipi | |
# --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment