PXELINUX: Add <Ctrl-N> to print the network information
[profile/ivi/syslinux.git] / ui.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2007 H. Peter Anvin - All Rights Reserved
4 ;;
5 ;;   This program is free software; you can redistribute it and/or modify
6 ;;   it under the terms of the GNU General Public License as published by
7 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
10 ;;
11 ;; -----------------------------------------------------------------------
12
13 ;
14 ; This file should be entered with the config file open (for getc)
15 ;
16 load_config_file:
17                 call parse_config               ; Parse configuration file
18 no_config_file:
19
20 ;
21 ; Check whether or not we are supposed to display the boot prompt.
22 ;
23 check_for_key:
24                 cmp word [ForcePrompt],0        ; Force prompt?
25                 jnz enter_command
26                 test byte [KbdFlags],5Bh        ; Shift Alt Caps Scroll
27                 jz auto_boot                    ; If neither, default boot
28
29 enter_command:
30                 cmp word [NoEscape],0           ; If NOESCAPE, no prompt,
31                 jne auto_boot                   ; always run default cmd
32
33                 mov si,boot_prompt
34                 call cwritestr
35
36                 mov byte [FuncFlag],0           ; <Ctrl-F> not pressed
37                 mov di,command_line
38
39 ;
40 ; get the very first character -- we can either time
41 ; out, or receive a character press at this time.  Some dorky BIOSes stuff
42 ; a return in the buffer on bootup, so wipe the keyboard buffer first.
43 ;
44 clear_buffer:   mov ah,11h                      ; Check for pending char
45                 int 16h
46                 jz get_char_time
47                 mov ah,10h                      ; Get char
48                 int 16h
49                 jmp short clear_buffer
50
51                 ; For the first character, both KbdTimeout and
52                 ; TotalTimeout apply; after that, only TotalTimeout.
53
54 get_char_time:
55                 mov eax,[TotalTimeout]
56                 mov [ThisTotalTo],eax
57                 mov eax,[KbdTimeout]
58                 mov [ThisKbdTo],eax
59
60 get_char:
61                 call getchar_timeout
62                 and dword [ThisKbdTo],0         ; For the next time...
63
64                 and al,al
65                 jz func_key
66
67 got_ascii:      cmp al,7Fh                      ; <DEL> == <BS>
68                 je backspace
69                 cmp al,' '                      ; ASCII?
70                 jb not_ascii
71                 ja enter_char
72                 cmp di,command_line             ; Space must not be first
73                 je short get_char
74 enter_char:     test byte [FuncFlag],1
75                 jz .not_ctrl_f
76                 mov byte [FuncFlag],0
77                 cmp al,'0'
78                 jb .not_ctrl_f
79                 je ctrl_f_0
80                 cmp al,'9'
81                 jbe ctrl_f
82 .not_ctrl_f:    cmp di,max_cmd_len+command_line ; Check there's space
83                 jnb short get_char
84                 stosb                           ; Save it
85                 call writechr                   ; Echo to screen
86                 jmp short get_char
87 not_ascii:      mov byte [FuncFlag],0
88                 cmp al,0Dh                      ; Enter
89                 je command_done
90                 cmp al,'F' & 1Fh                ; <Ctrl-F>
91                 je set_func_flag
92 %if IS_PXELINUX
93                 cmp al,'N' & 1Fh                ; <Ctrl-N>
94                 je show_network_info
95 %endif
96                 cmp al,'U' & 1Fh                ; <Ctrl-U>
97                 je kill_command                 ; Kill input line
98                 cmp al,'V' & 1Fh                ; <Ctrl-V>
99                 je print_version
100                 cmp al,'X' & 1Fh                ; <Ctrl-X>
101                 je force_text_mode
102                 cmp al,08h                      ; Backspace
103                 jne get_char
104 backspace:      cmp di,command_line             ; Make sure there is anything
105                 je get_char                     ; to erase
106                 dec di                          ; Unstore one character
107                 mov si,wipe_char                ; and erase it from the screen
108                 call cwritestr
109 get_char_2:
110                 jmp short get_char
111
112 kill_command:
113                 call crlf
114                 jmp enter_command
115
116 force_text_mode:
117                 call vgaclearmode
118                 jmp enter_command
119
120 set_func_flag:
121                 mov byte [FuncFlag],1
122                 jmp short get_char_2
123
124 ctrl_f_0:       add al,10                       ; <Ctrl-F>0 == F10
125 ctrl_f:         sub al,'1'
126                 xor ah,ah
127                 jmp short show_help
128
129 func_key:
130                 ; AL = 0 if we get here
131                 xchg al,ah
132                 cmp al,68                       ; F10
133                 ja short get_char_2
134                 sub al,59                       ; F1
135                 jb short get_char_2
136 show_help:      ; AX = func key # (0 = F1, 9 = F10)
137                 push di                         ; Save end-of-cmdline pointer
138                 shl ax,FILENAME_MAX_LG2         ; Convert to pointer
139                 add ax,FKeyName
140                 xchg di,ax
141                 cmp byte [di+NULLOFFSET],NULLFILE
142                 je short fk_nofile              ; Undefined F-key
143                 call searchdir
144                 jz short fk_nofile              ; File not found
145                 push si
146                 call crlf
147                 pop si
148                 call get_msg_file
149                 jmp short fk_wrcmd
150
151 print_version:
152                 push di                         ; Command line write pointer
153                 mov si,syslinux_banner
154                 call cwritestr
155 %ifdef HAVE_BIOSNAME
156                 mov si,[BIOSName]
157                 call cwritestr
158 %endif
159                 mov si,copyright_str
160                 call cwritestr
161
162                 ; ... fall through ...
163
164                 ; Write the boot prompt and command line again and
165                 ; wait for input.  Note that this expects the cursor
166                 ; to already have been CRLF'd, and that the old value
167                 ; of DI (the command line write pointer) is on the stack.
168 fk_wrcmd:
169                 mov si,boot_prompt
170                 call cwritestr
171                 pop di                          ; Command line write pointer
172                 push di
173                 mov byte [di],0                 ; Null-terminate command line
174                 mov si,command_line
175                 call cwritestr                  ; Write command line so far
176 fk_nofile:      pop di
177                 jmp short get_char_2
178
179 ;
180 ; Show network info (in the form of the ipappend strings)
181 ;
182 %if IS_PXELINUX
183 show_network_info:
184                 mov si,IPAppends                ; See comboot.doc
185                 mov cx,numIPAppends
186 .loop:
187                 lodsw
188                 push si
189                 mov si,ax
190                 call cwritestr
191                 call crlf
192                 pop si
193                 loop .loop
194                 jmp fk_wrcmd
195 %endif
196
197 ;
198 ; Jump here to run the default command line
199 ;
200 auto_boot:
201                 mov si,default_cmd
202                 mov di,command_line
203                 mov cx,(max_cmd_len+4) >> 2
204                 rep movsd
205                 jmp short load_kernel
206
207 ;
208 ; Jump here when the command line is completed
209 ;
210 command_done:
211                 call crlf
212                 cmp di,command_line             ; Did we just hit return?
213                 je auto_boot
214                 xor al,al                       ; Store a final null
215                 stosb
216
217 load_kernel:                                    ; Load the kernel now
218 ;
219 ; First we need to mangle the kernel name the way DOS would...
220 ;
221                 mov si,command_line
222                 mov di,KernelName
223                 push si
224                 call mangle_name
225                 pop si
226 ;
227 ; Fast-forward to first option (we start over from the beginning, since
228 ; mangle_name doesn't necessarily return a consistent ending state.)
229 ;
230 clin_non_wsp:   lodsb
231                 cmp al,' '
232                 ja clin_non_wsp
233 clin_is_wsp:    and al,al
234                 jz clin_opt_ptr
235                 lodsb
236                 cmp al,' '
237                 jbe clin_is_wsp
238 clin_opt_ptr:   dec si                          ; Point to first nonblank
239                 mov [CmdOptPtr],si              ; Save ptr to first option
240 ;
241 ; If "allowoptions 0", put a null character here in order to ignore any
242 ; user-specified options.
243 ;
244                 mov ax,[AllowOptions]
245                 and ax,ax
246                 jnz clin_opt_ok
247                 mov [si],al
248 clin_opt_ok:
249
250 ;
251 ; Now check if it is a "virtual kernel"
252 ;
253 vk_check:
254                 xor si,si                       ; Beginning of vk_seg
255 .scan:
256                 cmp si,[VKernelBytes]
257                 jae .not_vk
258
259                 push ds
260                 push word vk_seg
261                 pop ds
262
263                 mov di,VKernelBuf
264                 call rllunpack
265                 pop ds
266                 ; SI updated on return
267
268                 sub di,cx                       ; Return to beginning of buf
269                 push si
270                 mov si,KernelName
271                 mov cx,FILENAME_MAX
272                 es repe cmpsb
273                 pop si
274                 je .found
275                 jmp .scan
276
277 ;
278 ; We *are* using a "virtual kernel"
279 ;
280 .found:
281                 push es
282                 push word real_mode_seg
283                 pop es
284                 mov di,cmd_line_here
285                 mov si,VKernelBuf+vk_append
286                 mov cx,[VKernelBuf+vk_appendlen]
287                 rep movsb
288                 mov [CmdLinePtr],di             ; Where to add rest of cmd
289                 pop es
290                 mov di,KernelName
291                 push di
292                 mov si,VKernelBuf+vk_rname
293                 mov cx,FILENAME_MAX             ; We need ECX == CX later
294                 rep movsb
295                 pop di
296 %if IS_PXELINUX
297                 mov al,[VKernelBuf+vk_ipappend]
298                 mov [IPAppend],al
299 %endif
300                 xor bx,bx                       ; Try only one version
301
302                 mov al, [VKernelBuf+vk_type]
303                 mov [KernelType], al
304
305 %if IS_PXELINUX || IS_ISOLINUX
306                 ; Is this a "localboot" pseudo-kernel?
307 %if IS_PXELINUX
308                 cmp byte [VKernelBuf+vk_rname+4], 0
309 %else
310                 cmp byte [VKernelBuf+vk_rname], 0
311 %endif
312                 jne get_kernel          ; No, it's real, go get it
313
314                 mov ax, [VKernelBuf+vk_rname+1]
315                 jmp local_boot
316 %else
317                 jmp get_kernel
318 %endif
319
320 .not_vk:
321
322 ;
323 ; Not a "virtual kernel" - check that's OK and construct the command line
324 ;
325                 cmp word [AllowImplicit],byte 0
326                 je bad_implicit
327                 push es
328                 push si
329                 push di
330                 mov di,real_mode_seg
331                 mov es,di
332                 mov si,AppendBuf
333                 mov di,cmd_line_here
334                 mov cx,[AppendLen]
335                 rep movsb
336                 mov [CmdLinePtr],di
337                 pop di
338                 pop si
339                 pop es
340
341                 mov [KernelType], cl            ; CL == 0 here
342
343 ;
344 ; Find the kernel on disk
345 ;
346 get_kernel:     mov byte [KernelName+FILENAME_MAX],0    ; Zero-terminate filename/extension
347                 mov di,KernelName+4*IS_PXELINUX
348                 xor al,al
349                 mov cx,FILENAME_MAX-5           ; Need 4 chars + null
350                 repne scasb                     ; Scan for final null
351                 jne .no_skip
352                 dec di                          ; Point to final null
353 .no_skip:       mov [KernelExtPtr],di
354                 mov bx,exten_table
355 .search_loop:   push bx
356                 mov di,KernelName               ; Search on disk
357                 call searchdir
358                 pop bx
359                 jnz kernel_good
360                 mov eax,[bx]                    ; Try a different extension
361                 mov si,[KernelExtPtr]
362                 mov [si],eax
363                 mov byte [si+4],0
364                 add bx,byte 4
365                 cmp bx,exten_table_end
366                 jna .search_loop                ; allow == case (final case)
367                 ; Fall into bad_kernel
368 ;
369 ; bad_kernel: Kernel image not found
370 ; bad_implicit: The user entered a nonvirtual kernel name, with "implicit 0"
371 ;
372 bad_implicit:
373 bad_kernel:
374                 mov cx,[OnerrorLen]
375                 and cx,cx
376                 jnz on_error
377 .really:
378                 mov si,KernelName
379                 mov di,KernelCName
380                 push di
381                 call unmangle_name              ; Get human form
382                 mov si,err_notfound             ; Complain about missing kernel
383                 call cwritestr
384                 pop si                          ; KernelCName
385                 call cwritestr
386                 mov si,crlf_msg
387                 jmp abort_load                  ; Ask user for clue
388
389 ;
390 ; on_error: bad kernel, but we have onerror set; CX = OnerrorLen
391 ;
392 on_error:
393                 mov si,Onerror
394                 mov di,command_line
395                 push si                         ; <A>
396                 push di                         ; <B>
397                 push cx                         ; <C>
398                 push cx                         ; <D>
399                 push di                         ; <E>
400                 repe cmpsb
401                 pop di                          ; <E> di == command_line
402                 pop bx                          ; <D> bx == [OnerrorLen]
403                 je bad_kernel.really            ; Onerror matches command_line already
404                 neg bx                          ; bx == -[OnerrorLen]
405                 lea cx,[max_cmd_len+bx]
406                 ; CX == max_cmd_len-[OnerrorLen]
407                 mov di,command_line+max_cmd_len-1
408                 mov byte [di+1],0               ; Enforce null-termination
409                 lea si,[di+bx]
410                 std
411                 rep movsb                       ; Make space in command_line
412                 cld
413                 pop cx                          ; <C> cx == [OnerrorLen]
414                 pop di                          ; <B> di == command_line
415                 pop si                          ; <A> si  == Onerror
416                 rep movsb
417                 jmp load_kernel
418
419 ;
420 ; kernel_corrupt: Called if the kernel file does not seem healthy
421 ;
422 kernel_corrupt: mov si,err_notkernel
423                 jmp abort_load
424
425 ;
426 ; Get a key, observing ThisKbdTO and ThisTotalTO -- those are timeouts
427 ; which can be adjusted by the caller based on the corresponding
428 ; master variables; on return they're updated.
429 ;
430 ; This cheats.  If we say "no timeout" we actually get a timeout of
431 ; 7.5 years.
432 ;
433 getchar_timeout:
434                 call vgashowcursor
435                 RESET_IDLE
436
437 .loop:
438                 push word [BIOS_timer]
439                 call pollchar
440                 jnz .got_char
441                 pop ax
442                 cmp ax,[BIOS_timer]             ; Has the timer advanced?
443                 je .loop
444                 DO_IDLE
445
446                 dec dword [ThisKbdTo]
447                 jz .timeout
448                 dec dword [ThisTotalTo]
449                 jnz .loop
450
451 .timeout:
452                 ; Timeout!!!!
453                 pop cx                          ; Discard return address
454                 call vgahidecursor
455                 mov si,Ontimeout                ; Copy ontimeout command
456                 mov di,command_line
457                 mov cx,[OntimeoutLen]           ; if we have one...
458                 rep movsb
459                 jmp command_done
460
461 .got_char:
462                 pop cx                          ; Discard
463                 call getchar
464                 call vgahidecursor
465                 ret
466
467 ;
468 ; This is it!  We have a name (and location on the disk)... let's load
469 ; that sucker!!  First we have to decide what kind of file this is; base
470 ; that decision on the file extension.  The following extensions are
471 ; recognized; case insensitive:
472 ;
473 ; .com  - COMBOOT image
474 ; .cbt  - COMBOOT image
475 ; .c32  - COM32 image
476 ; .bs   - Boot sector
477 ; .0    - PXE bootstrap program (PXELINUX only)
478 ; .bin  - Boot sector
479 ; .bss  - Boot sector, but transfer over DOS superblock (SYSLINUX only)
480 ; .img  - Floppy image (ISOLINUX only)
481 ;
482 ; Anything else is assumed to be a Linux kernel.
483 ;
484                 section .bss
485                 alignb 4
486 Kernel_EAX      resd 1
487 Kernel_SI       resw 1
488
489                 section .text
490 kernel_good_saved:
491                 ; Alternate entry point for which the return from
492                 ; searchdir is stored in memory.  This is used for
493                 ; COMBOOT function INT 22h, AX=0016h.
494                 mov si,[Kernel_SI]
495                 mov eax,[Kernel_EAX]
496                 mov dx,[Kernel_EAX+2]
497
498 kernel_good:
499                 pusha
500                 mov si,KernelName
501                 mov di,KernelCName
502                 call unmangle_name
503                 sub di,KernelCName
504                 mov [KernelCNameLen],di
505                 popa
506
507                 push di
508                 push ax
509                 mov di,KernelName+4*IS_PXELINUX
510                 xor al,al
511                 mov cx,FILENAME_MAX
512                 repne scasb
513                 jne .one_step
514                 dec di
515 .one_step:      mov ecx,[di-4]                  ; 4 bytes before end
516                 pop ax
517                 pop di
518
519 ;
520 ; At this point, DX:AX contains the size of the kernel, SI contains
521 ; the file handle/cluster pointer, and ECX contains the extension (if any.)
522 ;
523                 movzx di,byte [KernelType]
524                 add di,di
525                 jmp [kerneltype_table+di]
526
527 is_unknown_filetype:
528                 or ecx,20202000h                ; Force lower case (except dot)
529
530                 cmp ecx,'.com'
531                 je is_comboot_image
532                 cmp ecx,'.cbt'
533                 je is_comboot_image
534                 cmp ecx,'.c32'
535                 je is_com32_image
536 %if IS_ISOLINUX
537                 cmp ecx,'.img'
538                 je is_disk_image
539 %endif
540                 cmp ecx,'.bss'
541                 je is_bss_sector
542                 cmp ecx,'.bin'
543                 je is_bootsector
544                 shr ecx,8
545                 cmp ecx,'.bs'
546                 je is_bootsector
547                 shr ecx,8
548                 cmp cx,'.0'
549                 je is_bootsector
550
551                 ; Otherwise Linux kernel
552                 jmp is_linux_kernel
553
554 is_config_file:
555                 pusha
556                 mov si,KernelCName              ; Save the config file name, for posterity
557                 mov di,ConfigName
558                 call strcpy
559                 popa
560                 call openfd
561                 call reset_config
562                 jmp load_config_file
563
564 ; This is an image type we can't deal with
565 is_bad_image:
566                 mov si,err_badimage
567                 call cwritestr
568                 jmp enter_command
569
570 %if IS_SYSLINUX || IS_MDSLINUX
571                 ; ok
572 %else
573 is_bss_sector   equ is_bad_image
574 %endif
575 %if IS_ISOLINUX
576                 ; ok
577 %else
578 is_disk_image   equ is_bad_image
579 %endif
580
581                 section .data
582 err_badimage    db 'Invalid image type for this media type!', CR, LF, 0
583
584                 align 2, db 0
585 kerneltype_table:
586                 dw is_unknown_filetype  ; VK_KERNEL
587                 dw is_linux_kernel      ; VK_LINUX
588                 dw is_bootsector        ; VK_BOOT
589                 dw is_bss_sector        ; VK_BSS
590                 dw is_bootsector        ; VK_PXE
591                 dw is_disk_image        ; VK_FDIMAGE
592                 dw is_comboot_image     ; VK_COMBOOT
593                 dw is_com32_image       ; VK_COM32
594                 dw is_config_file       ; VK_CONFIG
595
596                 section .bss
597                 alignb 4
598 ThisKbdTo       resd 1                  ; Temporary holder for KbdTimeout
599 ThisTotalTo     resd 1                  ; Temporary holder for TotalTimeout
600 KernelExtPtr    resw 1                  ; During search, final null pointer
601 CmdOptPtr       resw 1                  ; Pointer to first option on cmd line
602 KbdFlags        resb 1                  ; Check for keyboard escapes
603 FuncFlag        resb 1                  ; Escape sequences received from keyboard
604 KernelType      resb 1                  ; Kernel type, from vkernel, if known
605
606                 section .text