summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-24 21:18:28 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-24 21:18:28 +0200
commitb958a89b516218433d5982f1decce867d915cee4 (patch)
treeaefa666fc24911f37f609df5426e16398e189456
parent3c861e6cbc77d7aefcc2594b65a7d24d0df83357 (diff)
Break STACK_SIZE macro into 3 different macros
-rw-r--r--arch/x86/machine/boot.c4
-rw-r--r--arch/x86/machine/boot.h5
-rw-r--r--arch/x86/machine/boot_asm.S12
-rw-r--r--arch/x86/machine/cpu.c18
-rw-r--r--arch/x86/machine/param.h5
-rw-r--r--arch/x86/machine/tcb.c3
-rw-r--r--arch/x86/machine/tcb.h6
-rw-r--r--arch/x86/machine/trap.c2
-rw-r--r--arch/x86/machine/trap.h4
-rw-r--r--kern/thread.c6
10 files changed, 38 insertions, 27 deletions
diff --git a/arch/x86/machine/boot.c b/arch/x86/machine/boot.c
index 59f0d67e..72c5bb37 100644
--- a/arch/x86/machine/boot.c
+++ b/arch/x86/machine/boot.c
@@ -77,8 +77,8 @@
#include <vm/vm_kmem.h>
#include <vm/vm_setup.h>
-char boot_stack[STACK_SIZE] __aligned(DATA_ALIGN) __bootdata;
-char boot_ap_stack[STACK_SIZE] __aligned(DATA_ALIGN) __bootdata;
+char boot_stack[BOOT_STACK_SIZE] __aligned(DATA_ALIGN) __bootdata;
+char boot_ap_stack[BOOT_STACK_SIZE] __aligned(DATA_ALIGN) __bootdata;
unsigned int boot_ap_id __bootdata;
#ifdef __LP64__
diff --git a/arch/x86/machine/boot.h b/arch/x86/machine/boot.h
index d10f0c22..c2070593 100644
--- a/arch/x86/machine/boot.h
+++ b/arch/x86/machine/boot.h
@@ -22,6 +22,11 @@
#include <machine/param.h>
/*
+ * Size of the stack used when booting a processor.
+ */
+#define BOOT_STACK_SIZE PAGE_SIZE
+
+/*
* Macros used by the very early panic functions.
*/
#define BOOT_CGAMEM 0xb8000
diff --git a/arch/x86/machine/boot_asm.S b/arch/x86/machine/boot_asm.S
index dc9c9a45..4393c133 100644
--- a/arch/x86/machine/boot_asm.S
+++ b/arch/x86/machine/boot_asm.S
@@ -67,7 +67,7 @@ ASM_ENTRY(_start)
ljmp $BOOT_GDT_SEL_CODE, $1f
1:
- movl $(boot_stack + STACK_SIZE), %esp
+ movl $(boot_stack + BOOT_STACK_SIZE), %esp
#ifdef __LP64__
call boot_check_long_mode
@@ -99,7 +99,7 @@ ASM_ENTRY(_start)
#ifdef __LP64__
movq %rax, %cr3
- movq $(boot_stack + STACK_SIZE), %rsp
+ movq $(boot_stack + BOOT_STACK_SIZE), %rsp
#else /* __LP64__ */
movl %eax, %cr3
movl %cr0, %eax
@@ -108,7 +108,7 @@ ASM_ENTRY(_start)
ljmp $BOOT_GDT_SEL_CODE, $1f
1:
- movl $(boot_stack + STACK_SIZE), %esp
+ movl $(boot_stack + BOOT_STACK_SIZE), %esp
#endif /* __LP64__ */
xorl %ebp, %ebp
@@ -304,7 +304,7 @@ ASM_ENTRY(boot_ap_start32)
ljmp $BOOT_GDT_SEL_CODE, $1f
1:
- movl $(boot_ap_stack + STACK_SIZE), %esp
+ movl $(boot_ap_stack + BOOT_STACK_SIZE), %esp
#ifdef __LP64__
call boot_setup_tls
@@ -335,10 +335,10 @@ ASM_ENTRY(boot_ap_start32)
#ifdef __LP64__
movq %rax, %rsp
- addq $STACK_SIZE, %rsp
+ addq $BOOT_STACK_SIZE, %rsp
#else /* __LP64__ */
movl %eax, %esp
- addl $STACK_SIZE, %esp
+ addl $BOOT_STACK_SIZE, %esp
#endif /* __LP64__ */
xorl %ebp, %ebp
diff --git a/arch/x86/machine/cpu.c b/arch/x86/machine/cpu.c
index 4981ff63..83eaf90e 100644
--- a/arch/x86/machine/cpu.c
+++ b/arch/x86/machine/cpu.c
@@ -144,7 +144,7 @@ static struct cpu_gate_desc cpu_idt[CPU_IDT_SIZE] __aligned(8) __read_mostly;
* memory.
*/
static unsigned long cpu_double_fault_handler;
-static char cpu_double_fault_stack[STACK_SIZE] __aligned(DATA_ALIGN);
+static char cpu_double_fault_stack[TRAP_STACK_SIZE] __aligned(DATA_ALIGN);
void
cpu_delay(unsigned long usecs)
@@ -342,7 +342,7 @@ cpu_init_tss(struct cpu *cpu)
#ifdef __LP64__
assert(cpu->double_fault_stack != NULL);
tss->ist[CPU_TSS_IST_DF] = (unsigned long)cpu->double_fault_stack
- + STACK_SIZE;
+ + TRAP_STACK_SIZE;
#endif /* __LP64__ */
asm volatile("ltr %w0" : : "q" (CPU_GDT_SEL_TSS));
@@ -362,7 +362,7 @@ cpu_init_double_fault_tss(struct cpu *cpu)
tss->cr3 = cpu_get_cr3();
tss->eip = cpu_double_fault_handler;
tss->eflags = CPU_EFL_ONE;
- tss->ebp = (unsigned long)cpu->double_fault_stack + STACK_SIZE;
+ tss->ebp = (unsigned long)cpu->double_fault_stack + TRAP_STACK_SIZE;
tss->esp = tss->ebp;
tss->es = CPU_GDT_SEL_DATA;
tss->cs = CPU_GDT_SEL_CODE;
@@ -414,7 +414,7 @@ cpu_idt_set_double_fault(void (*isr)(void))
static void
cpu_load_idt(void)
{
- static volatile struct cpu_pseudo_desc idtr;
+ static volatile struct cpu_pseudo_desc idtr; /* TODO Review this */
idtr.address = (unsigned long)cpu_idt;
idtr.limit = sizeof(cpu_idt) - 1;
@@ -688,18 +688,20 @@ cpu_mp_setup(void)
io_write_byte(CPU_MP_CMOS_PORT_REG, CPU_MP_CMOS_REG_RESET);
io_write_byte(CPU_MP_CMOS_PORT_DATA, CPU_MP_CMOS_DATA_RESET_WARM);
+ /* TODO Allocate stacks out of the slab allocator for sub-page sizes */
+
for (i = 1; i < cpu_count(); i++) {
cpu = percpu_ptr(cpu_desc, i);
- page = vm_page_alloc(vm_page_order(STACK_SIZE), VM_PAGE_SEL_DIRECTMAP,
- VM_PAGE_KERNEL);
+ page = vm_page_alloc(vm_page_order(BOOT_STACK_SIZE),
+ VM_PAGE_SEL_DIRECTMAP, VM_PAGE_KERNEL);
if (page == NULL) {
panic("cpu: unable to allocate boot stack for cpu%u", i);
}
cpu->boot_stack = vm_page_direct_ptr(page);
- page = vm_page_alloc(vm_page_order(STACK_SIZE), VM_PAGE_SEL_DIRECTMAP,
- VM_PAGE_KERNEL);
+ page = vm_page_alloc(vm_page_order(TRAP_STACK_SIZE),
+ VM_PAGE_SEL_DIRECTMAP, VM_PAGE_KERNEL);
if (page == NULL) {
panic("cpu: unable to allocate double fault stack for cpu%u", i);
diff --git a/arch/x86/machine/param.h b/arch/x86/machine/param.h
index 042e46eb..d8f0fc3b 100644
--- a/arch/x86/machine/param.h
+++ b/arch/x86/machine/param.h
@@ -58,11 +58,6 @@
#define PAGE_MASK (PAGE_SIZE - 1)
/*
- * Kernel stack size for threads and interrupt handlers.
- */
-#define STACK_SIZE PAGE_SIZE
-
-/*
* Maximum number of available interrupts.
*/
#define INTR_TABLE_SIZE 256
diff --git a/arch/x86/machine/tcb.c b/arch/x86/machine/tcb.c
index 5d16ea2f..8604cee4 100644
--- a/arch/x86/machine/tcb.c
+++ b/arch/x86/machine/tcb.c
@@ -17,7 +17,6 @@
#include <kern/init.h>
#include <kern/macros.h>
-#include <kern/param.h>
#include <kern/thread.h>
#include <machine/cpu.h>
#include <machine/pmap.h>
@@ -85,7 +84,7 @@ tcb_init(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg)
}
tcb->bp = 0;
- tcb->sp = (uintptr_t)stack + STACK_SIZE;
+ tcb->sp = (uintptr_t)stack + TCB_STACK_SIZE;
tcb_stack_forge(tcb, fn, arg);
return 0;
}
diff --git a/arch/x86/machine/tcb.h b/arch/x86/machine/tcb.h
index 0f67b765..0bb900c6 100644
--- a/arch/x86/machine/tcb.h
+++ b/arch/x86/machine/tcb.h
@@ -25,9 +25,15 @@
#include <stdint.h>
#include <kern/macros.h>
+#include <kern/param.h>
#include <machine/cpu.h>
/*
+ * Thread stack size.
+ */
+#define TCB_STACK_SIZE PAGE_SIZE
+
+/*
* Thread control block.
*/
struct tcb {
diff --git a/arch/x86/machine/trap.c b/arch/x86/machine/trap.c
index e033b352..ee3153f5 100644
--- a/arch/x86/machine/trap.c
+++ b/arch/x86/machine/trap.c
@@ -37,7 +37,7 @@
#include <machine/trap.h>
struct trap_cpu_data {
- unsigned char intr_stack[STACK_SIZE] __aligned(DATA_ALIGN);
+ unsigned char intr_stack[TRAP_STACK_SIZE] __aligned(DATA_ALIGN);
};
static struct trap_cpu_data trap_cpu_data __percpu;
diff --git a/arch/x86/machine/trap.h b/arch/x86/machine/trap.h
index e4d5912b..c2885c59 100644
--- a/arch/x86/machine/trap.h
+++ b/arch/x86/machine/trap.h
@@ -21,6 +21,8 @@
#ifndef _X86_TRAP_H
#define _X86_TRAP_H
+#include <kern/param.h>
+
/*
* Architecture defined traps.
*/
@@ -63,6 +65,8 @@
#define TRAP_NR_VECTORS 256
+#define TRAP_STACK_SIZE PAGE_SIZE
+
#ifndef __ASSEMBLER__
#include <stdint.h>
diff --git a/kern/thread.c b/kern/thread.c
index e290be29..7b186cb7 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -1893,7 +1893,7 @@ thread_alloc_stack(void)
void *mem;
int error;
- stack_size = vm_page_round(STACK_SIZE);
+ stack_size = vm_page_round(TCB_STACK_SIZE);
mem = vm_kmem_alloc((PAGE_SIZE * 2) + stack_size);
if (mem == NULL) {
@@ -1934,7 +1934,7 @@ thread_free_stack(void *stack)
size_t stack_size;
char *va;
- stack_size = vm_page_round(STACK_SIZE);
+ stack_size = vm_page_round(TCB_STACK_SIZE);
va = (char *)stack - PAGE_SIZE;
vm_kmem_free_va(va, PAGE_SIZE);
@@ -2304,7 +2304,7 @@ thread_setup(void)
kmem_cache_init(&thread_cache, "thread", sizeof(struct thread),
CPU_L1_SIZE, NULL, 0);
#ifndef X15_THREAD_STACK_GUARD
- kmem_cache_init(&thread_stack_cache, "thread_stack", STACK_SIZE,
+ kmem_cache_init(&thread_stack_cache, "thread_stack", TCB_STACK_SIZE,
DATA_ALIGN, NULL, 0);
#endif /* X15_THREAD_STACK_GUARD */