1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2006 H. Peter Anvin - All Rights Reserved
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;; (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
16 ;; Common code for running a COMBOOT image
21 ; Parameter registers definition; this is the definition
22 ; of the stack frame used by INT 21h and INT 22h.
23 %define P_FLAGS word [bp+44]
24 %define P_FLAGSL byte [bp+44]
25 %define P_FLAGSH byte [bp+45]
26 %define P_CS word [bp+42]
27 %define P_IP word [bp+40]
28 %define P_DS word [bp+38]
29 %define P_ES word [bp+36]
30 %define P_FS word [bp+34]
31 %define P_GS word [bp+32]
32 %define P_EAX dword [bp+28]
33 %define P_AX word [bp+28]
34 %define P_HAX word [bp+30]
35 %define P_AL byte [bp+28]
36 %define P_AH byte [bp+29]
37 %define P_ECX dword [bp+24]
38 %define P_CX word [bp+24]
39 %define P_HCX word [bp+26]
40 %define P_CL byte [bp+24]
41 %define P_CH byte [bp+25]
42 %define P_EDX dword [bp+20]
43 %define P_DX word [bp+20]
44 %define P_HDX word [bp+22]
45 %define P_DL byte [bp+20]
46 %define P_DH byte [bp+21]
47 %define P_EBX dword [bp+16]
48 %define P_BX word [bp+16]
49 %define P_HBX word [bp+18]
50 %define P_BL byte [bp+16]
51 %define P_BH byte [bp+17]
52 %define P_EBP dword [bp+8]
53 %define P_BP word [bp+8]
54 %define P_HBP word [bp+10]
55 %define P_ESI dword [bp+4]
56 %define P_SI word [bp+4]
57 %define P_HSI word [bp+6]
58 %define P_EDI dword [bp]
59 %define P_DI word [bp]
60 %define P_HDI word [bp+2]
62 ; Looks like a COMBOOT image but too large
69 ; Load a COMBOOT image. A COMBOOT image is basically a DOS .COM file,
70 ; except that it may, of course, not contain any DOS system calls. We
71 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
76 cmp ax,0ff00h ; Max size in bytes
79 push si ; Save file handle
81 call make_plain_cmdline
83 call comboot_setup_api
89 mov cx,64 ; 256 bytes (size of PSP)
90 xor eax,eax ; Clear PSP
93 mov word [es:0], 020CDh ; INT 20h instruction
94 ; First non-free paragraph
95 ; This is valid because comboot_seg == real_mode_seg
96 ; == the highest segment used by all derivatives
97 int 12h ; Get DOS memory size
98 shl ax,6 ; Kilobytes -> paragraphs
102 %if real_mode_seg != comboot_seg
103 %error "This code assumes real_mode_seg == comboot_seg"
106 ; Copy the command line from high memory
108 mov cx,125 ; Max cmdline len (minus space and CR)
109 mov di,081h ; Offset in PSP for command line
110 mov al,' ' ; DOS command lines begin with a space
120 mov al,0Dh ; CR after last character
123 sub al,82h ; Include space but not CR
124 mov [es:80h],al ; Store command line length
126 ; Now actually load the file...
128 mov bx,100h ; Load at <seg>:0100h
129 mov cx,0FF00h >> SECTOR_SHIFT
130 ; Absolute maximum # of sectors
133 ; And invoke the program...
138 push word 0 ; Return to address 0 -> exit
140 jmp comboot_seg:100h ; Run it
142 ; Proper return vector
143 comboot_return: cli ; Don't trust anyone
144 push enter_command ; Normal return to command prompt
148 ; Set up the COMBOOT API interrupt vectors. This is also used
152 mov di,4*0x20 ; DOS interrupt vectors
153 mov eax,comboot_return ; INT 20h = exit
155 mov ax,comboot_int21 ; INT 21h = DOS-compatible syscalls
157 mov ax,comboot_int22 ; INT 22h = proprietary syscalls
160 mov cx,29 ; All remaining DOS vectors
164 ; INT 21h: generic DOS system call
175 mov bp,sp ; Set up stack frame
177 call adjust_screen ; The COMBOOT program might have changed the screen
185 ; The last function in the list is the
186 ; "no such function" function
188 call ax ; Call the invoked function
190 setc P_FLAGSL ; Propagate CF->error
198 ; Attempted to execute non-21h DOS system call
199 comboot_bogus: cli ; Don't trust anyone
205 ; Generic COMBOOT return to command line code
206 ; stack -> where to go next
207 ; CX -> message (for _msg version)
212 pop bx ; Return address
213 RESET_STACK_AND_SEGS AX
214 call adjust_screen ; The COMBOOT program might have changed the screen
224 ; INT 21h system calls
226 comboot_getkey: ; 01 = get key with echo
234 comboot_writechr: ; 02 = writechr
240 comboot_writeserial: ; 04 = write serial port
246 comboot_getkeynoecho: ; 08 = get key w/o echo
251 comboot_writestr: ; 09 = write DOS string
255 cmp al,'$' ; End string with $ - bizarre
262 comboot_checkkey: ; 0B = check keyboard status
263 cmp byte [APIKeyFlag],00h
267 dec al ; AL = 0FFh if present, 0 if not
272 comboot_checkver: ; 30 = check DOS version
273 ; We return 0 in all DOS-compatible version registers,
274 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
282 cmp byte [APIKeyFlag],00h
284 call getchar ; If not queued get input
285 and al,al ; Function key? (CF <- 0)
287 mov [APIKeyWait],ah ; High part of key
288 inc byte [APIKeyFlag] ; Set flag
291 .queued: mov al,[APIKeyWait]
292 dec byte [APIKeyFlag]
296 ; INT 22h - SYSLINUX-specific system calls
297 ; System call number in ax
310 mov bp,sp ; Set up stack frame
312 call adjust_screen ; The COMBOOT program might have changed the screen
316 xor ax,ax ; Function 0 -> unimplemented
320 call [bx+int22_table]
321 jmp comboot_resume ; On return
324 ; INT 22h AX=0000h Unimplemented call
331 ; INT 22h AX=0001h Get SYSLINUX version
334 ; Number of API functions supported
337 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
338 ; SYSLINUX derivative ID byte
341 mov P_BX,cs ; cs == 0
344 ; ES:SI -> version banner
345 mov P_SI,syslinux_banner
346 ; ES:DI -> copyright string
347 mov P_DI,copyright_str
354 ; INT 22h AX=0002h Write string
356 ; Write null-terminated string in ES:BX
366 ; INT 22h AX=0003h Run command
368 ; Terminates the COMBOOT program and executes the command line in
369 ; ES:BX as if it had been entered by the user.
376 push load_kernel ; Run a new kernel
377 jmp comboot_exit ; Terminate task, clean up
380 ; INT 22h AX=0004h Run default command
382 ; Terminates the COMBOOT program and executes the default command line
383 ; as if a timeout had happened or the user pressed <Enter>.
390 ; INT 22h AX=0005h Force text mode
392 ; Puts the video in standard text mode
400 ; INT 22h AX=0006h Open file
421 ; INT 22h AX=0007h Read file
430 xor si,si ; SI <- 0 on EOF, CF <- 0
435 ; INT 22h AX=0008h Close file
438 ; Do nothing for now. Eventually implement
439 ; an internal API for this.
444 ; INT 22h AX=0009h Call PXE stack
456 comapi_pxecall equ comapi_err ; Not available
460 ; INT 22h AX=000Ah Get Derivative-Specific Info
464 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
469 mov P_CL,SECTOR_SHIFT
486 mov P_CL,SECTOR_SHIFT
492 ; INT 22h AX=000Bh Get Serial Console Configuration
503 test byte [DisplayCon],01h
512 ; INT 22h AX=000Ch Perform final cleanup
516 ; Unload PXE if requested
519 sub bp,sp ; unload_pxe may move the stack around
521 add bp,sp ; restore frame pointer...
522 %elif IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
523 ; Restore original FDC table
524 mov eax,[OrigFDCTabPtr]
527 ; Reset the floppy disk subsystem
535 ; INT 22h AX=000Dh Clean up then replace bootstrap
540 mov [trackbuf+4],eax ; Copy from
542 mov [trackbuf+8],eax ; Total bytes
544 mov [trackbuf],eax ; Copy to
545 mov [EntryPoint],eax ; CS:IP entry point
549 jmp replace_bootstrap_one
553 ; INT 22h AX=000Eh Get configuration file name
562 ; INT 22h AX=000Fh Get IPAPPEND strings
567 mov P_CX,numIPAppends
574 IPAppends dw IPOption
576 numIPAppends equ ($-IPAppends)/2
579 comapi_ipappend equ comapi_err
585 ; INT 22h AX=0010h Resolve hostname
595 comapi_dnsresolv equ comapi_err
601 ; INT 22h AX=0011h Maximum number of shuffle descriptors
604 mov P_CX,(2*trackbufsize)/12
608 ; INT 22h AX=0012h Cleanup, shuffle and boot
613 cmp cx,(2*trackbufsize)/12
616 push cx ; On stack: descriptor count
618 lea cx,[ecx+ecx*2] ; CX *= 3
623 push di ; On stack: descriptor list address
624 fs rep movsd ; Copy the list
627 mov [EntryPoint],eax ; CS:IP entry point
631 jmp replace_bootstrap
637 ; INT 22h AX=0013h Idle call
641 ; The idle call seems to have detrimental effects on some machines when
642 ; called from a COM32 context (WHY?) -- disable it for now.
644 %if 0 ; def HAVE_IDLE
653 comapi_idle equ comapi_err
658 ; INT 22h AX=0014h Local boot
660 %if IS_PXELINUX || IS_ISOLINUX
665 comapi_localboot equ comapi_err
669 ; INT 22h AX=0015h Feature flags
673 mov P_BX,feature_flags
674 mov P_CX,feature_flags_len
679 ; INT 22h AX=0016h Run kernel image
693 ; The kernel image was found, so we can load it...
696 mov [Kernel_EAX+2],dx
698 ; It's not just possible, but quite likely, that ES:BX
699 ; points into real_mode_seg, so we need to exercise some
700 ; special care here... use xfer_buf_seg as an intermediary
720 ; Copy the command line into its proper place
730 mov byte [es:di-1],' ' ; Simulate APPEND
734 mov word [CmdOptPtr],zero_string
735 jmp kernel_good_saved
738 ; INT 22h AX=0017h Report video mode change
742 cmp ax,0Fh ; Unknown flags = failure
760 ; INT 22h AX=0018h Query custom font
775 ; INT 22h AX=0019h Read disk
777 %if IS_SYSLINUX || IS_MDSLINUX || IS_ISOLINUX || IS_EXTLINUX
779 mov esi,P_ESI ; Enforce ESI == EDI == 0, these
780 or esi,P_EDI ; are reserved for future expansion
793 comapi_readdisk equ comapi_err
804 int21 00h, comboot_return
805 int21 01h, comboot_getkey
806 int21 02h, comboot_writechr
807 int21 04h, comboot_writeserial
808 int21 08h, comboot_getkeynoecho
809 int21 09h, comboot_writestr
810 int21 0Bh, comboot_checkkey
811 int21 30h, comboot_checkver
812 int21 4Ch, comboot_return
813 int21 -1, comboot_bogus
814 int21_count equ ($-int21_table)/3
818 dw comapi_err ; 0000 unimplemented syscall
819 dw comapi_get_version ; 0001 get SYSLINUX version
820 dw comapi_writestr ; 0002 write string
821 dw comapi_run ; 0003 run specified command
822 dw comapi_run_default ; 0004 run default command
823 dw comapi_textmode ; 0005 force text mode
824 dw comapi_open ; 0006 open file
825 dw comapi_read ; 0007 read file
826 dw comapi_close ; 0008 close file
827 dw comapi_pxecall ; 0009 call PXE stack
828 dw comapi_derinfo ; 000A derivative-specific info
829 dw comapi_serialcfg ; 000B get serial port config
830 dw comapi_cleanup ; 000C perform final cleanup
831 dw comapi_chainboot ; 000D clean up then bootstrap
832 dw comapi_configfile ; 000E get name of config file
833 dw comapi_ipappend ; 000F get ipappend strings
834 dw comapi_dnsresolv ; 0010 resolve hostname
835 dw comapi_maxshuffle ; 0011 maximum shuffle descriptors
836 dw comapi_shuffle ; 0012 cleanup, shuffle and boot
837 dw comapi_idle ; 0013 idle call
838 dw comapi_localboot ; 0014 local boot
839 dw comapi_features ; 0015 feature flags
840 dw comapi_runkernel ; 0016 run kernel image
841 dw comapi_usingvga ; 0017 report video mode change
842 dw comapi_userfont ; 0018 query custom font
843 dw comapi_readdisk ; 0019 read disk
844 int22_count equ ($-int22_table)/2
849 zero_string db 0 ; Empty, null-terminated string
852 ; This is the feature flag array for INT 22h AX=0015h
855 db 1 ; Have local boot, idle not noop
857 db 3 ; Have local boot, idle is noop
859 db 2 ; No local boot, idle is noop
861 feature_flags_len equ ($-feature_flags)