Page 2 of 2
Re: Problem printing to screen in protected mode
Posted: Wed Mar 28, 2012 5:15 pm
by Ziddia
VolTeK wrote:sreg shows the content of the Segment registers. If you thought that was relevant there is a missing portion of education in either assembler, or how to use the debugger you need to gain.
0xFE0AF refers to bios memory. Do a cli hlt and get the address halted at, then replace the cli hlt with two nop instructions, run through again and perform a break at the address where the nop's are, and single step through there.
Also look up how to fully use bochs debugger (or its manual), and how to debug while you at it.
Lack of knowledge in the way of the debugger was the problem. However, I found the VirtualBox debugger easier (to me, at least).
At the end of the execution of the second stage, DS is 1000h (so is CS and ES, but hopefully that's either not a problem, or I'll come to it soon). This is where I want it. However, my GDT doesn't seem to be loaded correctly - when I try to print it, it gives me the following error:
Code: Select all
VBoxDbg> dg
0018 VERR_INVALID_SELECTOR
Someone posted earlier about noticing a potential flaw in the GDT. What was it?
Re: Problem printing to screen in protected mode
Posted: Thu Mar 29, 2012 5:46 am
by Ziddia
I rewrote the GDT section. It's giving me different output, but I still get the same error at the end.
Code: Select all
VBoxDbg> dg
0000 DataRO Bas=f800ff53 Lim=8f000000 DPL=3 P NA G AVL=1 L=0
0008 DataRO Bas=ff00ef57 Lim=0003f000 DPL=3 P NA BIG AVL=1 L=0
0010 Ill-0 00 f0 3e 00 00 c0 4d f8 DPL=2 P
0018 VERR_INVALID_SELECTOR
I'm not entirely sure what I'm looking at though. Could someone please explain it?
Re: Problem printing to screen in protected mode
Posted: Thu Mar 29, 2012 6:53 am
by Ziddia
berkus wrote:Did you set the right GDT limit?
I wrote it out as: dw gdt_end - gdt - 1
It's the same as the last time I tried to write the GDT. All the names are still the same.
Re: Problem printing to screen in protected mode
Posted: Thu Mar 29, 2012 9:45 am
by invalid
Ziddia wrote:berkus wrote:Did you set the right GDT limit?
I wrote it out as: dw gdt_end - gdt - 1
It's the same as the last time I tried to write the GDT. All the names are still the same.
The VB dg command shows limit=8f000000, try dumping memory to see if it was not overwritten or something.
Re: Problem printing to screen in protected mode
Posted: Thu Mar 29, 2012 12:28 pm
by DavidCooper
I checked your GDT code very carefully before and it was right. That doesn't mean it's being loaded properly though. I assume that "gdt_end - gdt - 1" does the first subtraction before the second one because other people write it the same way and it seems to work, but it still isn't clear what's actually happening when you run the lgtd instruction. If you could show a version of your code with the hex that the assember generates, it would be dead easy to find the point where it goes wrong.
Re: Problem printing to screen in protected mode
Posted: Thu Mar 29, 2012 2:57 pm
by Combuster
As far as the code goes, at LGDT [ds:gdt_desc] the effective address is 0x0000:0xsmallnumber, i.e. GDTR is loaded with garbage from the IVT.
Fix the segment registers and/or the missing ORG directive