Fix COMBOOT return; support DOS system calls 00 and 4C (both are EXIT.)
[profile/ivi/syslinux.git] / comboot.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 ;; comboot.inc
16 ;; 
17 ;; Common code for running a COMBOOT image
18 ;;
19
20 ; Looks like a COMBOOT image but too large
21 comboot_too_large:
22                 mov si,err_comlarge
23                 call cwritestr
24 cb_enter:       jmp enter_command
25
26 ;
27 ; Load a COMBOOT image.  A COMBOOT image is basically a DOS .COM file,
28 ; except that it may, of course, not contain any DOS system calls.  We
29 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
30 ;
31 is_comboot_image:
32                 and dx,dx
33                 jnz comboot_too_large
34                 cmp ax,0ff00h           ; Max size in bytes
35                 jae comboot_too_large
36
37                 ;
38                 ; Set up the DOS vectors in the IVT (INT 20h-3fh)
39                 ;
40                 mov di,4*0x20           ; DOS interrupt vectors
41                 mov eax,comboot_return
42                 stosd
43                 mov ax,comboot_int21
44                 stosd
45                 mov ax,comboot_bogus
46                 mov cx,30               ; All remaining DOS vectors
47                 rep stosd
48
49                 mov cx,comboot_seg
50                 mov es,cx
51
52                 mov bx,100h             ; Load at <seg>:0100h
53
54                 mov cx,[ClustPerMoby]   ; Absolute maximum # of clusters
55                 call getfssec
56
57                 xor di,di
58                 mov cx,64               ; 256 bytes (size of PSP)
59                 xor eax,eax             ; Clear PSP
60                 rep stosd
61
62                 mov word [es:0], 020CDh ; INT 20h instruction
63                 ; First non-free paragraph
64                 mov word [es:02h], comboot_seg+1000h
65
66                 ; Copy the command line from high memory
67                 mov cx,125              ; Max cmdline len (minus space and CR)
68                 mov si,[CmdOptPtr]
69                 mov di,081h             ; Offset in PSP for command line
70                 mov al,' '              ; DOS command lines begin with a space
71                 stosb
72
73 comboot_cmd_cp: lodsb
74                 and al,al
75                 jz comboot_end_cmd
76                 stosb
77                 loop comboot_cmd_cp
78 comboot_end_cmd: mov al,0Dh             ; CR after last character
79                 stosb
80                 mov al,126              ; Include space but not CR
81                 sub al,cl
82                 mov [es:80h], al        ; Store command line length
83
84                 mov [SavedSSSP],sp
85                 mov [SavedSSSP+2],ss    ; Save away SS:SP
86
87                 call vgaclearmode       ; Reset video
88
89                 mov ax,es
90                 mov ds,ax
91                 mov ss,ax
92                 xor sp,sp
93                 push word 0             ; Return to address 0 -> exit
94
95                 jmp comboot_seg:100h    ; Run it
96
97 ; Proper return vector
98 comboot_return: cli                     ; Don't trust anyone
99                 xor ax,ax
100                 jmp comboot_exit
101
102 ; INT 21h: generic DOS system call
103 comboot_int21:  and ah,ah               ; 00 = return
104                 je comboot_return
105                 cmp ah,4Ch              ; 4C = return with status
106                 je comboot_return
107
108                 ; Otherwise fall through to comboot_bogus
109
110 ; Attempted to execute non-21h DOS system call
111 comboot_bogus:  cli                     ; Don't trust anyone
112                 mov ax,err_notdos
113
114 ;
115 ; Generic COMBOOT return to command line code
116 ;
117 comboot_exit:
118                 lss sp,[cs:SavedSSSP]
119                 xor dx,dx
120                 mov ds,dx
121                 mov es,dx
122                 sti
123                 cld
124                 and ax,ax
125                 je .nomsg
126                 mov si,KernelCName
127                 call cwritestr
128                 xchg si,ax
129                 call cwritestr
130 .nomsg:         jmp cb_enter
131