diff options
| -rw-r--r-- | defs.h | 1 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | proc.c | 16 | ||||
| -rw-r--r-- | proc.h | 1 | ||||
| -rw-r--r-- | vm.c | 7 | 
5 files changed, 21 insertions, 6 deletions
| @@ -110,6 +110,7 @@ int             fork(void);  int             growproc(int);  int             kill(int);  struct cpu*     mycpu(void); +struct cpu*     getmycpu(void);  struct proc*    myproc();  void            pinit(void);  void            procdump(void); @@ -45,6 +45,8 @@ main(uint64 mbmagic, uint64 mbaddr)    return 0;  } +extern struct cpu* getmycpu(); +  // Common CPU setup code.  static void  mpmain(void) @@ -37,16 +37,15 @@ cpuid() {  // Must be called with interrupts disabled to avoid the caller being  // rescheduled between reading lapicid and running through the loop.  struct cpu* -mycpu(void) +getmycpu(void)  {    int apicid, i;    if(readeflags()&FL_IF) -    panic("mycpu called with interrupts enabled\n"); +    panic("getmycpu called with interrupts enabled\n");    apicid = lapicid(); -  // APIC IDs are not guaranteed to be contiguous. Maybe we should have -  // a reverse map, or reserve a register to store &cpus[i]. +  // APIC IDs are not guaranteed to be contiguous.    for (i = 0; i < ncpu; ++i) {      if (cpus[i].apicid == apicid)        return &cpus[i]; @@ -54,6 +53,15 @@ mycpu(void)    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  // while reading proc from the cpu structure  struct proc* @@ -3,6 +3,7 @@ struct cpu {    uint64 syscallno;            // Temporary used by sysentry    uint64 usp;                  // Temporary used by sysentry    struct proc *proc;           // The process running on this cpu or null +  struct cpu *cpu;             // XXX    uchar apicid;                // Local APIC ID    struct context *scheduler;   // swtch() here to enter scheduler    struct taskstate ts;         // Used by x86 to find stack for interrupt @@ -39,7 +39,8 @@ seginit(void)    struct cpu *c;    struct desctr dtr; -  c = mycpu(); +  c = getmycpu(); +      memmove(c->gdt, bootgdt, sizeof bootgdt);    dtr.limit = sizeof(c->gdt)-1;    dtr.base = (uint64) c->gdt; @@ -54,10 +55,12 @@ seginit(void)    writemsr(MSR_LSTAR, (uint64)&sysentry);    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);    writemsr(MSR_GS_BASE, (uint64)c);    writemsr(MSR_GS_KERNBASE, (uint64)c); +  c->cpu = c;  }  // Return the address of the PTE in page table pgdir | 
