2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2003 H. Peter Anvin - All Rights Reserved
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.
12 ;; -----------------------------------------------------------------------
17 ;; Common code for running a COMBOOT image
20 ; Parameter registers definition; this is the definition
21 ; of the stack frame used by INT 21h and INT 22h.
22 %define P_FLAGS word [bp+44]
23 %define P_FLAGSL byte [bp+44]
24 %define P_FLAGSH byte [bp+45]
25 %define P_CS word [bp+42]
26 %define P_IP word [bp+40]
27 %define P_DS word [bp+38]
28 %define P_ES word [bp+36]
29 %define P_FS word [bp+34]
30 %define P_GS word [bp+32]
31 %define P_EAX dword [bp+28]
32 %define P_AX word [bp+28]
33 %define P_HAX word [bp+30]
34 %define P_AL byte [bp+28]
35 %define P_AH byte [bp+29]
36 %define P_ECX dword [bp+24]
37 %define P_CX word [bp+24]
38 %define P_HCX word [bp+26]
39 %define P_CL byte [bp+24]
40 %define P_CH byte [bp+25]
41 %define P_EDX dword [bp+20]
42 %define P_DX word [bp+20]
43 %define P_HDX word [bp+22]
44 %define P_DL byte [bp+20]
45 %define P_DH byte [bp+21]
46 %define P_EBX dword [bp+16]
47 %define P_BX word [bp+16]
48 %define P_HBX word [bp+18]
49 %define P_BL byte [bp+16]
50 %define P_BH byte [bp+17]
51 %define P_EBP dword [bp+8]
52 %define P_BP word [bp+8]
53 %define P_HBP word [bp+10]
54 %define P_ESI dword [bp+4]
55 %define P_SI word [bp+4]
56 %define P_HSI word [bp+6]
57 %define P_EDI dword [bp]
58 %define P_DI word [bp]
59 %define P_HDI word [bp+2]
61 ; Looks like a COMBOOT image but too large
68 ; Load a COMBOOT image. A COMBOOT image is basically a DOS .COM file,
69 ; except that it may, of course, not contain any DOS system calls. We
70 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
75 cmp ax,0ff00h ; Max size in bytes
78 push si ; Save file handle
80 call make_plain_cmdline
82 call comboot_setup_api
88 mov cx,64 ; 256 bytes (size of PSP)
89 xor eax,eax ; Clear PSP
92 mov word [es:0], 020CDh ; INT 20h instruction
93 ; First non-free paragraph
94 ; This is valid because comboot_seg == real_mode_seg
95 ; == the highest segment used by all derivatives
96 int 12h ; Get DOS memory size
97 shl ax,6 ; Kilobytes -> paragraphs
101 %if real_mode_seg != comboot_seg
102 %error "This code assumes real_mode_seg == comboot_seg"
105 ; Copy the command line from high memory
107 mov cx,125 ; Max cmdline len (minus space and CR)
108 mov di,081h ; Offset in PSP for command line
109 mov al,' ' ; DOS command lines begin with a space
119 mov al,0Dh ; CR after last character
122 sub al,82h ; Include space but not CR
123 mov [es:80h],al ; Store command line length
125 ; Now actually load the file...
127 mov bx,100h ; Load at <seg>:0100h
128 mov cx,[ClustPerMoby] ; Absolute maximum # of clusters
131 ; And invoke the program...
133 mov [SavedSSSP+2],ss ; Save away SS:SP
139 push word 0 ; Return to address 0 -> exit
141 jmp comboot_seg:100h ; Run it
143 ; Proper return vector
144 comboot_return: cli ; Don't trust anyone
149 ; Set up the COMBOOT API interrupt vectors. This is also used
153 mov di,4*0x20 ; DOS interrupt vectors
154 mov eax,comboot_return ; INT 20h = exit
156 mov ax,comboot_int21 ; INT 21h = DOS-compatible syscalls
158 mov ax,comboot_int22 ; INT 22h = proprietary syscalls
161 mov cx,29 ; All remaining DOS vectors
165 ; INT 21h: generic DOS system call
176 mov bp,sp ; Set up stack frame
178 call adjust_screen ; The COMBOOT program might have changed the screen
186 ; The last function in the list is the
187 ; "no such function" function
189 call ax ; Call the invoked function
191 setc P_FLAGSL ; Propagate CF->error
199 ; Attempted to execute non-21h DOS system call
200 comboot_bogus: cli ; Don't trust anyone
203 ; Generic COMBOOT return to command line code
204 ; AX -> message (if any)
205 ; BX -> where to go next
208 mov bx,enter_command ; Normal return to command prompt
209 comboot_exit_special:
216 call adjust_screen ; The COMBOOT program might have changed the screen
226 ; INT 21h system calls
228 comboot_getkey: ; 01 = get key with echo
236 comboot_writechr: ; 02 = writechr
242 comboot_writeserial: ; 04 = write serial port
248 comboot_getkeynoecho: ; 08 = get key w/o echo
253 comboot_writestr: ; 09 = write string
257 cmp al,'$' ; End string with $ - bizarre
264 comboot_checkkey: ; 0B = check keyboard status
265 cmp byte [APIKeyFlag],00h
269 dec al ; AL = 0FFh if present, 0 if not
274 comboot_checkver: ; 30 = check DOS version
275 ; We return 0 in all DOS-compatible version registers,
276 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
285 cmp byte [APIKeyFlag],00h
287 call getchar ; If not queued get input
288 and al,al ; Function key?
290 mov [APIKeyWait],ah ; High part of key
291 inc byte [APIKeyFlag] ; Set flag
294 .queued: mov al,[APIKeyWait]
295 dec byte [APIKeyFlag]
299 ; INT 22h - SYSLINUX-specific system calls
300 ; System call number in ax
313 mov bp,sp ; Set up stack frame
315 call adjust_screen ; The COMBOOT program might have changed the screen
319 xor ax,ax ; Function 0 -> unimplemented
323 call [bx+int22_table]
324 jmp comboot_resume ; On return
327 ; INT 22h AX=0000h Unimplemented call
334 ; INT 22h AX=0001h Get SYSLINUX version
337 ; Number of API functions supported
340 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
341 ; SYSLINUX derivative ID byte
344 mov P_BX,cs ; cs == 0
347 ; ES:SI -> version banner
348 mov P_SI,syslinux_banner
349 ; ES:DI -> copyright string
350 mov P_DI,copyright_str
357 ; INT 22h AX=0002h Write string
359 ; Write null-terminated string in ES:BX
369 ; INT 22h AX=0003h Run command
371 ; Terminates the COMBOOT program and executes the command line in
372 ; ES:BX as if it had been entered by the user.
384 mov bx,load_kernel ; Run a new kernel
385 jmp comboot_exit_special ; Terminate task, clean up
388 ; INT 22h AX=0004h Run default command
390 ; Terminates the COMBOOT program and executes the default command line
391 ; as if a timeout had happened or the user pressed <Enter>.
395 jmp comboot_exit_special
398 ; INT 22h AX=0005h Force text mode
400 ; Puts the video in standard text mode
408 ; INT 22h AX=0006h Open file
434 ; INT 22h AX=0007h Read file
443 xor si,si ; SI <- 0 on EOF, CF <- 0
448 ; INT 22h AX=0008h Close file
451 ; Do nothing for now. Eventually implement
452 ; an internal API for this.
457 ; INT 22h AX=0009h Call PXE stack
469 comapi_pxecall equ comapi_err ; Not available
473 ; INT 22h AX=000Ah Get Derivative-Specific Info
477 %if IS_SYSLINUX || IS_MDSLINUX
478 mov al,[bsDriveNumber]
503 ; INT 22h AX=000Bh Get Serial Console Configuration
519 ; INT 22h AX=000Ch Perform final cleanup
523 ; Unload PXE if requested
526 sub bp,sp ; unload_pxe may move the stack around
528 add bp,sp ; restore frame pointer...
529 %elif IS_SYSLINUX || IS_MDSLINUX
530 ; Restore original FDC table
531 mov eax,[OrigFDCTabPtr]
534 ; Reset the floppy disk subsystem
543 ; INT 22h AX=000Dh Clean up then replace bootstrap
552 jmp replace_bootstrap
555 ; This stuff should really be in the data section...
563 int21 00h, comboot_return
564 int21 01h, comboot_getkey
565 int21 02h, comboot_writechr
566 int21 04h, comboot_writeserial
567 int21 08h, comboot_getkey
568 int21 09h, comboot_writestr
569 int21 0Bh, comboot_checkkey
570 int21 30h, comboot_checkver
571 int21 4Ch, comboot_return
572 int21 -1, comboot_bogus
573 int21_count equ ($-int21_table)/3
577 dw comapi_err ; 0000 unimplemented syscall
578 dw comapi_get_version ; 0001 get SYSLINUX version
579 dw comapi_writestr ; 0002 write string
580 dw comapi_run ; 0003 run specified command
581 dw comapi_run_default ; 0004 run default command
582 dw comapi_textmode ; 0005 force text mode
583 dw comapi_open ; 0006 open file
584 dw comapi_read ; 0007 read file
585 dw comapi_close ; 0008 close file
586 dw comapi_pxecall ; 0009 call PXE stack
587 dw comapi_derinfo ; 000A derivative-specific info
588 dw comapi_serialcfg ; 000B get serial port config
589 dw comapi_cleanup ; 000C perform final cleanup
590 dw comapi_chainboot ; 000D clean up then bootstrap
591 int22_count equ ($-int22_table)/2