Change mycpu() to use %gs.
This commit is contained in:
parent
821ee3fc99
commit
a7ca32e3a3
1
defs.h
1
defs.h
|
@ -110,6 +110,7 @@ int fork(void);
|
||||||
int growproc(int);
|
int growproc(int);
|
||||||
int kill(int);
|
int kill(int);
|
||||||
struct cpu* mycpu(void);
|
struct cpu* mycpu(void);
|
||||||
|
struct cpu* getmycpu(void);
|
||||||
struct proc* myproc();
|
struct proc* myproc();
|
||||||
void pinit(void);
|
void pinit(void);
|
||||||
void procdump(void);
|
void procdump(void);
|
||||||
|
|
2
main.c
2
main.c
|
@ -45,6 +45,8 @@ main(uint64 mbmagic, uint64 mbaddr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern struct cpu* getmycpu();
|
||||||
|
|
||||||
// Common CPU setup code.
|
// Common CPU setup code.
|
||||||
static void
|
static void
|
||||||
mpmain(void)
|
mpmain(void)
|
||||||
|
|
16
proc.c
16
proc.c
|
@ -37,16 +37,15 @@ cpuid() {
|
||||||
// Must be called with interrupts disabled to avoid the caller being
|
// Must be called with interrupts disabled to avoid the caller being
|
||||||
// rescheduled between reading lapicid and running through the loop.
|
// rescheduled between reading lapicid and running through the loop.
|
||||||
struct cpu*
|
struct cpu*
|
||||||
mycpu(void)
|
getmycpu(void)
|
||||||
{
|
{
|
||||||
int apicid, i;
|
int apicid, i;
|
||||||
|
|
||||||
if(readeflags()&FL_IF)
|
if(readeflags()&FL_IF)
|
||||||
panic("mycpu called with interrupts enabled\n");
|
panic("getmycpu called with interrupts enabled\n");
|
||||||
|
|
||||||
apicid = lapicid();
|
apicid = lapicid();
|
||||||
// APIC IDs are not guaranteed to be contiguous. Maybe we should have
|
// APIC IDs are not guaranteed to be contiguous.
|
||||||
// a reverse map, or reserve a register to store &cpus[i].
|
|
||||||
for (i = 0; i < ncpu; ++i) {
|
for (i = 0; i < ncpu; ++i) {
|
||||||
if (cpus[i].apicid == apicid)
|
if (cpus[i].apicid == apicid)
|
||||||
return &cpus[i];
|
return &cpus[i];
|
||||||
|
@ -54,6 +53,15 @@ mycpu(void)
|
||||||
panic("unknown apicid\n");
|
panic("unknown apicid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return this core's cpu struct using %gs. %gs points this core's struct
|
||||||
|
// cpu. Offet 24 in struct cpu is cpu.
|
||||||
|
struct cpu*
|
||||||
|
mycpu(void) {
|
||||||
|
struct cpu *c;
|
||||||
|
asm volatile("mov %%gs:24, %0" : "=r" (c));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
// Disable interrupts so that we are not rescheduled
|
// Disable interrupts so that we are not rescheduled
|
||||||
// while reading proc from the cpu structure
|
// while reading proc from the cpu structure
|
||||||
struct proc*
|
struct proc*
|
||||||
|
|
1
proc.h
1
proc.h
|
@ -3,6 +3,7 @@ struct cpu {
|
||||||
uint64 syscallno; // Temporary used by sysentry
|
uint64 syscallno; // Temporary used by sysentry
|
||||||
uint64 usp; // Temporary used by sysentry
|
uint64 usp; // Temporary used by sysentry
|
||||||
struct proc *proc; // The process running on this cpu or null
|
struct proc *proc; // The process running on this cpu or null
|
||||||
|
struct cpu *cpu; // XXX
|
||||||
uchar apicid; // Local APIC ID
|
uchar apicid; // Local APIC ID
|
||||||
struct context *scheduler; // swtch() here to enter scheduler
|
struct context *scheduler; // swtch() here to enter scheduler
|
||||||
struct taskstate ts; // Used by x86 to find stack for interrupt
|
struct taskstate ts; // Used by x86 to find stack for interrupt
|
||||||
|
|
7
vm.c
7
vm.c
|
@ -39,7 +39,8 @@ seginit(void)
|
||||||
struct cpu *c;
|
struct cpu *c;
|
||||||
struct desctr dtr;
|
struct desctr dtr;
|
||||||
|
|
||||||
c = mycpu();
|
c = getmycpu();
|
||||||
|
|
||||||
memmove(c->gdt, bootgdt, sizeof bootgdt);
|
memmove(c->gdt, bootgdt, sizeof bootgdt);
|
||||||
dtr.limit = sizeof(c->gdt)-1;
|
dtr.limit = sizeof(c->gdt)-1;
|
||||||
dtr.base = (uint64) c->gdt;
|
dtr.base = (uint64) c->gdt;
|
||||||
|
@ -54,10 +55,12 @@ seginit(void)
|
||||||
writemsr(MSR_LSTAR, (uint64)&sysentry);
|
writemsr(MSR_LSTAR, (uint64)&sysentry);
|
||||||
writemsr(MSR_SFMASK, FL_TF | FL_IF);
|
writemsr(MSR_SFMASK, FL_TF | FL_IF);
|
||||||
|
|
||||||
// Initialize cpu-local storage.
|
// Initialize cpu-local storage so that each core can easily
|
||||||
|
// find its struct cpu using %gs.
|
||||||
writegs(SEG_KDATA);
|
writegs(SEG_KDATA);
|
||||||
writemsr(MSR_GS_BASE, (uint64)c);
|
writemsr(MSR_GS_BASE, (uint64)c);
|
||||||
writemsr(MSR_GS_KERNBASE, (uint64)c);
|
writemsr(MSR_GS_KERNBASE, (uint64)c);
|
||||||
|
c->cpu = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the address of the PTE in page table pgdir
|
// Return the address of the PTE in page table pgdir
|
||||||
|
|
Loading…
Reference in a new issue