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
21 ; Check whether or not we are supposed to display the boot prompt.
24 cmp word [ForcePrompt],0 ; Force prompt?
26 test byte [KbdFlags],5Bh ; Shift Alt Caps Scroll
27 jz auto_boot ; If neither, default boot
30 cmp word [NoEscape],0 ; If NOESCAPE, no prompt,
31 jne auto_boot ; always run default cmd
36 mov byte [FuncFlag],0 ; <Ctrl-F> not pressed
40 ; get the very first character -- we can either time
41 ; out, or receive a character press at this time. Some dorky BIOSes stuff
42 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
44 clear_buffer: mov ah,11h ; Check for pending char
49 jmp short clear_buffer
51 ; For the first character, both KbdTimeout and
52 ; TotalTimeout apply; after that, only TotalTimeout.
55 mov eax,[TotalTimeout]
62 and dword [ThisKbdTo],0 ; For the next time...
67 got_ascii: cmp al,7Fh ; <DEL> == <BS>
72 cmp di,command_line ; Space must not be first
74 enter_char: test byte [FuncFlag],1
75 jnz ctrl_f ; Keystroke after <Ctrl-F>
76 cmp di,max_cmd_len+command_line ; Check there's space
79 call writechr ; Echo to screen
84 cmp al,'F' & 1Fh ; <Ctrl-F>
87 cmp al,'N' & 1Fh ; <Ctrl-N>
90 cmp al,'U' & 1Fh ; <Ctrl-U>
91 je kill_command ; Kill input line
92 cmp al,'V' & 1Fh ; <Ctrl-V>
94 cmp al,'X' & 1Fh ; <Ctrl-X>
96 cmp al,08h ; Backspace
98 backspace: cmp di,command_line ; Make sure there is anything
99 je get_char ; to erase
100 dec di ; Unstore one character
101 mov si,wipe_char ; and erase it from the screen
115 mov byte [FuncFlag],1
123 je .zero ; <Ctrl-F>0 = F10
124 or al,20h ; Lower case
127 cmp al,'a' ; F10-F12 = <Ctrl-F>A, B, C
141 ; AL = 0 if we get here
155 show_help: ; AX = func key # (0 = F1, 9 = F10, 11 = F12)
156 push di ; Save end-of-cmdline pointer
157 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
160 cmp byte [di+NULLOFFSET],NULLFILE
161 je short fk_nofile ; Undefined F-key
163 jz short fk_nofile ; File not found
171 push di ; Command line write pointer
172 mov si,syslinux_banner
181 ; ... fall through ...
183 ; Write the boot prompt and command line again and
184 ; wait for input. Note that this expects the cursor
185 ; to already have been CRLF'd, and that the old value
186 ; of DI (the command line write pointer) is on the stack.
190 pop di ; Command line write pointer
192 mov byte [di],0 ; Null-terminate command line
194 call cwritestr ; Write command line so far
199 ; Show network info (in the form of the ipappend strings)
203 push di ; Command line write pointer
205 mov si,IPAppends ; See comboot.doc
219 ; Jump here to run the default command line
224 mov cx,(max_cmd_len+4) >> 2
226 jmp short load_kernel
229 ; Jump here when the command line is completed
233 cmp di,command_line ; Did we just hit return?
235 xor al,al ; Store a final null
238 load_kernel: ; Load the kernel now
240 ; First we need to mangle the kernel name the way DOS would...
248 ; Fast-forward to first option (we start over from the beginning, since
249 ; mangle_name doesn't necessarily return a consistent ending state.)
254 clin_is_wsp: and al,al
259 clin_opt_ptr: dec si ; Point to first nonblank
260 mov [CmdOptPtr],si ; Save ptr to first option
262 ; If "allowoptions 0", put a null character here in order to ignore any
263 ; user-specified options.
265 mov ax,[AllowOptions]
272 ; Now check if it is a "virtual kernel"
275 xor si,si ; Beginning of vk_seg
277 cmp si,[VKernelBytes]
287 ; SI updated on return
289 sub di,cx ; Return to beginning of buf
299 ; We *are* using a "virtual kernel"
303 push word real_mode_seg
306 mov si,VKernelBuf+vk_append
307 mov cx,[VKernelBuf+vk_appendlen]
309 mov [CmdLinePtr],di ; Where to add rest of cmd
313 mov si,VKernelBuf+vk_rname
314 mov cx,FILENAME_MAX ; We need ECX == CX later
318 mov al,[VKernelBuf+vk_ipappend]
321 xor bx,bx ; Try only one version
323 mov al, [VKernelBuf+vk_type]
326 %if IS_PXELINUX || IS_ISOLINUX
327 ; Is this a "localboot" pseudo-kernel?
329 cmp byte [VKernelBuf+vk_rname+4], 0
331 cmp byte [VKernelBuf+vk_rname], 0
333 jne get_kernel ; No, it's real, go get it
335 mov ax, [VKernelBuf+vk_rname+1]
344 ; Not a "virtual kernel" - check that's OK and construct the command line
346 cmp word [AllowImplicit],byte 0
362 mov [KernelType], cl ; CL == 0 here
365 ; Find the kernel on disk
367 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
368 mov di,KernelName+4*IS_PXELINUX
370 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
371 repne scasb ; Scan for final null
373 dec di ; Point to final null
374 .no_skip: mov [KernelExtPtr],di
376 .search_loop: push bx
377 mov di,KernelName ; Search on disk
381 mov eax,[bx] ; Try a different extension
382 mov si,[KernelExtPtr]
386 cmp bx,exten_table_end
387 jna .search_loop ; allow == case (final case)
388 ; Fall into bad_kernel
390 ; bad_kernel: Kernel image not found
391 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
402 call unmangle_name ; Get human form
403 mov si,err_notfound ; Complain about missing kernel
408 jmp abort_load ; Ask user for clue
411 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
422 pop di ; <E> di == command_line
423 pop bx ; <D> bx == [OnerrorLen]
424 je bad_kernel.really ; Onerror matches command_line already
425 neg bx ; bx == -[OnerrorLen]
426 lea cx,[max_cmd_len+bx]
427 ; CX == max_cmd_len-[OnerrorLen]
428 mov di,command_line+max_cmd_len-1
429 mov byte [di+1],0 ; Enforce null-termination
432 rep movsb ; Make space in command_line
434 pop cx ; <C> cx == [OnerrorLen]
435 pop di ; <B> di == command_line
436 pop si ; <A> si == Onerror
441 ; kernel_corrupt: Called if the kernel file does not seem healthy
443 kernel_corrupt: mov si,err_notkernel
447 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
448 ; which can be adjusted by the caller based on the corresponding
449 ; master variables; on return they're updated.
451 ; This cheats. If we say "no timeout" we actually get a timeout of
459 push word [BIOS_timer]
463 cmp ax,[BIOS_timer] ; Has the timer advanced?
467 dec dword [ThisKbdTo]
469 dec dword [ThisTotalTo]
474 pop cx ; Discard return address
476 mov si,Ontimeout ; Copy ontimeout command
478 mov cx,[OntimeoutLen] ; if we have one...
489 ; This is it! We have a name (and location on the disk)... let's load
490 ; that sucker!! First we have to decide what kind of file this is; base
491 ; that decision on the file extension. The following extensions are
492 ; recognized; case insensitive:
494 ; .com - COMBOOT image
495 ; .cbt - COMBOOT image
498 ; .0 - PXE bootstrap program (PXELINUX only)
500 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
501 ; .img - Floppy image (ISOLINUX only)
503 ; Anything else is assumed to be a Linux kernel.
512 ; Alternate entry point for which the return from
513 ; searchdir is stored in memory. This is used for
514 ; COMBOOT function INT 22h, AX=0016h.
517 mov dx,[Kernel_EAX+2]
525 mov [KernelCNameLen],di
530 mov di,KernelName+4*IS_PXELINUX
536 .one_step: mov ecx,[di-4] ; 4 bytes before end
541 ; At this point, DX:AX contains the size of the kernel, SI contains
542 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
544 movzx di,byte [KernelType]
546 jmp [kerneltype_table+di]
549 or ecx,20202000h ; Force lower case (except dot)
572 ; Otherwise Linux kernel
577 mov si,KernelCName ; Save the config file name, for posterity
585 ; This is an image type we can't deal with
591 %if IS_SYSLINUX || IS_MDSLINUX
594 is_bss_sector equ is_bad_image
599 is_disk_image equ is_bad_image
603 err_badimage db 'Invalid image type for this media type!', CR, LF, 0
607 dw is_unknown_filetype ; VK_KERNEL
608 dw is_linux_kernel ; VK_LINUX
609 dw is_bootsector ; VK_BOOT
610 dw is_bss_sector ; VK_BSS
611 dw is_bootsector ; VK_PXE
612 dw is_disk_image ; VK_FDIMAGE
613 dw is_comboot_image ; VK_COMBOOT
614 dw is_com32_image ; VK_COM32
615 dw is_config_file ; VK_CONFIG
619 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
620 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
621 KernelExtPtr resw 1 ; During search, final null pointer
622 CmdOptPtr resw 1 ; Pointer to first option on cmd line
623 KbdFlags resb 1 ; Check for keyboard escapes
624 FuncFlag resb 1 ; Escape sequences received from keyboard
625 KernelType resb 1 ; Kernel type, from vkernel, if known
629 ; Linux kernel loading code is common.
631 %include "runkernel.inc"
634 ; COMBOOT-loading code
636 %include "comboot.inc"
638 %include "cmdline.inc"
641 ; Boot sector loading code
643 %include "bootsect.inc"
651 ; Hardware cleanup common code
653 %include "cleanup.inc"