1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009 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
297 mov cx,(max_cmd_len+4) >> 2
299 jmp short load_kernel
302 ; Jump here when the command line is completed
306 cmp di,command_line ; Did we just hit return?
308 xor al,al ; Store a final null
311 load_kernel: ; Load the kernel now
313 ; First we need to mangle the kernel name the way DOS would...
321 ; Fast-forward to first option (we start over from the beginning, since
322 ; mangle_name doesn't necessarily return a consistent ending state.)
327 clin_is_wsp: and al,al
332 clin_opt_ptr: dec si ; Point to first nonblank
333 mov [CmdOptPtr],si ; Save ptr to first option
335 ; If "allowoptions 0", put a null character here in order to ignore any
336 ; user-specified options.
338 mov ax,[AllowOptions]
345 ; Now check if it is a "virtual kernel"
348 mov esi,[HighMemSize] ; Start from top of memory
355 ; ESI updated on return
357 sub di,cx ; Return to beginning of buf
370 cmp byte [di],0 ; Must match end of string
375 ; We *are* using a "virtual kernel"
379 push word real_mode_seg
382 mov si,VKernelBuf+vk_append
383 mov cx,[VKernelBuf+vk_appendlen]
385 mov [CmdLinePtr],di ; Where to add rest of cmd
389 mov si,VKernelBuf+vk_rname
390 mov cx,FILENAME_MAX ; We need ECX == CX later
394 mov al,[VKernelBuf+vk_ipappend]
397 xor bx,bx ; Try only one version
399 mov al, [VKernelBuf+vk_type]
403 ; Is this a "localboot" pseudo-kernel?
405 cmp byte [VKernelBuf+vk_rname+4], 0
407 cmp byte [VKernelBuf+vk_rname], 0
409 jne get_kernel ; No, it's real, go get it
411 mov ax, [VKernelBuf+vk_rname+1]
420 ; Not a "virtual kernel" - check that's OK and construct the command line
422 cmp word [AllowImplicit],byte 0
438 mov [KernelType], cl ; CL == 0 here
441 ; Find the kernel on disk
443 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
444 mov di,KernelName+4*IS_PXELINUX
446 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
447 repne scasb ; Scan for final null
449 dec di ; Point to final null
450 .no_skip: mov [KernelExtPtr],di
452 .search_loop: push bx
453 mov di,KernelName ; Search on disk
457 mov eax,[bx] ; Try a different extension
458 mov si,[KernelExtPtr]
462 cmp bx,exten_table_end
463 jna .search_loop ; allow == case (final case)
464 ; Fall into bad_kernel
466 ; bad_kernel: Kernel image not found
467 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
478 call unmangle_name ; Get human form
479 mov si,err_notfound ; Complain about missing kernel
484 jmp abort_load ; Ask user for clue
487 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
498 pop di ; <E> di == command_line
499 pop bx ; <D> bx == [OnerrorLen]
500 je bad_kernel.really ; Onerror matches command_line already
501 neg bx ; bx == -[OnerrorLen]
502 lea cx,[max_cmd_len+bx]
503 ; CX == max_cmd_len-[OnerrorLen]
504 mov di,command_line+max_cmd_len-1
505 mov byte [di+1],0 ; Enforce null-termination
508 rep movsb ; Make space in command_line
510 pop cx ; <C> cx == [OnerrorLen]
511 pop di ; <B> di == command_line
512 pop si ; <A> si == Onerror
517 ; kernel_corrupt: Called if the kernel file does not seem healthy
519 kernel_corrupt: mov si,err_notkernel
523 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
524 ; which can be adjusted by the caller based on the corresponding
525 ; master variables; on return they're updated.
527 ; This cheats. If we say "no timeout" we actually get a timeout of
535 push word [BIOS_timer]
539 cmp ax,[BIOS_timer] ; Has the timer advanced?
543 dec dword [ThisKbdTo]
545 dec dword [ThisTotalTo]
550 pop cx ; Discard return address
552 mov si,Ontimeout ; Copy ontimeout command
554 mov cx,[OntimeoutLen] ; if we have one...
565 ; This is it! We have a name (and location on the disk)... let's load
566 ; that sucker!! First we have to decide what kind of file this is; base
567 ; that decision on the file extension. The following extensions are
568 ; recognized; case insensitive:
570 ; .com - COMBOOT image
571 ; .cbt - COMBOOT image
574 ; .0 - PXE bootstrap program (PXELINUX only)
576 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
577 ; .img - Floppy image (ISOLINUX only)
579 ; Anything else is assumed to be a Linux kernel.
588 ; Alternate entry point for which the return from
589 ; searchdir is stored in memory. This is used for
590 ; COMBOOT function INT 22h, AX=0016h.
597 ; Common initialization for all kernel types
610 mov [KernelCNameLen],di
612 ; Default memory limit, can be overridden by image loaders
613 mov eax,[HighMemRsvd]
614 mov [MyHighMemSize],eax
620 mov di,KernelName+4*IS_PXELINUX
626 .one_step: mov ecx,[di-4] ; 4 bytes before end
631 ; At this point, EAX contains the size of the kernel, SI contains
632 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
634 movzx di,byte [KernelType]
636 jmp [kerneltype_table+di]
639 or ecx,20202000h ; Force lower case (except dot)
662 ; Otherwise Linux kernel
667 mov si,KernelCName ; Save the config file name, for posterity
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"