Analogously to ARM. The setup_cpu_stack macro on ARM64 is slightly different: it sets up the stack for one CPU by loading cpus_online, incrementing it, and calcluates the stack location. In contrast to ARM, it return 0 in r0, as ARM64 doesn't have a separate IRQ stack. In this way, the whole API is compatible to ARM.
This is a preparation for the support of secondary CPUs. Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/arm64/header.S | 49 +++++++++++++++++++++++++++++++++++++--- inmates/lib/arm64/include/mach.h | 2 ++ inmates/lib/arm64/inmate.lds.S | 3 +-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/inmates/lib/arm64/header.S b/inmates/lib/arm64/header.S index e284aa5a..2c1f6a20 100644 --- a/inmates/lib/arm64/header.S +++ b/inmates/lib/arm64/header.S @@ -36,29 +36,72 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include <mach.h> + .macro ventry label .align 7 b \label .endm +/* Sets up the stack for a CPU. Clobbers x0-x2. Returns 0 in x0. + * + * The stack for the n'th onlined CPU is calculated as follows: + * stack_top = stack_bottom + n * stack_size + stack_size = + * = stack_bottom + (n + 1) * stack_size + * + * So the stack configuration looks as follows: + * +-----------+ <- stack_bottom + * | Pri | + * +-----------+ <- Primary CPU stack top + * | Sec1 | + * +-----------+ <- 1st secondary CPU stack top + * | Sec2 | + * +-----------+ <- 2nd secondary CPU stack top + * | ... | + */ +.macro setup_cpu_stack + /* increment cpus_online and store */ + mov x1, #0 + ldr x0, =cpus_online + ldr w1, [x0] + add x1, x1, #1 + str w1, [x0] + + ldr x0, =stack_bottom + + /* load the stack size */ + mov x2, #0 + ldr w2, stack_size + + /* calculate address of CPU stack */ + mul x1, x1, x2 + add x0, x0, x1 + + mov sp, x0 + + /* return NULL */ + mov x0, #0 +.endm + .section ".boot", "ax" .globl __reset_entry __reset_entry: ldr x0, =vectors msr vbar_el1, x0 - ldr x0, =stack_top - mov sp, x0 - mov x0, #(3 << 20) msr cpacr_el1, x0 + setup_cpu_stack msr daif, xzr isb b inmate_main +stack_size: + .word STACK_SIZE + handle_irq: bl vector_irq eret diff --git a/inmates/lib/arm64/include/mach.h b/inmates/lib/arm64/include/mach.h index a7b5a342..20b98e94 100644 --- a/inmates/lib/arm64/include/mach.h +++ b/inmates/lib/arm64/include/mach.h @@ -39,6 +39,8 @@ */ #define PAGE_SIZE 0x1000 +#define STACK_PAGES 1 +#define STACK_SIZE (STACK_PAGES * PAGE_SIZE) #ifdef CONFIG_MACH_AMD_SEATTLE #define CON_TYPE "PL011" diff --git a/inmates/lib/arm64/inmate.lds.S b/inmates/lib/arm64/inmate.lds.S index a2db6ac3..767df8fe 100644 --- a/inmates/lib/arm64/inmate.lds.S +++ b/inmates/lib/arm64/inmate.lds.S @@ -71,8 +71,7 @@ SECTIONS { } . = ALIGN(4096); - . = . + 0x1000; - stack_top = .; + stack_bottom = .; } ENTRY(__reset_entry) -- 2.14.1 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
