Reading a lot on osdev and xv6 helped me to understand the majority of what is going on in an OS.
I decided to experiment and modify the freebsd code.
I just came across that code :
(freebsd-master/sys/amd64/amd64/cpu_switch.S)
Code: Select all
movq %r15,PCB_R15(%r8)
(freebsd-master/sys/sys/assym.h)
Code: Select all
#define ASSYM_BIAS 0x10000 /* avoid zero-length arrays */
#define ASSYM_ABS(value) ((value) < 0 ? -((value) + 1) + 1ULL : (value))
#define ASSYM(name, value) \
char name ## sign[((value) < 0 ? 1 : 0) + ASSYM_BIAS]; \
char name ## w0[(ASSYM_ABS(value) & 0xFFFFU) + ASSYM_BIAS]; \
char name ## w1[((ASSYM_ABS(value) & 0xFFFF0000UL) >> 16) + ASSYM_BIAS]; \
char name ## w2[((ASSYM_ABS(value) & 0xFFFF00000000ULL) >> 32) + ASSYM_BIAS]; \
char name ## w3[((ASSYM_ABS(value) & 0xFFFF000000000000ULL) >> 48) + ASSYM_BIAS]
(freebsd-master/sys/amd64/amd64/genassym.c)
Code: Select all
ASSYM(PCB_R15, offsetof(struct pcb, pcb_r15));
Why do we have a parameter (%r8) since I don't see where it fits in the macro ?
There is obviously something done under the bonnet that I don't get..
Could you please help ?
Thanks
Julien