Protected mode segmentation

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.
Post Reply
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Protected mode segmentation

Post by inflater »

Okay, I just have learned (suthers...:oops:) :that if I want to access the physical address e.g. 0x100000 in pmode using GDT settings from DexOS, I have to use the "linear sel" selector (8h). In Bochs, I have confirmed it:

u 0x8:0x100000 - returns okay.

There are some cases that I must not use the "linear sel", a direct example: video driver, which would behave abnormally if DS and ES would be set to "linear sel" - 0x8 (since the chars/strings would point at completely different location).

If I don't use the "linear sel" selector and try to point to 0x100000, it will point to completely another location, because the active selector is 0x18, "sys_data", and that'll point to address 0x100000 + 0x83340 = 0x183340 :shock:.

So if I want to display contents of the first megabyte to screen using the SYS_DATA selector and using WriteS in ESI the specified pointer, I must use:

Code: Select all

LinearSelDifferential equ 0x83340

...

mov esi,0x100000 - LinearSelDifferential
call WriteS
I have also learned that 0x8:0x100000 (linear) is not the same as 0x18:0x100000 (sys_data). lol. I hope the equation "LinearSelDifferential" will not change when the kernel will grow...

Ah well, just another hair-tearing course of segmentation...
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Protected mode segmentation

Post by jal »

I'm sorry, but I cannot make sense of anything you're saying here. Were you drunk or something???


JAL
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Protected mode segmentation

Post by egos »

What means "linear sel"? Selector defines index of segment descriptor, which used to access specific memory region. If the base address stored in descriptor is equal to 0, then addressing within this segment will coincide with linear (FLAT) addressing.

Even if segment does not cover the needed region of memory, you can map it in this segment.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Protected mode segmentation

Post by Dex »

The DexOS GDT are made so real and pmode address are the same, this is done at run time
eg:

Code: Select all

	xor   ebx,ebx
	mov   bx,ds						    
	shl   ebx,4						    
	mov   [BaseAddOn],ebx					     
	mov   eax,ebx
	mov   [sys_code_1 + 2],ax				     
	mov   [sys_data_1 + 2],ax
	mov   [Real_code_1 + 2],ax				     
	mov   [Real_data_1 + 2],ax
	shr   eax,16
	mov   [sys_code_1 + 4],al
	mov   [sys_data_1 + 4],al
	mov   [Real_code_1 + 4],al
	mov   [Real_data_1 + 4],al
	mov   [sys_code_1 + 7],ah
	mov   [sys_data_1 + 7],ah
	mov   [Real_code_1 + 7],ah
	mov   [Real_data_1 + 7],ah
This means that the kernel has to be load below 1 MB, and the only way to get a real (0x100000)
is to use the "linear sel", if not you will get address + base (kenrel load address).
In DexOS you can get the base address and sub it off the address, ( you can get it by calling a function or using int 41h).
Post your load address and what you set the above code too, would be usefull.
Post Reply