# bootp.S86 - BOOTP record handling routines for netboot boot images # # Copyright (C) 2002-2003 Gero Kuhlmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # $Id: bootp.S86,v 1.1 2003/03/09 00:43:08 gkminix Exp $ # #==================================================================== # #include "common.i86" #include "bootp.i86" .file "bootp.S86" .line 30 # #==================================================================== # # Define the text segment and all public entry points # \(.text) .global btpini # define global symbols .global btptag # #==================================================================== # # Initialize BOOTP/DHCP record handling. We need to copy the # whole record out of the bootrom area. # Input: FS:SI - Pointer to bootp record # Output: SI - Offset to error message, zero if none # Changed registers: AX, BX, CX, DX, SI, DI # btpini: cmp byte ptr fs:BOOTP_OP[si],BOOTP_REPLY jne btpi1 # op code must indicate reply cmp dword ptr fs:BOOTP_VEND[si],BOOTP_MAGIC_RFC je btpi2 # vendor area must have valid magic ID btpi1: mov si,offset noberr jmp btpi9 btpi2: cld push ds mov ax,fs mov ds,ax mov bx,si xor cx,cx # CX is NOP counter add si,BOOTP_VEND + BOOTP_MAGIC_LEN btpi4: lodsb cmp al,BOOTP_RFC_NOP # handle NOP tag jne btpi5 inc cx cmp cx,16 # more than 16 NOP tags is VERY unusual jb btpi4 # so the bootp record maybe broken btpi8: pop ds mov si,offset btperr jmp btpi9 btpi5: cmp al,BOOTP_RFC_END # handle END tag jne btpi6 mov dx,si sub dx,bx # compute length of bootp record cmp dx,BOOTP_SIZE jae btpi7 mov dx,BOOTP_SIZE # use minimum size jmp btpi7 btpi6: lodsb # handle all other tags movzx cx,al add si,cx # jump to next tag xor cx,cx # reset NOP counter jmp btpi4 # proceed with next tag btpi7: cmp dx,MAX_BOOTP_LEN # check if BOOTP records fits jae btpi8 mov cx,dx mov si,bx # restore source pointer mov di,offset bootpbuf rep movsb # save the bootp record pop ds mov [bootplen],dx # set length of bootp record xor si,si # return with no error btpi9: ret # #==================================================================== # # Find a vendor tag in the BOOTP record. # Input: AL - Tag number # Output: DS:DI - Pointer to tag string # CX - String length (zero if tag not found) # Changed registers: AX, CX, DI # btptag: push si push bx mov di,offset bootpbuf mov si,di add si,[bootplen] # let DS:SI point to last bootp byte add di,BOOTP_VEND + BOOTP_MAGIC_LEN xor bx,bx btpt1: mov ah,[di] # load current vendor tag inc di cmp ah,BOOTP_RFC_NOP # NOP tag --> continue je btpt1 cmp ah,BOOTP_RFC_END # END tag --> abort je btpt3 movzx cx,byte ptr [di] # get length of current tag inc di cmp al,ah # we got our tag je btpt9 or bx,bx # check for overload flag only once jnz btpt2 cmp ah,BOOTP_RFC_OVRLD # check for option overload jne btpt2 mov bl,[di] # get option overload flag inc bh # set to not accept another overload btpt2: add di,cx # proceed with next tag cmp di,si jb btpt1 # got at end of bootp record btpt3: test bl,BOOTP_OVR_FILE jz btpt4 mov di,offset bootpbuf + BOOTP_FILE mov si,di # scan file section of BOOTP record add si,BOOTP_VEND - BOOTP_FILE and bl,0 - BOOTP_OVR_FILE - 1 jmp btpt1 btpt4: test bl,BOOTP_OVR_SNAME jz btpt8 mov di,offset bootpbuf + BOOTP_SNAME mov si,di # scan server name section add si,BOOTP_FILE - BOOTP_SNAME and bl,0 - BOOTP_OVR_SNAME - 1 jmp btpt1 btpt8: xor cx,cx btpt9: pop bx pop si ret # #==================================================================== # # String and constants definitions # \(.data) # Error messages noberr: .asciz "BOOTP/DHCP record missing" btperr: .asciz "BOOTP/DHCP record too large" # #==================================================================== # # Variable definitions # \(.bss) .global bootplen # define global symbols .global bootpbuf .lcomm bootplen,2 # length of bootp record .lcomm bootpbuf,MAX_BOOTP_LEN # space to hold BOOTP record # #==================================================================== # .end