2018-10-14 17:12:01 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 Travis Geiselbrecht
|
|
|
|
|
*
|
2019-07-05 17:22:23 -07:00
|
|
|
* Use of this source code is governed by a MIT-style
|
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
|
* https://opensource.org/licenses/MIT
|
2018-10-14 17:12:01 -07:00
|
|
|
*/
|
2019-06-17 18:28:51 -07:00
|
|
|
#include <lk/asm.h>
|
2019-12-04 09:08:57 -08:00
|
|
|
#include <arch/defines.h>
|
|
|
|
|
#include "config.h"
|
2018-10-14 17:12:01 -07:00
|
|
|
|
|
|
|
|
.section ".text.boot"
|
|
|
|
|
FUNCTION(_start)
|
2019-02-17 18:55:42 -08:00
|
|
|
.option push
|
|
|
|
|
.option norelax
|
2019-11-02 18:13:02 -07:00
|
|
|
// set the global pointer
|
2019-02-17 18:55:42 -08:00
|
|
|
la gp, __global_pointer$
|
|
|
|
|
.option pop
|
|
|
|
|
|
2019-11-02 18:13:02 -07:00
|
|
|
// if our hart isnt 0, trap the cpu
|
|
|
|
|
csrr t0, mhartid
|
|
|
|
|
|
|
|
|
|
// set the default stack
|
2018-10-14 17:12:01 -07:00
|
|
|
la sp, default_stack_top
|
2019-12-04 09:08:57 -08:00
|
|
|
// default stack locations for each hart:
|
|
|
|
|
// LOW ------------ HIGH
|
|
|
|
|
// [hart2][hart1][hart0]
|
|
|
|
|
li t1, ARCH_DEFAULT_STACK_SIZE
|
|
|
|
|
mul t1, t1, a0
|
|
|
|
|
sub sp, sp, t1
|
|
|
|
|
|
|
|
|
|
// everyone stores zero in _boot_status
|
|
|
|
|
la t5, _boot_status
|
|
|
|
|
sw zero, (t5)
|
|
|
|
|
|
|
|
|
|
bnez t0, .Lsecondary_trap
|
2018-10-14 17:12:01 -07:00
|
|
|
|
2019-11-02 17:21:13 -07:00
|
|
|
#if ARCH_RISCV_TWOSEGMENT
|
2019-11-02 18:13:02 -07:00
|
|
|
// copy preinitialized data from flash to memory
|
2018-10-14 17:12:01 -07:00
|
|
|
la t0, __data_start_rom
|
|
|
|
|
la t1, __data_start
|
|
|
|
|
la t2, __data_end
|
|
|
|
|
beq t0, t1, 1f
|
|
|
|
|
|
|
|
|
|
0:
|
|
|
|
|
lw t3, (t0)
|
|
|
|
|
sw t3, (t1)
|
|
|
|
|
add t0, t0, 4
|
|
|
|
|
add t1, t1, 4
|
|
|
|
|
bne t1, t2, 0b
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-02 18:13:02 -07:00
|
|
|
// zero bss
|
2018-10-14 17:12:01 -07:00
|
|
|
1:
|
|
|
|
|
la t0, __bss_start
|
|
|
|
|
la t1, __bss_end
|
|
|
|
|
0:
|
|
|
|
|
sw x0, (t0)
|
|
|
|
|
add t0, t0, 4
|
|
|
|
|
bne t0, t1, 0b
|
|
|
|
|
|
2019-12-04 09:08:57 -08:00
|
|
|
// Release any other harts into riscv_secondary_entry
|
|
|
|
|
fence w, w
|
|
|
|
|
add t0, zero, 1
|
|
|
|
|
sw t0, (t5)
|
|
|
|
|
|
2019-11-02 18:13:02 -07:00
|
|
|
// call main
|
2018-10-14 17:12:01 -07:00
|
|
|
jal lk_main
|
|
|
|
|
|
2019-11-02 18:13:02 -07:00
|
|
|
// should never return here
|
|
|
|
|
j .
|
|
|
|
|
|
|
|
|
|
.Lsecondary_trap:
|
2019-12-04 09:08:57 -08:00
|
|
|
#if WITH_SMP
|
|
|
|
|
// wait for _boot_status to be nonzero, then go into riscv_secondary_entry
|
|
|
|
|
lw t0, (t5)
|
|
|
|
|
beqz t0, .Lsecondary_trap
|
|
|
|
|
jal riscv_secondary_entry
|
|
|
|
|
#else
|
2019-11-02 18:13:02 -07:00
|
|
|
wfi
|
2018-10-14 17:12:01 -07:00
|
|
|
j .
|
2019-12-04 09:08:57 -08:00
|
|
|
#endif
|
2018-10-14 17:12:01 -07:00
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
.align 4
|
|
|
|
|
LOCAL_DATA(default_stack)
|
2019-12-04 09:08:57 -08:00
|
|
|
.skip ARCH_DEFAULT_STACK_SIZE * SMP_MAX_CPUS
|
2018-10-14 17:12:01 -07:00
|
|
|
LOCAL_DATA(default_stack_top)
|
2019-12-04 09:08:57 -08:00
|
|
|
LOCAL_DATA(_boot_status)
|
|
|
|
|
.dword
|