1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
;; -----------------------------------------------------------------------
;;
;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
;; Copyright 2009 Intel Corporation; author: H. Peter Anvin
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
;; Boston MA 02111-1307, USA; either version 2 of the License, or
;; (at your option) any later version; incorporated herein by reference.
;;
;; -----------------------------------------------------------------------
;;
;; parseconfig.inc
;;
;; Configuration file operations
;;
section .text
;
; "default" or "ui" command, with level (1 = default, 2 = ui)
;
pc_default: cmp ax,[DefaultLevel]
jb skipline ; == call skipline + ret
mov [DefaultLevel],ax
mov di,default_cmd
call getline
mov byte [di-1],0 ; null-terminate
ret
;
; "ontimeout" command
;
pc_ontimeout: mov di,Ontimeout
call getline
sub di,Ontimeout+1 ; Don't need final space
mov [OntimeoutLen],di
ret
;
; "onerror" command
;
pc_onerror: mov di,Onerror
call getline
sub di,Onerror
mov [OnerrorLen],di
ret
;
; "append" command
;
pc_append: cmp byte [VKernel],0
ja .vk
mov di,AppendBuf
call getline
sub di,AppendBuf
.app1: mov [AppendLen],di
ret
.vk: mov di,VKernelBuf+vk_append ; "append" command (vkernel)
call getline
sub di,VKernelBuf+vk_append
cmp di,byte 2
jne .app2
cmp byte [VKernelBuf+vk_append],'-'
jne .app2
xor di,di ; If "append -" -> null string
.app2: mov [VKernelBuf+vk_appendlen],di
ret
;
; "ipappend" command (PXELINUX only)
;
%if IS_PXELINUX
pc_ipappend: call getint
jc .err
cmp byte [VKernel],0
jne .vk
mov [IPAppend],bl
.err: ret
.vk: mov [VKernelBuf+vk_ipappend],bl
ret
%endif
;
; "localboot" command (PXELINUX, ISOLINUX)
;
%if HAS_LOCALBOOT
pc_localboot: call getint
cmp byte [VKernel],0 ; ("label" section only)
je .err
mov di,VKernelBuf+vk_rname
xor ax,ax
mov cx,FILENAME_MAX
rep stosb ; Null kernel name
%if IS_PXELINUX
; PXELINUX uses the first 4 bytes of vk_rname for the
; mangled IP address
mov [VKernelBuf+vk_rname+5], bx ; Return type
%else
mov [VKernelBuf+vk_rname+1], bx ; Return type
%endif
.err: ret
%endif ; HAS_LOCALBOOT
;
; "kernel", "config", ... command
;
pc_kernel: cmp byte [VKernel],0
je .err ; ("label" section only)
mov [VKernelBuf+vk_type],al
call pc_getline
mov di,VKernelBuf+vk_rname
call mangle_name
.err: ret
;
; "timeout", "totaltimeout" command
;
; N.B. 1/10 s ~ 1.D2162AABh clock ticks
;
pc_timeout: push ax
call getint
pop si
jc .err
mov eax,0D2162AABh
mul ebx ; clock ticks per 1/10 s
add ebx,edx
mov [si],ebx
.err: ret
;
; "totaltimeout" command
;
pc_totaltimeout:
;
; Generic integer variable setting commands:
; "prompt", "implicit"
;
pc_setint16:
push ax
call getint
pop si
jc .err
mov [si],bx
.err: ret
;
; Generic file-processing commands:
; "font", "kbdmap",
;
pc_filecmd: push ax ; Function to tailcall
call pc_getline
mov di,MNameBuf
call mangle_name
call searchdir
jnz .ok
pop ax ; Drop the successor function
.ok: ret ; Tailcall if OK, error return
;
; Commands that expect the file to be opened on top of the getc stack.
; "display", "include"
;
pc_opencmd: push ax ; Function to tailcall
call pc_getline
mov di,MNameBuf
call mangle_name
call open
jnz .ok
pop ax ; Drop the successor function
.ok: ret ; Tailcall if OK, error return
;
; "include" command (invoked from pc_opencmd)
;
pc_include: inc word [IncludeLevel]
.err: ret
;
; "serial" command
;
pc_serial: call getint
jc .err
push bx ; Serial port #
xor ax,ax
mov [FlowControl],ax ; Default to no flow control
mov [FlowIgnore],al
call skipspace
jc .nobaud
call ungetc
call getint
jc .nobaud
.valid_baud:
push ebx
call skipspace
jc .no_flow
call ungetc
call getint ; Hardware flow control?
jnc .valid_flow
.no_flow:
xor bx,bx ; Default -> no flow control
.valid_flow:
and bh,0Fh ; FlowIgnore
shl bh,4
mov [FlowIgnore],bh
mov bh,bl
and bx,0F003h ; Valid bits
mov [FlowControl],bx
pop ebx ; Baud rate
jmp short .parse_baud
.nobaud:
mov ebx,DEFAULT_BAUD ; No baud rate given
.parse_baud:
pop di ; Serial port #
cmp ebx,byte 75
jb .err ; < 75 baud == bogus
mov eax,BAUD_DIVISOR
cdq
div ebx
mov [BaudDivisor],ax
push ax ; Baud rate divisor
cmp di,3
ja .port_is_io ; If port > 3 then port is I/O addr
shl di,1
mov di,[di+serial_base] ; Get the I/O port from the BIOS
.port_is_io:
mov [SerialPort],di
;
; Begin code to actually set up the serial port
;
lea dx,[di+3] ; DX -> LCR
mov al,83h ; Enable DLAB
call slow_out
pop ax ; Divisor
mov dx,di ; DX -> LS
call slow_out
inc dx ; DX -> MS
mov al,ah
call slow_out
mov al,03h ; Disable DLAB
inc dx ; DX -> LCR
inc dx
call slow_out
in al,dx ; Read back LCR (detect missing hw)
cmp al,03h ; If nothing here we'll read 00 or FF
jne .err ; Assume serial port busted
dec dx
dec dx ; DX -> IER
xor al,al ; IRQ disable
call slow_out
inc dx ; DX -> FCR/IIR
mov al,01h
call slow_out ; Enable FIFOs if present
in al,dx
cmp al,0C0h ; FIFOs enabled and usable?
jae .fifo_ok
xor ax,ax ; Disable FIFO if unusable
call slow_out
.fifo_ok:
inc dx
inc dx ; DX -> MCR
in al,dx
or al,[FlowOutput] ; Assert bits
call slow_out
; Show some life
cmp byte [SerialNotice],0
je .notfirst
mov byte [SerialNotice],0
mov si,syslinux_banner
call write_serial_str
mov si,copyright_str
call write_serial_str
.notfirst:
ret
.err:
mov [SerialPort], word 0
ret
;
; Store mangled filename command (F-keys, "initrd")
;
pc_filename: push ax
call pc_getline
pop di
call mangle_name ; Mangle file name
ret
;
; "label" command
;
pc_label: call commit_vk ; Commit any current vkernel
mov byte [InitRD+NULLOFFSET],NULLFILE ; No "initrd" statement
mov di,VKernelBuf ; Erase the vkernelbuf for better compression
mov cx,(vk_size >> 1)
xor ax,ax
rep stosw
call pc_getline
mov di,VKernelBuf+vk_vname
mov cx,FILENAME_MAX-1
.loop:
lodsb
cmp al,' '
jna .done
stosb
loop .loop
.done:
mov byte [VKernel],1 ; We've seen a "label" statement
mov si,VKernelBuf+vk_vname ; By default, rname == vname
mov di,VKernelBuf+vk_rname
mov cx,FILENAME_MAX
rep movsb
mov si,AppendBuf ; Default append==global append
mov di,VKernelBuf+vk_append
mov cx,[AppendLen]
mov [VKernelBuf+vk_appendlen],cx
rep movsb
%if IS_PXELINUX ; PXELINUX only
mov al,[IPAppend] ; Default ipappend==global ipappend
mov [VKernelBuf+vk_ipappend],al
%endif
ret
;
; "say" command
;
pc_say: call pc_getline ; "say" command
call writestr
jmp crlf ; tailcall
;
; "text" command; ignore everything until we get an "endtext" line
;
pc_text: call skipline ; Ignore rest of line
.loop:
call pc_getline
jc .eof
; Leading spaces are already removed...
lodsd
and eax,0xdfdfdfdf ; Upper case
cmp eax,'ENDT'
jne .loop
lodsd
and eax,0x00dfdfdf ; Upper case and mask
cmp eax,'EXT'
jne .loop
; If we get here we hit ENDTEXT
.eof:
ret
;
; Comment line
;
pc_comment: ; Fall into pc_getline
;
; Common subroutine: load line into trackbuf; returns with SI -> trackbuf
; CF is set on EOF.
;
pc_getline: mov di,trackbuf
push di
call getline
mov byte [di],0 ; Null-terminate
pop si
ret
;
; Main loop for configuration file parsing
;
parse_config:
mov di,VKernelBuf ; Clear VKernelBuf at start
xor ax,ax
mov cx,vk_size
rep stosb
.again:
call getcommand ; Parse one command
jnc .again ; If not EOF...
call close
dec word [IncludeLevel] ; Still parsing?
jnz .again
;
; The fall through to commit_vk to commit any final
; VKernel being read
;
;
; commit_vk: Store the current VKernelBuf into buffer segment
;
commit_vk:
cmp byte [VKernel],0
jz .nolabel ; Nothing to commit...
mov di,VKernelBuf+vk_append
add di,[VKernelBuf+vk_appendlen]
; If we have an initrd statement, append it to the
; append statement
cmp byte [InitRD+NULLOFFSET],NULLFILE
je .noinitrd
mov si,str_initrd
mov cx,7 ; "initrd="
rep movsb
mov si,InitRD
call unmangle_name
mov al,' '
stosb
; For better compression, clean up the append field
.noinitrd:
mov ax,di
sub ax,VKernelBuf+vk_append
mov [VKernelBuf+vk_appendlen],ax
mov cx,max_cmd_len+1
sub cx,ax
xor ax,ax
rep stosb
; Pack into high memory
mov esi,VKernelBuf
mov edi,[VKernelEnd]
mov ecx,vk_size
call rllpack
mov [VKernelEnd],edi
.nolabel:
ret
.overflow:
mov si,vk_overflow_msg
call writestr
ret
section .data
vk_overflow_msg db 'Out of memory parsing config file', CR, LF, 0
SerialNotice db 1 ; Only print this once
section .bss
alignb 4
VKernelEnd resd 1 ; Lowest high memory address used
; This symbol should be used by loaders to indicate
; the highest address *they* are allowed to use.
HighMemRsvd equ VKernelEnd
; by vkernels
section .config
alignz 4
KbdTimeout dd 0 ; Keyboard timeout (if any)
TotalTimeout dd 0 ; Total timeout (if any)
AppendLen dw 0 ; Bytes in append= command
OntimeoutLen dw 0 ; Bytes in ontimeout command
OnerrorLen dw 0 ; Bytes in onerror command
CmdLinePtr dw cmd_line_here ; Command line advancing pointer
ForcePrompt dw 0 ; Force prompt
NoEscape dw 0 ; No escape
NoComplete dw 0 ; No label completion on TAB key
AllowImplicit dw 1 ; Allow implicit kernels
AllowOptions dw 1 ; User-specified options allowed
IncludeLevel dw 1 ; Nesting level
DefaultLevel dw 0 ; The current level of default
SerialPort dw 0 ; Serial port base (or 0 for no serial port)
VKernel db 0 ; Have we seen any "label" statements?
%if IS_PXELINUX
IPAppend db 0 ; Default IPAPPEND option
%endif
section .uibss
alignb 4 ; For the good of REP MOVSD
command_line resb max_cmd_len+2 ; Command line buffer
alignb 4
default_cmd resb max_cmd_len+1 ; "default" command line
%include "rllpack.inc"
|