Correct the sense of "noescape"
[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 ;;   Boston 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],0        ; Force prompt?
24                 jnz enter_command
25                 test byte [KbdFlags],5Bh        ; Shift Alt Caps Scroll
26                 jz auto_boot                    ; If neither, default boot
27
28 enter_command:
29                 cmp word [NoEscape],0           ; If NOESCAPE, no prompt,
30                 jne auto_boot                   ; always run default cmd
31
32                 mov si,boot_prompt
33                 call cwritestr
34
35                 mov byte [FuncFlag],0           ; <Ctrl-F> not pressed
36                 mov di,command_line
37 ;
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.
41 ;
42 clear_buffer:   mov ah,11h                      ; Check for pending char
43                 int 16h
44                 jz get_char_time
45                 mov ah,10h                      ; Get char
46                 int 16h
47                 jmp short clear_buffer
48 get_char_time:  
49                 call vgashowcursor
50                 RESET_IDLE
51                 mov cx,[KbdTimeOut]
52                 and cx,cx
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
57 time_loop:      push cx
58 tick_loop:      push dx
59                 call pollchar
60                 jnz get_char_pop
61                 mov dx,[BIOS_timer]             ; Get time "of day"
62                 pop ax
63                 cmp dx,ax                       ; Has the timer advanced?
64                 je tick_loop
65                 pop cx
66                 DO_IDLE
67                 loop time_loop                  ; If so, decrement counter
68
69                 ; Timeout!!!!
70                 call vgahidecursor
71                 mov si,Ontimeout                ; Copy ontimeout command
72                 mov cx,[OntimeoutLen]           ; if we have one...
73                 rep movsb
74 .stddefault:
75                 jmp command_done
76
77 get_char_pop:   pop eax                         ; Clear stack
78 get_char:
79                 call vgashowcursor
80                 call getchar
81                 call vgahidecursor
82                 and al,al
83                 jz func_key
84
85 got_ascii:      cmp al,7Fh                      ; <DEL> == <BS>
86                 je backspace
87                 cmp al,' '                      ; ASCII?
88                 jb not_ascii
89                 ja enter_char
90                 cmp di,command_line             ; Space must not be first
91                 je short get_char
92 enter_char:     test byte [FuncFlag],1
93                 jz .not_ctrl_f
94                 mov byte [FuncFlag],0
95                 cmp al,'0'
96                 jb .not_ctrl_f
97                 je ctrl_f_0
98                 cmp al,'9'
99                 jbe ctrl_f
100 .not_ctrl_f:    cmp di,max_cmd_len+command_line ; Check there's space
101                 jnb short get_char
102                 stosb                           ; Save it
103                 call writechr                   ; Echo to screen
104                 jmp short get_char
105 not_ascii:      mov byte [FuncFlag],0
106                 cmp al,0Dh                      ; Enter
107                 je command_done
108                 cmp al,'F' & 1Fh                ; <Ctrl-F>
109                 je set_func_flag
110                 cmp al,'U' & 1Fh                ; <Ctrl-U>
111                 je kill_command                 ; Kill input line
112                 cmp al,'V' & 1Fh                ; <Ctrl-V>
113                 je print_version
114                 cmp al,'X' & 1Fh                ; <Ctrl-X>
115                 je force_text_mode
116                 cmp al,08h                      ; Backspace
117                 jne get_char
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
122                 call cwritestr
123                 jmp short get_char_2
124
125 kill_command:
126                 call crlf
127                 jmp enter_command
128
129 force_text_mode:
130                 call vgaclearmode
131                 jmp enter_command
132
133 set_func_flag:
134                 mov byte [FuncFlag],1
135 get_char_2:
136                 jmp short get_char
137
138 ctrl_f_0:       add al,10                       ; <Ctrl-F>0 == F10
139 ctrl_f:         sub al,'1'
140                 xor ah,ah
141                 jmp short show_help
142
143 func_key:
144                 ; AL = 0 if we get here
145                 xchg al,ah
146                 cmp al,68                       ; F10
147                 ja short get_char_2
148                 sub al,59                       ; F1
149                 jb short get_char_2
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
153                 add ax,FKeyName
154                 xchg di,ax
155                 cmp byte [di+NULLOFFSET],NULLFILE
156                 je short fk_nofile              ; Undefined F-key
157                 call searchdir
158                 jz short fk_nofile              ; File not found
159                 push si
160                 call crlf
161                 pop si
162                 call get_msg_file
163                 jmp short fk_wrcmd
164
165 print_version:
166                 push di                         ; Command line write pointer
167                 mov si,syslinux_banner
168                 call cwritestr
169                 mov si,copyright_str
170                 call cwritestr
171
172                 ; ... fall through ...
173
174                 ; Write the boot prompt and command line again and
175                 ; wait for input.  Note that this expects the cursor
176                 ; to already have been CRLF'd, and that the old value
177                 ; of DI (the command line write pointer) is on the stack.
178 fk_wrcmd:
179                 mov si,boot_prompt
180                 call cwritestr
181                 pop di                          ; Command line write pointer
182                 push di
183                 mov byte [di],0                 ; Null-terminate command line
184                 mov si,command_line
185                 call cwritestr                  ; Write command line so far
186 fk_nofile:      pop di
187                 jmp short get_char_2
188
189 ;
190 ; Jump here to run the default command line
191 ;
192 auto_boot:
193                 mov si,default_cmd
194                 mov di,command_line
195                 mov cx,(max_cmd_len+4) >> 2
196                 rep movsd
197                 jmp short load_kernel
198
199 ;
200 ; Jump here when the command line is completed
201 ;
202 command_done:
203                 call crlf
204                 cmp di,command_line             ; Did we just hit return?
205                 je auto_boot
206                 xor al,al                       ; Store a final null
207                 stosb
208
209 load_kernel:                                    ; Load the kernel now
210 ;
211 ; First we need to mangle the kernel name the way DOS would...
212 ;
213                 mov si,command_line
214                 mov di,KernelName
215                 push si
216                 push di
217                 call mangle_name
218                 pop di
219                 pop si
220 ;
221 ; Fast-forward to first option (we start over from the beginning, since
222 ; mangle_name doesn't necessarily return a consistent ending state.)
223 ;
224 clin_non_wsp:   lodsb
225                 cmp al,' '
226                 ja clin_non_wsp
227 clin_is_wsp:    and al,al
228                 jz clin_opt_ptr
229                 lodsb
230                 cmp al,' '
231                 jbe clin_is_wsp
232 clin_opt_ptr:   dec si                          ; Point to first nonblank
233                 mov [CmdOptPtr],si              ; Save ptr to first option
234 ;
235 ; If "allowoptions 0", put a null character here in order to ignore any
236 ; user-specified options.
237 ;
238                 mov ax,[AllowOptions]
239                 and ax,ax
240                 jnz clin_opt_ok
241                 mov [si],al
242 clin_opt_ok:
243
244 ;
245 ; Now check if it is a "virtual kernel"
246 ;
247 vk_check:
248                 xor si,si                       ; Beginning of vk_seg
249 .scan:
250                 cmp si,[VKernelBytes]
251                 jae .not_vk
252
253                 push ds
254                 push word vk_seg
255                 pop ds
256
257                 mov di,VKernelBuf
258                 call rllunpack
259                 pop ds
260                 ; SI updated on return
261
262                 sub di,cx                       ; Return to beginning of buf
263                 push si
264                 mov si,KernelName
265                 mov cx,FILENAME_MAX
266                 es repe cmpsb
267                 pop si
268                 je .found
269                 jmp .scan
270
271 ;
272 ; We *are* using a "virtual kernel"
273 ;
274 .found:
275                 push es
276                 push word real_mode_seg
277                 pop es
278                 mov di,cmd_line_here
279                 mov si,VKernelBuf+vk_append
280                 mov cx,[VKernelBuf+vk_appendlen]
281                 rep movsb
282                 mov [CmdLinePtr],di             ; Where to add rest of cmd
283                 pop es
284                 mov di,KernelName
285                 push di 
286                 mov si,VKernelBuf+vk_rname
287                 mov cx,FILENAME_MAX             ; We need ECX == CX later
288                 rep movsb
289                 pop di
290 %if IS_PXELINUX
291                 mov al,[VKernelBuf+vk_ipappend]
292                 mov [IPAppend],al
293 %endif
294                 xor bx,bx                       ; Try only one version
295
296 %if IS_PXELINUX || IS_ISOLINUX
297                 ; Is this a "localboot" pseudo-kernel?
298 %if IS_PXELINUX
299                 cmp byte [VKernelBuf+vk_rname+4], 0
300 %else
301                 cmp byte [VKernelBuf+vk_rname], 0
302 %endif
303                 jne get_kernel          ; No, it's real, go get it
304
305                 mov ax, [VKernelBuf+vk_rname+1]
306                 jmp local_boot
307 %else
308                 jmp get_kernel
309 %endif
310
311 .not_vk:
312
313 ;
314 ; Not a "virtual kernel" - check that's OK and construct the command line
315 ;
316                 cmp word [AllowImplicit],byte 0
317                 je bad_implicit
318                 push es
319                 push si
320                 push di
321                 mov di,real_mode_seg
322                 mov es,di
323                 mov si,AppendBuf
324                 mov di,cmd_line_here
325                 mov cx,[AppendLen]
326                 rep movsb
327                 mov [CmdLinePtr],di
328                 pop di
329                 pop si
330                 pop es
331 ;
332 ; Find the kernel on disk
333 ;
334 get_kernel:     mov byte [KernelName+FILENAME_MAX],0    ; Zero-terminate filename/extension
335 %if IS_SYSLINUX || IS_MDSLINUX                  ; SYSLINUX has to deal with DOS mangled names...
336                 mov eax,[KernelName+8]          ; Save initial extension
337                 mov [exten_table_end],eax       ; Last case == initial ext.
338 %else
339                 mov di,KernelName+4*IS_PXELINUX
340                 xor al,al
341                 mov cx,FILENAME_MAX-5           ; Need 4 chars + null
342                 repne scasb                     ; Scan for final null
343                 jne .no_skip
344                 dec di                          ; Point to final null 
345 .no_skip:       mov [KernelExtPtr],di
346 %endif
347                 mov bx,exten_table
348 .search_loop:   push bx
349                 mov di,KernelName               ; Search on disk
350                 call searchdir
351                 pop bx
352                 jnz kernel_good
353                 mov eax,[bx]                    ; Try a different extension
354 %if IS_SYSLINUX || IS_MDSLINUX
355                 mov [KernelName+8],eax
356 %else
357                 mov si,[KernelExtPtr]
358                 mov [si],eax
359                 mov byte [si+4],0
360 %endif
361                 add bx,byte 4
362                 cmp bx,exten_table_end
363                 jna .search_loop                ; allow == case (final case)
364                 ; Fall into bad_kernel
365 ;
366 ; bad_kernel: Kernel image not found
367 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
368 ;
369 bad_implicit:
370 bad_kernel:
371                 mov cx,[OnerrorLen]
372                 and cx,cx
373                 jnz on_error
374 .really:
375                 mov si,KernelName
376                 mov di,KernelCName
377                 push di
378                 call unmangle_name              ; Get human form
379                 mov si,err_notfound             ; Complain about missing kernel
380                 call cwritestr
381                 pop si                          ; KernelCName
382                 call cwritestr
383                 mov si,crlf_msg
384                 jmp abort_load                  ; Ask user for clue
385
386 ;
387 ; on_error: bad kernel, but we have onerror set
388 ;
389 on_error:
390                 mov si,Onerror
391                 mov di,command_line
392                 push si                         ; <A>
393                 push di                         ; <B>
394                 push cx                         ; <C>
395                 push cx                         ; <D>
396                 push di                         ; <E>
397                 repe cmpsb
398                 pop di                          ; <E> di == command_line
399                 pop bx                          ; <D> bx == [OnerrorLen]
400                 je bad_kernel.really            ; Onerror matches command_line already
401                 neg bx                          ; bx == -[OnerrorLen]
402                 lea cx,[max_cmd_len+bx]
403                 ; CX == max_cmd_len-[OnerrorLen]
404                 mov di,command_line+max_cmd_len-1
405                 mov byte [di+1],0               ; Enforce null-termination
406                 lea si,[di+bx]
407                 std
408                 rep movsb                       ; Make space in command_line
409                 cld
410                 pop cx                          ; <C> cx == [OnerrorLen]
411                 pop di                          ; <B> di == command_line
412                 pop si                          ; <A> si  == Onerror
413                 rep movsb
414                 jmp load_kernel
415
416 ;
417 ; kernel_corrupt: Called if the kernel file does not seem healthy
418 ;
419 kernel_corrupt: mov si,err_notkernel
420                 jmp abort_load
421 ;
422 ; This is it!  We have a name (and location on the disk)... let's load
423 ; that sucker!!  First we have to decide what kind of file this is; base
424 ; that decision on the file extension.  The following extensions are
425 ; recognized; case insensitive:
426 ;
427 ; .com  - COMBOOT image
428 ; .cbt  - COMBOOT image
429 ; .c32  - COM32 image
430 ; .bs   - Boot sector
431 ; .0    - PXE bootstrap program (PXELINUX only)
432 ; .bin  - Boot sector
433 ; .bss  - Boot sector, but transfer over DOS superblock (SYSLINUX only)
434 ; .img  - Floppy image (ISOLINUX only)
435 ;
436 ; Anything else is assumed to be a Linux kernel.
437 ;
438 kernel_good:
439                 pusha
440                 mov si,KernelName
441                 mov di,KernelCName
442                 call unmangle_name
443                 sub di,KernelCName
444                 mov [KernelCNameLen],di
445                 popa
446                 
447 %if IS_SYSLINUX || IS_MDSLINUX
448                 mov ecx,[KernelName+7]
449                 mov cl,'.'
450 %else
451                 push di
452                 push ax
453                 mov di,KernelName+4*IS_PXELINUX
454                 xor al,al
455                 mov cx,FILENAME_MAX
456                 repne scasb
457                 jne .one_step
458                 dec di
459 .one_step:      mov ecx,[di-4]                  ; 4 bytes before end
460                 pop ax
461                 pop di
462 %endif
463
464 ;
465 ; At this point, DX:AX contains the size of the kernel, and SI contains
466 ; the file handle/cluster pointer.
467 ;
468                 or ecx,20202000h                ; Force lower case
469
470                 cmp ecx,'.com'
471                 je is_comboot_image
472                 cmp ecx,'.cbt'
473                 je is_comboot_image
474                 cmp ecx,'.c32'
475                 je is_com32_image
476 %if IS_ISOLINUX
477                 cmp ecx,'.img'
478                 je is_disk_image
479 %endif
480                 cmp ecx,'.bss'
481                 je is_bss_sector
482                 cmp ecx,'.bin'
483                 je is_bootsector
484 %if IS_SYSLINUX || IS_MDSLINUX
485                 cmp ecx,'.bs '
486                 je is_bootsector
487                 cmp ecx,'.0  '
488                 je is_bootsector
489 %else
490                 shr ecx,8
491                 cmp ecx,'.bs'
492                 je is_bootsector
493                 shr ecx,8
494                 cmp cx,'.0'
495                 je is_bootsector
496 %endif
497                 ; Otherwise Linux kernel
498
499                 section .bss
500                 alignb 2
501 KernelExtPtr    resw 1                  ; During search, final null pointer
502 CmdOptPtr       resw 1                  ; Pointer to first option on cmd line
503 KbdFlags        resb 1                  ; Check for keyboard escapes
504 FuncFlag        resb 1                  ; Escape sequences received from keyboard
505
506                 section .text