head_32.S 4.3 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 93
	/* Set up the stack */
	leal	boot_stack_end(%ebx), %esp

94 95 96 97
	/* Zero EFLAGS */
	pushl	$0
	popfl

98 99
/*
 * Copy the compressed kernel to the end of our buffer
100 101
 * where decompression in place becomes safe.
 */
102
	pushl	%esi
103 104
	leal	(_bss-4)(%ebp), %esi
	leal	(_bss-4)(%ebx), %edi
105
	movl	$(_bss - startup_32), %ecx
106
	shrl	$2, %ecx
107
	std
108
	rep	movsl
109
	cld
110
	popl	%esi
111

112 113
/*
 * Compute the kernel start address.
114 115
 */
#ifdef CONFIG_RELOCATABLE
116 117
	addl    $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
	andl    $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
118
#else
119
	movl	$LOAD_PHYSICAL_ADDR, %ebp
120
#endif
L
Linus Torvalds 已提交
121 122

/*
123
 * Jump to the relocated address.
L
Linus Torvalds 已提交
124
 */
125 126
	leal	relocated(%ebx), %eax
	jmp	*%eax
127 128
ENDPROC(startup_32)

129
	.text
130 131
relocated:

L
Linus Torvalds 已提交
132
/*
133
 * Clear BSS (stack is currently empty)
L
Linus Torvalds 已提交
134
 */
135
	xorl	%eax, %eax
136
	leal	_bss(%ebx), %edi
137 138
	leal	_ebss(%ebx), %ecx
	subl	%edi, %ecx
139 140
	shrl	$2, %ecx
	rep	stosl
141

L
Linus Torvalds 已提交
142 143 144
/*
 * Do the decompression, and jump to the new kernel..
 */
145 146 147 148 149 150 151 152 153 154 155 156 157 158
	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
159 160

#if CONFIG_RELOCATABLE
161 162
/*
 * Find the address of the relocations.
163
 */
164 165
	movl	%ebp, %edi
	addl	%ecx, %edi
166

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

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

/*
188
 * Jump to the decompressed kernel.
L
Linus Torvalds 已提交
189
 */
190 191
	xorl	%ebx, %ebx
	jmp	*%ebp
192

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