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 (C) 1994-2007 H. Peter Anvin
12 ; This program is free software; you can redistribute it and/or modify
13 ; it under the terms of the GNU General Public License as published by
14 ; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
15 ; Boston MA 02111-1307, USA; either version 2 of the License, or
16 ; (at your option) any later version; incorporated herein by reference.
18 ; ****************************************************************************
25 ; Some semi-configurable constants... change on your own risk.
28 FILENAME_MAX_LG2
equ 7 ; log2(Max filename size Including final null)
29 FILENAME_MAX
equ (1 << FILENAME_MAX_LG2
)
30 NULLFILE
equ 0 ; Zero byte == null file name
31 NULLOFFSET
equ 4 ; Position in which to look
32 REBOOT_TIME
equ 5*60 ; If failure, time until full reset
33 %assign HIGHMEM_SLOP
128*1024 ; Avoid this much memory near the top
34 MAX_OPEN_LG2
equ 5 ; log2(Max number of open sockets)
35 MAX_OPEN
equ (1 << MAX_OPEN_LG2
)
36 PKTBUF_SIZE
equ (65536/MAX_OPEN
) ; Per-socket packet buffer size
37 TFTP_PORT
equ htons
(69) ; Default TFTP port
38 PKT_RETRY
equ 6 ; Packet transmit retry count
39 PKT_TIMEOUT
equ 12 ; Initial timeout, timer ticks @ 55 ms
40 ; Desired TFTP block size
41 ; For Ethernet MTU is normally 1500. Unfortunately there seems to
42 ; be a fair number of networks with "substandard" MTUs which break.
43 ; The code assumes TFTP_LARGEBLK <= 2K.
45 TFTP_LARGEBLK
equ (TFTP_MTU
-20-8-4) ; MTU - IP hdr - UDP hdr - TFTP hdr
46 ; Standard TFTP block size
47 TFTP_BLOCKSIZE_LG2
equ 9 ; log2(bytes/block)
48 TFTP_BLOCKSIZE
equ (1 << TFTP_BLOCKSIZE_LG2
)
49 %assign USE_PXE_PROVIDED_STACK
1 ; Use stack provided by PXE?
51 SECTOR_SHIFT
equ TFTP_BLOCKSIZE_LG2
52 SECTOR_SIZE
equ TFTP_BLOCKSIZE
55 ; This is what we need to do when idle
56 ; *** This is disabled because some PXE stacks wait for unacceptably
57 ; *** long if there are no packets receivable.
59 %define HAVE_IDLE
0 ; idle is not a noop
78 ; TFTP operation codes
80 TFTP_RRQ
equ htons
(1) ; Read request
81 TFTP_WRQ
equ htons
(2) ; Write request
82 TFTP_DATA
equ htons
(3) ; Data packet
83 TFTP_ACK
equ htons
(4) ; ACK packet
84 TFTP_ERROR
equ htons
(5) ; ERROR packet
85 TFTP_OACK
equ htons
(6) ; OACK packet
90 TFTP_EUNDEF
equ htons
(0) ; Unspecified error
91 TFTP_ENOTFOUND
equ htons
(1) ; File not found
92 TFTP_EACCESS
equ htons
(2) ; Access violation
93 TFTP_ENOSPACE
equ htons
(3) ; Disk full
94 TFTP_EBADOP
equ htons
(4) ; Invalid TFTP operation
95 TFTP_EBADID
equ htons
(5) ; Unknown transfer
96 TFTP_EEXISTS
equ htons
(6) ; File exists
97 TFTP_ENOUSER
equ htons
(7) ; No such user
98 TFTP_EOPTNEG
equ htons
(8) ; Option negotiation failure
101 ; The following structure is used for "virtual kernels"; i.e. LILO-style
102 ; option labels. The options we permit here are `kernel' and `append
103 ; Since there is no room in the bottom 64K for all of these, we
104 ; stick them at vk_seg:0000 and copy them down before we need them.
107 vk_vname: resb FILENAME_MAX
; Virtual name **MUST BE FIRST!**
108 vk_rname: resb FILENAME_MAX
; Real name
109 vk_ipappend: resb
1 ; "IPAPPEND" flag
110 vk_type: resb
1 ; Type of file
113 vk_append: resb max_cmd_len
+1 ; Command line
115 vk_end: equ $
; Should be <= vk_size
119 ; Segment assignments in the bottom 640K
120 ; 0000h - main code/data segment (and BIOS segment)
122 real_mode_seg
equ 4000h
123 pktbuf_seg
equ 3000h ; Packet buffers segments
124 vk_seg
equ 2000h ; Virtual kernels
125 xfer_buf_seg
equ 1000h ; Bounce buffer for I/O to high mem
126 comboot_seg
equ real_mode_seg
; COMBOOT image loading zone
129 ; BOOTP/DHCP packet pattern
133 .opcode resb
1 ; BOOTP/DHCP "opcode"
134 .hardware resb
1 ; ARP hardware type
135 .hardlen resb
1 ; Hardware address length
136 .gatehops resb
1 ; Used by forwarders
137 .ident resd
1 ; Transaction ID
138 .seconds resw
1 ; Seconds elapsed
139 .flags resw
1 ; Broadcast flags
140 .cip resd
1 ; Client IP
141 .yip resd
1 ; "Your" IP
142 .sip resd
1 ; Next server IP
143 .gip resd
1 ; Relay agent IP
144 .macaddr resb
16 ; Client MAC address
145 .sname resb
64 ; Server name (optional)
146 .bootfile resb
128 ; Boot file name
147 .option_magic resd
1 ; Vendor option magic cookie
148 .options resb
1260 ; Vendor options
151 BOOTP_OPTION_MAGIC
equ htonl
(0x63825363) ; See RFC 2132
154 ; TFTP connection data structure. Each one of these corresponds to a local
155 ; UDP port. The size of this structure must be a power of 2.
156 ; HBO = host byte order; NBO = network byte order
157 ; (*) = written by options negotiation code, must be dword sized
160 tftp_localport resw
1 ; Local port number (0 = not in use)
161 tftp_remoteport resw
1 ; Remote port number
162 tftp_remoteip resd
1 ; Remote IP address
163 tftp_filepos resd
1 ; Bytes downloaded (including buffer)
164 tftp_filesize resd
1 ; Total file size(*)
165 tftp_blksize resd
1 ; Block size for this connection(*)
166 tftp_bytesleft resw
1 ; Unclaimed data bytes
167 tftp_lastpkt resw
1 ; Sequence number of last packet (NBO)
168 tftp_dataptr resw
1 ; Pointer to available data
169 resw
2 ; Currently unusued
170 ; At end since it should not be zeroed on socked close
171 tftp_pktbuf resw
1 ; Packet buffer offset
174 %if
(open_file_t_size
& (open_file_t_size
-1))
175 %error
"open_file_t is not a power of 2"
179 ; ---------------------------------------------------------------------------
181 ; ---------------------------------------------------------------------------
184 ; Memory below this point is reserved for the BIOS and the MBR
187 trackbufsize
equ 8192
188 trackbuf resb trackbufsize
; Track buffer goes here
189 getcbuf resb trackbufsize
192 ; Put some large buffers here, before RBFG_brainfuck,
193 ; where we can still carefully control the address
196 alignb open_file_t_size
197 Files resb MAX_OPEN
*open_file_t_size
200 BootFile resb
256 ; Boot file from DHCP packet
201 PathPrefix resb
256 ; Path prefix derived from boot file
202 DotQuadBuf resb
16 ; Buffer for dotted-quad IP address
203 IPOption resb
80 ; ip= option buffer
204 InitStack resd
1 ; Pointer to reset stack (SS:SP)
205 PXEStack resd
1 ; Saved stack during PXE call
207 ; Warning here: RBFG build 22 randomly overwrites memory location
208 ; [0x5680,0x576c), possibly more. It seems that it gets confused and
209 ; screws up the pointer to its own internal packet buffer and starts
210 ; writing a received ARP packet into low memory.
211 RBFG_brainfuck resb
0E00h
215 RebootTime resd
1 ; Reboot timeout, if set by option
216 StrucPtr resd
1 ; Pointer to PXENV+ or !PXE structure
217 APIVer resw
1 ; PXE API version found
218 IPOptionLen resw
1 ; Length of IPOption
219 IdleTimer resw
1 ; Time to check for ARP?
220 LocalBootType resw
1 ; Local boot return code
221 PktTimeout resw
1 ; Timeout for current packet
222 RealBaseMem resw
1 ; Amount of DOS memory after freeing
223 OverLoad resb
1 ; Set if DHCP packet uses "overloading"
224 DHCPMagic resb
1 ; PXELINUX magic flags
226 ; The relative position of these fields matter!
227 MAC_MAX
equ 32 ; Handle hardware addresses this long
228 MACLen resb
1 ; MAC address len
229 MACType resb
1 ; MAC address type
230 MAC resb MAC_MAX
+1 ; Actual MAC address
231 BOOTIFStr resb
7 ; Space for "BOOTIF="
232 MACStr resb
3*(MAC_MAX
+1) ; MAC address as a string
234 ; The relative position of these fields matter!
235 UUIDType resb
1 ; Type byte from DHCP option
236 UUID resb
16 ; UUID, from the PXE stack
237 UUIDNull resb
1 ; dhcp_copyoption zero-terminates
240 ; PXE packets which don't need static initialization
243 pxe_unload_stack_pkt:
244 .
status: resw
1 ; Status
245 .
reserved: resw
10 ; Reserved
246 pxe_unload_stack_pkt_len
equ $
-pxe_unload_stack_pkt
249 ; BOOTP/DHCP packet buffer
252 packet_buf resb
2048 ; Transfer packet
253 packet_buf_size
equ $
-packet_buf
256 ; Constants for the xfer_buf_seg
258 ; The xfer_buf_seg is also used to store message file buffers. We
259 ; need two trackbuffers (text and graphics), plus a work buffer
260 ; for the graphics decompressor.
262 xbs_textbuf
equ 0 ; Also hard-coded, do not change
263 xbs_vgabuf
equ trackbufsize
264 xbs_vgatmpbuf
equ 2*trackbufsize
268 ; PXELINUX needs more BSS than the other derivatives;
269 ; therefore we relocate it from 7C00h on startup.
271 StackBuf
equ $
; Base of stack if we use our own
274 ; Primary entry point.
278 pushfd ; Paranoia... in case of return to PXE
279 pushad ; ... save as much state as possible
290 %if TEXT_START
!= 0x7c00
291 ; This is uglier than it should be, but works around
292 ; some NASM 0.98.38 bugs.
293 mov di,section..bcopy32.start
294 add di,__bcopy_size
-4
295 lea si,[di-(TEXT_START
-7C00h
)]
296 lea cx,[di-(TEXT_START
-4)]
298 std ; Overlapping areas, copy backwards
302 jmp 0:_start1
; Canonicalize address
305 les bx,[bp+48] ; ES:BX -> !PXE or PXENV+ structure
307 ; That is all pushed onto the PXE stack. Save the pointer
308 ; to it and switch to an internal stack.
312 %if USE_PXE_PROVIDED_STACK
313 ; Apparently some platforms go bonkers if we
314 ; set up our own stack...
322 sti ; Stack set up and ready
326 ; Initialize screen (if we're using one)
328 push es ; Save ES -> PXE entry structure
332 pop es ; Restore ES -> PXE entry structure
334 ; Tell the user we got this far
336 mov si,syslinux_banner
343 ; Assume API version 2.1, in case we find the !PXE structure without
344 ; finding the PXENV+ structure. This should really look at the Base
345 ; Code ROM ID structure in have_pxe, but this is adequate for now --
346 ; if we have !PXE, we have to be 2.1 or higher, and we don't care
347 ; about higher versions than that.
349 mov word [APIVer
],0201h
352 ; Now we need to find the !PXE structure. It's *supposed* to be pointed
353 ; to by SS:[SP+4], but support INT 1Ah, AX=5650h method as well.
354 ; FIX: ES:BX should point to the PXENV+ structure on entry as well.
355 ; We should make that the second test, and not trash ES:BX...
357 cmp dword [es:bx], '!PXE'
360 ; Uh-oh, not there... try plan B
362 %if USE_PXE_PROVIDED_STACK
== 0
365 int 1Ah ; May trash regs
366 %if USE_PXE_PROVIDED_STACK
== 0
374 ; Okay, that gave us the PXENV+ structure, find !PXE
375 ; structure from that (if available)
376 cmp dword [es:bx], 'PXEN'
378 cmp word [es:bx+4], 'V+'
381 ; Nothing there either. Last-ditch: scan memory
382 call memory_scan_for_pxe_struct
; !PXE scan
384 call memory_scan_for_pxenv_struct
; PXENV+ scan
387 no_pxe: mov si,err_nopxe
405 cmp ax,0201h ; API version 2.1 or higher
409 les bx,[es:bx+28h] ; !PXE structure pointer
410 cmp dword [es:bx],'!PXE'
413 ; Nope, !PXE structure missing despite API 2.1+, or at least
414 ; the pointer is missing. Do a last-ditch attempt to find it.
415 call memory_scan_for_pxe_struct
418 ; Otherwise, no dice, use PXENV+ structure
422 old_api: ; Need to use a PXENV+ structure
423 mov si,using_pxenv_msg
426 mov eax,[es:bx+0Ah] ; PXE RM API
434 mov si,undi_data_len_msg
444 mov si,undi_code_len_msg
450 ; Compute base memory size from PXENV+ structure
452 movzx eax,word [es:bx+20h] ; UNDI data seg
453 cmp ax,[es:bx+24h] ; UNDI code seg
463 shr eax,10 ; Convert to kilobytes
466 mov si,pxenventry_msg
468 mov ax,[PXENVEntry
+2]
489 mov si,undi_data_len_msg
499 mov si,undi_code_len_msg
505 ; Compute base memory size from !PXE structure
532 pop es ; Restore CS == DS == ES
535 ; Network-specific initialization
538 mov [LocalDomain
],al ; No LocalDomain received
541 ; The DHCP client identifiers are best gotten from the DHCPREQUEST
542 ; packet (query info 1).
546 call pxe_get_cached_info
549 ; We don't use flags from the request packet, so
550 ; this is a good time to initialize DHCPMagic...
551 mov byte [DHCPMagic
],0
554 ; Now attempt to get the BOOTP/DHCP packet that brought us life (and an IP
555 ; address). This lives in the DHCPACK packet (query info 2).
559 call pxe_get_cached_info
560 call parse_dhcp
; Parse DHCP packet
562 ; Save away MAC address (assume this is in query info 2. If this
563 ; turns out to be problematic it might be better getting it from
564 ; the query info 1 packet.)
567 movzx cx,byte [trackbuf
+bootp.hardlen
]
570 xor cx,cx ; Bad hardware address length
573 mov al,[trackbuf
+bootp.hardware
]
575 mov si,trackbuf
+bootp.macaddr
579 ; Enable this if we really need to zero-pad this field...
580 ; mov cx,MAC+MAC_MAX+1
586 ; Now, get the boot file and other info. This lives in the CACHED_REPLY
587 ; packet (query info 3).
590 call pxe_get_cached_info
591 call parse_dhcp
; Parse DHCP packet
594 ; Generate the bootif string, and the hardware-based config string.
599 mov cx,bootif_str_len
602 movzx cx,byte [MACLen
]
607 mov cl,1 ; CH == 0 already
613 mov [di-1],cl ; Null-terminate and strip final dash
615 ; Generate ip= option
625 call gendotquad
; This takes network byte order input
627 xchg ah,al ; Convert to host byte order
628 ror eax,16 ; (BSWAP doesn't work on 386)
645 ; Check to see if we got any PXELINUX-specific DHCP options; in particular,
646 ; if we didn't get the magic enable, do not recognize any other options.
649 test byte [DHCPMagic
], 1 ; If we didn't get the magic enable...
651 mov byte [DHCPMagic
], 0 ; If not, kill all other options
656 ; Initialize UDP stack
660 mov [pxe_udp_open_pkt.sip
],eax
661 mov di,pxe_udp_open_pkt
662 mov bx,PXENV_UDP_OPEN
665 cmp word [pxe_udp_open_pkt.status
], byte 0
667 .
failed: mov si,err_udpinit
673 ; Common initialization code
675 %include "cpuinit.inc"
678 ; Now we're all set to start with our *real* business. First load the
679 ; configuration file (if any) and parse it.
681 ; In previous versions I avoided using 32-bit registers because of a
682 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
683 ; random. I figure, though, that if there are any of those still left
684 ; they probably won't be trying to install Linux on them...
686 ; The code is still ripe with 16-bitisms, though. Not worth the hassle
687 ; to take'm out. In fact, we may want to put them back if we're going
688 ; to boot ELKS at some point.
692 ; Store standard filename prefix
694 prefix: test byte [DHCPMagic
], 04h ; Did we get a path prefix option
703 lea si,[di-2] ; Skip final null!
706 cmp al,'.' ; Count . or - as alphanum
718 .
alnum: loop .find_alnum
720 .
notalnum: mov byte [si+2],0 ; Zero-terminate after delimiter
723 mov si,tftpprefix_msg
730 ; Load configuration file
735 ; Begin looking for configuration file
738 test byte [DHCPMagic
], 02h
741 ; We got a DHCP option, try it first
751 ; Have to guess config file name...
753 ; Try loading by UUID.
754 cmp byte [HaveUUID
],0
769 mov [di-1],cl ; Remove last dash and zero-terminate
775 ; Try loading by MAC address
783 ; Nope, try hexadecimal IP prefixes...
787 call uchexbytes
; Convert to hex string
789 mov cx,8 ; Up to 8 attempts
791 mov byte [di],0 ; Zero-terminate string
794 dec di ; Drop one character
797 ; Final attempt: "default" string
798 mov si,default_str
; "default" string
826 ; Now we have the config file open. Parse the config file and
827 ; run the user interface.
832 ; Linux kernel loading code is common. However, we need to define
833 ; a couple of helper macros...
836 ; Handle "ipappend" option
837 %define HAVE_SPECIAL_APPEND
838 %macro SPECIAL_APPEND
0
839 test byte [IPAppend
],01h ; ip=
847 test byte [IPAppend
],02h
851 mov byte [es:di-1],' ' ; Replace null with space
856 %define HAVE_UNLOAD_PREP
861 %include "runkernel.inc"
864 ; COMBOOT-loading code
866 %include "comboot.inc"
868 %include "cmdline.inc"
871 ; Boot sector loading code
873 %include "bootsect.inc"
876 ; Boot to the local disk by returning the appropriate PXE magic.
877 ; AX contains the appropriate return code.
882 mov [LocalBootType
],ax
886 ; Restore the environment we were called with
893 mov ax,[cs:LocalBootType
]
903 ; kaboom: write a message and bail out. Wait for quite a while,
904 ; or a user keypress, then do a hard reboot.
907 RESET_STACK_AND_SEGS
AX
908 .
patch: mov si,bailmsg
909 call writestr
; Returns with AL = 0
910 .
drain: call pollchar
917 and al,09h ; Magic+Timeout
925 .
wait2: mov dx,[BIOS_timer
]
926 .
wait3: call pollchar
937 mov word [BIOS_magic
],0 ; Cold reboot
938 jmp 0F000h:0FFF0h
; Reset vector address
941 ; memory_scan_for_pxe_struct:
943 ; If none of the standard methods find the !PXE structure, look for it
944 ; by scanning memory.
947 ; CF = 0, ES:BX -> !PXE structure
948 ; Otherwise CF = 1, all registers saved
950 memory_scan_for_pxe_struct:
957 mov ax,[BIOS_fbm
] ; Starting segment
958 shl ax,(10-4) ; Kilobytes -> paragraphs
959 ; mov ax,01000h ; Start to look here
960 dec ax ; To skip inc ax
963 cmp ax,0A000h
; End of memory
972 movzx cx,byte [es:4] ; Length of structure
973 cmp cl,08h ; Minimum length
982 jnz .mismatch
; Checksum must == 0
985 mov [bp+8],bx ; Save BX into stack frame (will be == 0)
993 .
not_found: mov si,notfound_msg
1001 ; memory_scan_for_pxenv_struct:
1003 ; If none of the standard methods find the PXENV+ structure, look for it
1004 ; by scanning memory.
1006 ; On exit, if found:
1007 ; CF = 0, ES:BX -> PXENV+ structure
1008 ; Otherwise CF = 1, all registers saved
1010 memory_scan_for_pxenv_struct:
1012 mov si,trymempxenv_msg
1014 ; mov ax,[BIOS_fbm] ; Starting segment
1015 ; shl ax,(10-4) ; Kilobytes -> paragraphs
1016 mov ax,01000h ; Start to look here
1017 dec ax ; To skip inc ax
1020 cmp ax,0A000h
; End of memory
1029 movzx cx,byte [es:8] ; Length of structure
1030 cmp cl,26h ; Minimum length
1038 jnz .mismatch
; Checksum must == 0
1040 mov [bp+8],bx ; Save BX into stack frame
1046 .
not_found: mov si,notfound_msg
1054 ; Deallocates a file structure (pointer in SI)
1057 ; XXX: We should check to see if this file is still open on the server
1058 ; side and send a courtesy ERROR packet to the server.
1063 mov word [si],0 ; Not in use
1069 ; Open a TFTP connection to the server
1072 ; DS:DI = mangled filename
1075 ; SI = socket pointer
1076 ; DX:AX = file length in bytes
1091 call allocate_socket
1094 mov ax,PKT_RETRY
; Retry counter
1095 mov word [PktTimeout
],PKT_TIMEOUT
; Initial timeout
1097 .
sendreq: push ax ; [bp-2] - Retry counter
1098 push si ; [bp-4] - File name
1101 mov [pxe_udp_write_pkt.buffer
],di
1103 mov ax,TFTP_RRQ
; TFTP opcode
1106 lodsd ; EAX <- server override (if any)
1108 jnz .noprefix
; No prefix, and we have the server
1110 push si ; Add common prefix
1116 mov eax,[ServerIP
] ; Get default server
1119 call strcpy
; Filename
1121 mov [bx+tftp_remoteip
],eax
1123 push bx ; [bp-6] - TFTP block
1125 push bx ; [bp-8] - TID (local port no)
1127 mov [pxe_udp_write_pkt.status
],byte 0
1128 mov [pxe_udp_write_pkt.sip
],eax
1129 ; Now figure out the gateway
1135 mov [pxe_udp_write_pkt.gip
],eax
1136 mov [pxe_udp_write_pkt.lport
],bx
1138 mov [pxe_udp_write_pkt.rport
],ax
1140 mov cx,tftp_tail_len
1142 sub di,packet_buf
; Get packet size
1143 mov [pxe_udp_write_pkt.buffersize
],di
1145 mov di,pxe_udp_write_pkt
1146 mov bx,PXENV_UDP_WRITE
1149 cmp word [pxe_udp_write_pkt.status
],byte 0
1153 ; Danger, Will Robinson! We need to support timeout
1154 ; and retry lest we just lost a packet...
1157 ; Packet transmitted OK, now we need to receive
1158 .
getpacket: push word [PktTimeout
] ; [bp-10]
1159 push word [BIOS_timer
] ; [bp-12]
1161 .
pkt_loop: mov bx,[bp-8] ; TID
1163 mov word [pxe_udp_read_pkt.status
],0
1164 mov [pxe_udp_read_pkt.buffer
],di
1165 mov [pxe_udp_read_pkt.buffer
+2],ds
1166 mov word [pxe_udp_read_pkt.buffersize
],packet_buf_size
1168 mov [pxe_udp_read_pkt.dip
],eax
1169 mov [pxe_udp_read_pkt.lport
],bx
1170 mov di,pxe_udp_read_pkt
1171 mov bx,PXENV_UDP_READ
1174 jz .got_packet
; Wait for packet
1180 dec word [bp-10] ; Timeout
1182 pop ax ; Adjust stack
1184 shl word [PktTimeout
],1 ; Exponential backoff
1188 mov si,[bp-6] ; TFTP pointer
1191 mov eax,[si+tftp_remoteip
]
1192 cmp [pxe_udp_read_pkt.sip
],eax ; This is technically not to the TFTP spec?
1195 ; Got packet - reset timeout
1196 mov word [PktTimeout
],PKT_TIMEOUT
1198 pop ax ; Adjust stack
1201 mov ax,[pxe_udp_read_pkt.rport
]
1202 mov [si+tftp_remoteport
],ax
1204 ; filesize <- -1 == unknown
1205 mov dword [si+tftp_filesize
], -1
1206 ; Default blksize unless blksize option negotiated
1207 mov word [si+tftp_blksize
], TFTP_BLOCKSIZE
1209 mov cx,[pxe_udp_read_pkt.buffersize
]
1210 sub cx,2 ; CX <- bytes after opcode
1211 jb .failure
; Garbled reply
1217 je .bailnow
; ERROR reply: don't try again
1222 ; Now we need to parse the OACK packet to get the transfer
1223 ; size. SI -> first byte of options; CX -> byte count
1225 jcxz .no_tsize
; No options acked
1229 .
opt_name_loop: lodsb
1232 or al,20h ; Convert to lowercase
1235 ; We ran out, and no final null
1237 .
got_opt_name: ; si -> option value
1238 dec cx ; bytes left in pkt
1239 jz .err_reply
; Option w/o value
1241 ; Parse option pointed to by bx; guaranteed to be
1245 mov si,bx ; -> option name
1246 mov bx,tftp_opt_table
1251 mov di,[bx] ; Option pointer
1252 mov cx,[bx+2] ; Option len
1256 je .get_value
; OK, known option
1262 jmp .err_reply
; Non-negotiated option returned
1264 .
get_value: pop si ; si -> option value
1265 pop cx ; cx -> bytes left in pkt
1266 mov bx,[bx+4] ; Pointer to data target
1267 add bx,[bp-6] ; TFTP socket pointer
1275 ja .err_reply
; Not a decimal digit
1280 ; Ran out before final null, accept anyway
1285 jnz .get_opt_name
; Not end of packet
1292 pop si ; We want the packet ptr in SI
1294 mov eax,[si+tftp_filesize
]
1298 shr edx,16 ; DX:AX == EAX
1300 and eax,eax ; Set ZF depending on file size
1302 pop bp ; Junk (retry counter)
1303 jz .error_si
; ZF = 1 need to free the socket
1312 .
err_reply: ; Option negotiation error. Send ERROR reply.
1313 ; ServerIP and gateway are already programmed in
1315 mov ax,[si+tftp_remoteport
]
1316 mov word [pxe_udp_write_pkt.rport
],ax
1317 mov word [pxe_udp_write_pkt.buffer
],tftp_opt_err
1318 mov word [pxe_udp_write_pkt.buffersize
],tftp_opt_err_len
1319 mov di,pxe_udp_write_pkt
1320 mov bx,PXENV_UDP_WRITE
1323 ; Write an error message and explode
1328 .
bailnow: mov word [bp-2],1 ; Immediate error - no retry
1330 .
failure: pop bx ; Junk
1334 dec ax ; Retry counter
1335 jnz .sendreq
; Try again
1337 .
error: mov si,bx ; Socket pointer
1338 .
error_si: ; Socket pointer already in SI
1339 call free_socket
; ZF <- 1, SI <- 0
1343 ; allocate_socket: Allocate a local UDP port structure
1347 ; BX = socket pointer
1355 .
check: cmp word [bx], byte 0
1357 add bx,open_file_t_size
1362 ; Allocate a socket number. Socket numbers are made
1363 ; guaranteed unique by including the socket slot number
1364 ; (inverted, because we use the loop counter cx); add a
1365 ; counter value to keep the numbers from being likely to
1366 ; get immediately reused.
1368 ; The NextSocket variable also contains the top two bits
1369 ; set. This generates a value in the range 49152 to
1376 and ax,((1 << (13-MAX_OPEN_LG2
))-1) |
0xC000
1378 shl cx,13-MAX_OPEN_LG2
1380 xchg ch,cl ; Convert to network byte order
1381 mov [bx],cx ; Socket in use
1387 ; Free socket: socket in SI; return SI = 0, ZF = 1 for convenience
1395 mov cx,tftp_pktbuf
>> 1 ; tftp_pktbuf is not cleared
1404 ; Read a dot-quad pathname in DS:SI and output an IP
1405 ; address in EAX, with SI pointing to the first
1406 ; nonmatching character.
1408 ; Return CF=1 on error.
1422 aad ; AL += 10 * AH; AH = 0;
1437 loop .realerror
; If CX := 1 then we're done
1443 dec si ; CF unchanged!
1447 ; mangle_name: Mangle a filename pointed to by DS:SI into a buffer pointed
1448 ; to by ES:DI; ends on encountering any whitespace.
1451 ; This verifies that a filename is < FILENAME_MAX characters
1452 ; and doesn't contain whitespace, and zero-pads the output buffer,
1453 ; so "repe cmpsb" can do a compare.
1455 ; The first four bytes of the manged name is the IP address of
1456 ; the download host.
1463 je .noip
; Null filename?!?!
1464 cmp word [si],'::' ; Leading ::?
1474 ; We have a :: prefix of some sort, it could be either
1475 ; a DNS name or a dot-quad IP address. Try the dot-quad
1499 pop cx ; Adjust stack
1500 inc si ; Skip double colon
1504 stosd ; Save IP address prefix
1505 mov cx,FILENAME_MAX
-5
1509 cmp al,' ' ; If control or space, end
1514 inc cx ; At least one null byte
1515 xor ax,ax ; Zero-fill name
1516 rep stosb ; Doesn't do anything if CX=0
1521 ; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled
1522 ; filename to the conventional representation. This is needed
1523 ; for the BOOT_IMAGE= parameter for the kernel.
1524 ; NOTE: A 13-byte buffer is mandatory, even if the string is
1525 ; known to be shorter.
1527 ; DS:SI -> input mangled file name
1528 ; ES:DI -> output buffer
1530 ; On return, DI points to the first byte after the output name,
1531 ; which is set to a null byte.
1543 dec di ; Point to final null byte
1550 ; This is the main PXENV+/!PXE entry point, using the PXENV+
1551 ; calling convention. This is a separate local routine so
1552 ; we can hook special things from it if necessary. In particular,
1553 ; some PXE stacks seem to not like being invoked from anything but
1554 ; the initial stack, so humour it.
1558 %if USE_PXE_PROVIDED_STACK
== 0
1559 mov [cs:PXEStack
],sp
1560 mov [cs:PXEStack
+2],ss
1561 lss sp,[cs:InitStack
]
1563 .
jump: call 0:pxe_thunk
; Default to calling the thunk
1564 %if USE_PXE_PROVIDED_STACK
== 0
1565 lss sp,[cs:PXEStack
]
1567 cld ; Make sure DF <- 0
1570 ; Must be after function def due to NASM bug
1571 PXENVEntry
equ pxenv.jump
+1
1576 ; Convert from the PXENV+ calling convention (BX, ES, DI) to the !PXE
1577 ; calling convention (using the stack.)
1579 ; This is called as a far routine so that we can just stick it into
1580 ; the PXENVEntry variable.
1588 cmc ; Set CF unless ax == 0
1591 ; Must be after function def due to NASM bug
1592 PXEEntry
equ pxe_thunk.jump
+1
1595 ; getfssec: Get multiple clusters from a file, given the starting cluster.
1597 ; In this case, get multiple blocks from a specific TCP connection.
1601 ; SI -> TFTP socket pointer
1602 ; CX -> 512-byte block count; 0FFFFh = until end of file
1604 ; SI -> TFTP socket pointer (or 0 on EOF)
1615 shl ecx,TFTP_BLOCKSIZE_LG2
; Convert to bytes
1616 jz .hit_eof
; Nothing to do?
1621 movzx eax,word [bx+tftp_bytesleft
]
1625 jcxz .need_packet
; No bytes available?
1628 mov ax,cx ; EAX<31:16> == ECX<31:16> == 0
1629 mov si,[bx+tftp_dataptr
]
1630 sub [bx+tftp_bytesleft
],cx
1631 fs rep movsb ; Copy from packet buffer
1632 mov [bx+tftp_dataptr
],si
1643 ; Is there anything left of this?
1644 mov eax,[si+tftp_filesize
]
1645 sub eax,[si+tftp_filepos
]
1646 jnz .bytes_left
; CF <- 0
1648 cmp [si+tftp_bytesleft
],ax
1649 jnz .bytes_left
; CF <- 0
1651 ; The socket is closed and the buffer drained
1652 ; Close socket structure and re-init for next user
1659 ; No data in buffer, check to see if we can get a packet...
1663 mov eax,[bx+tftp_filesize
]
1664 cmp eax,[bx+tftp_filepos
]
1665 je .hit_eof
; Already EOF'd; socket already closed
1677 ; Get a fresh packet; expects fs -> pktbuf_seg and ds:si -> socket structure
1684 ; Start by ACKing the previous packet; this should cause the
1685 ; next packet to be sent.
1687 mov word [PktTimeout
],PKT_TIMEOUT
1689 .
send_ack: push cx ; <D> Retry count
1691 mov ax,[si+tftp_lastpkt
]
1692 call ack_packet
; Send ACK
1694 ; We used to test the error code here, but sometimes
1695 ; PXE would return negative status even though we really
1696 ; did send the ACK. Now, just treat a failed send as
1697 ; a normally lost packet, and let it time out in due
1700 .
send_ok: ; Now wait for packet.
1701 mov dx,[BIOS_timer
] ; Get current time
1704 .
wait_data: push cx ; <E> Timeout
1705 push dx ; <F> Old time
1707 mov bx,[si+tftp_pktbuf
]
1708 mov [pxe_udp_read_pkt.buffer
],bx
1709 mov [pxe_udp_read_pkt.buffer
+2],fs
1710 mov [pxe_udp_read_pkt.buffersize
],word PKTBUF_SIZE
1711 mov eax,[si+tftp_remoteip
]
1712 mov [pxe_udp_read_pkt.sip
],eax
1714 mov [pxe_udp_read_pkt.dip
],eax
1715 mov ax,[si+tftp_remoteport
]
1716 mov [pxe_udp_read_pkt.rport
],ax
1717 mov ax,[si+tftp_localport
]
1718 mov [pxe_udp_read_pkt.lport
],ax
1719 mov di,pxe_udp_read_pkt
1720 mov bx,PXENV_UDP_READ
1727 ; No packet, or receive failure
1729 pop ax ; <F> Old time
1730 pop cx ; <E> Timeout
1731 cmp ax,dx ; Same time -> don't advance timeout
1732 je .wait_data
; Same clock tick
1733 loop .wait_data
; Decrease timeout
1735 pop cx ; <D> Didn't get any, send another ACK
1736 shl word [PktTimeout
],1 ; Exponential backoff
1738 jmp kaboom
; Forget it...
1740 .
recv_ok: pop dx ; <F>
1743 cmp word [pxe_udp_read_pkt.buffersize
],byte 4
1744 jb .wait_data
; Bad size for a DATA packet
1746 mov bx,[si+tftp_pktbuf
]
1747 cmp word [fs:bx],TFTP_DATA
; Not a data packet?
1748 jne .wait_data
; Then wait for something else
1750 mov ax,[si+tftp_lastpkt
]
1751 xchg ah,al ; Host byte order
1752 inc ax ; Which packet are we waiting for?
1753 xchg ah,al ; Network byte order
1757 ; Wrong packet, ACK the packet and then try again
1758 ; This is presumably because the ACK got lost,
1759 ; so the server just resent the previous packet
1762 jmp .send_ok
; Reset timeout
1764 .
right_packet: ; It's the packet we want. We're also EOF if the size < blocksize
1766 pop cx ; <D> Don't need the retry count anymore
1768 mov [si+tftp_lastpkt
],ax ; Update last packet number
1770 movzx ecx,word [pxe_udp_read_pkt.buffersize
]
1771 sub cx,byte 4 ; Skip TFTP header
1773 ; If this is a zero-length block, don't mess with the pointers,
1774 ; since we may have just set up the previous block that way
1777 ; Set pointer to data block
1778 lea ax,[bx+4] ; Data past TFTP header
1779 mov [si+tftp_dataptr
],ax
1781 add [si+tftp_filepos
],ecx
1782 mov [si+tftp_bytesleft
],cx
1784 cmp cx,[si+tftp_blksize
] ; Is it a full block?
1785 jb .last_block
; If so, it's not EOF
1787 ; If we had the exact right number of bytes, always get
1788 ; one more packet to get the (zero-byte) EOF packet and
1790 mov eax,[si+tftp_filepos
]
1791 cmp [si+tftp_filesize
],eax
1797 .
last_block: ; Last block - ACK packet immediately
1801 ; Make sure we know we are at end of file
1802 mov eax,[si+tftp_filepos
]
1803 mov [si+tftp_filesize
],eax
1810 ; Send ACK packet. This is a common operation and so is worth canning.
1814 ; AX = Packet # to ack (network byte order)
1817 ; All registers preserved
1819 ; This function uses the pxe_udp_write_pkt but not the packet_buf.
1823 mov [ack_packet_buf
+2],ax ; Packet number to ack
1825 mov [pxe_udp_write_pkt.lport
],ax
1826 mov ax,[si+tftp_remoteport
]
1827 mov [pxe_udp_write_pkt.rport
],ax
1828 mov eax,[si+tftp_remoteip
]
1829 mov [pxe_udp_write_pkt.sip
],eax
1835 mov [pxe_udp_write_pkt.gip
],eax
1836 mov [pxe_udp_write_pkt.buffer
],word ack_packet_buf
1837 mov [pxe_udp_write_pkt.buffersize
], word 4
1838 mov di,pxe_udp_write_pkt
1839 mov bx,PXENV_UDP_WRITE
1841 cmp ax,byte 0 ; ZF = 1 if write OK
1848 ; This function unloads the PXE and UNDI stacks and unclaims
1852 test byte [KeepPXE
],01h ; Should we keep PXE around?
1862 mov si,new_api_unload
1863 cmp byte [APIVer
+1],2 ; Major API version >= 2?
1865 mov si,old_api_unload
1868 .
call_loop: xor ax,ax
1873 mov di,pxe_unload_stack_pkt
1876 mov cx,pxe_unload_stack_pkt_len
>> 1
1881 mov ax,word [pxe_unload_stack_pkt.status
]
1882 cmp ax,PXENV_STATUS_SUCCESS
1889 mov dx,[RealBaseMem
]
1890 cmp dx,[BIOS_fbm
] ; Sanity check
1894 ; Check that PXE actually unhooked the INT 1Ah chain
1895 movzx eax,word [4*0x1a]
1896 movzx ecx,word [4*0x1a+2]
1900 cmp ax,dx ; Not in range
1914 mov si,cant_free_msg
1930 ; We want to keep PXE around, but still we should reset
1931 ; it to the standard bootup configuration
1936 mov bx,PXENV_UDP_CLOSE
1937 mov di,pxe_udp_close_pkt
1945 ; Take an IP address (in network byte order) in EAX and
1946 ; output a dotted quad string to ES:DI.
1947 ; DI points to terminal null at end of string on exit.
1956 jb .lt10
; If so, skip first 2 digits
1959 jb .lt100
; If so, skip first digit
1962 ; Now AH = 100-digit; AL = remainder
1969 ; Now AH = 10-digit; AL = remainder
1980 ror eax,8 ; Move next char into LSB
1988 ; uchexbytes/lchexbytes
1990 ; Take a number of bytes in memory and convert to upper/lower-case
1994 ; DS:SI = input bytes
1995 ; ES:DI = output buffer
1996 ; CX = number of bytes
1998 ; DS:SI = first byte after
1999 ; ES:DI = first byte after
2031 ; pxe_get_cached_info
2033 ; Get a DHCP packet from the PXE stack into the trackbuf.
2040 ; Assumes CS == DS == ES.
2042 pxe_get_cached_info:
2044 mov di,pxe_bootp_query_pkt
2053 stosw ; Buffer offset
2055 stosw ; Buffer segment
2057 pop di ; DI -> parameter set
2058 mov bx,PXENV_GET_CACHED_INFO
2065 mov cx,[pxe_bootp_query_pkt.buffersize
]
2069 mov si,err_pxefailed
2075 ; Parse a DHCP packet. This includes dealing with "overloaded"
2076 ; option fields (see RFC 2132, section 9.3)
2078 ; This should fill in the following global variables, if the
2079 ; information is present:
2081 ; MyIP - client IP address
2082 ; ServerIP - boot server IP address
2083 ; Netmask - network mask
2084 ; Gateway - default gateway router IP
2085 ; BootFile - boot file name
2086 ; DNSServers - DNS server IPs
2087 ; LocalDomain - Local domain name
2088 ; MACLen, MAC - Client identifier, if MACLen == 0
2090 ; This assumes the DHCP packet is in "trackbuf" and the length
2091 ; of the packet in in CX on entry.
2095 mov byte [OverLoad
],0 ; Assume no overload
2096 mov eax, [trackbuf
+bootp.yip
]
2099 cmp al,224 ; Class D or higher -> bad
2103 mov eax, [trackbuf
+bootp.sip
]
2106 cmp al,224 ; Class D or higher -> bad
2110 sub cx, bootp.options
2112 mov si, trackbuf
+bootp.option_magic
2114 cmp eax, BOOTP_OPTION_MAGIC
2116 call parse_dhcp_options
2118 mov si, trackbuf
+bootp.bootfile
2119 test byte [OverLoad
],1
2122 call parse_dhcp_options
2123 jmp short .parsed_file
2126 jz .parsed_file
; No bootfile name
2131 stosb ; Null-terminate
2133 mov si, trackbuf
+bootp.sname
2134 test byte [OverLoad
],2
2137 call parse_dhcp_options
2142 ; Parse a sequence of DHCP options, pointed to by DS:SI; the field
2143 ; size is CX -- some DHCP servers leave option fields unterminated
2144 ; in violation of the spec.
2146 ; For parse_some_dhcp_options, DH contains the minimum value for
2147 ; the option to recognize -- this is used to restrict parsing to
2148 ; PXELINUX-specific options only.
2153 parse_some_dhcp_options:
2160 jz .done
; Last byte; must be PAD, END or malformed
2161 cmp al, 0 ; PAD option
2163 cmp al,255 ; END option
2166 ; Anything else will have a length field
2167 mov dl,al ; DL <- option number
2169 lodsb ; AX <- option length
2171 sub cx,ax ; Decrement bytes left counter
2172 jb .done
; Malformed option: length > field size
2174 cmp dl,dh ; Is the option value valid?
2177 mov bx,dhcp_option_list
2179 cmp bx,dhcp_option_list_end
2191 ; Unknown option. Skip to the next one.
2211 ; Parse individual DHCP options. SI points to the option data and
2212 ; AX to the option length. DL contains the option number.
2213 ; All registers are saved around the routine.
2228 cmp cl,DNS_MAX_SERVERS
2230 mov cl,DNS_MAX_SERVERS
2234 mov [LastDNSServer
],di
2237 dopt
16, local_domain
2241 xchg [bx],al ; Zero-terminate option
2243 call dns_mangle
; Convert to DNS label set
2244 mov [bx],al ; Restore ending byte
2247 dopt
43, vendor_encaps
2248 mov dh,208 ; Only recognize PXELINUX options
2249 mov cx,ax ; Length of option = max bytes to parse
2250 call parse_some_dhcp_options
; Parse recursive structure
2253 dopt
52, option_overload
2258 dopt
61, client_identifier
2259 cmp ax,MAC_MAX
; Too long?
2261 cmp ax,2 ; Too short?
2263 cmp [MACLen
],ah ; Only do this if MACLen == 0
2266 lodsb ; Client identifier type
2269 jne .skip
; Client identifier is not a MAC
2276 dopt
64, bootfile_name
2280 dopt
97, uuid_client_identifier
2281 cmp ax,17 ; type byte + 16 bytes UUID
2283 mov dl,[si] ; Must have type 0 == UUID
2284 or dl,[HaveUUID
] ; Capture only the first instance
2286 mov byte [HaveUUID
],1 ; Got UUID
2291 dopt
208, pxelinux_magic
2292 cmp al,4 ; Must have length == 4
2294 cmp dword [si], htonl
(0xF100747E) ; Magic number
2296 or byte [DHCPMagic
],1 ; Found magic #
2299 dopt
209, pxelinux_configfile
2301 or byte [DHCPMagic
],2 ; Got config file
2304 dopt
210, pxelinux_pathprefix
2306 or byte [DHCPMagic
],4 ; Got path prefix
2309 dopt
211, pxelinux_reboottime
2313 xchg bl,bh ; Convert to host byte order
2316 mov [RebootTime
],ebx
2317 or byte [DHCPMagic
],8 ; Got RebootTime
2320 ; Common code for copying an option verbatim
2321 ; Copies the option into ES:DI and null-terminates it.
2322 ; Returns with AX=0 and SI past the option.
2324 xchg cx,ax ; CX <- option length
2326 xchg cx,ax ; AX <- 0
2327 stosb ; Null-terminate
2331 dhcp_option_list_end:
2336 uuid_dashes
db 4,2,2,2,6,0 ; Bytes per UUID dashed section
2342 ; Generate an ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
2343 ; option into IPOption based on a DHCP packet in trackbuf.
2344 ; Assumes CS == DS == ES.
2365 call gendotquad
; Zero-terminates its output
2367 mov [IPOptionLen
],di
2372 ; Call the receive loop while idle. This is done mostly so we can respond to
2373 ; ARP messages, but perhaps in the future this can be used to do network
2376 ; hpa sez: people using automatic control on the serial port get very
2377 ; unhappy if we poll for ARP too often (the PXE stack is pretty slow,
2378 ; typically.) Therefore, only poll if at least 4 BIOS timer ticks have
2379 ; passed since the last poll, and reset this when a character is
2380 ; received (RESET_IDLE).
2386 mov ax,[cs:BIOS_timer
]
2387 mov [cs:IdleTimer
],ax
2393 mov ax,[cs:BIOS_timer
]
2394 sub ax,[cs:IdleTimer
]
2406 mov [pxe_udp_read_pkt.status
],al ; 0
2407 mov [pxe_udp_read_pkt.buffer
],di
2408 mov [pxe_udp_read_pkt.buffer
+2],ds
2409 mov word [pxe_udp_read_pkt.buffersize
],packet_buf_size
2411 mov [pxe_udp_read_pkt.dip
],eax
2412 mov word [pxe_udp_read_pkt.lport
],htons
(9) ; discard port
2413 mov di,pxe_udp_read_pkt
2414 mov bx,PXENV_UDP_READ
2425 ; -----------------------------------------------------------------------------
2427 ; -----------------------------------------------------------------------------
2429 %include "getc.inc" ; getc et al
2430 %include "conio.inc" ; Console I/O
2431 %include "writestr.inc" ; String output
2432 writestr
equ cwritestr
2433 %include "writehex.inc" ; Hexadecimal output
2434 %include "configinit.inc" ; Initialize configuration
2435 %include "parseconfig.inc" ; High-level config file handling
2436 %include "parsecmd.inc" ; Low-level config file handling
2437 %include "bcopy32.inc" ; 32-bit bcopy
2438 %include "loadhigh.inc" ; Load a file into high memory
2439 %include "font.inc" ; VGA font stuff
2440 %include "graphics.inc" ; VGA graphics
2441 %include "highmem.inc" ; High memory sizing
2442 %include "strcpy.inc" ; strcpy()
2443 %include "rawcon.inc" ; Console I/O w/o using the console functions
2444 %include "dnsresolv.inc" ; DNS resolver
2446 ; -----------------------------------------------------------------------------
2447 ; Begin data section
2448 ; -----------------------------------------------------------------------------
2452 copyright_str
db ' Copyright (C) 1994-', year
, ' H. Peter Anvin'
2454 boot_prompt
db 'boot: ', 0
2455 wipe_char
db BS
, ' ', BS
, 0
2456 err_notfound
db 'Could not find kernel image: ',0
2457 err_notkernel
db CR
, LF
, 'Invalid or corrupt kernel image.', CR
, LF
, 0
2458 err_noram
db 'It appears your computer has less than '
2460 db 'K of low ("DOS")'
2462 db 'RAM. Linux needs at least this amount to boot. If you get'
2464 db 'this message in error, hold down the Ctrl key while'
2466 db 'booting, and I will take your word for it.', CR
, LF
, 0
2467 err_badcfg
db 'Unknown keyword in config file.', CR
, LF
, 0
2468 err_noparm
db 'Missing parameter in config file.', CR
, LF
, 0
2469 err_noinitrd
db CR
, LF
, 'Could not find ramdisk image: ', 0
2470 err_nohighmem
db 'Not enough memory to load specified kernel.', CR
, LF
, 0
2471 err_highload
db CR
, LF
, 'Kernel transfer failure.', CR
, LF
, 0
2472 err_oldkernel
db 'Cannot load a ramdisk with an old kernel image.'
2474 err_notdos
db ': attempted DOS system call', CR
, LF
, 0
2475 err_comlarge
db 'COMBOOT image too large.', CR
, LF
, 0
2476 err_a20
db CR
, LF
, 'A20 gate not responding!', CR
, LF
, 0
2477 err_bootfailed
db CR
, LF
, 'Boot failed: press a key to retry, or wait for reset...', CR
, LF
, 0
2478 bailmsg
equ err_bootfailed
2479 err_nopxe
db "No !PXE or PXENV+ API found; we're dead...", CR
, LF
, 0
2480 err_pxefailed
db 'PXE API call failed, error ', 0
2481 err_udpinit
db 'Failed to initialize UDP stack', CR
, LF
, 0
2482 err_noconfig
db 'Unable to locate configuration file', CR
, LF
, 0
2483 err_oldtftp
db 'TFTP server does not support the tsize option', CR
, LF
, 0
2484 found_pxenv
db 'Found PXENV+ structure', CR
, LF
, 0
2485 using_pxenv_msg
db 'Old PXE API detected, using PXENV+ structure', CR
, LF
, 0
2486 apiver_str
db 'PXE API version is ',0
2487 pxeentry_msg
db 'PXE entry point found (we hope) at ', 0
2488 pxenventry_msg
db 'PXENV entry point found (we hope) at ', 0
2489 trymempxe_msg
db 'Scanning memory for !PXE structure... ', 0
2490 trymempxenv_msg
db 'Scanning memory for PXENV+ structure... ', 0
2491 undi_data_msg
db 'UNDI data segment at: ',0
2492 undi_data_len_msg
db 'UNDI data segment size: ',0
2493 undi_code_msg
db 'UNDI code segment at: ',0
2494 undi_code_len_msg
db 'UNDI code segment size: ',0
2495 cant_free_msg
db 'Failed to free base memory, error ', 0
2496 notfound_msg
db 'not found', CR
, LF
, 0
2497 myipaddr_msg
db 'My IP address seems to be ',0
2498 tftpprefix_msg
db 'TFTP prefix: ', 0
2499 localboot_msg
db 'Booting from local disk...', CR
, LF
, 0
2500 cmdline_msg
db 'Command line: ', CR
, LF
, 0
2501 ready_msg
db 'Ready.', CR
, LF
, 0
2502 trying_msg
db 'Trying to load: ', 0
2503 crlfloading_msg
db CR
, LF
; Fall through
2504 loading_msg
db 'Loading ', 0
2507 fourbs_msg
db BS
, BS
, BS
, BS
, 0
2508 aborted_msg
db ' aborted.' ; Fall through to crlf_msg!
2511 crff_msg
db CR
, FF
, 0
2512 default_str
db 'default', 0
2513 syslinux_banner
db CR
, LF
, 'PXELINUX ', version_str
, ' ', date
, ' ', 0
2514 cfgprefix
db 'pxelinux.cfg/' ; No final null!
2515 cfgprefix_len
equ ($
-cfgprefix
)
2518 ; Command line options we'd like to take a look at
2520 ; mem= and vga= are handled as normal 32-bit integer values
2521 initrd_cmd
db 'initrd='
2522 initrd_cmd_len
equ $
-initrd_cmd
2524 ; This one we make ourselves
2525 bootif_str
db 'BOOTIF='
2526 bootif_str_len
equ $
-bootif_str
2528 ; Config file keyword table
2530 %include "keywords.inc"
2533 ; Extensions to search for (in *forward* order).
2534 ; (.bs and .bss are disabled for PXELINUX, since they are not supported)
2537 exten_table: db '.cbt' ; COMBOOT (specific)
2538 db '.0', 0, 0 ; PXE bootstrap program
2539 db '.com' ; COMBOOT (same as DOS)
2542 dd 0, 0 ; Need 8 null bytes here
2545 ; PXE unload sequences
2549 db PXENV_UNDI_SHUTDOWN
2550 db PXENV_UNLOAD_STACK
2555 db PXENV_UNDI_SHUTDOWN
2556 db PXENV_UNLOAD_STACK
2557 db PXENV_UNDI_CLEANUP
2561 ; PXE query packets partially filled in
2564 pxe_bootp_query_pkt:
2565 .
status: resw
1 ; Status
2566 .
packettype: resw
1 ; Boot server packet type
2567 .
buffersize: resw
1 ; Packet size
2568 .
buffer: resw
2 ; seg:off of buffer
2569 .
bufferlimit: resw
1 ; Unused
2573 .
status: dw 0 ; Status
2574 .
sip: dd 0 ; Source (our) IP
2577 .
status: dw 0 ; Status
2580 .
status: dw 0 ; Status
2581 .
sip: dd 0 ; Server IP
2582 .
gip: dd 0 ; Gateway IP
2583 .
lport: dw 0 ; Local port
2584 .
rport: dw 0 ; Remote port
2585 .
buffersize: dw 0 ; Size of packet
2586 .
buffer: dw 0, 0 ; seg:off of buffer
2589 .
status: dw 0 ; Status
2590 .
sip: dd 0 ; Source IP
2591 .
dip: dd 0 ; Destination (our) IP
2592 .
rport: dw 0 ; Remote port
2593 .
lport: dw 0 ; Local port
2594 .
buffersize: dw 0 ; Max packet size
2595 .
buffer: dw 0, 0 ; seg:off of buffer
2598 ; Misc initialized (data) variables
2601 BaseStack
dd StackBuf
; ESP of base stack
2602 dw 0 ; SS of base stack
2603 NextSocket
dw 49152 ; Counter for allocating socket numbers
2604 KeepPXE
db 0 ; Should PXE be kept around?
2609 tftp_tail
db 'octet', 0 ; Octet mode
2610 tsize_str
db 'tsize' ,0 ; Request size
2611 tsize_len
equ ($
-tsize_str
)
2613 blksize_str
db 'blksize', 0 ; Request large blocks
2614 blksize_len
equ ($
-blksize_str
)
2615 asciidec TFTP_LARGEBLK
2617 tftp_tail_len
equ ($
-tftp_tail
)
2621 ; Options negotiation parsing table (string pointer, string len, offset
2622 ; into socket structure)
2625 dw tsize_str
, tsize_len
, tftp_filesize
2626 dw blksize_str
, blksize_len
, tftp_blksize
2627 tftp_opts
equ ($
-tftp_opt_table
)/6
2630 ; Error packet to return on options negotiation error
2632 tftp_opt_err
dw TFTP_ERROR
; ERROR packet
2633 dw TFTP_EOPTNEG
; ERROR 8: bad options
2634 db 'tsize option required', 0 ; Error message
2635 tftp_opt_err_len
equ ($
-tftp_opt_err
)
2638 ack_packet_buf: dw TFTP_ACK
, 0 ; TFTP ACK packet
2641 ; IP information (initialized to "unknown" values)
2642 MyIP
dd 0 ; My IP address
2643 ServerIP
dd 0 ; IP address of boot server
2644 Netmask
dd 0 ; Netmask of this subnet
2645 Gateway
dd 0 ; Default router
2646 ServerPort
dw TFTP_PORT
; TFTP server port
2649 ; Variables that are uninitialized in SYSLINUX but initialized here
2652 BufSafe
dw trackbufsize
/TFTP_BLOCKSIZE
; Clusters we can load into trackbuf
2653 BufSafeSec
dw trackbufsize
/512 ; = how many sectors?
2654 BufSafeBytes
dw trackbufsize
; = how many bytes?
2655 EndOfGetCBuf
dw getcbuf
+trackbufsize
; = getcbuf+BufSafeBytes
2657 %if
( trackbufsize
% TFTP_BLOCKSIZE
) != 0
2658 %error trackbufsize must be a multiple of TFTP_BLOCKSIZE