1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2007 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
23 ; Check whether or not we are supposed to display the boot prompt.
26 cmp word [ForcePrompt],0 ; Force prompt?
28 test byte [KbdFlags],5Bh ; Shift Alt Caps Scroll
29 jz auto_boot ; If neither, default boot
32 cmp word [NoEscape],0 ; If NOESCAPE, no prompt,
33 jne auto_boot ; always run default cmd
38 mov byte [FuncFlag],0 ; <Ctrl-F> not pressed
42 ; get the very first character -- we can either time
43 ; out, or receive a character press at this time. Some dorky BIOSes stuff
44 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
46 clear_buffer: mov ah,11h ; Check for pending char
51 jmp short clear_buffer
53 ; For the first character, both KbdTimeout and
54 ; TotalTimeout apply; after that, only TotalTimeout.
57 mov eax,[TotalTimeout]
64 and dword [ThisKbdTo],0 ; For the next time...
69 got_ascii: cmp al,7Fh ; <DEL> == <BS>
74 cmp di,command_line ; Space must not be first
76 enter_char: test byte [FuncFlag],1
77 jnz ctrl_f ; Keystroke after <Ctrl-F>
78 cmp di,max_cmd_len+command_line ; Check there's space
81 call writechr ; Echo to screen
86 cmp al,'F' & 1Fh ; <Ctrl-F>
89 cmp al,'N' & 1Fh ; <Ctrl-N>
92 cmp al,'U' & 1Fh ; <Ctrl-U>
93 je kill_command ; Kill input line
94 cmp al,'V' & 1Fh ; <Ctrl-V>
96 cmp al,'X' & 1Fh ; <Ctrl-X>
98 cmp al,08h ; Backspace
100 backspace: cmp di,command_line ; Make sure there is anything
101 je get_char ; to erase
102 dec di ; Unstore one character
103 mov si,wipe_char ; and erase it from the screen
117 mov byte [FuncFlag],1
125 je .zero ; <Ctrl-F>0 = F10
126 or al,20h ; Lower case
129 cmp al,'a' ; F10-F12 = <Ctrl-F>A, B, C
143 ; AL = 0 if we get here
157 show_help: ; AX = func key # (0 = F1, 9 = F10, 11 = F12)
158 push di ; Save end-of-cmdline pointer
159 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
162 cmp byte [di+NULLOFFSET],NULLFILE
163 je short fk_nofile ; Undefined F-key
165 jz short fk_nofile ; File not found
173 push di ; Command line write pointer
174 mov si,syslinux_banner
183 ; ... fall through ...
185 ; Write the boot prompt and command line again and
186 ; wait for input. Note that this expects the cursor
187 ; to already have been CRLF'd, and that the old value
188 ; of DI (the command line write pointer) is on the stack.
192 pop di ; Command line write pointer
194 mov byte [di],0 ; Null-terminate command line
196 call cwritestr ; Write command line so far
201 ; Show network info (in the form of the ipappend strings)
205 push di ; Command line write pointer
207 mov si,IPAppends ; See comboot.doc
221 ; Jump here to run the default command line
226 mov cx,(max_cmd_len+4) >> 2
228 jmp short load_kernel
231 ; Jump here when the command line is completed
235 cmp di,command_line ; Did we just hit return?
237 xor al,al ; Store a final null
240 load_kernel: ; Load the kernel now
242 ; First we need to mangle the kernel name the way DOS would...
250 ; Fast-forward to first option (we start over from the beginning, since
251 ; mangle_name doesn't necessarily return a consistent ending state.)
256 clin_is_wsp: and al,al
261 clin_opt_ptr: dec si ; Point to first nonblank
262 mov [CmdOptPtr],si ; Save ptr to first option
264 ; If "allowoptions 0", put a null character here in order to ignore any
265 ; user-specified options.
267 mov ax,[AllowOptions]
274 ; Now check if it is a "virtual kernel"
277 xor si,si ; Beginning of vk_seg
279 cmp si,[VKernelBytes]
289 ; SI updated on return
291 sub di,cx ; Return to beginning of buf
301 ; We *are* using a "virtual kernel"
305 push word real_mode_seg
308 mov si,VKernelBuf+vk_append
309 mov cx,[VKernelBuf+vk_appendlen]
311 mov [CmdLinePtr],di ; Where to add rest of cmd
315 mov si,VKernelBuf+vk_rname
316 mov cx,FILENAME_MAX ; We need ECX == CX later
320 mov al,[VKernelBuf+vk_ipappend]
323 xor bx,bx ; Try only one version
325 mov al, [VKernelBuf+vk_type]
328 %if IS_PXELINUX || IS_ISOLINUX
329 ; Is this a "localboot" pseudo-kernel?
331 cmp byte [VKernelBuf+vk_rname+4], 0
333 cmp byte [VKernelBuf+vk_rname], 0
335 jne get_kernel ; No, it's real, go get it
337 mov ax, [VKernelBuf+vk_rname+1]
346 ; Not a "virtual kernel" - check that's OK and construct the command line
348 cmp word [AllowImplicit],byte 0
364 mov [KernelType], cl ; CL == 0 here
367 ; Find the kernel on disk
369 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
370 mov di,KernelName+4*IS_PXELINUX
372 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
373 repne scasb ; Scan for final null
375 dec di ; Point to final null
376 .no_skip: mov [KernelExtPtr],di
378 .search_loop: push bx
379 mov di,KernelName ; Search on disk
383 mov eax,[bx] ; Try a different extension
384 mov si,[KernelExtPtr]
388 cmp bx,exten_table_end
389 jna .search_loop ; allow == case (final case)
390 ; Fall into bad_kernel
392 ; bad_kernel: Kernel image not found
393 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
404 call unmangle_name ; Get human form
405 mov si,err_notfound ; Complain about missing kernel
410 jmp abort_load ; Ask user for clue
413 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
424 pop di ; <E> di == command_line
425 pop bx ; <D> bx == [OnerrorLen]
426 je bad_kernel.really ; Onerror matches command_line already
427 neg bx ; bx == -[OnerrorLen]
428 lea cx,[max_cmd_len+bx]
429 ; CX == max_cmd_len-[OnerrorLen]
430 mov di,command_line+max_cmd_len-1
431 mov byte [di+1],0 ; Enforce null-termination
434 rep movsb ; Make space in command_line
436 pop cx ; <C> cx == [OnerrorLen]
437 pop di ; <B> di == command_line
438 pop si ; <A> si == Onerror
443 ; kernel_corrupt: Called if the kernel file does not seem healthy
445 kernel_corrupt: mov si,err_notkernel
449 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
450 ; which can be adjusted by the caller based on the corresponding
451 ; master variables; on return they're updated.
453 ; This cheats. If we say "no timeout" we actually get a timeout of
461 push word [BIOS_timer]
465 cmp ax,[BIOS_timer] ; Has the timer advanced?
469 dec dword [ThisKbdTo]
471 dec dword [ThisTotalTo]
476 pop cx ; Discard return address
478 mov si,Ontimeout ; Copy ontimeout command
480 mov cx,[OntimeoutLen] ; if we have one...
491 ; This is it! We have a name (and location on the disk)... let's load
492 ; that sucker!! First we have to decide what kind of file this is; base
493 ; that decision on the file extension. The following extensions are
494 ; recognized; case insensitive:
496 ; .com - COMBOOT image
497 ; .cbt - COMBOOT image
500 ; .0 - PXE bootstrap program (PXELINUX only)
502 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
503 ; .img - Floppy image (ISOLINUX only)
505 ; Anything else is assumed to be a Linux kernel.
514 ; Alternate entry point for which the return from
515 ; searchdir is stored in memory. This is used for
516 ; COMBOOT function INT 22h, AX=0016h.
519 mov dx,[Kernel_EAX+2]
527 mov [KernelCNameLen],di
532 mov di,KernelName+4*IS_PXELINUX
538 .one_step: mov ecx,[di-4] ; 4 bytes before end
543 ; At this point, DX:AX contains the size of the kernel, SI contains
544 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
546 movzx di,byte [KernelType]
548 jmp [kerneltype_table+di]
551 or ecx,20202000h ; Force lower case (except dot)
574 ; Otherwise Linux kernel
579 mov si,KernelCName ; Save the config file name, for posterity
587 ; This is an image type we can't deal with
593 %if IS_SYSLINUX || IS_MDSLINUX
596 is_bss_sector equ is_bad_image
601 is_disk_image equ is_bad_image
605 boot_prompt db 'boot: ', 0
606 wipe_char db BS, ' ', BS, 0
607 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
608 err_notfound db 'Could not find kernel image: ',0
609 err_notkernel db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
614 dw is_unknown_filetype ; VK_KERNEL
615 dw is_linux_kernel ; VK_LINUX
616 dw is_bootsector ; VK_BOOT
617 dw is_bss_sector ; VK_BSS
618 dw is_bootsector ; VK_PXE
619 dw is_disk_image ; VK_FDIMAGE
620 dw is_comboot_image ; VK_COMBOOT
621 dw is_com32_image ; VK_COM32
622 dw is_config_file ; VK_CONFIG
626 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
627 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
628 KernelExtPtr resw 1 ; During search, final null pointer
629 CmdOptPtr resw 1 ; Pointer to first option on cmd line
630 KbdFlags resb 1 ; Check for keyboard escapes
631 FuncFlag resb 1 ; Escape sequences received from keyboard
632 KernelType resb 1 ; Kernel type, from vkernel, if known
636 ; Linux kernel loading code is common.
638 %include "runkernel.inc"
641 ; COMBOOT-loading code
643 %include "comboot.inc"
645 %include "cmdline.inc"
648 ; Boot sector loading code
650 %include "bootsect.inc"
658 ; Hardware cleanup common code
660 %include "cleanup.inc"