Where did all those last few posts go? Did it have something to do with the forum not working earlier?
Anyways, post again I must.
I'm getting a GPF if a task switch occurs during the execution of an INT. I have switched the int type from to a TRAP gate, as pype recommended. When I get the error:
EFLAGS: 0x10002 (Aren't the top 16 bits reserved/0?)
Error Code: 0x210
Code:
(Application)
Code: Select all
global _PrintString
global _ClearScreen
global _ArgA
global _Main
_Main:
;call _ClearScreen
.L1
mov ebx, StrN1
call _PrintString
jmp .L1
call _GetChar
mov ebx, StrN2
call _PrintString
ret
_ClearScreen:
mov ax, 0x00
int 0x50 ;Call text services
ret ;Return to C code
_PrintString:
mov ax, 0x01
int 0x50 ;Call text services
ret ;Return to C code
_GetChar:
.Le1:
mov ax, 0x02
int 0x50
;cmp al, 0
;je .Le1
ret
StrN1 db "Hello world! Type a letter:", 10, 0
StrN2 db 10, "You typed a letter!", 10, 0
(I have the infinite print string loop so that it almost garuantees it will be running an INT while a task switch occurs/IRQ0.
(INT handler)
Code: Select all
;Text mode services handler!
extern _ClearScreen
extern _PrintString
extern _GetChar
global _SRV_TextModeService
_SRV_TextModeService:
cmp ax, 0x00 ;Clear Screen?
je ClearScreenService ;Yes
cmp ax, 0x01 ;Print String?
je PrintStringService ;Yes
cmp ax, 0x02 ;Getchar?
je GetCharService ;Yes
iret ;Invalid function, just return
ClearScreenService: ;Clear screen function
call _ClearScreen ;Clear the screen (call C code)
jmp ServiceCommonReturn
PrintStringService: ;Print string function
push ebx ;Push argument to C code, pointer to string
call _PrintString ;Print it (call C code)
add esp, 4
jmp ServiceCommonReturn
GetCharService:
.L1:
xor eax, eax
call _GetChar
cmp al, 0
je .L1
jmp ServiceCommonReturn
ServiceCommonReturn:
cli
iret
(Task Switch Handler)
Code: Select all
global _ASM_TaskStub
extern _MT_SwitchTask
extern _CurrentCR3
;When called by an IRQ from processor, allows task switches
_ASM_TaskStub:
cli
pushad ;Push all general purpose registers
push ds ;Push data segment
push es ;Push data segment 'e'
push fs ;Push data segment 'f'
push gs ;Push data segment 'g'
mov eax, esp ;Get current stack pointer
push eax ;Push it as argument to C function
call _MT_SwitchTask ;Call 'C code' task scheduler
add esp, 4 ;Clean up pushed argument to 'C code'
mov esp, eax ;Set new task's stack pointer. (EAX from C code return value)
mov eax, [_CurrentCR3] ;Get CR3 from C code data
mov cr3, eax ;Set new CR3 for task
pop gs ;Pop off data segment 'g'
pop fs ;Pop off data segment 'f'
pop es ;Pop off data segment 'e'
pop ds ;Pop off data segmemt
popad ;Pop all general purpose registers
iret ;Interrupt Return. Installs EIP etc. of new task