summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbel Romero Pérez <romeroperezabel@gmail.com>2018-06-28 00:04:07 -0400
committerAbel Romero Pérez <romeroperezabel@gmail.com>2018-06-28 00:04:07 -0400
commitf9bc3d6248f5d3192bbe863db0468b6b5202caf1 (patch)
tree72d5b9ba4f1e548394cbeba34f22ab01907b6d44
parent07f9fb8350b7f90fe1942c80ef5003d068a7bf00 (diff)
initial commit
-rw-r--r--.gitignore3
-rw-r--r--i386/i386/cpu_number.S4
-rw-r--r--kern/cpu_number.c28
3 files changed, 35 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 92fc6e7f..1a75fccc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,3 +50,6 @@ build-aux/
/doc/mach.toc
/doc/mach.tp
/doc/mach.vr
+/build
+Makefile.am.orig
+Makefile.am.rej
diff --git a/i386/i386/cpu_number.S b/i386/i386/cpu_number.S
new file mode 100644
index 00000000..95036b8b
--- /dev/null
+++ b/i386/i386/cpu_number.S
@@ -0,0 +1,4 @@
+.macro CPU_NUMBER reg
+ call cpu_number
+ movl %eax, \reg
+.endm
diff --git a/kern/cpu_number.c b/kern/cpu_number.c
new file mode 100644
index 00000000..324ed752
--- /dev/null
+++ b/kern/cpu_number.c
@@ -0,0 +1,28 @@
+int apic2kernel[255];
+int cpu_number_start = 0, cpu_number_counter = 0;
+
+static 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];
+}