clean up %fs %gs use

This commit is contained in:
rsc 2009-05-31 01:12:08 +00:00
parent e97519a6d2
commit 7b644318dd
4 changed files with 5 additions and 8 deletions

View file

@ -7,7 +7,6 @@
#define SEG_KCODE 1 // kernel code #define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack #define SEG_KDATA 2 // kernel data+stack
#define SEG_KCPU 3 // kernel per-cpu data
#define CR0_PE 1 // protected mode enable bit #define CR0_PE 1 // protected mode enable bit
@ -63,7 +62,7 @@ start32:
movw %ax, %ds # -> DS: Data Segment movw %ax, %ds # -> DS: Data Segment
movw %ax, %es # -> ES: Extra Segment movw %ax, %es # -> ES: Extra Segment
movw %ax, %ss # -> SS: Stack Segment movw %ax, %ss # -> SS: Stack Segment
movw $(SEG_KCPU<<3), %ax # Our per-cpu segment selector movw $0, %ax # Zero segments not ready for use
movw %ax, %fs # -> FS movw %ax, %fs # -> FS
movw %ax, %gs # -> GS movw %ax, %gs # -> GS

2
proc.c
View file

@ -93,9 +93,9 @@ ksegment(void)
c1->gdt[SEG_UDATA] = SEG_NULL; c1->gdt[SEG_UDATA] = SEG_NULL;
c1->gdt[SEG_TSS] = SEG_NULL; c1->gdt[SEG_TSS] = SEG_NULL;
lgdt(c1->gdt, sizeof(c1->gdt)); lgdt(c1->gdt, sizeof(c1->gdt));
loadfsgs(SEG_KCPU << 3);
// Initialize cpu-local variables. // Initialize cpu-local variables.
setgs(SEG_KCPU << 3);
c = c1; c = c1;
cp = 0; cp = 0;
} }

View file

@ -13,10 +13,7 @@ alltraps:
pushal pushal
# Set up data and per-cpu segments. # Set up data and per-cpu segments.
# Can find out KDATA from %ss.
# Assume that KCPU is KDATA+1.
movw $(SEG_KDATA<<3), %ax movw $(SEG_KDATA<<3), %ax
movw %ss, %ax
movw %ax, %ds movw %ax, %ds
movw %ax, %es movw %ax, %es
movw $(SEG_KCPU<<3), %ax movw $(SEG_KCPU<<3), %ax

5
x86.h
View file

@ -104,9 +104,10 @@ xchg(volatile uint *addr, uint newval)
} }
static inline void static inline void
setgs(ushort gs) loadfsgs(ushort v)
{ {
asm volatile("movw %0, %%gs" : : "r" (gs)); asm volatile("movw %0, %%fs" : : "r" (v));
asm volatile("movw %0, %%gs" : : "r" (v));
} }
static inline void static inline void