Problem printing to screen in protected mode

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.
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post 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?
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post 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?
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post 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.
invalid
Member
Member
Posts: 60
Joined: Thu Feb 23, 2012 8:39 am

Re: Problem printing to screen in protected mode

Post 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.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Problem printing to screen in protected mode

Post 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.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem printing to screen in protected mode

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply