If onerror is set, invoke onerror on escape
[profile/ivi/syslinux.git] / abort.inc
1 ; $Id$
2 ; -----------------------------------------------------------------------
3 ;   
4 ;   Copyright 2005 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 ; abort.inc
16 ;
17 ; Code to terminate a kernel load
18 ;
19
20 ;
21 ; abort_check: let the user abort with <ESC> or <Ctrl-C>
22 ;
23 abort_load      equ abort_check.do_abort
24
25 abort_check:
26                 call pollchar
27                 jz .ret1
28                 pusha
29                 call getchar
30                 cmp al,27                       ; <ESC>
31                 je .kill
32                 cmp al,3                        ; <Ctrl-C>
33                 jne .ret2
34 .kill:          mov si,aborted_msg
35
36                 ; ... fall through ...
37
38 ;
39 ; abort_load: Called by various routines which wants to print a fatal
40 ;             error message and return to the command prompt.  Since this
41 ;             may happen at just about any stage of the boot process, assume
42 ;             our state is messed up, and just reset the segment registers
43 ;             and the stack forcibly.
44 ;
45 ;             SI    = offset (in _text) of error message to print
46 ;
47 .do_abort:
48                 mov ax,cs                       ; Restore CS = DS = ES
49                 mov ds,ax
50                 mov es,ax
51 %if IS_SYSLINUX || IS_EXTLINUX
52                 mov ss,ax                       ; Just in case...
53                 mov sp,StackBuf-2*3             ; Reset stack
54 %elif IS_PXELINUX
55                 lss esp,[BaseStack]
56 %elif IS_ISOLINUX
57                 lss sp,[cs:Stack]
58 %else
59                 NEED TO KNOW HOW TO RESET STACK
60 %endif
61                 sti
62                 call cwritestr                  ; Expects SI -> error msg
63
64                 ; If onerror is set, jump to onerror, otherwise return
65                 ; to the command prompt
66                 mov cx,[OnerrorLen]
67                 and cx,cx
68                 jnz on_error
69                 jmp enter_command               ; Return to command prompt
70
71 ;
72 ; End of abort_check
73 ;
74 .ret2:          popa
75 .ret1:          ret