--- trunk/mkinitrd-magellan/isolinux/parseconfig.inc 2010/08/19 08:27:19 1132 +++ trunk/mkinitrd-magellan/isolinux/parseconfig.inc 2010/08/19 09:50:43 1133 @@ -1,7 +1,7 @@ -;; $Id: parseconfig.inc,v 1.1 2007-09-01 22:44:05 niro Exp $ ;; ----------------------------------------------------------------------- -;; -;; Copyright 1994-2004 H. Peter Anvin - All Rights Reserved +;; +;; 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 @@ -19,9 +19,12 @@ section .text ; -; "default" command -; -pc_default: mov di,default_cmd +; "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 @@ -52,7 +55,7 @@ mov di,AppendBuf call getline sub di,AppendBuf -.app1: mov [AppendLen],di +.app1: mov [AppendLen],di ret .vk: mov di,VKernelBuf+vk_append ; "append" command (vkernel) call getline @@ -80,30 +83,25 @@ %endif ; -; "localboot" command (PXELINUX, ISOLINUX) +; "localboot" command ; -%if IS_PXELINUX || IS_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 + mov [VKernelBuf+vk_rname],bx + mov byte [VKernelBuf+vk_type],VK_LOCALBOOT .err: ret -%endif +%endif ; HAS_LOCALBOOT + +; +; "kernel", "config", ... command ; -; "kernel" 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 @@ -144,35 +142,50 @@ ; ; Generic file-processing commands: -; "display", "font", "kbdmap" +; "font", "kbdmap", ; pc_filecmd: push ax ; Function to tailcall call pc_getline mov di,MNameBuf - push di call mangle_name - pop di - call searchdir ; tailcall + 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 eax,eax + mov [FlowControl],eax ; Default to no flow control call skipspace - jnc .ok - pop bx -.err: ret -.ok: + jc .nobaud call ungetc call getint - mov [FlowControl], word 0 ; Default to no flow control jc .nobaud -.valid_baud: +.valid_baud: push ebx call skipspace jc .no_flow @@ -186,7 +199,7 @@ shl bh,4 mov [FlowIgnore],bh mov bh,bl - and bx,0F003h ; Valid bits + and bx,0F00Bh ; Valid bits mov [FlowControl],bx pop ebx ; Baud rate jmp short .parse_baud @@ -211,62 +224,69 @@ ; ; Begin code to actually set up the serial port ; + call sirq_cleanup_nowipe ; Cleanup existing IRQ handler + lea dx,[di+3] ; DX -> LCR mov al,83h ; Enable DLAB - call slow_out + slow_out dx,al pop ax ; Divisor mov dx,di ; DX -> LS - call slow_out + slow_out dx,al inc dx ; DX -> MS mov al,ah - call slow_out + slow_out dx,al 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 .serial_port_bad ; Assume serial port busted - dec dx - dec dx ; DX -> IER - xor al,al ; IRQ disable - call slow_out + slow_out dx,al - inc dx ; DX -> FCR/IIR + 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 ; DX -> IIR/FCR mov al,01h - call slow_out ; Enable FIFOs if present + slow_out dx,al ; 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 + slow_out dx,al .fifo_ok: inc dx inc dx ; DX -> MCR - in al,dx - or al,[FlowOutput] ; Assert bits - call slow_out + mov al,[FlowOutput] ; Assert bits + slow_out dx,al + + ; Enable interrupts if requested + test al,8 + jz .noirq + call sirq_install +.noirq: ; 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 -.serial_port_bad: +.err: mov [SerialPort], word 0 ret ; -; "F"-key command +; Store mangled filename command (F-keys, "initrd") ; -pc_fkey: push ax +pc_filename: push ax call pc_getline pop di call mangle_name ; Mangle file name @@ -276,23 +296,30 @@ ; "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 - call mangle_name ; Mangle virtual name + 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 si,VKernelBuf+vk_vname ; By default, rname == mangled vname mov di,VKernelBuf+vk_rname - mov cx,FILENAME_MAX + call mangle_name + mov si,AppendBuf ; Default append==global append + mov di,VKernelBuf+vk_append + mov cx,[AppendLen] + mov [VKernelBuf+vk_appendlen],cx 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 @@ -307,18 +334,39 @@ 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 - xor al,al - stosb ; Null-terminate + mov byte [di],0 ; Null-terminate pop si ret @@ -330,9 +378,14 @@ xor ax,ax mov cx,vk_size rep stosb + .again: - call getcommand - jnc .again ; If not EOF do it 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 @@ -341,32 +394,42 @@ ; commit_vk: Store the current VKernelBuf into buffer segment ; commit_vk: - ; For better compression, clean up the append field - mov ax,[VKernelBuf+vk_appendlen] + cmp byte [VKernel],0 + jz .nolabel ; Nothing to commit... + mov di,VKernelBuf+vk_append - add di,ax + 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 temporarily into trackbuf - mov si,VKernelBuf - mov di,trackbuf - mov cx,vk_size + ; Pack into high memory + mov esi,VKernelBuf + mov edi,[VKernelEnd] + mov ecx,vk_size call rllpack - ; Now DX = number of bytes - mov di,[VKernelBytes] - mov cx,dx - add dx,di - jc .overflow ; If > 1 segment - mov [VKernelBytes],dx - mov si,trackbuf - push es - push word vk_seg - pop es - rep movsb - pop es + mov [VKernelEnd],edi +.nolabel: ret .overflow: mov si,vk_overflow_msg @@ -375,8 +438,18 @@ 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 - align 4, db 0 + ; 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 @@ -385,13 +458,18 @@ 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 -SerialPort dw 0 ; Serial port base (or 0 for no serial port) -VKernelBytes dw 0 ; Number of bytes used by vkernels +IncludeLevel dw 1 ; Nesting level +DefaultLevel dw 0 ; The current level of default VKernel db 0 ; Have we seen any "label" statements? - section .latebss +%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