1 ; -*- fundamental -*- (asm-mode sucks)
2 ; ****************************************************************************
6 ; A program to boot Linux kernels off a TFTP server using the Intel PXE
7 ; network booting API. It is based on the SYSLINUX boot loader for
10 ; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
11 ; Copyright 2009 Intel Corporation; author: H. Peter Anvin
13 ; This program is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
16 ; Boston MA 02111-1307, USA; either version 2 of the License, or
17 ; (at your option) any later version; incorporated herein by reference.
19 ; ****************************************************************************
25 ; gPXE extensions support
29 ; Some semi-configurable constants... change on your own risk.
32 NULLFILE
equ 0 ; Zero byte == null file name
33 NULLOFFSET
equ 0 ; Position in which to look
34 REBOOT_TIME
equ 5*60 ; If failure, time until full reset
35 %assign HIGHMEM_SLOP
128*1024 ; Avoid this much memory near the top
36 TFTP_BLOCKSIZE_LG2
equ 9 ; log2(bytes/block)
37 TFTP_BLOCKSIZE
equ (1 << TFTP_BLOCKSIZE_LG2
)
39 SECTOR_SHIFT
equ TFTP_BLOCKSIZE_LG2
40 SECTOR_SIZE
equ TFTP_BLOCKSIZE
43 ; The following structure is used for "virtual kernels"; i.e. LILO-style
44 ; option labels. The options we permit here are `kernel' and `append
45 ; Since there is no room in the bottom 64K for all of these, we
46 ; stick them in high memory and copy them down before we need them.
49 vk_vname: resb FILENAME_MAX
; Virtual name **MUST BE FIRST!**
50 vk_rname: resb FILENAME_MAX
; Real name
51 vk_ipappend: resb
1 ; "IPAPPEND" flag
52 vk_type: resb
1 ; Type of file
55 vk_append: resb max_cmd_len
+1 ; Command line
57 vk_end: equ $
; Should be <= vk_size
61 ; ---------------------------------------------------------------------------
63 ; ---------------------------------------------------------------------------
66 ; Memory below this point is reserved for the BIOS and the MBR
71 trackbuf resb trackbufsize
; Track buffer goes here
74 ; These fields save information from before the time
75 ; .bss is zeroed... must be in .earlybss
81 PXEStack resd
1 ; Saved stack during PXE call
84 global DHCPMagic
, RebootTime
, APIVer
85 RebootTime resd
1 ; Reboot timeout, if set by option
86 StrucPtr resw
2 ; Pointer to PXENV+ or !PXE structure
87 APIVer resw
1 ; PXE API version found
88 LocalBootType resw
1 ; Local boot return code
89 DHCPMagic resb
1 ; PXELINUX magic flags
92 StackBuf
equ STACK_TOP
-44 ; Base of stack if we use our own
93 StackHome
equ StackBuf
95 ; PXE loads the whole file, but assume it can't be more
96 ; than (384-31)K in size.
100 ; Primary entry point.
104 jmp 0:_start1
; Canonicalize the address and skip
108 ; Patch area for adding hardwired DHCP options
112 hcdhcp_magic
dd 0x2983c8ac ; Magic number
113 hcdhcp_len
dd 7*4 ; Size of this structure
114 hcdhcp_flags
dd 0 ; Reserved for the future
115 ; Parameters to be parsed before the ones from PXE
116 bdhcp_offset
dd 0 ; Offset (entered by patcher)
117 bdhcp_len
dd 0 ; Length (entered by patcher)
118 ; Parameters to be parsed *after* the ones from PXE
119 adhcp_offset
dd 0 ; Offset (entered by patcher)
120 adhcp_len
dd 0 ; Length (entered by patcher)
123 pushfd ; Paranoia... in case of return to PXE
124 pushad ; ... save as much state as possible
135 %if
0 ; debugging code only... not intended for production use
136 ; Clobber the stack segment, to test for specific pathologies
138 mov cx,STACK_LEN
>> 1
142 ; Clobber the tail of the 64K segment, too
145 sub cx,di ; CX = 0 previously
150 ; That is all pushed onto the PXE stack. Save the pointer
151 ; to it and switch to an internal stack.
156 sti ; Stack set up and ready
158 ; Move the hardwired DHCP options (if present) to a safe place...
162 mov ax,trackbufsize
/2
169 mov eax,[bdhcp_offset
]
185 mov ax,trackbufsize
/2
192 mov eax,[adhcp_offset
]
199 mov di,trackbuf
+trackbufsize
/2
207 ; Initialize screen (if we're using one)
212 ; Tell the user we got this far
214 mov si,syslinux_banner
237 ; Initialize the idle mechanism
242 ; Now we're all set to start with our *real* business. First load the
243 ; configuration file (if any) and parse it.
245 ; In previous versions I avoided using 32-bit registers because of a
246 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
247 ; random. I figure, though, that if there are any of those still left
248 ; they probably won't be trying to install Linux on them...
250 ; The code is still ripe with 16-bitisms, though. Not worth the hassle
251 ; to take'm out. In fact, we may want to put them back if we're going
252 ; to boot ELKS at some point.
256 ; Linux kernel loading code is common. However, we need to define
257 ; a couple of helper macros...
261 %define HAVE_UNLOAD_PREP
267 ; Open configuration file. ldlinux.c32 needs ConfigName to be set - so we need
268 ; to call open_config() before loading it.
270 ; Note: We don't need to check return value of open_config() function. It will
271 ; call kaboom() on failure.
277 ; Jump to 32-bit ELF space
280 jmp kaboom
; load_env32() shouldn't return. If it does, then kaboom!
287 ; As core/ui.inc used to be included here in core/pxelinux.asm, and it's no
288 ; longer used, its global variables that were previously used by
289 ; core/pxelinux.asm are now declared here.
296 global CmdOptPtr
, KbdMap
298 ThisKbdTo resd
1 ; Temporary holder for KbdTimeout
299 ThisTotalTo resd
1 ; Temporary holder for TotalTimeout
300 KernelExtPtr resw
1 ; During search, final null pointer
301 CmdOptPtrj resw
1 ; Pointer to first option on cmd line
302 KbdFlags resb
1 ; Check for keyboard escapes
303 FuncFlag resb
1 ; Escape sequences received from keyboard
304 KernelType resb
1 ; Kernel type, from vkernel, if known
305 KbdMap resb
256 ; Keyboard map
307 KernelName resb FILENAME_MAX
; Mangled name for kernel
310 PXERetry
dw 0 ; Extra PXE retries
313 SerialNotice
db 1 ; Only print this once
315 global IPAppends
, numIPAppends
317 IPAppends
dw IPOption
318 numIPAppends
equ ($
-IPAppends
)/2
322 ; COMBOOT-loading code
323 %include "comboot.inc"
326 ; Hardware cleanup common code
327 %include "localboot.inc"
333 ; kaboom: write a message and bail out. Wait for quite a while,
334 ; or a user keypress, then do a hard reboot.
336 ; Note: use BIOS_timer here; we may not have jiffies set up.
340 RESET_STACK_AND_SEGS
AX
341 .
patch: mov si,bailmsg
342 call writestr_early
; Returns with AL = 0
343 .
drain: call pollchar
350 and al,09h ; Magic+Timeout
358 .
wait2: mov dx,[BIOS_timer
]
359 .
wait3: call pollchar
371 mov word [BIOS_magic
],0 ; Cold reboot
372 jmp 0F000h:0FFF0h
; Reset vector address
377 ; This is the main PXENV+/!PXE entry point, using the PXENV+
378 ; calling convention. This is a separate local routine so
379 ; we can hook special things from it if necessary. In particular,
380 ; some PXE stacks seem to not like being invoked from anything but
381 ; the initial stack, so humour it.
383 ; While we're at it, save and restore all registers.
390 ; We may be removing ourselves from memory
391 cmp bx,0073h ; PXENV_RESTART_TFTP
393 cmp bx,00E5h
; gPXE PXENV_FILE_EXEC
401 mov [cs:PXEStack
+2],ss
402 lss sp,[cs:InitStack
]
404 ; Pre-clear the Status field
407 ; This works either for the PXENV+ or the !PXE calling
408 ; convention, as long as we ignore CF (which is redundant
415 mov [cs:PXEStatus
],ax
421 setnz [bp+32] ; If AX != 0 set CF on return
423 ; This clobbers the AX return, but we already saved it into
424 ; the PXEStatus variable.
427 ; If the call failed, it could return.
437 popfd ; Restore flags (incl. IF, DF)
440 ; Must be after function def due to NASM bug
442 PXEEntry
equ pxenv.jump
+1
451 ; Invoke INT 1Ah on the PXE stack. This is used by the "Plan C" method
452 ; for finding the PXE entry point.
457 mov [cs:PXEStack
+2],ss
458 lss sp,[cs:InitStack
]
460 int 1Ah ; May trash registers
466 ; Special unload for gPXE: this switches the InitStack from
467 ; gPXE to the ROM PXE stack.
472 mov bx,PXENV_FILE_EXIT_HOOK
473 mov di,pxe_file_exit_hook
477 ; Now we actually need to exit back to gPXE, which will
478 ; give control back to us on the *new* "original stack"...
496 ; gPXE will have a stack frame looking much like our
497 ; InitStack, except it has a magic cookie at the top,
498 ; and the segment registers are in reverse order.
508 mov [cs:InitStack
],sp
509 mov [cs:InitStack
+2],ss
534 .
offset: dw gpxe_unload.resume
540 ; -----------------------------------------------------------------------------
542 ; -----------------------------------------------------------------------------
544 %include "common.inc" ; Universal modules
546 ; -----------------------------------------------------------------------------
548 ; -----------------------------------------------------------------------------
552 global copyright_str
, syslinux_banner
553 copyright_str
db ' Copyright (C) 1994-'
555 db ' H. Peter Anvin et al', CR
, LF
, 0
556 err_bootfailed
db CR
, LF
, 'Boot failed: press a key to retry, or wait for reset...', CR
, LF
, 0
557 bailmsg
equ err_bootfailed
558 localboot_msg
db 'Booting from local disk...', CR
, LF
, 0
559 syslinux_banner
db CR
, LF
, MY_NAME
, ' ', VERSION_STR
, ' ', DATE_STR
, ' ', 0
562 ; Misc initialized (data) variables
566 KeepPXE
db 0 ; Should PXE be kept around?
569 ; IP information. Note that the field are in the same order as the
570 ; Linux kernel expects in the ip= option.
576 .IPv4 resd
1 ; IPv4 information
577 .MyIP resd
1 ; My IP address