Starting to move towards proper HAL and ring3

- slight clean up of PCI driver
- Added TaskSegment header
- Rename some folders
This commit is contained in:
2023-02-11 12:22:45 +01:00
parent 520104a43a
commit 1f90a5d862
17 changed files with 209 additions and 86 deletions

View File

@ -0,0 +1,59 @@
#pragma once
#include "gdt/gdtc.h"
#include "../../lib/include/string.h"
struct TaskStateSegment {
uint32_t prev_tss;
uint32_t esp0;
uint32_t ss0;
// everythinge else is unused
uint32_t esp1;
uint32_t ss1;
uint32_t esp2;
uint32_t ss2;
uint32_t cr3;
uint32_t eip;
uint32_t eflags;
uint32_t eax;
uint32_t ecx;
uint32_t edx;
uint32_t ebx;
uint32_t esp;
uint32_t ebp;
uint32_t esi;
uint32_t edi;
uint32_t es;
uint32_t cs;
uint32_t ss;
uint32_t ds;
uint32_t fs;
uint32_t gs;
uint32_t ldt;
uint16_t trap;
uint16_t iomap_base;
}__attribute__((packed));
TaskStateSegment tss0 = {};
inline void flush_tss(){
asm volatile("mov (5 * 8) |0 , %eax; ltr %ax");
}
void setup_tss(){
// ensure the tss is zero'd
//memset((void*)&tss0, 0, sizeof(tss0));
tss0.ss0 = (uint32_t) &(GlobalDescriptorTable[KERNEL_DATA_SEGMENT]);
uint32_t esp_addr =0 ;
asm volatile ("movl %%esp, %0" : "=a"(esp_addr));
tss0.esp0 = esp_addr;
// Task Segment Descriptor
add_descriptor(TASK_STATE_SEGMENT, (unsigned long)&tss0, sizeof(tss0), 0x89, 0x0);
flush_tss();
}

View File

@ -1,17 +1,9 @@
#include "gdtc.h"
#include "../../terminal/kterm.h"
#define NULL_SEGMENT 0
#define KERNEL_CODE_SEGMENT 1
#define KERNEL_DATA_SEGMENT 2
#define USER_CODE_SEGMENT 3
#define USER_DATA_SEGMENT 4
#define TASK_STATE_SEGMENT 5
SegmentDescriptor GlobalDescriptorTable[6];
GlobalDescriptorTableDescriptor gdtDescriptor;
tss32 TaskStateSegment = {};
void add_descriptor(int which , unsigned long base, unsigned long limit, unsigned char access, unsigned char granularity ){
@ -32,9 +24,6 @@ void add_descriptor(int which , unsigned long base, unsigned long limit, unsigne
void initGDT(){
printf("Init GDT!\n");
// NULL segment
add_descriptor(NULL_SEGMENT, 0,0,0,0);
@ -50,14 +39,9 @@ void initGDT(){
// User Data Segement
add_descriptor(USER_DATA_SEGMENT, 0, 0xFFFFFFFF, 0xF2, 0xCF);
// Task Segment Descriptor
add_descriptor(TASK_STATE_SEGMENT, (unsigned long)&TaskStateSegment, sizeof(TaskStateSegment), 0x89, 0x0);
// init Gdt Descriptor
gdtDescriptor.limit = ((sizeof(SegmentDescriptor ) * 5 ) - 1);
gdtDescriptor.base = (unsigned int) (&GlobalDescriptorTable);
LoadGlobalDescriptorTable();
}

View File

@ -1,5 +1,16 @@
#pragma once
#include <stdint.h>
#define NULL_SEGMENT 0
#define KERNEL_CODE_SEGMENT 1
#define KERNEL_DATA_SEGMENT 2
#define USER_CODE_SEGMENT 3
#define USER_DATA_SEGMENT 4
#define TASK_STATE_SEGMENT 5
struct SegmentDescriptor {
unsigned short limit_low;
unsigned short base_low;
@ -9,10 +20,7 @@ struct SegmentDescriptor {
unsigned char base_high;
}__attribute__((packed));
struct tss32 {
uint64_t bits;
uint8_t other_bits :5;
}__attribute__((packed));
extern SegmentDescriptor GlobalDescriptorTable[6];
struct GlobalDescriptorTableDescriptor{
unsigned short limit;