Flat memory model in kernel

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
CocaCola
Member
Member
Posts: 36
Joined: Fri Sep 07, 2012 9:11 am

Flat memory model in kernel

Post by CocaCola »

Do the first two valid entries in the GDT, for code and data, apply to the kernel?
As in, after I set up the GDT and get into protected mode could I use a plain 32-bit pointer to access any memory location?
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Flat memory model in kernel

Post by iansjack »

Like any other program, the kernel uses whatever values you put in CS, DS, SS, etc as segment selectors. Whether those represent to a flat memory model or not is up to you.
User avatar
CocaCola
Member
Member
Posts: 36
Joined: Fri Sep 07, 2012 9:11 am

Re: Flat memory model in kernel

Post by CocaCola »

So if the data entry in the GDT ranges from 0 to FFFFF and the privileges are right (and granularity is on) then I should be able to use within the kernel a 32-bit pointer to address up to 4 GB, right?

Unreal mode looks a bit like what I'm asking, except I am unsure about leaving protected mode.

I am confused about how to use memory in protected mode. Surely I don't need to mess with the registers in my C code?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Flat memory model in kernel

Post by dozniak »

C code produced by gcc assumes flat memory model in protected mode.

Which means, CS, DS, ES, SS all point to the same memory region, CS is executable, while DS, ES and SS are also writable.
Learn to read.
Post Reply