No explicit ss register in the gdt ?

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
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

No explicit ss register in the gdt ?

Post by JulienDarc »

Hello,

My question is 64-bit related.

I see everywhere that there is no SS register descriptor in the gdt, just CS and DS register descriptors.

The Intel manual, volume 1, chapter 3, page 14 (top), says :
Unlike the CS register, the SS register can be loaded explicitly, which permits application programs to set
up multiple stacks and switch among them.
Ok, so as a general rule, the cpu is smart enough to set the registers dynamically, except CS and DS.
And there is no need for an explicit descriptor for those.

I just want to validate the knowledge, because otherwise i cannot learn ;)

Thanks for this great learning place ,

Julien
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: No explicit ss register in the gdt ?

Post by Brendan »

Hi,
JulienDarc wrote:My question is 64-bit related.

I see everywhere that there is no SS register descriptor in the gdt, just CS and DS register descriptors.
What you see is a GDT entry that describes a "generic read/write not executable" area, which is probably used for SS, DS and ES. It's not specifically for DS alone. Note: For 64-bit code in long mode, the CPU ignores the segment base and limit but does not ignore attributes and permissions and therefore you still need GDT entries for SS, DS, ES, etc.
JulienDarc wrote:The Intel manual, volume 1, chapter 3, page 14 (top), says :
Unlike the CS register, the SS register can be loaded explicitly, which permits application programs to set
up multiple stacks and switch among them.
Basically all Intel are saying here is that there is no "mov cs,ax" instruction (like "mov ss,ax" and "mov ds,ax"). This instruction doesn't exist because it rarely makes sense to change CS without changing IP, and in the (extremely rare) cases where it's useful a "jmp far" is good enough.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: No explicit ss register in the gdt ?

Post by JulienDarc »

Thanks Brendan,

You made it crystal clear :)
Last edited by JulienDarc on Fri Mar 27, 2015 5:32 am, edited 1 time in total.
ExeTwezz
Member
Member
Posts: 104
Joined: Sun Sep 21, 2014 7:16 am
Libera.chat IRC: exetwezz

Re: No explicit ss register in the gdt ?

Post by ExeTwezz »

Brendan wrote: Note: For 64-bit code in long mode, the CPU ignores the segment base and limit but does not ignore attributes and permissions and therefore you still need GDT entries for SS, DS, ES, etc.
Actually, the GS and FS registers are exceptions, so the CPU doesn't ignore their base addresses in the GDT, as says 3.4.2.1 of Volume 1.

Edit: s/in the GDT//
Last edited by ExeTwezz on Fri Mar 27, 2015 4:32 am, edited 1 time in total.
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

Re: No explicit ss register in the gdt ?

Post by madanra »

ExeTwezz wrote:Actually, the GS and FS registers are exceptions, so the CPU doesn't ignore their base addresses in the GDT, as says 3.4.2.1 of Volume 1.
I thought FS and GS used a base address stored in an MSR, rather than the GDT? (See SWAPGS, WRFSBASE, WRGSBASE etc.)
Post Reply