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-2008 H. Peter Anvin - All Rights Reserved
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 in high memory 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 3000h
123 pktbuf_seg equ 2000h ; Packet buffers segments
124 xfer_buf_seg equ 1000h ; Bounce buffer for I/O to high mem
125 comboot_seg equ real_mode_seg ; COMBOOT image loading zone
128 ; BOOTP/DHCP packet pattern
132 .opcode resb 1 ; BOOTP/DHCP "opcode"
133 .hardware resb 1 ; ARP hardware type
134 .hardlen resb 1 ; Hardware address length
135 .gatehops resb 1 ; Used by forwarders
136 .ident resd 1 ; Transaction ID
137 .seconds resw 1 ; Seconds elapsed
138 .flags resw 1 ; Broadcast flags
139 .cip resd 1 ; Client IP
140 .yip resd 1 ; "Your" IP
141 .sip resd 1 ; Next server IP
142 .gip resd 1 ; Relay agent IP
143 .macaddr resb 16 ; Client MAC address
144 .sname resb 64 ; Server name (optional)
145 .bootfile resb 128 ; Boot file name
146 .option_magic resd 1 ; Vendor option magic cookie
147 .options resb 1260 ; Vendor options
150 BOOTP_OPTION_MAGIC equ htonl(0x63825363) ; See RFC 2132
153 ; TFTP connection data structure. Each one of these corresponds to a local
154 ; UDP port. The size of this structure must be a power of 2.
155 ; HBO = host byte order; NBO = network byte order
156 ; (*) = written by options negotiation code, must be dword sized
159 tftp_localport resw 1 ; Local port number (0 = not in use)
160 tftp_remoteport resw 1 ; Remote port number
161 tftp_remoteip resd 1 ; Remote IP address
162 tftp_filepos resd 1 ; Bytes downloaded (including buffer)
163 tftp_filesize resd 1 ; Total file size(*)
164 tftp_blksize resd 1 ; Block size for this connection(*)
165 tftp_bytesleft resw 1 ; Unclaimed data bytes
166 tftp_lastpkt resw 1 ; Sequence number of last packet (NBO)
167 tftp_dataptr resw 1 ; Pointer to available data
168 tftp_goteof resb 1 ; 1 if the EOF packet received
169 resb 3 ; 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
191 alignb open_file_t_size
192 Files resb MAX_OPEN*open_file_t_size
195 BootFile resb 256 ; Boot file from DHCP packet
196 PathPrefix resb 256 ; Path prefix derived from boot file
197 DotQuadBuf resb 16 ; Buffer for dotted-quad IP address
198 IPOption resb 80 ; ip= option buffer
199 InitStack resd 1 ; Pointer to reset stack (SS:SP)
200 PXEStack resd 1 ; Saved stack during PXE call
204 RebootTime resd 1 ; Reboot timeout, if set by option
205 StrucPtr resd 1 ; Pointer to PXENV+ or !PXE structure
206 APIVer resw 1 ; PXE API version found
207 IPOptionLen resw 1 ; Length of IPOption
208 IdleTimer resw 1 ; Time to check for ARP?
209 LocalBootType resw 1 ; Local boot return code
210 PktTimeout resw 1 ; Timeout for current packet
211 RealBaseMem resw 1 ; Amount of DOS memory after freeing
212 OverLoad resb 1 ; Set if DHCP packet uses "overloading"
213 DHCPMagic resb 1 ; PXELINUX magic flags
215 ; The relative position of these fields matter!
216 MAC_MAX equ 32 ; Handle hardware addresses this long
217 MACLen resb 1 ; MAC address len
218 MACType resb 1 ; MAC address type
219 MAC resb MAC_MAX+1 ; Actual MAC address
220 BOOTIFStr resb 7 ; Space for "BOOTIF="
221 MACStr resb 3*(MAC_MAX+1) ; MAC address as a string
223 ; The relative position of these fields matter!
224 UUIDType resb 1 ; Type byte from DHCP option
225 UUID resb 16 ; UUID, from the PXE stack
226 UUIDNull resb 1 ; dhcp_copyoption zero-terminates
229 ; PXE packets which don't need static initialization
232 pxe_unload_stack_pkt:
233 .status: resw 1 ; Status
234 .reserved: resw 10 ; Reserved
235 pxe_unload_stack_pkt_len equ $-pxe_unload_stack_pkt
238 ; BOOTP/DHCP packet buffer
242 packet_buf resb 2048 ; Transfer packet
243 packet_buf_size equ $-packet_buf
247 ; PXELINUX needs more BSS than the other derivatives;
248 ; therefore we relocate it from 7C00h on startup.
250 StackBuf equ $ ; Base of stack if we use our own
253 ; Primary entry point.
257 pushfd ; Paranoia... in case of return to PXE
258 pushad ; ... save as much state as possible
269 %if TEXT_START != 0x7c00
270 ; This is uglier than it should be, but works around
271 ; some NASM 0.98.38 bugs.
272 mov di,section..bcopy32.start
273 add di,__bcopy_size-4
274 lea si,[di-(TEXT_START-7C00h)]
275 lea cx,[di-(TEXT_START-4)]
277 std ; Overlapping areas, copy backwards
281 jmp 0:_start1 ; Canonicalize address
284 les bx,[bp+48] ; ES:BX -> !PXE or PXENV+ structure
286 ; That is all pushed onto the PXE stack. Save the pointer
287 ; to it and switch to an internal stack.
291 %if USE_PXE_PROVIDED_STACK
292 ; Apparently some platforms go bonkers if we
293 ; set up our own stack...
301 sti ; Stack set up and ready
305 ; Initialize screen (if we're using one)
307 push es ; Save ES -> PXE entry structure
311 pop es ; Restore ES -> PXE entry structure
313 ; Tell the user we got this far
315 mov si,syslinux_banner
322 ; Assume API version 2.1, in case we find the !PXE structure without
323 ; finding the PXENV+ structure. This should really look at the Base
324 ; Code ROM ID structure in have_pxe, but this is adequate for now --
325 ; if we have !PXE, we have to be 2.1 or higher, and we don't care
326 ; about higher versions than that.
328 mov word [APIVer],0201h
331 ; Now we need to find the !PXE structure. It's *supposed* to be pointed
332 ; to by SS:[SP+4], but support INT 1Ah, AX=5650h method as well.
333 ; FIX: ES:BX should point to the PXENV+ structure on entry as well.
334 ; We should make that the second test, and not trash ES:BX...
336 cmp dword [es:bx], '!PXE'
339 ; Uh-oh, not there... try plan B
341 %if USE_PXE_PROVIDED_STACK == 0
344 int 1Ah ; May trash regs
345 %if USE_PXE_PROVIDED_STACK == 0
353 ; Okay, that gave us the PXENV+ structure, find !PXE
354 ; structure from that (if available)
355 cmp dword [es:bx], 'PXEN'
357 cmp word [es:bx+4], 'V+'
360 ; Nothing there either. Last-ditch: scan memory
361 call memory_scan_for_pxe_struct ; !PXE scan
363 call memory_scan_for_pxenv_struct ; PXENV+ scan
366 no_pxe: mov si,err_nopxe
384 cmp ax,0201h ; API version 2.1 or higher
388 les bx,[es:bx+28h] ; !PXE structure pointer
389 cmp dword [es:bx],'!PXE'
392 ; Nope, !PXE structure missing despite API 2.1+, or at least
393 ; the pointer is missing. Do a last-ditch attempt to find it.
394 call memory_scan_for_pxe_struct
397 ; Otherwise, no dice, use PXENV+ structure
401 old_api: ; Need to use a PXENV+ structure
402 mov si,using_pxenv_msg
405 mov eax,[es:bx+0Ah] ; PXE RM API
413 mov si,undi_data_len_msg
423 mov si,undi_code_len_msg
429 ; Compute base memory size from PXENV+ structure
431 movzx eax,word [es:bx+20h] ; UNDI data seg
432 cmp ax,[es:bx+24h] ; UNDI code seg
442 shr eax,10 ; Convert to kilobytes
445 mov si,pxenventry_msg
447 mov ax,[PXENVEntry+2]
468 mov si,undi_data_len_msg
478 mov si,undi_code_len_msg
484 ; Compute base memory size from !PXE structure
511 pop es ; Restore CS == DS == ES
514 ; Network-specific initialization
517 mov [LocalDomain],al ; No LocalDomain received
520 ; The DHCP client identifiers are best gotten from the DHCPREQUEST
521 ; packet (query info 1).
525 call pxe_get_cached_info
528 ; We don't use flags from the request packet, so
529 ; this is a good time to initialize DHCPMagic...
530 ; Initialize it to 1 meaning we will accept options found;
531 ; in earlier versions of PXELINUX bit 0 was used to indicate
532 ; we have found option 208 with the appropriate magic number;
533 ; we no longer require that, but MAY want to re-introduce
534 ; it in the future for vendor encapsulated options.
535 mov byte [DHCPMagic],1
538 ; Now attempt to get the BOOTP/DHCP packet that brought us life (and an IP
539 ; address). This lives in the DHCPACK packet (query info 2).
543 call pxe_get_cached_info
544 call parse_dhcp ; Parse DHCP packet
546 ; Save away MAC address (assume this is in query info 2. If this
547 ; turns out to be problematic it might be better getting it from
548 ; the query info 1 packet.)
551 movzx cx,byte [trackbuf+bootp.hardlen]
554 xor cx,cx ; Bad hardware address length
557 mov al,[trackbuf+bootp.hardware]
559 mov si,trackbuf+bootp.macaddr
563 ; Enable this if we really need to zero-pad this field...
564 ; mov cx,MAC+MAC_MAX+1
570 ; Now, get the boot file and other info. This lives in the CACHED_REPLY
571 ; packet (query info 3).
574 call pxe_get_cached_info
575 call parse_dhcp ; Parse DHCP packet
578 ; Generate the bootif string, and the hardware-based config string.
583 mov cx,bootif_str_len
586 movzx cx,byte [MACLen]
591 mov cl,1 ; CH == 0 already
597 mov [di-1],cl ; Null-terminate and strip final dash
599 ; Generate ip= option
609 call gendotquad ; This takes network byte order input
611 xchg ah,al ; Convert to host byte order
612 ror eax,16 ; (BSWAP doesn't work on 386)
629 ; Check to see if we got any PXELINUX-specific DHCP options; in particular,
630 ; if we didn't get the magic enable, do not recognize any other options.
633 test byte [DHCPMagic], 1 ; If we didn't get the magic enable...
635 mov byte [DHCPMagic], 0 ; If not, kill all other options
640 ; Initialize UDP stack
644 mov [pxe_udp_open_pkt.sip],eax
645 mov di,pxe_udp_open_pkt
646 mov bx,PXENV_UDP_OPEN
649 cmp word [pxe_udp_open_pkt.status], byte 0
651 .failed: mov si,err_udpinit
657 ; Common initialization code
659 %include "cpuinit.inc"
662 ; Now we're all set to start with our *real* business. First load the
663 ; configuration file (if any) and parse it.
665 ; In previous versions I avoided using 32-bit registers because of a
666 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
667 ; random. I figure, though, that if there are any of those still left
668 ; they probably won't be trying to install Linux on them...
670 ; The code is still ripe with 16-bitisms, though. Not worth the hassle
671 ; to take'm out. In fact, we may want to put them back if we're going
672 ; to boot ELKS at some point.
676 ; Store standard filename prefix
678 prefix: test byte [DHCPMagic], 04h ; Did we get a path prefix option
687 lea si,[di-2] ; Skip final null!
690 cmp al,'.' ; Count . or - as alphanum
702 .alnum: loop .find_alnum
704 .notalnum: mov byte [si+2],0 ; Zero-terminate after delimiter
707 mov si,tftpprefix_msg
714 ; Load configuration file
719 ; Begin looking for configuration file
722 test byte [DHCPMagic], 02h
725 ; We got a DHCP option, try it first
735 ; Have to guess config file name...
737 ; Try loading by UUID.
738 cmp byte [HaveUUID],0
753 mov [di-1],cl ; Remove last dash and zero-terminate
759 ; Try loading by MAC address
767 ; Nope, try hexadecimal IP prefixes...
771 call uchexbytes ; Convert to hex string
773 mov cx,8 ; Up to 8 attempts
775 mov byte [di],0 ; Zero-terminate string
778 dec di ; Drop one character
781 ; Final attempt: "default" string
782 mov si,default_str ; "default" string
800 mov di,KernelName ; Borrow this buffer for mangled name
810 ; Linux kernel loading code is common. However, we need to define
811 ; a couple of helper macros...
814 ; Handle "ipappend" option
815 %define HAVE_SPECIAL_APPEND
816 %macro SPECIAL_APPEND 0
817 test byte [IPAppend],01h ; ip=
825 test byte [IPAppend],02h
829 mov byte [es:di-1],' ' ; Replace null with space
834 %define HAVE_UNLOAD_PREP
840 ; Now we have the config file open. Parse the config file and
841 ; run the user interface.
846 ; Boot to the local disk by returning the appropriate PXE magic.
847 ; AX contains the appropriate return code.
852 mov [LocalBootType],ax
856 ; Restore the environment we were called with
863 mov ax,[cs:LocalBootType]
868 ; kaboom: write a message and bail out. Wait for quite a while,
869 ; or a user keypress, then do a hard reboot.
872 RESET_STACK_AND_SEGS AX
873 .patch: mov si,bailmsg
874 call writestr ; Returns with AL = 0
875 .drain: call pollchar
882 and al,09h ; Magic+Timeout
890 .wait2: mov dx,[BIOS_timer]
891 .wait3: call pollchar
902 mov word [BIOS_magic],0 ; Cold reboot
903 jmp 0F000h:0FFF0h ; Reset vector address
906 ; memory_scan_for_pxe_struct:
908 ; If none of the standard methods find the !PXE structure, look for it
909 ; by scanning memory.
912 ; CF = 0, ES:BX -> !PXE structure
913 ; Otherwise CF = 1, all registers saved
915 memory_scan_for_pxe_struct:
922 mov ax,[BIOS_fbm] ; Starting segment
923 shl ax,(10-4) ; Kilobytes -> paragraphs
924 ; mov ax,01000h ; Start to look here
925 dec ax ; To skip inc ax
928 cmp ax,0A000h ; End of memory
937 movzx cx,byte [es:4] ; Length of structure
938 cmp cl,08h ; Minimum length
947 jnz .mismatch ; Checksum must == 0
950 mov [bp+8],bx ; Save BX into stack frame (will be == 0)
958 .not_found: mov si,notfound_msg
966 ; memory_scan_for_pxenv_struct:
968 ; If none of the standard methods find the PXENV+ structure, look for it
969 ; by scanning memory.
972 ; CF = 0, ES:BX -> PXENV+ structure
973 ; Otherwise CF = 1, all registers saved
975 memory_scan_for_pxenv_struct:
977 mov si,trymempxenv_msg
979 ; mov ax,[BIOS_fbm] ; Starting segment
980 ; shl ax,(10-4) ; Kilobytes -> paragraphs
981 mov ax,01000h ; Start to look here
982 dec ax ; To skip inc ax
985 cmp ax,0A000h ; End of memory
994 movzx cx,byte [es:8] ; Length of structure
995 cmp cl,26h ; Minimum length
1003 jnz .mismatch ; Checksum must == 0
1005 mov [bp+8],bx ; Save BX into stack frame
1011 .not_found: mov si,notfound_msg
1019 ; Deallocates a file structure (pointer in SI)
1022 ; XXX: We should check to see if this file is still open on the server
1023 ; side and send a courtesy ERROR packet to the server.
1028 mov word [si],0 ; Not in use
1034 ; Open a TFTP connection to the server
1037 ; DS:DI = mangled filename
1040 ; SI = socket pointer
1041 ; EAX = file length in bytes, or -1 if unknown
1056 call allocate_socket
1059 mov ax,PKT_RETRY ; Retry counter
1060 mov word [PktTimeout],PKT_TIMEOUT ; Initial timeout
1062 .sendreq: push ax ; [bp-2] - Retry counter
1063 push si ; [bp-4] - File name
1066 mov [pxe_udp_write_pkt.buffer],di
1068 mov ax,TFTP_RRQ ; TFTP opcode
1071 lodsd ; EAX <- server override (if any)
1073 jnz .noprefix ; No prefix, and we have the server
1075 push si ; Add common prefix
1081 mov eax,[ServerIP] ; Get default server
1084 call strcpy ; Filename
1086 mov [bx+tftp_remoteip],eax
1088 push bx ; [bp-6] - TFTP block
1090 push bx ; [bp-8] - TID (local port no)
1092 mov [pxe_udp_write_pkt.status],byte 0
1093 mov [pxe_udp_write_pkt.sip],eax
1094 ; Now figure out the gateway
1100 mov [pxe_udp_write_pkt.gip],eax
1101 mov [pxe_udp_write_pkt.lport],bx
1103 mov [pxe_udp_write_pkt.rport],ax
1105 mov cx,tftp_tail_len
1107 sub di,packet_buf ; Get packet size
1108 mov [pxe_udp_write_pkt.buffersize],di
1110 mov di,pxe_udp_write_pkt
1111 mov bx,PXENV_UDP_WRITE
1114 cmp word [pxe_udp_write_pkt.status],byte 0
1118 ; Danger, Will Robinson! We need to support timeout
1119 ; and retry lest we just lost a packet...
1122 ; Packet transmitted OK, now we need to receive
1123 .getpacket: push word [PktTimeout] ; [bp-10]
1124 push word [BIOS_timer] ; [bp-12]
1126 .pkt_loop: mov bx,[bp-8] ; TID
1128 mov word [pxe_udp_read_pkt.status],0
1129 mov [pxe_udp_read_pkt.buffer],di
1130 mov [pxe_udp_read_pkt.buffer+2],ds
1131 mov word [pxe_udp_read_pkt.buffersize],packet_buf_size
1133 mov [pxe_udp_read_pkt.dip],eax
1134 mov [pxe_udp_read_pkt.lport],bx
1135 mov di,pxe_udp_read_pkt
1136 mov bx,PXENV_UDP_READ
1139 jz .got_packet ; Wait for packet
1145 dec word [bp-10] ; Timeout
1147 pop ax ; Adjust stack
1149 shl word [PktTimeout],1 ; Exponential backoff
1153 mov si,[bp-6] ; TFTP pointer
1156 ; Make sure the packet actually came from the server
1157 ; This is technically not to the TFTP spec?
1158 mov eax,[si+tftp_remoteip]
1159 cmp [pxe_udp_read_pkt.sip],eax
1162 ; Got packet - reset timeout
1163 mov word [PktTimeout],PKT_TIMEOUT
1165 pop ax ; Adjust stack
1168 mov ax,[pxe_udp_read_pkt.rport]
1169 mov [si+tftp_remoteport],ax
1171 ; filesize <- -1 == unknown
1172 mov dword [si+tftp_filesize], -1
1173 ; Default blksize unless blksize option negotiated
1174 mov word [si+tftp_blksize], TFTP_BLOCKSIZE
1176 movzx ecx,word [pxe_udp_read_pkt.buffersize]
1177 sub cx,2 ; CX <- bytes after opcode
1178 jb .failure ; Garbled reply
1184 je .bailnow ; ERROR reply: don't try again
1186 ; If the server doesn't support any options, we'll get
1187 ; a DATA reply instead of OACK. Stash the data in
1188 ; the file buffer and go with the default value for
1194 jne .err_reply ; Unknown packet type
1196 ; Now we need to parse the OACK packet to get the transfer
1198 ; SI -> first byte of options; [E]CX -> byte count
1200 jcxz .done_pkt ; No options acked
1204 .opt_name_loop: lodsb
1207 or al,20h ; Convert to lowercase
1210 ; We ran out, and no final null
1212 .got_opt_name: ; si -> option value
1213 dec cx ; bytes left in pkt
1214 jz .err_reply ; Option w/o value
1216 ; Parse option pointed to by bx; guaranteed to be
1220 mov si,bx ; -> option name
1221 mov bx,tftp_opt_table
1226 mov di,[bx] ; Option pointer
1227 mov cx,[bx+2] ; Option len
1231 je .get_value ; OK, known option
1237 jmp .err_reply ; Non-negotiated option returned
1239 .get_value: pop si ; si -> option value
1240 pop cx ; cx -> bytes left in pkt
1241 mov bx,[bx+4] ; Pointer to data target
1242 add bx,[bp-6] ; TFTP socket pointer
1250 ja .err_reply ; Not a decimal digit
1255 ; Ran out before final null, accept anyway
1260 jnz .get_opt_name ; Not end of packet
1267 pop si ; We want the packet ptr in SI
1269 mov eax,[si+tftp_filesize]
1270 and eax,eax ; Set ZF depending on file size
1272 pop bp ; Junk (retry counter)
1273 jz .error_si ; ZF = 1 need to free the socket
1282 .no_oack: ; We got a DATA packet, meaning no options are
1283 ; suported. Save the data away and consider the length
1284 ; undefined, *unless* this is the only data packet...
1285 mov bx,[bp-6] ; File pointer
1286 sub cx,2 ; Too short?
1288 lodsw ; Block number
1291 mov [bx+tftp_lastpkt],ax
1292 cmp cx,TFTP_BLOCKSIZE
1293 ja .err_reply ; Corrupt...
1295 mov [bx+tftp_filesize],ecx
1296 .unknown_size: mov [bx+tftp_bytesleft],cx
1301 mov [bx+tftp_dataptr],di
1308 .err_reply: ; Option negotiation error. Send ERROR reply.
1309 ; ServerIP and gateway are already programmed in
1311 mov ax,[si+tftp_remoteport]
1312 mov word [pxe_udp_write_pkt.rport],ax
1313 mov word [pxe_udp_write_pkt.buffer],tftp_opt_err
1314 mov word [pxe_udp_write_pkt.buffersize],tftp_opt_err_len
1315 mov di,pxe_udp_write_pkt
1316 mov bx,PXENV_UDP_WRITE
1319 ; Write an error message and explode
1324 .bailnow: mov word [bp-2],1 ; Immediate error - no retry
1326 .failure: pop bx ; Junk
1330 dec ax ; Retry counter
1331 jnz .sendreq ; Try again
1333 .error: mov si,bx ; Socket pointer
1334 .error_si: ; Socket pointer already in SI
1335 call free_socket ; ZF <- 1, SI <- 0
1339 ; allocate_socket: Allocate a local UDP port structure
1343 ; BX = socket pointer
1351 .check: cmp word [bx], byte 0
1353 add bx,open_file_t_size
1358 ; Allocate a socket number. Socket numbers are made
1359 ; guaranteed unique by including the socket slot number
1360 ; (inverted, because we use the loop counter cx); add a
1361 ; counter value to keep the numbers from being likely to
1362 ; get immediately reused.
1364 ; The NextSocket variable also contains the top two bits
1365 ; set. This generates a value in the range 49152 to
1372 and ax,((1 << (13-MAX_OPEN_LG2))-1) | 0xC000
1374 shl cx,13-MAX_OPEN_LG2
1376 xchg ch,cl ; Convert to network byte order
1377 mov [bx],cx ; Socket in use
1383 ; Free socket: socket in SI; return SI = 0, ZF = 1 for convenience
1391 mov cx,tftp_pktbuf >> 1 ; tftp_pktbuf is not cleared
1400 ; Read a dot-quad pathname in DS:SI and output an IP
1401 ; address in EAX, with SI pointing to the first
1402 ; nonmatching character.
1404 ; Return CF=1 on error.
1406 ; No segment assumptions permitted.
1420 aad ; AL += 10 * AH; AH = 0;
1435 loop .realerror ; If CX := 1 then we're done
1441 dec si ; CF unchanged!
1445 ; mangle_name: Mangle a filename pointed to by DS:SI into a buffer pointed
1446 ; to by ES:DI; ends on encountering any whitespace.
1449 ; This verifies that a filename is < FILENAME_MAX characters
1450 ; and doesn't contain whitespace, and zero-pads the output buffer,
1451 ; so "repe cmpsb" can do a compare.
1453 ; The first four bytes of the manged name is the IP address of
1454 ; the download host.
1456 ; No segment assumptions permitted.
1461 mov eax,[cs:ServerIP]
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.
1525 ; NOTE: The output buffer needs to be able to hold an
1526 ; expanded IP address.
1528 ; DS:SI -> input mangled file name
1529 ; ES:DI -> output buffer
1531 ; On return, DI points to the first byte after the output name,
1532 ; which is set to a null byte.
1544 dec di ; Point to final null byte
1551 ; This is the main PXENV+/!PXE entry point, using the PXENV+
1552 ; calling convention. This is a separate local routine so
1553 ; we can hook special things from it if necessary. In particular,
1554 ; some PXE stacks seem to not like being invoked from anything but
1555 ; the initial stack, so humour it.
1559 %if USE_PXE_PROVIDED_STACK == 0
1560 mov [cs:PXEStack],sp
1561 mov [cs:PXEStack+2],ss
1562 lss sp,[cs:InitStack]
1564 .jump: call 0:pxe_thunk ; Default to calling the thunk
1565 %if USE_PXE_PROVIDED_STACK == 0
1566 lss sp,[cs:PXEStack]
1568 cld ; Make sure DF <- 0
1571 ; Must be after function def due to NASM bug
1572 PXENVEntry equ pxenv.jump+1
1577 ; Convert from the PXENV+ calling convention (BX, ES, DI) to the !PXE
1578 ; calling convention (using the stack.)
1580 ; This is called as a far routine so that we can just stick it into
1581 ; the PXENVEntry variable.
1589 cmc ; Set CF unless ax == 0
1592 ; Must be after function def due to NASM bug
1593 PXEEntry equ pxe_thunk.jump+1
1596 ; getfssec: Get multiple clusters from a file, given the starting cluster.
1598 ; In this case, get multiple blocks from a specific TCP connection.
1602 ; SI -> TFTP socket pointer
1603 ; CX -> 512-byte block count; 0FFFFh = until end of file
1605 ; SI -> TFTP socket pointer (or 0 on EOF)
1607 ; ECX -> number of bytes actually read
1620 shl ecx,TFTP_BLOCKSIZE_LG2 ; Convert to bytes
1621 push ecx ; Initial request size
1622 jz .hit_eof ; Nothing to do?
1626 movzx eax,word [si+tftp_bytesleft]
1635 mov ax,cx ; EAX<31:16> == ECX<31:16> == 0
1636 mov bx,[si+tftp_dataptr]
1637 sub [si+tftp_bytesleft],cx
1639 fs rep movsb ; Copy from packet buffer
1641 mov [si+tftp_dataptr],bx
1650 pop eax ; Initial request amount
1652 sub ecx,eax ; ... minus anything not gotten
1657 ; Is there anything left of this?
1658 mov eax,[si+tftp_filesize]
1659 sub eax,[si+tftp_filepos]
1662 cmp [si+tftp_bytesleft],ax ; AX == 0
1665 cmp byte [si+tftp_goteof],0
1667 ; I'm 99% sure this can't happen, but...
1668 call fill_buffer ; Receive/ACK the EOF packet
1670 ; The socket is closed and the buffer drained
1671 ; Close socket structure and re-init for next user
1684 ; Get a fresh packet if the buffer is drained, and we haven't hit
1685 ; EOF yet. The buffer should be filled immediately after draining!
1687 ; expects fs -> pktbuf_seg and ds:si -> socket structure
1690 cmp word [si+tftp_bytesleft],0
1692 ret ; Otherwise, nothing to do
1700 ; Note: getting the EOF packet is not the same thing
1701 ; as tftp_filepos == tftp_filesize; if the EOF packet
1702 ; is empty the latter condition can be true without
1703 ; having gotten the official EOF.
1704 cmp byte [si+tftp_goteof],0
1705 jne .ret ; Alread EOF
1708 ; Start by ACKing the previous packet; this should cause the
1709 ; next packet to be sent.
1711 mov word [PktTimeout],PKT_TIMEOUT
1713 .send_ack: push cx ; <D> Retry count
1715 mov ax,[si+tftp_lastpkt]
1716 call ack_packet ; Send ACK
1718 ; We used to test the error code here, but sometimes
1719 ; PXE would return negative status even though we really
1720 ; did send the ACK. Now, just treat a failed send as
1721 ; a normally lost packet, and let it time out in due
1724 .send_ok: ; Now wait for packet.
1725 mov dx,[BIOS_timer] ; Get current time
1728 .wait_data: push cx ; <E> Timeout
1729 push dx ; <F> Old time
1731 mov bx,[si+tftp_pktbuf]
1732 mov [pxe_udp_read_pkt.buffer],bx
1733 mov [pxe_udp_read_pkt.buffer+2],fs
1734 mov [pxe_udp_read_pkt.buffersize],word PKTBUF_SIZE
1735 mov eax,[si+tftp_remoteip]
1736 mov [pxe_udp_read_pkt.sip],eax
1738 mov [pxe_udp_read_pkt.dip],eax
1739 mov ax,[si+tftp_remoteport]
1740 mov [pxe_udp_read_pkt.rport],ax
1741 mov ax,[si+tftp_localport]
1742 mov [pxe_udp_read_pkt.lport],ax
1743 mov di,pxe_udp_read_pkt
1744 mov bx,PXENV_UDP_READ
1751 ; No packet, or receive failure
1753 pop ax ; <F> Old time
1754 pop cx ; <E> Timeout
1755 cmp ax,dx ; Same time -> don't advance timeout
1756 je .wait_data ; Same clock tick
1757 loop .wait_data ; Decrease timeout
1759 pop cx ; <D> Didn't get any, send another ACK
1760 shl word [PktTimeout],1 ; Exponential backoff
1762 jmp kaboom ; Forget it...
1764 .recv_ok: pop dx ; <F>
1767 cmp word [pxe_udp_read_pkt.buffersize],byte 4
1768 jb .wait_data ; Bad size for a DATA packet
1770 mov bx,[si+tftp_pktbuf]
1771 cmp word [fs:bx],TFTP_DATA ; Not a data packet?
1772 jne .wait_data ; Then wait for something else
1774 mov ax,[si+tftp_lastpkt]
1775 xchg ah,al ; Host byte order
1776 inc ax ; Which packet are we waiting for?
1777 xchg ah,al ; Network byte order
1781 ; Wrong packet, ACK the packet and then try again
1782 ; This is presumably because the ACK got lost,
1783 ; so the server just resent the previous packet
1786 jmp .send_ok ; Reset timeout
1788 .right_packet: ; It's the packet we want. We're also EOF if the
1791 pop cx ; <D> Don't need the retry count anymore
1793 mov [si+tftp_lastpkt],ax ; Update last packet number
1795 movzx ecx,word [pxe_udp_read_pkt.buffersize]
1796 sub cx,byte 4 ; Skip TFTP header
1798 ; Set pointer to data block
1799 lea ax,[bx+4] ; Data past TFTP header
1800 mov [si+tftp_dataptr],ax
1802 add [si+tftp_filepos],ecx
1803 mov [si+tftp_bytesleft],cx
1805 cmp cx,[si+tftp_blksize] ; Is it a full block?
1806 jb .last_block ; If not, it's EOF
1814 .last_block: ; Last block - ACK packet immediately
1819 ; Make sure we know we are at end of file
1820 mov eax,[si+tftp_filepos]
1821 mov [si+tftp_filesize],eax
1822 mov byte [si+tftp_goteof],1
1829 ; Send ACK packet. This is a common operation and so is worth canning.
1833 ; AX = Packet # to ack (network byte order)
1836 ; All registers preserved
1838 ; This function uses the pxe_udp_write_pkt but not the packet_buf.
1842 mov [ack_packet_buf+2],ax ; Packet number to ack
1844 mov [pxe_udp_write_pkt.lport],ax
1845 mov ax,[si+tftp_remoteport]
1846 mov [pxe_udp_write_pkt.rport],ax
1847 mov eax,[si+tftp_remoteip]
1848 mov [pxe_udp_write_pkt.sip],eax
1854 mov [pxe_udp_write_pkt.gip],eax
1855 mov [pxe_udp_write_pkt.buffer],word ack_packet_buf
1856 mov [pxe_udp_write_pkt.buffersize], word 4
1857 mov di,pxe_udp_write_pkt
1858 mov bx,PXENV_UDP_WRITE
1860 cmp ax,byte 0 ; ZF = 1 if write OK
1867 ; This function unloads the PXE and UNDI stacks and unclaims
1871 test byte [KeepPXE],01h ; Should we keep PXE around?
1881 mov si,new_api_unload
1882 cmp byte [APIVer+1],2 ; Major API version >= 2?
1884 mov si,old_api_unload
1887 .call_loop: xor ax,ax
1892 mov di,pxe_unload_stack_pkt
1895 mov cx,pxe_unload_stack_pkt_len >> 1
1900 mov ax,word [pxe_unload_stack_pkt.status]
1901 cmp ax,PXENV_STATUS_SUCCESS
1908 mov dx,[RealBaseMem]
1909 cmp dx,[BIOS_fbm] ; Sanity check
1913 ; Check that PXE actually unhooked the INT 1Ah chain
1914 movzx eax,word [4*0x1a]
1915 movzx ecx,word [4*0x1a+2]
1919 cmp ax,dx ; Not in range
1933 mov si,cant_free_msg
1949 ; We want to keep PXE around, but still we should reset
1950 ; it to the standard bootup configuration
1955 mov bx,PXENV_UDP_CLOSE
1956 mov di,pxe_udp_close_pkt
1964 ; Take an IP address (in network byte order) in EAX and
1965 ; output a dotted quad string to ES:DI.
1966 ; DI points to terminal null at end of string on exit.
1975 jb .lt10 ; If so, skip first 2 digits
1978 jb .lt100 ; If so, skip first digit
1981 ; Now AH = 100-digit; AL = remainder
1988 ; Now AH = 10-digit; AL = remainder
1999 ror eax,8 ; Move next char into LSB
2007 ; uchexbytes/lchexbytes
2009 ; Take a number of bytes in memory and convert to upper/lower-case
2013 ; DS:SI = input bytes
2014 ; ES:DI = output buffer
2015 ; CX = number of bytes
2017 ; DS:SI = first byte after
2018 ; ES:DI = first byte after
2050 ; pxe_get_cached_info
2052 ; Get a DHCP packet from the PXE stack into the trackbuf.
2059 ; Assumes CS == DS == ES.
2061 pxe_get_cached_info:
2063 mov di,pxe_bootp_query_pkt
2072 stosw ; Buffer offset
2074 stosw ; Buffer segment
2076 pop di ; DI -> parameter set
2077 mov bx,PXENV_GET_CACHED_INFO
2084 mov cx,[pxe_bootp_query_pkt.buffersize]
2088 mov si,err_pxefailed
2094 ; Parse a DHCP packet. This includes dealing with "overloaded"
2095 ; option fields (see RFC 2132, section 9.3)
2097 ; This should fill in the following global variables, if the
2098 ; information is present:
2100 ; MyIP - client IP address
2101 ; ServerIP - boot server IP address
2102 ; Netmask - network mask
2103 ; Gateway - default gateway router IP
2104 ; BootFile - boot file name
2105 ; DNSServers - DNS server IPs
2106 ; LocalDomain - Local domain name
2107 ; MACLen, MAC - Client identifier, if MACLen == 0
2109 ; This assumes the DHCP packet is in "trackbuf" and the length
2110 ; of the packet in in CX on entry.
2114 mov byte [OverLoad],0 ; Assume no overload
2115 mov eax, [trackbuf+bootp.yip]
2118 cmp al,224 ; Class D or higher -> bad
2122 mov eax, [trackbuf+bootp.sip]
2125 cmp al,224 ; Class D or higher -> bad
2129 sub cx, bootp.options
2131 mov si, trackbuf+bootp.option_magic
2133 cmp eax, BOOTP_OPTION_MAGIC
2135 call parse_dhcp_options
2137 mov si, trackbuf+bootp.bootfile
2138 test byte [OverLoad],1
2141 call parse_dhcp_options
2142 jmp short .parsed_file
2145 jz .parsed_file ; No bootfile name
2150 stosb ; Null-terminate
2152 mov si, trackbuf+bootp.sname
2153 test byte [OverLoad],2
2156 call parse_dhcp_options
2161 ; Parse a sequence of DHCP options, pointed to by DS:SI; the field
2162 ; size is CX -- some DHCP servers leave option fields unterminated
2163 ; in violation of the spec.
2165 ; For parse_some_dhcp_options, DH contains the minimum value for
2166 ; the option to recognize -- this is used to restrict parsing to
2167 ; PXELINUX-specific options only.
2172 parse_some_dhcp_options:
2179 jz .done ; Last byte; must be PAD, END or malformed
2180 cmp al, 0 ; PAD option
2182 cmp al,255 ; END option
2185 ; Anything else will have a length field
2186 mov dl,al ; DL <- option number
2188 lodsb ; AX <- option length
2190 sub cx,ax ; Decrement bytes left counter
2191 jb .done ; Malformed option: length > field size
2193 cmp dl,dh ; Is the option value valid?
2196 mov bx,dhcp_option_list
2198 cmp bx,dhcp_option_list_end
2210 ; Unknown option. Skip to the next one.
2230 ; Parse individual DHCP options. SI points to the option data and
2231 ; AX to the option length. DL contains the option number.
2232 ; All registers are saved around the routine.
2247 cmp cl,DNS_MAX_SERVERS
2249 mov cl,DNS_MAX_SERVERS
2253 mov [LastDNSServer],di
2256 dopt 16, local_domain
2260 xchg [bx],al ; Zero-terminate option
2262 call dns_mangle ; Convert to DNS label set
2263 mov [bx],al ; Restore ending byte
2266 dopt 43, vendor_encaps
2267 mov dh,208 ; Only recognize PXELINUX options
2268 mov cx,ax ; Length of option = max bytes to parse
2269 call parse_some_dhcp_options ; Parse recursive structure
2272 dopt 52, option_overload
2279 cmp dword [ServerIP],0
2280 jne .skip ; Already have a next server IP
2281 cmp al,224 ; Class D or higher
2286 dopt 61, client_identifier
2287 cmp ax,MAC_MAX ; Too long?
2289 cmp ax,2 ; Too short?
2291 cmp [MACLen],ah ; Only do this if MACLen == 0
2294 lodsb ; Client identifier type
2297 jne .skip ; Client identifier is not a MAC
2304 dopt 67, bootfile_name
2308 dopt 97, uuid_client_identifier
2309 cmp ax,17 ; type byte + 16 bytes UUID
2311 mov dl,[si] ; Must have type 0 == UUID
2312 or dl,[HaveUUID] ; Capture only the first instance
2314 mov byte [HaveUUID],1 ; Got UUID
2319 dopt 209, pxelinux_configfile
2321 or byte [DHCPMagic],2 ; Got config file
2324 dopt 210, pxelinux_pathprefix
2326 or byte [DHCPMagic],4 ; Got path prefix
2329 dopt 211, pxelinux_reboottime
2333 xchg bl,bh ; Convert to host byte order
2336 mov [RebootTime],ebx
2337 or byte [DHCPMagic],8 ; Got RebootTime
2340 ; Common code for copying an option verbatim
2341 ; Copies the option into ES:DI and null-terminates it.
2342 ; Returns with AX=0 and SI past the option.
2344 xchg cx,ax ; CX <- option length
2346 xchg cx,ax ; AX <- 0
2347 stosb ; Null-terminate
2351 dhcp_option_list_end:
2356 uuid_dashes db 4,2,2,2,6,0 ; Bytes per UUID dashed section
2362 ; Generate an ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
2363 ; option into IPOption based on a DHCP packet in trackbuf.
2364 ; Assumes CS == DS == ES.
2385 call gendotquad ; Zero-terminates its output
2387 mov [IPOptionLen],di
2392 ; Call the receive loop while idle. This is done mostly so we can respond to
2393 ; ARP messages, but perhaps in the future this can be used to do network
2396 ; hpa sez: people using automatic control on the serial port get very
2397 ; unhappy if we poll for ARP too often (the PXE stack is pretty slow,
2398 ; typically.) Therefore, only poll if at least 4 BIOS timer ticks have
2399 ; passed since the last poll, and reset this when a character is
2400 ; received (RESET_IDLE).
2406 mov ax,[cs:BIOS_timer]
2407 mov [cs:IdleTimer],ax
2413 mov ax,[cs:BIOS_timer]
2414 sub ax,[cs:IdleTimer]
2426 mov [pxe_udp_read_pkt.status],al ; 0
2427 mov [pxe_udp_read_pkt.buffer],di
2428 mov [pxe_udp_read_pkt.buffer+2],ds
2429 mov word [pxe_udp_read_pkt.buffersize],packet_buf_size
2431 mov [pxe_udp_read_pkt.dip],eax
2432 mov word [pxe_udp_read_pkt.lport],htons(9) ; discard port
2433 mov di,pxe_udp_read_pkt
2434 mov bx,PXENV_UDP_READ
2445 ; -----------------------------------------------------------------------------
2447 ; -----------------------------------------------------------------------------
2449 %include "getc.inc" ; getc et al
2450 %include "conio.inc" ; Console I/O
2451 %include "writestr.inc" ; String output
2452 writestr equ cwritestr
2453 %include "writehex.inc" ; Hexadecimal output
2454 %include "configinit.inc" ; Initialize configuration
2455 %include "parseconfig.inc" ; High-level config file handling
2456 %include "parsecmd.inc" ; Low-level config file handling
2457 %include "bcopy32.inc" ; 32-bit bcopy
2458 %include "loadhigh.inc" ; Load a file into high memory
2459 %include "font.inc" ; VGA font stuff
2460 %include "graphics.inc" ; VGA graphics
2461 %include "highmem.inc" ; High memory sizing
2462 %include "strcpy.inc" ; strcpy()
2463 %include "rawcon.inc" ; Console I/O w/o using the console functions
2464 %include "dnsresolv.inc" ; DNS resolver
2465 %include "adv.inc" ; Auxillary Data Vector
2467 ; -----------------------------------------------------------------------------
2468 ; Begin data section
2469 ; -----------------------------------------------------------------------------
2473 copyright_str db ' Copyright (C) 1994-', year, ' H. Peter Anvin'
2475 err_bootfailed db CR, LF, 'Boot failed: press a key to retry, or wait for reset...', CR, LF, 0
2476 bailmsg equ err_bootfailed
2477 err_nopxe db "No !PXE or PXENV+ API found; we're dead...", CR, LF, 0
2478 err_pxefailed db 'PXE API call failed, error ', 0
2479 err_udpinit db 'Failed to initialize UDP stack', CR, LF, 0
2480 err_noconfig db 'Unable to locate configuration file', CR, LF, 0
2481 err_oldtftp db 'TFTP server does not support the tsize option', CR, LF, 0
2482 found_pxenv db 'Found PXENV+ structure', CR, LF, 0
2483 using_pxenv_msg db 'Old PXE API detected, using PXENV+ structure', CR, LF, 0
2484 apiver_str db 'PXE API version is ',0
2485 pxeentry_msg db 'PXE entry point found (we hope) at ', 0
2486 pxenventry_msg db 'PXENV entry point found (we hope) at ', 0
2487 trymempxe_msg db 'Scanning memory for !PXE structure... ', 0
2488 trymempxenv_msg db 'Scanning memory for PXENV+ structure... ', 0
2489 undi_data_msg db 'UNDI data segment at: ',0
2490 undi_data_len_msg db 'UNDI data segment size: ',0
2491 undi_code_msg db 'UNDI code segment at: ',0
2492 undi_code_len_msg db 'UNDI code segment size: ',0
2493 cant_free_msg db 'Failed to free base memory, error ', 0
2494 notfound_msg db 'not found', CR, LF, 0
2495 myipaddr_msg db 'My IP address seems to be ',0
2496 tftpprefix_msg db 'TFTP prefix: ', 0
2497 localboot_msg db 'Booting from local disk...', CR, LF, 0
2498 trying_msg db 'Trying to load: ', 0
2499 fourbs_msg db BS, BS, BS, BS, 0
2500 default_str db 'default', 0
2501 syslinux_banner db CR, LF, 'PXELINUX ', version_str, ' ', date, ' ', 0
2502 cfgprefix db 'pxelinux.cfg/' ; No final null!
2503 cfgprefix_len equ ($-cfgprefix)
2506 ; Command line options we'd like to take a look at
2508 ; mem= and vga= are handled as normal 32-bit integer values
2509 initrd_cmd db 'initrd='
2510 initrd_cmd_len equ $-initrd_cmd
2512 ; This one we make ourselves
2513 bootif_str db 'BOOTIF='
2514 bootif_str_len equ $-bootif_str
2516 ; Config file keyword table
2518 %include "keywords.inc"
2521 ; Extensions to search for (in *forward* order).
2522 ; (.bs and .bss are disabled for PXELINUX, since they are not supported)
2525 exten_table: db '.cbt' ; COMBOOT (specific)
2526 db '.0', 0, 0 ; PXE bootstrap program
2527 db '.com' ; COMBOOT (same as DOS)
2530 dd 0, 0 ; Need 8 null bytes here
2533 ; PXE unload sequences
2537 db PXENV_UNDI_SHUTDOWN
2538 db PXENV_UNLOAD_STACK
2543 db PXENV_UNDI_SHUTDOWN
2544 db PXENV_UNLOAD_STACK
2545 db PXENV_UNDI_CLEANUP
2549 ; PXE query packets partially filled in
2552 pxe_bootp_query_pkt:
2553 .status: resw 1 ; Status
2554 .packettype: resw 1 ; Boot server packet type
2555 .buffersize: resw 1 ; Packet size
2556 .buffer: resw 2 ; seg:off of buffer
2557 .bufferlimit: resw 1 ; Unused
2561 .status: dw 0 ; Status
2562 .sip: dd 0 ; Source (our) IP
2565 .status: dw 0 ; Status
2568 .status: dw 0 ; Status
2569 .sip: dd 0 ; Server IP
2570 .gip: dd 0 ; Gateway IP
2571 .lport: dw 0 ; Local port
2572 .rport: dw 0 ; Remote port
2573 .buffersize: dw 0 ; Size of packet
2574 .buffer: dw 0, 0 ; seg:off of buffer
2577 .status: dw 0 ; Status
2578 .sip: dd 0 ; Source IP
2579 .dip: dd 0 ; Destination (our) IP
2580 .rport: dw 0 ; Remote port
2581 .lport: dw 0 ; Local port
2582 .buffersize: dw 0 ; Max packet size
2583 .buffer: dw 0, 0 ; seg:off of buffer
2586 ; Misc initialized (data) variables
2589 BaseStack dd StackBuf ; ESP of base stack
2590 dw 0 ; SS of base stack
2591 NextSocket dw 49152 ; Counter for allocating socket numbers
2592 KeepPXE db 0 ; Should PXE be kept around?
2597 tftp_tail db 'octet', 0 ; Octet mode
2598 tsize_str db 'tsize' ,0 ; Request size
2599 tsize_len equ ($-tsize_str)
2601 blksize_str db 'blksize', 0 ; Request large blocks
2602 blksize_len equ ($-blksize_str)
2603 asciidec TFTP_LARGEBLK
2605 tftp_tail_len equ ($-tftp_tail)
2609 ; Options negotiation parsing table (string pointer, string len, offset
2610 ; into socket structure)
2613 dw tsize_str, tsize_len, tftp_filesize
2614 dw blksize_str, blksize_len, tftp_blksize
2615 tftp_opts equ ($-tftp_opt_table)/6
2618 ; Error packet to return on options negotiation error
2620 tftp_opt_err dw TFTP_ERROR ; ERROR packet
2621 dw TFTP_EOPTNEG ; ERROR 8: bad options
2622 db 'tsize option required', 0 ; Error message
2623 tftp_opt_err_len equ ($-tftp_opt_err)
2626 ack_packet_buf: dw TFTP_ACK, 0 ; TFTP ACK packet
2629 ; IP information (initialized to "unknown" values)
2630 MyIP dd 0 ; My IP address
2631 ServerIP dd 0 ; IP address of boot server
2632 Netmask dd 0 ; Netmask of this subnet
2633 Gateway dd 0 ; Default router
2634 ServerPort dw TFTP_PORT ; TFTP server port
2637 ; Variables that are uninitialized in SYSLINUX but initialized here
2640 BufSafe dw trackbufsize/TFTP_BLOCKSIZE ; Clusters we can load into trackbuf
2641 BufSafeBytes dw trackbufsize ; = how many bytes?
2643 %if ( trackbufsize % TFTP_BLOCKSIZE ) != 0
2644 %error trackbufsize must be a multiple of TFTP_BLOCKSIZE