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>
118 cmp al,'N' & 1Fh ; <Ctrl-N>
120 cmp al,'U' & 1Fh ; <Ctrl-U>
121 je kill_command ; Kill input line
122 cmp al,'V' & 1Fh ; <Ctrl-V>
124 cmp al,'X' & 1Fh ; <Ctrl-X>
126 cmp al,08h ; Backspace
128 backspace: cmp di,command_line ; Make sure there is anything
129 je get_char ; to erase
130 dec di ; Unstore one character
131 mov si,wipe_char ; and erase it from the screen
145 mov byte [FuncFlag],1
149 cmp word [NoComplete],0 ; Label completion enabled?
151 push di ; Save pointer
155 mov esi,[MallocStart] ; Start from top of memory
160 push cx ; save command line size
164 ; ESI updated on return
166 sub di,cx ; Return to beginning of buf
167 pop cx ; restore command line size
196 je .zero ; <Ctrl-F>0 = F10
197 or al,20h ; Lower case
200 cmp al,'a' ; F10-F12 = <Ctrl-F>A, B, C
214 ; AL = 0 if we get here
228 show_help: ; AX = func key # (0 = F1, 9 = F10, 11 = F12)
229 push di ; Save end-of-cmdline pointer
230 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
233 cmp byte [di+NULLOFFSET],NULLFILE
234 je short fk_nofile ; Undefined F-key
236 jz short fk_nofile ; File not found
242 push di ; Command line write pointer
243 mov si,syslinux_banner
252 ; ... fall through ...
254 ; Write the boot prompt and command line again and
255 ; wait for input. Note that this expects the cursor
256 ; to already have been CRLF'd, and that the old value
257 ; of DI (the command line write pointer) is on the stack.
261 pop di ; Command line write pointer
263 mov byte [di],0 ; Null-terminate command line
265 call writestr ; Write command line so far
270 ; Show system info (in the form of the sysappend strings)
274 pm_call print_sysappend
278 ; Jump here to run the default command line
281 cmp word [DefaultLevel],0 ; No UI or DEFAULT?
283 mov si,no_default_msg
285 cmp word [NoEscape],0 ; NOESCAPE but no DEFAULT?
286 jne kaboom ; If so, we're stuck!
292 mov cx,(max_cmd_len+4) >> 2
294 jmp short load_kernel
297 no_default_msg db 'No DEFAULT or UI configuration directive found!'
303 ; Jump here when the command line is completed
307 cmp di,command_line ; Did we just hit return?
309 xor al,al ; Store a final null
312 load_kernel: ; Load the kernel now
314 ; First we need to mangle the kernel name the way DOS would...
319 pm_call pm_mangle_name
322 ; Fast-forward to first option (we start over from the beginning, since
323 ; pm_mangle_name doesn't necessarily return a consistent ending state.)
328 clin_is_wsp: and al,al
333 clin_opt_ptr: dec si ; Point to first nonblank
334 mov [CmdOptPtr],si ; Save ptr to first option
336 ; If "allowoptions 0", put a null character here in order to ignore any
337 ; user-specified options.
339 mov ax,[AllowOptions]
346 ; Now check if it is a "virtual kernel"
349 mov esi,[MallocStart] ; Start from top of memory
356 ; ESI updated on return
358 sub di,cx ; Return to beginning of buf
371 cmp byte [di],0 ; Must match end of string
376 ; We *are* using a "virtual kernel"
380 push word real_mode_seg
383 mov si,VKernelBuf+vk_append
384 mov cx,[VKernelBuf+vk_appendlen]
386 mov byte [es:di],cl ; Null-terminate
387 mov [CmdLinePtr],di ; Where to add rest of cmd
391 mov si,VKernelBuf+vk_rname
392 mov cx,FILENAME_MAX ; We need ECX == CX later
395 mov eax,[VKernelBuf+vk_sysappend]
397 xor bx,bx ; Try only one version
399 mov al,[VKernelBuf+vk_type]
402 ; Is this a "localboot" pseudo-kernel?
403 cmp al,VK_LOCALBOOT ; al == KernelType
404 mov ax,[VKernelBuf+vk_rname] ; Possible localboot type
410 ; Not a "virtual kernel" - check that's OK and construct the command line
412 cmp word [AllowImplicit],byte 0
423 mov byte [es:di],cl ; Null-terminate
429 mov [KernelType], cl ; CL == 0 here
432 ; Find the kernel on disk
434 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
437 jbe bad_kernel ; Missing kernel name
439 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
440 repne scasb ; Scan for final null
442 dec di ; Point to final null
443 .no_skip: mov [KernelExtPtr],di
445 .search_loop: push bx
446 mov di,KernelName ; Search on disk
450 mov eax,[bx] ; Try a different extension
451 mov si,[KernelExtPtr]
455 cmp bx,exten_table_end
456 jna .search_loop ; allow == case (final case)
457 ; Fall into bad_kernel
459 ; bad_kernel: Kernel image not found
460 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
468 mov si,err_notfound ; Complain about missing kernel
473 jmp abort_load ; Ask user for clue
476 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
487 pop di ; <E> di == command_line
488 pop bx ; <D> bx == [OnerrorLen]
489 je bad_kernel.really ; Onerror matches command_line already
490 neg bx ; bx == -[OnerrorLen]
491 lea cx,[max_cmd_len+bx]
492 ; CX == max_cmd_len-[OnerrorLen]
493 mov di,command_line+max_cmd_len-1
494 mov byte [di+1],0 ; Enforce null-termination
497 rep movsb ; Make space in command_line
499 pop cx ; <C> cx == [OnerrorLen]
500 pop di ; <B> di == command_line
501 pop si ; <A> si == Onerror
506 ; kernel_corrupt: Called if the kernel file does not seem healthy
508 kernel_corrupt: mov si,err_notkernel
512 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
513 ; which can be adjusted by the caller based on the corresponding
514 ; master variables; on return they're updated.
516 ; This cheats. If we say "no timeout" we actually get a timeout of
524 push word [__jiffies]
529 cmp ax,[__jiffies] ; Has the timer advanced?
532 dec dword [ThisKbdTo]
534 dec dword [ThisTotalTo]
539 pop cx ; Discard return address
541 mov si,Ontimeout ; Copy ontimeout command
543 mov cx,[OntimeoutLen] ; if we have one...
554 ; This is it! We have a name (and location on the disk)... let's load
555 ; that sucker!! First we have to decide what kind of file this is; base
556 ; that decision on the file extension. The following extensions are
557 ; recognized; case insensitive:
559 ; .com - COMBOOT image
560 ; .cbt - COMBOOT image
563 ; .0 - PXE bootstrap program (PXELINUX only)
565 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
566 ; .img - Floppy image (ISOLINUX only)
568 ; Anything else is assumed to be a Linux kernel.
577 ; Alternate entry point for which the return from
578 ; searchdir is stored in memory. This is used for
579 ; COMBOOT function INT 22h, AX=0016h.
586 ; Common initialization for all kernel types
595 ; Default memory limit, can be overridden by image loaders
596 mov eax,[HighMemRsvd]
597 mov [MyHighMemSize],eax
609 .one_step: mov ecx,[di-4] ; 4 bytes before end
614 ; At this point, EAX contains the size of the kernel, SI contains
615 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
617 movzx di,byte [KernelType]
619 jmp [kerneltype_table+di]
622 or ecx,20202000h ; Force lower case (except dot)
641 ; Otherwise Linux kernel
646 call make_plain_cmdline
647 pm_call pm_is_config_file
653 ; This is an image type we can't deal with
662 is_bss_sector equ is_bad_image
665 is_disk_image equ is_bad_image ; No longer supported
668 boot_prompt db 'boot: ', 0
669 wipe_char db BS, ' ', BS, 0
670 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
671 err_notfound db 'Could not find kernel image: ',0
672 err_notkernel db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
677 dw is_unknown_filetype ; VK_KERNEL
678 dw is_linux_kernel ; VK_LINUX
679 dw is_bootsector ; VK_BOOT
680 dw is_bss_sector ; VK_BSS
681 dw is_bootsector ; VK_PXE
682 dw is_disk_image ; VK_FDIMAGE
683 dw is_comboot_image ; VK_COMBOOT
684 dw is_com32_image ; VK_COM32
685 dw is_config_file ; VK_CONFIG
689 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
690 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
691 KernelExtPtr resw 1 ; During search, final null pointer
692 CmdOptPtr resw 1 ; Pointer to first option on cmd line
693 KbdFlags resb 1 ; Check for keyboard escapes
694 FuncFlag resb 1 ; Escape sequences received from keyboard
695 KernelType resb 1 ; Kernel type, from vkernel, if known
699 ; Linux kernel loading code is common.
701 %include "runkernel.inc"
704 ; COMBOOT-loading code
706 %include "comboot.inc"
708 %include "cmdline.inc"
711 ; Boot sector loading code
713 %include "bootsect.inc"
721 ; Hardware cleanup common code
723 %include "cleanup.inc"