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