One more timeoutcmd -> ontimeout
[profile/ivi/syslinux.git] / ui.inc
1 ;; $Id$
2 ;; -----------------------------------------------------------------------
3 ;;   
4 ;;   Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
5 ;;
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 ;;   Bostom MA 02111-1307, USA; either version 2 of the License, or
10 ;;   (at your option) any later version; incorporated herein by reference.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;
15 ; This file should be entered with the config file open (for getc)
16 ;
17                 call parse_config               ; Parse configuration file
18 no_config_file:
19 ;
20 ; Check whether or not we are supposed to display the boot prompt.
21 ;
22 check_for_key:
23                 cmp word [ForcePrompt],byte 0   ; Force prompt?
24                 jnz enter_command
25                 test byte [KbdFlags],5Bh        ; Caps, Scroll, Shift, Alt
26                 jz auto_boot                    ; If neither, default boot
27
28 enter_command:
29                 mov si,boot_prompt
30                 call cwritestr
31
32                 mov byte [FuncFlag],0           ; <Ctrl-F> not pressed
33                 mov di,command_line
34 ;
35 ; get the very first character -- we can either time
36 ; out, or receive a character press at this time.  Some dorky BIOSes stuff
37 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
38 ;
39 clear_buffer:   mov ah,1                        ; Check for pending char
40                 int 16h
41                 jz get_char_time
42                 xor ax,ax                       ; Get char
43                 int 16h
44                 jmp short clear_buffer
45 get_char_time:  
46                 call vgashowcursor
47                 mov cx,[KbdTimeOut]
48                 and cx,cx
49                 jz get_char                     ; Timeout == 0 -> no timeout
50                 inc cx                          ; The first loop will happen
51                                                 ; immediately as we don't
52                                                 ; know the appropriate DX value
53 time_loop:      push cx
54 tick_loop:      push dx
55                 call pollchar
56                 jnz get_char_pop
57                 mov dx,[BIOS_timer]             ; Get time "of day"
58                 pop ax
59                 cmp dx,ax                       ; Has the timer advanced?
60                 je tick_loop
61                 pop cx
62                 DO_IDLE
63                 loop time_loop                  ; If so, decrement counter
64
65                 ; Timeout!!!!
66                 call vgahidecursor
67                 mov si,Ontimeout                ; Copy ontimeout command
68                 mov cx,[OntimeoutLen]           ; if we have one...
69                 rep movsb
70 .stddefault:
71                 jmp command_done
72
73 get_char_pop:   pop eax                         ; Clear stack
74 get_char:
75                 call vgashowcursor
76                 call getchar
77                 call vgahidecursor
78                 and al,al
79                 jz func_key
80
81 got_ascii:      cmp al,7Fh                      ; <DEL> == <BS>
82                 je backspace
83                 cmp al,' '                      ; ASCII?
84                 jb not_ascii
85                 ja enter_char
86                 cmp di,command_line             ; Space must not be first
87                 je short get_char
88 enter_char:     test byte [FuncFlag],1
89                 jz .not_ctrl_f
90                 mov byte [FuncFlag],0
91                 cmp al,'0'
92                 jb .not_ctrl_f
93                 je ctrl_f_0
94                 cmp al,'9'
95                 jbe ctrl_f
96 .not_ctrl_f:    cmp di,max_cmd_len+command_line ; Check there's space
97                 jnb short get_char
98                 stosb                           ; Save it
99                 call writechr                   ; Echo to screen
100                 jmp short get_char
101 not_ascii:      mov byte [FuncFlag],0
102                 cmp al,0Dh                      ; Enter
103                 je command_done
104                 cmp al,06h                      ; <Ctrl-F>
105                 je set_func_flag
106                 cmp al,16h                      ; <Ctrl-V>
107                 je print_version
108                 cmp al,08h                      ; Backspace
109                 jne get_char
110 backspace:      cmp di,command_line             ; Make sure there is anything
111                 je get_char                     ; to erase
112                 dec di                          ; Unstore one character
113                 mov si,wipe_char                ; and erase it from the screen
114                 call cwritestr
115                 jmp short get_char_2
116
117 set_func_flag:
118                 mov byte [FuncFlag],1
119 get_char_2:
120                 jmp short get_char
121
122 ctrl_f_0:       add al,10                       ; <Ctrl-F>0 == F10
123 ctrl_f:         sub al,'1'
124                 xor ah,ah
125                 jmp short show_help
126
127 func_key:
128                 ; AL = 0 if we get here
129                 xchg al,ah
130                 cmp al,68                       ; F10
131                 ja short get_char_2
132                 sub al,59                       ; F1
133                 jb short get_char_2
134 show_help:      ; AX = func key # (0 = F1, 9 = F10)
135                 push di                         ; Save end-of-cmdline pointer
136                 shl ax,FILENAME_MAX_LG2         ; Convert to pointer
137                 add ax,FKeyName
138                 xchg di,ax
139                 cmp byte [di],NULLFILE
140                 je short fk_nofile              ; Undefined F-key
141                 call searchdir
142                 jz short fk_nofile              ; File not found
143                 push si
144                 call crlf
145                 pop si
146                 call get_msg_file
147                 jmp short fk_wrcmd
148
149 print_version:
150                 push di                         ; Command line write pointer
151                 mov si,syslinux_banner
152                 call cwritestr
153                 mov si,copyright_str
154                 call cwritestr
155
156                 ; ... fall through ...
157
158                 ; Write the boot prompt and command line again and
159                 ; wait for input.  Note that this expects the cursor
160                 ; to already have been CRLF'd, and that the old value
161                 ; of DI (the command line write pointer) is on the stack.
162 fk_wrcmd:
163                 mov si,boot_prompt
164                 call cwritestr
165                 pop di                          ; Command line write pointer
166                 push di
167                 mov byte [di],0                 ; Null-terminate command line
168                 mov si,command_line
169                 call cwritestr                  ; Write command line so far
170 fk_nofile:      pop di
171                 jmp short get_char_2
172 auto_boot:
173                 mov si,default_cmd
174                 mov di,command_line
175                 mov cx,(max_cmd_len+4) >> 2
176                 rep movsd
177                 jmp short load_kernel
178 command_done:
179                 call crlf
180                 cmp di,command_line             ; Did we just hit return?
181                 je auto_boot
182                 xor al,al                       ; Store a final null
183                 stosb
184
185 load_kernel:                                    ; Load the kernel now
186 ;
187 ; First we need to mangle the kernel name the way DOS would...
188 ;
189                 mov si,command_line
190                 mov di,KernelName
191                 push si
192                 push di
193                 call mangle_name
194                 pop di
195                 pop si
196 ;
197 ; Fast-forward to first option (we start over from the beginning, since
198 ; mangle_name doesn't necessarily return a consistent ending state.)
199 ;
200 clin_non_wsp:   lodsb
201                 cmp al,' '
202                 ja clin_non_wsp
203 clin_is_wsp:    and al,al
204                 jz clin_opt_ptr
205                 lodsb
206                 cmp al,' '
207                 jbe clin_is_wsp
208 clin_opt_ptr:   dec si                          ; Point to first nonblank
209                 mov [CmdOptPtr],si              ; Save ptr to first option
210 ;
211 ; Now check if it is a "virtual kernel"
212 ;
213                 mov cx,[VKernelCtr]
214                 push ds
215                 push word vk_seg
216                 pop ds
217                 cmp cx,byte 0
218                 je not_vk
219                 xor si,si                       ; Point to first vkernel
220 vk_check:       pusha
221                 mov cx,FILENAME_MAX
222                 repe cmpsb                      ; Is this it?
223                 je vk_found
224                 popa
225                 add si,vk_size
226                 loop vk_check
227 not_vk:         pop ds
228 ;
229 ; Not a "virtual kernel" - check that's OK and construct the command line
230 ;
231                 cmp word [AllowImplicit],byte 0
232                 je bad_implicit
233                 push es
234                 push si
235                 push di
236                 mov di,real_mode_seg
237                 mov es,di
238                 mov si,AppendBuf
239                 mov di,cmd_line_here
240                 mov cx,[AppendLen]
241                 rep movsb
242                 mov [CmdLinePtr],di
243                 pop di
244                 pop si
245                 pop es
246 ;
247 ; Find the kernel on disk
248 ;
249 get_kernel:     mov byte [KernelName+FILENAME_MAX],0    ; Zero-terminate filename/extension
250 %if IS_SYSLINUX || IS_MDSLINUX                  ; SYSLINUX has to deal with DOS mangled names...
251                 mov eax,[KernelName+8]          ; Save initial extension
252                 mov [exten_table_end],eax       ; Last case == initial ext.
253 %else
254                 mov di,KernelName
255                 xor al,al
256                 mov cx,FILENAME_MAX-5           ; Need 4 chars + null
257                 repne scasb                     ; Scan for final null
258                 jne .no_skip
259                 dec di                          ; Point to final null 
260 .no_skip:       mov [KernelExtPtr],di
261 %endif
262                 mov bx,exten_table
263 .search_loop:   push bx
264                 mov di,KernelName               ; Search on disk
265                 call searchdir
266                 pop bx
267                 jnz kernel_good
268                 mov eax,[bx]                    ; Try a different extension
269 %if IS_SYSLINUX || IS_MDSLINUX
270                 mov [KernelName+8],eax
271 %else
272                 mov si,[KernelExtPtr]
273                 mov [si],eax
274                 mov byte [si+4],0
275 %endif
276                 add bx,byte 4
277                 cmp bx,exten_table_end
278                 jna .search_loop                ; allow == case (final case)
279 bad_kernel:     
280                 mov si,KernelName
281                 mov di,KernelCName
282                 push di
283                 call unmangle_name              ; Get human form
284                 mov si,err_notfound             ; Complain about missing kernel
285                 call cwritestr
286                 pop si                          ; KernelCName
287                 call cwritestr
288                 mov si,crlf_msg
289                 jmp abort_load                  ; Ask user for clue
290 ;
291 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
292 ;
293 bad_implicit:   mov si,KernelName               ; For the error message
294                 mov di,KernelCName
295                 call unmangle_name
296                 jmp short bad_kernel
297 ;
298 ; vk_found: We *are* using a "virtual kernel"
299 ;
300 vk_found:       popa
301                 push di
302                 mov di,VKernelBuf
303                 mov cx,vk_size >> 2
304                 rep movsd
305                 push es                         ; Restore old DS
306                 pop ds
307                 push es
308                 push word real_mode_seg
309                 pop es
310                 mov di,cmd_line_here
311                 mov si,VKernelBuf+vk_append
312                 mov cx,[VKernelBuf+vk_appendlen]
313                 rep movsb
314                 mov [CmdLinePtr],di             ; Where to add rest of cmd
315                 pop es
316                 pop di                          ; DI -> KernelName
317                 push di 
318                 mov si,VKernelBuf+vk_rname
319                 mov cx,FILENAME_MAX             ; We need ECX == CX later
320                 rep movsb
321                 pop di
322 %if IS_PXELINUX
323                 mov al,[VKernelBuf+vk_ipappend]
324                 mov [IPAppend],al
325 %endif
326                 xor bx,bx                       ; Try only one version
327
328 %if IS_SYSLINUX || IS_MDSLINUX
329                 jmp get_kernel
330 %else
331                 ; Is this a "localboot" pseudo-kernel?
332                 cmp byte [VKernelBuf+vk_rname], 0
333                 jne get_kernel          ; No, it's real, go get it
334
335                 mov ax, [VKernelBuf+vk_rname+1]
336                 jmp local_boot
337 %endif
338
339 ;
340 ; kernel_corrupt: Called if the kernel file does not seem healthy
341 ;
342 kernel_corrupt: mov si,err_notkernel
343                 jmp abort_load
344 ;
345 ; This is it!  We have a name (and location on the disk)... let's load
346 ; that sucker!!  First we have to decide what kind of file this is; base
347 ; that decision on the file extension.  The following extensions are
348 ; recognized; case insensitive:
349 ;
350 ; .com  - COMBOOT image
351 ; .cbt  - COMBOOT image
352 ; .c32  - COM32 image
353 ; .bs   - Boot sector
354 ; .0    - PXE bootstrap program (PXELINUX only)
355 ; .bin  - Boot sector
356 ; .bss  - Boot sector, but transfer over DOS superblock (SYSLINUX only)
357 ; .img  - Floppy image (ISOLINUX only)
358 ;
359 ; Anything else is assumed to be a Linux kernel.
360 ;
361 kernel_good:
362                 pusha
363                 mov si,KernelName
364                 mov di,KernelCName
365                 call unmangle_name
366                 sub di,KernelCName
367                 mov [KernelCNameLen],di
368                 popa
369                 
370 %if IS_SYSLINUX || IS_MDSLINUX
371                 mov ecx,[KernelName+7]
372                 mov cl,'.'
373 %else
374                 push di
375                 push ax
376                 mov di,KernelName
377                 xor al,al
378                 mov cx,FILENAME_MAX
379                 repne scasb
380                 jne .one_step
381                 dec di
382 .one_step:      mov ecx,[di-4]                  ; 4 bytes before end
383                 pop ax
384                 pop di
385 %endif
386
387 ;
388 ; At this point, DX:AX contains the size of the kernel, and SI contains
389 ; the file handle/cluster pointer.
390 ;
391                 or ecx,20202000h                ; Force lower case
392
393                 cmp ecx,'.com'
394                 je is_comboot_image
395                 cmp ecx,'.cbt'
396                 je is_comboot_image
397                 cmp ecx,'.c32'
398                 je is_com32_image
399 %if IS_ISOLINUX
400                 cmp ecx,'.img'
401                 je is_disk_image
402 %endif
403                 cmp ecx,'.bss'
404                 je is_bss_sector
405                 cmp ecx,'.bin'
406                 je is_bootsector
407 %if IS_SYSLINUX || IS_MDSLINUX
408                 cmp ecx,'.bs '
409                 je is_bootsector
410                 cmp ecx,'.0  '
411                 je is_bootsector
412 %else
413                 shr ecx,8
414                 cmp ecx,'.bs'
415                 je is_bootsector
416                 shr ecx,8
417                 cmp cx,'.0'
418                 je is_bootsector
419 %endif
420                 ; Otherwise Linux kernel
421