improved generic payload entry point
This commit is contained in:
@@ -20,12 +20,14 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
foreach(NAME ${PL_NAMES})
|
||||
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.S)
|
||||
add_executable(payload_${NAME} ${CMAKE_CURRENT_LIST_DIR}/payload_entry.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.S)
|
||||
add_executable(payload_${NAME} ${CMAKE_CURRENT_LIST_DIR}/payload_entry.S
|
||||
${CMAKE_CURRENT_LIST_DIR}/payload_entry.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.S)
|
||||
else()
|
||||
add_executable(payload_${NAME} ${CMAKE_CURRENT_LIST_DIR}/payload_entry.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.c)
|
||||
add_executable(payload_${NAME} ${CMAKE_CURRENT_LIST_DIR}/payload_entry.S
|
||||
${CMAKE_CURRENT_LIST_DIR}/payload_entry.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/${NAME}.c)
|
||||
endif()
|
||||
|
||||
add_custom_command(TARGET payload_${NAME} POST_BUILD
|
||||
|
||||
17
c8_remote/lib/payload/payload_entry.S
Normal file
17
c8_remote/lib/payload/payload_entry.S
Normal file
@@ -0,0 +1,17 @@
|
||||
.extern entry_sync
|
||||
.extern entry_async
|
||||
.extern load_sync_entry
|
||||
|
||||
.global _start
|
||||
.section .text
|
||||
_start:
|
||||
mov x10, x30
|
||||
bl load_sync_entry
|
||||
mov x30, x10
|
||||
|
||||
# if we came from the synchronous entry point, branch to entry_sync
|
||||
cmp x9, x10
|
||||
b.eq entry_sync
|
||||
|
||||
# else branch to the payload's async entry points
|
||||
b entry_async
|
||||
@@ -1,29 +1,13 @@
|
||||
#include "bootrom_addr.h"
|
||||
#include "dev_util.h"
|
||||
#include "bootrom_addr.h"
|
||||
|
||||
extern uint64_t entry_sync(uint64_t *args);
|
||||
extern uint64_t entry_async(uint64_t *base);
|
||||
|
||||
TEXT_SECTION
|
||||
uint64_t _start(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3,
|
||||
uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7)
|
||||
PAYLOAD_SECTION
|
||||
void load_sync_entry()
|
||||
{
|
||||
uint64_t entry, args[8];
|
||||
__asm__ volatile ("mov %0, x30" : "=r" (entry));
|
||||
uint64_t addr = ADDR_SYNC_ENTRY;
|
||||
__asm__ volatile("mov x9, %0" :: "i" (addr & 0xFFFFu));
|
||||
__asm__ volatile("movk x9, %0, LSL #16" :: "i" ((addr & 0xFFFF0000u) >> 16u));
|
||||
__asm__ volatile("movk x9, %0, LSL #32" :: "i" ((addr & 0xFFFF00000000u) >> 32u));
|
||||
__asm__ volatile("movk x9, %0, LSL #48" :: "i" ((addr & 0xFFFF000000000000u) >> 48u));
|
||||
|
||||
if(entry == ADDR_SYNC_ENTRY /* todo: correct entry */)
|
||||
{
|
||||
args[0] = arg0;
|
||||
args[1] = arg1;
|
||||
args[2] = arg2;
|
||||
args[3] = arg3;
|
||||
args[4] = arg4;
|
||||
args[5] = arg5;
|
||||
args[6] = arg6;
|
||||
args[7] = arg7;
|
||||
|
||||
return entry_sync(args);
|
||||
}
|
||||
else
|
||||
return entry_async((uint64_t *) arg0);
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
#include "bootrom_func.h"
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_sync(uint64_t *args)
|
||||
void entry_sync(uint8_t *src, uint8_t *dst, uint8_t *key, int32_t rep)
|
||||
{
|
||||
int i, j;
|
||||
unsigned char src_data[16];
|
||||
|
||||
unsigned char *src = (unsigned char *) args[0];
|
||||
unsigned char *dst = (unsigned char *) args[1];
|
||||
unsigned char *key = (unsigned char *) args[2];
|
||||
int rep = (int) args[3];
|
||||
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
src_data[j] = src[j];
|
||||
@@ -21,12 +16,7 @@ uint64_t entry_sync(uint64_t *args)
|
||||
if(i % 2 == 0) hardware_aes(16, src_data, dst, 16, 0, key, 0);
|
||||
else hardware_aes(16, dst, src_data, 16, 0, key, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_async(uint64_t *base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void entry_async(uint64_t *base){}
|
||||
@@ -141,18 +141,12 @@ void aes128_encrypt_ecb(unsigned char *msg, unsigned int msg_len, unsigned char
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_sync(uint64_t *args)
|
||||
uint64_t entry_sync(unsigned char *msg, unsigned int msg_len, unsigned char key[16],
|
||||
unsigned char sbox[16][16], unsigned char rc_lookup[11],
|
||||
unsigned char mul2[256], unsigned char mul3[256])
|
||||
{
|
||||
unsigned long long start = 0, end = 0;
|
||||
|
||||
unsigned char *msg = (unsigned char *) args[0];
|
||||
unsigned int msg_len = (unsigned int) args[1];
|
||||
unsigned char *key = (unsigned char *) args[2];
|
||||
unsigned char *sbox = (unsigned char *) args[3];
|
||||
unsigned char *rc_lookup = (unsigned char *) args[4];
|
||||
unsigned char *mul2 = (unsigned char *) args[5];
|
||||
unsigned char *mul3 = (unsigned char *) args[6];
|
||||
|
||||
__asm__ volatile ("mrs %0, cntpct_el0" : "=r" (start));
|
||||
aes128_encrypt_ecb(msg, msg_len, key, sbox, rc_lookup, mul2, mul3);
|
||||
__asm__ volatile ("mrs %0, cntpct_el0" : "=r" (end));
|
||||
@@ -167,7 +161,7 @@ uint64_t entry_sync(uint64_t *args)
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_async(uint64_t *base)
|
||||
void entry_async(uint64_t *base)
|
||||
{
|
||||
unsigned long long start = 0, end = 0;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void fix_heap()
|
||||
check_all_chksums();
|
||||
}
|
||||
|
||||
extern uint64_t entry_sync(uint64_t *args)
|
||||
void entry_sync()
|
||||
{
|
||||
fix_heap();
|
||||
|
||||
@@ -47,10 +47,6 @@ extern uint64_t entry_sync(uint64_t *args)
|
||||
*(ADDR_DFU_STATUS) = 1;
|
||||
|
||||
event_notify(ADDR_DFU_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern uint64_t entry_async(uint64_t *base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void entry_async(uint64_t *base){}
|
||||
@@ -39,13 +39,13 @@ uint64_t floppysleep_iteration(float *init)
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_sync(uint64_t *args)
|
||||
uint64_t entry_sync(float *init_ptr)
|
||||
{
|
||||
return floppysleep_iteration((float *) args[0]);
|
||||
return floppysleep_iteration(init_ptr);
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
uint64_t entry_async(uint64_t *args)
|
||||
void entry_async(uint64_t *args)
|
||||
{
|
||||
float *init_ptr = (float *) args[0];
|
||||
args[0] = 0;
|
||||
@@ -54,7 +54,7 @@ uint64_t entry_async(uint64_t *args)
|
||||
{
|
||||
floppysleep_iteration(init_ptr);
|
||||
|
||||
if(args[0] % 1000000 == 0) task_resched();
|
||||
args[0]++;
|
||||
if(args[0] % 100000 == 0) task_resched();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
#include "dev_util.h"
|
||||
|
||||
PAYLOAD_SECTION
|
||||
extern uint64_t entry_sync(uint64_t *args)
|
||||
void entry_sync()
|
||||
{
|
||||
__asm__("dmb sy");
|
||||
__asm__("ic iallu");
|
||||
__asm__("dsb sy");
|
||||
__asm__("isb");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PAYLOAD_SECTION
|
||||
extern uint64_t entry_async(uint64_t *base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void entry_async(){}
|
||||
Reference in New Issue
Block a user