I would like to analyze and understand Linux kernel source code. I've downloaded the source code of the early Linux versions and a lot of code is more or less straightforward, however I got stuck trying to understand the pieces involving bunches of assembly instructions. One of such instructions is set_gate (seems like it's one of the very crucial kernel routines):
Code: Select all
#define _set_gate(gate_addr,type,dpl,addr) \
__asm__ ("movw %%dx,%%ax\n\t" \
"movw %0,%%dx\n\t" \
"movl %%eax,%1\n\t" \
"movl %%edx,%2" \
: \
: "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
"o" (*((char *) (gate_addr))), \
"o" (*(4+(char *) (gate_addr))), \
"d" ((char *) (addr)),"a" (0x00080000))
What I understand (not sure if correctly) from above:
movw transfers a word from a register to a register (not sure which one is the source register and which one is the target one).
movl trasfers dword from a register to a register (the same doubt as above).
Why something is transferred from dx to ax (or reverse?) I have no idea. I don't understand what's the purpose of this operation as it is not known what is in any of these registers before the transfer is executed.
What does %, %% mean - I also don't know. What is %1 and %2 I have no idea at all.
And as to the fragment starting with : \ , I completely don't understand what is done there.
If you could make these points clearer, it would be much appreciated.