1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
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_CSIP dword [bp+40]
30 %define P_DS word [bp+38]
31 %define P_ES word [bp+36]
32 %define P_FS word [bp+34]
33 %define P_GS word [bp+32]
34 %define P_EAX dword [bp+28]
35 %define P_AX word [bp+28]
36 %define P_HAX word [bp+30]
37 %define P_AL byte [bp+28]
38 %define P_AH byte [bp+29]
39 %define P_ECX dword [bp+24]
40 %define P_CX word [bp+24]
41 %define P_HCX word [bp+26]
42 %define P_CL byte [bp+24]
43 %define P_CH byte [bp+25]
44 %define P_EDX dword [bp+20]
45 %define P_DX word [bp+20]
46 %define P_HDX word [bp+22]
47 %define P_DL byte [bp+20]
48 %define P_DH byte [bp+21]
49 %define P_EBX dword [bp+16]
50 %define P_BX word [bp+16]
51 %define P_HBX word [bp+18]
52 %define P_BL byte [bp+16]
53 %define P_BH byte [bp+17]
54 %define P_EBP dword [bp+8]
55 %define P_BP word [bp+8]
56 %define P_HBP word [bp+10]
57 %define P_ESI dword [bp+4]
58 %define P_SI word [bp+4]
59 %define P_HSI word [bp+6]
60 %define P_EDI dword [bp]
61 %define P_DI word [bp]
62 %define P_HDI word [bp+2]
64 ; Looks like a COMBOOT image but too large
72 ; Load a COMBOOT image. A COMBOOT image is basically a DOS .COM file,
73 ; except that it may, of course, not contain any DOS system calls. We
74 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
77 push si ; Save file handle
79 call make_plain_cmdline
81 call comboot_setup_api
87 mov cx,64 ; 256 bytes (size of PSP)
88 xor eax,eax ; Clear PSP
91 mov word [es:0], 020CDh ; INT 20h instruction
92 ; First non-free paragraph
93 ; This is valid because comboot_seg == real_mode_seg
94 ; == the highest segment used by all derivatives
95 int 12h ; Get DOS memory size
96 shl ax,6 ; Kilobytes -> paragraphs
100 %if real_mode_seg != comboot_seg
101 %error "This code assumes real_mode_seg == comboot_seg"
104 ; Copy the command line from high memory
106 mov cx,125 ; Max cmdline len (minus space and CR)
107 mov di,081h ; Offset in PSP for command line
108 mov al,' ' ; DOS command lines begin with a space
118 mov al,0Dh ; CR after last character
121 sub al,82h ; Include space but not CR
122 mov [es:80h],al ; Store command line length
124 ; Now actually load the file...
126 mov bx,100h ; Load at <seg>:0100h
127 mov cx,0FF00h ; Maximum number of bytes
129 cmp ecx,65536-256-2 ; Maximum size
132 ; And invoke the program...
137 push word 0 ; Return to address 0 -> exit
139 jmp comboot_seg:100h ; Run it
142 ; Set up the COMBOOT API interrupt vectors. This is now done at
143 ; initialization time.
146 mov di,DOSErrTramp ; Error trampolines
149 mov eax,02EB206Ah ; push 20h; jmp $+4
155 mov ax,comboot_bogus-2
160 mov si,4*20h ; DOS interrupt vectors
161 mov bx,comboot_vectors
162 mov di,DOSSaveVectors
173 ; Restore the original state of the COMBOOT API vectors, and free
174 ; any low memory allocated by the comboot module.
178 mov si,DOSSaveVectors
181 rep movsd ; Restore DOS-range vectors
187 DOSSaveVectors resd 32
190 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
193 dw comboot_return ; INT 20 = exit
194 dw comboot_int21 ; INT 21 = DOS-compatible system calls
195 dw comboot_int22 ; INT 22 = native system calls
196 dw comboot_err(23h) ; INT 23 = DOS Ctrl-C handler
197 dw comboot_err(24h) ; INT 24 = DOS critical error handler
198 dw comboot_err(25h) ; INT 25 = DOS absolute disk read
199 dw comboot_err(26h) ; INT 26 = DOS absolute disk write
200 dw comboot_err(27h) ; INT 27 = DOS TSR
201 dw comboot_int28 ; INT 28 = DOS idle interrupt
202 dw comboot_int29 ; INT 29 = DOS fast console output
203 dw comboot_err(2Ah) ; INT 2A = DOS network API (NetBIOS)
204 dw comboot_err(2Bh) ; INT 2B = DOS reserved
205 dw comboot_err(2Ch) ; INT 2C = DOS reserved
206 dw comboot_iret ; INT 2D = DOS reserved, AMIS
207 dw comboot_err(2Eh) ; INT 2E = DOS run command
208 dw comboot_iret ; INT 2F = DOS multiplex interrupt
209 dw comboot_err(30h) ; INT 30 = DOS CP/M system calls
210 dw comboot_err(31h) ; INT 31 = DPMI
211 dw comboot_err(32h) ; INT 32 = DOS reserved
212 dw comboot_iret ; INT 33 = DOS mouse API
213 dw comboot_err(34h) ; INT 34 = DOS FPU emulation
214 dw comboot_err(35h) ; INT 35 = DOS FPU emulation
215 dw comboot_err(36h) ; INT 36 = DOS FPU emulation
216 dw comboot_err(37h) ; INT 37 = DOS FPU emulation
217 dw comboot_err(38h) ; INT 38 = DOS FPU emulation
218 dw comboot_err(39h) ; INT 39 = DOS FPU emulation
219 dw comboot_err(3Ah) ; INT 3A = DOS FPU emulation
220 dw comboot_err(3Bh) ; INT 3B = DOS FPU emulation
221 dw comboot_err(3Ch) ; INT 3C = DOS FPU emulation
222 dw comboot_err(3Dh) ; INT 3D = DOS FPU emulation
223 dw comboot_err(3Eh) ; INT 3E = DOS FPU emulation
224 dw comboot_err(3Fh) ; INT 3F = DOS overlay manager
228 ; INT 21h: generic DOS system call
239 mov bp,sp ; Set up stack frame
241 call adjust_screen ; The COMBOOT program might have changed the screen
249 ; The last function in the list is the
250 ; "no such function" function
252 call ax ; Call the invoked function
254 mov bp,sp ; In case the function clobbers BP
255 setc P_FLAGSL ; Propagate CF->error
270 ; Attempted to execute invalid DOS system call
271 ; The interrupt number is on the stack.
272 comboot_bogus: pop dx ; Interrupt number
275 push comboot_bogus_tail
279 call writehex2 ; Interrupt number
283 call writehex4 ; Function number (AX)
287 call writehex8 ; CS:IP of the origin
291 ; Proper return vector
292 ; Note: this gets invoked both via INT 21h and directly via INT 20h.
293 ; We don't need to cld explicitly here, because comboot_exit does that
294 ; when invoking RESET_STACK_AND_SEGS.
296 cli ; May not have a safe stack
297 push enter_command ; Normal return to command prompt
301 ; Generic COMBOOT return to command line code
302 ; stack -> where to go next
303 ; CX -> message (for _msg version)
305 extern comboot_cleanup_lowmem
309 pop bx ; Return address
310 RESET_STACK_AND_SEGS si ; Contains sti, cld
311 pm_call comboot_cleanup_lowmem
312 call adjust_screen ; The COMBOOT program might have changed the screen
322 ; INT 21h system calls
324 comboot_getkey: ; 01 = get key with echo
332 comboot_writechr: ; 02 = writechr
338 comboot_writeserial: ; 04 = write serial port
344 comboot_getkeynoecho: ; 08 = get key w/o echo
349 comboot_writestr: ; 09 = write DOS string
353 cmp al,'$' ; End string with $ - bizarre
360 comboot_checkkey: ; 0B = check keyboard status
361 cmp byte [APIKeyFlag],00h
365 dec al ; AL = 0FFh if present, 0 if not
370 comboot_checkver: ; 30 = check DOS version
371 ; We return 0 in all DOS-compatible version registers,
372 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
380 cmp byte [APIKeyFlag],00h
382 call getchar ; If not queued get input
383 and al,al ; Function key? (CF <- 0)
385 mov [APIKeyWait],ah ; High part of key
386 inc byte [APIKeyFlag] ; Set flag
389 .queued: mov al,[APIKeyWait]
390 dec byte [APIKeyFlag]
403 ; INT 29h - DOS fast write character
408 call writechr ; Preserves registers!
412 ; INT 22h - SYSLINUX-specific system calls
413 ; System call number in ax
426 mov bp,sp ; Set up stack frame
428 call adjust_screen ; The COMBOOT program might have changed the screen
432 xor ax,ax ; Function 0 -> unimplemented
436 call [bx+int22_table]
437 jmp comboot_resume ; On return
440 ; INT 22h AX=0000h Unimplemented call
447 ; INT 22h AX=0001h Get SYSLINUX version
450 ; Number of API functions supported
453 mov P_CX,(VERSION_MAJOR << 8)+VERSION_MINOR
454 ; SYSLINUX derivative ID byte
457 mov P_BX,cs ; cs == 0
460 ; ES:SI -> version banner
461 mov P_SI,syslinux_banner + 2 ; Skip leading CR LF
462 ; ES:DI -> copyright string
463 mov P_DI,copyright_str + 1 ; Skip leading space
470 ; INT 22h AX=0002h Write string
472 ; Write null-terminated string in ES:BX
482 ; INT 22h AX=0003h Run command
484 ; Terminates the COMBOOT program and executes the command line in
485 ; ES:BX as if it had been entered by the user.
492 push load_kernel ; Run a new kernel
493 jmp comboot_exit ; Terminate task, clean up
496 ; INT 22h AX=0004h Run default command
498 ; Terminates the COMBOOT program and executes the default command line
499 ; as if a timeout had happened or the user pressed <Enter>.
506 ; INT 22h AX=0005h Force text mode
508 ; Puts the video in standard text mode
516 ; INT 22h AX=0006h Open file
528 ; INT 22h AX=0007h Read file
537 xor si,si ; SI <- 0 on EOF, CF <- 0
543 ; INT 22h AX=0008h Close file
547 pm_call pm_close_file
552 ; INT 22h AX=0009h Call PXE stack
564 comapi_pxecall equ comapi_err ; Not available
568 ; INT 22h AX=000Ah Get Derivative-Specific Info
583 mov eax,[IPInfo.MyIP]
598 %if IS_SYSLINUX || IS_EXTLINUX
607 mov P_CH,al ; Mode (el torito/cbios/ebios)
614 ; INT 22h AX=000Bh Get Serial Console Configuration
625 test byte [DisplayCon],01h
634 ; INT 22h AX=000Ch Perform final cleanup
638 ; Unload PXE if requested
641 sub bp,sp ; unload_pxe may move the stack around
643 add bp,sp ; restore frame pointer...
644 %elif IS_SYSLINUX || IS_EXTLINUX
645 ; Restore original FDC table
646 mov eax,[OrigFDCTabPtr]
649 call cleanup_hardware
654 ; INT 22h AX=000Dh Clean up then replace bootstrap
659 mov [trackbuf+4],eax ; Copy from
661 mov [trackbuf+8],eax ; Total bytes
663 mov [trackbuf],eax ; Copy to
664 push eax ; Entry point on stack
668 jmp replace_bootstrap_one
671 ; INT 22h AX=000Eh Get configuration file name
680 ; INT 22h AX=000Fh Get IPAPPEND strings
684 mov P_CX,numIPAppends
690 ; INT 22h AX=0010h Resolve hostname
693 extern pxe_dns_resolv
697 pm_call pxe_dns_resolv
702 comapi_dnsresolv equ comapi_err
708 ; INT 22h AX=0011h Obsolete
712 ; INT 22h AX=0012h Obsolete
716 ; INT 22h AX=0013h Idle call
724 ; INT 22h AX=0014h Local boot
731 comapi_localboot equ comapi_err
732 %endif ; HAS_LOCALBOOT
735 ; INT 22h AX=0015h Feature flags
739 mov P_BX,feature_flags
740 mov P_CX,feature_flags_len
745 ; INT 22h AX=0016h Run kernel image
753 ; It's not just possible, but quite likely, that ES:BX
754 ; points into real_mode_seg or xfer_buf_seg, so we
755 ; need to exercise some special care here... use
756 ; VKernelBuf for temporary storage.
768 pm_call pm_mangle_name
773 ; The kernel image was found, so we can load it...
785 ; Copy the command line into its proper place
792 mov word [es:di-1],' ' ; Simulate APPEND: space plus null
795 mov word [CmdOptPtr],zero_string
796 jmp kernel_good_saved
798 .error equ comapi_usingvga.error
801 ; INT 22h AX=0017h Report video mode change
805 cmp ax,0Fh ; Unknown flags = failure
823 ; INT 22h AX=0018h Query custom font
838 ; INT 22h AX=0019h Read disk
840 %if IS_SYSLINUX || IS_ISOLINUX || IS_EXTLINUX
842 cmp P_EDI,0 ; Reserved for future expansion
848 mov bp,P_CX ; WE CANNOT use P_* after touching bp!
856 comapi_readdisk equ comapi_err
860 ; INT 22h AX=001Ah Obsolete
864 ; INT 22h AX=001Bh Obsolete
868 ; INT 22h AX=001Ch Get pointer to auxillary data vector
877 ; INT 22h AX=001Dh Write auxillary data vector
879 comapi_writeadv equ adv_write
882 ; INT 22h AX=001Eh Keyboard remapping table
887 mov P_CX,256 ; Length
896 ; INT 22h AX=001Fh Get current working directory
900 mov P_BX,CurrentDirName
905 ; INT 22h AX=0023h Query shuffler size
908 ; +15 is padding to guarantee alignment
909 mov P_CX,__bcopyxx_len + 15
913 ; INT 22h AX=0024h Cleanup, shuffle and boot raw
920 jmp shuffle_and_boot_raw
930 int21 00h, comboot_return
931 int21 01h, comboot_getkey
932 int21 02h, comboot_writechr
933 int21 04h, comboot_writeserial
934 int21 08h, comboot_getkeynoecho
935 int21 09h, comboot_writestr
936 int21 0Bh, comboot_checkkey
937 int21 30h, comboot_checkver
938 int21 4Ch, comboot_return
939 int21 -1, comboot_bad_int21
940 int21_count equ ($-int21_table)/3
944 dw comapi_err ; 0000 unimplemented syscall
945 dw comapi_get_version ; 0001 get SYSLINUX version
946 dw comapi_writestr ; 0002 write string
947 dw comapi_run ; 0003 run specified command
948 dw comapi_run_default ; 0004 run default command
949 dw comapi_textmode ; 0005 force text mode
950 dw comapi_open ; 0006 open file
951 dw comapi_read ; 0007 read file
952 dw comapi_close ; 0008 close file
953 dw comapi_pxecall ; 0009 call PXE stack
954 dw comapi_derinfo ; 000A derivative-specific info
955 dw comapi_serialcfg ; 000B get serial port config
956 dw comapi_cleanup ; 000C perform final cleanup
957 dw comapi_err ; 000D clean up then bootstrap
958 dw comapi_configfile ; 000E get name of config file
959 dw comapi_ipappend ; 000F get ipappend strings
960 dw comapi_dnsresolv ; 0010 resolve hostname
961 dw comapi_err ; 0011 maximum shuffle descriptors
962 dw comapi_err ; 0012 cleanup, shuffle and boot
963 dw comapi_idle ; 0013 idle call
964 dw comapi_localboot ; 0014 local boot
965 dw comapi_features ; 0015 feature flags
966 dw comapi_runkernel ; 0016 run kernel image
967 dw comapi_usingvga ; 0017 report video mode change
968 dw comapi_userfont ; 0018 query custom font
969 dw comapi_readdisk ; 0019 read disk
970 dw comapi_err ; 001A cleanup, shuffle and boot to pm
971 dw comapi_err ; 001B cleanup, shuffle and boot to rm
972 dw comapi_getadv ; 001C get pointer to ADV
973 dw comapi_writeadv ; 001D write ADV to disk
974 dw comapi_kbdtable ; 001E keyboard remapping table
975 dw comapi_getcwd ; 001F get current working directory
976 dw comapi_err ; 0020 open directory
977 dw comapi_err ; 0021 read directory
978 dw comapi_err ; 0022 close directory
979 dw comapi_shufsize ; 0023 query shuffler size
980 dw comapi_shufraw ; 0024 cleanup, shuffle and boot raw
981 int22_count equ ($-int22_table)/2
986 zero_string db 0 ; Empty, null-terminated string
989 ; This is the feature flag array for INT 22h AX=0015h
991 ; Note: PXELINUX clears the idle is noop flag if appropriate
992 ; in pxe_detect_nic_type
995 db 1 ; Have local boot, idle is not noop
996 feature_flags_len equ ($-feature_flags)
998 err_notdos db ': attempted DOS system call INT ',0
999 err_comlarge db 'COMBOOT image too large.', CR, LF, 0
1003 DOSErrTramp resd 33 ; Error trampolines
1006 ConfigName resb FILENAME_MAX
1007 %ifndef HAVE_CURRENTDIRNAME
1008 global CurrentDirName
1009 CurrentDirName resb FILENAME_MAX