summaryrefslogtreecommitdiff
path: root/arch/x86
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
commit3eb451546eb96d8050cab12f1ddba4f5d940ca2a (patch)
treeaefa666fc24911f37f609df5426e16398e189456 /arch/x86
parente6b37afb4e304b2f1c63f7424e40f1f991fab00a (diff)
Break STACK_SIZE macro into 3 different macros
Diffstat (limited to 'arch/x86')
-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
9 files changed, 35 insertions, 24 deletions
diff --git a/arch/x86/machine/boot.c b/arch/x86/machine/boot.c
index 59f0d67..72c5bb3 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 d10f0c2..c207059 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 dc9c9a4..4393c13 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 4981ff6..83eaf90 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 042e46e..d8f0fc3 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 5d16ea2..8604cee 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 0f67b76..0bb900c 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 e033b35..ee3153f 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 e4d5912..c2885c5 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>