head_32.S 4.4 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
#include <linux/init.h>
L
Linus Torvalds 已提交
27 28
#include <linux/linkage.h>
#include <asm/segment.h>
29
#include <asm/page_types.h>
30
#include <asm/boot.h>
R
Rusty Russell 已提交
31
#include <asm/asm-offsets.h>
L
Linus Torvalds 已提交
32

33
	__HEAD
34
ENTRY(startup_32)
M
Matt Fleming 已提交
35
#ifdef CONFIG_EFI_STUB
36 37 38
	jmp	preferred_addr

	.balign	0x10
M
Matt Fleming 已提交
39 40 41 42 43 44 45 46 47
	/*
	 * We don't need the return address, so set up the stack so
	 * efi_main() can find its arugments.
	 */
	add	$0x4, %esp

	call	efi_main
	cmpl	$0, %eax
	movl	%eax, %esi
48
	jne	2f
M
Matt Fleming 已提交
49
1:
50 51 52 53 54 55
	/* EFI init failed, so hang. */
	hlt
	jmp	1b
2:
	call	3f
3:
M
Matt Fleming 已提交
56
	popl	%eax
57
	subl	$3b, %eax
M
Matt Fleming 已提交
58 59 60 61 62 63 64
	subl	BP_pref_address(%esi), %eax
	add	BP_code32_start(%esi), %eax
	leal	preferred_addr(%eax), %eax
	jmp	*%eax

preferred_addr:
#endif
65
	cld
66 67 68 69 70 71
	/*
	 * 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 已提交
72

73
	cli
74 75 76 77 78 79
	movl	$__BOOT_DS, %eax
	movl	%eax, %ds
	movl	%eax, %es
	movl	%eax, %fs
	movl	%eax, %gs
	movl	%eax, %ss
80
1:
R
Rusty Russell 已提交
81

82 83
/*
 * Calculate the delta between where we were compiled to run
84 85 86
 * 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
87 88
 * data at 0x1e4 (defined as a scratch field) are used as the stack
 * for this calculation. Only 4 bytes are needed.
89
 */
90 91 92 93
	leal	(BP_scratch+4)(%esi), %esp
	call	1f
1:	popl	%ebp
	subl	$1b, %ebp
94

95 96
/*
 * %ebp contains the address we are loaded at by the boot loader and %ebx
97 98
 * contains the address where we should move the kernel image temporarily
 * for safe in-place decompression.
99
 */
100

101
#ifdef CONFIG_RELOCATABLE
102
	movl	%ebp, %ebx
103 104 105 106 107
	movl	BP_kernel_alignment(%esi), %eax
	decl	%eax
	addl    %eax, %ebx
	notl	%eax
	andl    %eax, %ebx
108
#else
109
	movl	$LOAD_PHYSICAL_ADDR, %ebx
110 111
#endif

112 113
	/* Target address to relocate to for decompression */
	addl	$z_extract_offset, %ebx
114

115 116 117
	/* Set up the stack */
	leal	boot_stack_end(%ebx), %esp

118 119 120 121
	/* Zero EFLAGS */
	pushl	$0
	popfl

122 123
/*
 * Copy the compressed kernel to the end of our buffer
124 125
 * where decompression in place becomes safe.
 */
126
	pushl	%esi
127 128
	leal	(_bss-4)(%ebp), %esi
	leal	(_bss-4)(%ebx), %edi
129
	movl	$(_bss - startup_32), %ecx
130
	shrl	$2, %ecx
131
	std
132
	rep	movsl
133
	cld
134
	popl	%esi
135

L
Linus Torvalds 已提交
136
/*
137
 * Jump to the relocated address.
L
Linus Torvalds 已提交
138
 */
139 140
	leal	relocated(%ebx), %eax
	jmp	*%eax
141 142
ENDPROC(startup_32)

143
	.text
144 145
relocated:

L
Linus Torvalds 已提交
146
/*
147
 * Clear BSS (stack is currently empty)
L
Linus Torvalds 已提交
148
 */
149
	xorl	%eax, %eax
150
	leal	_bss(%ebx), %edi
151 152
	leal	_ebss(%ebx), %ecx
	subl	%edi, %ecx
153 154
	shrl	$2, %ecx
	rep	stosl
155

156 157 158 159 160 161 162 163 164 165 166 167 168
/*
 * Adjust our own GOT
 */
	leal	_got(%ebx), %edx
	leal	_egot(%ebx), %ecx
1:
	cmpl	%ecx, %edx
	jae	2f
	addl	%ebx, (%edx)
	addl	$4, %edx
	jmp	1b
2:

L
Linus Torvalds 已提交
169 170 171
/*
 * Do the decompression, and jump to the new kernel..
 */
172
	leal	z_extract_offset_negative(%ebx), %ebp
173 174
				/* push arguments for decompress_kernel: */
	pushl	%ebp		/* output address */
175
	pushl	$z_input_len	/* input_len */
176 177 178 179 180 181 182
	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
183 184

#if CONFIG_RELOCATABLE
185 186
/*
 * Find the address of the relocations.
187
 */
188
	leal	z_output_len(%ebp), %edi
189

190 191
/*
 * Calculate the delta between where vmlinux was compiled to run
192 193
 * and where it was actually loaded.
 */
194 195 196
	movl	%ebp, %ebx
	subl	$LOAD_PHYSICAL_ADDR, %ebx
	jz	2f	/* Nothing to be done if loaded at compiled addr. */
L
Linus Torvalds 已提交
197
/*
198
 * Process relocations.
L
Linus Torvalds 已提交
199
 */
200

201 202 203 204 205 206
1:	subl	$4, %edi
	movl	(%edi), %ecx
	testl	%ecx, %ecx
	jz	2f
	addl	%ebx, -__PAGE_OFFSET(%ebx, %ecx)
	jmp	1b
207 208
2:
#endif
L
Linus Torvalds 已提交
209 210

/*
211
 * Jump to the decompressed kernel.
L
Linus Torvalds 已提交
212
 */
213 214
	xorl	%ebx, %ebx
	jmp	*%ebp
215

216 217 218 219 220
/*
 * Stack and heap for uncompression
 */
	.bss
	.balign 4
221 222 223 224 225
boot_heap:
	.fill BOOT_HEAP_SIZE, 1, 0
boot_stack:
	.fill BOOT_STACK_SIZE, 1, 0
boot_stack_end: