1FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
2
3#include <librm.h>
4
5#define BZI_LOAD_HIGH_ADDR 0x100000
6
7	.text
8	.arch i386
9	.code16
10	.section ".prefix", "ax", @progbits
11	.globl	_lkrn_start
12_lkrn_start:
13
14/*****************************************************************************
15 *
16 * Kernel header
17 *
18 * We place our prefix (i.e. our .prefix and .text16.early sections)
19 * within the bzImage real-mode portion which gets loaded at
20 * 1000:0000, and our payload (i.e. everything else) within the
21 * bzImage protected-mode portion which gets loaded at 0x100000
22 * upwards.
23 *
24 */
25
26	.org	0x1f1
27setup_sects:
28	.byte	-1 /* Allow for initial "boot sector" */
29	.section ".zinfo.fixup", "a", @progbits	/* Compressor fixups */
30	.ascii	"ADHL"
31	.long	setup_sects
32	.long	512
33	.long	0
34	.previous
35root_flags:
36	.word	0
37syssize:
38	.long	0
39	.section ".zinfo.fixup", "a", @progbits	/* Compressor fixups */
40	.ascii	"ADPL"
41	.long	syssize
42	.long	16
43	.long	0
44	.previous
45ram_size:
46	.word	0
47vid_mode:
48	.word	0
49root_dev:
50	.word	0
51boot_flag:
52	.word	0xaa55
53jump:
54	/* Manually specify a two-byte jmp instruction here rather
55	 * than leaving it up to the assembler.
56	 */
57	.byte	0xeb, ( setup - header )
58header:
59	.byte	'H', 'd', 'r', 'S'
60version:
61	.word	0x0207 /* 2.07 */
62realmode_swtch:
63	.long	0
64start_sys:
65	.word	0
66kernel_version:
67	.word	version_string - 0x200
68type_of_loader:
69	.byte	0
70loadflags:
71	.byte	0x01 /* LOADED_HIGH */
72setup_move_size:
73	.word	0
74code32_start:
75	.long	0
76ramdisk_image:
77	.long	0
78ramdisk_size:
79	.long	0
80bootsect_kludge:
81	.long	0
82heap_end_ptr:
83	.word	0
84ext_loader_ver:
85	.byte	0
86ext_loader_type:
87	.byte	0
88cmd_line_ptr:
89	.long	0
90initrd_addr_max:
91	.long	0xffffffff
92kernel_alignment:
93	.long	0
94relocatable_kernel:
95	.byte	0
96min_alignment:
97	.byte	0
98xloadflags:
99	.word	0
100cmdline_size:
101	.long	0x7ff
102hardware_subarch:
103	.long	0
104hardware_subarch_data:
105	.byte	0, 0, 0, 0, 0, 0, 0, 0
106
107version_string:
108	.asciz	VERSION
109
110/*****************************************************************************
111 *
112 * Setup code
113 *
114 */
115
116setup:
117	/* Fix up code segment */
118	pushw	%ds
119	pushw	$1f
120	lret
1211:
122	/* Set up stack just below 0x7c00 and clear direction flag */
123	xorw	%ax, %ax
124	movw	%ax, %ss
125	movw	$0x7c00, %sp
126	cld
127
128	/* Retrieve command-line pointer */
129	movl	cmd_line_ptr, %edx
130	testl	%edx, %edx
131	jz	no_cmd_line
132
133	/* Set up %es:%di to point to command line */
134	movl	%edx, %edi
135	andl	$0xf, %edi
136	rorl	$4, %edx
137	movw	%dx, %es
138
139	/* Find length of command line */
140	pushw	%di
141	movw	$0xffff, %cx
142	repnz scasb
143	notw	%cx
144	popw	%si
145
146	/* Make space for command line on stack */
147	movw	%sp, %di
148	subw	%cx, %di
149	andw	$~0xf, %di
150	movw	%di, %sp
151
152	/* Copy command line to stack */
153	pushw	%ds
154	pushw	%es
155	popw	%ds
156	pushw	%ss
157	popw	%es
158	rep movsb
159	popw	%ds
160
161	/* Store new command-line pointer */
162	movzwl	%sp, %edx
163no_cmd_line:
164
165	/* Calculate maximum relocation address */
166	movl	ramdisk_image, %ebp
167	testl	%ebp, %ebp
168	jnz	1f
169	orl	$0xffffffff, %ebp /* Allow arbitrary relocation if no initrd */
1701:
171	/* Install iPXE */
172	call	alloc_basemem
173	xorl	%esi, %esi
174	xorl	%edi, %edi
175	call	install_prealloc
176
177	/* Set up real-mode stack */
178	movw	%bx, %ss
179	movw	$_estack16, %sp
180
181	/* Jump to .text16 segment */
182	pushw	%ax
183	pushw	$1f
184	lret
185	.section ".text16", "awx", @progbits
1861:
187	/* Retrieve initrd pointer and size */
188	movl	ramdisk_image, %ebp
189	movl	ramdisk_size, %ecx
190
191	/* Set up %ds for access to .data16 */
192	movw	%bx, %ds
193
194	/* Store command-line pointer */
195	movl	%edx, cmdline_phys
196
197	/* Store initrd pointer and size */
198	movl	%ebp, initrd_phys
199	movl	%ecx, initrd_len
200
201	/* Run iPXE */
202	virtcall main
203
204	/* Uninstall iPXE */
205	call	uninstall
206
207	/* Boot next device */
208	int $0x18
209
210/*****************************************************************************
211 *
212 * Open payload (called by libprefix)
213 *
214 * Parameters:
215 *   %ds:0000 : Prefix
216 *   %esi : Buffer for copy of image source (or zero if no buffer available)
217 *   %ecx : Expected offset within buffer of first payload block
218 * Returns:
219 *   %esi : Valid image source address (buffered or unbuffered)
220 *   %ecx : Actual offset within buffer of first payload block
221 *   CF set on error
222 */
223
224	.section ".text16.early", "awx", @progbits
225	.globl	open_payload
226open_payload:
227
228	/* Our payload will always end up at BZI_LOAD_HIGH_ADDR */
229	movl	$BZI_LOAD_HIGH_ADDR, %esi
230	xorl	%ecx, %ecx
231	lret
232
233	/* Payload must be aligned to a whole number of setup sectors */
234	.globl	_payload_align
235	.equ	_payload_align, 512
236