1 ; -*- fundamental -*- (asm-mode sucks)
3 ; ****************************************************************************
7 ; A program to boot Linux kernels off a TFTP server using the Intel PXE
8 ; network booting API. It is based on the SYSLINUX boot loader for
11 ; Copyright (C) 1994-2005 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 ; ****************************************************************************
26 %include "tracers.inc"
31 ; Some semi-configurable constants... change on your own risk.
34 FILENAME_MAX_LG2
equ 7 ; log2(Max filename size Including final null)
35 FILENAME_MAX
equ (1 << FILENAME_MAX_LG2
)
36 NULLFILE
equ 0 ; Zero byte == null file name
37 NULLOFFSET
equ 4 ; Position in which to look
38 REBOOT_TIME
equ 5*60 ; If failure, time until full reset
39 %assign HIGHMEM_SLOP
128*1024 ; Avoid this much memory near the top
40 MAX_OPEN_LG2
equ 5 ; log2(Max number of open sockets)
41 MAX_OPEN
equ (1 << MAX_OPEN_LG2
)
42 PKTBUF_SIZE
equ (65536/MAX_OPEN
) ; Per-socket packet buffer size
43 TFTP_PORT
equ htons
(69) ; Default TFTP port
44 PKT_RETRY
equ 6 ; Packet transmit retry count
45 PKT_TIMEOUT
equ 12 ; Initial timeout, timer ticks @ 55 ms
46 ; Desired TFTP block size
47 ; For Ethernet MTU is normally 1500. Unfortunately there seems to
48 ; be a fair number of networks with "substandard" MTUs which break.
49 ; The code assumes TFTP_LARGEBLK <= 2K.
51 TFTP_LARGEBLK
equ (TFTP_MTU
-20-8-4) ; MTU - IP hdr - UDP hdr - TFTP hdr
52 ; Standard TFTP block size
53 TFTP_BLOCKSIZE_LG2
equ 9 ; log2(bytes/block)
54 TFTP_BLOCKSIZE
equ (1 << TFTP_BLOCKSIZE_LG2
)
55 %assign USE_PXE_PROVIDED_STACK
1 ; Use stack provided by PXE?
57 SECTOR_SHIFT
equ TFTP_BLOCKSIZE_LG2
58 SECTOR_SIZE
equ TFTP_BLOCKSIZE
61 ; This is what we need to do when idle
63 %define HAVE_IDLE
1 ; idle is not a noop
73 ; TFTP operation codes
75 TFTP_RRQ
equ htons
(1) ; Read request
76 TFTP_WRQ
equ htons
(2) ; Write request
77 TFTP_DATA
equ htons
(3) ; Data packet
78 TFTP_ACK
equ htons
(4) ; ACK packet
79 TFTP_ERROR
equ htons
(5) ; ERROR packet
80 TFTP_OACK
equ htons
(6) ; OACK packet
85 TFTP_EUNDEF
equ htons
(0) ; Unspecified error
86 TFTP_ENOTFOUND
equ htons
(1) ; File not found
87 TFTP_EACCESS
equ htons
(2) ; Access violation
88 TFTP_ENOSPACE
equ htons
(3) ; Disk full
89 TFTP_EBADOP
equ htons
(4) ; Invalid TFTP operation
90 TFTP_EBADID
equ htons
(5) ; Unknown transfer
91 TFTP_EEXISTS
equ htons
(6) ; File exists
92 TFTP_ENOUSER
equ htons
(7) ; No such user
93 TFTP_EOPTNEG
equ htons
(8) ; Option negotiation failure
96 ; The following structure is used for "virtual kernels"; i.e. LILO-style
97 ; option labels. The options we permit here are `kernel' and `append
98 ; Since there is no room in the bottom 64K for all of these, we
99 ; stick them at vk_seg:0000 and copy them down before we need them.
102 vk_vname: resb FILENAME_MAX
; Virtual name **MUST BE FIRST!**
103 vk_rname: resb FILENAME_MAX
; Real name
104 vk_ipappend: resb
1 ; "IPAPPEND" flag
108 vk_append: resb max_cmd_len
+1 ; Command line
110 vk_end: equ $
; Should be <= vk_size
114 ; Segment assignments in the bottom 640K
115 ; 0000h - main code/data segment (and BIOS segment)
117 real_mode_seg
equ 4000h
118 vk_seg
equ 3000h ; Virtual kernels
119 xfer_buf_seg
equ 2000h ; Bounce buffer for I/O to high mem
120 pktbuf_seg
equ 1000h ; Packet buffers segments
121 comboot_seg
equ real_mode_seg
; COMBOOT image loading zone
124 ; BOOTP/DHCP packet pattern
128 .opcode resb
1 ; BOOTP/DHCP "opcode"
129 .hardware resb
1 ; ARP hardware type
130 .hardlen resb
1 ; Hardware address length
131 .gatehops resb
1 ; Used by forwarders
132 .ident resd
1 ; Transaction ID
133 .seconds resw
1 ; Seconds elapsed
134 .flags resw
1 ; Broadcast flags
135 .cip resd
1 ; Client IP
136 .yip resd
1 ; "Your" IP
137 .sip resd
1 ; Next server IP
138 .gip resd
1 ; Relay agent IP
139 .macaddr resb
16 ; Client MAC address
140 .sname resb
64 ; Server name (optional)
141 .bootfile resb
128 ; Boot file name
142 .option_magic resd
1 ; Vendor option magic cookie
143 .options resb
1260 ; Vendor options
146 BOOTP_OPTION_MAGIC
equ htonl
(0x63825363) ; See RFC 2132
149 ; TFTP connection data structure. Each one of these corresponds to a local
150 ; UDP port. The size of this structure must be a power of 2.
151 ; HBO = host byte order; NBO = network byte order
152 ; (*) = written by options negotiation code, must be dword sized
155 tftp_localport resw
1 ; Local port number (0 = not in use)
156 tftp_remoteport resw
1 ; Remote port number
157 tftp_remoteip resd
1 ; Remote IP address
158 tftp_filepos resd
1 ; Bytes downloaded (including buffer)
159 tftp_filesize resd
1 ; Total file size(*)
160 tftp_blksize resd
1 ; Block size for this connection(*)
161 tftp_bytesleft resw
1 ; Unclaimed data bytes
162 tftp_lastpkt resw
1 ; Sequence number of last packet (NBO)
163 tftp_dataptr resw
1 ; Pointer to available data
164 resw
2 ; Currently unusued
165 ; At end since it should not be zeroed on socked close
166 tftp_pktbuf resw
1 ; Packet buffer offset
169 %if
(open_file_t_size
& (open_file_t_size
-1))
170 %error
"open_file_t is not a power of 2"
174 ; ---------------------------------------------------------------------------
176 ; ---------------------------------------------------------------------------
179 ; Memory below this point is reserved for the BIOS and the MBR
182 trackbufsize
equ 8192
183 trackbuf resb trackbufsize
; Track buffer goes here
184 getcbuf resb trackbufsize
187 ; Put some large buffers here, before RBFG_brainfuck,
188 ; where we can still carefully control the address
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 ConfigServer resd
1 ; Null prefix for mangled config name
197 ConfigName resb
256-4 ; Configuration file from DHCP option
198 PathPrefix resb
256 ; Path prefix derived from boot file
199 DotQuadBuf resb
16 ; Buffer for dotted-quad IP address
200 IPOption resb
80 ; ip= option buffer
201 InitStack resd
1 ; Pointer to reset stack (SS:SP)
202 PXEStack resd
1 ; Saved stack during PXE call
204 ; Warning here: RBFG build 22 randomly overwrites memory location
205 ; [0x5680,0x576c), possibly more. It seems that it gets confused and
206 ; screws up the pointer to its own internal packet buffer and starts
207 ; writing a received ARP packet into low memory.
208 RBFG_brainfuck resb
0E00h
212 RebootTime resd
1 ; Reboot timeout, if set by option
213 StrucPtr resd
1 ; Pointer to PXENV+ or !PXE structure
214 APIVer resw
1 ; PXE API version found
215 IPOptionLen resw
1 ; Length of IPOption
216 IdleTimer resw
1 ; Time to check for ARP?
217 LocalBootType resw
1 ; Local boot return code
218 PktTimeout resw
1 ; Timeout for current packet
219 RealBaseMem resw
1 ; Amount of DOS memory after freeing
220 OverLoad resb
1 ; Set if DHCP packet uses "overloading"
222 ; The relative position of these fields matter!
223 MACLen resb
1 ; MAC address len
224 MACType resb
1 ; MAC address type
225 MAC resb
16 ; Actual MAC address
226 BOOTIFStr resb
7 ; Space for "BOOTIF="
227 MACStr resb
3*17 ; MAC address as a string
230 ; PXE packets which don't need static initialization
233 pxe_unload_stack_pkt:
234 .
status: resw
1 ; Status
235 .
reserved: resw
10 ; Reserved
236 pxe_unload_stack_pkt_len
equ $
-pxe_unload_stack_pkt
239 ; BOOTP/DHCP packet buffer
242 packet_buf resb
2048 ; Transfer packet
243 packet_buf_size
equ $
-packet_buf
246 ; Constants for the xfer_buf_seg
248 ; The xfer_buf_seg is also used to store message file buffers. We
249 ; need two trackbuffers (text and graphics), plus a work buffer
250 ; for the graphics decompressor.
252 xbs_textbuf
equ 0 ; Also hard-coded, do not change
253 xbs_vgabuf
equ trackbufsize
254 xbs_vgatmpbuf
equ 2*trackbufsize
258 ; PXELINUX needs more BSS than the other derivatives;
259 ; therefore we relocate it from 7C00h on startup.
261 StackBuf
equ $
; Base of stack if we use our own
264 ; Primary entry point.
268 pushfd ; Paranoia... in case of return to PXE
269 pushad ; ... save as much state as possible
280 %if TEXT_START
!= 0x7c00
281 ; This is uglier than it should be, but works around
282 ; some NASM 0.98.38 bugs.
283 mov di,section..bcopy32.start
284 add di,__bcopy_size
-4
285 lea si,[di-(TEXT_START
-7C00h
)]
286 lea cx,[di-(TEXT_START
-4)]
288 std ; Overlapping areas, copy backwards
292 jmp 0:_start1
; Canonicalize address
295 les bx,[bp+48] ; ES:BX -> !PXE or PXENV+ structure
297 ; That is all pushed onto the PXE stack. Save the pointer
298 ; to it and switch to an internal stack.
302 %if USE_PXE_PROVIDED_STACK
303 ; Apparently some platforms go bonkers if we
304 ; set up our own stack...
312 sti ; Stack set up and ready
316 ; Initialize screen (if we're using one)
318 ; Now set up screen parameters
321 ; Wipe the F-key area
324 mov cx,10*(1 << FILENAME_MAX_LG2
)
325 push es ; Save ES -> PXE structure
332 ; Tell the user we got this far
334 mov si,syslinux_banner
341 ; Assume API version 2.1, in case we find the !PXE structure without
342 ; finding the PXENV+ structure. This should really look at the Base
343 ; Code ROM ID structure in have_pxe, but this is adequate for now --
344 ; if we have !PXE, we have to be 2.1 or higher, and we don't care
345 ; about higher versions than that.
347 mov word [APIVer
],0201h
350 ; Now we need to find the !PXE structure. It's *supposed* to be pointed
351 ; to by SS:[SP+4], but support INT 1Ah, AX=5650h method as well.
352 ; FIX: ES:BX should point to the PXENV+ structure on entry as well.
353 ; We should make that the second test, and not trash ES:BX...
355 cmp dword [es:bx], '!PXE'
358 ; Uh-oh, not there... try plan B
360 %if USE_PXE_PROVIDED_STACK
== 0
363 int 1Ah ; May trash regs
364 %if USE_PXE_PROVIDED_STACK
== 0
372 ; Okay, that gave us the PXENV+ structure, find !PXE
373 ; structure from that (if available)
374 cmp dword [es:bx], 'PXEN'
376 cmp word [es:bx+4], 'V+'
379 ; Nothing there either. Last-ditch: scan memory
380 call memory_scan_for_pxe_struct
; !PXE scan
382 call memory_scan_for_pxenv_struct
; PXENV+ scan
385 no_pxe: mov si,err_nopxe
403 cmp ax,0201h ; API version 2.1 or higher
407 les bx,[es:bx+28h] ; !PXE structure pointer
408 cmp dword [es:bx],'!PXE'
411 ; Nope, !PXE structure missing despite API 2.1+, or at least
412 ; the pointer is missing. Do a last-ditch attempt to find it.
413 call memory_scan_for_pxe_struct
416 ; Otherwise, no dice, use PXENV+ structure
420 old_api: ; Need to use a PXENV+ structure
421 mov si,using_pxenv_msg
424 mov eax,[es:bx+0Ah] ; PXE RM API
432 mov si,undi_data_len_msg
442 mov si,undi_code_len_msg
448 ; Compute base memory size from PXENV+ structure
450 movzx eax,word [es:bx+20h] ; UNDI data seg
451 cmp ax,[es:bx+24h] ; UNDI code seg
461 shr eax,10 ; Convert to kilobytes
464 mov si,pxenventry_msg
466 mov ax,[PXENVEntry
+2]
487 mov si,undi_data_len_msg
497 mov si,undi_code_len_msg
503 ; Compute base memory size from !PXE structure
530 pop es ; Restore CS == DS == ES
533 ; Network-specific initialization
536 mov [LocalDomain
],al ; No LocalDomain received
539 ; Now attempt to get the BOOTP/DHCP packet that brought us life (and an IP
540 ; address). This lives in the DHCPACK packet (query info 2).
543 mov di,pxe_bootp_query_pkt_2
544 mov bx,PXENV_GET_CACHED_INFO
547 push word [pxe_bootp_query_pkt_2.status
]
552 mov di,pxe_bootp_size_query_pkt
553 mov bx,PXENV_GET_CACHED_INFO
558 mov ax,[pxe_bootp_size_query_pkt.buffersize
]
571 jmp kaboom
; We're dead
574 pop cx ; Forget status
575 mov cx,[pxe_bootp_query_pkt_2.buffersize
]
576 call parse_dhcp
; Parse DHCP packet
578 ; Save away MAC address (assume this is in query info 2. If this
579 ; turns out to be problematic it might be better getting it from
580 ; the query info 1 packet.)
583 movzx cx,byte [trackbuf
+bootp.hardlen
]
585 mov al,[trackbuf
+bootp.hardware
]
587 mov si,trackbuf
+bootp.macaddr
598 mov cx,bootif_str_len
618 mov [di-1],byte 0 ; Null-terminate and strip final colon
621 ; Now, get the boot file and other info. This lives in the CACHED_REPLY
622 ; packet (query info 3).
624 mov [pxe_bootp_size_query_pkt.packettype
], byte 3
626 mov di,pxe_bootp_query_pkt_3
627 mov bx,PXENV_GET_CACHED_INFO
630 push word [pxe_bootp_query_pkt_3.status
]
635 ; Packet loaded OK...
636 pop cx ; Forget status
637 mov cx,[pxe_bootp_query_pkt_3.buffersize
]
638 call parse_dhcp
; Parse DHCP packet
640 ; Generate ip= option
650 call gendotquad
; This takes network byte order input
652 xchg ah,al ; Convert to host byte order
653 ror eax,16 ; (BSWAP doesn't work on 386)
670 ; Check to see if we got any PXELINUX-specific DHCP options; in particular,
671 ; if we didn't get the magic enable, do not recognize any other options.
674 test byte [DHCPMagic
], 1 ; If we didn't get the magic enable...
676 mov byte [DHCPMagic
], 0 ; If not, kill all other options
681 ; Initialize UDP stack
685 mov [pxe_udp_open_pkt.sip
],eax
686 mov di,pxe_udp_open_pkt
687 mov bx,PXENV_UDP_OPEN
690 cmp word [pxe_udp_open_pkt.status
], byte 0
692 .
failed: mov si,err_udpinit
698 ; Common initialization code
701 %include "cpuinit.inc"
704 ; Now we're all set to start with our *real* business. First load the
705 ; configuration file (if any) and parse it.
707 ; In previous versions I avoided using 32-bit registers because of a
708 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
709 ; random. I figure, though, that if there are any of those still left
710 ; they probably won't be trying to install Linux on them...
712 ; The code is still ripe with 16-bitisms, though. Not worth the hassle
713 ; to take'm out. In fact, we may want to put them back if we're going
714 ; to boot ELKS at some point.
718 ; Store standard filename prefix
720 prefix: test byte [DHCPMagic
], 04h ; Did we get a path prefix option
729 lea si,[di-2] ; Skip final null!
732 cmp al,'.' ; Count . or - as alphanum
744 .
alnum: loop .find_alnum
746 .
notalnum: mov byte [si+2],0 ; Zero-terminate after delimiter
749 mov si,tftpprefix_msg
756 ; Load configuration file
761 ; Begin looking for configuration file
766 stosd ; The config file is always from the server
768 test byte [DHCPMagic
], 02h
771 ; We got a DHCP option, try it first
774 ; mov di,ConfigName ; - already the case
788 ; Try loading by MAC address
789 ; Have to guess config file name
808 xchg ah,al ; Convert to host byte order
811 .
hexify_loop: rol eax,4
823 mov cx,9 ; Up to 9 attempts
825 .
tryagain: mov byte [di],0
831 rep movsb ; Copy "default" string
852 ; Now we have the config file open. Parse the config file and
853 ; run the user interface.
858 ; Linux kernel loading code is common. However, we need to define
859 ; a couple of helper macros...
862 ; Handle "ipappend" option
863 %define HAVE_SPECIAL_APPEND
864 %macro SPECIAL_APPEND
0
865 test byte [IPAppend
],01h ; ip=
873 test byte [IPAppend
],02h
877 mov byte [es:di-1],' ' ; Replace null with space
882 %define HAVE_UNLOAD_PREP
887 %include "runkernel.inc"
890 ; COMBOOT-loading code
892 %include "comboot.inc"
894 %include "cmdline.inc"
897 ; Boot sector loading code
899 %include "bootsect.inc"
902 ; Boot to the local disk by returning the appropriate PXE magic.
903 ; AX contains the appropriate return code.
908 mov [LocalBootType
],ax
912 ; Restore the environment we were called with
919 mov ax,[cs:LocalBootType
]
929 ; kaboom: write a message and bail out. Wait for quite a while,
930 ; or a user keypress, then do a hard reboot.
938 .
patch: mov si,bailmsg
939 call writestr
; Returns with AL = 0
940 .
drain: call pollchar
947 and al,09h ; Magic+Timeout
955 .
wait2: mov dx,[BIOS_timer
]
956 .
wait3: call pollchar
967 mov word [BIOS_magic
],0 ; Cold reboot
968 jmp 0F000h:0FFF0h
; Reset vector address
971 ; memory_scan_for_pxe_struct:
973 ; If none of the standard methods find the !PXE structure, look for it
974 ; by scanning memory.
977 ; CF = 0, ES:BX -> !PXE structure
978 ; Otherwise CF = 1, all registers saved
980 memory_scan_for_pxe_struct:
987 mov ax,[BIOS_fbm
] ; Starting segment
988 shl ax,(10-4) ; Kilobytes -> paragraphs
989 ; mov ax,01000h ; Start to look here
990 dec ax ; To skip inc ax
993 cmp ax,0A000h
; End of memory
1002 movzx cx,byte [es:4] ; Length of structure
1003 cmp cl,08h ; Minimum length
1012 jnz .mismatch
; Checksum must == 0
1015 mov [bp+8],bx ; Save BX into stack frame (will be == 0)
1023 .
not_found: mov si,notfound_msg
1031 ; memory_scan_for_pxenv_struct:
1033 ; If none of the standard methods find the PXENV+ structure, look for it
1034 ; by scanning memory.
1036 ; On exit, if found:
1037 ; CF = 0, ES:BX -> PXENV+ structure
1038 ; Otherwise CF = 1, all registers saved
1040 memory_scan_for_pxenv_struct:
1042 mov si,trymempxenv_msg
1044 ; mov ax,[BIOS_fbm] ; Starting segment
1045 ; shl ax,(10-4) ; Kilobytes -> paragraphs
1046 mov ax,01000h ; Start to look here
1047 dec ax ; To skip inc ax
1050 cmp ax,0A000h
; End of memory
1059 movzx cx,byte [es:8] ; Length of structure
1060 cmp cl,26h ; Minimum length
1068 jnz .mismatch
; Checksum must == 0
1070 mov [bp+8],bx ; Save BX into stack frame
1076 .
not_found: mov si,notfound_msg
1085 ; Open a TFTP connection to the server
1088 ; DS:DI = mangled filename
1091 ; SI = socket pointer
1092 ; DX:AX = file length in bytes
1107 call allocate_socket
1110 mov ax,PKT_RETRY
; Retry counter
1111 mov word [PktTimeout
],PKT_TIMEOUT
; Initial timeout
1113 .
sendreq: push ax ; [bp-2] - Retry counter
1114 push si ; [bp-4] - File name
1117 mov [pxe_udp_write_pkt.buffer
],di
1119 mov ax,TFTP_RRQ
; TFTP opcode
1122 lodsd ; EAX <- server override (if any)
1124 jnz .noprefix
; No prefix, and we have the server
1126 push si ; Add common prefix
1132 mov eax,[ServerIP
] ; Get default server
1135 call strcpy
; Filename
1137 mov [bx+tftp_remoteip
],eax
1139 push bx ; [bp-6] - TFTP block
1141 push bx ; [bp-8] - TID (local port no)
1143 mov [pxe_udp_write_pkt.status
],byte 0
1144 mov [pxe_udp_write_pkt.sip
],eax
1145 ; Now figure out the gateway
1151 mov [pxe_udp_write_pkt.gip
],eax
1152 mov [pxe_udp_write_pkt.lport
],bx
1154 mov [pxe_udp_write_pkt.rport
],ax
1156 mov cx,tftp_tail_len
1158 sub di,packet_buf
; Get packet size
1159 mov [pxe_udp_write_pkt.buffersize
],di
1161 mov di,pxe_udp_write_pkt
1162 mov bx,PXENV_UDP_WRITE
1165 cmp word [pxe_udp_write_pkt.status
],byte 0
1169 ; Danger, Will Robinson! We need to support timeout
1170 ; and retry lest we just lost a packet...
1173 ; Packet transmitted OK, now we need to receive
1174 .
getpacket: push word [PktTimeout
] ; [bp-10]
1175 push word [BIOS_timer
] ; [bp-12]
1177 .
pkt_loop: mov bx,[bp-8] ; TID
1179 mov word [pxe_udp_read_pkt.status
],0
1180 mov [pxe_udp_read_pkt.buffer
],di
1181 mov [pxe_udp_read_pkt.buffer
+2],ds
1182 mov word [pxe_udp_read_pkt.buffersize
],packet_buf_size
1184 mov [pxe_udp_read_pkt.dip
],eax
1185 mov [pxe_udp_read_pkt.lport
],bx
1186 mov di,pxe_udp_read_pkt
1187 mov bx,PXENV_UDP_READ
1190 jz .got_packet
; Wait for packet
1196 dec word [bp-10] ; Timeout
1198 pop ax ; Adjust stack
1200 shl word [PktTimeout
],1 ; Exponential backoff
1204 mov si,[bp-6] ; TFTP pointer
1207 mov eax,[si+tftp_remoteip
]
1208 cmp [pxe_udp_read_pkt.sip
],eax ; This is technically not to the TFTP spec?
1211 ; Got packet - reset timeout
1212 mov word [PktTimeout
],PKT_TIMEOUT
1214 pop ax ; Adjust stack
1217 mov ax,[pxe_udp_read_pkt.rport
]
1218 mov [si+tftp_remoteport
],ax
1220 ; filesize <- -1 == unknown
1221 mov dword [si+tftp_filesize
], -1
1222 ; Default blksize unless blksize option negotiated
1223 mov word [si+tftp_blksize
], TFTP_BLOCKSIZE
1225 mov cx,[pxe_udp_read_pkt.buffersize
]
1226 sub cx,2 ; CX <- bytes after opcode
1227 jb .failure
; Garbled reply
1233 je .bailnow
; ERROR reply: don't try again
1238 ; Now we need to parse the OACK packet to get the transfer
1239 ; size. SI -> first byte of options; CX -> byte count
1241 jcxz .no_tsize
; No options acked
1245 .
opt_name_loop: lodsb
1248 or al,20h ; Convert to lowercase
1251 ; We ran out, and no final null
1253 .
got_opt_name: ; si -> option value
1254 dec cx ; bytes left in pkt
1255 jz .err_reply
; Option w/o value
1257 ; Parse option pointed to by bx; guaranteed to be
1261 mov si,bx ; -> option name
1262 mov bx,tftp_opt_table
1267 mov di,[bx] ; Option pointer
1268 mov cx,[bx+2] ; Option len
1272 je .get_value
; OK, known option
1278 jmp .err_reply
; Non-negotiated option returned
1280 .
get_value: pop si ; si -> option value
1281 pop cx ; cx -> bytes left in pkt
1282 mov bx,[bx+4] ; Pointer to data target
1283 add bx,[bp-6] ; TFTP socket pointer
1291 ja .err_reply
; Not a decimal digit
1296 ; Ran out before final null, accept anyway
1301 jnz .get_opt_name
; Not end of packet
1308 pop si ; We want the packet ptr in SI
1310 mov eax,[si+tftp_filesize
]
1314 shr edx,16 ; DX:AX == EAX
1316 and eax,eax ; Set ZF depending on file size
1318 pop bp ; Junk (retry counter)
1319 jz .error_si
; ZF = 1 need to free the socket
1328 .
err_reply: ; Option negotiation error. Send ERROR reply.
1329 ; ServerIP and gateway are already programmed in
1331 mov ax,[si+tftp_remoteport
]
1332 mov word [pxe_udp_write_pkt.rport
],ax
1333 mov word [pxe_udp_write_pkt.buffer
],tftp_opt_err
1334 mov word [pxe_udp_write_pkt.buffersize
],tftp_opt_err_len
1335 mov di,pxe_udp_write_pkt
1336 mov bx,PXENV_UDP_WRITE
1339 ; Write an error message and explode
1344 .
bailnow: mov word [bp-2],1 ; Immediate error - no retry
1346 .
failure: pop bx ; Junk
1350 dec ax ; Retry counter
1351 jnz .sendreq
; Try again
1353 .
error: mov si,bx ; Socket pointer
1354 .
error_si: ; Socket pointer already in SI
1355 call free_socket
; ZF <- 1, SI <- 0
1359 ; allocate_socket: Allocate a local UDP port structure
1363 ; BX = socket pointer
1371 .
check: cmp word [bx], byte 0
1373 add bx,open_file_t_size
1378 ; Allocate a socket number. Socket numbers are made
1379 ; guaranteed unique by including the socket slot number
1380 ; (inverted, because we use the loop counter cx); add a
1381 ; counter value to keep the numbers from being likely to
1382 ; get immediately reused.
1384 ; The NextSocket variable also contains the top two bits
1385 ; set. This generates a value in the range 49152 to
1392 and ax,((1 << (13-MAX_OPEN_LG2
))-1) |
0xC000
1394 shl cx,13-MAX_OPEN_LG2
1396 xchg ch,cl ; Convert to network byte order
1397 mov [bx],cx ; Socket in use
1403 ; Free socket: socket in SI; return SI = 0, ZF = 1 for convenience
1411 mov cx,tftp_pktbuf
>> 1 ; tftp_pktbuf is not cleared
1420 ; Read a dot-quad pathname in DS:SI and output an IP
1421 ; address in EAX, with SI pointing to the first
1422 ; nonmatching character.
1424 ; Return CF=1 on error.
1438 aad ; AL += 10 * AH; AH = 0;
1453 loop .realerror
; If CX := 1 then we're done
1459 dec si ; CF unchanged!
1463 ; mangle_name: Mangle a filename pointed to by DS:SI into a buffer pointed
1464 ; to by ES:DI; ends on encountering any whitespace.
1466 ; This verifies that a filename is < FILENAME_MAX characters
1467 ; and doesn't contain whitespace, and zero-pads the output buffer,
1468 ; so "repe cmpsb" can do a compare.
1470 ; The first four bytes of the manged name is the IP address of
1471 ; the download host.
1477 je .noip
; Null filename?!?!
1478 cmp word [si],'::' ; Leading ::?
1488 ; We have a :: prefix of some sort, it could be either
1489 ; a DNS name or a dot-quad IP address. Try the dot-quad
1513 pop cx ; Adjust stack
1514 inc si ; Skip double colon
1518 stosd ; Save IP address prefix
1519 mov cx,FILENAME_MAX
-5
1523 cmp al,' ' ; If control or space, end
1528 inc cx ; At least one null byte
1529 xor ax,ax ; Zero-fill name
1530 rep stosb ; Doesn't do anything if CX=0
1534 ; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled
1535 ; filename to the conventional representation. This is needed
1536 ; for the BOOT_IMAGE= parameter for the kernel.
1537 ; NOTE: A 13-byte buffer is mandatory, even if the string is
1538 ; known to be shorter.
1540 ; DS:SI -> input mangled file name
1541 ; ES:DI -> output buffer
1543 ; On return, DI points to the first byte after the output name,
1544 ; which is set to a null byte.
1556 dec di ; Point to final null byte
1563 ; This is the main PXENV+/!PXE entry point, using the PXENV+
1564 ; calling convention. This is a separate local routine so
1565 ; we can hook special things from it if necessary. In particular,
1566 ; some PXE stacks seem to not like being invoked from anything but
1567 ; the initial stack, so humour it.
1571 %if USE_PXE_PROVIDED_STACK
== 0
1572 mov [cs:PXEStack
],sp
1573 mov [cs:PXEStack
+2],ss
1574 lss sp,[cs:InitStack
]
1576 .
jump: call 0:pxe_thunk
; Default to calling the thunk
1577 %if USE_PXE_PROVIDED_STACK
== 0
1578 lss sp,[cs:PXEStack
]
1580 cld ; Make sure DF <- 0
1583 ; Must be after function def due to NASM bug
1584 PXENVEntry
equ pxenv.jump
+1
1589 ; Convert from the PXENV+ calling convention (BX, ES, DI) to the !PXE
1590 ; calling convention (using the stack.)
1592 ; This is called as a far routine so that we can just stick it into
1593 ; the PXENVEntry variable.
1601 cmc ; Set CF unless ax == 0
1604 ; Must be after function def due to NASM bug
1605 PXEEntry
equ pxe_thunk.jump
+1
1608 ; getfssec: Get multiple clusters from a file, given the starting cluster.
1610 ; In this case, get multiple blocks from a specific TCP connection.
1614 ; SI -> TFTP socket pointer
1615 ; CX -> 512-byte block count; 0FFFFh = until end of file
1617 ; SI -> TFTP socket pointer (or 0 on EOF)
1628 shl ecx,TFTP_BLOCKSIZE_LG2
; Convert to bytes
1629 jz .hit_eof
; Nothing to do?
1634 movzx eax,word [bx+tftp_bytesleft
]
1638 jcxz .need_packet
; No bytes available?
1641 mov ax,cx ; EAX<31:16> == ECX<31:16> == 0
1642 mov si,[bx+tftp_dataptr
]
1643 sub [bx+tftp_bytesleft
],cx
1644 fs rep movsb ; Copy from packet buffer
1645 mov [bx+tftp_dataptr
],si
1656 ; Is there anything left of this?
1657 mov eax,[si+tftp_filesize
]
1658 sub eax,[si+tftp_filepos
]
1659 jnz .bytes_left
; CF <- 0
1661 cmp [si+tftp_bytesleft
],ax
1662 jnz .bytes_left
; CF <- 0
1664 ; The socket is closed and the buffer drained
1665 ; Close socket structure and re-init for next user
1672 ; No data in buffer, check to see if we can get a packet...
1676 mov eax,[bx+tftp_filesize
]
1677 cmp eax,[bx+tftp_filepos
]
1678 je .hit_eof
; Already EOF'd; socket already closed
1690 ; Get a fresh packet; expects fs -> pktbuf_seg and ds:si -> socket structure
1697 ; Start by ACKing the previous packet; this should cause the
1698 ; next packet to be sent.
1700 mov word [PktTimeout
],PKT_TIMEOUT
1702 .
send_ack: push cx ; <D> Retry count
1704 mov ax,[si+tftp_lastpkt
]
1705 call ack_packet
; Send ACK
1707 ; We used to test the error code here, but sometimes
1708 ; PXE would return negative status even though we really
1709 ; did send the ACK. Now, just treat a failed send as
1710 ; a normally lost packet, and let it time out in due
1713 .
send_ok: ; Now wait for packet.
1714 mov dx,[BIOS_timer
] ; Get current time
1717 .
wait_data: push cx ; <E> Timeout
1718 push dx ; <F> Old time
1720 mov bx,[si+tftp_pktbuf
]
1721 mov [pxe_udp_read_pkt.buffer
],bx
1722 mov [pxe_udp_read_pkt.buffer
+2],fs
1723 mov [pxe_udp_read_pkt.buffersize
],word PKTBUF_SIZE
1724 mov eax,[si+tftp_remoteip
]
1725 mov [pxe_udp_read_pkt.sip
],eax
1727 mov [pxe_udp_read_pkt.dip
],eax
1728 mov ax,[si+tftp_remoteport
]
1729 mov [pxe_udp_read_pkt.rport
],ax
1730 mov ax,[si+tftp_localport
]
1731 mov [pxe_udp_read_pkt.lport
],ax
1732 mov di,pxe_udp_read_pkt
1733 mov bx,PXENV_UDP_READ
1740 ; No packet, or receive failure
1742 pop ax ; <F> Old time
1743 pop cx ; <E> Timeout
1744 cmp ax,dx ; Same time -> don't advance timeout
1745 je .wait_data
; Same clock tick
1746 loop .wait_data
; Decrease timeout
1748 pop cx ; <D> Didn't get any, send another ACK
1749 shl word [PktTimeout
],1 ; Exponential backoff
1751 jmp kaboom
; Forget it...
1753 .
recv_ok: pop dx ; <F>
1756 cmp word [pxe_udp_read_pkt.buffersize
],byte 4
1757 jb .wait_data
; Bad size for a DATA packet
1759 mov bx,[si+tftp_pktbuf
]
1760 cmp word [fs:bx],TFTP_DATA
; Not a data packet?
1761 jne .wait_data
; Then wait for something else
1763 mov ax,[si+tftp_lastpkt
]
1764 xchg ah,al ; Host byte order
1765 inc ax ; Which packet are we waiting for?
1766 xchg ah,al ; Network byte order
1770 ; Wrong packet, ACK the packet and then try again
1771 ; This is presumably because the ACK got lost,
1772 ; so the server just resent the previous packet
1775 jmp .send_ok
; Reset timeout
1777 .
right_packet: ; It's the packet we want. We're also EOF if the size < blocksize
1779 pop cx ; <D> Don't need the retry count anymore
1781 mov [si+tftp_lastpkt
],ax ; Update last packet number
1783 movzx ecx,word [pxe_udp_read_pkt.buffersize
]
1784 sub cx,byte 4 ; Skip TFTP header
1786 ; If this is a zero-length block, don't mess with the pointers,
1787 ; since we may have just set up the previous block that way
1790 ; Set pointer to data block
1791 lea ax,[bx+4] ; Data past TFTP header
1792 mov [si+tftp_dataptr
],ax
1794 add [si+tftp_filepos
],ecx
1795 mov [si+tftp_bytesleft
],cx
1797 cmp cx,[si+tftp_blksize
] ; Is it a full block?
1798 jb .last_block
; If so, it's not EOF
1800 ; If we had the exact right number of bytes, always get
1801 ; one more packet to get the (zero-byte) EOF packet and
1803 mov eax,[si+tftp_filepos
]
1804 cmp [si+tftp_filesize
],eax
1810 .
last_block: ; Last block - ACK packet immediately
1814 ; Make sure we know we are at end of file
1815 mov eax,[si+tftp_filepos
]
1816 mov [si+tftp_filesize
],eax
1823 ; Send ACK packet. This is a common operation and so is worth canning.
1827 ; AX = Packet # to ack (network byte order)
1830 ; All registers preserved
1832 ; This function uses the pxe_udp_write_pkt but not the packet_buf.
1836 mov [ack_packet_buf
+2],ax ; Packet number to ack
1838 mov [pxe_udp_write_pkt.lport
],ax
1839 mov ax,[si+tftp_remoteport
]
1840 mov [pxe_udp_write_pkt.rport
],ax
1841 mov eax,[si+tftp_remoteip
]
1842 mov [pxe_udp_write_pkt.sip
],eax
1848 mov [pxe_udp_write_pkt.gip
],eax
1849 mov [pxe_udp_write_pkt.buffer
],word ack_packet_buf
1850 mov [pxe_udp_write_pkt.buffersize
], word 4
1851 mov di,pxe_udp_write_pkt
1852 mov bx,PXENV_UDP_WRITE
1854 cmp ax,byte 0 ; ZF = 1 if write OK
1861 ; This function unloads the PXE and UNDI stacks and unclaims
1865 test byte [KeepPXE
],01h ; Should we keep PXE around?
1875 mov si,new_api_unload
1876 cmp byte [APIVer
+1],2 ; Major API version >= 2?
1878 mov si,old_api_unload
1881 .
call_loop: xor ax,ax
1886 mov di,pxe_unload_stack_pkt
1889 mov cx,pxe_unload_stack_pkt_len
>> 1
1894 mov ax,word [pxe_unload_stack_pkt.status
]
1895 cmp ax,PXENV_STATUS_SUCCESS
1901 ; This isn't necessary anymore; we can use the memory area previously
1902 ; used by the PXE stack indefinitely, and the chainload code sets up
1903 ; a new stack independently. Leave the source code in here for now,
1904 ; but expect to rip it out soonish.
1906 %if
0 ; USE_PXE_PROVIDED_STACK
1907 ; We need to switch to our local stack here...
1915 sub ax,[BaseStack
+4] ; Are we using the base stack
1916 je .is_base_stack
; (as opposed to the COMBOOT stack)?
1918 lgs si,[SavedSSSP
] ; COMBOOT stack
1924 mov [BaseStack
+4],es
1927 mov [SavedSSSP
],di ; New SP
1928 mov [SavedSSSP
+2],es
1931 and ax,ax ; Remember which stack
1934 ; Update the base stack pointer since it's in use
1944 mov dx,[RealBaseMem
]
1945 cmp dx,[BIOS_fbm
] ; Sanity check
1949 ; Check that PXE actually unhooked the INT 1Ah chain
1950 movzx eax,word [4*0x1a]
1951 movzx ecx,word [4*0x1a+2]
1955 cmp ax,dx ; Not in range
1969 mov si,cant_free_msg
1985 ; We want to keep PXE around, but still we should reset
1986 ; it to the standard bootup configuration
1991 mov bx,PXENV_UDP_CLOSE
1992 mov di,pxe_udp_close_pkt
2000 ; Take an IP address (in network byte order) in EAX and
2001 ; output a dotted quad string to ES:DI.
2002 ; DI points to terminal null at end of string on exit.
2011 jb .lt10
; If so, skip first 2 digits
2014 jb .lt100
; If so, skip first digit
2017 ; Now AH = 100-digit; AL = remainder
2024 ; Now AH = 10-digit; AL = remainder
2035 ror eax,8 ; Move next char into LSB
2046 ; Parse a DHCP packet. This includes dealing with "overloaded"
2047 ; option fields (see RFC 2132, section 9.3)
2049 ; This should fill in the following global variables, if the
2050 ; information is present:
2052 ; MyIP - client IP address
2053 ; ServerIP - boot server IP address
2054 ; Netmask - network mask
2055 ; Gateway - default gateway router IP
2056 ; BootFile - boot file name
2057 ; DNSServers - DNS server IPs
2058 ; LocalDomain - Local domain name
2060 ; This assumes the DHCP packet is in "trackbuf" and the length
2061 ; of the packet in in CX on entry.
2065 mov byte [OverLoad
],0 ; Assume no overload
2066 mov eax, [trackbuf
+bootp.yip
]
2069 cmp al,224 ; Class D or higher -> bad
2073 mov eax, [trackbuf
+bootp.sip
]
2076 cmp al,224 ; Class D or higher -> bad
2080 sub cx, bootp.options
2082 mov si, trackbuf
+bootp.option_magic
2084 cmp eax, BOOTP_OPTION_MAGIC
2086 call parse_dhcp_options
2088 mov si, trackbuf
+bootp.bootfile
2089 test byte [OverLoad
],1
2092 call parse_dhcp_options
2093 jmp short .parsed_file
2096 jz .parsed_file
; No bootfile name
2101 stosb ; Null-terminate
2103 mov si, trackbuf
+bootp.sname
2104 test byte [OverLoad
],2
2107 call parse_dhcp_options
2112 ; Parse a sequence of DHCP options, pointed to by DS:SI; the field
2113 ; size is CX -- some DHCP servers leave option fields unterminated
2114 ; in violation of the spec.
2116 ; For parse_some_dhcp_options, DH contains the minimum value for
2117 ; the option to recognize -- this is used to restrict parsing to
2118 ; PXELINUX-specific options only.
2123 parse_some_dhcp_options:
2130 jz .done
; Last byte; must be PAD, END or malformed
2131 cmp al, 0 ; PAD option
2133 cmp al,255 ; END option
2136 ; Anything else will have a length field
2137 mov dl,al ; DL <- option number
2139 lodsb ; AX <- option length
2141 sub cx,ax ; Decrement bytes left counter
2142 jb .done
; Malformed option: length > field size
2144 cmp dl,dh ; Is the option value valid?
2147 cmp dl,1 ; SUBNET MASK option
2154 cmp dl,3 ; ROUTER option
2161 cmp dl,6 ; DNS SERVERS option
2166 cmp cl,DNS_MAX_SERVERS
2168 mov cl,DNS_MAX_SERVERS
2172 mov [LastDNSServer
],di
2177 cmp dl,15 ; DNS LOCAL DOMAIN option
2178 jne .not_localdomain
2183 xchg [bx],al ; Zero-terminate option
2185 call dns_mangle
; Convert to DNS label set
2186 mov [bx],al ; Restore ending byte
2191 cmp dl,43 ; VENDOR ENCAPSULATED option
2194 mov dh,208 ; Only recognize PXELINUX options
2195 mov cx,ax ; Length of option = max bytes to parse
2196 call parse_some_dhcp_options
; Parse recursive structure
2201 cmp dl,52 ; OPTION OVERLOAD option
2208 cmp dl,67 ; BOOTFILE NAME option
2211 jmp short .copyoption
2213 ret ; This is here to make short jumps easier
2216 cmp dl,208 ; PXELINUX MAGIC option
2218 cmp al,4 ; Must have length == 4
2220 cmp dword [si], htonl
(0xF100747E) ; Magic number
2222 or byte [DHCPMagic
], byte 1 ; Found magic #
2226 cmp dl,209 ; PXELINUX CONFIGFILE option
2229 or byte [DHCPMagic
], byte 2 ; Got config file
2230 jmp short .copyoption
2233 cmp dl,210 ; PXELINUX PATHPREFIX option
2236 or byte [DHCPMagic
], byte 4 ; Got path prefix
2237 jmp short .copyoption
2240 cmp dl,211 ; PXELINUX REBOOTTIME option
2245 xchg bl,bh ; Convert to host byte order
2248 mov [RebootTime
],ebx
2249 or byte [DHCPMagic
], byte 8 ; Got RebootTime
2250 ; jmp short .opt_done
2253 ; Unknown option. Skip to the next one.
2259 ; Common code for copying an option verbatim
2263 xchg cx,ax ; Now ax == 0
2264 stosb ; Null-terminate
2265 jmp short .opt_done_noskip
2270 ; Generate an ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
2271 ; option into IPOption based on a DHCP packet in trackbuf.
2272 ; Assumes CS == DS == ES.
2293 call gendotquad
; Zero-terminates its output
2295 mov [IPOptionLen
],di
2300 ; Call the receive loop while idle. This is done mostly so we can respond to
2301 ; ARP messages, but perhaps in the future this can be used to do network
2304 ; hpa sez: people using automatic control on the serial port get very
2305 ; unhappy if we poll for ARP too often (the PXE stack is pretty slow,
2306 ; typically.) Therefore, only poll if at least 4 BIOS timer ticks have
2307 ; passed since the last poll, and reset this when a character is
2308 ; received (RESET_IDLE).
2312 mov ax,[cs:BIOS_timer
]
2313 mov [cs:IdleTimer
],ax
2319 mov ax,[cs:BIOS_timer
]
2320 sub ax,[cs:IdleTimer
]
2332 mov [pxe_udp_read_pkt.status
],al ; 0
2333 mov [pxe_udp_read_pkt.buffer
],di
2334 mov [pxe_udp_read_pkt.buffer
+2],ds
2335 mov word [pxe_udp_read_pkt.buffersize
],packet_buf_size
2337 mov [pxe_udp_read_pkt.dip
],eax
2338 mov word [pxe_udp_read_pkt.lport
],htons
(9) ; discard port
2339 mov di,pxe_udp_read_pkt
2340 mov bx,PXENV_UDP_READ
2349 ; -----------------------------------------------------------------------------
2351 ; -----------------------------------------------------------------------------
2353 %include "getc.inc" ; getc et al
2354 %include "conio.inc" ; Console I/O
2355 %include "writestr.inc" ; String output
2356 writestr
equ cwritestr
2357 %include "writehex.inc" ; Hexadecimal output
2358 %include "parseconfig.inc" ; High-level config file handling
2359 %include "parsecmd.inc" ; Low-level config file handling
2360 %include "bcopy32.inc" ; 32-bit bcopy
2361 %include "loadhigh.inc" ; Load a file into high memory
2362 %include "font.inc" ; VGA font stuff
2363 %include "graphics.inc" ; VGA graphics
2364 %include "highmem.inc" ; High memory sizing
2365 %include "strcpy.inc" ; strcpy()
2366 %include "rawcon.inc" ; Console I/O w/o using the console functions
2367 %include "dnsresolv.inc" ; DNS resolver
2369 ; -----------------------------------------------------------------------------
2370 ; Begin data section
2371 ; -----------------------------------------------------------------------------
2375 hextbl_lower
db '0123456789abcdef'
2376 copyright_str
db ' Copyright (C) 1994-', year
, ' H. Peter Anvin'
2378 boot_prompt
db 'boot: ', 0
2379 wipe_char
db BS
, ' ', BS
, 0
2380 err_notfound
db 'Could not find kernel image: ',0
2381 err_notkernel
db CR
, LF
, 'Invalid or corrupt kernel image.', CR
, LF
, 0
2382 err_noram
db 'It appears your computer has less than '
2384 db 'K of low ("DOS")'
2386 db 'RAM. Linux needs at least this amount to boot. If you get'
2388 db 'this message in error, hold down the Ctrl key while'
2390 db 'booting, and I will take your word for it.', CR
, LF
, 0
2391 err_badcfg
db 'Unknown keyword in config file.', CR
, LF
, 0
2392 err_noparm
db 'Missing parameter in config file.', CR
, LF
, 0
2393 err_noinitrd
db CR
, LF
, 'Could not find ramdisk image: ', 0
2394 err_nohighmem
db 'Not enough memory to load specified kernel.', CR
, LF
, 0
2395 err_highload
db CR
, LF
, 'Kernel transfer failure.', CR
, LF
, 0
2396 err_oldkernel
db 'Cannot load a ramdisk with an old kernel image.'
2398 err_notdos
db ': attempted DOS system call', CR
, LF
, 0
2399 err_comlarge
db 'COMBOOT image too large.', CR
, LF
, 0
2400 err_bssimage
db 'BSS images not supported.', CR
, LF
, 0
2401 err_a20
db CR
, LF
, 'A20 gate not responding!', CR
, LF
, 0
2402 err_bootfailed
db CR
, LF
, 'Boot failed: press a key to retry, or wait for reset...', CR
, LF
, 0
2403 bailmsg
equ err_bootfailed
2404 err_nopxe
db "No !PXE or PXENV+ API found; we're dead...", CR
, LF
, 0
2405 err_pxefailed
db 'PXE API call failed, error ', 0
2406 err_udpinit
db 'Failed to initialize UDP stack', CR
, LF
, 0
2407 err_oldtftp
db 'TFTP server does not support the tsize option', CR
, LF
, 0
2408 found_pxenv
db 'Found PXENV+ structure', CR
, LF
, 0
2409 using_pxenv_msg
db 'Old PXE API detected, using PXENV+ structure', CR
, LF
, 0
2410 apiver_str
db 'PXE API version is ',0
2411 pxeentry_msg
db 'PXE entry point found (we hope) at ', 0
2412 pxenventry_msg
db 'PXENV entry point found (we hope) at ', 0
2413 trymempxe_msg
db 'Scanning memory for !PXE structure... ', 0
2414 trymempxenv_msg
db 'Scanning memory for PXENV+ structure... ', 0
2415 undi_data_msg
db 'UNDI data segment at: ',0
2416 undi_data_len_msg
db 'UNDI data segment size: ',0
2417 undi_code_msg
db 'UNDI code segment at: ',0
2418 undi_code_len_msg
db 'UNDI code segment size: ',0
2419 cant_free_msg
db 'Failed to free base memory, error ', 0
2420 notfound_msg
db 'not found', CR
, LF
, 0
2421 myipaddr_msg
db 'My IP address seems to be ',0
2422 tftpprefix_msg
db 'TFTP prefix: ', 0
2423 localboot_msg
db 'Booting from local disk...', CR
, LF
, 0
2424 cmdline_msg
db 'Command line: ', CR
, LF
, 0
2425 ready_msg
db 'Ready.', CR
, LF
, 0
2426 trying_msg
db 'Trying to load: ', 0
2427 crlfloading_msg
db CR
, LF
; Fall through
2428 loading_msg
db 'Loading ', 0
2431 fourbs_msg
db BS
, BS
, BS
, BS
, 0
2432 aborted_msg
db ' aborted.' ; Fall through to crlf_msg!
2435 crff_msg
db CR
, FF
, 0
2436 default_str
db 'default', 0
2437 default_len
equ ($
-default_str
)
2438 syslinux_banner
db CR
, LF
, 'PXELINUX ', version_str
, ' ', date
, ' ', 0
2439 cfgprefix
db 'pxelinux.cfg/' ; No final null!
2440 cfgprefix_len
equ ($
-cfgprefix
)
2443 ; Command line options we'd like to take a look at
2445 ; mem= and vga= are handled as normal 32-bit integer values
2446 initrd_cmd
db 'initrd='
2447 initrd_cmd_len
equ $
-initrd_cmd
2449 ; This one we make ourselves
2450 bootif_str
db 'BOOTIF='
2451 bootif_str_len
equ $
-bootif_str
2453 ; Config file keyword table
2455 %include "keywords.inc"
2458 ; Extensions to search for (in *forward* order).
2459 ; (.bs and .bss are disabled for PXELINUX, since they are not supported)
2462 exten_table: db '.cbt' ; COMBOOT (specific)
2463 db '.0', 0, 0 ; PXE bootstrap program
2464 db '.com' ; COMBOOT (same as DOS)
2467 dd 0, 0 ; Need 8 null bytes here
2470 ; PXE unload sequences
2474 db PXENV_UNDI_SHUTDOWN
2475 db PXENV_UNLOAD_STACK
2480 db PXENV_UNDI_SHUTDOWN
2481 db PXENV_UNLOAD_STACK
2482 db PXENV_UNDI_CLEANUP
2486 ; PXE query packets partially filled in
2488 pxe_bootp_query_pkt_2:
2489 .
status: dw 0 ; Status
2490 .
packettype: dw 2 ; DHCPACK packet
2491 .
buffersize: dw trackbufsize
; Packet size
2492 .
buffer: dw trackbuf
, 0 ; seg:off of buffer
2493 .
bufferlimit: dw trackbufsize
; Unused
2495 pxe_bootp_query_pkt_3:
2496 .
status: dw 0 ; Status
2497 .
packettype: dw 3 ; Boot server packet
2498 .
buffersize: dw trackbufsize
; Packet size
2499 .
buffer: dw trackbuf
, 0 ; seg:off of buffer
2500 .
bufferlimit: dw trackbufsize
; Unused
2502 pxe_bootp_size_query_pkt:
2503 .
status: dw 0 ; Status
2504 .
packettype: dw 2 ; DHCPACK packet
2505 .
buffersize: dw 0 ; Packet size
2506 .
buffer: dw 0, 0 ; seg:off of buffer
2507 .
bufferlimit: dw 0 ; Unused
2510 .
status: dw 0 ; Status
2511 .
sip: dd 0 ; Source (our) IP
2514 .
status: dw 0 ; Status
2517 .
status: dw 0 ; Status
2518 .
sip: dd 0 ; Server IP
2519 .
gip: dd 0 ; Gateway IP
2520 .
lport: dw 0 ; Local port
2521 .
rport: dw 0 ; Remote port
2522 .
buffersize: dw 0 ; Size of packet
2523 .
buffer: dw 0, 0 ; seg:off of buffer
2526 .
status: dw 0 ; Status
2527 .
sip: dd 0 ; Source IP
2528 .
dip: dd 0 ; Destination (our) IP
2529 .
rport: dw 0 ; Remote port
2530 .
lport: dw 0 ; Local port
2531 .
buffersize: dw 0 ; Max packet size
2532 .
buffer: dw 0, 0 ; seg:off of buffer
2535 ; Misc initialized (data) variables
2538 BaseStack
dd StackBuf
; ESP of base stack
2539 dw 0 ; SS of base stack
2540 NextSocket
dw 49152 ; Counter for allocating socket numbers
2541 KeepPXE
db 0 ; Should PXE be kept around?
2546 tftp_tail
db 'octet', 0 ; Octet mode
2547 tsize_str
db 'tsize' ,0 ; Request size
2548 tsize_len
equ ($
-tsize_str
)
2550 blksize_str
db 'blksize', 0 ; Request large blocks
2551 blksize_len
equ ($
-blksize_str
)
2552 asciidec TFTP_LARGEBLK
2554 tftp_tail_len
equ ($
-tftp_tail
)
2558 ; Options negotiation parsing table (string pointer, string len, offset
2559 ; into socket structure)
2562 dw tsize_str
, tsize_len
, tftp_filesize
2563 dw blksize_str
, blksize_len
, tftp_blksize
2564 tftp_opts
equ ($
-tftp_opt_table
)/6
2567 ; Error packet to return on options negotiation error
2569 tftp_opt_err
dw TFTP_ERROR
; ERROR packet
2570 dw TFTP_EOPTNEG
; ERROR 8: bad options
2571 db 'tsize option required', 0 ; Error message
2572 tftp_opt_err_len
equ ($
-tftp_opt_err
)
2575 ack_packet_buf: dw TFTP_ACK
, 0 ; TFTP ACK packet
2578 ; IP information (initialized to "unknown" values)
2579 MyIP
dd 0 ; My IP address
2580 ServerIP
dd 0 ; IP address of boot server
2581 Netmask
dd 0 ; Netmask of this subnet
2582 Gateway
dd 0 ; Default router
2583 ServerPort
dw TFTP_PORT
; TFTP server port
2586 ; Variables that are uninitialized in SYSLINUX but initialized here
2589 BufSafe
dw trackbufsize
/TFTP_BLOCKSIZE
; Clusters we can load into trackbuf
2590 BufSafeSec
dw trackbufsize
/512 ; = how many sectors?
2591 BufSafeBytes
dw trackbufsize
; = how many bytes?
2592 EndOfGetCBuf
dw getcbuf
+trackbufsize
; = getcbuf+BufSafeBytes
2594 %if
( trackbufsize
% TFTP_BLOCKSIZE
) != 0
2595 %error trackbufsize must be a multiple of TFTP_BLOCKSIZE
2598 IPAppend
db 0 ; Default IPAPPEND option
2599 DHCPMagic
db 0 ; DHCP site-specific option info