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
142 ; Proper return vector
143 ; Note: this gets invoked both via INT 21h and directly via INT 20h.
144 ; We don't need to cld explicitly here, because comboot_exit does that
145 ; when invoking RESET_STACK_AND_SEGS.
146 comboot_return: cli ; May not have a safe stack
147 push enter_command ; Normal return to command prompt
151 ; Set up the COMBOOT API interrupt vectors. This is now done at
152 ; initialization time.
155 mov di,DOSErrTramp ; Error trampolines
158 mov eax,02EB206Ah ; push 20h; jmp $+4
164 mov ax,comboot_bogus-2
169 mov si,4*20h ; DOS interrupt vectors
170 mov bx,comboot_vectors
171 mov di,DOSSaveVectors
182 ; Restore the original state of the COMBOOT API vectors
186 mov si,DOSSaveVectors
189 rep movsd ; Restore DOS-range vectors
195 DOSSaveVectors resd 32
198 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
201 dw comboot_return ; INT 20 = exit
202 dw comboot_int21 ; INT 21 = DOS-compatible system calls
203 dw comboot_int22 ; INT 22 = native system calls
204 dw comboot_err(23h) ; INT 23 = DOS Ctrl-C handler
205 dw comboot_err(24h) ; INT 24 = DOS critical error handler
206 dw comboot_err(25h) ; INT 25 = DOS absolute disk read
207 dw comboot_err(26h) ; INT 26 = DOS absolute disk write
208 dw comboot_err(27h) ; INT 27 = DOS TSR
209 dw comboot_int28 ; INT 28 = DOS idle interrupt
210 dw comboot_int29 ; INT 29 = DOS fast console output
211 dw comboot_err(2Ah) ; INT 2A = DOS network API (NetBIOS)
212 dw comboot_err(2Bh) ; INT 2B = DOS reserved
213 dw comboot_err(2Ch) ; INT 2C = DOS reserved
214 dw comboot_iret ; INT 2D = DOS reserved, AMIS
215 dw comboot_err(2Eh) ; INT 2E = DOS run command
216 dw comboot_iret ; INT 2F = DOS multiplex interrupt
217 dw comboot_err(30h) ; INT 30 = DOS CP/M system calls
218 dw comboot_err(31h) ; INT 31 = DPMI
219 dw comboot_err(32h) ; INT 32 = DOS reserved
220 dw comboot_iret ; INT 33 = DOS mouse API
221 dw comboot_err(34h) ; INT 34 = DOS FPU emulation
222 dw comboot_err(35h) ; INT 35 = DOS FPU emulation
223 dw comboot_err(36h) ; INT 36 = DOS FPU emulation
224 dw comboot_err(37h) ; INT 37 = DOS FPU emulation
225 dw comboot_err(38h) ; INT 38 = DOS FPU emulation
226 dw comboot_err(39h) ; INT 39 = DOS FPU emulation
227 dw comboot_err(3Ah) ; INT 3A = DOS FPU emulation
228 dw comboot_err(3Bh) ; INT 3B = DOS FPU emulation
229 dw comboot_err(3Ch) ; INT 3C = DOS FPU emulation
230 dw comboot_err(3Dh) ; INT 3D = DOS FPU emulation
231 dw comboot_err(3Eh) ; INT 3E = DOS FPU emulation
232 dw comboot_err(3Fh) ; INT 3F = DOS overlay manager
236 ; INT 21h: generic DOS system call
247 mov bp,sp ; Set up stack frame
249 call adjust_screen ; The COMBOOT program might have changed the screen
257 ; The last function in the list is the
258 ; "no such function" function
260 call ax ; Call the invoked function
262 mov bp,sp ; In case the function clobbers BP
263 setc P_FLAGSL ; Propagate CF->error
278 ; Attempted to execute invalid DOS system call
279 ; The interrupt number is on the stack.
280 comboot_bogus: pop dx ; Interrupt number
283 push comboot_bogus_tail
287 call writehex2 ; Interrupt number
291 call writehex4 ; Function number (AX)
295 call writehex8 ; CS:IP of the origin
300 ; Generic COMBOOT return to command line code
301 ; stack -> where to go next
302 ; CX -> message (for _msg version)
307 pop bx ; Return address
308 RESET_STACK_AND_SEGS SI ; Contains sti, cld
309 call adjust_screen ; The COMBOOT program might have changed the screen
319 ; INT 21h system calls
321 comboot_getkey: ; 01 = get key with echo
329 comboot_writechr: ; 02 = writechr
335 comboot_writeserial: ; 04 = write serial port
341 comboot_getkeynoecho: ; 08 = get key w/o echo
346 comboot_writestr: ; 09 = write DOS string
350 cmp al,'$' ; End string with $ - bizarre
357 comboot_checkkey: ; 0B = check keyboard status
358 cmp byte [APIKeyFlag],00h
362 dec al ; AL = 0FFh if present, 0 if not
367 comboot_checkver: ; 30 = check DOS version
368 ; We return 0 in all DOS-compatible version registers,
369 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
377 cmp byte [APIKeyFlag],00h
379 call getchar ; If not queued get input
380 and al,al ; Function key? (CF <- 0)
382 mov [APIKeyWait],ah ; High part of key
383 inc byte [APIKeyFlag] ; Set flag
386 .queued: mov al,[APIKeyWait]
387 dec byte [APIKeyFlag]
400 ; INT 29h - DOS fast write character
405 call writechr ; Preserves registers!
409 ; INT 22h - SYSLINUX-specific system calls
410 ; System call number in ax
423 mov bp,sp ; Set up stack frame
425 call adjust_screen ; The COMBOOT program might have changed the screen
429 xor ax,ax ; Function 0 -> unimplemented
433 call [bx+int22_table]
434 jmp comboot_resume ; On return
437 ; INT 22h AX=0000h Unimplemented call
444 ; INT 22h AX=0001h Get SYSLINUX version
447 ; Number of API functions supported
450 mov P_CX,(VERSION_MAJOR << 8)+VERSION_MINOR
451 ; SYSLINUX derivative ID byte
454 mov P_BX,cs ; cs == 0
457 ; ES:SI -> version banner
458 mov P_SI,syslinux_banner
459 ; ES:DI -> copyright string
460 mov P_DI,copyright_str
467 ; INT 22h AX=0002h Write string
469 ; Write null-terminated string in ES:BX
479 ; INT 22h AX=0003h Run command
481 ; Terminates the COMBOOT program and executes the command line in
482 ; ES:BX as if it had been entered by the user.
489 push load_kernel ; Run a new kernel
490 jmp comboot_exit ; Terminate task, clean up
493 ; INT 22h AX=0004h Run default command
495 ; Terminates the COMBOOT program and executes the default command line
496 ; as if a timeout had happened or the user pressed <Enter>.
503 ; INT 22h AX=0005h Force text mode
505 ; Puts the video in standard text mode
513 ; INT 22h AX=0006h Open file
531 ; INT 22h AX=0007h Read file
540 xor si,si ; SI <- 0 on EOF, CF <- 0
546 ; INT 22h AX=0008h Close file
555 ; INT 22h AX=0009h Call PXE stack
567 comapi_pxecall equ comapi_err ; Not available
571 ; INT 22h AX=000Ah Get Derivative-Specific Info
589 mov P_CL,SECTOR_SHIFT
594 %if IS_SYSLINUX || IS_EXTLINUX
603 mov P_CH,al ; Mode (el torito/cbios/ebios)
610 ; INT 22h AX=000Bh Get Serial Console Configuration
621 test byte [DisplayCon],01h
630 ; INT 22h AX=000Ch Perform final cleanup
634 ; Unload PXE if requested
637 sub bp,sp ; unload_pxe may move the stack around
639 add bp,sp ; restore frame pointer...
640 %elif IS_SYSLINUX || IS_EXTLINUX
641 ; Restore original FDC table
642 mov eax,[OrigFDCTabPtr]
645 call cleanup_hardware
650 ; INT 22h AX=000Dh Clean up then replace bootstrap
655 mov [trackbuf+4],eax ; Copy from
657 mov [trackbuf+8],eax ; Total bytes
659 mov [trackbuf],eax ; Copy to
660 push eax ; Entry point on stack
664 jmp replace_bootstrap_one
667 ; INT 22h AX=000Eh Get configuration file name
676 ; INT 22h AX=000Fh Get IPAPPEND strings
680 mov P_CX,numIPAppends
686 ; INT 22h AX=0010h Resolve hostname
697 comapi_dnsresolv equ comapi_err
703 ; INT 22h AX=0011h Obsolete
707 ; INT 22h AX=0012h Obsolete
711 ; INT 22h AX=0013h Idle call
719 ; INT 22h AX=0014h Local boot
726 comapi_localboot equ comapi_err
727 %endif ; HAS_LOCALBOOT
730 ; INT 22h AX=0015h Feature flags
734 mov P_BX,feature_flags
735 mov P_CX,feature_flags_len
740 ; INT 22h AX=0016h Run kernel image
756 ; The kernel image was found, so we can load it...
760 ; It's not just possible, but quite likely, that ES:BX
761 ; points into real_mode_seg or xfer_buf_seg, so we
762 ; need to exercise some special care here... use
763 ; trackbuf as an intermediary
779 ; Copy the command line into its proper place
786 mov byte [es:di-1],' ' ; Simulate APPEND
789 mov word [CmdOptPtr],zero_string
790 jmp kernel_good_saved
792 .error equ comapi_usingvga.error
795 ; INT 22h AX=0017h Report video mode change
799 cmp ax,0Fh ; Unknown flags = failure
817 ; INT 22h AX=0018h Query custom font
832 ; INT 22h AX=0019h Read disk
834 %if IS_SYSLINUX || IS_ISOLINUX || IS_EXTLINUX
836 mov esi,P_ESI ; Enforce ESI == EDI == 0, these
837 or esi,P_EDI ; are reserved for future expansion
842 mov bp,P_CX ; WE CANNOT use P_* after touching bp!
850 comapi_readdisk equ comapi_err
854 ; INT 22h AX=001Ah Obsolete
858 ; INT 22h AX=001Bh Obsolete
862 ; INT 22h AX=001Ch Get pointer to auxillary data vector
871 ; INT 22h AX=001Dh Write auxillary data vector
873 comapi_writeadv equ adv_write
876 ; INT 22h AX=001Eh Keyboard remapping table
881 mov P_CX,256 ; Length
890 ; INT 22h AX=001Fh Get current working directory
894 mov P_BX,CurrentDirName
899 ; INT 22h AX=0020h Open directory
910 jnz comapi_err ; Didn't find a directory
912 jz comapi_err ; Found nothing
914 pm_call alloc_fill_dir
921 comapi_opendir equ comapi_err
925 ; INT 22h AX=0021h Read directory
939 comapi_readdir equ comapi_err
943 ; INT 22h AX=0022h Close directory
945 comapi_closedir equ comapi_close
948 ; INT 22h AX=0023h Query shuffler size
951 mov P_CX,bcopyxx_safe
955 ; INT 22h AX=0024h Cleanup, shuffle and boot raw
962 jmp shuffle_and_boot_raw
972 int21 00h, comboot_return
973 int21 01h, comboot_getkey
974 int21 02h, comboot_writechr
975 int21 04h, comboot_writeserial
976 int21 08h, comboot_getkeynoecho
977 int21 09h, comboot_writestr
978 int21 0Bh, comboot_checkkey
979 int21 30h, comboot_checkver
980 int21 4Ch, comboot_return
981 int21 -1, comboot_bad_int21
982 int21_count equ ($-int21_table)/3
986 dw comapi_err ; 0000 unimplemented syscall
987 dw comapi_get_version ; 0001 get SYSLINUX version
988 dw comapi_writestr ; 0002 write string
989 dw comapi_run ; 0003 run specified command
990 dw comapi_run_default ; 0004 run default command
991 dw comapi_textmode ; 0005 force text mode
992 dw comapi_open ; 0006 open file
993 dw comapi_read ; 0007 read file
994 dw comapi_close ; 0008 close file
995 dw comapi_pxecall ; 0009 call PXE stack
996 dw comapi_derinfo ; 000A derivative-specific info
997 dw comapi_serialcfg ; 000B get serial port config
998 dw comapi_cleanup ; 000C perform final cleanup
999 dw comapi_err ; 000D clean up then bootstrap
1000 dw comapi_configfile ; 000E get name of config file
1001 dw comapi_ipappend ; 000F get ipappend strings
1002 dw comapi_dnsresolv ; 0010 resolve hostname
1003 dw comapi_err ; 0011 maximum shuffle descriptors
1004 dw comapi_err ; 0012 cleanup, shuffle and boot
1005 dw comapi_idle ; 0013 idle call
1006 dw comapi_localboot ; 0014 local boot
1007 dw comapi_features ; 0015 feature flags
1008 dw comapi_runkernel ; 0016 run kernel image
1009 dw comapi_usingvga ; 0017 report video mode change
1010 dw comapi_userfont ; 0018 query custom font
1011 dw comapi_readdisk ; 0019 read disk
1012 dw comapi_err ; 001A cleanup, shuffle and boot to pm
1013 dw comapi_err ; 001B cleanup, shuffle and boot to rm
1014 dw comapi_getadv ; 001C get pointer to ADV
1015 dw comapi_writeadv ; 001D write ADV to disk
1016 dw comapi_kbdtable ; 001E keyboard remapping table
1017 dw comapi_getcwd ; 001F get current working directory
1018 dw comapi_opendir ; 0020 open directory
1019 dw comapi_readdir ; 0021 read directory
1020 dw comapi_closedir ; 0022 close directory
1021 dw comapi_shufsize ; 0023 query shuffler size
1022 dw comapi_shufraw ; 0024 cleanup, shuffle and boot raw
1023 int22_count equ ($-int22_table)/2
1028 zero_string db 0 ; Empty, null-terminated string
1031 ; This is the feature flag array for INT 22h AX=0015h
1033 ; Note: PXELINUX clears the idle is noop flag if appropriate
1034 ; in pxe_detect_nic_type
1037 db 1 ; Have local boot, idle is not noop
1038 feature_flags_len equ ($-feature_flags)
1040 err_notdos db ': attempted DOS system call INT ',0
1041 err_comlarge db 'COMBOOT image too large.', CR, LF, 0
1045 DOSErrTramp resd 33 ; Error trampolines
1047 global ConfigName, CurrentDirName
1048 ConfigName resb FILENAME_MAX
1049 CurrentDirName resb FILENAME_MAX