diff -ruN gnumach-1.8+git20180218/kern/cpu_number.h gnumach-1.8+git20180218~/kern/cpu_number.h --- gnumach-1.8+git20180218/kern/cpu_number.h 2016-10-02 19:45:20.000000000 +0200 +++ gnumach-1.8+git20180218~/kern/cpu_number.h 2018-06-17 02:13:48.000000000 +0200 @@ -35,9 +35,41 @@ #if (NCPUS == 1) /* cpu number is always 0 on a single processor system */ -#define cpu_number() (0) + #define cpu_number() (0) + #define CPU_L1_SIZE (1 << CPU_L1_SHIFT) + +#else #define CPU_L1_SIZE (1 << CPU_L1_SHIFT) +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]; +} + #endif /* NCPUS == 1 */ #endif /* _KERN_CPU_NUMBER_H_ */ diff -ruN gnumach-1.8+git20180218/kern/machine.h gnumach-1.8+git20180218~/kern/machine.h --- gnumach-1.8+git20180218/kern/machine.h 2016-10-02 19:45:20.000000000 +0200 +++ gnumach-1.8+git20180218~/kern/machine.h 2018-06-17 02:11:40.000000000 +0200 @@ -54,5 +54,6 @@ * action_thread() shuts down processors or changes their assignment. */ extern void action_thread_continue (void) __attribute__((noreturn)); +extern void action_thread (void)__attribute__((noreturn)); #endif /* _MACHINE_H_ */ diff -ruN gnumach-1.8+git20180218/kern/sched_prim.h gnumach-1.8+git20180218~/kern/sched_prim.h --- gnumach-1.8+git20180218/kern/sched_prim.h 2017-06-10 01:26:02.000000000 +0200 +++ gnumach-1.8+git20180218~/kern/sched_prim.h 2018-06-17 02:22:27.000000000 +0200 @@ -185,4 +185,6 @@ extern void idle_thread(void) __attribute__((noreturn)); extern void sched_thread(void); +extern void cause_ast_check(processor); /*new*/ + #endif /* _KERN_SCHED_PRIM_H_ */ diff -ruN gnumach-1.8+git20180218/kern/thread.h gnumach-1.8+git20180218~/kern/thread.h --- gnumach-1.8+git20180218/kern/thread.h 2016-10-02 19:45:20.000000000 +0200 +++ gnumach-1.8+git20180218~/kern/thread.h 2018-06-17 02:23:50.000000000 +0200 @@ -344,6 +344,9 @@ extern kern_return_t thread_assign_default( thread_t thread); extern void stack_collect(void); + +extern void cause_ast_check(processor); /*new*/ + #endif /*