comboot: re-enable the idle call
[syslinux.git] / core / comboot.inc
blob5367f6f777c311d7bff260b560797d808ca3c775
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 ;;
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 ;; -----------------------------------------------------------------------
14 ;; comboot.inc
16 ;; Common code for running a COMBOOT image
19                 section .text
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_CSIP          dword [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
64 comboot_too_large:
65                 call close_file
66                 mov si,err_comlarge
67                 call writestr
68                 jmp enter_command
71 ; Load a COMBOOT image.  A COMBOOT image is basically a DOS .COM file,
72 ; except that it may, of course, not contain any DOS system calls.  We
73 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
75 is_comboot_image:
76                 push si                 ; Save file handle
78                 call make_plain_cmdline
80                 call comboot_setup_api
82                 mov cx,comboot_seg
83                 mov es,cx
85                 xor di,di
86                 mov cx,64               ; 256 bytes (size of PSP)
87                 xor eax,eax             ; Clear PSP
88                 rep stosd
90                 mov word [es:0], 020CDh ; INT 20h instruction
91                 ; First non-free paragraph
92                 ; This is valid because comboot_seg == real_mode_seg
93                 ; == the highest segment used by all derivatives
94                 int 12h                 ; Get DOS memory size
95                 shl ax,6                ; Kilobytes -> paragraphs
96                 mov word [es:02h],ax
98 %ifndef DEPEND
99 %if real_mode_seg != comboot_seg
100 %error "This code assumes real_mode_seg == comboot_seg"
101 %endif
102 %endif
103                 ; Copy the command line from high memory
104                 mov si,cmd_line_here
105                 mov cx,125              ; Max cmdline len (minus space and CR)
106                 mov di,081h             ; Offset in PSP for command line
107                 mov al,' '              ; DOS command lines begin with a space
108                 stosb
110 .loop:          es lodsb
111                 and al,al
112                 jz .done
113                 stosb
114                 loop .loop
115 .done:
117                 mov al,0Dh              ; CR after last character
118                 stosb
119                 mov ax,di
120                 sub al,82h              ; Include space but not CR
121                 mov [es:80h],al         ; Store command line length
123                 ; Now actually load the file...
124                 pop si                  ; File handle
125                 mov bx,100h             ; Load at <seg>:0100h
126                 mov cx,10000h >> SECTOR_SHIFT
127                                         ; Absolute maximum # of sectors
128                 call getfssec
129                 cmp ecx,65536-256-2     ; Maximum size
130                 ja comboot_too_large
132                 ; And invoke the program...
133                 mov ax,es
134                 mov ds,ax
135                 mov ss,ax
136                 xor sp,sp
137                 push word 0             ; Return to address 0 -> exit
139                 jmp comboot_seg:100h    ; Run it
141 ; Proper return vector
142 ; Note: this gets invoked both via INT 21h and directly via INT 20h.
143 ; We don't need to cld explicitly here, because comboot_exit does that
144 ; when invoking RESET_STACK_AND_SEGS.
145 comboot_return: cli                     ; Don't trust anyone
146                 push enter_command      ; Normal return to command prompt
147                 jmp comboot_exit
150 ; Set up the COMBOOT API interrupt vectors.  This is also used
151 ; by the COM32 code.
153 comboot_setup_api:
154                 mov di,DOSErrTramp      ; Error trampolines
155                 mov cx,32
156                 push cx
157                 mov eax,02EB206Ah       ; push 20h; jmp $+4
158 .loop1:         stosd
159                 inc ah
160                 loop .loop1
161                 dec di
162                 mov byte [di-1],0E9h
163                 mov ax,comboot_bogus-2
164                 sub ax,di
165                 stosw
167                 pop cx                  ; CX <- 32
168                 mov si,4*20h            ; DOS interrupt vectors
169                 mov bx,comboot_vectors
170                 mov di,DOSSaveVectors
171 .loop2:
172                 movsd
173                 movzx eax,word [bx]
174                 inc bx
175                 inc bx
176                 mov [si-4],eax
177                 loop .loop2
178                 ret
180                 section .bss
181                 alignb 4
182 DOSSaveVectors  resd 32
184                 section .data
185 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
187 comboot_vectors:
188                 dw comboot_return       ; INT 20 = exit
189                 dw comboot_int21        ; INT 21 = DOS-compatible system calls
190                 dw comboot_int22        ; INT 22 = native system calls
191                 dw comboot_err(23h)     ; INT 23 = DOS Ctrl-C handler
192                 dw comboot_err(24h)     ; INT 24 = DOS critical error handler
193                 dw comboot_err(25h)     ; INT 25 = DOS absolute disk read
194                 dw comboot_err(26h)     ; INT 26 = DOS absolute disk write
195                 dw comboot_err(27h)     ; INT 27 = DOS TSR
196                 dw comboot_int28        ; INT 28 = DOS idle interrupt
197                 dw comboot_int29        ; INT 29 = DOS fast console output
198                 dw comboot_err(2Ah)     ; INT 2A = DOS network API (NetBIOS)
199                 dw comboot_err(2Bh)     ; INT 2B = DOS reserved
200                 dw comboot_err(2Ch)     ; INT 2C = DOS reserved
201                 dw comboot_iret         ; INT 2D = DOS reserved, AMIS
202                 dw comboot_err(2Eh)     ; INT 2E = DOS run command
203                 dw comboot_iret         ; INT 2F = DOS multiplex interrupt
204                 dw comboot_err(30h)     ; INT 30 = DOS CP/M system calls
205                 dw comboot_err(31h)     ; INT 31 = DPMI
206                 dw comboot_err(32h)     ; INT 32 = DOS reserved
207                 dw comboot_iret         ; INT 33 = DOS mouse API
208                 dw comboot_err(34h)     ; INT 34 = DOS FPU emulation
209                 dw comboot_err(35h)     ; INT 35 = DOS FPU emulation
210                 dw comboot_err(36h)     ; INT 36 = DOS FPU emulation
211                 dw comboot_err(37h)     ; INT 37 = DOS FPU emulation
212                 dw comboot_err(38h)     ; INT 38 = DOS FPU emulation
213                 dw comboot_err(39h)     ; INT 39 = DOS FPU emulation
214                 dw comboot_err(3Ah)     ; INT 3A = DOS FPU emulation
215                 dw comboot_err(3Bh)     ; INT 3B = DOS FPU emulation
216                 dw comboot_err(3Ch)     ; INT 3C = DOS FPU emulation
217                 dw comboot_err(3Dh)     ; INT 3D = DOS FPU emulation
218                 dw comboot_err(3Eh)     ; INT 3E = DOS FPU emulation
219                 dw comboot_err(3Fh)     ; INT 3F = DOS overlay manager
221                 section .text
223 ; INT 21h: generic DOS system call
224 comboot_int21:  cli
225                 push ds
226                 push es
227                 push fs
228                 push gs
229                 pushad
230                 cld
231                 mov bp,cs
232                 mov ds,bp
233                 mov es,bp
234                 mov bp,sp                       ; Set up stack frame
236                 call adjust_screen              ; The COMBOOT program might have changed the screen
238                 mov cx,int21_count
239                 mov si,int21_table
240 .again:         lodsb
241                 cmp al,P_AH
242                 lodsw
243                 loopne .again
244                 ; The last function in the list is the
245                 ; "no such function" function
246                 clc
247                 call ax                 ; Call the invoked function
248 comboot_resume:
249                 mov bp,sp               ; In case the function clobbers BP
250                 setc P_FLAGSL           ; Propagate CF->error
251                 popad
252                 pop gs
253                 pop fs
254                 pop es
255                 pop ds
256 comboot_iret:
257                 iret
259 comboot_bad_int21:
260                 mov ax,P_AX
261                 push P_CSIP
262                 push 21h
263                 ; Fall through
265 ; Attempted to execute invalid DOS system call
266 ; The interrupt number is on the stack.
267 comboot_bogus:  cli                     ; Don't trust anyone
268                 pop dx                  ; Interrupt number
269                 pop edi                 ; CS:IP
270                 mov cx,err_notdos
271                 push comboot_bogus_tail
272                 jmp comboot_exit_msg
273 comboot_bogus_tail:
274                 xchg ax,dx
275                 call writehex2          ; Interrupt number
276                 mov al,' '
277                 call writechr
278                 xchg ax,dx
279                 call writehex4          ; Function number (AX)
280                 mov al,' '
281                 call writechr
282                 mov eax,edi
283                 call writehex8          ; CS:IP of the origin
284                 call crlf
285                 jmp enter_command
288 ; Generic COMBOOT return to command line code
289 ;  stack -> where to go next
290 ;     CX -> message (for _msg version)
292 comboot_exit:
293                 xor cx,cx
294 comboot_exit_msg:
295                 pop bx                  ; Return address
296                 RESET_STACK_AND_SEGS SI ; Contains cld
297                 call adjust_screen      ; The COMBOOT program might have changed the screen
298                 pusha
299                 mov si,DOSSaveVectors
300                 mov di,4*20h
301                 mov cx,20h
302                 rep movsd               ; Restore DOS-range vectors
303                 popa
304                 jcxz .nomsg
305                 mov si,KernelCName
306                 call writestr
307                 mov si,cx
308                 call writestr
309 .nomsg:
310                 jmp bx
313 ; INT 21h system calls
315 comboot_getkey:                         ; 01 = get key with echo
316                 call vgashowcursor
317                 call comboot_getchar
318                 call vgahidecursor
319                 call writechr
320                 clc
321                 ret
323 comboot_writechr:                       ; 02 = writechr
324                 mov al,P_DL
325                 call writechr
326                 clc
327                 ret
329 comboot_writeserial:                    ; 04 = write serial port
330                 mov al,P_DL
331                 call write_serial
332                 clc
333                 ret
335 comboot_getkeynoecho:                   ; 08 = get key w/o echo
336                 call comboot_getchar
337                 clc
338                 ret
340 comboot_writestr:                       ; 09 = write DOS string
341                 mov es,P_DS
342                 mov si,P_DX
343 .loop:          es lodsb
344                 cmp al,'$'              ; End string with $ - bizarre
345                 je .done
346                 call writechr
347                 jmp short .loop
348 .done:          clc
349                 ret
351 comboot_checkkey:                       ; 0B = check keyboard status
352                 cmp byte [APIKeyFlag],00h
353                 jnz .waiting
354                 call pollchar
355 .waiting:       setz al
356                 dec al                  ; AL = 0FFh if present, 0 if not
357                 mov P_AL,al
358                 clc
359                 ret
361 comboot_checkver:                       ; 30 = check DOS version
362                 ; We return 0 in all DOS-compatible version registers,
363                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
364                 mov P_EAX,'SY' << 16
365                 mov P_EBX,'SL' << 16
366                 mov P_ECX,'IN' << 16
367                 mov P_EDX,'UX' << 16
368                 ret
370 comboot_getchar:
371                 cmp byte [APIKeyFlag],00h
372                 jne .queued
373                 call getchar            ; If not queued get input
374                 and al,al               ; Function key?  (CF <- 0)
375                 jnz .done
376                 mov [APIKeyWait],ah     ; High part of key
377                 inc byte [APIKeyFlag]   ; Set flag
378 .done:          mov P_AL,al
379                 ret
380 .queued:        mov al,[APIKeyWait]
381                 dec byte [APIKeyFlag]
382                 jmp .done
385 ; INT 28h - DOS idle
387 %ifdef HAVE_IDLE
388 comboot_int28:
389                 cli
390                 cld
391                 pushad
392                 xor ax,ax
393                 push ds
394                 push es
395                 mov ds,ax
396                 mov es,ax
397                 DO_IDLE
398                 pop es
399                 pop ds
400                 popad
401                 iret
402 %else
403 comboot_int28   equ comboot_iret
404 %endif
407 ; INT 29h - DOS fast write character
409 comboot_int29:
410                 cli
411                 cld
412                 call writechr                   ; Preserves registers!
413                 iret
416 ; INT 22h - SYSLINUX-specific system calls
417 ;           System call number in ax
419 comboot_int22:
420                 cli
421                 push ds
422                 push es
423                 push fs
424                 push gs
425                 pushad
426                 cld
427                 mov bp,cs
428                 mov ds,bp
429                 mov es,bp
430                 mov bp,sp                       ; Set up stack frame
432                 call adjust_screen              ; The COMBOOT program might have changed the screen
434                 cmp ax,int22_count
435                 jb .ok
436                 xor ax,ax                       ; Function 0 -> unimplemented
437 .ok:
438                 xchg ax,bx
439                 add bx,bx                       ; CF <- 0
440                 call [bx+int22_table]
441                 jmp comboot_resume              ; On return
444 ; INT 22h AX=0000h      Unimplemented call
446 comapi_err:
447                 stc
448                 ret
451 ; INT 22h AX=0001h      Get SYSLINUX version
453 comapi_get_version:
454                 ; Number of API functions supported
455                 mov P_AX,int22_count
456                 ; SYSLINUX version
457                 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
458                 ; SYSLINUX derivative ID byte
459                 mov P_DX,my_id
460                 ; For future use
461                 mov P_BX,cs     ; cs == 0
463                 mov P_ES,ds
464                 ; ES:SI -> version banner
465                 mov P_SI,syslinux_banner
466                 ; ES:DI -> copyright string
467                 mov P_DI,copyright_str
469 comapi_nop:
470                 clc
471                 ret
474 ; INT 22h AX=0002h      Write string
476 ; Write null-terminated string in ES:BX
478 comapi_writestr:
479                 mov ds,P_ES
480                 mov si,P_BX
481                 call writestr
482                 clc
483                 ret
486 ; INT 22h AX=0003h      Run command
488 ; Terminates the COMBOOT program and executes the command line in
489 ; ES:BX as if it had been entered by the user.
491 comapi_run:
492                 mov ds,P_ES
493                 mov si,P_BX
494                 mov di,command_line
495                 call strcpy
496                 push load_kernel                ; Run a new kernel
497                 jmp comboot_exit                ; Terminate task, clean up
500 ; INT 22h AX=0004h      Run default command
502 ; Terminates the COMBOOT program and executes the default command line
503 ; as if a timeout had happened or the user pressed <Enter>.
505 comapi_run_default:
506                 push auto_boot
507                 jmp comboot_exit
510 ; INT 22h AX=0005h      Force text mode
512 ; Puts the video in standard text mode
514 comapi_textmode:
515                 call vgaclearmode
516                 clc
517                 ret
520 ; INT 22h AX=0006h      Open file
522 comapi_open:
523                 push ds
524                 mov ds,P_ES
525                 mov si,P_SI
526                 mov di,InitRD
527                 call mangle_name
528                 pop ds
529                 call searchdir
530                 jz comapi_err
531                 mov P_EAX,eax
532                 mov P_CX,SECTOR_SIZE
533                 mov P_SI,si
534                 clc
535                 ret
538 ; INT 22h AX=0007h      Read file
540 comapi_read:
541                 mov es,P_ES
542                 mov bx,P_BX
543                 mov si,P_SI
544                 mov cx,P_CX
545                 call getfssec
546                 jnc .noteof
547                 xor si,si               ; SI <- 0 on EOF, CF <- 0
548 .noteof:        mov P_SI,si
549                 mov P_ECX,ecx
550                 ret
553 ; INT 22h AX=0008h      Close file
555 comapi_close:
556                 mov si,P_SI
557                 call close_file
558                 clc
559                 ret
562 ; INT 22h AX=0009h      Call PXE stack
564 %if IS_PXELINUX
565 comapi_pxecall:
566                 mov bx,P_BX
567                 mov es,P_ES
568                 mov di,P_DI
569                 call pxenv
570                 mov ax,[PXEStatus]
571                 mov P_AX,ax
572                 ret
573 %else
574 comapi_pxecall  equ comapi_err                  ; Not available
575 %endif
578 ; INT 22h AX=000Ah      Get Derivative-Specific Info
580 comapi_derinfo:
581                 mov P_AL,my_id
582 %if IS_PXELINUX
583                 mov ax,[APIVer]
584                 mov P_DX,ax
585                 mov ax,[StrucPtr]
586                 mov P_BX,ax
587                 mov ax,[StrucPtr+2]
588                 mov P_ES,ax
589                 mov ax,[InitStack]
590                 mov P_SI,ax
591                 mov ax,[InitStack+2]
592                 mov P_FS,ax
593 %else
594                 ; Physical medium...
596                 mov P_CL,SECTOR_SHIFT
597                 mov al,[DriveNumber]
598                 mov P_DL,al
599                 mov P_FS,cs
600                 mov P_SI,OrigESDI
601 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
602                 mov P_ES,cs
603                 mov P_BX,PartInfo
604 %elif IS_ISOLINUX
605                 mov P_ES,cs
606                 mov P_BX,spec_packet
607 %endif
608 %endif
609                 clc
610                 ret
613 ; INT 22h AX=000Bh      Get Serial Console Configuration
615 comapi_serialcfg:
616                 mov ax,[SerialPort]
617                 mov P_DX,ax
618                 mov ax,[BaudDivisor]
619                 mov P_CX,ax
620                 mov ax,[FlowControl]
621                 or al,ah
622                 mov ah,[FlowIgnore]
623                 shr ah,4
624                 test byte [DisplayCon],01h
625                 jnz .normalconsole
626                 or ah,80h
627 .normalconsole:
628                 mov P_BX,ax
629                 clc
630                 ret
633 ; INT 22h AX=000Ch      Perform final cleanup
635 comapi_cleanup:
636 %if IS_PXELINUX
637                 ; Unload PXE if requested
638                 test dl,3
639                 setnz [KeepPXE]
640                 sub bp,sp               ; unload_pxe may move the stack around
641                 call unload_pxe
642                 add bp,sp               ; restore frame pointer...
643 %elif IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
644                 ; Restore original FDC table
645                 mov eax,[OrigFDCTabPtr]
646                 mov [fdctab],eax
647 %endif
648                 ; Reset the floppy disk subsystem
649                 xor ax,ax
650                 xor dx,dx
651                 int 13h
652                 clc
653                 ret
656 ; INT 22h AX=000Dh      Clean up then replace bootstrap
658 comapi_chainboot:
659                 call comapi_cleanup
660                 mov eax,P_EDI
661                 mov [trackbuf+4],eax            ; Copy from
662                 mov eax,P_ECX
663                 mov [trackbuf+8],eax            ; Total bytes
664                 mov eax,7C00h
665                 mov [trackbuf],eax              ; Copy to
666                 mov [EntryPoint],eax            ; CS:IP entry point
667                 mov esi,P_ESI
668                 mov edx,P_EBX
669                 mov bx,P_DS
670                 jmp replace_bootstrap_one
674 ; INT 22h AX=000Eh      Get configuration file name
676 comapi_configfile:
677                 mov P_ES,cs
678                 mov P_BX,ConfigName
679                 clc
680                 ret
683 ; INT 22h AX=000Fh      Get IPAPPEND strings
685 %if IS_PXELINUX
686 comapi_ipappend:
687                 mov P_ES,cs
688                 mov P_CX,numIPAppends
689                 mov P_BX,IPAppends
690                 clc
691                 ret
693                 section .data
694                 alignb 2, db 0
695 IPAppends       dw IPOption
696                 dw BOOTIFStr
697 numIPAppends    equ ($-IPAppends)/2
699 %else
700 comapi_ipappend equ comapi_err
701 %endif
703                 section .text
706 ; INT 22h AX=0010h      Resolve hostname
708 %if IS_PXELINUX
709 comapi_dnsresolv:
710                 mov ds,P_ES
711                 mov si,P_BX
712                 call dns_resolv
713                 mov P_EAX,eax
714                 clc
715                 ret
716 %else
717 comapi_dnsresolv equ comapi_err
718 %endif
720                 section .text
723 ; INT 22h AX=0011h      Maximum number of shuffle descriptors
725 comapi_maxshuffle:
726                 mov P_CX,trackbufsize/12
727                 ret
730 ; INT 22h AX=0012h      Cleanup, shuffle and boot
732 comapi_shuffle:
733                 cmp P_CX,(2*trackbufsize)/12
734                 ja .error
736                 call comapi_cleanup
738                 mov cx, P_CX
739                 push cx                         ; On stack: descriptor count
741                 lea cx,[ecx+ecx*2]              ; CX *= 3
743                 mov fs,P_ES
744                 mov si,P_DI
745                 mov di,trackbuf
746                 push di                         ; On stack: descriptor list address
747                 fs rep movsd                    ; Copy the list
749                 mov eax,P_EBP
750                 mov [EntryPoint],eax            ; CS:IP entry point
751                 mov esi,P_ESI
752                 mov edx,P_EBX
753                 mov bx,P_DS
754                 jmp replace_bootstrap
755 .error:
756                 stc
757                 ret
760 ; INT 22h AX=0013h      Idle call
763 ; *** FIX THIS ***
764 ; The idle call seems to have detrimental effects on some machines when
765 ; called from a COM32 context (WHY?) --  disable it for now.
766 ; *** IS THIS STILL TRUE? ***
768 %ifdef HAVE_IDLE
769 comapi_idle:
770                 DO_IDLE
771                 clc
772                 ret
774 %else
775 comapi_idle     equ comapi_err
776 %endif
779 ; INT 22h AX=0014h      Local boot
781 %if HAS_LOCALBOOT
782 comapi_localboot:
783                 mov ax,P_DX
784                 jmp local_boot
785 %else
786 comapi_localboot equ comapi_err
787 %endif ; HAS_LOCALBOOT
790 ; INT 22h AX=0015h      Feature flags
792 comapi_features:
793                 mov P_ES,cs
794                 mov P_BX,feature_flags
795                 mov P_CX,feature_flags_len
796                 clc
797                 ret
800 ; INT 22h AX=0016h      Run kernel image
802 comapi_runkernel:
803                 mov al,P_DL
804                 cmp al,VK_TYPES-1
805                 ja .error
806                 mov [KernelType],al
807                 push ds
808                 mov ds,P_DS
809                 mov si,P_SI
810                 mov di,KernelName
811                 call mangle_name
812                 pop ds
813                 call searchdir
814                 jz comapi_err
816                 ; The kernel image was found, so we can load it...
817                 mov [Kernel_SI],si
818                 mov [Kernel_EAX],eax
820                 ; It's not just possible, but quite likely, that ES:BX
821                 ; points into real_mode_seg, so we need to exercise some
822                 ; special care here... use xfer_buf_seg as an intermediary
823                 push ds
824                 push es
825                 mov ax,xfer_buf_seg
826                 mov ds,P_ES
827                 mov si,P_BX
828                 mov es,ax
829                 xor di,di
830                 call strcpy
831                 pop es
832                 pop ds
834 %if IS_PXELINUX
835                 mov al,P_CL
836                 mov [IPAppend],al
837 %endif
839                 call comboot_exit
841 .finish:
842                 ; Copy the command line into its proper place
843                 push ds
844                 push es
845                 mov ax,xfer_buf_seg
846                 mov dx,real_mode_seg
847                 mov ds,ax
848                 mov es,dx
849                 xor si,si
850                 mov di,cmd_line_here
851                 call strcpy
852                 mov byte [es:di-1],' '          ; Simulate APPEND
853                 pop es
854                 pop ds
855                 mov [CmdLinePtr],di
856                 mov word [CmdOptPtr],zero_string
857                 jmp kernel_good_saved
859 .error          equ comapi_shuffle.error
862 ; INT 22h AX=0017h  Report video mode change
864 comapi_usingvga:
865                 mov ax,P_BX
866                 cmp ax,0Fh              ; Unknown flags = failure
867                 ja .error
868                 mov [UsingVGA],al
869                 mov cx,P_CX
870                 mov dx,P_DX
871                 mov [GXPixCols],cx
872                 mov [GXPixRows],dx
873                 test al,08h
874                 jnz .notext
875                 call adjust_screen
876 .notext:
877                 clc
878                 ret
879 .error:
880                 stc
881                 ret
884 ; INT 22h AX=0018h  Query custom font
886 comapi_userfont:
887                 mov al,[UserFont]
888                 and al,al
889                 jz .done
890                 mov al,[VGAFontSize]
891                 mov P_ES,ds
892                 mov P_BX,vgafontbuf
894 .done:          ; CF=0 here
895                 mov P_AL,al
896                 ret
899 ; INT 22h AX=0019h  Read disk
901 %if IS_SYSLINUX || IS_MDSLINUX || IS_ISOLINUX || IS_EXTLINUX
902 comapi_readdisk:
903                 mov esi,P_ESI           ; Enforce ESI == EDI == 0, these
904                 or esi,P_EDI            ; are reserved for future expansion
905                 jnz .err
906                 mov eax,P_EDX
907                 mov es,P_ES
908                 mov bx,P_BX
909                 mov bp,P_CX             ; WE CANNOT use P_* after touching bp!
910                 call getlinsec
911                 clc
912                 ret
913 .err:
914                 stc
915                 ret
916 %else
917 comapi_readdisk equ comapi_err
918 %endif
921 ; INT 22h AX=001Ah      Cleanup, shuffle and boot to flat protected mode
923 comapi_shufflepm:
924                 cmp P_CX,(2*trackbufsize)/12
925                 ja .error
927                 call comapi_cleanup
929                 mov cx, P_CX
930                 push cx                         ; On stack: descriptor count
932                 lea cx,[ecx+ecx*2]              ; CX *= 3
934                 mov fs,P_ES
935                 mov si,P_DI
936                 mov di,trackbuf
937                 push di                         ; On stack: descriptor list address
938                 fs rep movsd                    ; Copy the list
940                 mov fs,P_DS
941                 mov si,P_SI
942                 mov edi,TrampolineBuf
943                 mov al,0B8h                     ; MOV EAX opcode
944                 mov cl,9
945 .maketramp:
946                 stosb                           ; MOV opcode
947                 inc ax                          ; Next register opcode
948                 fs movsd                        ; immediate value
949                 loop .maketramp
950                 mov byte [di-5],0E9h            ; Last opcode is JMP
951                 sub [di-4],edi                  ; Make JMP target relative
953                 mov dword [EntryPoint],trampoline_to_pm
954                 xor bx,bx                       ; DS on entry
955                 jmp replace_bootstrap
956 .error:
957                 stc
958                 ret
961 ; INT 22h AX=001Bh      Cleanup, shuffle and boot with register setting
963 comapi_shufflerm:
964                 cmp P_CX,(2*trackbufsize)/12
965                 ja .error
967                 call comapi_cleanup
969                 mov cx, P_CX
970                 push cx                         ; On stack: descriptor count
972                 lea cx,[ecx+ecx*2]              ; CX *= 3
974                 mov fs,P_ES
975                 mov si,P_DI
976                 mov di,trackbuf
977                 push di                         ; On stack: descriptor list address
978                 fs rep movsd                    ; Copy the list
980                 mov fs,P_DS
981                 mov si,P_SI
982                 mov di,TrampolineBuf
984                 ; Generate segment-loading instructions
985                 mov bx,0C08Eh                   ; MOV ES,AX
986                 mov cl,6                        ; 6 segment registers (incl CS)
987 .segtramp:
988                 mov al,0B8h
989                 stosb                           ; MOV AX,imm16 opcode
990                 fs movsw                        ; imm16
991                 mov ax,bx
992                 add bh,8
993                 stosw                           ; MOV xS,AX
994                 loop .segtramp
996                 ; Clobber the MOV CS,AX instruction.
997                 mov word [di-22], 9090h         ; NOP NOP
999                 ; Generate GPR-loading instructions
1000                 mov ax,0B866h                   ; MOV EAX,imm32
1001                 mov cl,8                        ; 8 GPRs
1002 .gprtramp:
1003                 stosw                           ; MOV ExX,imm32 opcode
1004                 fs movsd                        ; imm32
1005                 inc ah
1006                 loop .gprtramp
1008                 mov al,0EAh                     ; JMP FAR imm16:imm16 opcode
1009                 stosb
1010                 fs movsd                        ; CS:IP
1012                 mov dword [EntryPoint],TrampolineBuf
1013                 jmp replace_bootstrap
1014 .error:
1015                 stc
1016                 ret
1019 ; INT 22h AX=001Ch      Get pointer to auxillary data vector
1021 comapi_getadv:
1022                 mov P_ES,ds
1023                 mov P_BX,adv0.data
1024                 mov P_CX,ADV_LEN
1025                 ret
1028 ; INT 22h AX=001Dh      Write auxillary data vector
1030 comapi_writeadv equ adv_write
1032                 section .data
1034 %macro          int21 2
1035                 db %1
1036                 dw %2
1037 %endmacro
1039 int21_table:
1040                 int21   00h, comboot_return
1041                 int21   01h, comboot_getkey
1042                 int21   02h, comboot_writechr
1043                 int21   04h, comboot_writeserial
1044                 int21   08h, comboot_getkeynoecho
1045                 int21   09h, comboot_writestr
1046                 int21   0Bh, comboot_checkkey
1047                 int21   30h, comboot_checkver
1048                 int21   4Ch, comboot_return
1049                 int21    -1, comboot_bad_int21
1050 int21_count     equ ($-int21_table)/3
1052                 align 2, db 0
1053 int22_table:
1054                 dw comapi_err           ; 0000 unimplemented syscall
1055                 dw comapi_get_version   ; 0001 get SYSLINUX version
1056                 dw comapi_writestr      ; 0002 write string
1057                 dw comapi_run           ; 0003 run specified command
1058                 dw comapi_run_default   ; 0004 run default command
1059                 dw comapi_textmode      ; 0005 force text mode
1060                 dw comapi_open          ; 0006 open file
1061                 dw comapi_read          ; 0007 read file
1062                 dw comapi_close         ; 0008 close file
1063                 dw comapi_pxecall       ; 0009 call PXE stack
1064                 dw comapi_derinfo       ; 000A derivative-specific info
1065                 dw comapi_serialcfg     ; 000B get serial port config
1066                 dw comapi_cleanup       ; 000C perform final cleanup
1067                 dw comapi_chainboot     ; 000D clean up then bootstrap
1068                 dw comapi_configfile    ; 000E get name of config file
1069                 dw comapi_ipappend      ; 000F get ipappend strings
1070                 dw comapi_dnsresolv     ; 0010 resolve hostname
1071                 dw comapi_maxshuffle    ; 0011 maximum shuffle descriptors
1072                 dw comapi_shuffle       ; 0012 cleanup, shuffle and boot
1073                 dw comapi_idle          ; 0013 idle call
1074                 dw comapi_localboot     ; 0014 local boot
1075                 dw comapi_features      ; 0015 feature flags
1076                 dw comapi_runkernel     ; 0016 run kernel image
1077                 dw comapi_usingvga      ; 0017 report video mode change
1078                 dw comapi_userfont      ; 0018 query custom font
1079                 dw comapi_readdisk      ; 0019 read disk
1080                 dw comapi_shufflepm     ; 001A cleanup, shuffle and boot to pm
1081                 dw comapi_shufflerm     ; 001B cleanup, shuffle and boot to rm
1082                 dw comapi_getadv        ; 001C get pointer to ADV
1083                 dw comapi_writeadv      ; 001D write ADV to disk
1084 int22_count     equ ($-int22_table)/2
1086 APIKeyWait      db 0
1087 APIKeyFlag      db 0
1089 zero_string     db 0                    ; Empty, null-terminated string
1092 ; This is the feature flag array for INT 22h AX=0015h
1094 ; Note: PXELINUX clears the idle is noop flag if appropriate
1095 ; in pxe_detect_nic_type
1097 feature_flags:
1098                 db 3                    ; Have local boot, idle is noop
1099 feature_flags_len equ ($-feature_flags)
1101 err_notdos      db ': attempted DOS system call INT ',0
1102 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
1104                 section .bss1
1105                 alignb 4
1106 DOSErrTramp     resd    33              ; Error trampolines
1107 ConfigName      resb    FILENAME_MAX