Просмотр исходного кода

[lkrnprefix] Make gPXE .lkrn images conform to the zImage 2.07 format

tags/v0.9.4
Stefan Hajnoczi 16 лет назад
Родитель
Сommit
1719b105cd
1 измененных файлов: 88 добавлений и 39 удалений
  1. 88
    39
      src/arch/i386/prefix/lkrnprefix.S

+ 88
- 39
src/arch/i386/prefix/lkrnprefix.S Просмотреть файл

@@ -10,8 +10,8 @@
10 10
 	Description:	
11 11
 
12 12
 	This is just a little bit of code and data that can get prepended
13
-	to an Etherboot ROM image in order to allow LILO to load the
14
-	result as if it were a Linux kernel image.
13
+	to a ROM image in order to allow bootloaders to load the result
14
+	as if it were a Linux kernel image.
15 15
 
16 16
 	A real Linux kernel image consists of a one-sector boot loader
17 17
 	(to load the image from a floppy disk), followed a few sectors
@@ -21,19 +21,16 @@
21 21
 	contains some other parameters that aren't interesting in this
22 22
 	case.
23 23
 
24
-	When LILO loads the sectors that comprise a kernel image, it doesn't
25
-	execute the code in the first sector (since that code would try to
26
-	load the image from a floppy disk.)  The code in the first sector
27
-	below doesn't expect to get executed (and prints an error message
28
-	if it ever -is- executed.)  LILO's only interested in knowing the
29
-	number of setup sectors advertised in the table (at offset 497 in
30
-	the first sector.)
24
+	When a bootloader loads the sectors that comprise a kernel image,
25
+	it doesn't execute the code in the first sector (since that code
26
+	would try to load the image from a floppy disk.)  The code in the
27
+	first sector below doesn't expect to get executed (and prints an
28
+	error message if it ever -is- executed.)
31 29
 
32
-	Etherboot doesn't require much in the way of setup code.
33
-	Historically, the Linux kernel required at least 4 sectors of
34
-	setup code.  Current versions of LILO look at the byte at
35
-	offset 497 in the first sector to indicate how many sectors
36
-	of setup code are contained in the image.
30
+	We don't require much in the way of setup code.  Historically, the
31
+	Linux kernel required at least 4 sectors of setup code.
32
+	Therefore, at least 4 sectors must be present even though we don't
33
+	use them.
37 34
 
38 35
 */
39 36
 
@@ -85,15 +82,25 @@ why:	.ascii	"This image cannot be loaded from a floppy disk.\r\n"
85 82
 why_end: 
86 83
 
87 84
 
85
+/*
86
+	The following header is documented in the Linux source code at
87
+	Documentation/i386/boot.txt
88
+*/
88 89
 	.org	497
89 90
 setup_sects: 
90 91
 	.byte	SETUPSECS
91 92
 root_flags: 
92 93
 	.word	0
93 94
 syssize: 
94
-	.word	_load_size_pgh - PREFIXPGH
95
-swap_dev: 
96
-	.word	0
95
+	.long	_load_size_pgh - PREFIXPGH
96
+
97
+	.section ".zinfo.fixup", "a"	/* Compressor fixup information */
98
+	.ascii	"SUBL"
99
+	.long	syssize
100
+	.long	16
101
+	.long	0
102
+	.previous
103
+	
97 104
 ram_size: 
98 105
 	.word	0
99 106
 vid_mode: 
@@ -102,44 +109,86 @@ root_dev:
102 109
 	.word	0
103 110
 boot_flag: 
104 111
 	.word	0xAA55
105
-
106
-
107
-	.org	512
108
-
109
-	.section ".zinfo.fixup", "a"	/* Compressor fixup information */
110
-	.ascii	"SUBW"
111
-	.long	syssize
112
-	.long	16
112
+jump:
113
+	jmp	setup_code
114
+header:
115
+	.byte	'H', 'd', 'r', 'S'
116
+version:
117
+	.word	0x0207 /* 2.07 */
118
+realmode_swtch:
113 119
 	.long	0
114
-	.previous
115
-	
116
-/*
117
-	We're now at the beginning of the second sector of the image -
118
-	where the setup code goes.
120
+start_sys:
121
+	.word	0
122
+kernel_version:
123
+	.word	0
124
+type_of_loader:
125
+	.byte	0
126
+loadflags:
127
+	.byte	0
128
+setup_move_size:
129
+	.word	0
130
+code32_start:
131
+	.long	0
132
+ramdisk_image:
133
+	.long	0
134
+ramdisk_size:
135
+	.long	0
136
+bootsect_kludge:
137
+	.long	0
138
+heap_end_ptr:
139
+	.word	0
140
+pad1:
141
+	.word	0
142
+cmd_line_ptr:
143
+	.long	0
144
+initrd_addr_max:
145
+	.long	0
146
+kernel_alignment:
147
+	.long	0
148
+relocatable_kernel:
149
+	.byte	0
150
+pad2:
151
+	.byte	0, 0, 0
152
+cmdline_size:
153
+	.long	0
154
+hardware_subarch:
155
+	.long	0
156
+hardware_subarch_data:
157
+	.byte	0, 0, 0, 0, 0, 0, 0, 0
119 158
 
120
-	We don't need to do too much setup for Etherboot.
159
+/*
160
+	We don't need to do too much setup.
121 161
 
122 162
 	This code gets loaded at SETUPSEG:0.  It wants to start
123
-	executing the Etherboot image that's loaded at SYSSEG:0 and
163
+	executing the image that's loaded at SYSSEG:0 and
124 164
 	whose entry point is SYSSEG:0.
125 165
 */
126 166
 setup_code:
127
-	/* Etherboot expects to be contiguous in memory once loaded.
128
-	 * LILO doesn't do this, but since we don't need any
129
-	 * information that's left in the prefix, it doesn't matter:
130
-	 * we just have to ensure that %cs:0000 is where the start of
131
-	 * the Etherboot image *would* be.
167
+	/* We expect to be contiguous in memory once loaded.  The Linux image
168
+	 * boot process requires that setup code is loaded separately from
169
+	 * "non-real code".  Since we don't need any information that's left
170
+	 * in the prefix, it doesn't matter: we just have to ensure that
171
+	 * %cs:0000 is where the start of the image *would* be.
132 172
 	 */
133
-	ljmp	$(SYSSEG-(PREFIXSIZE/16)), $run_etherboot
173
+	ljmp	$(SYSSEG-(PREFIXSIZE/16)), $run_gpxe
134 174
 
135 175
 
136 176
 	.org	PREFIXSIZE
137 177
 /*
138 178
 	We're now at the beginning of the kernel proper.
139 179
  */
140
-run_etherboot:
180
+run_gpxe:
181
+	/* Set up stack just below 0x7c00 */
182
+	xorw	%ax, %ax
183
+	movw	%ax, %ss
184
+	movw	$0x7c00, %sp
185
+
141 186
 	call	install
142 187
 
188
+	/* Set up real-mode stack */
189
+	movw	%bx, %ss
190
+	movw	$_estack16, %sp
191
+
143 192
 	/* Jump to .text16 segment */
144 193
 	pushw	%ax
145 194
 	pushw	$1f

Загрузка…
Отмена
Сохранить