problem with taskswitching...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ThomasSendelbach

problem with taskswitching...

Post by ThomasSendelbach »

Here a part of the code of my kernel
it handles the multitasking ...
if i switch the task with switch_task(0x28);
the pc reboots or he?s halting
but he should print out many Y on the screen :(


****************************************
#define ACCESSED   0x01
#define DATASEG_NOTREADABLE  0x00
#define DATASEG    0x02
#define DATASEG_RESERVED  0x04
#define DATASEG_EXPANDABLE    0x06
#define CODESEG_NOTREADABLE  0x08
#define CODESEG    0x0A
#define CODESEG_CONFORM_NR  0x0C
#define CODESEG_CONFORM   0x0E
#define SEGMENT    0x10
#define SYSTEM    0x00
#define DPL0    0x00
#define DPL1    0x20
#define DPL2    0x40
#define DPL3    0x60
#define PRESENT    0x80


#define TSS_80286   0x01
#define LDT    0x02
#define TSS_80286_ACTIVE  0x03
#define CALLGATE_80286   0x04
#define TASKGATE   0x05
#define INTGATE_80286   0x06
#define TRAPGATE_80286   0x07
#define TSS_80386   0x09
#define TSS_80386_ACTIVE  0x0B
#define CALLGATE_80386   0x0C
#define INTGATE_80386   0x0E
#define TRAPGATE_80386   0x0F


#define GRAN    0x40;
#define _80386    0x30;
#define AVL    0x10;



*********************************
typedef struct
{
unsigned short seg_0_15;
unsigned short addr_0_15;
unsigned char addr_16_23;
unsigned char type;
unsigned char seg_16_19;
unsigned char addr_24_31;
}__attribute__((packed)) DESK;

struct task_gate
{
unsigned long reserviert1;
unsigned long selektor;
unsigned char reserviert2;
unsigned char type;
unsigned long reserviert3;
}__attribute__((packed));


typedef struct
{
  unsigned short backlink, __blh;
  unsigned long esp0;
  unsigned short ss0, __ss0h;
  unsigned long esp1;
  unsigned short ss1, __ss1h;
  unsigned long esp2;
  unsigned short ss2, __ss2h;
  unsigned long cr3, eip, eflags;
  unsigned long eax,ecx,edx,ebx,esp,ebp,esi,edi;
  unsigned short es, __esh;
  unsigned short cs, __csh;
  unsigned short ss, __ssh;
  unsigned short ds, __dsh;
  unsigned short fs, __fsh;
  unsigned short gs, __gsh;
  unsigned short ldt, __ldth;
  unsigned short trace, iomapbase;
}__attribute__((packed)) TSS_STRUCT;

void init_task(unsigned char num,void *taskaddresse)
{
tasktabelle[num].esp=0xFFFF;
tasktabelle[num].es=0x8;
tasktabelle[num].cs=0x10;
tasktabelle[num].ss=0x18;
tasktabelle[num].ds=0x8;
tasktabelle[num].fs=0;
tasktabelle[num].gs=0;
tasktabelle[num].eip=(unsigned long)taskaddresse;
tasktabelle[num].eflags=0x0002;
tasktabelle[num].iomapbase=sizeof(TSS_STRUCT);
}

void ltr(unsigned short selector)
{
  asm ("ltr %0": :"r" (selector));
}

void switch_task(unsigned int selector)
{
  unsigned int sel[2];
  sel[1] = selector;

  asm ("ljmp %0": :"m" (*sel));
}


void desk(unsigned char num,unsigned long segsize,void *addr,unsigned char
type,unsigned char gran)
{
unsigned char a=0;
a=(unsigned long)addr;

gdt[num].seg_0_15=segsize & 0xffff;
gdt[num].seg_16_19=(segsize >> 16) & 0xFF;
gdt[num].type=type;
gdt[num].seg_16_19+=gran;

gdt[num].addr_0_15=a & 0xffff;
gdt[num].addr_16_23=(a >> 16) & 0xFF;
gdt[num].addr_24_31=(a >> 24) & 0xFF;
}
TSS_STRUCT tasktabelle[10];
DESK gdt[256];
**************task o**********************
void o()
{
go:
putchar('Y');
goto go;
}
****************************************
void main()
{
desk(0,0,0,0,0);
desk(1,0xFFFFF,0,DATASEG | SEGMENT | DPL0 | PRESENT,0xbf);
desk(2,0xFFFFF,0,CODESEG | SEGMENT | DPL0 | PRESENT,0xbf);
desk(3,0xFFFF,0, DATASEG | SEGMENT | DPL0 | PRESENT,0);

//somecode....
//....loading the gdt idt init the pit the pic and and and...


init_task(0,0);
init_task(1,o);

desk(4,sizeof(TSS_STRUCT),&tasktabelle[0],TSS_80386 | PRESENT,0);
desk(5,sizeof(TSS_STRUCT),&tasktabelle[1],TSS_80386 | PRESENT,0);
ltr(0x20);
switch_task(0x28);
//.....
//....
}
****************************************
please if someone could help me ... help me :)

[email protected]
or
[email protected]
or over the board
ThomasSendelbach

Re: problem with taskswitching...

Post by ThomasSendelbach »

the selector for the first task(kernel) is 0x20
the second for o(); is 0x28
Thomas Sendelbach

Re: problem with taskswitching...

Post by Thomas Sendelbach »

problem solved in function desk false cast
Post Reply