problem with task switching

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
crackers

problem with task switching

Post by crackers »

I've problem with initiating task switching. My code looks like this

Code: Select all

void main()
{
 init_sys();
 add_Task(...);
 asm("jmp $0x50,$0");  // switch to new task
}
and 10th position in GDT is TSS segment descriptor.
Problem is that under Bochs my VM is reseting and in log I'm getting something like this

Code: Select all

00004601482i[FDD  ] partial read() on floppy image returns 192/512
00004618365i[CPU0 ] read_virtual_checks(): read beyond limit
00004618377i[CPU0 ] read_virtual_checks(): read beyond limit
00004618389i[CPU0 ] read_virtual_checks(): read beyond limit


(Last line is repeated many times and at after that I have)

00009269278i[CPU0 ] can_push(): expand-up: esp < N
00009269278i[CPU0 ] can_push(): expand-up: esp < N
00009269278e[CPU0 ] exception(): 3rd (12) exception with no resolution, shutdown status is 00h, resetting
Under VMware I'm getting messagebox "VMware Workstation internal monitor error NOT_IMPLEMENTED vmcore/vmm32/cpu/segment.c:2388. Please report this problem....." and so on.
I don't know what I'm doing wrong. I've tried to decrease TSS limit to be below 0x67. Then I'm getting 10th exception so till this moment everything is ok - 3rd point of task switching in intel manual (page 6-13). I've set T flag in TSS but I'm not getting 1st exception so somewhere between points 4 - 14 (intel manual) in task switching somethings goes wrong. At the end of Bochs log I've

Code: Select all

00009269278i[CPU0 ] protected mode
00009269278i[CPU0 ] CS.d_b = 32 bit
00009269278i[CPU0 ] SS.d_b = 32 bit
00009269278i[CPU0 ] | EAX=00000000  EBX=00000000  ECX=00000000  EDX=00000000
00009269278i[CPU0 ] | ESP=00000003  EBP=0000000f  ESI=00000000  EDI=00000000
00009269278i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00009269278i[CPU0 ] | SEG selector     base    limit G D
00009269278i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00009269278i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00009269278i[CPU0 ] |  DS:000c( 0001| 1|  0) 00011260 0000ffff 0 1
00009269278i[CPU0 ] |  SS:002c( 0005| 1|  0) 000bfffc 0000ffff 0 1
00009269278i[CPU0 ] |  ES:000c( 0001| 1|  0) 00011260 0000ffff 0 1
00009269278i[CPU0 ] |  FS:000c( 0001| 1|  0) 00011260 0000ffff 0 1
00009269278i[CPU0 ] |  GS:000c( 0001| 1|  0) 00011260 0000ffff 0 1
00009269278i[CPU0 ] | EIP=00010099 (00010099)
00009269278i[CPU0 ] | CR0=0x00000019 CR1=0 CR2=0x00000000
00009269278i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
It looks like all segment registers have been read from TSS except for CS and Other registers (EAX, EBX,...). Also I've noticed that ESP has rather small value so I think that something is being called until there is no more place on stack (I think that those 'read_virtual_checks(): read beyond limit' have something to do with it).
When I delete asm("jmp $0x50,$0"); instruction from my code everything works fine.

If anyone know what is wrong, what should I check or how to get more info from bochs than 'read_virtual_checks...' Iwould be very grateful.
JAAman

Re:problem with task switching

Post by JAAman »

have you looked at section 5.15 -- #TS (int10)? (page 5-40 --rev.16)
it gives a list of reasons why you might get a #TS (which can be in either the new or old task context)


that FDD error looks strange (i mean, should there be one in your task switch?), i wonder if its related?

otherwise, your invalid reads could be because of step 8? (updating the old TSS)
haven't done hard-switching myself, so im just guessing


ps:
when you reference intel page#s, specify the revision, as some pages change (though section#s will not, you were in section 6.3)
crackers

Re:problem with task switching

Post by crackers »

JAAman wrote: have you looked at section 5.15 -- #TS (int10)? (page 5-40 --rev.16)
it gives a list of reasons why you might get a #TS (which can be in either the new or old task context)
I think tou misunderstood me. I'm not getting any exception. Only reboot (Bochs) or some info (VMware). Exception I was talking about was forced by me (I wanted to know how far process of task switching is getting)
JAAman wrote: that FDD error looks strange (i mean, should there be one in your task switch?), i wonder if its related?
You mean this

Code: Select all

00004601482i[FDD  ] partial read() on floppy image returns 192/512
I think it's only informing that something was read from floppy. I put there so you could see where those "read_virtual_checks(): read beyond limit" start to show up.
JAAman wrote: otherwise, your invalid reads could be because of step 8? (updating the old TSS)
haven't done hard-switching myself, so im just guessing
I thought about that too. I wonder what happens when I'm initiating task switching? Should I initialiaze TR register, because I'm not sure is processor able to tell that it should'nt write anything to old TSS because there was'nt any task before.
JAAman wrote: ps:
when you reference intel page#s, specify the revision, as some pages change (though section#s will not, you were in section 6.3)
I must admit that I did'nt know that. thx
xenos

Re:problem with task switching

Post by xenos »

When you jump to the new TSS, the current register values are stored in the current TSS which ich referenced by the contents of the task register. Have you set up another TSS where the old register values can be placed and loaded its address into the task register using the ltr instruction? If not, you might get some exceptions causing a triple fault that will reboot the system.
crackers

Re:problem with task switching

Post by crackers »

XenOS wrote: When you jump to the new TSS, the current register values are stored in the current TSS which ich referenced by the contents of the task register. Have you set up another TSS where the old register values can be placed and loaded its address into the task register using the ltr instruction? If not, you might get some exceptions causing a triple fault that will reboot the system.
I've load TR register before swiching to new task and it helped. Well I'm still getting some double exceptions, but after succesful task switch. big thx ;D
JAAman

Re:problem with task switching

Post by JAAman »

I think tou misunderstood me. I'm not getting any exception. Only reboot (Bochs) or some info (VMware). Exception I was talking about was forced by me (I wanted to know how far process of task switching is getting)
there is always an exception -- however it is possible that you cannot trap it (do to invalid state) -- basicaly if your system is rebooting, then there is an exception that isn't being caught (or a hardware failure -- not really possible under bochs, though i it normally doesn't just reboot either)
Post Reply