PXELINUX: Print an error message if the config file is not found
[syslinux.git] / parseconfig.inc
blobaef31613387c48c949beb8ed7391718a383ec47b
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2004 H. Peter Anvin - All Rights Reserved
4 ;;
5 ;;   This program is free software; you can redistribute it and/or modify
6 ;;   it under the terms of the GNU General Public License as published by
7 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
14 ;; parseconfig.inc
16 ;; Configuration file operations
19                 section .text
21 ; "default" command
23 pc_default:     mov di,default_cmd
24                 call getline
25                 mov byte [di-1],0               ; null-terminate
26                 ret
29 ; "ontimeout" command
31 pc_ontimeout:   mov di,Ontimeout
32                 call getline
33                 sub di,Ontimeout+1              ; Don't need final space
34                 mov [OntimeoutLen],di
35                 ret
38 ; "onerror" command
40 pc_onerror:     mov di,Onerror
41                 call getline
42                 sub di,Onerror
43                 mov [OnerrorLen],di
44                 ret
47 ; "append" command
49 pc_append:      cmp byte [VKernel],0
50                 ja .vk
51                 mov di,AppendBuf
52                 call getline
53                 sub di,AppendBuf
54 .app1:          mov [AppendLen],di
55                 ret
56 .vk:            mov di,VKernelBuf+vk_append     ; "append" command (vkernel)
57                 call getline
58                 sub di,VKernelBuf+vk_append
59                 cmp di,byte 2
60                 jne .app2
61                 cmp byte [VKernelBuf+vk_append],'-'
62                 jne .app2
63                 xor di,di                       ; If "append -" -> null string
64 .app2:          mov [VKernelBuf+vk_appendlen],di
65                 ret
68 ; "ipappend" command (PXELINUX only)
70 %if IS_PXELINUX
71 pc_ipappend:    call getint
72                 jc .err
73                 cmp byte [VKernel],0
74                 jne .vk
75                 mov [IPAppend],bl
76 .err:           ret
77 .vk:            mov [VKernelBuf+vk_ipappend],bl
78                 ret
79 %endif
82 ; "localboot" command (PXELINUX, ISOLINUX)
84 %if IS_PXELINUX || IS_ISOLINUX
85 pc_localboot:   call getint
86                 cmp byte [VKernel],0            ; ("label" section only)
87                 je .err
88                 mov di,VKernelBuf+vk_rname
89                 xor ax,ax
90                 mov cx,FILENAME_MAX
91                 rep stosb                       ; Null kernel name
92 %if IS_PXELINUX
93                 ; PXELINUX uses the first 4 bytes of vk_rname for the
94                 ; mangled IP address
95                 mov [VKernelBuf+vk_rname+5], bx ; Return type
96 %else
97                 mov [VKernelBuf+vk_rname+1], bx ; Return type
98 %endif
99 .err:           ret
100 %endif
103 ; "kernel" command
104 pc_kernel:      cmp byte [VKernel],0
105                 je .err                         ; ("label" section only)
106                 call pc_getline
107                 mov di,VKernelBuf+vk_rname
108                 call mangle_name
109 .err:           ret
112 ; "timeout", "totaltimeout" command
114 ; N.B. 1/10 s ~ 1.D2162AABh clock ticks
116 pc_timeout:     push ax
117                 call getint
118                 pop si
119                 jc .err
120                 mov eax,0D2162AABh
121                 mul ebx                         ; clock ticks per 1/10 s
122                 add ebx,edx
123                 mov [si],ebx
124 .err:           ret
128 ; "totaltimeout" command
130 pc_totaltimeout:
133 ; Generic integer variable setting commands:
134 ; "prompt", "implicit"
136 pc_setint16:
137                 push ax
138                 call getint
139                 pop si
140                 jc .err
141                 mov [si],bx
142 .err:           ret
145 ; Generic file-processing commands:
146 ; "display", "font", "kbdmap"
148 pc_filecmd:     push ax                         ; Function to tailcall
149                 call pc_getline
150                 mov di,MNameBuf
151                 push di
152                 call mangle_name
153                 pop di
154                 call searchdir                  ; tailcall
155                 jnz .ok
156                 pop ax                          ; Drop the successor function
157 .ok:            ret                             ; Tailcall if OK, error return
160 ; "serial" command
162 pc_serial:      call getint
163                 jc .err
164                 push bx                         ; Serial port #
165                 call skipspace
166                 jnc .ok
167                 pop bx
168 .err:           ret
169 .ok:
170                 call ungetc
171                 call getint
172                 mov [FlowControl], word 0       ; Default to no flow control
173                 jc .nobaud
174 .valid_baud:
175                 push ebx
176                 call skipspace
177                 jc .no_flow
178                 call ungetc
179                 call getint                     ; Hardware flow control?
180                 jnc .valid_flow
181 .no_flow:
182                 xor bx,bx                       ; Default -> no flow control
183 .valid_flow:
184                 and bh,0Fh                      ; FlowIgnore
185                 shl bh,4
186                 mov [FlowIgnore],bh
187                 mov bh,bl
188                 and bx,0F003h                   ; Valid bits
189                 mov [FlowControl],bx
190                 pop ebx                         ; Baud rate
191                 jmp short .parse_baud
192 .nobaud:
193                 mov ebx,DEFAULT_BAUD            ; No baud rate given
194 .parse_baud:
195                 pop di                          ; Serial port #
196                 cmp ebx,byte 75
197                 jb .err                         ; < 75 baud == bogus
198                 mov eax,BAUD_DIVISOR
199                 cdq
200                 div ebx
201                 mov [BaudDivisor],ax
202                 push ax                         ; Baud rate divisor
203                 cmp di,3
204                 ja .port_is_io                  ; If port > 3 then port is I/O addr
205                 shl di,1
206                 mov di,[di+serial_base]         ; Get the I/O port from the BIOS
207 .port_is_io:
208                 mov [SerialPort],di
210                 ;
211                 ; Begin code to actually set up the serial port
212                 ;
213                 lea dx,[di+3]                   ; DX -> LCR
214                 mov al,83h                      ; Enable DLAB
215                 call slow_out
217                 pop ax                          ; Divisor
218                 mov dx,di                       ; DX -> LS
219                 call slow_out
221                 inc dx                          ; DX -> MS
222                 mov al,ah
223                 call slow_out
225                 mov al,03h                      ; Disable DLAB
226                 inc dx                          ; DX -> LCR
227                 inc dx
228                 call slow_out
230                 in al,dx                        ; Read back LCR (detect missing hw)
231                 cmp al,03h                      ; If nothing here we'll read 00 or FF
232                 jne .serial_port_bad            ; Assume serial port busted
233                 dec dx
234                 dec dx                          ; DX -> IER
235                 xor al,al                       ; IRQ disable
236                 call slow_out
238                 inc dx                          ; DX -> FCR/IIR
239                 mov al,01h
240                 call slow_out                   ; Enable FIFOs if present
241                 in al,dx
242                 cmp al,0C0h                     ; FIFOs enabled and usable?
243                 jae .fifo_ok
244                 xor ax,ax                       ; Disable FIFO if unusable
245                 call slow_out
246 .fifo_ok:
248                 inc dx
249                 inc dx                          ; DX -> MCR
250                 in al,dx
251                 or al,[FlowOutput]              ; Assert bits
252                 call slow_out
254                 ; Show some life
255                 mov si,syslinux_banner
256                 call write_serial_str
257                 mov si,copyright_str
258                 call write_serial_str
259                 ret
261 .serial_port_bad:
262                 mov [SerialPort], word 0
263                 ret
266 ; "F"-key command
268 pc_fkey:        push ax
269                 call pc_getline
270                 pop di
271                 call mangle_name                ; Mangle file name
272                 ret
275 ; "label" command
277 pc_label:       call commit_vk                  ; Commit any current vkernel
278                 mov di,VKernelBuf               ; Erase the vkernelbuf for better compression
279                 mov cx,(vk_size >> 1)
280                 xor ax,ax
281                 rep stosw
282                 call pc_getline
283                 mov di,VKernelBuf+vk_vname
284                 call mangle_name                ; Mangle virtual name
285                 mov byte [VKernel],1            ; We've seen a "label" statement
286                 mov si,VKernelBuf+vk_vname      ; By default, rname == vname
287                 mov di,VKernelBuf+vk_rname
288                 mov cx,FILENAME_MAX
289                 rep movsb
290                 mov si,AppendBuf                ; Default append==global append
291                 mov di,VKernelBuf+vk_append
292                 mov cx,[AppendLen]
293                 mov [VKernelBuf+vk_appendlen],cx
294                 rep movsb
295 %if IS_PXELINUX                                 ; PXELINUX only
296                 mov al,[IPAppend]               ; Default ipappend==global ipappend
297                 mov [VKernelBuf+vk_ipappend],al
298 %endif
299                 ret
302 ; "say" command
304 pc_say:         call pc_getline                 ; "say" command
305                 call writestr
306                 jmp crlf                        ; tailcall
309 ; Comment line
311 pc_comment:     ; Fall into pc_getline
314 ; Common subroutine: load line into trackbuf; returns with SI -> trackbuf
316 pc_getline:     mov di,trackbuf
317                 push di
318                 call getline
319                 xor al,al
320                 stosb                           ; Null-terminate
321                 pop si
322                 ret
325 ; Main loop for configuration file parsing
327 parse_config:
328                 mov di,VKernelBuf               ; Clear VKernelBuf at start
329                 xor ax,ax
330                 mov cx,vk_size
331                 rep stosb
332 .again:
333                 call getcommand
334                 jnc .again                      ; If not EOF do it again
335                 ;
336                 ; The fall through to commit_vk to commit any final
337                 ; VKernel being read
338                 ;
340 ; commit_vk: Store the current VKernelBuf into buffer segment
342 commit_vk:
343                 ; For better compression, clean up the append field
344                 mov ax,[VKernelBuf+vk_appendlen]
345                 mov di,VKernelBuf+vk_append
346                 add di,ax
347                 mov cx,max_cmd_len+1
348                 sub cx,ax
349                 xor ax,ax
350                 rep stosb
352                 ; Pack temporarily into trackbuf
353                 mov si,VKernelBuf
354                 mov di,trackbuf
355                 mov cx,vk_size
356                 call rllpack
357                 ; Now DX = number of bytes
358                 mov di,[VKernelBytes]
359                 mov cx,dx
360                 add dx,di
361                 jc .overflow                    ; If > 1 segment
362                 mov [VKernelBytes],dx
363                 mov si,trackbuf
364                 push es
365                 push word vk_seg
366                 pop es
367                 rep movsb
368                 pop es
369                 ret
370 .overflow:
371                 mov si,vk_overflow_msg
372                 call writestr
373                 ret
375                 section .data
376 vk_overflow_msg db 'Out of memory parsing config file', CR, LF, 0
378                 align 4, db 0
379 KbdTimeout      dd 0                    ; Keyboard timeout (if any)
380 TotalTimeout    dd 0                    ; Total timeout (if any)
381 AppendLen       dw 0                    ; Bytes in append= command
382 OntimeoutLen    dw 0                    ; Bytes in ontimeout command
383 OnerrorLen      dw 0                    ; Bytes in onerror command
384 CmdLinePtr      dw cmd_line_here        ; Command line advancing pointer
385 ForcePrompt     dw 0                    ; Force prompt
386 NoEscape        dw 0                    ; No escape
387 AllowImplicit   dw 1                    ; Allow implicit kernels
388 AllowOptions    dw 1                    ; User-specified options allowed
389 SerialPort      dw 0                    ; Serial port base (or 0 for no serial port)
390 VKernelBytes    dw 0                    ; Number of bytes used by vkernels
391 VKernel         db 0                    ; Have we seen any "label" statements?
393                 section .latebss
394                 alignb 4                ; For the good of REP MOVSD
395 command_line    resb max_cmd_len+2      ; Command line buffer
396                 alignb 4
397 default_cmd     resb max_cmd_len+1      ; "default" command line
399 %include "rllpack.inc"