Software Based Multitasking
Posted: Thu Dec 27, 2007 10:17 am
Hey everyone,
I have decided to go with software-based multitasking, and I have already written some code for it. I'm not sure when I should call the task switcher. Should I call it in my IRQ code, or in the actual 8253 timer handler? Here is my code:
Switch.asm:
C switch:
Exception:
Edit:
Just started getting this error:
Thanks in advance for your help
--Michael
I have decided to go with software-based multitasking, and I have already written some code for it. I'm not sure when I should call the task switcher. Should I call it in my IRQ code, or in the actual 8253 timer handler? Here is my code:
Switch.asm:
Code: Select all
extern kernel_entry
global tswitch
tswitch:
push gs
push fs
push es
push ds
push ebp
push edi
push esi
push edx
push ecx
push ebx
push eax
mov ebx, esp
mov esp, stacktop
push ebx
mov ax, 10h
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call kernel_entry
pop ebx
mov esp, ebx
pop eax
pop ebx
pop ecx
pop edx
pop esi
pop edi
pop ebp
pop ds
pop es
pop fs
pop gs
add esp, 8
iret
[section .bss]
resb 8192
stacktop:
Code: Select all
#include <regs.h>
int kernel_entry( struct regs *r )
{
printf("Entry\n");
//asm("hlt"); //If I have this here, no exception
return r;
}
Code: Select all
void timer_handler(struct regs *r)
{
timer_ticks++;
printf("Tick: %i\n", timer_ticks);
if (!( timer_ticks % 100 ))
{
printf("switching...");
tswitch();
printf("returning...");
}
}
Code: Select all
00022236158e[CPU0 ] check_cs: not a valid code segment !
00076686000p[WGUI ] >>PANIC<< POWER button turned off.
00076686000i[SYS ] Last time is 1198772194
00076686000i[CPU0 ] protected mode
00076686000i[CPU0 ] CS.d_b = 32 bit
00076686000i[CPU0 ] SS.d_b = 32 bit
00076686000i[CPU0 ] | EAX=000000f0 EBX=00067dd8 ECX=00000026 EDX=000003d5
00076686000i[CPU0 ] | ESP=00067dc4 EBP=00067dcc ESI=0002beb5 EDI=0002beb6
00076686000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
00076686000i[CPU0 ] | SEG selector base limit G D
00076686000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00076686000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00076686000i[CPU0 ] | EIP=00100984 (00100984)
00076686000i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x00000000
00076686000i[CPU0 ] | CR3=0x0010b000 CR4=0x00000000
00076686000i[CPU0 ] >> jmp .+0xfffffffe (0x00100984) : EBFE
00076686000i[ ] restoring default signal behavior
00076686000i[CTRL ] quit_sim called with exit code 1
Just started getting this error:
Code: Select all
fetch_raw_descriptor: LDT: index (7e97)fd2 > limit (0)
--Michael