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-07-18 22:43:49 +01:00
|
|
|
|
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) {
|
|
|
|
DEBUG("failed to open file (%ld)!\n", handle);
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = semihosting_file_read(handle, &len, buf)) < 0) {
|
|
|
|
DEBUG("failed to read file (%ld)!\n", ret);
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
int main(void)
|
|
|
|
{
|
2019-07-30 01:16:25 +01:00
|
|
|
enableTraps();
|
|
|
|
|
2019-08-02 04:12:24 +01:00
|
|
|
if (currentCoreCtx->isBootCore) {
|
2019-07-29 21:38:44 +01:00
|
|
|
uartInit(115200);
|
2019-07-31 23:46:16 +01:00
|
|
|
DEBUG("EL2: core %u reached main first!\n", currentCoreCtx->coreId);
|
2019-07-31 01:30:17 +01:00
|
|
|
if (currentCoreCtx->kernelEntrypoint == 0) {
|
|
|
|
if (semihosting_connection_supported()) {
|
|
|
|
loadKernelViaSemihosting();
|
|
|
|
//panic();
|
|
|
|
} else {
|
|
|
|
DEBUG("Kernel not loaded!\n");
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
}
|
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-08-02 04:12:24 +01:00
|
|
|
DEBUG("Test 0x%08llx %016llx\n", get_physical_address_el1_stage12(0x08010000ull), GET_SYSREG(par_el1));
|
2019-07-29 21:38:44 +01:00
|
|
|
}
|
2019-07-19 00:45:56 +01:00
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|