More fixes to the extlinux installer; change back to writable types
[profile/ivi/syslinux.git] / parseconfig.inc
1 ;; $Id$
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                 mov [VKernelBuf+vk_rname+1], bx ; Return type
94 .err:           ret
95 %endif
96
97 ;
98 ; "kernel" command
99 pc_kernel:      cmp byte [VKernel],0
100                 je .err                         ; ("label" section only)
101                 call pc_getline
102                 mov di,VKernelBuf+vk_rname
103                 call mangle_name
104 .err:           ret
105
106 ;
107 ; "timeout" command
108 ;
109 pc_timeout:     call getint
110                 jc .err
111                 mov ax,0D215h                   ; There are approx 1.D215h
112                 mul bx                          ; clock ticks per 1/10 s
113                 add bx,dx
114                 mov [KbdTimeOut],bx
115 .err:           ret
116
117 ;
118 ; Generic integer variable setting commands:
119 ; "prompt", "implicit"
120 ;
121 pc_setint16:
122                 push ax
123                 call getint
124                 pop si
125                 jc .err
126                 mov [si],bx
127 .err:           ret
128
129 ;
130 ; Generic file-processing commands:
131 ; "display", "font", "kbdmap"
132 ;
133 pc_filecmd:     push ax                         ; Function to tailcall
134                 call pc_getline
135                 mov di,MNameBuf
136                 push di
137                 call mangle_name
138                 pop di
139                 call searchdir                  ; tailcall
140                 jnz .ok
141                 pop ax                          ; Drop the successor function
142 .ok:            ret                             ; Tailcall if OK, error return
143
144 ;
145 ; "serial" command
146 ;
147 pc_serial:      call getint
148                 jc .err
149                 push bx                         ; Serial port #
150                 call skipspace
151                 jnc .ok
152                 pop bx
153 .err:           ret
154 .ok:
155                 call ungetc
156                 call getint
157                 mov [FlowControl], word 0       ; Default to no flow control
158                 jc .nobaud
159 .valid_baud:    
160                 push ebx
161                 call skipspace
162                 jc .no_flow
163                 call ungetc
164                 call getint                     ; Hardware flow control?
165                 jnc .valid_flow
166 .no_flow:
167                 xor bx,bx                       ; Default -> no flow control
168 .valid_flow:
169                 and bh,0Fh                      ; FlowIgnore
170                 shl bh,4
171                 mov [FlowIgnore],bh
172                 mov bh,bl
173                 and bx,0F003h                   ; Valid bits
174                 mov [FlowControl],bx
175                 pop ebx                         ; Baud rate
176                 jmp short .parse_baud
177 .nobaud:
178                 mov ebx,DEFAULT_BAUD            ; No baud rate given
179 .parse_baud:
180                 pop di                          ; Serial port #
181                 cmp ebx,byte 75
182                 jb .err                         ; < 75 baud == bogus
183                 mov eax,BAUD_DIVISOR
184                 cdq
185                 div ebx
186                 mov [BaudDivisor],ax
187                 push ax                         ; Baud rate divisor
188                 cmp di,3
189                 ja .port_is_io                  ; If port > 3 then port is I/O addr
190                 shl di,1
191                 mov di,[di+serial_base]         ; Get the I/O port from the BIOS
192 .port_is_io:
193                 mov [SerialPort],di
194                 lea dx,[di+3]                   ; DX -> LCR
195                 mov al,83h                      ; Enable DLAB
196                 call slow_out
197                 pop ax                          ; Divisor
198                 mov dx,di                       ; DX -> LS
199                 call slow_out
200                 inc dx                          ; DX -> MS
201                 mov al,ah
202                 call slow_out
203                 mov al,03h                      ; Disable DLAB
204                 add dx,byte 2                   ; DX -> LCR
205                 call slow_out
206                 in al,dx                        ; Read back LCR (detect missing hw)
207                 cmp al,03h                      ; If nothing here we'll read 00 or FF
208                 jne .serial_port_bad            ; Assume serial port busted
209                 sub dx,byte 2                   ; DX -> IER
210                 xor al,al                       ; IRQ disable
211                 call slow_out
212
213                 add dx,byte 3                   ; DX -> MCR
214                 in al,dx
215                 or al,[FlowOutput]              ; Assert bits
216                 call slow_out
217
218                 ; Show some life
219                 mov si,syslinux_banner
220                 call write_serial_str
221                 mov si,copyright_str
222                 call write_serial_str
223                 ret
224
225 .serial_port_bad:
226                 mov [SerialPort], word 0
227                 ret
228
229 ;
230 ; "F"-key command
231 ;
232 pc_fkey:        push ax
233                 call pc_getline
234                 pop di
235                 call mangle_name                ; Mangle file name
236                 ret
237
238 ;
239 ; "label" command
240 ;
241 pc_label:       call commit_vk                  ; Commit any current vkernel
242                 mov di,VKernelBuf               ; Erase the vkernelbuf for better compression
243                 mov cx,(vk_size >> 1)
244                 xor ax,ax
245                 rep stosw
246                 call pc_getline
247                 mov di,VKernelBuf+vk_vname
248                 call mangle_name                ; Mangle virtual name
249                 mov byte [VKernel],1            ; We've seen a "label" statement
250                 mov si,VKernelBuf+vk_vname      ; By default, rname == vname
251                 mov di,VKernelBuf+vk_rname
252                 mov cx,FILENAME_MAX
253                 rep movsb
254                 mov si,AppendBuf                ; Default append==global append
255                 mov di,VKernelBuf+vk_append
256                 mov cx,[AppendLen]
257                 mov [VKernelBuf+vk_appendlen],cx
258                 rep movsb
259 %if IS_PXELINUX                                 ; PXELINUX only
260                 mov al,[IPAppend]               ; Default ipappend==global ipappend
261                 mov [VKernelBuf+vk_ipappend],al
262 %endif
263                 ret
264
265 ;
266 ; "say" command
267 ;
268 pc_say:         call pc_getline                 ; "say" command
269                 call writestr
270                 jmp crlf                        ; tailcall
271
272 ;
273 ; Comment line
274 ;
275 pc_comment      equ pc_getline                  ; Get a line and discard
276
277 ;
278 ; Common subroutine: load line into trackbuf; returns with SI -> trackbuf
279 ;
280 pc_getline:     mov di,trackbuf
281                 push di
282                 call getline
283                 xor al,al
284                 stosb                           ; Null-terminate
285                 pop si
286                 ret
287
288 ;
289 ; Main loop for configuration file parsing
290 ;
291 parse_config:
292                 call getcommand
293                 jnc parse_config                ; If not EOF do it again
294                 ;
295                 ; The fall through to commit_vk to commit any final
296                 ; VKernel being read
297                 ;
298 ;
299 ; commit_vk: Store the current VKernelBuf into buffer segment
300 ;
301 commit_vk:
302                 ; For better compression, clean up the append field
303                 mov ax,[VKernelBuf+vk_appendlen]
304                 mov di,VKernelBuf+vk_append
305                 add di,ax
306                 mov cx,max_cmd_len+1
307                 sub cx,ax
308                 xor ax,ax
309                 rep stosb
310
311                 ; Pack temporarily into trackbuf
312                 mov si,VKernelBuf
313                 mov di,trackbuf
314                 mov cx,vk_size
315                 call rllpack
316                 ; Now DX = number of bytes
317                 mov di,[VKernelBytes]
318                 mov cx,dx
319                 add dx,di
320                 jc .overflow                    ; If > 1 segment
321                 mov [VKernelBytes],dx
322                 mov si,trackbuf
323                 push es
324                 push word vk_seg
325                 pop es
326                 rep movsb
327                 pop es
328                 ret
329 .overflow:
330                 mov si,vk_overflow_msg
331                 call writestr
332                 ret
333
334                 section .data
335 vk_overflow_msg db 'Out of memory parsing config file', CR, LF, 0
336
337                 align 2, db 0
338 AppendLen       dw 0                    ; Bytes in append= command
339 OntimeoutLen    dw 0                    ; Bytes in ontimeout command
340 OnerrorLen      dw 0                    ; Bytes in onerror command
341 KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
342 CmdLinePtr      dw cmd_line_here        ; Command line advancing pointer
343 initrd_flag     equ $
344 initrd_ptr      dw 0                    ; Initial ramdisk pointer/flag
345 ForcePrompt     dw 0                    ; Force prompt
346 AllowImplicit   dw 1                    ; Allow implicit kernels
347 AllowOptions    dw 1                    ; User-specified options allowed
348 SerialPort      dw 0                    ; Serial port base (or 0 for no serial port)
349 VKernelBytes    dw 0                    ; Number of bytes used by vkernels
350 VKernel         db 0                    ; Have we seen any "label" statements?
351
352                 section .bss
353                 alignb 4                ; For the good of REP MOVSD
354 command_line    resb max_cmd_len+2      ; Command line buffer
355                 alignb 4
356 default_cmd     resb max_cmd_len+1      ; "default" command line
357
358 %include "rllpack.inc"