Page 1 of 1

Who can answer this question?

Posted: Wed Mar 24, 2004 12:00 am
by SeeSaw
How do you read or write a memory location without using the segment selecotrs and offsets while in protected mode?  For example, how do you right into the GDT?  It is not a segment.  Please explain it both with assembler and C.

Thanx a lot for your kind help!

RE:Who can answer this question?

Posted: Thu Mar 25, 2004 12:00 am
by Moose
You can't.
Segments and thus, selectors, split up memory for protection. Even if you only have one segment, you still need the segment for it.

Everytime you want to reference a logical address the cpu is always using a segment selector + offset to create a physical memory address. This has to be done, at least in pmode.

Even if you're just moving values to a variable, the cpu is taking offset addresses with segment selectors for a physical address.

Moose.

RE:Who can answer this question?

Posted: Thu Mar 25, 2004 12:00 am
by SeeSaw
So how do you write into the GDT?  The GDT is not a segment!

RE:Who can answer this question?

Posted: Thu Mar 25, 2004 12:00 am
by Moose
You'd setup a GDT table and setup the gdtr before you enter pmode using real mode principles.

Or if you've booted from a multiboot bootloader, the gdt table will be setup and you'd already be in pmode. In which case you'd reset the gdtr to a new gdt table that your os would setup using ds which is already setup to be a segment the size of 4gb for you.

RE:Who can answer this question?

Posted: Thu Mar 25, 2004 12:00 am
by hartyl
in that case you have to make a GDT-entry already in real-mode:
base: 0x00000000
limit: 4GB (pg: 4kbyte)
ring0

when you use this selector, you can access all the memory.
mov ax, <4GB-selector>
mov es,ax
mov eax,0xdeadbeef
mov [es:0x00000000],eax ;write into the very first byte of the memory

in C it's actually not possible. you'll have to do it inline-assembler. as i don't really got the AT&T-syntax, i can't explain you.

greets, hartyl

RE:Who can answer this question?

Posted: Thu Mar 25, 2004 12:00 am
by SeeSaw
Thank you a lot dear hartyl, I've got the answer to my question.