I'm working with some low-level C code and I don't quite understand what's going on here:
/* Description of the current CPU. */
struct cpuid { unsigned eax, ebx, ecx, edx; };
/* Return information about the CPU. See <http://wiki.osdev.org/CPUID>. */
static struct cpuid
cpuid (unsigned int leaf, unsigned int subleaf)
{
struct cpuid result;
asm ("cpuid"
: "=a" (result.eax), "=b" (result.ebx),
"=c" (result.ecx), "=d" (result.edx)
: "a" (leaf), "c" (subleaf));
return result;
}
I've tried looking for information on the asm()
function, including that wiki page, but I'm still struggling in deciphering the code. I understand that the :
syntax is an old-school, deprecated way to initialize structs, but I don't really see how it's working here.
edit:
my question is specifically about what this snippet of code is doing, not the syntax or any of that. just this section and what's going on.