arch/x86/boot/compressed/head_32.S

Source file repositories/reference/linux-study-clean/arch/x86/boot/compressed/head_32.S

File Facts

System
Linux kernel
Corpus path
arch/x86/boot/compressed/head_32.S
Extension
.S
Size
4543 bytes
Lines
189
Domain
Architecture Layer
Bucket
arch/x86
Inferred role
Architecture Layer: arch/x86
Status
atlas-only

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

.text

#include <linux/init.h>
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/page_types.h>
#include <asm/boot.h>
#include <asm/asm-offsets.h>
#include <asm/bootparam.h>

/*
 * These symbols needed to be marked as .hidden to prevent the BFD linker from
 * generating R_386_32 (rather than R_386_RELATIVE) relocations for them when
 * the 32-bit compressed kernel is linked as PIE. This is no longer necessary,
 * but it doesn't hurt to keep them .hidden.
 */
	.hidden _bss
	.hidden _ebss
	.hidden _end

	__HEAD
SYM_FUNC_START(startup_32)
	cld
	cli

/*
 * Calculate the delta between where we were compiled to run
 * at and where we were actually loaded at.  This can only be done
 * with a short local call on x86.  Nothing  else will tell us what
 * address we are running at.  The reserved chunk of the real-mode
 * data at 0x1e4 (defined as a scratch field) are used as the stack
 * for this calculation. Only 4 bytes are needed.
 */
	leal	(BP_scratch+4)(%esi), %esp
	call	1f
1:	popl	%edx
	addl	$_GLOBAL_OFFSET_TABLE_+(.-1b), %edx

	/* Load new GDT */
	leal	gdt@GOTOFF(%edx), %eax
	movl	%eax, 2(%eax)
	lgdt	(%eax)

	/* Load segment registers with our descriptors */
	movl	$__BOOT_DS, %eax
	movl	%eax, %ds
	movl	%eax, %es
	movl	%eax, %fs
	movl	%eax, %gs
	movl	%eax, %ss

/*
 * %edx contains the address we are loaded at by the boot loader (plus the
 * offset to the GOT).  The below code calculates %ebx to be the address where
 * we should move the kernel image temporarily for safe in-place decompression
 * (again, plus the offset to the GOT).
 *
 * %ebp is calculated to be the address that the kernel will be decompressed to.
 */

#ifdef CONFIG_RELOCATABLE
	leal	startup_32@GOTOFF(%edx), %ebx
	movl	BP_kernel_alignment(%esi), %eax
	decl	%eax
	addl    %eax, %ebx
	notl	%eax
	andl    %eax, %ebx
	cmpl	$LOAD_PHYSICAL_ADDR, %ebx
	jae	1f
#endif

Annotation

Implementation Notes