Page 1 of 1
Far jump to task
Posted: Sun Dec 15, 2013 8:53 pm
by ManyGifts
Hey I have main task + 2 more tasks, until now i was doing
call 40h:0h
To call my task, where 40h is selector.
Until now i was using iret instruction and I was rewriting EIP register for used TSS and then send eoi in timer interrupt
0x20 value for port 0x20
Now i started using jmp dword 0x:40:0x0 and i have infinite loop in my tasks
Before jmp dword 0x40:0x0 i send EOI signal 0x20 value for port 0x20
But i have noticed that it's working wrong i can't debugg it becouse bochs dont break point for itq0 interrupts but it seems like only 1 interrupt income
It was like that (pseudo-code):
irq0_interrupt_income:
mov al, 20h
out 20h, al
cmp byte [tasknumber], 0
je run0task
inc byte [tasknumber]
jmp dword 0x40:0x0 ;run task1
run0task:
mov byte [tasknumber], 0
jmp dword 0x48:0x0 ;run task 2
iretd
What may be reason of it ?
By the way i have noticed on some site that guy was sending 0x60 value for port 0x20 as EOI signal. what for ? It's extra bit set there, but why ?
Re: Far jump to task
Posted: Sun Dec 15, 2013 11:52 pm
by BMW
Do you even know assembly, or BBCode?
Re: Far jump to task
Posted: Mon Dec 16, 2013 5:09 am
by ManyGifts
BMW wrote:Do you even know assembly, or BBCode?
I dont understand ?
Re: Far jump to task
Posted: Mon Dec 16, 2013 6:45 am
by Combuster
I dont[sic] understand ?
But you edited nonetheless.
pseudo-code
Is the real code so much bigger that it matters? That might also be the error.
But i[sic] have noticed that it's working wrong i[sic] can't debugg[sic] it becouse[sic] bochs dont[sic] break point[sic] for itq0[sic] interrupts but it seems like only 1 interrupt income[sic]
don't, no space before punctuaton, I (the capital letter), missing punctuation, I, debug, because, doesn't, breakpoint, IRQ0, was received. It rather looks like English is your biggest enemy right now. That or you're too lazy to do any form of writing correctly - text or code.
That aside, this actually is a frequently asked question:
FAQ - so maybe you should be more careful in doing what it says.
From now on, all instances of number 20 are to have a different meaning?
Now, could you please sanitize everything so that we aren't wasting time trying to figure out what garbage is real and which isn't?
Re: Far jump to task
Posted: Mon Dec 16, 2013 7:34 am
by ManyGifts
Combuster wrote:I dont[sic] understand ?
But you edited nonetheless.
pseudo-code
Is the real code so much bigger that it matters? That might also be the error.
But i[sic] have noticed that it's working wrong i[sic] can't debugg[sic] it becouse[sic] bochs dont[sic] break point[sic] for itq0[sic] interrupts but it seems like only 1 interrupt income[sic]
don't, no space before punctuaton, I (the capital letter), missing punctuation, I, debug, because, doesn't, breakpoint, IRQ0, was received. It rather looks like English is your biggest enemy right now. That or you're too lazy to do any form of writing correctly - text or code.
That aside, this actually is a frequently asked question:
FAQ - so maybe you should be more careful in doing what it says.
From now on, all instances of number 20 are to have a different meaning?
Now, could you please sanitize everything so that we aren't wasting time trying to figure out what garbage is real and which isn't?
Sorry it was like 4:00 a.m. at my country while i was posting it, yea i see mistakes now, sry
So let's have an exmaple:
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
add word [currentTSS],8 ;Get next TSS to switch to
cmp word [currentTSS],0x38 ;Is it too high?
jbe .l1 ; no
mov word [currentTSS],0x30 ; yes, wrap around to first TSS
.l1:
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
pop eax
iretd
My problem is that
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
Seems to be false, because it seems like it does not continue after jump instruction and IRETD instruction is not executed. Also irq0 procedure is not executed no more...
As far jmp argument I use selector of GDT.
My irq0 is 32-bit interrupt gate type
I don't use task gate, should I ?
What is wrong in it ?
Also, what category of FAQ would help me ? I don't see anything useful for this problem.
Re: Far jump to task
Posted: Mon Dec 16, 2013 2:04 pm
by Brendan
Hi,
ManyGifts wrote:So let's have an exmaple:
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
add word [currentTSS],8 ;Get next TSS to switch to
cmp word [currentTSS],0x38 ;Is it too high?
jbe .l1 ; no
mov word [currentTSS],0x30 ; yes, wrap around to first TSS
.l1:
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
pop eax
iretd
My problem is that
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
This "jmp" causes a task switch, where the address of the instruction after then "jmp" is stored in the "CS" and "EIP" fields of the current task's TSS, and then CS and EIP (and other stuff) is loaded from the TSS you're switching to. The next instruction the CPU executes will (hopefully) be whatever is at the "CS:EIP" stored in the TSS you switched to. Eventually (hopefully) something will cause a task switch back to your task, and your task will continue executing at whatever is at the "CS:EIP" stored in your task's TSS, which will be the address of the instruction after the "jmp" (which was stored in the TSS earlier by the "jmp" instruction).
Basically; "execution of this task will continue after the jump (when something switches back to this task)".
ManyGifts wrote:Seems to be false, because it seems like it does not continue after jump instruction and IRETD instruction is not executed. Also irq0 procedure is not executed no more...
That's because you never switch back to the task. I'd guess your code crashes before that happens.
Cheers,
Brendan
Re: Far jump to task
Posted: Mon Dec 16, 2013 2:28 pm
by ManyGifts
Brendan wrote:Hi,
ManyGifts wrote:So let's have an exmaple:
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
add word [currentTSS],8 ;Get next TSS to switch to
cmp word [currentTSS],0x38 ;Is it too high?
jbe .l1 ; no
mov word [currentTSS],0x30 ; yes, wrap around to first TSS
.l1:
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
pop eax
iretd
My problem is that
jmp far [currentTSSfarPointer] ;WARNING: Task switch and not a JMP (execution continues after the jump)
This "jmp" causes a task switch, where the address of the instruction after then "jmp" is stored in the "CS" and "EIP" fields of the current task's TSS, and then CS and EIP (and other stuff) is loaded from the TSS you're switching to. The next instruction the CPU executes will (hopefully) be whatever is at the "CS:EIP" stored in the TSS you switched to. Eventually (hopefully) something will cause a task switch back to your task, and your task will continue executing at whatever is at the "CS:EIP" stored in your task's TSS, which will be the address of the instruction after the "jmp" (which was stored in the TSS earlier by the "jmp" instruction).
Basically; "execution of this task will continue after the jump (when something switches back to this task)".
ManyGifts wrote:Seems to be false, because it seems like it does not continue after jump instruction and IRETD instruction is not executed. Also irq0 procedure is not executed no more...
That's because you never switch back to the task. I'd guess your code crashes before that happens.
Cheers,
Brendan
Yes, you're right - it doesn't back to IRQ0 handler, but how to deal with it ?
I want to have a infinite loop in my tasks and don't use IRETD instruction there.
I have noticed that
jmp far has other opcode than
jmp dword. I was also switching by:
db 0eah
dd 0
dw 0x40
That equals
jmp dword, where 0x40 is selector of task's GDT.
I have found some examples at book where it was done as in my code or perhaps i haven't noticed something. Really dunno... please some details how to resolve this problem.
Re: Far jump to task
Posted: Mon Dec 16, 2013 3:15 pm
by Gigasoft
Did you remember to initialize EFLAGS in the second task's TSS so that the IF bit is set?
Re: Far jump to task
Posted: Mon Dec 16, 2013 4:35 pm
by ManyGifts
Gigasoft wrote:Did you remember to initialize EFLAGS in the second task's TSS so that the IF bit is set?
You are right, IF bit in EFLAGS was a problem.
I did It some right away you posted it and after that i noticed another problem (
). I have 5 tasks in my queue and I have noticed that each task run correctly for 1st time, but after 2nd run it breaks because something wrong happens.
Well when interrupt occurs then NT flag and IF flag is set to 0. That seems to be a problem but I have set it again to TSS before jump to new task and it didn't help. What is the reason of it ?