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]
418 ; Is this a "localboot" pseudo-kernel?
419 cmp al,VK_LOCALBOOT ; al == KernelType
420 mov ax,[VKernelBuf+vk_rname] ; Possible localboot type
426 ; Not a "virtual kernel" - check that's OK and construct the command line
428 cmp word [AllowImplicit],byte 0
439 mov byte [es:di],cl ; Null-terminate
445 mov [KernelType], cl ; CL == 0 here
448 ; Find the kernel on disk
450 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
453 jbe bad_kernel ; Missing kernel name
455 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
456 repne scasb ; Scan for final null
458 dec di ; Point to final null
459 .no_skip: mov [KernelExtPtr],di
461 .search_loop: push bx
462 mov di,KernelName ; Search on disk
466 mov eax,[bx] ; Try a different extension
467 mov si,[KernelExtPtr]
471 cmp bx,exten_table_end
472 jna .search_loop ; allow == case (final case)
473 ; Fall into bad_kernel
475 ; bad_kernel: Kernel image not found
476 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
484 mov si,err_notfound ; Complain about missing kernel
489 jmp abort_load ; Ask user for clue
492 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
503 pop di ; <E> di == command_line
504 pop bx ; <D> bx == [OnerrorLen]
505 je bad_kernel.really ; Onerror matches command_line already
506 neg bx ; bx == -[OnerrorLen]
507 lea cx,[max_cmd_len+bx]
508 ; CX == max_cmd_len-[OnerrorLen]
509 mov di,command_line+max_cmd_len-1
510 mov byte [di+1],0 ; Enforce null-termination
513 rep movsb ; Make space in command_line
515 pop cx ; <C> cx == [OnerrorLen]
516 pop di ; <B> di == command_line
517 pop si ; <A> si == Onerror
522 ; kernel_corrupt: Called if the kernel file does not seem healthy
524 kernel_corrupt: mov si,err_notkernel
528 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
529 ; which can be adjusted by the caller based on the corresponding
530 ; master variables; on return they're updated.
532 ; This cheats. If we say "no timeout" we actually get a timeout of
540 push word [__jiffies]
545 cmp ax,[__jiffies] ; Has the timer advanced?
548 dec dword [ThisKbdTo]
550 dec dword [ThisTotalTo]
555 pop cx ; Discard return address
557 mov si,Ontimeout ; Copy ontimeout command
559 mov cx,[OntimeoutLen] ; if we have one...
570 ; This is it! We have a name (and location on the disk)... let's load
571 ; that sucker!! First we have to decide what kind of file this is; base
572 ; that decision on the file extension. The following extensions are
573 ; recognized; case insensitive:
575 ; .com - COMBOOT image
576 ; .cbt - COMBOOT image
579 ; .0 - PXE bootstrap program (PXELINUX only)
581 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
582 ; .img - Floppy image (ISOLINUX only)
584 ; Anything else is assumed to be a Linux kernel.
593 ; Alternate entry point for which the return from
594 ; searchdir is stored in memory. This is used for
595 ; COMBOOT function INT 22h, AX=0016h.
602 ; Common initialization for all kernel types
611 ; Default memory limit, can be overridden by image loaders
612 mov eax,[HighMemRsvd]
613 mov [MyHighMemSize],eax
625 .one_step: mov ecx,[di-4] ; 4 bytes before end
630 ; At this point, EAX contains the size of the kernel, SI contains
631 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
633 movzx di,byte [KernelType]
635 jmp [kerneltype_table+di]
638 or ecx,20202000h ; Force lower case (except dot)
661 ; Otherwise Linux kernel
666 call make_plain_cmdline
667 pm_call pm_is_config_file
673 ; This is an image type we can't deal with
682 is_bss_sector equ is_bad_image
687 is_disk_image equ is_bad_image
691 boot_prompt db 'boot: ', 0
692 wipe_char db BS, ' ', BS, 0
693 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
694 err_notfound db 'Could not find kernel image: ',0
695 err_notkernel db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
700 dw is_unknown_filetype ; VK_KERNEL
701 dw is_linux_kernel ; VK_LINUX
702 dw is_bootsector ; VK_BOOT
703 dw is_bss_sector ; VK_BSS
704 dw is_bootsector ; VK_PXE
705 dw is_disk_image ; VK_FDIMAGE
706 dw is_comboot_image ; VK_COMBOOT
707 dw is_com32_image ; VK_COM32
708 dw is_config_file ; VK_CONFIG
712 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
713 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
714 KernelExtPtr resw 1 ; During search, final null pointer
715 CmdOptPtr resw 1 ; Pointer to first option on cmd line
716 KbdFlags resb 1 ; Check for keyboard escapes
717 FuncFlag resb 1 ; Escape sequences received from keyboard
718 KernelType resb 1 ; Kernel type, from vkernel, if known
722 ; Linux kernel loading code is common.
724 %include "runkernel.inc"
727 ; COMBOOT-loading code
729 %include "comboot.inc"
731 %include "cmdline.inc"
734 ; Boot sector loading code
736 %include "bootsect.inc"
744 ; Hardware cleanup common code
746 %include "cleanup.inc"