1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Save kernel stack top to TSS

This commit is contained in:
Braiden Vasco 2017-11-05 15:26:30 +00:00
parent a7cdcecbdc
commit 1b8a637016
8 changed files with 21 additions and 11 deletions

View file

@ -9,6 +9,7 @@ extern char _kernel_offset;
extern char _kernel_size;
extern char _kernel_phys_base;
extern char _kernel_virt_base;
extern char _kernel_stack_top;
static struct KernelMQ_Info kinfo;
@ -35,6 +36,8 @@ const struct KernelMQ_Info *init(unsigned long multiboot_magic, unsigned long mu
kinfo.kernel_and_modules_total_size = kinfo.kernel_size + kinfo.modules_total_size;
kinfo.kernel_stack_top = (unsigned long)&_kernel_stack_top;
paging_clear();
paging_identity();
/* kinfo.freepde_start = */ paging_mapkernel(&kinfo);

View file

@ -58,7 +58,7 @@ void main(const struct KernelMQ_Info *const kinfo_ptr)
memory_initialize(&kinfo);
protected_initialize();
protected_initialize(&kinfo);
// Set up a new post-relocate bootstrap pagetable so that
// we can map in VM, and we no longer rely on pre-relocated

View file

@ -53,7 +53,7 @@ static void idt_set_gate(unsigned char num, unsigned int base, unsigned short se
void gdt_flush(const struct GdtPointer *pointer);
void idt_flush(const struct IdtPointer *pointer);
void protected_initialize()
void protected_initialize(const struct KernelMQ_Info *const kinfo)
{
logger_info("Remap the IRQ table.");
@ -76,7 +76,7 @@ void protected_initialize()
gdt_set_gate(GDT_USER_CS_INDEX, 0, 0xFFFFFFFF, 0xFA, 0xCF);
gdt_set_gate(GDT_USER_DS_INDEX, 0, 0xFFFFFFFF, 0xF2, 0xCF);
tss_write_to_gdt(&gdt_entries[GDT_TSS_INDEX]);
tss_write_to_gdt(kinfo, &gdt_entries[GDT_TSS_INDEX]);
logger_info("Setup IDT.");

View file

@ -1,6 +1,8 @@
#ifndef KERNELMQ_INCLUDED_PROTECTED
#define KERNELMQ_INCLUDED_PROTECTED 1
void protected_initialize();
#include <kernelmq/info.h>
void protected_initialize(const struct KernelMQ_Info *kinfo);
#endif

View file

@ -14,9 +14,10 @@
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
_kernel_stack_top:
.global _kernel_stack_top
.section .text
@ -27,13 +28,13 @@ stack_top:
.type halt, @function
_start:
mov $stack_top, %esp // Initialize stack
mov $_kernel_stack_top, %esp // Initialize stack
push %ebx // Multiboot information pointer
push %eax // Multiboot magic number
call init
mov $stack_top, %esp // Initialize stack
mov $_kernel_stack_top, %esp // Initialize stack
push %eax // Kernel information pointer
call main

View file

@ -56,7 +56,7 @@ __attribute__((packed));
static struct tss_entry tss;
void tss_write_to_gdt(void *gdt_entry_ptr)
void tss_write_to_gdt(const struct KernelMQ_Info *const kinfo, void *gdt_entry_ptr)
{
struct gdt_entry_bits *const g = gdt_entry_ptr;
@ -84,5 +84,5 @@ void tss_write_to_gdt(void *gdt_entry_ptr)
kmemset(&tss, 0, sizeof(tss));
tss.ss0 = GDT_KERNEL_DS_SELECTOR;
tss.esp0 = 0; // TODO: get from kinfo
tss.esp0 = kinfo->kernel_stack_top;
}

View file

@ -1,6 +1,8 @@
#ifndef KERNELMQ_INCLUDED_TSS
#define KERNELMQ_INCLUDED_TSS 1
void tss_write_to_gdt(void *gdt_entry);
#include <kernelmq/info.h>
void tss_write_to_gdt(const struct KernelMQ_Info *kinfo, void *gdt_entry);
#endif

View file

@ -47,6 +47,8 @@ struct KernelMQ_Info {
unsigned long modules_total_size;
unsigned long kernel_and_modules_total_size;
unsigned long kernel_stack_top;
};
unsigned char kernelmq_info_validate_and_copy(struct KernelMQ_Info *dest, const struct KernelMQ_Info *src);