From 4c8e066aae6a8f69bb24994b1ce45d305c8469f5 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 4 Nov 2017 12:46:57 +0100 Subject: [PATCH] allocate stacks on demand, reduce the size of the BSS section --- arch/x86/include/asm/gdt.h | 26 +++++++++++++++----------- arch/x86/kernel/gdt.c | 27 +++++++++++++++++++++------ arch/x86/mm/memory.c | 3 +++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/gdt.h b/arch/x86/include/asm/gdt.h index 1f8c7f01d..3f8b462ca 100644 --- a/arch/x86/include/asm/gdt.h +++ b/arch/x86/include/asm/gdt.h @@ -51,26 +51,26 @@ extern "C" { #define GDT_FLAG_TSS_BUSY 0x02 #define GDT_FLAG_SEGMENT 0x10 -/// Privilege level: Ring 0 +/// Privilege level: Ring 0 #define GDT_FLAG_RING0 0x00 /// Privilege level: Ring 1 #define GDT_FLAG_RING1 0x20 -/// Privilege level: Ring 2 +/// Privilege level: Ring 2 #define GDT_FLAG_RING2 0x40 -/// Privilege level: Ring 3 +/// Privilege level: Ring 3 #define GDT_FLAG_RING3 0x60 /// Segment is present #define GDT_FLAG_PRESENT 0x80 /// Segment was accessed #define GDT_FLAG_ACCESSED 0x01 -/** - * @brief Granularity of segment limit +/** + * @brief Granularity of segment limit * - set: segment limit unit is 4 KB (page size) * - not set: unit is bytes */ #define GDT_FLAG_4K_GRAN 0x80 /** - * @brief Default operand size + * @brief Default operand size * - set: 32 bit * - not set: 16 bit */ @@ -78,7 +78,7 @@ extern "C" { #define GDT_FLAG_32_BIT 0x40 #define GDT_FLAG_64_BIT 0x20 -/** @brief Defines a GDT entry +/** @brief Defines a GDT entry * * A global descriptor table entry consists of: * - 32 bit base address (chunkwise embedded into this structure) @@ -115,16 +115,16 @@ typedef struct { #if GDT_ENTRIES > 8192 #error Too many GDT entries! -#endif +#endif /** @brief Installs the global descriptor table * * The installation involves the following steps: - * - set up the special GDT pointer + * - set up the special GDT pointer * - set up the entries in our GDT - * - finally call gdt_flush() in our assembler file + * - finally call gdt_flush() in our assembler file * in order to tell the processor where the new GDT is - * - update the new segment registers + * - update the new segment registers */ void gdt_install(void); @@ -143,6 +143,10 @@ void gdt_set_gate(int num, unsigned long base, unsigned long limit, void configure_gdt_entry(gdt_entry_t *dest_entry, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran); +/** @brief Initialize the task state segments + */ +void tss_init(void); + #ifdef __cplusplus } #endif diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index dca9c9f3b..b4e25006c 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,6 @@ gdt_ptr_t gp; // currently, our kernel has full access to the ioports static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}}; static tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE))); -static uint8_t stack_table[MAX_CORES][KERNEL_STACK_SIZE*MAX_IST] __attribute__ ((aligned (PAGE_SIZE))); extern const void boot_stack; @@ -94,7 +94,8 @@ void gdt_install(void) { int i, num = 0; - memset(task_state_segments, 0x00, MAX_CORES*sizeof(tss_t)); + // part of bss => already initialized + //memset(task_state_segments, 0x00, MAX_CORES*sizeof(tss_t)); /* Setup the GDT pointer and limit */ gp.limit = (sizeof(gdt_entry_t) * GDT_ENTRIES) - 1; @@ -148,10 +149,6 @@ void gdt_install(void) */ for(i=0; i update tss + tss_init(); + return ret; oom: