Allocate the main program stacks after the loaded program.

After we relocate the program, we restart it. So there is no need to copy
over the old stack contents. This allows us to increase the maximum number
of APs without a run time overhead. The maximum number of APs will still
be limited by the size of low memory.
This commit is contained in:
Martin Whitaker
2022-01-29 14:16:51 +00:00
parent 73bfc1878a
commit fe4374e818
3 changed files with 16 additions and 33 deletions

View File

@@ -12,13 +12,8 @@
only affects memory footprint, so
can be increased if needed */
// NOTE: Before the APs are started, the BSP stack can extend downwards into
// the area reserved for the AP stacks. So the stack size given here just
// needs to be enough for running the main application once initialisation
// is complete. The pmem initialisation needs ~12KB of stack, so make sure
// the total stack size is at least that.
#define PCPU_STACK_SIZE 2048 /* Stack size for each CPU core */
#define BSP_STACK_SIZE 16384 /* Stack size for the BSP */
#define AP_STACK_SIZE 1024 /* Stack size for each AP */
#define LOW_LOAD_ADDR 0x00010000 /* The low load address for the main program */
#define HIGH_LOAD_ADDR 0x00100000 /* The high load address for the main program */

View File

@@ -88,13 +88,15 @@ startup:
movl %esi, boot_params_addr@GOTOFF(%ebx)
1:
# Pick the correct stack.
# Pick the correct stack. The stacks are allocated immediately
# after the end of the loaded program, BSP first, then APs.
call smp_my_pcpu_num
movl $PCPU_STACK_SIZE, %edx
movl $AP_STACK_SIZE, %edx
mul %edx
leal bsp_stack_top@GOTOFF(%ebx), %esp
subl %eax, %esp
addl $BSP_STACK_SIZE, %eax
leal _end@GOTOFF(%ebx), %esp
addl %eax, %esp
# Initialise the GDT descriptor.
@@ -552,19 +554,11 @@ first_boot:
.previous
# Stacks.
# Startup stack.
.bss
.align 16
ap_stacks_base:
. = . + (PCPU_STACK_SIZE * MAX_APS)
ap_stacks_top:
bsp_stack_base:
. = . + PCPU_STACK_SIZE
bsp_stack_top:
startup_stack_base:
. = . + 64
startup_stack_top:

View File

@@ -147,14 +147,16 @@ startup:
leaq startup_stack_top(%rip), %rsp
# Pick the correct stack.
# Pick the correct stack. The stacks are allocated immediately
# after the end of the loaded program, BSP first, then APs.
xorq %rax, %rax
call smp_my_pcpu_num
movl $PCPU_STACK_SIZE, %edx
movl $AP_STACK_SIZE, %edx
mul %edx
leaq bsp_stack_top(%rip), %rsp
subq %rax, %rsp
addq $BSP_STACK_SIZE, %rax
leaq _end(%rip), %rsp
addq %rax, %rsp
# Initialise the pml4 and pdp tables.
@@ -597,19 +599,11 @@ first_boot:
.previous
# Stacks.
# Startup stack.
.bss
.align 16
ap_stacks_base:
. = . + (PCPU_STACK_SIZE * MAX_APS)
ap_stacks_top:
bsp_stack_base:
. = . + PCPU_STACK_SIZE
bsp_stack_top:
startup_stack_base:
. = . + 64
startup_stack_top: