From a7ca32e3a3ec2d3c1947a06fbcde0f779b0b1fec Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 9 Oct 2018 20:22:48 -0400 Subject: Change mycpu() to use %gs. --- proc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 55e435c..3c0acbd 100644 --- a/proc.c +++ b/proc.c @@ -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* -- cgit v1.2.3