head_32.S 4.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  linux/boot/head.S
 *
 *  Copyright (C) 1991, 1992, 1993  Linus Torvalds
 */

/*
 *  head.S contains the 32-bit startup code.
 *
 * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
 * the page directory will exist. The startup code will be overwritten by
 * the page directory. [According to comments etc elsewhere on a compressed
 * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
 *
15
 * Page 0 is deliberately kept safe, since System Management Mode code in
L
Linus Torvalds 已提交
16
 * laptops may need to access the BIOS data stored there.  This is also
17
 * useful for future device drivers that either access the BIOS via VM86
L
Linus Torvalds 已提交
18 19 20 21 22 23
 * mode.
 */

/*
 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
 */
24
	.text
L
Linus Torvalds 已提交
25 26 27

#include <linux/linkage.h>
#include <asm/segment.h>
28
#include <asm/page_types.h>
29
#include <asm/boot.h>
R
Rusty Russell 已提交
30
#include <asm/asm-offsets.h>
L
Linus Torvalds 已提交
31

32
	.section ".text.head","ax",@progbits
33
ENTRY(startup_32)
34
	cld
35 36 37 38 39 40
	/*
	 * Test KEEP_SEGMENTS flag to see if the bootloader is asking
	 * us to not reload segments
	 */
	testb	$(1<<6), BP_loadflags(%esi)
	jnz	1f
R
Rusty Russell 已提交
41

42
	cli
43 44 45 46 47 48
	movl	$__BOOT_DS, %eax
	movl	%eax, %ds
	movl	%eax, %es
	movl	%eax, %fs
	movl	%eax, %gs
	movl	%eax, %ss
49
1:
R
Rusty Russell 已提交
50

51 52
/*
 * Calculate the delta between where we were compiled to run
53 54 55
 * 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
56 57
 * data at 0x1e4 (defined as a scratch field) are used as the stack
 * for this calculation. Only 4 bytes are needed.
58
 */
59 60 61 62
	leal	(BP_scratch+4)(%esi), %esp
	call	1f
1:	popl	%ebp
	subl	$1b, %ebp
63

64 65
/*
 * %ebp contains the address we are loaded at by the boot loader and %ebx
66 67
 * contains the address where we should move the kernel image temporarily
 * for safe in-place decompression.
68
 */
69

70
#ifdef CONFIG_RELOCATABLE
71
	movl	%ebp, %ebx
72 73
	addl    $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
	andl    $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
74
#else
75
	movl	$LOAD_PHYSICAL_ADDR, %ebx
76 77
#endif

78 79
	/* Target address to relocate to for decompression */
	addl	$z_extract_offset, %ebx
80

81 82 83
	/* Set up the stack */
	leal	boot_stack_end(%ebx), %esp

84 85 86 87
	/* Zero EFLAGS */
	pushl	$0
	popfl

88 89
/*
 * Copy the compressed kernel to the end of our buffer
90 91
 * where decompression in place becomes safe.
 */
92
	pushl	%esi
93 94
	leal	(_bss-4)(%ebp), %esi
	leal	(_bss-4)(%ebx), %edi
95
	movl	$(_bss - startup_32), %ecx
96
	shrl	$2, %ecx
97
	std
98
	rep	movsl
99
	cld
100
	popl	%esi
101

102 103
/*
 * Compute the kernel start address.
104 105
 */
#ifdef CONFIG_RELOCATABLE
106 107
	addl    $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
	andl    $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
108
#else
109
	movl	$LOAD_PHYSICAL_ADDR, %ebp
110
#endif
L
Linus Torvalds 已提交
111 112

/*
113
 * Jump to the relocated address.
L
Linus Torvalds 已提交
114
 */
115 116
	leal	relocated(%ebx), %eax
	jmp	*%eax
117 118
ENDPROC(startup_32)

119
	.text
120 121
relocated:

L
Linus Torvalds 已提交
122
/*
123
 * Clear BSS (stack is currently empty)
L
Linus Torvalds 已提交
124
 */
125
	xorl	%eax, %eax
126
	leal	_bss(%ebx), %edi
127 128
	leal	_ebss(%ebx), %ecx
	subl	%edi, %ecx
129 130
	shrl	$2, %ecx
	rep	stosl
131

L
Linus Torvalds 已提交
132 133 134
/*
 * Do the decompression, and jump to the new kernel..
 */
135
	leal	z_extract_offset_negative(%ebx), %ebp
136 137
				/* push arguments for decompress_kernel: */
	pushl	%ebp		/* output address */
138
	pushl	$z_input_len	/* input_len */
139 140 141 142 143 144 145
	leal	input_data(%ebx), %eax
	pushl	%eax		/* input_data */
	leal	boot_heap(%ebx), %eax
	pushl	%eax		/* heap area */
	pushl	%esi		/* real mode pointer */
	call	decompress_kernel
	addl	$20, %esp
146 147

#if CONFIG_RELOCATABLE
148 149
/*
 * Find the address of the relocations.
150
 */
151
	leal	z_output_len(%ebp), %edi
152

153 154
/*
 * Calculate the delta between where vmlinux was compiled to run
155 156
 * and where it was actually loaded.
 */
157 158 159
	movl	%ebp, %ebx
	subl	$LOAD_PHYSICAL_ADDR, %ebx
	jz	2f	/* Nothing to be done if loaded at compiled addr. */
L
Linus Torvalds 已提交
160
/*
161
 * Process relocations.
L
Linus Torvalds 已提交
162
 */
163

164 165 166 167 168 169
1:	subl	$4, %edi
	movl	(%edi), %ecx
	testl	%ecx, %ecx
	jz	2f
	addl	%ebx, -__PAGE_OFFSET(%ebx, %ecx)
	jmp	1b
170 171
2:
#endif
L
Linus Torvalds 已提交
172 173

/*
174
 * Jump to the decompressed kernel.
L
Linus Torvalds 已提交
175
 */
176 177
	xorl	%ebx, %ebx
	jmp	*%ebp
178

179 180 181 182 183
/*
 * Stack and heap for uncompression
 */
	.bss
	.balign 4
184 185 186 187 188
boot_heap:
	.fill BOOT_HEAP_SIZE, 1, 0
boot_stack:
	.fill BOOT_STACK_SIZE, 1, 0
boot_stack_end: