Clean up the transition to PM for shuffle-and-boot-to-PM
[syslinux.git] / parseconfig.inc
blobef1ed1122049a3792d42dbb923f54553d2a0622b
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2007 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", "config", ... command
105 pc_kernel:      cmp byte [VKernel],0
106                 je .err                         ; ("label" section only)
107                 mov [VKernelBuf+vk_type],al
108                 call pc_getline
109                 mov di,VKernelBuf+vk_rname
110                 call mangle_name
111 .err:           ret
114 ; "timeout", "totaltimeout" command
116 ; N.B. 1/10 s ~ 1.D2162AABh clock ticks
118 pc_timeout:     push ax
119                 call getint
120                 pop si
121                 jc .err
122                 mov eax,0D2162AABh
123                 mul ebx                         ; clock ticks per 1/10 s
124                 add ebx,edx
125                 mov [si],ebx
126 .err:           ret
130 ; "totaltimeout" command
132 pc_totaltimeout:
135 ; Generic integer variable setting commands:
136 ; "prompt", "implicit"
138 pc_setint16:
139                 push ax
140                 call getint
141                 pop si
142                 jc .err
143                 mov [si],bx
144 .err:           ret
147 ; Generic file-processing commands:
148 ; "display", "font", "kbdmap", "include"
150 pc_filecmd:     push ax                         ; Function to tailcall
151                 call pc_getline
152                 mov di,MNameBuf
153                 call mangle_name
154                 call searchdir                  ; tailcall
155                 jnz .ok
156                 pop ax                          ; Drop the successor function
157 .ok:            ret                             ; Tailcall if OK, error return
160 ; "include" command (invoked from pc_filecmd)
162 pc_include:     call openfd
163                 jz .err
164                 inc word [IncludeLevel]
165 .err:           ret
168 ; "serial" command
170 pc_serial:      call getint
171                 jc .err
172                 push bx                         ; Serial port #
173                 call skipspace
174                 jnc .ok
175                 pop bx
176 .err:           ret
177 .ok:
178                 call ungetc
179                 call getint
180                 mov [FlowControl], word 0       ; Default to no flow control
181                 jc .nobaud
182 .valid_baud:
183                 push ebx
184                 call skipspace
185                 jc .no_flow
186                 call ungetc
187                 call getint                     ; Hardware flow control?
188                 jnc .valid_flow
189 .no_flow:
190                 xor bx,bx                       ; Default -> no flow control
191 .valid_flow:
192                 and bh,0Fh                      ; FlowIgnore
193                 shl bh,4
194                 mov [FlowIgnore],bh
195                 mov bh,bl
196                 and bx,0F003h                   ; Valid bits
197                 mov [FlowControl],bx
198                 pop ebx                         ; Baud rate
199                 jmp short .parse_baud
200 .nobaud:
201                 mov ebx,DEFAULT_BAUD            ; No baud rate given
202 .parse_baud:
203                 pop di                          ; Serial port #
204                 cmp ebx,byte 75
205                 jb .err                         ; < 75 baud == bogus
206                 mov eax,BAUD_DIVISOR
207                 cdq
208                 div ebx
209                 mov [BaudDivisor],ax
210                 push ax                         ; Baud rate divisor
211                 cmp di,3
212                 ja .port_is_io                  ; If port > 3 then port is I/O addr
213                 shl di,1
214                 mov di,[di+serial_base]         ; Get the I/O port from the BIOS
215 .port_is_io:
216                 mov [SerialPort],di
218                 ;
219                 ; Begin code to actually set up the serial port
220                 ;
221                 lea dx,[di+3]                   ; DX -> LCR
222                 mov al,83h                      ; Enable DLAB
223                 call slow_out
225                 pop ax                          ; Divisor
226                 mov dx,di                       ; DX -> LS
227                 call slow_out
229                 inc dx                          ; DX -> MS
230                 mov al,ah
231                 call slow_out
233                 mov al,03h                      ; Disable DLAB
234                 inc dx                          ; DX -> LCR
235                 inc dx
236                 call slow_out
238                 in al,dx                        ; Read back LCR (detect missing hw)
239                 cmp al,03h                      ; If nothing here we'll read 00 or FF
240                 jne .serial_port_bad            ; Assume serial port busted
241                 dec dx
242                 dec dx                          ; DX -> IER
243                 xor al,al                       ; IRQ disable
244                 call slow_out
246                 inc dx                          ; DX -> FCR/IIR
247                 mov al,01h
248                 call slow_out                   ; Enable FIFOs if present
249                 in al,dx
250                 cmp al,0C0h                     ; FIFOs enabled and usable?
251                 jae .fifo_ok
252                 xor ax,ax                       ; Disable FIFO if unusable
253                 call slow_out
254 .fifo_ok:
256                 inc dx
257                 inc dx                          ; DX -> MCR
258                 in al,dx
259                 or al,[FlowOutput]              ; Assert bits
260                 call slow_out
262                 ; Show some life
263                 cmp byte [SerialNotice],0
264                 je .notfirst
265                 mov byte [SerialNotice],0
267                 mov si,syslinux_banner
268                 call write_serial_str
269                 mov si,copyright_str
270                 call write_serial_str
271 .notfirst:
272                 ret
274 .serial_port_bad:
275                 mov [SerialPort], word 0
276                 ret
279 ; "F"-key command
281 pc_fkey:        push ax
282                 call pc_getline
283                 pop di
284                 call mangle_name                ; Mangle file name
285                 ret
288 ; "label" command
290 pc_label:       call commit_vk                  ; Commit any current vkernel
291                 mov di,VKernelBuf               ; Erase the vkernelbuf for better compression
292                 mov cx,(vk_size >> 1)
293                 xor ax,ax
294                 rep stosw
295                 call pc_getline
296                 mov di,VKernelBuf+vk_vname
297                 call mangle_name                ; Mangle virtual name
298                 mov byte [VKernel],1            ; We've seen a "label" statement
299                 mov si,VKernelBuf+vk_vname      ; By default, rname == vname
300                 ; mov di,VKernelBuf+vk_rname    ; -- already set
301                 mov cx,FILENAME_MAX
302                 rep movsb
303                 mov si,AppendBuf                ; Default append==global append
304                 mov di,VKernelBuf+vk_append
305                 mov cx,[AppendLen]
306                 mov [VKernelBuf+vk_appendlen],cx
307                 rep movsb
308 %if IS_PXELINUX                                 ; PXELINUX only
309                 mov al,[IPAppend]               ; Default ipappend==global ipappend
310                 mov [VKernelBuf+vk_ipappend],al
311 %endif
312                 ret
315 ; "say" command
317 pc_say:         call pc_getline                 ; "say" command
318                 call writestr
319                 jmp crlf                        ; tailcall
322 ; "text" command; ignore everything until we get an "endtext" line
324 pc_text:        call pc_getline                 ; Ignore rest of line
325 .loop:
326                 call pc_getline
327                 jc .eof
329                 ; Leading spaces are already removed...
330                 lodsd
331                 and eax,0xdfdfdfdf              ; Upper case
332                 cmp eax,'ENDT'
333                 jne .loop
334                 lodsd
335                 and eax,0x00dfdfdf              ; Upper case and mask
336                 cmp eax,'EXT'
337                 jne .loop
338                 ; If we get here we hit ENDTEXT
339 .eof:
340                 ret
343 ; Comment line
345 pc_comment:     ; Fall into pc_getline
348 ; Common subroutine: load line into trackbuf; returns with SI -> trackbuf
349 ; CF is set on EOF.
351 pc_getline:     mov di,trackbuf
352                 push di
353                 call getline
354                 mov byte [di],0                 ; Null-terminate
355                 pop si
356                 ret
359 ; Main loop for configuration file parsing
361 parse_config:
362                 mov di,VKernelBuf               ; Clear VKernelBuf at start
363                 xor ax,ax
364                 mov cx,vk_size
365                 rep stosb
367 .again:
368                 call getcommand                 ; Parse one command
369                 jnc .again                      ; If not EOF...
370                 call close
371                 dec word [IncludeLevel]         ; Still parsing?
372                 jnz .again
374                 ;
375                 ; The fall through to commit_vk to commit any final
376                 ; VKernel being read
377                 ;
379 ; commit_vk: Store the current VKernelBuf into buffer segment
381 commit_vk:
382                 ; For better compression, clean up the append field
383                 mov ax,[VKernelBuf+vk_appendlen]
384                 mov di,VKernelBuf+vk_append
385                 add di,ax
386                 mov cx,max_cmd_len+1
387                 sub cx,ax
388                 xor ax,ax
389                 rep stosb
391                 ; Pack temporarily into trackbuf
392                 mov si,VKernelBuf
393                 mov di,trackbuf
394                 mov cx,vk_size
395                 call rllpack
396                 ; Now DX = number of bytes
397                 mov di,[VKernelBytes]
398                 mov cx,dx
399                 add dx,di
400                 jc .overflow                    ; If > 1 segment
401                 mov [VKernelBytes],dx
402                 mov si,trackbuf
403                 push es
404                 push word vk_seg
405                 pop es
406                 rep movsb
407                 pop es
408                 ret
409 .overflow:
410                 mov si,vk_overflow_msg
411                 call writestr
412                 ret
414                 section .data
415 vk_overflow_msg db 'Out of memory parsing config file', CR, LF, 0
416 SerialNotice    db 1                    ; Only print this once
418                 section .config
419                 align 4, db 0
420 KbdTimeout      dd 0                    ; Keyboard timeout (if any)
421 TotalTimeout    dd 0                    ; Total timeout (if any)
422 AppendLen       dw 0                    ; Bytes in append= command
423 OntimeoutLen    dw 0                    ; Bytes in ontimeout command
424 OnerrorLen      dw 0                    ; Bytes in onerror command
425 CmdLinePtr      dw cmd_line_here        ; Command line advancing pointer
426 ForcePrompt     dw 0                    ; Force prompt
427 NoEscape        dw 0                    ; No escape
428 AllowImplicit   dw 1                    ; Allow implicit kernels
429 AllowOptions    dw 1                    ; User-specified options allowed
430 IncludeLevel    dw 1                    ; Nesting level
431 SerialPort      dw 0                    ; Serial port base (or 0 for no serial port)
432 VKernelBytes    dw 0                    ; Number of bytes used by vkernels
433 VKernel         db 0                    ; Have we seen any "label" statements?
435 %if IS_PXELINUX
436 IPAppend        db 0                    ; Default IPAPPEND option
437 %endif
439                 section .bss
440                 alignb 4                ; For the good of REP MOVSD
441 command_line    resb max_cmd_len+2      ; Command line buffer
442                 alignb 4
443 default_cmd     resb max_cmd_len+1      ; "default" command line
445 %include "rllpack.inc"