head_32.S 4.2 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 78
#endif

	/* Replace the compressed data size with the uncompressed size */
79 80 81
	subl	input_len(%ebp), %ebx
	movl	output_len(%ebp), %eax
	addl	%eax, %ebx
82
	/* Add 8 bytes for every 32K input block */
83 84
	shrl	$12, %eax
	addl	%eax, %ebx
85
	/* Add 32K + 18 bytes of extra slack */
86
	addl	$(32768 + 18), %ebx
87
	/* Align on a 4K boundary */
88 89
	addl	$4095, %ebx
	andl	$~4095, %ebx
90

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

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

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

121
	.text
122 123
relocated:

L
Linus Torvalds 已提交
124 125 126
/*
 * Clear BSS
 */
127
	xorl	%eax, %eax
128
	leal	_bss(%ebx), %edi
129 130
	leal	_ebss(%ebx), %ecx
	subl	%edi, %ecx
L
Linus Torvalds 已提交
131
	cld
132
	rep	stosb
133 134 135 136

/*
 * Setup the stack for the decompressor
 */
137
	leal	boot_stack_end(%ebx), %esp
138

L
Linus Torvalds 已提交
139 140 141
/*
 * Do the decompression, and jump to the new kernel..
 */
142 143 144 145 146 147 148 149 150 151 152 153 154 155
	movl	output_len(%ebx), %eax
	pushl	%eax
				/* push arguments for decompress_kernel: */
	pushl	%ebp		/* output address */
	movl	input_len(%ebx), %eax
	pushl	%eax		/* input_len */
	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
	popl	%ecx
156 157

#if CONFIG_RELOCATABLE
158 159
/*
 * Find the address of the relocations.
160
 */
161 162
	movl	%ebp, %edi
	addl	%ecx, %edi
163

164 165
/*
 * Calculate the delta between where vmlinux was compiled to run
166 167
 * and where it was actually loaded.
 */
168 169 170
	movl	%ebp, %ebx
	subl	$LOAD_PHYSICAL_ADDR, %ebx
	jz	2f	/* Nothing to be done if loaded at compiled addr. */
L
Linus Torvalds 已提交
171
/*
172
 * Process relocations.
L
Linus Torvalds 已提交
173
 */
174

175 176 177 178 179 180
1:	subl	$4, %edi
	movl	(%edi), %ecx
	testl	%ecx, %ecx
	jz	2f
	addl	%ebx, -__PAGE_OFFSET(%ebx, %ecx)
	jmp	1b
181 182
2:
#endif
L
Linus Torvalds 已提交
183 184

/*
185
 * Jump to the decompressed kernel.
L
Linus Torvalds 已提交
186
 */
187 188
	xorl	%ebx, %ebx
	jmp	*%ebp
189

190 191 192 193 194
/*
 * Stack and heap for uncompression
 */
	.bss
	.balign 4
195 196 197 198 199
boot_heap:
	.fill BOOT_HEAP_SIZE, 1, 0
boot_stack:
	.fill BOOT_STACK_SIZE, 1, 0
boot_stack_end: