2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2005 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
39 ; get the very first character -- we can either time
40 ; out, or receive a character press at this time. Some dorky BIOSes stuff
41 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
43 clear_buffer: mov ah,11h ; Check for pending char
48 jmp short clear_buffer
50 ; For the first character, both KbdTimeout and
51 ; TotalTimeout apply; after that, only TotalTimeout.
54 mov eax,[TotalTimeout]
61 and dword [ThisKbdTo],0 ; For the next time...
66 got_ascii: cmp al,7Fh ; <DEL> == <BS>
71 cmp di,command_line ; Space must not be first
73 enter_char: test byte [FuncFlag],1
81 .not_ctrl_f: cmp di,max_cmd_len+command_line ; Check there's space
84 call writechr ; Echo to screen
86 not_ascii: mov byte [FuncFlag],0
89 cmp al,'F' & 1Fh ; <Ctrl-F>
91 cmp al,'U' & 1Fh ; <Ctrl-U>
92 je kill_command ; Kill input line
93 cmp al,'V' & 1Fh ; <Ctrl-V>
95 cmp al,'X' & 1Fh ; <Ctrl-X>
97 cmp al,08h ; Backspace
99 backspace: cmp di,command_line ; Make sure there is anything
100 je get_char ; to erase
101 dec di ; Unstore one character
102 mov si,wipe_char ; and erase it from the screen
115 mov byte [FuncFlag],1
119 ctrl_f_0: add al,10 ; <Ctrl-F>0 == F10
125 ; AL = 0 if we get here
131 show_help: ; AX = func key # (0 = F1, 9 = F10)
132 push di ; Save end-of-cmdline pointer
133 shl ax,FILENAME_MAX_LG2 ; Convert to pointer
136 cmp byte [di+NULLOFFSET],NULLFILE
137 je short fk_nofile ; Undefined F-key
139 jz short fk_nofile ; File not found
147 push di ; Command line write pointer
148 mov si,syslinux_banner
157 ; ... fall through ...
159 ; Write the boot prompt and command line again and
160 ; wait for input. Note that this expects the cursor
161 ; to already have been CRLF'd, and that the old value
162 ; of DI (the command line write pointer) is on the stack.
166 pop di ; Command line write pointer
168 mov byte [di],0 ; Null-terminate command line
170 call cwritestr ; Write command line so far
175 ; Jump here to run the default command line
180 mov cx,(max_cmd_len+4) >> 2
182 jmp short load_kernel
185 ; Jump here when the command line is completed
189 cmp di,command_line ; Did we just hit return?
191 xor al,al ; Store a final null
194 load_kernel: ; Load the kernel now
196 ; First we need to mangle the kernel name the way DOS would...
206 ; Fast-forward to first option (we start over from the beginning, since
207 ; mangle_name doesn't necessarily return a consistent ending state.)
212 clin_is_wsp: and al,al
217 clin_opt_ptr: dec si ; Point to first nonblank
218 mov [CmdOptPtr],si ; Save ptr to first option
220 ; If "allowoptions 0", put a null character here in order to ignore any
221 ; user-specified options.
223 mov ax,[AllowOptions]
230 ; Now check if it is a "virtual kernel"
233 xor si,si ; Beginning of vk_seg
235 cmp si,[VKernelBytes]
245 ; SI updated on return
247 sub di,cx ; Return to beginning of buf
257 ; We *are* using a "virtual kernel"
261 push word real_mode_seg
264 mov si,VKernelBuf+vk_append
265 mov cx,[VKernelBuf+vk_appendlen]
267 mov [CmdLinePtr],di ; Where to add rest of cmd
271 mov si,VKernelBuf+vk_rname
272 mov cx,FILENAME_MAX ; We need ECX == CX later
276 mov al,[VKernelBuf+vk_ipappend]
279 xor bx,bx ; Try only one version
281 %if IS_PXELINUX || IS_ISOLINUX
282 ; Is this a "localboot" pseudo-kernel?
284 cmp byte [VKernelBuf+vk_rname+4], 0
286 cmp byte [VKernelBuf+vk_rname], 0
288 jne get_kernel ; No, it's real, go get it
290 mov ax, [VKernelBuf+vk_rname+1]
299 ; Not a "virtual kernel" - check that's OK and construct the command line
301 cmp word [AllowImplicit],byte 0
317 ; Find the kernel on disk
319 get_kernel: mov byte [KernelName+FILENAME_MAX],0 ; Zero-terminate filename/extension
320 %if IS_SYSLINUX || IS_MDSLINUX ; SYSLINUX has to deal with DOS mangled names...
321 mov eax,[KernelName+8] ; Save initial extension
322 mov [exten_table_end],eax ; Last case == initial ext.
324 mov di,KernelName+4*IS_PXELINUX
326 mov cx,FILENAME_MAX-5 ; Need 4 chars + null
327 repne scasb ; Scan for final null
329 dec di ; Point to final null
330 .no_skip: mov [KernelExtPtr],di
333 .search_loop: push bx
334 mov di,KernelName ; Search on disk
338 mov eax,[bx] ; Try a different extension
339 %if IS_SYSLINUX || IS_MDSLINUX
340 mov [KernelName+8],eax
342 mov si,[KernelExtPtr]
347 cmp bx,exten_table_end
348 jna .search_loop ; allow == case (final case)
349 ; Fall into bad_kernel
351 ; bad_kernel: Kernel image not found
352 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
363 call unmangle_name ; Get human form
364 mov si,err_notfound ; Complain about missing kernel
369 jmp abort_load ; Ask user for clue
372 ; on_error: bad kernel, but we have onerror set
383 pop di ; <E> di == command_line
384 pop bx ; <D> bx == [OnerrorLen]
385 je bad_kernel.really ; Onerror matches command_line already
386 neg bx ; bx == -[OnerrorLen]
387 lea cx,[max_cmd_len+bx]
388 ; CX == max_cmd_len-[OnerrorLen]
389 mov di,command_line+max_cmd_len-1
390 mov byte [di+1],0 ; Enforce null-termination
393 rep movsb ; Make space in command_line
395 pop cx ; <C> cx == [OnerrorLen]
396 pop di ; <B> di == command_line
397 pop si ; <A> si == Onerror
402 ; kernel_corrupt: Called if the kernel file does not seem healthy
404 kernel_corrupt: mov si,err_notkernel
408 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
409 ; which can be adjusted by the caller based on the corresponding
410 ; master variables; on return they're updated.
412 ; This cheats. If we say "no timeout" we actually get a timeout of
420 push word [BIOS_timer]
424 cmp ax,[BIOS_timer] ; Has the timer advanced?
428 dec dword [ThisKbdTo]
430 dec dword [ThisTotalTo]
435 pop cx ; Discard return address
437 mov si,Ontimeout ; Copy ontimeout command
439 mov cx,[OntimeoutLen] ; if we have one...
450 ; This is it! We have a name (and location on the disk)... let's load
451 ; that sucker!! First we have to decide what kind of file this is; base
452 ; that decision on the file extension. The following extensions are
453 ; recognized; case insensitive:
455 ; .com - COMBOOT image
456 ; .cbt - COMBOOT image
459 ; .0 - PXE bootstrap program (PXELINUX only)
461 ; .bss - Boot sector, but transfer over DOS superblock (SYSLINUX only)
462 ; .img - Floppy image (ISOLINUX only)
464 ; Anything else is assumed to be a Linux kernel.
473 ; Alternate entry point for which the return from
474 ; searchdir is stored in memory. This is used for
475 ; COMBOOT function INT 22h, AX=0016h.
478 mov dx,[Kernel_EAX+2]
486 mov [KernelCNameLen],di
489 %if IS_SYSLINUX || IS_MDSLINUX
490 mov ecx,[KernelName+7]
495 mov di,KernelName+4*IS_PXELINUX
501 .one_step: mov ecx,[di-4] ; 4 bytes before end
507 ; At this point, DX:AX contains the size of the kernel, and SI contains
508 ; the file handle/cluster pointer.
510 or ecx,20202000h ; Force lower case
526 %if IS_SYSLINUX || IS_MDSLINUX
539 ; Otherwise Linux kernel
543 ThisKbdTo resd 1 ; Temporary holder for KbdTimeout
544 ThisTotalTo resd 1 ; Temporary holder for TotalTimeout
545 KernelExtPtr resw 1 ; During search, final null pointer
546 CmdOptPtr resw 1 ; Pointer to first option on cmd line
547 KbdFlags resb 1 ; Check for keyboard escapes
548 FuncFlag resb 1 ; Escape sequences received from keyboard