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"
|
2020-01-12 01:59:26 +00:00
|
|
|
#include "transport_interface.h"
|
2020-01-20 02:24:02 +00:00
|
|
|
#include "guest_memory.h"
|
2020-01-25 20:16:10 +00:00
|
|
|
#include "fpu.h"
|
2019-08-10 23:56:49 +01:00
|
|
|
|
2020-01-17 22:10:26 +00:00
|
|
|
#include "memory_map.h"
|
|
|
|
#include "mmu.h"
|
2019-07-31 01:30:17 +01:00
|
|
|
|
|
|
|
static void loadKernelViaSemihosting(void)
|
|
|
|
{
|
2020-01-17 22:10:26 +00:00
|
|
|
// Note: !! hardcoded addresses !!
|
2019-07-31 01:30:17 +01:00
|
|
|
size_t len = 1<<20; // max len
|
2020-01-17 22:10:26 +00:00
|
|
|
uintptr_t buf = 0x60000000 + (1<<20);
|
|
|
|
|
2019-07-31 01:30:17 +01:00
|
|
|
long handle = -1, ret;
|
|
|
|
|
2020-01-17 22:10:26 +00:00
|
|
|
u64 *mmuTable = (u64 *)MEMORY_MAP_VA_TTBL;
|
|
|
|
mmu_map_block_range(
|
|
|
|
1, mmuTable, 0x40000000, 0x40000000, 0x40000000,
|
|
|
|
MMU_PTE_BLOCK_XN | MMU_PTE_BLOCK_INNER_SHAREBLE | MMU_PTE_BLOCK_MEMTYPE(MEMORY_MAP_MEMTYPE_NORMAL_UNCACHEABLE)
|
|
|
|
);
|
|
|
|
|
2020-01-20 02:24:02 +00:00
|
|
|
__tlb_invalidate_el2_local();
|
|
|
|
__dsb_local();
|
2020-01-17 22:10:26 +00:00
|
|
|
|
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);
|
2020-01-25 17:20:43 +00:00
|
|
|
ENSURE2(handle >= 0, "failed to open file (%ld)!\n", handle);
|
2019-07-31 01:30:17 +01:00
|
|
|
|
2020-01-25 17:20:43 +00:00
|
|
|
ret = semihosting_file_read(handle, &len, buf);
|
|
|
|
ENSURE2(ret >= 0, "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);
|
2020-01-17 22:10:26 +00:00
|
|
|
|
|
|
|
mmu_unmap_range(1, mmuTable, 0x40000000, 0x40000000);
|
2020-01-20 02:24:02 +00:00
|
|
|
__tlb_invalidate_el2_local();
|
|
|
|
__dsb_local();
|
2020-01-17 22:10:26 +00:00
|
|
|
|
2019-07-31 01:30:17 +01:00
|
|
|
currentCoreCtx->kernelEntrypoint = buf;
|
|
|
|
}
|
|
|
|
|
2020-01-12 21:51:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "platform/uart.h"
|
2020-01-27 00:46:00 +00:00
|
|
|
#include "debug_manager.h"
|
2020-01-12 21:51:50 +00:00
|
|
|
typedef struct TestCtx {
|
|
|
|
char buf[512+1];
|
|
|
|
} TestCtx;
|
|
|
|
|
|
|
|
static TestCtx g_testCtx;
|
|
|
|
|
|
|
|
size_t testReceiveCallback(TransportInterface *iface, void *p)
|
|
|
|
{
|
|
|
|
TestCtx *ctx = (TestCtx *)p;
|
2020-01-27 00:46:00 +00:00
|
|
|
debugManagerPauseCores(BIT(0));
|
2020-01-12 21:51:50 +00:00
|
|
|
return transportInterfaceReadDataUntil(iface, ctx->buf, 512, '\r');
|
|
|
|
}
|
|
|
|
|
|
|
|
void testProcessDataCallback(TransportInterface *iface, void *p, size_t sz)
|
|
|
|
{
|
|
|
|
(void)iface;
|
|
|
|
(void)sz;
|
2020-01-30 01:22:37 +00:00
|
|
|
debugManagerUnpauseCores(BIT(0));
|
2020-01-12 21:51:50 +00:00
|
|
|
TestCtx *ctx = (TestCtx *)p;
|
|
|
|
DEBUG("EL2 [core %u]: you typed: %s\n", currentCoreCtx->coreId, ctx->buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test(void)
|
|
|
|
{
|
|
|
|
TransportInterface *iface = transportInterfaceCreate(
|
|
|
|
TRANSPORT_INTERFACE_TYPE_UART,
|
|
|
|
DEFAULT_UART,
|
|
|
|
DEFAULT_UART_FLAGS,
|
|
|
|
testReceiveCallback,
|
|
|
|
testProcessDataCallback,
|
|
|
|
&g_testCtx
|
|
|
|
);
|
2020-01-14 02:09:51 +00:00
|
|
|
transportInterfaceSetInterruptAffinity(iface, BIT(1));
|
2020-01-12 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void thermosphereMain(ExceptionStackFrame *frame, u64 pct)
|
2019-07-18 22:43:49 +01:00
|
|
|
{
|
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) {
|
2020-01-12 01:59:26 +00:00
|
|
|
transportInterfaceInitLayer();
|
|
|
|
debugLogInit();
|
2020-01-31 23:23:41 +00:00
|
|
|
//test();
|
2020-01-31 02:53:40 +00:00
|
|
|
debugManagerInit(TRANSPORT_INTERFACE_TYPE_UART, DEFAULT_UART, DEFAULT_UART_FLAGS);
|
2019-08-07 20:38:40 +01:00
|
|
|
DEBUG("EL2: core %u reached main first!\n", currentCoreCtx->coreId);
|
|
|
|
}
|
|
|
|
|
2020-01-12 01:59:26 +00:00
|
|
|
enableTraps();
|
|
|
|
enableBreakpointsAndWatchpoints();
|
|
|
|
timerInit();
|
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) {
|
2020-01-25 17:20:43 +00:00
|
|
|
ENSURE2(semihosting_connection_supported(), "Kernel not loaded!\n");
|
|
|
|
loadKernelViaSemihosting();
|
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;
|
2020-01-12 21:51:50 +00:00
|
|
|
frame->cntpct_el0 = pct;
|
2020-01-25 20:16:10 +00:00
|
|
|
|
|
|
|
// Initialize FPU registers -- no need to memset, the regcaches are in .tempbss
|
|
|
|
fpuCommitRegisters();
|
|
|
|
fpuCleanInvalidateRegisterCache();
|
2020-01-31 00:28:05 +00:00
|
|
|
|
|
|
|
if (!currentCoreCtx->isBootCore) {
|
|
|
|
debugManagerReportEvent(DBGEVENT_CORE_ON);
|
2020-01-31 23:23:41 +00:00
|
|
|
} else {
|
2020-02-01 16:20:45 +00:00
|
|
|
debugManagerReportEvent(DBGEVENT_DEBUGGER_BREAK);
|
2020-01-31 00:28:05 +00:00
|
|
|
}
|
2019-07-18 22:43:49 +01:00
|
|
|
}
|