1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;; (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
14 ; This file should be entered with the config file open (for getc)
17 call parse_config ; Parse configuration file
22 ; Check for an ADV boot-once entry
29 ; We apparently have a boot-once set; clear it and
30 ; then execute the boot-once...
32 ; Save the boot-once data; SI = data, CX = length
38 ; Clear the boot-once data from the ADV
39 xor cx,cx ; Set to zero = delete
48 ; Check whether or not we are supposed to display the boot prompt.
51 cmp word [ForcePrompt],0 ; Force prompt?
53 test byte [KbdFlags],5Bh ; Shift Alt Caps Scroll
54 jz auto_boot ; If neither, default boot
57 cmp word [NoEscape],0 ; If NOESCAPE, no prompt,
58 jne auto_boot ; always run default cmd
63 mov byte [FuncFlag],0 ; <Ctrl-F> not pressed
67 ; get the very first character -- we can either time
68 ; out, or receive a character press at this time. Some dorky BIOSes stuff
69 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
71 clear_buffer: mov ah,11h ; Check for pending char
76 jmp short clear_buffer
78 ; For the first character, both KbdTimeout and
79 ; TotalTimeout apply; after that, only TotalTimeout.
82 mov eax,[TotalTimeout]
89 and dword [ThisKbdTo],0 ; For the next time...
94 got_ascii: cmp al,7Fh ; <DEL> == <BS>
99 cmp di,command_line ; Space must not be first
101 enter_char: test byte [FuncFlag],1
102 jnz ctrl_f ; Keystroke after <Ctrl-F>
103 cmp di,max_cmd_len+command_line ; Check there's space
106 call writechr ; Echo to screen
111 cmp al,'F' & 1Fh ; <Ctrl-F>
114 cmp al,'N' & 1Fh ; <Ctrl-N>
117 cmp al,'U' & 1Fh ; <Ctrl-U>
118 je kill_command ; Kill input line
119 cmp al,'V' & 1Fh ; <Ctrl-V>
121 cmp al,'X' & 1Fh ; <Ctrl-X>
123 cmp al,08h ; Backspace
125 backspace: cmp di,command_line ; Make sure there is anything
126 je get_char ; to erase
127 dec di ; Unstore one character
128 mov si,wipe_char ; and erase it from the screen
142 mov byte [FuncFlag],1
150 je .zero ; <Ctrl-F>0 = F10
151 or al,20h ; Lower case
154 cmp al,'a' ; F10-F12 = <Ctrl-F>A, B, C
168 ; AL = 0 if we get here
182 show_help: ; AX = func key # (0 = F1, 9 = F10, 11 = F12)
183 push di ; Save end-of-cmdline pointer
184 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
187 cmp byte [di+NULLOFFSET],NULLFILE
188 je short fk_nofile ; Undefined F-key
190 jz short fk_nofile ; File not found
196 push di ; Command line write pointer
197 mov si,syslinux_banner
206 ; ... fall through ...
208 ; Write the boot prompt and command line again and
209 ; wait for input. Note that this expects the cursor
210 ; to already have been CRLF'd, and that the old value
211 ; of DI (the command line write pointer) is on the stack.
215 pop di ; Command line write pointer
217 mov byte [di],0 ; Null-terminate command line
219 call writestr ; Write command line so far
224 ; Show network info (in the form of the ipappend strings)
228 push di ; Command line write pointer
230 mov si,IPAppends ; See comboot.doc
244 ; Jump here to run the default command line
249 mov cx,(max_cmd_len+4) >> 2
251 jmp short load_kernel
254 ; Jump here when the command line is completed
258 cmp di,command_line ; Did we just hit return?
260 xor al,al ; Store a final null
263 load_kernel: ; Load the kernel now
265 ; First we need to mangle the kernel name the way DOS would...
273 ; Fast-forward to first option (we start over from the beginning, since
274 ; mangle_name doesn't necessarily return a consistent ending state.)
279 clin_is_wsp: and al,al
284 clin_opt_ptr: dec si ; Point to first nonblank
285 mov [CmdOptPtr],si ; Save ptr to first option
287 ; If "allowoptions 0", put a null character here in order to ignore any
288 ; user-specified options.
290 mov ax,[AllowOptions]
297 ; Now check if it is a "virtual kernel"
300 mov esi,[HighMemSize] ; Start from top of memory
307 ; ESI updated on return
309 sub di,cx ; Return to beginning of buf
322 cmp byte [di],0 ; Must match end of string
327 ; We *are* using a "virtual kernel"
331 push word real_mode_seg
334 mov si,VKernelBuf+vk_append
335 mov cx,[VKernelBuf+vk_appendlen]
337 mov [CmdLinePtr],di ; Where to add rest of cmd
341 mov si,VKernelBuf+vk_rname
342 mov cx,FILENAME_MAX ; We need ECX == CX later
346 mov al,[VKernelBuf+vk_ipappend]
349 xor bx,bx ; Try only one version
351 mov al, [VKernelBuf+vk_type]
355 ; Is this a "localboot" pseudo-kernel?
357 cmp byte [VKernelBuf+vk_rname+4], 0
359 cmp byte [VKernelBuf+vk_rname], 0
361 jne get_kernel ; No, it's real, go get it
363 mov ax, [VKernelBuf+vk_rname+1]
372 ; Not a "virtual kernel" - check that's OK and construct the command line
374 cmp word [AllowImplicit],byte 0
390 mov [KernelType], cl ; CL == 0 here
393 ; Find the kernel on disk
395 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
396 mov di,KernelName+4*IS_PXELINUX
398 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
399 repne scasb ; Scan for final null
401 dec di ; Point to final null
402 .no_skip: mov [KernelExtPtr],di
404 .search_loop: push bx
405 mov di,KernelName ; Search on disk
409 mov eax,[bx] ; Try a different extension
410 mov si,[KernelExtPtr]
414 cmp bx,exten_table_end
415 jna .search_loop ; allow == case (final case)
416 ; Fall into bad_kernel
418 ; bad_kernel: Kernel image not found
419 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
430 call unmangle_name ; Get human form
431 mov si,err_notfound ; Complain about missing kernel
436 jmp abort_load ; Ask user for clue
439 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
450 pop di ; <E> di == command_line
451 pop bx ; <D> bx == [OnerrorLen]
452 je bad_kernel.really ; Onerror matches command_line already
453 neg bx ; bx == -[OnerrorLen]
454 lea cx,[max_cmd_len+bx]
455 ; CX == max_cmd_len-[OnerrorLen]
456 mov di,command_line+max_cmd_len-1
457 mov byte [di+1],0 ; Enforce null-termination
460 rep movsb ; Make space in command_line
462 pop cx ; <C> cx == [OnerrorLen]
463 pop di ; <B> di == command_line
464 pop si ; <A> si == Onerror
469 ; kernel_corrupt: Called if the kernel file does not seem healthy
471 kernel_corrupt: mov si,err_notkernel
475 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
476 ; which can be adjusted by the caller based on the corresponding
477 ; master variables; on return they're updated.
479 ; This cheats. If we say "no timeout" we actually get a timeout of
487 push word [BIOS_timer]
491 cmp ax,[BIOS_timer] ; Has the timer advanced?
495 dec dword [ThisKbdTo]
497 dec dword [ThisTotalTo]
502 pop cx ; Discard return address
504 mov si,Ontimeout ; Copy ontimeout command
506 mov cx,[OntimeoutLen] ; if we have one...
517 ; This is it! We have a name (and location on the disk)... let's load
518 ; that sucker!! First we have to decide what kind of file this is; base
519 ; that decision on the file extension. The following extensions are
520 ; recognized; case insensitive:
522 ; .com - COMBOOT image
523 ; .cbt - COMBOOT image
526 ; .0 - PXE bootstrap program (PXELINUX only)
528 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
529 ; .img - Floppy image (ISOLINUX only)
531 ; Anything else is assumed to be a Linux kernel.
540 ; Alternate entry point for which the return from
541 ; searchdir is stored in memory. This is used for
542 ; COMBOOT function INT 22h, AX=0016h.
553 mov [KernelCNameLen],di
555 ; Default memory limit, can be overridden by image loaders
556 mov eax,[HighMemRsvd]
557 mov [MyHighMemSize],eax
563 mov di,KernelName+4*IS_PXELINUX
569 .one_step: mov ecx,[di-4] ; 4 bytes before end
574 ; At this point, EAX contains the size of the kernel, SI contains
575 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
577 movzx di,byte [KernelType]
579 jmp [kerneltype_table+di]
582 or ecx,20202000h ; Force lower case (except dot)
605 ; Otherwise Linux kernel
610 mov si,KernelCName ; Save the config file name, for posterity
618 ; This is an image type we can't deal with
624 %if IS_SYSLINUX || IS_MDSLINUX
627 is_bss_sector equ is_bad_image
632 is_disk_image equ is_bad_image
636 boot_prompt db 'boot: ', 0
637 wipe_char db BS, ' ', BS, 0
638 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
639 err_notfound db 'Could not find kernel image: ',0
640 err_notkernel db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
645 dw is_unknown_filetype ; VK_KERNEL
646 dw is_linux_kernel ; VK_LINUX
647 dw is_bootsector ; VK_BOOT
648 dw is_bss_sector ; VK_BSS
649 dw is_bootsector ; VK_PXE
650 dw is_disk_image ; VK_FDIMAGE
651 dw is_comboot_image ; VK_COMBOOT
652 dw is_com32_image ; VK_COM32
653 dw is_config_file ; VK_CONFIG
657 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
658 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
659 KernelExtPtr resw 1 ; During search, final null pointer
660 CmdOptPtr resw 1 ; Pointer to first option on cmd line
661 KbdFlags resb 1 ; Check for keyboard escapes
662 FuncFlag resb 1 ; Escape sequences received from keyboard
663 KernelType resb 1 ; Kernel type, from vkernel, if known
667 ; Linux kernel loading code is common.
669 %include "runkernel.inc"
672 ; COMBOOT-loading code
674 %include "comboot.inc"
676 %include "cmdline.inc"
679 ; Boot sector loading code
681 %include "bootsect.inc"
689 ; Hardware cleanup common code
691 %include "cleanup.inc"