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