Brendan wrote:Hi,
yee1 wrote:This code is working in Bochs but it's not working with virtual box / real machine. What may be cause of it ?
It shouldn't be working in Bochs either - you have to send the EOI to the PIC before you do the task switch.
Also note that it's cleaner to do an indirect far jump ("jmp far [currentTSS]") instead of "if(1) jmp 1; elseif(2) jmp 2; elseif(3) jmp 3;...".
Finally (eventually) you want this split into 3 pieces - the IRQ handler, a "reschedule" function and a "goto_task" function. For an example and explanation see
this post.
Cheers,
Brendan
About EIO - Yes, you're right. I was writing this code from memory and forgot about this, it's in my code. But my problem is about task switching and running instructions after task switch (jmp dword) instruction.
Ok the, it seems that you're talking about this code:
Code: Select all
section .data
currentTSSfarPointer:
dd 0 ;Note: CPU ignores the "offset" part, so there's not much point having it..
currentTSS:
dw 0x38
section .text
;Note: IRQ0 *must* be an "interrupt gate" (and can not be a "trap gate")
irq0_interrupt_service:
push eax
;send eoi signal (end of interrupt)
mov al, 0x20
out 0x20, al
call reschedule
pop eax
iretd
;Find task to run and switch to it
reschedule:
push eax
movzx eax,[currentTSS]
add eax,,8 ;eax = next TSS to switch to
cmp eax,0x38 ;Is it too high?
jbe .l1 ; no
mov eax,0x30 ; yes, wrap around to first TSS
call gotoTask
pop eax
ret
;Switch to a specific task
;
;Input
; ax = TSS for task to switch to
gotoTask:
cmp [currentTSS],ax ;Is this task currently running?
je .done ; yes, do *not* attempt to switch (will cause GPF)
mov [currentTSS],ax
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
.done:
ret
I don't understand this line of code
Code: Select all
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
Why will it continue execution of next instructions after
jmp far [currentTSSfarPointer] is executed ?
Well I know there should be values to be pop'ed from stack by iret instruction, but how it's possible that after far jump next instruction won't be executed of jumped task ? When irq interrupt is done at stack it has pushed 12 bytes (eip/cs/eflags), right ? But eip/cs/eflags are saved data of task where irq was executed. When iret will be executed it would back task that it was executed from, right ?
Well you have used "jmp far" instruction, i suppose it for tasm or fasm. I write my code in nasm and i am using "jmp dword" instruction. Is it wrong ? Opcodes of both instructions are different.
Thank you.