Page 1 of 1

Strange error while switching task from main task and INT

Posted: Tue Dec 31, 2013 3:24 pm
by yee1
Hey,

My scheduler is based on IRQ0 interrupt.
While it's done in this way (nasm):

Code: Select all

main_program:
;some code here
sti
just_a_loop_in_main_program:
jmp just_a_loop_in_main_program

irq0_handler:
jmp dword 38h:0h
I know that I should make inside irq0_handler:
- a queue with tasks to switch,
- set 0x60 value to port 0x20,
- iretd instruction execution,
but it's only here to present my problem. In my code all of it is included ;) Main idea of code presented above is that it will be executed in main task (0x30 selector) and hardware switch will be done properly. A goal here was to move from main task (sel 0x30) to new task (0x38 sel).

Second code presents like:

Code: Select all

main_program:
;some code here

jmp dword 38h:0h

just_a_loop_in_main_program:
jmp just_a_loop_in_main_program
Above interrupts are disabled. A goal here is same as in first example, to change task from main (0x30 selector) to second (0x38 selector). This code causes Bochs returning errors, here is log:
00147099153i[BIOS ] Booting from 0000:7c00
00153600004i[XGUI ] charmap update. Font Height is 16
00168295795e[CPU0 ] jump_protected: gate type 11 unsupported
00168295801e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295807e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295813e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295819e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295825e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295831e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295837e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295843e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295849e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295855e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295861e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295867e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295873e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295879e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295885e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295891e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295897e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295903e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295909e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295915e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295921e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295927e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295933e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295939e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295945e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295951e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295957e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295963e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295969e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295975e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295981e[CPU0 ] fetch_raw_descriptor: LDTR.valid=0
00168295981e[CPU0 ] stackPrefetch(4): access [0xfffffffc] > SS.limit [0x00007000]
00168295981e[CPU0 ] stackPrefetch(4): access [0xfffffffc] > SS.limit [0x00007000]
00168295981i[CPU0 ] CPU is in protected mode (active)
00168295981i[CPU0 ] CS.mode = 32 bit
00168295981i[CPU0 ] SS.mode = 32 bit
00168295981i[CPU0 ] EFER = 0x00000000
00168295981i[CPU0 ] | EAX=0000ea46 EBX=00000004 ECX=00000002 EDX=00000000
00168295981i[CPU0 ] | ESP=00000004 EBP=00000000 ESI=00000090 EDI=00000000
Why jumping from task (not interrupt executed in main task context) causes problem here ?

I haven't set ESP0/SS0 values for TSS of new task I am jumping to. Main task and new task privilege levels are both "0". May it be a reason ? I didn't understand what SS0/ESP0 is for. OSdev wiki says about it only for software task switching. If some one could explain it to me then I would be grateful ;)

Re: Strange error while switching task from main task and IN

Posted: Thu Jan 02, 2014 12:24 pm
by yee1
I still haven't solved it...

Re: Strange error while switching task from main task and IN

Posted: Thu Jan 02, 2014 2:11 pm
by iansjack
What debugging have you done so far?

Re: Strange error while switching task from main task and IN

Posted: Sat Jan 04, 2014 3:44 pm
by yee1
iansjack wrote:What debugging have you done so far?
I've done until now almost same what I have written at first post. I am just walking around with this problem.

Task switching is working when it's executed from IRQ0 interrupt handler but it's not working when it executed directly from main task as describe above.

Re: Strange error while switching task from main task and IN

Posted: Sat Jan 04, 2014 4:07 pm
by iansjack
So you've not done any debugging, you're just thinking about the problem?

It may be possible to solve it that way, but I think you'd find it a lot easier if you looked at what was actually happening. Breakpoints, single-stepping, that sort of thing, watching what is happening to memory and registers as each instruction is executed. Even a few judicious print statements can help. This is probably a relatively simple problem compared with others you might later run up against, so it's a good opportunity to hone your debugging skills.