# HG changeset patch # User John Tsiombikas # Date 1303509078 -10800 # Node ID 8ea6debe42656d1dfe1e6daec19ccf511efab047 # Parent 9939a6d7a45a1ea08d4094cffa302a1890c726d8 starting on the task switching implementation diff -r 9939a6d7a45a -r 8ea6debe4265 src/intr.c --- a/src/intr.c Wed Apr 06 07:42:44 2011 +0300 +++ b/src/intr.c Sat Apr 23 00:51:18 2011 +0300 @@ -159,7 +159,7 @@ desc->d[3] = (addr & 0xffff0000) >> 16; } -#define IS_TRAP(n) ((n) < 32) +#define IS_TRAP(n) ((n) >= 32 && !IS_IRQ(n)) static void set_intr_entry(int num, void (*handler)(void)) { int type = IS_TRAP(num) ? GATE_TRAP : GATE_INTR; diff -r 9939a6d7a45a -r 8ea6debe4265 src/proc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/proc.h Sat Apr 23 00:51:18 2011 +0300 @@ -0,0 +1,14 @@ +#ifndef PROC_H_ +#define PROC_H_ + +#include "tss.h" + +struct process { + int id; + + struct task_state tss; + + struct process *next; +}; + +#endif /* PROC_H_ */ diff -r 9939a6d7a45a -r 8ea6debe4265 src/segm.c --- a/src/segm.c Wed Apr 06 07:42:44 2011 +0300 +++ b/src/segm.c Sat Apr 23 00:51:18 2011 +0300 @@ -11,6 +11,8 @@ #define BIT_CODE (1 << 11) #define BIT_NOSYS (1 << 12) #define BIT_PRESENT (1 << 15) +/* TSS busy bit */ +#define BIT_BUSY (1 << 9) /* bits for the last 16bit part of the descriptor */ #define BIT_BIG (1 << 6) @@ -19,7 +21,11 @@ enum {TYPE_DATA, TYPE_CODE}; +#define TSS_TYPE_BITS 0x900 +#define TSS_BUSY BIT_BUSY + static void segm_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, int type); +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy); /* these functions are implemented in segm-asm.S */ void setup_selectors(uint16_t code, uint16_t data); @@ -27,7 +33,7 @@ /* our global descriptor table */ -static desc_t gdt[3]; +static desc_t gdt[6]; void init_segm(void) @@ -35,6 +41,9 @@ memset(gdt, 0, sizeof gdt); segm_desc(gdt + SEGM_KCODE, 0, 0xffffffff, 0, TYPE_CODE); segm_desc(gdt + SEGM_KDATA, 0, 0xffffffff, 0, TYPE_DATA); + segm_desc(gdt + SEGM_UCODE, 0, 0xffffffff, 3, TYPE_CODE); + segm_desc(gdt + SEGM_UDATA, 0, 0xffffffff, 3, TYPE_DATA); + /*task_desc(gdt + SEGM_TASK, 0, 0xffffffff, 3, TSS_BUSY);*/ set_gdt((uint32_t)gdt, sizeof gdt - 1); @@ -64,3 +73,13 @@ */ desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN | BIT_BIG; } + +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy) +{ + desc->d[0] = limit & 0xffff; + desc->d[1] = base & 0xffff; + + desc->d[2] = ((base >> 16) & 0xff) | ((dpl & 3) << 13) | BIT_PRESENT | + TSS_TYPE_BITS | busy; + desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN; +} diff -r 9939a6d7a45a -r 8ea6debe4265 src/segm.h --- a/src/segm.h Wed Apr 06 07:42:44 2011 +0300 +++ b/src/segm.h Sat Apr 23 00:51:18 2011 +0300 @@ -3,6 +3,9 @@ #define SEGM_KCODE 1 #define SEGM_KDATA 2 +#define SEGM_UCODE 3 +#define SEGM_UDATA 4 +#define SEGM_TASK 5 void init_segm(void); diff -r 9939a6d7a45a -r 8ea6debe4265 src/tss.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tss.h Sat Apr 23 00:51:18 2011 +0300 @@ -0,0 +1,21 @@ +#ifndef TSS_H_ +#define TSS_H_ + +#include + +struct task_state { + uint32_t prev_task; + uint32_t esp0, ss0; + uint32_t esp1, ss1; + uint32_t esp2, ss2; + uint32_t cr3; + uint32_t eip; + uint32_t eflags; + uint32_t eax, ecx, edx, ebx; + uint32_t esp, ebp, esi, edi; + uint32_t es, cs, ss, ds, fs, gs; + uint32_t ldt_sel; + uint16_t trap, iomap_addr; +} __attribute__((packed)); + +#endif /* TSS_H_ */