I am working on understanding how the Linux kernel v3.19 prepares for decompression on a machine with x86_64 architecture in arch/x86/boot/compressed/head_64.S. The part that is confusing me is the copying of the compressed kernel image to another location in memory before decompression takes place. I have copied the code below with my understanding of each line; the lines with // ? comments are the ones I am having trouble with.
/*
* Copy the compressed kernel to the end of our buffer
* where decompression in place becomes safe.
*/
pushq %rsi // %rsi contains the pointer to `boot_params`
leaq (_bss-8)(%rip), %rsi // ?
leaq (_bss-8)(%rbx), %rdi // ?
movq $_bss /* - $startup_32 */, %rcx // ?
shrq $3, %rcx // ?
std // set the direction so %rsi and %edi are decremented
rep movsq // copy data from %rsi to %rdi 8 bytes at a time
cld // clear the direction flag
popq %rsi // restore pointer to `boot_params`
I know that at this point %rbx contains the location where the kernel will be relocated for decompression and that %rbp (while not mentioned in this code snippet) contains the location the kernel was loaded at runtime. Further, I am aware that _bss refers to the start of the .bss section as given by the linker script in arch/x86/boot/compressed/vmlinux.lds.S, and that the compressed kernel image that we want to copy is at .rodata..compressed, which sits between .head.text and .text (where we are currently, I believe).
What I am not following and need help with is:
What section does
_bss-8refer to?This may become clear once I understand what
_bss-8is, but how does(_bss-8)(%rip)and(_bss-8)(%rbx)give us where the compressed kernel currently is and where it is going?Why are we putting
$_bss >> 3into%rcxas the counter for copying data? Why not something related torodata..compressed?