1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009 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,10000h >> SECTOR_SHIFT
128 ; Absolute maximum # of sectors
130 cmp ecx,65536-256-2 ; Maximum size
133 ; And invoke the program...
138 push word 0 ; Return to address 0 -> exit
140 jmp comboot_seg:100h ; Run it
143 ; Set up the COMBOOT API interrupt vectors. This is now done at
144 ; initialization time.
147 mov di,DOSErrTramp ; Error trampolines
150 mov eax,02EB206Ah ; push 20h; jmp $+4
156 mov ax,comboot_bogus-2
161 mov si,4*20h ; DOS interrupt vectors
162 mov bx,comboot_vectors
163 mov di,DOSSaveVectors
174 ; Restore the original state of the COMBOOT API vectors, and free
175 ; any low memory allocated by the comboot module.
179 mov si,DOSSaveVectors
182 rep movsd ; Restore DOS-range vectors
188 DOSSaveVectors resd 32
191 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
194 dw comboot_return ; INT 20 = exit
195 dw comboot_int21 ; INT 21 = DOS-compatible system calls
196 dw comboot_int22 ; INT 22 = native system calls
197 dw comboot_err(23h) ; INT 23 = DOS Ctrl-C handler
198 dw comboot_err(24h) ; INT 24 = DOS critical error handler
199 dw comboot_err(25h) ; INT 25 = DOS absolute disk read
200 dw comboot_err(26h) ; INT 26 = DOS absolute disk write
201 dw comboot_err(27h) ; INT 27 = DOS TSR
202 dw comboot_int28 ; INT 28 = DOS idle interrupt
203 dw comboot_int29 ; INT 29 = DOS fast console output
204 dw comboot_err(2Ah) ; INT 2A = DOS network API (NetBIOS)
205 dw comboot_err(2Bh) ; INT 2B = DOS reserved
206 dw comboot_err(2Ch) ; INT 2C = DOS reserved
207 dw comboot_iret ; INT 2D = DOS reserved, AMIS
208 dw comboot_err(2Eh) ; INT 2E = DOS run command
209 dw comboot_iret ; INT 2F = DOS multiplex interrupt
210 dw comboot_err(30h) ; INT 30 = DOS CP/M system calls
211 dw comboot_err(31h) ; INT 31 = DPMI
212 dw comboot_err(32h) ; INT 32 = DOS reserved
213 dw comboot_iret ; INT 33 = DOS mouse API
214 dw comboot_err(34h) ; INT 34 = DOS FPU emulation
215 dw comboot_err(35h) ; INT 35 = DOS FPU emulation
216 dw comboot_err(36h) ; INT 36 = DOS FPU emulation
217 dw comboot_err(37h) ; INT 37 = DOS FPU emulation
218 dw comboot_err(38h) ; INT 38 = DOS FPU emulation
219 dw comboot_err(39h) ; INT 39 = DOS FPU emulation
220 dw comboot_err(3Ah) ; INT 3A = DOS FPU emulation
221 dw comboot_err(3Bh) ; INT 3B = DOS FPU emulation
222 dw comboot_err(3Ch) ; INT 3C = DOS FPU emulation
223 dw comboot_err(3Dh) ; INT 3D = DOS FPU emulation
224 dw comboot_err(3Eh) ; INT 3E = DOS FPU emulation
225 dw comboot_err(3Fh) ; INT 3F = DOS overlay manager
229 ; INT 21h: generic DOS system call
240 mov bp,sp ; Set up stack frame
242 call adjust_screen ; The COMBOOT program might have changed the screen
250 ; The last function in the list is the
251 ; "no such function" function
253 call ax ; Call the invoked function
255 mov bp,sp ; In case the function clobbers BP
256 setc P_FLAGSL ; Propagate CF->error
271 ; Attempted to execute invalid DOS system call
272 ; The interrupt number is on the stack.
273 comboot_bogus: pop dx ; Interrupt number
276 push comboot_bogus_tail
280 call writehex2 ; Interrupt number
284 call writehex4 ; Function number (AX)
288 call writehex8 ; CS:IP of the origin
292 ; Proper return vector
293 ; Note: this gets invoked both via INT 21h and directly via INT 20h.
294 ; We don't need to cld explicitly here, because comboot_exit does that
295 ; when invoking RESET_STACK_AND_SEGS.
297 cli ; May not have a safe stack
298 push enter_command ; Normal return to command prompt
302 ; Generic COMBOOT return to command line code
303 ; stack -> where to go next
304 ; CX -> message (for _msg version)
306 extern comboot_cleanup_lowmem
310 pop bx ; Return address
311 RESET_STACK_AND_SEGS si ; Contains sti, cld
312 pm_call comboot_cleanup_lowmem
313 call adjust_screen ; The COMBOOT program might have changed the screen
323 ; INT 21h system calls
325 comboot_getkey: ; 01 = get key with echo
333 comboot_writechr: ; 02 = writechr
339 comboot_writeserial: ; 04 = write serial port
345 comboot_getkeynoecho: ; 08 = get key w/o echo
350 comboot_writestr: ; 09 = write DOS string
354 cmp al,'$' ; End string with $ - bizarre
361 comboot_checkkey: ; 0B = check keyboard status
362 cmp byte [APIKeyFlag],00h
366 dec al ; AL = 0FFh if present, 0 if not
371 comboot_checkver: ; 30 = check DOS version
372 ; We return 0 in all DOS-compatible version registers,
373 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
381 cmp byte [APIKeyFlag],00h
383 call getchar ; If not queued get input
384 and al,al ; Function key? (CF <- 0)
386 mov [APIKeyWait],ah ; High part of key
387 inc byte [APIKeyFlag] ; Set flag
390 .queued: mov al,[APIKeyWait]
391 dec byte [APIKeyFlag]
404 ; INT 29h - DOS fast write character
409 call writechr ; Preserves registers!
413 ; INT 22h - SYSLINUX-specific system calls
414 ; System call number in ax
427 mov bp,sp ; Set up stack frame
429 call adjust_screen ; The COMBOOT program might have changed the screen
433 xor ax,ax ; Function 0 -> unimplemented
437 call [bx+int22_table]
438 jmp comboot_resume ; On return
441 ; INT 22h AX=0000h Unimplemented call
448 ; INT 22h AX=0001h Get SYSLINUX version
451 ; Number of API functions supported
454 mov P_CX,(VERSION_MAJOR << 8)+VERSION_MINOR
455 ; SYSLINUX derivative ID byte
458 mov P_BX,cs ; cs == 0
461 ; ES:SI -> version banner
462 mov P_SI,syslinux_banner
463 ; ES:DI -> copyright string
464 mov P_DI,copyright_str
471 ; INT 22h AX=0002h Write string
473 ; Write null-terminated string in ES:BX
483 ; INT 22h AX=0003h Run command
485 ; Terminates the COMBOOT program and executes the command line in
486 ; ES:BX as if it had been entered by the user.
493 push load_kernel ; Run a new kernel
494 jmp comboot_exit ; Terminate task, clean up
497 ; INT 22h AX=0004h Run default command
499 ; Terminates the COMBOOT program and executes the default command line
500 ; as if a timeout had happened or the user pressed <Enter>.
507 ; INT 22h AX=0005h Force text mode
509 ; Puts the video in standard text mode
517 ; INT 22h AX=0006h Open file
524 pm_call pm_mangle_name
535 ; INT 22h AX=0007h Read file
544 xor si,si ; SI <- 0 on EOF, CF <- 0
550 ; INT 22h AX=0008h Close file
559 ; INT 22h AX=0009h Call PXE stack
571 comapi_pxecall equ comapi_err ; Not available
575 ; INT 22h AX=000Ah Get Derivative-Specific Info
595 mov P_CL,SECTOR_SHIFT
600 %if IS_SYSLINUX || IS_EXTLINUX
609 mov P_CH,al ; Mode (el torito/cbios/ebios)
616 ; INT 22h AX=000Bh Get Serial Console Configuration
627 test byte [DisplayCon],01h
636 ; INT 22h AX=000Ch Perform final cleanup
640 ; Unload PXE if requested
643 sub bp,sp ; unload_pxe may move the stack around
645 add bp,sp ; restore frame pointer...
646 %elif IS_SYSLINUX || IS_EXTLINUX
647 ; Restore original FDC table
648 mov eax,[OrigFDCTabPtr]
651 call cleanup_hardware
656 ; INT 22h AX=000Dh Clean up then replace bootstrap
661 mov [trackbuf+4],eax ; Copy from
663 mov [trackbuf+8],eax ; Total bytes
665 mov [trackbuf],eax ; Copy to
666 push eax ; Entry point on stack
670 jmp replace_bootstrap_one
673 ; INT 22h AX=000Eh Get configuration file name
682 ; INT 22h AX=000Fh Get IPAPPEND strings
686 mov P_CX,numIPAppends
692 ; INT 22h AX=0010h Resolve hostname
695 extern pxe_dns_resolv
699 pm_call pxe_dns_resolv
704 comapi_dnsresolv equ comapi_err
710 ; INT 22h AX=0011h Obsolete
714 ; INT 22h AX=0012h Obsolete
718 ; INT 22h AX=0013h Idle call
726 ; INT 22h AX=0014h Local boot
733 comapi_localboot equ comapi_err
734 %endif ; HAS_LOCALBOOT
737 ; INT 22h AX=0015h Feature flags
741 mov P_BX,feature_flags
742 mov P_CX,feature_flags_len
747 ; INT 22h AX=0016h Run kernel image
755 ; It's not just possible, but quite likely, that ES:BX
756 ; points into real_mode_seg or xfer_buf_seg, so we
757 ; need to exercise some special care here... use
758 ; vk_append for temporary storage.
770 pm_call pm_mangle_name
775 ; The kernel image was found, so we can load it...
787 ; Copy the command line into its proper place
794 mov word [es:di-1],' ' ; Simulate APPEND: space plus null
797 mov word [CmdOptPtr],zero_string
798 jmp kernel_good_saved
800 .error equ comapi_usingvga.error
803 ; INT 22h AX=0017h Report video mode change
807 cmp ax,0Fh ; Unknown flags = failure
825 ; INT 22h AX=0018h Query custom font
840 ; INT 22h AX=0019h Read disk
842 %if IS_SYSLINUX || IS_ISOLINUX || IS_EXTLINUX
844 mov esi,P_ESI ; Enforce ESI == EDI == 0, these
845 or esi,P_EDI ; are reserved for future expansion
850 mov bp,P_CX ; WE CANNOT use P_* after touching bp!
858 comapi_readdisk equ comapi_err
862 ; INT 22h AX=001Ah Obsolete
866 ; INT 22h AX=001Bh Obsolete
870 ; INT 22h AX=001Ch Get pointer to auxillary data vector
879 ; INT 22h AX=001Dh Write auxillary data vector
881 comapi_writeadv equ adv_write
884 ; INT 22h AX=001Eh Keyboard remapping table
889 mov P_CX,256 ; Length
898 ; INT 22h AX=001Fh Get current working directory
902 mov P_BX,CurrentDirName
907 ; INT 22h AX=0023h Query shuffler size
910 ; +15 is padding to guarantee alignment
911 mov P_CX,__bcopyxx_len + 15
915 ; INT 22h AX=0024h Cleanup, shuffle and boot raw
922 jmp shuffle_and_boot_raw
932 int21 00h, comboot_return
933 int21 01h, comboot_getkey
934 int21 02h, comboot_writechr
935 int21 04h, comboot_writeserial
936 int21 08h, comboot_getkeynoecho
937 int21 09h, comboot_writestr
938 int21 0Bh, comboot_checkkey
939 int21 30h, comboot_checkver
940 int21 4Ch, comboot_return
941 int21 -1, comboot_bad_int21
942 int21_count equ ($-int21_table)/3
946 dw comapi_err ; 0000 unimplemented syscall
947 dw comapi_get_version ; 0001 get SYSLINUX version
948 dw comapi_writestr ; 0002 write string
949 dw comapi_run ; 0003 run specified command
950 dw comapi_run_default ; 0004 run default command
951 dw comapi_textmode ; 0005 force text mode
952 dw comapi_open ; 0006 open file
953 dw comapi_read ; 0007 read file
954 dw comapi_close ; 0008 close file
955 dw comapi_pxecall ; 0009 call PXE stack
956 dw comapi_derinfo ; 000A derivative-specific info
957 dw comapi_serialcfg ; 000B get serial port config
958 dw comapi_cleanup ; 000C perform final cleanup
959 dw comapi_err ; 000D clean up then bootstrap
960 dw comapi_configfile ; 000E get name of config file
961 dw comapi_ipappend ; 000F get ipappend strings
962 dw comapi_dnsresolv ; 0010 resolve hostname
963 dw comapi_err ; 0011 maximum shuffle descriptors
964 dw comapi_err ; 0012 cleanup, shuffle and boot
965 dw comapi_idle ; 0013 idle call
966 dw comapi_localboot ; 0014 local boot
967 dw comapi_features ; 0015 feature flags
968 dw comapi_runkernel ; 0016 run kernel image
969 dw comapi_usingvga ; 0017 report video mode change
970 dw comapi_userfont ; 0018 query custom font
971 dw comapi_readdisk ; 0019 read disk
972 dw comapi_err ; 001A cleanup, shuffle and boot to pm
973 dw comapi_err ; 001B cleanup, shuffle and boot to rm
974 dw comapi_getadv ; 001C get pointer to ADV
975 dw comapi_writeadv ; 001D write ADV to disk
976 dw comapi_kbdtable ; 001E keyboard remapping table
977 dw comapi_getcwd ; 001F get current working directory
978 dw comapi_err ; 0020 open directory
979 dw comapi_err ; 0021 read directory
980 dw comapi_err ; 0022 close directory
981 dw comapi_shufsize ; 0023 query shuffler size
982 dw comapi_shufraw ; 0024 cleanup, shuffle and boot raw
983 int22_count equ ($-int22_table)/2
988 zero_string db 0 ; Empty, null-terminated string
991 ; This is the feature flag array for INT 22h AX=0015h
993 ; Note: PXELINUX clears the idle is noop flag if appropriate
994 ; in pxe_detect_nic_type
997 db 1 ; Have local boot, idle is not noop
998 feature_flags_len equ ($-feature_flags)
1000 err_notdos db ': attempted DOS system call INT ',0
1001 err_comlarge db 'COMBOOT image too large.', CR, LF, 0
1005 DOSErrTramp resd 33 ; Error trampolines
1008 ConfigName resb FILENAME_MAX
1009 %ifndef HAVE_CURRENTDIRNAME
1010 global CurrentDirName
1011 CurrentDirName resb FILENAME_MAX