2019-08-05 01:21:18 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
#include "utils.h"
|
2019-07-29 21:38:44 +01:00
|
|
|
#include "core_ctx.h"
|
2019-07-31 01:30:17 +01:00
|
|
|
#include "debug_log.h"
|
2019-07-22 00:04:53 +01:00
|
|
|
#include "platform/uart.h"
|
2019-07-31 01:30:17 +01:00
|
|
|
#include "semihosting.h"
|
2019-07-30 01:16:25 +01:00
|
|
|
#include "traps.h"
|
2019-08-02 04:12:24 +01:00
|
|
|
#include "sysreg.h"
|
2019-08-05 01:21:18 +01:00
|
|
|
#include "exceptions.h"
|
|
|
|
#include "single_step.h"
|
2019-08-05 22:49:25 +01:00
|
|
|
#include "breakpoints.h"
|
|
|
|
#include "watchpoints.h"
|
2020-01-09 19:24:05 +00:00
|
|
|
#include "timer.h"
|
2019-08-10 23:56:49 +01:00
|
|
|
#include "irq.h"
|
|
|
|
|
2019-07-31 01:30:17 +01:00
|
|
|
extern const u8 __start__[];
|
|
|
|
|
|
|
|
static void loadKernelViaSemihosting(void)
|
|
|
|
{
|
|
|
|
size_t len = 1<<20; // max len
|
|
|
|
uintptr_t buf = (uintptr_t)__start__ + (1<<20);
|
|
|
|
long handle = -1, ret;
|
|
|
|
|
2019-07-31 23:46:16 +01:00
|
|
|
DEBUG("Loading kernel via semihosted file I/O... ");
|
2019-07-31 01:30:17 +01:00
|
|
|
handle = semihosting_file_open("test_kernel.bin", FOPEN_MODE_RB);
|
|
|
|
if (handle < 0) {
|
2020-01-02 18:41:52 +00:00
|
|
|
PANIC("failed to open file (%ld)!\n", handle);
|
2019-07-31 01:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = semihosting_file_read(handle, &len, buf)) < 0) {
|
2020-01-02 18:41:52 +00:00
|
|
|
PANIC("failed to read file (%ld)!\n", ret);
|
2019-07-31 01:30:17 +01:00
|
|
|
}
|
|
|
|
|
2019-07-31 23:46:16 +01:00
|
|
|
DEBUG("OK!\n");
|
2019-07-31 01:30:17 +01:00
|
|
|
semihosting_file_close(handle);
|
|
|
|
currentCoreCtx->kernelEntrypoint = buf;
|
|
|
|
}
|
|
|
|
|
2020-01-02 18:41:52 +00:00
|
|
|
void thermosphereMain(ExceptionStackFrame *frame)
|
2019-07-18 22:43:49 +01:00
|
|
|
{
|
2019-07-30 01:16:25 +01:00
|
|
|
enableTraps();
|
2019-08-06 05:09:51 +01:00
|
|
|
enableBreakpointsAndWatchpoints();
|
2020-01-09 19:24:05 +00:00
|
|
|
timerInit();
|
2019-08-10 23:56:49 +01:00
|
|
|
initIrq();
|
2019-08-06 05:09:51 +01:00
|
|
|
|
2019-08-07 20:38:40 +01:00
|
|
|
if (currentCoreCtx->isBootCore) {
|
|
|
|
uartInit(115200);
|
|
|
|
DEBUG("EL2: core %u reached main first!\n", currentCoreCtx->coreId);
|
|
|
|
}
|
|
|
|
|
2019-08-06 05:09:51 +01:00
|
|
|
initBreakpoints();
|
|
|
|
initWatchpoints();
|
2019-07-30 01:16:25 +01:00
|
|
|
|
2019-08-02 04:12:24 +01:00
|
|
|
if (currentCoreCtx->isBootCore) {
|
2019-07-31 01:30:17 +01:00
|
|
|
if (currentCoreCtx->kernelEntrypoint == 0) {
|
|
|
|
if (semihosting_connection_supported()) {
|
|
|
|
loadKernelViaSemihosting();
|
|
|
|
} else {
|
2020-01-02 18:41:52 +00:00
|
|
|
PANIC("Kernel not loaded!\n");
|
2019-07-31 01:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-29 21:38:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-07-31 23:46:16 +01:00
|
|
|
DEBUG("EL2: core %u reached main!\n", currentCoreCtx->coreId);
|
2019-07-29 21:38:44 +01:00
|
|
|
}
|
2019-07-19 00:45:56 +01:00
|
|
|
|
2020-01-08 22:18:56 +00:00
|
|
|
setCurrentCoreActive();
|
|
|
|
|
2019-08-05 01:21:18 +01:00
|
|
|
// Set up exception frame: init regs to 0, set spsr, elr, etc.
|
|
|
|
memset(frame, 0, sizeof(ExceptionStackFrame));
|
2020-01-08 22:18:56 +00:00
|
|
|
frame->spsr_el2 = (0xF << 6) | (1 << 2) | 1; // EL1h+DAIF
|
|
|
|
frame->elr_el2 = currentCoreCtx->kernelEntrypoint;
|
|
|
|
frame->x[0] = currentCoreCtx->kernelArgument;
|
|
|
|
frame->cntvct_el0 = GET_SYSREG(cntvct_el0);
|
2019-07-18 22:43:49 +01:00
|
|
|
}
|