# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

### 29.2. x86 addressing modes

Example: userland/arch/x86_64/address_modes.S

Several x86 instructions can calculate addresses of a complex form:

    s:a(b, c, d)

which expands to:

    a + b + c * d

Where the instruction encoding allows for:

- `a`: any 8 or 32-bit general purpose register

- `b`: any 32-bit general purpose register except ESP

- `c`: 1, 2, 4 or 8 (encoded in 2 SIB bits)

- `d`: immediate constant

- `s`: a segment register. Cannot be tested simply from userland, so we won’t talk about them here. See: https://github.com/cirosantilli/x86-bare-metal-examples/blob/6606a2647d44bc14e6fd695c0ea2b6b7a5f04ca3/segment_registers_real_mode.S

The common compiler usage is:

- `a`: base pointer

- `b`: array offset

- `c` and `d`: struct offset

Bibliography:

- Intel 64 and IA-32 Architectures Software Developer’s Manuals Volume 1 3.7.5 "Specifying an Offset"

- https://sourceware.org/binutils/docs-2.18/as/i386_002dMemory.html