GDT: Downside of Basic Flat Model?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
LazyKitty
Posts: 5
Joined: Wed Mar 28, 2018 6:33 am

GDT: Downside of Basic Flat Model?

Post by LazyKitty »

Hi, I've been lurking here for a while and started working on a kernel (whenever I'm not procrastinating), starting with the Barebones tutorial.
Currently I've got paging implemented with higher half, but I'm a bit confused by the GDT (I actually wanted to implement interrupts so I can catch Page Faults, but the wiki mentioned I should do the GDT first), so I decided to finally make an account and ask.

The Intel Manual mentions that models other than the basic flat model have hardware protections against program bugs.

What exactly are these protections and how relevant are they while using paging?
Are there any downsides to just using the basic flat model? (Any reason I should not use it? Is it a security issue?)
What should I be considering to pick the right model?
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: GDT: Downside of Basic Flat Model?

Post by Korona »

No modern compiler or runtime supports non-flat models. That's a huge disadvantage that most people are not accepting (including Linux, Windows and all other common kernels). There have been some religious wars about whether x86 segmentation provides any meaningful provides any benefit at all (you can use the search function for that) but a majority of frequent users (me including) thinks that this is not the case.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
LazyKitty
Posts: 5
Joined: Wed Mar 28, 2018 6:33 am

Re: GDT: Downside of Basic Flat Model?

Post by LazyKitty »

Korona wrote:No modern compiler or runtime supports non-flat models. That's a huge disadvantage that most people are not accepting (including Linux, Windows and all other common kernels). There have been some religious wars about whether x86 segmentation provides any meaningful provides any benefit at all (you can use the search function for that) but a majority of frequent users (me including) thinks that this is not the case.
Alright, I'll be going with the flat model, then. Thanks.

I assume the segmentation itself is just there for historical/backwards compatibility reasons, since there is paging now?
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: GDT: Downside of Basic Flat Model?

Post by Korona »

In Linux, Windows and the other established x86 kernels, yes, it is ignored as much as possible and Intel only includes it for backwards compatibility. You cannot disable it so you live with it and set all segments to a flat model. On x86_64 segmentation is not functional any more (i.e. segment limits are ignored).
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Post Reply