Who can answer this question?

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
SeeSaw

Who can answer this question?

Post 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!
Moose

RE:Who can answer this question?

Post 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.
SeeSaw

RE:Who can answer this question?

Post by SeeSaw »

So how do you write into the GDT?  The GDT is not a segment!
Moose

RE:Who can answer this question?

Post 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.
hartyl

RE:Who can answer this question?

Post 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
SeeSaw

RE:Who can answer this question?

Post by SeeSaw »

Thank you a lot dear hartyl, I've got the answer to my question.
Post Reply