2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2005 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 ;; Boston 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
22 ; Parameter registers definition; this is the definition
23 ; of the stack frame used by INT 21h and INT 22h.
24 %define P_FLAGS word [bp+44]
25 %define P_FLAGSL byte [bp+44]
26 %define P_FLAGSH byte [bp+45]
27 %define P_CS word [bp+42]
28 %define P_IP word [bp+40]
29 %define P_DS word [bp+38]
30 %define P_ES word [bp+36]
31 %define P_FS word [bp+34]
32 %define P_GS word [bp+32]
33 %define P_EAX dword [bp+28]
34 %define P_AX word [bp+28]
35 %define P_HAX word [bp+30]
36 %define P_AL byte [bp+28]
37 %define P_AH byte [bp+29]
38 %define P_ECX dword [bp+24]
39 %define P_CX word [bp+24]
40 %define P_HCX word [bp+26]
41 %define P_CL byte [bp+24]
42 %define P_CH byte [bp+25]
43 %define P_EDX dword [bp+20]
44 %define P_DX word [bp+20]
45 %define P_HDX word [bp+22]
46 %define P_DL byte [bp+20]
47 %define P_DH byte [bp+21]
48 %define P_EBX dword [bp+16]
49 %define P_BX word [bp+16]
50 %define P_HBX word [bp+18]
51 %define P_BL byte [bp+16]
52 %define P_BH byte [bp+17]
53 %define P_EBP dword [bp+8]
54 %define P_BP word [bp+8]
55 %define P_HBP word [bp+10]
56 %define P_ESI dword [bp+4]
57 %define P_SI word [bp+4]
58 %define P_HSI word [bp+6]
59 %define P_EDI dword [bp]
60 %define P_DI word [bp]
61 %define P_HDI word [bp+2]
63 ; Looks like a COMBOOT image but too large
70 ; Load a COMBOOT image. A COMBOOT image is basically a DOS .COM file,
71 ; except that it may, of course, not contain any DOS system calls. We
72 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
77 cmp ax,0ff00h ; Max size in bytes
80 push si ; Save file handle
82 call make_plain_cmdline
84 call comboot_setup_api
90 mov cx,64 ; 256 bytes (size of PSP)
91 xor eax,eax ; Clear PSP
94 mov word [es:0], 020CDh ; INT 20h instruction
95 ; First non-free paragraph
96 ; This is valid because comboot_seg == real_mode_seg
97 ; == the highest segment used by all derivatives
98 int 12h ; Get DOS memory size
99 shl ax,6 ; Kilobytes -> paragraphs
103 %if real_mode_seg != comboot_seg
104 %error "This code assumes real_mode_seg == comboot_seg"
107 ; Copy the command line from high memory
109 mov cx,125 ; Max cmdline len (minus space and CR)
110 mov di,081h ; Offset in PSP for command line
111 mov al,' ' ; DOS command lines begin with a space
121 mov al,0Dh ; CR after last character
124 sub al,82h ; Include space but not CR
125 mov [es:80h],al ; Store command line length
127 ; Now actually load the file...
129 mov bx,100h ; Load at <seg>:0100h
130 mov cx,0FF00h >> SECTOR_SHIFT
131 ; Absolute maximum # of sectors
134 ; And invoke the program...
136 mov [SavedSSSP+2],ss ; Save away SS:SP
142 push word 0 ; Return to address 0 -> exit
144 jmp comboot_seg:100h ; Run it
146 ; Proper return vector
147 comboot_return: cli ; Don't trust anyone
152 ; Set up the COMBOOT API interrupt vectors. This is also used
156 mov di,4*0x20 ; DOS interrupt vectors
157 mov eax,comboot_return ; INT 20h = exit
159 mov ax,comboot_int21 ; INT 21h = DOS-compatible syscalls
161 mov ax,comboot_int22 ; INT 22h = proprietary syscalls
164 mov cx,29 ; All remaining DOS vectors
168 ; INT 21h: generic DOS system call
179 mov bp,sp ; Set up stack frame
181 call adjust_screen ; The COMBOOT program might have changed the screen
189 ; The last function in the list is the
190 ; "no such function" function
192 call ax ; Call the invoked function
194 setc P_FLAGSL ; Propagate CF->error
202 ; Attempted to execute non-21h DOS system call
203 comboot_bogus: cli ; Don't trust anyone
206 ; Generic COMBOOT return to command line code
207 ; AX -> message (if any)
208 ; BX -> where to go next
211 mov bx,enter_command ; Normal return to command prompt
212 comboot_exit_special:
219 call adjust_screen ; The COMBOOT program might have changed the screen
229 ; INT 21h system calls
231 comboot_getkey: ; 01 = get key with echo
239 comboot_writechr: ; 02 = writechr
245 comboot_writeserial: ; 04 = write serial port
251 comboot_getkeynoecho: ; 08 = get key w/o echo
256 comboot_writestr: ; 09 = write DOS string
260 cmp al,'$' ; End string with $ - bizarre
267 comboot_checkkey: ; 0B = check keyboard status
268 cmp byte [APIKeyFlag],00h
272 dec al ; AL = 0FFh if present, 0 if not
277 comboot_checkver: ; 30 = check DOS version
278 ; We return 0 in all DOS-compatible version registers,
279 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
287 cmp byte [APIKeyFlag],00h
289 call getchar ; If not queued get input
290 and al,al ; Function key? (CF <- 0)
292 mov [APIKeyWait],ah ; High part of key
293 inc byte [APIKeyFlag] ; Set flag
296 .queued: mov al,[APIKeyWait]
297 dec byte [APIKeyFlag]
301 ; INT 22h - SYSLINUX-specific system calls
302 ; System call number in ax
315 mov bp,sp ; Set up stack frame
317 call adjust_screen ; The COMBOOT program might have changed the screen
321 xor ax,ax ; Function 0 -> unimplemented
325 call [bx+int22_table]
326 jmp comboot_resume ; On return
329 ; INT 22h AX=0000h Unimplemented call
336 ; INT 22h AX=0001h Get SYSLINUX version
339 ; Number of API functions supported
342 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
343 ; SYSLINUX derivative ID byte
346 mov P_BX,cs ; cs == 0
349 ; ES:SI -> version banner
350 mov P_SI,syslinux_banner
351 ; ES:DI -> copyright string
352 mov P_DI,copyright_str
359 ; INT 22h AX=0002h Write string
361 ; Write null-terminated string in ES:BX
371 ; INT 22h AX=0003h Run command
373 ; Terminates the COMBOOT program and executes the command line in
374 ; ES:BX as if it had been entered by the user.
382 mov bx,load_kernel ; Run a new kernel
383 jmp comboot_exit_special ; Terminate task, clean up
386 ; INT 22h AX=0004h Run default command
388 ; Terminates the COMBOOT program and executes the default command line
389 ; as if a timeout had happened or the user pressed <Enter>.
393 jmp comboot_exit_special
396 ; INT 22h AX=0005h Force text mode
398 ; Puts the video in standard text mode
406 ; INT 22h AX=0006h Open file
427 ; INT 22h AX=0007h Read file
436 xor si,si ; SI <- 0 on EOF, CF <- 0
441 ; INT 22h AX=0008h Close file
444 ; Do nothing for now. Eventually implement
445 ; an internal API for this.
450 ; INT 22h AX=0009h Call PXE stack
462 comapi_pxecall equ comapi_err ; Not available
466 ; INT 22h AX=000Ah Get Derivative-Specific Info
470 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
496 ; INT 22h AX=000Bh Get Serial Console Configuration
507 test byte [DisplayCon],01h
516 ; INT 22h AX=000Ch Perform final cleanup
520 ; Unload PXE if requested
523 sub bp,sp ; unload_pxe may move the stack around
525 add bp,sp ; restore frame pointer...
526 %elif IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
527 ; Restore original FDC table
528 mov eax,[OrigFDCTabPtr]
531 ; Reset the floppy disk subsystem
539 ; INT 22h AX=000Dh Clean up then replace bootstrap
544 mov [trackbuf+4],eax ; Copy from
546 mov [trackbuf+8],eax ; Total bytes
548 mov [trackbuf],eax ; Copy to
549 mov [EntryPoint],eax ; CS:IP entry point
553 jmp replace_bootstrap_one
557 ; INT 22h AX=000Eh Get configuration file name
566 ; INT 22h AX=000Fh Get IPAPPEND strings
571 mov P_CX,numIPAppends
578 IPAppends dw IPOption
580 numIPAppends equ ($-IPAppends)/2
583 comapi_ipappend equ comapi_err
589 ; INT 22h AX=0010h Resolve hostname
599 comapi_dnsresolv equ comapi_err
605 ; INT 22h AX=0011h Maximum number of shuffle descriptors
608 mov P_CX,(2*trackbufsize)/12
612 ; INT 22h AX=0012h Cleanup, shuffle and boot
617 cmp cx,(2*trackbufsize)/12
620 push cx ; On stack: descriptor count
622 lea cx,[ecx+ecx*2] ; CX *= 3
627 push di ; On stack: descriptor list address
628 fs rep movsd ; Copy the list
631 mov [EntryPoint],eax ; CS:IP entry point
635 jmp replace_bootstrap
641 ; INT 22h AX=0013h Idle call
645 ; The idle call seems to have detrimental effects on some machines when
646 ; called from a COM32 context (WHY?) -- disable it for now.
648 %if 0 ; def HAVE_IDLE
657 comapi_idle equ comapi_err
662 ; INT 22h AX=0014h Local boot
664 %if IS_PXELINUX || IS_ISOLINUX
669 comapi_localboot equ comapi_err
673 ; INT 22h AX=0015h Feature flags
677 mov P_BX,feature_flags
678 mov P_CX,feature_flags_len
683 ; INT 22h AX=0016h Run kernel image
697 ; The kernel image was found, so we can load it...
700 mov [Kernel_EAX+2],dx
702 ; It's not just possible, but quite likely, that ES:BX
703 ; points into real_mode_seg, so we need to exercise some
704 ; special care here... use xfer_buf_seg as an intermediary
723 jmp comboot_exit_special
726 ; Copy the command line into its proper place
736 mov byte [es:di-1],' ' ; Simulate APPEND
740 mov word [CmdOptPtr],zero_string
741 jmp kernel_good_saved
751 int21 00h, comboot_return
752 int21 01h, comboot_getkey
753 int21 02h, comboot_writechr
754 int21 04h, comboot_writeserial
755 int21 08h, comboot_getkeynoecho
756 int21 09h, comboot_writestr
757 int21 0Bh, comboot_checkkey
758 int21 30h, comboot_checkver
759 int21 4Ch, comboot_return
760 int21 -1, comboot_bogus
761 int21_count equ ($-int21_table)/3
765 dw comapi_err ; 0000 unimplemented syscall
766 dw comapi_get_version ; 0001 get SYSLINUX version
767 dw comapi_writestr ; 0002 write string
768 dw comapi_run ; 0003 run specified command
769 dw comapi_run_default ; 0004 run default command
770 dw comapi_textmode ; 0005 force text mode
771 dw comapi_open ; 0006 open file
772 dw comapi_read ; 0007 read file
773 dw comapi_close ; 0008 close file
774 dw comapi_pxecall ; 0009 call PXE stack
775 dw comapi_derinfo ; 000A derivative-specific info
776 dw comapi_serialcfg ; 000B get serial port config
777 dw comapi_cleanup ; 000C perform final cleanup
778 dw comapi_chainboot ; 000D clean up then bootstrap
779 dw comapi_configfile ; 000E get name of config file
780 dw comapi_ipappend ; 000F get ipappend strings
781 dw comapi_dnsresolv ; 0010 resolve hostname
782 dw comapi_maxshuffle ; 0011 maximum shuffle descriptors
783 dw comapi_shuffle ; 0012 cleanup, shuffle and boot
784 dw comapi_idle ; 0013 idle call
785 dw comapi_localboot ; 0014 local boot
786 dw comapi_features ; 0015 feature flags
787 dw comapi_runkernel ; 0016 run kernel image
788 int22_count equ ($-int22_table)/2
793 zero_string db 0 ; Empty, null-terminated string
796 ; This is the feature flag array for INT 22h AX=0015h
799 db 1 ; Have local boot, idle not noop
801 db 3 ; Have local boot, idle is noop
803 db 2 ; No local boot, idle is noop
805 feature_flags_len equ ($-feature_flags)