Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved cpu_number() to cpu_number.c, created CPU_NUMBER ASM macro
- Loading branch information
Showing
9 changed files
with
85 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,6 @@ build-aux/ | |
/doc/mach.toc | ||
/doc/mach.tp | ||
/doc/mach.vr | ||
/build | ||
Makefile.am.orig | ||
Makefile.am.rej |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
int apic2kernel[255]; | ||
int cpu_number_start = 0, cpu_number_counter = 0; | ||
|
||
int cpu_number(void) { | ||
int eax = 1, ebx = 0, ecx = 0, edx = 0; | ||
unsigned int i = 0; | ||
int apic_id = 0; | ||
|
||
if (!cpu_number_start) { | ||
for (i = 0; i < 255; i++) { | ||
apic2kernel[i] = -1; | ||
} | ||
cpu_number_start = 1; | ||
} | ||
|
||
asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (eax)); | ||
apic_id = (char) (ebx >> 24) & 0xff; | ||
//printf("apic_id = %d\n", apic_id); | ||
|
||
if (apic2kernel[apic_id] != -1) { | ||
return apic2kernel[apic_id]; | ||
} else { | ||
apic2kernel[apic_id] = cpu_number_counter; | ||
cpu_number_counter++; | ||
} | ||
|
||
return apic2kernel[apic_id]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.macro CPU_NUMBER reg | ||
call cpu_number | ||
movl %eax, \reg | ||
.endm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
int apic2kernel[255]; | ||
int cpu_number_start = 0, cpu_number_counter = 0; | ||
|
||
int cpu_number(void) { | ||
int eax = 1, ebx = 0, ecx = 0, edx = 0; | ||
unsigned int i = 0; | ||
int apic_id = 0; | ||
|
||
if (!cpu_number_start) { | ||
for (i = 0; i < 255; i++) { | ||
apic2kernel[i] = -1; | ||
} | ||
cpu_number_start = 1; | ||
} | ||
|
||
asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (eax)); | ||
apic_id = (char) (ebx >> 24) & 0xff; | ||
//printf("apic_id = %d\n", apic_id); | ||
|
||
if (apic2kernel[apic_id] != -1) { | ||
return apic2kernel[apic_id]; | ||
} else { | ||
apic2kernel[apic_id] = cpu_number_counter; | ||
cpu_number_counter++; | ||
} | ||
|
||
return apic2kernel[apic_id]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters