Remove the noop API call, and instead use function 0 for internal
[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                 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                 call comboot_setup_api
38
39                 mov cx,comboot_seg
40                 mov es,cx
41
42                 mov bx,100h             ; Load at <seg>:0100h
43
44                 mov cx,[ClustPerMoby]   ; Absolute maximum # of clusters
45                 call getfssec
46
47                 xor di,di
48                 mov cx,64               ; 256 bytes (size of PSP)
49                 xor eax,eax             ; Clear PSP
50                 rep stosd
51
52                 mov word [es:0], 020CDh ; INT 20h instruction
53                 ; First non-free paragraph
54                 mov word [es:02h], comboot_seg+1000h
55
56                 ; Copy the command line from high memory
57                 mov cx,125              ; Max cmdline len (minus space and CR)
58                 mov si,[CmdOptPtr]
59                 mov di,081h             ; Offset in PSP for command line
60                 mov al,' '              ; DOS command lines begin with a space
61                 stosb
62
63 comboot_cmd_cp: lodsb
64                 and al,al
65                 jz comboot_end_cmd
66                 stosb
67                 loop comboot_cmd_cp
68 comboot_end_cmd: mov al,0Dh             ; CR after last character
69                 stosb
70                 mov al,126              ; Include space but not CR
71                 sub al,cl
72                 mov [es:80h], al        ; Store command line length
73
74                 mov [SavedSSSP],sp
75                 mov [SavedSSSP+2],ss    ; Save away SS:SP
76
77                 mov ax,es
78                 mov ds,ax
79                 mov ss,ax
80                 xor sp,sp
81                 push word 0             ; Return to address 0 -> exit
82
83                 jmp comboot_seg:100h    ; Run it
84
85 ; Proper return vector
86 comboot_return: cli                     ; Don't trust anyone
87                 xor ax,ax
88                 jmp comboot_exit
89
90 ;
91 ; Set up the COMBOOT API interrupt vectors.  This is also used
92 ; by the COM32 code.
93 ;
94 comboot_setup_api:
95                 mov di,4*0x20           ; DOS interrupt vectors
96                 mov eax,comboot_return  ; INT 20h = exit
97                 stosd
98                 mov ax,comboot_int21    ; INT 21h = DOS-compatible syscalls
99                 stosd
100                 mov ax,comboot_int22    ; INT 22h = proprietary syscalls
101                 stosd
102                 mov ax,comboot_bogus
103                 mov cx,29               ; All remaining DOS vectors
104                 rep stosd
105                 ret
106
107 ; INT 21h: generic DOS system call
108 comboot_int21:  push ds
109                 push cs
110                 pop ds                  ; Set DS <- CS
111                 and ah,ah               ; 00 = return
112                 je comboot_return
113                 cmp ah,02h
114                 jb comboot_getkeyecho   ; 01 = get key with echo
115                 je comboot_writechr     ; 02 = writechr
116                 cmp ah,08h              ; 08 = get key w/o echo
117                 je comboot_getkey
118                 cmp ah,09h              ; 09 = writestr
119                 je comboot_writestr
120                 cmp ah,0Bh              ; 0B = check keyboard
121                 je comboot_checkkey
122                 cmp ah,30h              ; 30 = check version
123                 je comboot_checkver
124                 cmp ah,4Ch              ; 4C = return with status
125                 je comboot_return
126
127                 ; Otherwise fall through to comboot_bogus
128
129 ; Attempted to execute non-21h DOS system call
130 comboot_bogus:  cli                     ; Don't trust anyone
131                 mov ax,err_notdos
132 ;
133 ; Generic COMBOOT return to command line code
134 ;  AX -> message (if any)
135 ;  BX -> where to go next
136 ;
137 comboot_exit:
138                 mov bx,enter_command    ; Normal return to command prompt
139 comboot_exit_special:
140                 xor dx,dx
141                 mov ds,dx
142                 mov es,dx
143                 lss sp,[SavedSSSP]
144                 sti
145                 cld
146                 and ax,ax
147                 je .nomsg
148                 mov si,KernelCName
149                 call cwritestr
150                 xchg si,ax
151                 call cwritestr
152 .nomsg:         jmp bx
153
154 ;
155 ; INT 21h system calls
156 ;
157 comboot_getkeyecho:                     ; 01 = get key with echo
158                 call vgashowcursor
159                 call getchar
160                 call vgahidecursor
161                 call writechr
162                 jmp comboot_resume_ok
163
164 comboot_writechr:                       ; 02 = writechr
165                 xchg ax,dx
166                 call writechr
167                 xchg ax,dx
168                 jmp comboot_resume_ok
169
170 comboot_getkey:                         ; 08 = get key w/o echo
171                 call vgashowcursor
172                 call getchar
173                 call vgahidecursor
174                 jmp comboot_resume_ok
175
176 comboot_writestr:                       ; 09 = write string
177                 pusha
178                 push es
179                 mov bp,sp
180                 mov es,[bp-20]          ; Old DS
181                 mov si,dx
182 .loop:          es lodsb
183                 cmp al,'$'              ; End string with $ - bizarre
184                 je .done
185                 call writechr
186                 jmp short .loop
187 .done:          pop es
188                 popa
189                 jmp comboot_resume_ok
190
191 comboot_checkkey:                       ; 0B = check keyboard status
192                 call pollchar
193                 setz al
194                 dec al                  ; AL = 0FFh if present, 0 if not
195                 jmp comboot_resume_ok
196
197 comboot_checkver:                       ; 30 = check DOS version
198                 ; We return 0 in all DOS-compatible version registers,
199                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
200                 mov eax,'SY' << 16
201                 mov ebx,'SL' << 16
202                 mov ecx,'IN' << 16
203                 mov edx,'UX' << 16
204                 ;jmp comboot_resume_ok
205
206 ;
207 ; Resume comboot execution
208 ;
209 comboot_resume_ok:
210                 clc
211 comboot_resume:
212                 pop ds
213                 iret
214
215 comboot_apierr:
216                 stc
217                 jmp comboot_resume
218
219 ;
220 ; INT 22h - SYSLINUX-specific system calls
221 ;           System call number in ax
222 ;
223 comboot_int22:
224                 push ds
225                 push cs
226                 pop ds
227
228                 cmp ax,int22_count
229                 jb .ok
230                 xor ax,ax                       ; Function 0 -> unimplemented
231 .ok:
232                 xchg ax,bx
233                 add bx,bx
234                 call [bx+int22_table]
235                 jmp comboot_resume              ; On return
236
237 ;
238 ; INT 22h AX=0000h      Unimplemented call
239 ;
240 comapi_err:
241                 stc
242                 ret
243
244 ;
245 ; INT 22h AX=0001h      Get SYSLINUX version
246 ;
247 comapi_get_version:
248                 ; Number of API functions supported
249                 mov ax,int22_count
250                 ; SYSLINUX version
251                 mov cx,(VER_MAJOR << 8)+VER_MINOR
252                 ; SYSLINUX derivative ID byte
253                 mov dx,my_id
254                 ; For future use
255                 xor bx,bx
256
257                 push cs
258                 pop es
259                 ; ES:SI -> version banner
260                 mov si,syslinux_banner
261                 ; ES:DI -> copyright string
262                 mov di,copyright_str
263
264 comapi_nop:
265                 clc
266                 ret
267
268 ;
269 ; INT 22h AX=0002h      Write string
270 ;
271 ; Write null-terminated string in ES:BX
272 ;
273 comapi_writestr:
274                 push es
275                 pop ds
276                 mov si,ax
277                 jmp writestr                    ; Write string from ES:BX
278
279 ;
280 ; INT 22h AX=0003h      Run command
281 ;
282 ; Terminates the COMBOOT program and executes the command line in
283 ; ES:BX as if it had been entered by the user.
284 ;
285 comapi_run:
286                 push es
287                 push ds
288                 pop es
289                 pop ds
290                 mov si,ax
291                 mov di,command_line
292 .copyloop:
293                 lodsb
294                 stosb
295                 and al,al
296                 jnz .copyloop
297                 xor ax,ax
298                 mov bx,load_kernel              ; Run a new kernel
299                 jmp comboot_exit_special        ; Terminate task, clean up
300
301 ;
302 ; INT 22h AX=0004h      Run default command             
303 ;
304 ; Terminates the COMBOOT program and executes the default command line
305 ; as if a timeout had happened or the user pressed <Enter>.
306 ;
307 comapi_run_default:
308                 mov bx,auto_boot
309                 jmp comboot_exit_special
310
311 ;
312 ; INT 22h AX=0005h      Force text mode
313 ;
314 ; Puts the video in standard text mode
315 ;
316 comapi_textmode:
317                 call vgaclearmode
318                 clc
319                 ret
320
321 ;
322 ; INT 22h AX=0006h      Open file
323 ;
324 comapi_open:
325                 push ds
326                 push ds
327                 push es
328                 pop ds
329                 pop es
330                 mov di,InitRD
331                 push di
332                 call mangle_name
333                 pop di
334                 pop ds
335                 call searchdir
336                 jz .err
337                 xchg eax,edx
338                 shr eax,16
339                 xchg ax,dx
340                 mov cx,[ClustSize]
341                 clc
342                 ret
343 .err:
344                 stc
345                 ret
346
347
348 ;
349 ; INT 22h AX=0007h      Read file
350 ;
351 comapi_read:
352                 xchg ax,bx
353                 call getfssec
354                 jnc .noteof
355                 xor si,si               ; SI <- 0 on EOF, CF <- 0
356 .noteof:        ret
357
358 ;
359 ; INT 22h AX=0008h      Close file
360 ;
361 comapi_close:
362                 ; Do nothing for now.  Eventually implement
363                 ; an internal API for this.
364                 clc
365                 ret
366
367 ;
368 ; INT 22h AX=0009h      Call PXE stack
369 ;
370 %if IS_PXELINUX
371 comapi_pxecall:
372                 call far [PXENVEntry]
373                 clc
374                 ret
375 %else
376 comapi_pxecall  equ comapi_err                  ; Not available
377 %endif
378
379                 align 2, db 0
380 int22_table:
381                 dw comapi_err                   ; 0000 unimplemented syscall
382                 dw comapi_get_version           ; 0001 get SYSLINUX version
383                 dw comapi_writestr              ; 0002 write string
384                 dw comapi_run                   ; 0003 run specified command
385                 dw comapi_run_default           ; 0004 run default command
386                 dw comapi_textmode              ; 0005 force text mode
387                 dw comapi_open                  ; 0006 open file
388                 dw comapi_read                  ; 0007 read file
389                 dw comapi_close                 ; 0008 close file
390                 dw comapi_pxecall               ; 0009 call PXE stack
391 int22_count     equ ($-int22_table)/2