Page 1 of 1

Can't use interrupts after returning to realmode under Bochs

Posted: Sun Mar 02, 2008 12:42 pm
by yakujabi
I'm trying to set a video mode by returning to real-mode and issuing an interrupt.

It works well under all VMs I've tried, but Bochs just hangs in the interrupt handler without returning. I also get the following line spammed in the logfile:

io write to address 00000000, len=2

The steps I've taken to return to real-mode are:

0) cli
1) copy some 16-bit code to a low address
2) far-jump to that code on a 16-bit, 64k-limit code segment
3) clear first bit of cr0
4) far-jump to the next instruction
5) set proper real-mode segment register values
5) reset IDT & GDT to the real-mode defaults
6) set proper real-mode segment register values again (don't know if it's needed)
7) issue an interrupt

I'll appreciate it if anyone points out any mistakes I've made or any Bochs-gotchas that could be causing this behaviour. Thanks
:)

Posted: Sun Mar 02, 2008 12:57 pm
by Masterkiller
Did you check memory location 0000h:0000h? It should containt Interrupt Vector Table. IDT is not valid in real-mode, you could even keep it. Address 0x00000 shoud contain 32-bit value seg:offset for INT 0 and so on up to 0x3FF.

Re: Can't use interrupts after returning to realmode under B

Posted: Sun Mar 02, 2008 1:00 pm
by Brendan
Hi,

I think you might end up with a 32-bit stack (where "push byte 0x00" decreases SP by 4). Try this to see:

0) cli
1) copy some 16-bit code to a low address
2) far-jump to that code on a 16-bit, 64k-limit code segment
3) load 16-bit data segment registers (especially SS)
4) clear first bit of cr0
5) far-jump to the next instruction
6) set proper real-mode segment register values
7) reset IDT to the real-mode default (don't worry about the GDT)
8 ) issue an interrupt


Cheers,

Brendan

Posted: Sun Mar 02, 2008 1:22 pm
by Dex
You could also compare your code to my vesa demos, as the does what you want to do.
http://www.dex4u.com/demos/VesaDemo.zip

Re: Can't use interrupts after returning to realmode under B

Posted: Sun Mar 02, 2008 1:50 pm
by yakujabi
Brendan wrote:Hi,
I think you might end up with a 32-bit stack
Brendan
Thanks Brendan! The problem was indeed stack-related,it's fixed now, and the interrupt returns just fine

...except that it doesn't much more than that :shock:
Doesn't crash, doesn't print anything to the logfile, and worst of all, doesn't change video-modes :(

Any ideas on this one?

Thanks :)

Posted: Mon Mar 03, 2008 2:12 am
by yakujabi
Well, it turned out that I had a 16-bit stack that uses ESP, so now everything works well.

Thanks Brendan!