Skip to content

Commit

Permalink
exceptions: add el3_call()
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Chan <[email protected]>
  • Loading branch information
asdfugil authored and marcan committed Oct 30, 2024
1 parent 1fd17b8 commit 9ca6d1c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions proxyclient/m1n1/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ class M1N1Proxy(Reloadable):
P_PUT_SIMD_STATE = 0x00f
P_REBOOT = 0x010
P_SLEEP = 0x011
P_EL3_CALL = 0x012

P_WRITE64 = 0x100
P_WRITE32 = 0x101
Expand Down Expand Up @@ -760,6 +761,10 @@ def reboot(self):
self.request(self.P_REBOOT, no_reply=True)
def sleep(self, deep=False):
self.request(self.P_SLEEP, deep, no_reply=True)
def el3_call(self, addr, *args):
if len(args) > 4:
raise ValueError("Too many arguments")
return self.request(self.P_EL3_CALL, addr, *args)

def write64(self, addr, data):
'''write 8 byte value to given address'''
Expand Down
4 changes: 4 additions & 0 deletions src/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ void exc_sync(u64 *regs)
// Monitor call
u32 imm = mrs(ESR_EL3) & 0xffff;
switch (imm) {
case 42:
regs[0] = ((uint64_t(*)(uint64_t, uint64_t, uint64_t, uint64_t))regs[0])(
regs[1], regs[2], regs[3], regs[4]);
return;
default:
printf("Unknown SMC: 0x%x\n", imm);
break;
Expand Down
1 change: 1 addition & 0 deletions src/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void print_regs(u64 *regs, int el12);

uint64_t el0_call(void *func, uint64_t a, uint64_t b, uint64_t c, uint64_t d);
uint64_t el1_call(void *func, uint64_t a, uint64_t b, uint64_t c, uint64_t d);
uint64_t el3_call(void *func, uint64_t a, uint64_t b, uint64_t c, uint64_t d);

#endif

Expand Down
6 changes: 6 additions & 0 deletions src/exception_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,9 @@ _el1_vectors_start:
hvc 0x1e
.align 7
hvc 0x1f

.globl el3_call
.type el3_call, @function
el3_call:
smc 42
ret
3 changes: 3 additions & 0 deletions src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ int proxy_process(ProxyRequest *request, ProxyReply *reply)
case P_SLEEP:
cpu_sleep(request->args[0]);
break;
case P_EL3_CALL:
reply->retval = el3_call((void *)request->args[0], request->args[1], request->args[2],
request->args[3], request->args[4]);

case P_WRITE64:
exc_guard = GUARD_SKIP;
Expand Down
1 change: 1 addition & 0 deletions src/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum {
P_PUT_SIMD_STATE,
P_REBOOT,
P_SLEEP,
P_EL3_CALL,

P_WRITE64 = 0x100, // Generic register functions
P_WRITE32,
Expand Down
6 changes: 6 additions & 0 deletions src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ void smp_secondary_entry(void)
}
}

void smp_secondary_prep_el3(void)
{
msr(TPIDR_EL3, target_cpu);
return;
}

static void smp_start_cpu(int index, int die, int cluster, int core, u64 impl, u64 cpu_start_base)
{
int i;
Expand Down
5 changes: 4 additions & 1 deletion src/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern u8 *secondary_stacks[MAX_CPUS];
extern u8 *secondary_stacks_el3[MAX_EL3_CPUS];

void smp_secondary_entry(void);
void smp_secondary_prep_el3(void);

void smp_start_secondaries(void);
void smp_stop_secondaries(bool deep_sleep);
Expand All @@ -35,7 +36,9 @@ void smp_send_ipi(int cpu);

static inline int smp_id(void)
{
if (in_el2())
if (in_el3())
return mrs(TPIDR_EL3);
else if (in_el2())
return mrs(TPIDR_EL2);
else
return mrs(TPIDR_EL1);
Expand Down
4 changes: 3 additions & 1 deletion src/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ void _cpu_reset_c(void *stack)

exception_initialize();

if (in_el3())
if (in_el3()) {
smp_secondary_prep_el3();
return;
}

if (!is_boot_cpu())
smp_secondary_entry();
Expand Down

0 comments on commit 9ca6d1c

Please sign in to comment.