Contents of /tags/mkinitrd-6_2_3/isolinux/parseconfig.inc
Parent Directory | Revision Log
Revision 1054 -
(show annotations)
(download)
Mon May 31 20:54:44 2010 UTC (14 years, 4 months ago) by niro
File size: 8588 byte(s)
Mon May 31 20:54:44 2010 UTC (14 years, 4 months ago) by niro
File size: 8588 byte(s)
tagged 'mkinitrd-6_2_3'
1 | ;; $Id: parseconfig.inc,v 1.1 2007-09-01 22:44:05 niro 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", "totaltimeout" command |
114 | ; |
115 | ; N.B. 1/10 s ~ 1.D2162AABh clock ticks |
116 | ; |
117 | pc_timeout: push ax |
118 | call getint |
119 | pop si |
120 | jc .err |
121 | mov eax,0D2162AABh |
122 | mul ebx ; clock ticks per 1/10 s |
123 | add ebx,edx |
124 | mov [si],ebx |
125 | .err: ret |
126 | |
127 | |
128 | ; |
129 | ; "totaltimeout" command |
130 | ; |
131 | pc_totaltimeout: |
132 | |
133 | ; |
134 | ; Generic integer variable setting commands: |
135 | ; "prompt", "implicit" |
136 | ; |
137 | pc_setint16: |
138 | push ax |
139 | call getint |
140 | pop si |
141 | jc .err |
142 | mov [si],bx |
143 | .err: ret |
144 | |
145 | ; |
146 | ; Generic file-processing commands: |
147 | ; "display", "font", "kbdmap" |
148 | ; |
149 | pc_filecmd: push ax ; Function to tailcall |
150 | call pc_getline |
151 | mov di,MNameBuf |
152 | push di |
153 | call mangle_name |
154 | pop di |
155 | call searchdir ; tailcall |
156 | jnz .ok |
157 | pop ax ; Drop the successor function |
158 | .ok: ret ; Tailcall if OK, error return |
159 | |
160 | ; |
161 | ; "serial" command |
162 | ; |
163 | pc_serial: call getint |
164 | jc .err |
165 | push bx ; Serial port # |
166 | call skipspace |
167 | jnc .ok |
168 | pop bx |
169 | .err: ret |
170 | .ok: |
171 | call ungetc |
172 | call getint |
173 | mov [FlowControl], word 0 ; Default to no flow control |
174 | jc .nobaud |
175 | .valid_baud: |
176 | push ebx |
177 | call skipspace |
178 | jc .no_flow |
179 | call ungetc |
180 | call getint ; Hardware flow control? |
181 | jnc .valid_flow |
182 | .no_flow: |
183 | xor bx,bx ; Default -> no flow control |
184 | .valid_flow: |
185 | and bh,0Fh ; FlowIgnore |
186 | shl bh,4 |
187 | mov [FlowIgnore],bh |
188 | mov bh,bl |
189 | and bx,0F003h ; Valid bits |
190 | mov [FlowControl],bx |
191 | pop ebx ; Baud rate |
192 | jmp short .parse_baud |
193 | .nobaud: |
194 | mov ebx,DEFAULT_BAUD ; No baud rate given |
195 | .parse_baud: |
196 | pop di ; Serial port # |
197 | cmp ebx,byte 75 |
198 | jb .err ; < 75 baud == bogus |
199 | mov eax,BAUD_DIVISOR |
200 | cdq |
201 | div ebx |
202 | mov [BaudDivisor],ax |
203 | push ax ; Baud rate divisor |
204 | cmp di,3 |
205 | ja .port_is_io ; If port > 3 then port is I/O addr |
206 | shl di,1 |
207 | mov di,[di+serial_base] ; Get the I/O port from the BIOS |
208 | .port_is_io: |
209 | mov [SerialPort],di |
210 | |
211 | ; |
212 | ; Begin code to actually set up the serial port |
213 | ; |
214 | lea dx,[di+3] ; DX -> LCR |
215 | mov al,83h ; Enable DLAB |
216 | call slow_out |
217 | |
218 | pop ax ; Divisor |
219 | mov dx,di ; DX -> LS |
220 | call slow_out |
221 | |
222 | inc dx ; DX -> MS |
223 | mov al,ah |
224 | call slow_out |
225 | |
226 | mov al,03h ; Disable DLAB |
227 | inc dx ; DX -> LCR |
228 | inc dx |
229 | call slow_out |
230 | |
231 | in al,dx ; Read back LCR (detect missing hw) |
232 | cmp al,03h ; If nothing here we'll read 00 or FF |
233 | jne .serial_port_bad ; Assume serial port busted |
234 | dec dx |
235 | dec dx ; DX -> IER |
236 | xor al,al ; IRQ disable |
237 | call slow_out |
238 | |
239 | inc dx ; DX -> FCR/IIR |
240 | mov al,01h |
241 | call slow_out ; Enable FIFOs if present |
242 | in al,dx |
243 | cmp al,0C0h ; FIFOs enabled and usable? |
244 | jae .fifo_ok |
245 | xor ax,ax ; Disable FIFO if unusable |
246 | call slow_out |
247 | .fifo_ok: |
248 | |
249 | inc dx |
250 | inc dx ; DX -> MCR |
251 | in al,dx |
252 | or al,[FlowOutput] ; Assert bits |
253 | call slow_out |
254 | |
255 | ; Show some life |
256 | mov si,syslinux_banner |
257 | call write_serial_str |
258 | mov si,copyright_str |
259 | call write_serial_str |
260 | ret |
261 | |
262 | .serial_port_bad: |
263 | mov [SerialPort], word 0 |
264 | ret |
265 | |
266 | ; |
267 | ; "F"-key command |
268 | ; |
269 | pc_fkey: push ax |
270 | call pc_getline |
271 | pop di |
272 | call mangle_name ; Mangle file name |
273 | ret |
274 | |
275 | ; |
276 | ; "label" command |
277 | ; |
278 | pc_label: call commit_vk ; Commit any current vkernel |
279 | mov di,VKernelBuf ; Erase the vkernelbuf for better compression |
280 | mov cx,(vk_size >> 1) |
281 | xor ax,ax |
282 | rep stosw |
283 | call pc_getline |
284 | mov di,VKernelBuf+vk_vname |
285 | call mangle_name ; Mangle virtual name |
286 | mov byte [VKernel],1 ; We've seen a "label" statement |
287 | mov si,VKernelBuf+vk_vname ; By default, rname == vname |
288 | mov di,VKernelBuf+vk_rname |
289 | mov cx,FILENAME_MAX |
290 | rep movsb |
291 | mov si,AppendBuf ; Default append==global append |
292 | mov di,VKernelBuf+vk_append |
293 | mov cx,[AppendLen] |
294 | mov [VKernelBuf+vk_appendlen],cx |
295 | rep movsb |
296 | %if IS_PXELINUX ; PXELINUX only |
297 | mov al,[IPAppend] ; Default ipappend==global ipappend |
298 | mov [VKernelBuf+vk_ipappend],al |
299 | %endif |
300 | ret |
301 | |
302 | ; |
303 | ; "say" command |
304 | ; |
305 | pc_say: call pc_getline ; "say" command |
306 | call writestr |
307 | jmp crlf ; tailcall |
308 | |
309 | ; |
310 | ; Comment line |
311 | ; |
312 | pc_comment: ; Fall into pc_getline |
313 | |
314 | ; |
315 | ; Common subroutine: load line into trackbuf; returns with SI -> trackbuf |
316 | ; |
317 | pc_getline: mov di,trackbuf |
318 | push di |
319 | call getline |
320 | xor al,al |
321 | stosb ; Null-terminate |
322 | pop si |
323 | ret |
324 | |
325 | ; |
326 | ; Main loop for configuration file parsing |
327 | ; |
328 | parse_config: |
329 | mov di,VKernelBuf ; Clear VKernelBuf at start |
330 | xor ax,ax |
331 | mov cx,vk_size |
332 | rep stosb |
333 | .again: |
334 | call getcommand |
335 | jnc .again ; If not EOF do it again |
336 | ; |
337 | ; The fall through to commit_vk to commit any final |
338 | ; VKernel being read |
339 | ; |
340 | ; |
341 | ; commit_vk: Store the current VKernelBuf into buffer segment |
342 | ; |
343 | commit_vk: |
344 | ; For better compression, clean up the append field |
345 | mov ax,[VKernelBuf+vk_appendlen] |
346 | mov di,VKernelBuf+vk_append |
347 | add di,ax |
348 | mov cx,max_cmd_len+1 |
349 | sub cx,ax |
350 | xor ax,ax |
351 | rep stosb |
352 | |
353 | ; Pack temporarily into trackbuf |
354 | mov si,VKernelBuf |
355 | mov di,trackbuf |
356 | mov cx,vk_size |
357 | call rllpack |
358 | ; Now DX = number of bytes |
359 | mov di,[VKernelBytes] |
360 | mov cx,dx |
361 | add dx,di |
362 | jc .overflow ; If > 1 segment |
363 | mov [VKernelBytes],dx |
364 | mov si,trackbuf |
365 | push es |
366 | push word vk_seg |
367 | pop es |
368 | rep movsb |
369 | pop es |
370 | ret |
371 | .overflow: |
372 | mov si,vk_overflow_msg |
373 | call writestr |
374 | ret |
375 | |
376 | section .data |
377 | vk_overflow_msg db 'Out of memory parsing config file', CR, LF, 0 |
378 | |
379 | align 4, db 0 |
380 | KbdTimeout dd 0 ; Keyboard timeout (if any) |
381 | TotalTimeout dd 0 ; Total timeout (if any) |
382 | AppendLen dw 0 ; Bytes in append= command |
383 | OntimeoutLen dw 0 ; Bytes in ontimeout command |
384 | OnerrorLen dw 0 ; Bytes in onerror command |
385 | CmdLinePtr dw cmd_line_here ; Command line advancing pointer |
386 | ForcePrompt dw 0 ; Force prompt |
387 | NoEscape dw 0 ; No escape |
388 | AllowImplicit dw 1 ; Allow implicit kernels |
389 | AllowOptions dw 1 ; User-specified options allowed |
390 | SerialPort dw 0 ; Serial port base (or 0 for no serial port) |
391 | VKernelBytes dw 0 ; Number of bytes used by vkernels |
392 | VKernel db 0 ; Have we seen any "label" statements? |
393 | |
394 | section .latebss |
395 | alignb 4 ; For the good of REP MOVSD |
396 | command_line resb max_cmd_len+2 ; Command line buffer |
397 | alignb 4 |
398 | default_cmd resb max_cmd_len+1 ; "default" command line |
399 | |
400 | %include "rllpack.inc" |