# HG changeset patch # User John Tsiombikas # Date 1306559207 -10800 # Node ID 2cb5ab18e76e52400908cb9d1c215c1dc0a8ffc6 # Parent 3ed041d07ae13f95883e5ba43ee18bb58ff27b50# Parent a2c6110bd24b27e5e605799dfce6cd52a472a589 merged the task bits, not completed also removed the memory-manager debugging calls from main diff -r 3ed041d07ae1 -r 2cb5ab18e76e src/intr.c --- a/src/intr.c Fri May 27 13:08:23 2011 +0300 +++ b/src/intr.c Sat May 28 08:06:47 2011 +0300 @@ -156,7 +156,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 3ed041d07ae1 -r 2cb5ab18e76e src/main.c --- a/src/main.c Fri May 27 13:08:23 2011 +0300 +++ b/src/main.c Sat May 28 08:06:47 2011 +0300 @@ -66,26 +66,6 @@ /* initialization complete, enable interrupts */ enable_intr(); - dbg_print_vm(MEM_USER); - dbg_print_vm(MEM_KERNEL); - - { - void *foo, *bar, *xyzzy, *koko, *lala; - - foo = malloc(128); - bar = malloc(32 * 1024); - xyzzy = malloc(8000); - - free(bar); - - koko = malloc(700); - lala = malloc(6 * 1024 * 1024); - - free(xyzzy); - free(foo); - free(koko); - free(lala); - } for(;;) { char c, keypress; diff -r 3ed041d07ae1 -r 2cb5ab18e76e src/proc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/proc.h Sat May 28 08:06:47 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 3ed041d07ae1 -r 2cb5ab18e76e src/segm.c --- a/src/segm.c Fri May 27 13:08:23 2011 +0300 +++ b/src/segm.c Sat May 28 08:06:47 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 3ed041d07ae1 -r 2cb5ab18e76e src/segm.h --- a/src/segm.h Fri May 27 13:08:23 2011 +0300 +++ b/src/segm.h Sat May 28 08:06:47 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 3ed041d07ae1 -r 2cb5ab18e76e src/tss.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tss.h Sat May 28 08:06:47 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_ */