[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enable SMP support

From: Richard Braun
Subject: Re: Enable SMP support
Date: Fri, 15 Jun 2018 19:18:55 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Fri, Jun 15, 2018 at 06:27:21PM +0200, Almudena Garcia wrote:
> I'm trying to define the cpu_number() in multiprocessor.
> To do this, I tried to use CPUID assembly x86 instruction, to get the CPU
> SMP number.
> The function, in C, is this:
> static inline char smp_processor_id(void) {
>   char apic_id = 0;
>   asm("mov $1, %%eax\n\t"
>   "cpuid\n\t"
>   "mov %%bh, %0\n\t" : "=g" (apic_id));
>   return apic_id;
> }
> In Linux, after executing this in a test source, It returns '8'
> But, when I try to execute It in Hurd, It shows a segmentation fault.
> I attach the test source file
> Can you help me?

You said in your initial message that you were willing to start all this
at your own risk. Well this is it, and it's only the very beginning.

This inline assembly snippet is invalid because it doesn't tell the
compiler that it uses registers, which may conflict with the code
generated by the compiler. Read the GCC extended inline assembly
documentation carefully, and especially the machine constraints [1]
for the x86 family. The idea is to create an eax variable with the
value 1 in C, pass that to the inline assembly expression with the
appropriate constraint, and do something similar for the returned
value in ebx, and then extract bh from it.

Richard Braun


reply via email to

[Prev in Thread] Current Thread [Next in Thread]