kern

changeset 29:8ea6debe4265

starting on the task switching implementation
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 23 Apr 2011 00:51:18 +0300
parents 9939a6d7a45a
children a2c6110bd24b
files src/intr.c src/proc.h src/segm.c src/segm.h src/tss.h
diffstat 5 files changed, 59 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/intr.c	Wed Apr 06 07:42:44 2011 +0300
     1.2 +++ b/src/intr.c	Sat Apr 23 00:51:18 2011 +0300
     1.3 @@ -159,7 +159,7 @@
     1.4  	desc->d[3] = (addr & 0xffff0000) >> 16;
     1.5  }
     1.6  
     1.7 -#define IS_TRAP(n)	((n) < 32)
     1.8 +#define IS_TRAP(n)	((n) >= 32 && !IS_IRQ(n))
     1.9  static void set_intr_entry(int num, void (*handler)(void))
    1.10  {
    1.11  	int type = IS_TRAP(num) ? GATE_TRAP : GATE_INTR;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/proc.h	Sat Apr 23 00:51:18 2011 +0300
     2.3 @@ -0,0 +1,14 @@
     2.4 +#ifndef PROC_H_
     2.5 +#define PROC_H_
     2.6 +
     2.7 +#include "tss.h"
     2.8 +
     2.9 +struct process {
    2.10 +	int id;
    2.11 +
    2.12 +	struct task_state tss;
    2.13 +
    2.14 +	struct process *next;
    2.15 +};
    2.16 +
    2.17 +#endif	/* PROC_H_ */
     3.1 --- a/src/segm.c	Wed Apr 06 07:42:44 2011 +0300
     3.2 +++ b/src/segm.c	Sat Apr 23 00:51:18 2011 +0300
     3.3 @@ -11,6 +11,8 @@
     3.4  #define BIT_CODE		(1 << 11)
     3.5  #define BIT_NOSYS		(1 << 12)
     3.6  #define BIT_PRESENT		(1 << 15)
     3.7 +/* TSS busy bit */
     3.8 +#define BIT_BUSY		(1 << 9)
     3.9  
    3.10  /* bits for the last 16bit part of the descriptor */
    3.11  #define BIT_BIG			(1 << 6)
    3.12 @@ -19,7 +21,11 @@
    3.13  
    3.14  enum {TYPE_DATA, TYPE_CODE};
    3.15  
    3.16 +#define TSS_TYPE_BITS	0x900
    3.17 +#define TSS_BUSY		BIT_BUSY
    3.18 +
    3.19  static void segm_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, int type);
    3.20 +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy);
    3.21  
    3.22  /* these functions are implemented in segm-asm.S */
    3.23  void setup_selectors(uint16_t code, uint16_t data);
    3.24 @@ -27,7 +33,7 @@
    3.25  
    3.26  
    3.27  /* our global descriptor table */
    3.28 -static desc_t gdt[3];
    3.29 +static desc_t gdt[6];
    3.30  
    3.31  
    3.32  void init_segm(void)
    3.33 @@ -35,6 +41,9 @@
    3.34  	memset(gdt, 0, sizeof gdt);
    3.35  	segm_desc(gdt + SEGM_KCODE, 0, 0xffffffff, 0, TYPE_CODE);
    3.36  	segm_desc(gdt + SEGM_KDATA, 0, 0xffffffff, 0, TYPE_DATA);
    3.37 +	segm_desc(gdt + SEGM_UCODE, 0, 0xffffffff, 3, TYPE_CODE);
    3.38 +	segm_desc(gdt + SEGM_UDATA, 0, 0xffffffff, 3, TYPE_DATA);
    3.39 +	/*task_desc(gdt + SEGM_TASK, 0, 0xffffffff, 3, TSS_BUSY);*/
    3.40  
    3.41  	set_gdt((uint32_t)gdt, sizeof gdt - 1);
    3.42  
    3.43 @@ -64,3 +73,13 @@
    3.44  	 */
    3.45  	desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN | BIT_BIG;
    3.46  }
    3.47 +
    3.48 +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy)
    3.49 +{
    3.50 +	desc->d[0] = limit & 0xffff;
    3.51 +	desc->d[1] = base & 0xffff;
    3.52 +
    3.53 +	desc->d[2] = ((base >> 16) & 0xff) | ((dpl & 3) << 13) | BIT_PRESENT |
    3.54 +		TSS_TYPE_BITS | busy;
    3.55 +	desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN;
    3.56 +}
     4.1 --- a/src/segm.h	Wed Apr 06 07:42:44 2011 +0300
     4.2 +++ b/src/segm.h	Sat Apr 23 00:51:18 2011 +0300
     4.3 @@ -3,6 +3,9 @@
     4.4  
     4.5  #define SEGM_KCODE	1
     4.6  #define SEGM_KDATA	2
     4.7 +#define SEGM_UCODE	3
     4.8 +#define SEGM_UDATA	4
     4.9 +#define SEGM_TASK	5
    4.10  
    4.11  void init_segm(void);
    4.12  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/tss.h	Sat Apr 23 00:51:18 2011 +0300
     5.3 @@ -0,0 +1,21 @@
     5.4 +#ifndef TSS_H_
     5.5 +#define TSS_H_
     5.6 +
     5.7 +#include <inttypes.h>
     5.8 +
     5.9 +struct task_state {
    5.10 +	uint32_t prev_task;
    5.11 +	uint32_t esp0, ss0;
    5.12 +	uint32_t esp1, ss1;
    5.13 +	uint32_t esp2, ss2;
    5.14 +	uint32_t cr3;
    5.15 +	uint32_t eip;
    5.16 +	uint32_t eflags;
    5.17 +	uint32_t eax, ecx, edx, ebx;
    5.18 +	uint32_t esp, ebp, esi, edi;
    5.19 +	uint32_t es, cs, ss, ds, fs, gs;
    5.20 +	uint32_t ldt_sel;
    5.21 +	uint16_t trap, iomap_addr;
    5.22 +} __attribute__((packed));
    5.23 +
    5.24 +#endif	/* TSS_H_ */