1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
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.
12 ;; -----------------------------------------------------------------------
15 ; This file should be entered with the config file open (for getc)
18 call parse_config ; Parse configuration file
23 ; Check for an ADV boot-once entry
30 ; We apparently have a boot-once set; clear it and
31 ; then execute the boot-once...
33 ; Save the boot-once data; SI = data, CX = length
39 ; Clear the boot-once data from the ADV
40 xor cx,cx ; Set to zero = delete
49 ; Check whether or not we are supposed to display the boot prompt.
52 test byte [KbdFlags],5Bh ; Shift Alt Caps Scroll
54 cmp word [ForcePrompt],0 ; Force prompt?
56 cmp word [DefaultLevel],1 ; Active UI statement?
60 cmp word [NoEscape],0 ; If NOESCAPE, no prompt,
61 jne auto_boot ; always run default cmd
66 mov byte [FuncFlag],0 ; <Ctrl-F> not pressed
70 ; get the very first character -- we can either time
71 ; out, or receive a character press at this time. Some dorky BIOSes stuff
72 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
74 clear_buffer: mov ah,11h ; Check for pending char
79 jmp short clear_buffer
81 ; For the first character, both KbdTimeout and
82 ; TotalTimeout apply; after that, only TotalTimeout.
85 mov eax,[TotalTimeout]
92 and dword [ThisKbdTo],0 ; For the next time...
97 got_ascii: cmp al,7Fh ; <DEL> == <BS>
102 cmp di,command_line ; Space must not be first
104 enter_char: test byte [FuncFlag],1
105 jnz ctrl_f ; Keystroke after <Ctrl-F>
106 cmp di,max_cmd_len+command_line ; Check there's space
109 call writechr ; Echo to screen
116 cmp al,'F' & 1Fh ; <Ctrl-F>
119 cmp al,'N' & 1Fh ; <Ctrl-N>
122 cmp al,'U' & 1Fh ; <Ctrl-U>
123 je kill_command ; Kill input line
124 cmp al,'V' & 1Fh ; <Ctrl-V>
126 cmp al,'X' & 1Fh ; <Ctrl-X>
128 cmp al,08h ; Backspace
130 backspace: cmp di,command_line ; Make sure there is anything
131 je get_char ; to erase
132 dec di ; Unstore one character
133 mov si,wipe_char ; and erase it from the screen
147 mov byte [FuncFlag],1
151 cmp word [NoComplete],0 ; Label completion enabled?
153 push di ; Save pointer
157 mov esi,[HighMemSize] ; Start from top of memory
162 push cx ; save command line size
166 ; ESI updated on return
168 sub di,cx ; Return to beginning of buf
169 pop cx ; restore command line size
198 je .zero ; <Ctrl-F>0 = F10
199 or al,20h ; Lower case
202 cmp al,'a' ; F10-F12 = <Ctrl-F>A, B, C
216 ; AL = 0 if we get here
230 show_help: ; AX = func key # (0 = F1, 9 = F10, 11 = F12)
231 push di ; Save end-of-cmdline pointer
232 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
235 cmp byte [di+NULLOFFSET],NULLFILE
236 je short fk_nofile ; Undefined F-key
238 jz short fk_nofile ; File not found
244 push di ; Command line write pointer
245 mov si,syslinux_banner
254 ; ... fall through ...
256 ; Write the boot prompt and command line again and
257 ; wait for input. Note that this expects the cursor
258 ; to already have been CRLF'd, and that the old value
259 ; of DI (the command line write pointer) is on the stack.
263 pop di ; Command line write pointer
265 mov byte [di],0 ; Null-terminate command line
267 call writestr ; Write command line so far
272 ; Show network info (in the form of the ipappend strings)
276 push di ; Command line write pointer
278 mov si,IPAppends ; See comboot.doc
292 ; Jump here to run the default command line
295 cmp word [DefaultLevel],0 ; No UI or DEFAULT?
297 mov si,no_default_msg
299 cmp word [NoEscape],0 ; NOESCAPE but no DEFAULT?
300 jne kaboom ; If so, we're stuck!
306 mov cx,(max_cmd_len+4) >> 2
308 jmp short load_kernel
311 no_default_msg db 'No DEFAULT or UI configuration directive found!'
317 ; Jump here when the command line is completed
321 cmp di,command_line ; Did we just hit return?
323 xor al,al ; Store a final null
326 load_kernel: ; Load the kernel now
328 ; First we need to mangle the kernel name the way DOS would...
333 pm_call pm_mangle_name
336 ; Fast-forward to first option (we start over from the beginning, since
337 ; pm_mangle_name doesn't necessarily return a consistent ending state.)
342 clin_is_wsp: and al,al
347 clin_opt_ptr: dec si ; Point to first nonblank
348 mov [CmdOptPtr],si ; Save ptr to first option
350 ; If "allowoptions 0", put a null character here in order to ignore any
351 ; user-specified options.
353 mov ax,[AllowOptions]
360 ; Now check if it is a "virtual kernel"
363 mov esi,[HighMemSize] ; Start from top of memory
370 ; ESI updated on return
372 sub di,cx ; Return to beginning of buf
385 cmp byte [di],0 ; Must match end of string
390 ; We *are* using a "virtual kernel"
394 push word real_mode_seg
397 mov si,VKernelBuf+vk_append
398 mov cx,[VKernelBuf+vk_appendlen]
400 mov byte [es:di],cl ; Null-terminate
401 mov [CmdLinePtr],di ; Where to add rest of cmd
405 mov si,VKernelBuf+vk_rname
406 mov cx,FILENAME_MAX ; We need ECX == CX later
410 mov al,[VKernelBuf+vk_ipappend]
413 xor bx,bx ; Try only one version
415 mov al,[VKernelBuf+vk_type]
419 ; Is this a "localboot" pseudo-kernel?
420 cmp al,VK_LOCALBOOT ; al == KernelType
421 mov ax,[VKernelBuf+vk_rname] ; Possible localboot type
428 ; Not a "virtual kernel" - check that's OK and construct the command line
430 cmp word [AllowImplicit],byte 0
441 mov byte [es:di],cl ; Null-terminate
447 mov [KernelType], cl ; CL == 0 here
450 ; Find the kernel on disk
452 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
455 jbe bad_kernel ; Missing kernel name
457 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
458 repne scasb ; Scan for final null
460 dec di ; Point to final null
461 .no_skip: mov [KernelExtPtr],di
463 .search_loop: push bx
464 mov di,KernelName ; Search on disk
468 mov eax,[bx] ; Try a different extension
469 mov si,[KernelExtPtr]
473 cmp bx,exten_table_end
474 jna .search_loop ; allow == case (final case)
475 ; Fall into bad_kernel
477 ; bad_kernel: Kernel image not found
478 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
486 mov si,err_notfound ; Complain about missing kernel
491 jmp abort_load ; Ask user for clue
494 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
505 pop di ; <E> di == command_line
506 pop bx ; <D> bx == [OnerrorLen]
507 je bad_kernel.really ; Onerror matches command_line already
508 neg bx ; bx == -[OnerrorLen]
509 lea cx,[max_cmd_len+bx]
510 ; CX == max_cmd_len-[OnerrorLen]
511 mov di,command_line+max_cmd_len-1
512 mov byte [di+1],0 ; Enforce null-termination
515 rep movsb ; Make space in command_line
517 pop cx ; <C> cx == [OnerrorLen]
518 pop di ; <B> di == command_line
519 pop si ; <A> si == Onerror
524 ; kernel_corrupt: Called if the kernel file does not seem healthy
526 kernel_corrupt: mov si,err_notkernel
530 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
531 ; which can be adjusted by the caller based on the corresponding
532 ; master variables; on return they're updated.
534 ; This cheats. If we say "no timeout" we actually get a timeout of
542 push word [__jiffies]
547 cmp ax,[__jiffies] ; Has the timer advanced?
550 dec dword [ThisKbdTo]
552 dec dword [ThisTotalTo]
557 pop cx ; Discard return address
559 mov si,Ontimeout ; Copy ontimeout command
561 mov cx,[OntimeoutLen] ; if we have one...
572 ; This is it! We have a name (and location on the disk)... let's load
573 ; that sucker!! First we have to decide what kind of file this is; base
574 ; that decision on the file extension. The following extensions are
575 ; recognized; case insensitive:
577 ; .com - COMBOOT image
578 ; .cbt - COMBOOT image
581 ; .0 - PXE bootstrap program (PXELINUX only)
583 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
584 ; .img - Floppy image (ISOLINUX only)
586 ; Anything else is assumed to be a Linux kernel.
595 ; Alternate entry point for which the return from
596 ; searchdir is stored in memory. This is used for
597 ; COMBOOT function INT 22h, AX=0016h.
604 ; Common initialization for all kernel types
613 ; Default memory limit, can be overridden by image loaders
614 mov eax,[HighMemRsvd]
615 mov [MyHighMemSize],eax
627 .one_step: mov ecx,[di-4] ; 4 bytes before end
632 ; At this point, EAX contains the size of the kernel, SI contains
633 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
635 movzx di,byte [KernelType]
637 jmp [kerneltype_table+di]
640 or ecx,20202000h ; Force lower case (except dot)
663 ; Otherwise Linux kernel
668 call make_plain_cmdline
669 pm_call pm_is_config_file
675 ; This is an image type we can't deal with
684 is_bss_sector equ is_bad_image
689 is_disk_image equ is_bad_image
693 boot_prompt db 'boot: ', 0
694 wipe_char db BS, ' ', BS, 0
695 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
696 err_notfound db 'Could not find kernel image: ',0
697 err_notkernel db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
702 dw is_unknown_filetype ; VK_KERNEL
703 dw is_linux_kernel ; VK_LINUX
704 dw is_bootsector ; VK_BOOT
705 dw is_bss_sector ; VK_BSS
706 dw is_bootsector ; VK_PXE
707 dw is_disk_image ; VK_FDIMAGE
708 dw is_comboot_image ; VK_COMBOOT
709 dw is_com32_image ; VK_COM32
710 dw is_config_file ; VK_CONFIG
714 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
715 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
716 KernelExtPtr resw 1 ; During search, final null pointer
717 CmdOptPtr resw 1 ; Pointer to first option on cmd line
718 KbdFlags resb 1 ; Check for keyboard escapes
719 FuncFlag resb 1 ; Escape sequences received from keyboard
720 KernelType resb 1 ; Kernel type, from vkernel, if known
724 ; Linux kernel loading code is common.
726 %include "runkernel.inc"
729 ; COMBOOT-loading code
731 %include "comboot.inc"
733 %include "cmdline.inc"
736 ; Boot sector loading code
738 %include "bootsect.inc"
746 ; Hardware cleanup common code
748 %include "cleanup.inc"