Page 1 of 1

Protected mode segmentation

Posted: Mon Sep 01, 2008 4:49 am
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...

Re: Protected mode segmentation

Posted: Mon Sep 01, 2008 5:30 am
by jal
I'm sorry, but I cannot make sense of anything you're saying here. Were you drunk or something???


JAL

Re: Protected mode segmentation

Posted: Mon Sep 01, 2008 5:47 am
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.

Re: Protected mode segmentation

Posted: Mon Sep 01, 2008 7:00 am
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.