Protected Mode Hello world.

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.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Protected Mode Hello world.

Post by Troy Martin »

raghuk wrote:
Troy Martin wrote:Okay, but here's the odd thing: 0x16!? Well thar's a problem, it should be 0x18. Selectors are usually multiples of 8, as that's the size of a selector...
Small correction there. Size of a selector is 16 bits. Selector needs not be multiples of 8. Usually they are multiples of 8 because bits 0-1 represent requested privilege level and bit 2 represents table indicator (GDT = 0, LDT = 1). For kernel code/data segments we have RPL = 0 and TI = 0. Hence they are multiples of 8.
I mean the selector entries in the GDT. They're 8 bytes long, which makes 0x16 incorrect. (0x16 == 22)
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
raghuk
Member
Member
Posts: 35
Joined: Tue Jun 30, 2009 2:47 am
Location: Bangalore, India

Re: Protected Mode Hello world.

Post by raghuk »

Troy Martin wrote:I mean the selector entries in the GDT. They're 8 bytes long, which makes 0x16 incorrect. (0x16 == 22)
You mean "descriptor" entries. 0x16 is incorrect because 0x16 = 00010110 and bit 2 is set. That means the selector is pointing to LDT and not GDT. It has nothing to with the fact that a descriptor is 8 bytes. For e.g. selector 0x13 is not divisible by 8 but still points at GDT.

This is how a selector is structured:

Index to GDT/LDT (Bits 3-15)
TI (Bit 2)
RPL (Bits 0-1)
Post Reply