kern

diff src/segm.c @ 29:8ea6debe4265

starting on the task switching implementation
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 23 Apr 2011 00:51:18 +0300
parents b11a86695493
children f65b348780e3
line diff
     1.1 --- a/src/segm.c	Wed Apr 06 07:42:44 2011 +0300
     1.2 +++ b/src/segm.c	Sat Apr 23 00:51:18 2011 +0300
     1.3 @@ -11,6 +11,8 @@
     1.4  #define BIT_CODE		(1 << 11)
     1.5  #define BIT_NOSYS		(1 << 12)
     1.6  #define BIT_PRESENT		(1 << 15)
     1.7 +/* TSS busy bit */
     1.8 +#define BIT_BUSY		(1 << 9)
     1.9  
    1.10  /* bits for the last 16bit part of the descriptor */
    1.11  #define BIT_BIG			(1 << 6)
    1.12 @@ -19,7 +21,11 @@
    1.13  
    1.14  enum {TYPE_DATA, TYPE_CODE};
    1.15  
    1.16 +#define TSS_TYPE_BITS	0x900
    1.17 +#define TSS_BUSY		BIT_BUSY
    1.18 +
    1.19  static void segm_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, int type);
    1.20 +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy);
    1.21  
    1.22  /* these functions are implemented in segm-asm.S */
    1.23  void setup_selectors(uint16_t code, uint16_t data);
    1.24 @@ -27,7 +33,7 @@
    1.25  
    1.26  
    1.27  /* our global descriptor table */
    1.28 -static desc_t gdt[3];
    1.29 +static desc_t gdt[6];
    1.30  
    1.31  
    1.32  void init_segm(void)
    1.33 @@ -35,6 +41,9 @@
    1.34  	memset(gdt, 0, sizeof gdt);
    1.35  	segm_desc(gdt + SEGM_KCODE, 0, 0xffffffff, 0, TYPE_CODE);
    1.36  	segm_desc(gdt + SEGM_KDATA, 0, 0xffffffff, 0, TYPE_DATA);
    1.37 +	segm_desc(gdt + SEGM_UCODE, 0, 0xffffffff, 3, TYPE_CODE);
    1.38 +	segm_desc(gdt + SEGM_UDATA, 0, 0xffffffff, 3, TYPE_DATA);
    1.39 +	/*task_desc(gdt + SEGM_TASK, 0, 0xffffffff, 3, TSS_BUSY);*/
    1.40  
    1.41  	set_gdt((uint32_t)gdt, sizeof gdt - 1);
    1.42  
    1.43 @@ -64,3 +73,13 @@
    1.44  	 */
    1.45  	desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN | BIT_BIG;
    1.46  }
    1.47 +
    1.48 +static void task_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, unsigned int busy)
    1.49 +{
    1.50 +	desc->d[0] = limit & 0xffff;
    1.51 +	desc->d[1] = base & 0xffff;
    1.52 +
    1.53 +	desc->d[2] = ((base >> 16) & 0xff) | ((dpl & 3) << 13) | BIT_PRESENT |
    1.54 +		TSS_TYPE_BITS | busy;
    1.55 +	desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN;
    1.56 +}