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