Browse Source

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

tags/v0.9.4
Stefan Hajnoczi 16 years ago
parent
commit
1719b105cd
1 changed files with 88 additions and 39 deletions
  1. 88
    39
      src/arch/i386/prefix/lkrnprefix.S

+ 88
- 39
src/arch/i386/prefix/lkrnprefix.S View File

10
 	Description:	
10
 	Description:	
11
 
11
 
12
 	This is just a little bit of code and data that can get prepended
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
 	A real Linux kernel image consists of a one-sector boot loader
16
 	A real Linux kernel image consists of a one-sector boot loader
17
 	(to load the image from a floppy disk), followed a few sectors
17
 	(to load the image from a floppy disk), followed a few sectors
21
 	contains some other parameters that aren't interesting in this
21
 	contains some other parameters that aren't interesting in this
22
 	case.
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
 why_end: 
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
 	.org	497
89
 	.org	497
89
 setup_sects: 
90
 setup_sects: 
90
 	.byte	SETUPSECS
91
 	.byte	SETUPSECS
91
 root_flags: 
92
 root_flags: 
92
 	.word	0
93
 	.word	0
93
 syssize: 
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
 ram_size: 
104
 ram_size: 
98
 	.word	0
105
 	.word	0
99
 vid_mode: 
106
 vid_mode: 
102
 	.word	0
109
 	.word	0
103
 boot_flag: 
110
 boot_flag: 
104
 	.word	0xAA55
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
 	.long	0
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
 	This code gets loaded at SETUPSEG:0.  It wants to start
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
 	whose entry point is SYSSEG:0.
164
 	whose entry point is SYSSEG:0.
125
 */
165
 */
126
 setup_code:
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
 	.org	PREFIXSIZE
176
 	.org	PREFIXSIZE
137
 /*
177
 /*
138
 	We're now at the beginning of the kernel proper.
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
 	call	install
186
 	call	install
142
 
187
 
188
+	/* Set up real-mode stack */
189
+	movw	%bx, %ss
190
+	movw	$_estack16, %sp
191
+
143
 	/* Jump to .text16 segment */
192
 	/* Jump to .text16 segment */
144
 	pushw	%ax
193
 	pushw	%ax
145
 	pushw	$1f
194
 	pushw	$1f

Loading…
Cancel
Save