2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
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)
17 call parse_config ; Parse configuration file
20 ; Check whether or not we are supposed to display the boot prompt.
23 cmp word [ForcePrompt],0 ; Force prompt?
25 test byte [KbdFlags],5Bh ; Shift Alt Caps Scroll
26 jz auto_boot ; If neither, default boot
29 cmp word [NoEscape],0 ; If NOESCAPE, no prompt,
30 jne auto_boot ; always run default cmd
35 mov byte [FuncFlag],0 ; <Ctrl-F> not pressed
38 ; get the very first character -- we can either time
39 ; out, or receive a character press at this time. Some dorky BIOSes stuff
40 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
42 clear_buffer: mov ah,11h ; Check for pending char
47 jmp short clear_buffer
53 jz get_char ; Timeout == 0 -> no timeout
54 inc cx ; The first loop will happen
55 ; immediately as we don't
56 ; know the appropriate DX value
61 mov dx,[BIOS_timer] ; Get time "of day"
63 cmp dx,ax ; Has the timer advanced?
67 loop time_loop ; If so, decrement counter
71 mov si,Ontimeout ; Copy ontimeout command
72 mov cx,[OntimeoutLen] ; if we have one...
77 get_char_pop: pop eax ; Clear stack
85 got_ascii: cmp al,7Fh ; <DEL> == <BS>
90 cmp di,command_line ; Space must not be first
92 enter_char: test byte [FuncFlag],1
100 .not_ctrl_f: cmp di,max_cmd_len+command_line ; Check there's space
103 call writechr ; Echo to screen
105 not_ascii: mov byte [FuncFlag],0
108 cmp al,'F' & 1Fh ; <Ctrl-F>
110 cmp al,'U' & 1Fh ; <Ctrl-U>
111 je kill_command ; Kill input line
112 cmp al,'V' & 1Fh ; <Ctrl-V>
114 cmp al,'X' & 1Fh ; <Ctrl-X>
116 cmp al,08h ; Backspace
118 backspace: cmp di,command_line ; Make sure there is anything
119 je get_char ; to erase
120 dec di ; Unstore one character
121 mov si,wipe_char ; and erase it from the screen
134 mov byte [FuncFlag],1
138 ctrl_f_0: add al,10 ; <Ctrl-F>0 == F10
144 ; AL = 0 if we get here
150 show_help: ; AX = func key # (0 = F1, 9 = F10)
151 push di ; Save end-of-cmdline pointer
152 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
155 cmp byte [di+NULLOFFSET],NULLFILE
156 je short fk_nofile ; Undefined F-key
158 jz short fk_nofile ; File not found
166 push di ; Command line write pointer
167 mov si,syslinux_banner
176 ; ... fall through ...
178 ; Write the boot prompt and command line again and
179 ; wait for input. Note that this expects the cursor
180 ; to already have been CRLF'd, and that the old value
181 ; of DI (the command line write pointer) is on the stack.
185 pop di ; Command line write pointer
187 mov byte [di],0 ; Null-terminate command line
189 call cwritestr ; Write command line so far
194 ; Jump here to run the default command line
199 mov cx,(max_cmd_len+4) >> 2
201 jmp short load_kernel
204 ; Jump here when the command line is completed
208 cmp di,command_line ; Did we just hit return?
210 xor al,al ; Store a final null
213 load_kernel: ; Load the kernel now
215 ; First we need to mangle the kernel name the way DOS would...
225 ; Fast-forward to first option (we start over from the beginning, since
226 ; mangle_name doesn't necessarily return a consistent ending state.)
231 clin_is_wsp: and al,al
236 clin_opt_ptr: dec si ; Point to first nonblank
237 mov [CmdOptPtr],si ; Save ptr to first option
239 ; If "allowoptions 0", put a null character here in order to ignore any
240 ; user-specified options.
242 mov ax,[AllowOptions]
249 ; Now check if it is a "virtual kernel"
252 xor si,si ; Beginning of vk_seg
254 cmp si,[VKernelBytes]
264 ; SI updated on return
266 sub di,cx ; Return to beginning of buf
276 ; We *are* using a "virtual kernel"
280 push word real_mode_seg
283 mov si,VKernelBuf+vk_append
284 mov cx,[VKernelBuf+vk_appendlen]
286 mov [CmdLinePtr],di ; Where to add rest of cmd
290 mov si,VKernelBuf+vk_rname
291 mov cx,FILENAME_MAX ; We need ECX == CX later
295 mov al,[VKernelBuf+vk_ipappend]
298 xor bx,bx ; Try only one version
300 %if IS_PXELINUX || IS_ISOLINUX
301 ; Is this a "localboot" pseudo-kernel?
303 cmp byte [VKernelBuf+vk_rname+4], 0
305 cmp byte [VKernelBuf+vk_rname], 0
307 jne get_kernel ; No, it's real, go get it
309 mov ax, [VKernelBuf+vk_rname+1]
318 ; Not a "virtual kernel" - check that's OK and construct the command line
320 cmp word [AllowImplicit],byte 0
336 ; Find the kernel on disk
338 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
339 %if IS_SYSLINUX || IS_MDSLINUX ; SYSLINUX has to deal with DOS mangled names...
340 mov eax,[KernelName+8] ; Save initial extension
341 mov [exten_table_end],eax ; Last case == initial ext.
343 mov di,KernelName+4*IS_PXELINUX
345 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
346 repne scasb ; Scan for final null
348 dec di ; Point to final null
349 .no_skip: mov [KernelExtPtr],di
352 .search_loop: push bx
353 mov di,KernelName ; Search on disk
357 mov eax,[bx] ; Try a different extension
358 %if IS_SYSLINUX || IS_MDSLINUX
359 mov [KernelName+8],eax
361 mov si,[KernelExtPtr]
366 cmp bx,exten_table_end
367 jna .search_loop ; allow == case (final case)
368 ; Fall into bad_kernel
370 ; bad_kernel: Kernel image not found
371 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
382 call unmangle_name ; Get human form
383 mov si,err_notfound ; Complain about missing kernel
388 jmp abort_load ; Ask user for clue
391 ; on_error: bad kernel, but we have onerror set
402 pop di ; <E> di == command_line
403 pop bx ; <D> bx == [OnerrorLen]
404 je bad_kernel.really ; Onerror matches command_line already
405 neg bx ; bx == -[OnerrorLen]
406 lea cx,[max_cmd_len+bx]
407 ; CX == max_cmd_len-[OnerrorLen]
408 mov di,command_line+max_cmd_len-1
409 mov byte [di+1],0 ; Enforce null-termination
412 rep movsb ; Make space in command_line
414 pop cx ; <C> cx == [OnerrorLen]
415 pop di ; <B> di == command_line
416 pop si ; <A> si == Onerror
421 ; kernel_corrupt: Called if the kernel file does not seem healthy
423 kernel_corrupt: mov si,err_notkernel
426 ; This is it! We have a name (and location on the disk)... let's load
427 ; that sucker!! First we have to decide what kind of file this is; base
428 ; that decision on the file extension. The following extensions are
429 ; recognized; case insensitive:
431 ; .com - COMBOOT image
432 ; .cbt - COMBOOT image
435 ; .0 - PXE bootstrap program (PXELINUX only)
437 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
438 ; .img - Floppy image (ISOLINUX only)
440 ; Anything else is assumed to be a Linux kernel.
449 ; Alternate entry point for which the return from
450 ; searchdir is stored in memory. This is used for
451 ; COMBOOT function INT 22h, AX=0016h.
454 mov dx,[Kernel_EAX+2]
462 mov [KernelCNameLen],di
465 %if IS_SYSLINUX || IS_MDSLINUX
466 mov ecx,[KernelName+7]
471 mov di,KernelName+4*IS_PXELINUX
477 .one_step: mov ecx,[di-4] ; 4 bytes before end
483 ; At this point, DX:AX contains the size of the kernel, and SI contains
484 ; the file handle/cluster pointer.
486 or ecx,20202000h ; Force lower case
502 %if IS_SYSLINUX || IS_MDSLINUX
515 ; Otherwise Linux kernel
519 KernelExtPtr resw 1 ; During search, final null pointer
520 CmdOptPtr resw 1 ; Pointer to first option on cmd line
521 KbdFlags resb 1 ; Check for keyboard escapes
522 FuncFlag resb 1 ; Escape sequences received from keyboard