Revamp runkernel.inc for "lengthless" operation
[syslinux.git] / comboot.inc
blob7c0f40f728da5070fc29e38702800100a2f8d8cd
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_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
63 comboot_too_large:
64                 mov si,err_comlarge
65                 call cwritestr
66                 jmp enter_command
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.
73 is_comboot_image:
74                 cmp eax,0ff00h          ; Max size in bytes
75                 jae comboot_too_large
77                 push si                 ; Save file handle
79                 call make_plain_cmdline
81                 call comboot_setup_api
83                 mov cx,comboot_seg
84                 mov es,cx
86                 xor di,di
87                 mov cx,64               ; 256 bytes (size of PSP)
88                 xor eax,eax             ; Clear PSP
89                 rep stosd
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
97                 mov word [es:02h],ax
99 %ifndef DEPEND
100 %if real_mode_seg != comboot_seg
101 %error "This code assumes real_mode_seg == comboot_seg"
102 %endif
103 %endif
104                 ; Copy the command line from high memory
105                 mov si,cmd_line_here
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
109                 stosb
111 .loop:          es lodsb
112                 and al,al
113                 jz .done
114                 stosb
115                 loop .loop
116 .done:
118                 mov al,0Dh              ; CR after last character
119                 stosb
120                 mov ax,di
121                 sub al,82h              ; Include space but not CR
122                 mov [es:80h],al         ; Store command line length
124                 ; Now actually load the file...
125                 pop si                  ; File handle
126                 mov bx,100h             ; Load at <seg>:0100h
127                 mov cx,0FF00h >> SECTOR_SHIFT
128                                         ; Absolute maximum # of sectors
129                 call getfssec
131                 ; And invoke the program...
132                 mov ax,es
133                 mov ds,ax
134                 mov ss,ax
135                 xor sp,sp
136                 push word 0             ; Return to address 0 -> exit
138                 jmp comboot_seg:100h    ; Run it
140 ; Proper return vector
141 comboot_return: cli                     ; Don't trust anyone
142                 push enter_command      ; Normal return to command prompt
143                 jmp comboot_exit
146 ; Set up the COMBOOT API interrupt vectors.  This is also used
147 ; by the COM32 code.
149 comboot_setup_api:
150                 mov di,4*0x20           ; DOS interrupt vectors
151                 mov eax,comboot_return  ; INT 20h = exit
152                 stosd
153                 mov ax,comboot_int21    ; INT 21h = DOS-compatible syscalls
154                 stosd
155                 mov ax,comboot_int22    ; INT 22h = proprietary syscalls
156                 stosd
157                 mov ax,comboot_bogus
158                 mov cx,29               ; All remaining DOS vectors
159                 rep stosd
160                 ret
162 ; INT 21h: generic DOS system call
163 comboot_int21:  cli
164                 push ds
165                 push es
166                 push fs
167                 push gs
168                 pushad
169                 cld
170                 mov bp,cs
171                 mov ds,bp
172                 mov es,bp
173                 mov bp,sp                       ; Set up stack frame
175                 call adjust_screen              ; The COMBOOT program might have changed the screen
177                 mov cx,int21_count
178                 mov si,int21_table
179 .again:         lodsb
180                 cmp al,P_AH
181                 lodsw
182                 loopne .again
183                 ; The last function in the list is the
184                 ; "no such function" function
185                 clc
186                 call ax                 ; Call the invoked function
187 comboot_resume:
188                 mov bp,sp               ; In case the function clobbers BP
189                 setc P_FLAGSL           ; Propagate CF->error
190                 popad
191                 pop gs
192                 pop fs
193                 pop es
194                 pop ds
195                 iret
197 ; Attempted to execute non-21h DOS system call
198 comboot_bogus:  cli                     ; Don't trust anyone
199                 mov cx,err_notdos
200                 push enter_command
201                 jmp comboot_exit_msg
204 ; Generic COMBOOT return to command line code
205 ;  stack -> where to go next
206 ;     CX -> message (for _msg version)
208 comboot_exit:
209                 xor cx,cx
210 comboot_exit_msg:
211                 pop bx                  ; Return address
212                 RESET_STACK_AND_SEGS AX
213                 call adjust_screen      ; The COMBOOT program might have changed the screen
214                 jcxz .nomsg
215                 mov si,KernelCName
216                 call cwritestr
217                 mov si,cx
218                 call cwritestr
219 .nomsg:
220                 jmp bx
223 ; INT 21h system calls
225 comboot_getkey:                         ; 01 = get key with echo
226                 call vgashowcursor
227                 call comboot_getchar
228                 call vgahidecursor
229                 call writechr
230                 clc
231                 ret
233 comboot_writechr:                       ; 02 = writechr
234                 mov al,P_DL
235                 call writechr
236                 clc
237                 ret
239 comboot_writeserial:                    ; 04 = write serial port
240                 mov al,P_DL
241                 call write_serial
242                 clc
243                 ret
245 comboot_getkeynoecho:                   ; 08 = get key w/o echo
246                 call comboot_getchar
247                 clc
248                 ret
250 comboot_writestr:                       ; 09 = write DOS string
251                 mov es,P_DS
252                 mov si,P_DX
253 .loop:          es lodsb
254                 cmp al,'$'              ; End string with $ - bizarre
255                 je .done
256                 call writechr
257                 jmp short .loop
258 .done:          clc
259                 ret
261 comboot_checkkey:                       ; 0B = check keyboard status
262                 cmp byte [APIKeyFlag],00h
263                 jnz .waiting
264                 call pollchar
265 .waiting:       setz al
266                 dec al                  ; AL = 0FFh if present, 0 if not
267                 mov P_AL,al
268                 clc
269                 ret
271 comboot_checkver:                       ; 30 = check DOS version
272                 ; We return 0 in all DOS-compatible version registers,
273                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
274                 mov P_EAX,'SY' << 16
275                 mov P_EBX,'SL' << 16
276                 mov P_ECX,'IN' << 16
277                 mov P_EDX,'UX' << 16
278                 ret
280 comboot_getchar:
281                 cmp byte [APIKeyFlag],00h
282                 jne .queued
283                 call getchar            ; If not queued get input
284                 and al,al               ; Function key?  (CF <- 0)
285                 jnz .done
286                 mov [APIKeyWait],ah     ; High part of key
287                 inc byte [APIKeyFlag]   ; Set flag
288 .done:          mov P_AL,al
289                 ret
290 .queued:        mov al,[APIKeyWait]
291                 dec byte [APIKeyFlag]
292                 jmp .done
295 ; INT 22h - SYSLINUX-specific system calls
296 ;           System call number in ax
298 comboot_int22:
299                 cli
300                 push ds
301                 push es
302                 push fs
303                 push gs
304                 pushad
305                 cld
306                 mov bp,cs
307                 mov ds,bp
308                 mov es,bp
309                 mov bp,sp                       ; Set up stack frame
311                 call adjust_screen              ; The COMBOOT program might have changed the screen
313                 cmp ax,int22_count
314                 jb .ok
315                 xor ax,ax                       ; Function 0 -> unimplemented
316 .ok:
317                 xchg ax,bx
318                 add bx,bx                       ; CF <- 0
319                 call [bx+int22_table]
320                 jmp comboot_resume              ; On return
323 ; INT 22h AX=0000h      Unimplemented call
325 comapi_err:
326                 stc
327                 ret
330 ; INT 22h AX=0001h      Get SYSLINUX version
332 comapi_get_version:
333                 ; Number of API functions supported
334                 mov P_AX,int22_count
335                 ; SYSLINUX version
336                 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
337                 ; SYSLINUX derivative ID byte
338                 mov P_DX,my_id
339                 ; For future use
340                 mov P_BX,cs     ; cs == 0
342                 mov P_ES,ds
343                 ; ES:SI -> version banner
344                 mov P_SI,syslinux_banner
345                 ; ES:DI -> copyright string
346                 mov P_DI,copyright_str
348 comapi_nop:
349                 clc
350                 ret
353 ; INT 22h AX=0002h      Write string
355 ; Write null-terminated string in ES:BX
357 comapi_writestr:
358                 mov ds,P_ES
359                 mov si,P_BX
360                 call writestr
361                 clc
362                 ret
365 ; INT 22h AX=0003h      Run command
367 ; Terminates the COMBOOT program and executes the command line in
368 ; ES:BX as if it had been entered by the user.
370 comapi_run:
371                 mov ds,P_ES
372                 mov si,P_BX
373                 mov di,command_line
374                 call strcpy
375                 push load_kernel                ; Run a new kernel
376                 jmp comboot_exit                ; Terminate task, clean up
379 ; INT 22h AX=0004h      Run default command
381 ; Terminates the COMBOOT program and executes the default command line
382 ; as if a timeout had happened or the user pressed <Enter>.
384 comapi_run_default:
385                 push auto_boot
386                 jmp comboot_exit
389 ; INT 22h AX=0005h      Force text mode
391 ; Puts the video in standard text mode
393 comapi_textmode:
394                 call vgaclearmode
395                 clc
396                 ret
399 ; INT 22h AX=0006h      Open file
401 comapi_open:
402                 push ds
403                 mov ds,P_ES
404                 mov si,P_SI
405                 mov di,InitRD
406                 call mangle_name
407                 pop ds
408                 call searchdir
409                 jz comapi_err
410                 mov P_EAX,eax
411                 mov P_CX,SECTOR_SIZE
412                 mov P_SI,si
413                 clc
414                 ret
417 ; INT 22h AX=0007h      Read file
419 comapi_read:
420                 mov es,P_ES
421                 mov bx,P_BX
422                 mov si,P_SI
423                 mov cx,P_CX
424                 call getfssec
425                 jnc .noteof
426                 xor si,si               ; SI <- 0 on EOF, CF <- 0
427 .noteof:        mov P_SI,si
428                 ret
431 ; INT 22h AX=0008h      Close file
433 comapi_close:
434                 mov si,P_SI
435                 call close_file
436                 clc
437                 ret
440 ; INT 22h AX=0009h      Call PXE stack
442 %if IS_PXELINUX
443 comapi_pxecall:
444                 mov bx,P_BX
445                 mov es,P_ES
446                 mov di,P_DI
447                 call pxenv
448                 mov P_AX,ax
449                 clc
450                 ret
451 %else
452 comapi_pxecall  equ comapi_err                  ; Not available
453 %endif
456 ; INT 22h AX=000Ah      Get Derivative-Specific Info
458 comapi_derinfo:
459                 mov P_AL,my_id
460 %if IS_PXELINUX
461                 mov ax,[APIVer]
462                 mov P_DX,ax
463                 mov ax,[StrucPtr]
464                 mov P_BX,ax
465                 mov ax,[StrucPtr+2]
466                 mov P_ES,ax
467                 mov ax,[InitStack]
468                 mov P_SI,ax
469                 mov ax,[InitStack+2]
470                 mov P_FS,ax
471 %else
472                 ; Physical medium...
474                 mov P_CL,SECTOR_SHIFT
475                 mov al,[DriveNumber]
476                 mov P_DL,al
477                 mov P_FS,cs
478                 mov P_SI,OrigESDI
479 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
480                 mov P_ES,cs
481                 mov P_BX,PartInfo
482 %elif IS_ISOLINUX
483                 mov P_ES,cs
484                 mov P_BX,spec_packet
485 %endif
486 %endif
487                 clc
488                 ret
491 ; INT 22h AX=000Bh      Get Serial Console Configuration
493 comapi_serialcfg:
494                 mov ax,[SerialPort]
495                 mov P_DX,ax
496                 mov ax,[BaudDivisor]
497                 mov P_CX,ax
498                 mov ax,[FlowControl]
499                 or al,ah
500                 mov ah,[FlowIgnore]
501                 shr ah,4
502                 test byte [DisplayCon],01h
503                 jnz .normalconsole
504                 or ah,80h
505 .normalconsole:
506                 mov P_BX,ax
507                 clc
508                 ret
511 ; INT 22h AX=000Ch      Perform final cleanup
513 comapi_cleanup:
514 %if IS_PXELINUX
515                 ; Unload PXE if requested
516                 test dl,3
517                 setnz [KeepPXE]
518                 sub bp,sp               ; unload_pxe may move the stack around
519                 call unload_pxe
520                 add bp,sp               ; restore frame pointer...
521 %elif IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
522                 ; Restore original FDC table
523                 mov eax,[OrigFDCTabPtr]
524                 mov [fdctab],eax
525 %endif
526                 ; Reset the floppy disk subsystem
527                 xor ax,ax
528                 xor dx,dx
529                 int 13h
530                 clc
531                 ret
534 ; INT 22h AX=000Dh      Clean up then replace bootstrap
536 comapi_chainboot:
537                 call comapi_cleanup
538                 mov eax,P_EDI
539                 mov [trackbuf+4],eax            ; Copy from
540                 mov eax,P_ECX
541                 mov [trackbuf+8],eax            ; Total bytes
542                 mov eax,7C00h
543                 mov [trackbuf],eax              ; Copy to
544                 mov [EntryPoint],eax            ; CS:IP entry point
545                 mov esi,P_ESI
546                 mov edx,P_EBX
547                 mov bx,P_DS
548                 jmp replace_bootstrap_one
552 ; INT 22h AX=000Eh      Get configuration file name
554 comapi_configfile:
555                 mov P_ES,cs
556                 mov P_BX,ConfigName
557                 clc
558                 ret
561 ; INT 22h AX=000Fh      Get IPAPPEND strings
563 %if IS_PXELINUX
564 comapi_ipappend:
565                 mov P_ES,cs
566                 mov P_CX,numIPAppends
567                 mov P_BX,IPAppends
568                 clc
569                 ret
571                 section .data
572                 alignb 2, db 0
573 IPAppends       dw IPOption
574                 dw BOOTIFStr
575 numIPAppends    equ ($-IPAppends)/2
577 %else
578 comapi_ipappend equ comapi_err
579 %endif
581                 section .text
584 ; INT 22h AX=0010h      Resolve hostname
586 %if IS_PXELINUX
587 comapi_dnsresolv:
588                 mov ds,P_ES
589                 mov si,P_BX
590                 call dns_resolv
591                 mov P_EAX,eax
592                 clc
593                 ret
594 %else
595 comapi_dnsresolv equ comapi_err
596 %endif
598                 section .text
601 ; INT 22h AX=0011h      Maximum number of shuffle descriptors
603 comapi_maxshuffle:
604                 mov P_CX,trackbufsize/12
605                 ret
608 ; INT 22h AX=0012h      Cleanup, shuffle and boot
610 comapi_shuffle:
611                 cmp P_CX,(2*trackbufsize)/12
612                 ja .error
614                 call comapi_cleanup
616                 mov cx, P_CX
617                 push cx                         ; On stack: descriptor count
619                 lea cx,[ecx+ecx*2]              ; CX *= 3
621                 mov fs,P_ES
622                 mov si,P_DI
623                 mov di,trackbuf
624                 push di                         ; On stack: descriptor list address
625                 fs rep movsd                    ; Copy the list
627                 mov eax,P_EBP
628                 mov [EntryPoint],eax            ; CS:IP entry point
629                 mov esi,P_ESI
630                 mov edx,P_EBX
631                 mov bx,P_DS
632                 jmp replace_bootstrap
633 .error:
634                 stc
635                 ret
638 ; INT 22h AX=0013h      Idle call
641 ; *** FIX THIS ***
642 ; The idle call seems to have detrimental effects on some machines when
643 ; called from a COM32 context (WHY?) --  disable it for now.
645 %if 0 ; def HAVE_IDLE
647 comapi_idle:
648                 DO_IDLE
649                 clc
650                 ret
652 %else
654 comapi_idle     equ comapi_err
656 %endif
659 ; INT 22h AX=0014h      Local boot
661 %if IS_PXELINUX || IS_ISOLINUX
662 comapi_localboot:
663                 mov ax,P_DX
664                 jmp local_boot
665 %else
666 comapi_localboot equ comapi_err
667 %endif
670 ; INT 22h AX=0015h      Feature flags
672 comapi_features:
673                 mov P_ES,cs
674                 mov P_BX,feature_flags
675                 mov P_CX,feature_flags_len
676                 clc
677                 ret
680 ; INT 22h AX=0016h      Run kernel image
682 comapi_runkernel:
683                 mov al,P_DL
684                 cmp al,VK_TYPES-1
685                 ja .error
686                 mov [KernelType],al
687                 push ds
688                 mov ds,P_DS
689                 mov si,P_SI
690                 mov di,KernelName
691                 call mangle_name
692                 pop ds
693                 call searchdir
694                 jz comapi_err
696                 ; The kernel image was found, so we can load it...
697                 mov [Kernel_SI],si
698                 mov [Kernel_EAX],eax
700                 ; It's not just possible, but quite likely, that ES:BX
701                 ; points into real_mode_seg, so we need to exercise some
702                 ; special care here... use xfer_buf_seg as an intermediary
703                 push ds
704                 push es
705                 mov ax,xfer_buf_seg
706                 mov ds,P_ES
707                 mov si,P_BX
708                 mov es,ax
709                 xor di,di
710                 call strcpy
711                 pop es
712                 pop ds
714 %if IS_PXELINUX
715                 mov al,P_CL
716                 mov [IPAppend],al
717 %endif
719                 call comboot_exit
721 .finish:
722                 ; Copy the command line into its proper place
723                 push ds
724                 push es
725                 mov ax,xfer_buf_seg
726                 mov dx,real_mode_seg
727                 mov ds,ax
728                 mov es,dx
729                 xor si,si
730                 mov di,cmd_line_here
731                 call strcpy
732                 mov byte [es:di-1],' '          ; Simulate APPEND
733                 pop es
734                 pop ds
735                 mov [CmdLinePtr],di
736                 mov word [CmdOptPtr],zero_string
737                 jmp kernel_good_saved
739 .error          equ comapi_shuffle.error
742 ; INT 22h AX=0017h  Report video mode change
744 comapi_usingvga:
745                 mov ax,P_BX
746                 cmp ax,0Fh              ; Unknown flags = failure
747                 ja .error
748                 mov [UsingVGA],al
749                 mov cx,P_CX
750                 mov dx,P_DX
751                 mov [GXPixCols],cx
752                 mov [GXPixRows],dx
753                 test al,08h
754                 jnz .notext
755                 call adjust_screen
756 .notext:
757                 clc
758                 ret
759 .error:
760                 stc
761                 ret
764 ; INT 22h AX=0018h  Query custom font
766 comapi_userfont:
767                 mov al,[UserFont]
768                 and al,al
769                 jz .done
770                 mov al,[VGAFontSize]
771                 mov P_ES,ds
772                 mov P_BX,vgafontbuf
774 .done:          ; CF=0 here
775                 mov P_AL,al
776                 ret
779 ; INT 22h AX=0019h  Read disk
781 %if IS_SYSLINUX || IS_MDSLINUX || IS_ISOLINUX || IS_EXTLINUX
782 comapi_readdisk:
783                 mov esi,P_ESI           ; Enforce ESI == EDI == 0, these
784                 or esi,P_EDI            ; are reserved for future expansion
785                 jnz .err
786                 mov eax,P_EDX
787                 mov es,P_ES
788                 mov bx,P_BX
789                 mov bp,P_CX             ; WE CANNOT use P_* after touching bp!
790                 call getlinsec
791                 clc
792                 ret
793 .err:
794                 stc
795                 ret
796 %else
797 comapi_readdisk equ comapi_err
798 %endif
801 ; INT 22h AX=001Ah      Cleanup, shuffle and boot to flat protected mode
803 comapi_shufflepm:
804                 cmp P_CX,(2*trackbufsize)/12
805                 ja .error
807                 call comapi_cleanup
809                 mov cx, P_CX
810                 push cx                         ; On stack: descriptor count
812                 lea cx,[ecx+ecx*2]              ; CX *= 3
814                 mov fs,P_ES
815                 mov si,P_DI
816                 mov di,trackbuf
817                 push di                         ; On stack: descriptor list address
818                 fs rep movsd                    ; Copy the list
820                 mov fs,P_DS
821                 mov si,P_SI
822                 mov edi,TrampolineBuf
823                 mov al,0B8h                     ; MOV EAX opcode
824                 mov cl,9
825 .maketramp:
826                 stosb                           ; MOV opcode
827                 inc ax                          ; Next register opcode
828                 fs movsd                        ; immediate value
829                 loop .maketramp
830                 mov byte [di-5],0E9h            ; Last opcode is JMP
831                 sub [di-4],edi                  ; Make JMP target relative
833                 mov dword [EntryPoint],trampoline_to_pm
834                 xor bx,bx                       ; DS on entry
835                 jmp replace_bootstrap
836 .error:
837                 stc
838                 ret
841 ; INT 22h AX=001Bh      Cleanup, shuffle and boot with register setting
843 comapi_shufflerm:
844                 cmp P_CX,(2*trackbufsize)/12
845                 ja .error
847                 call comapi_cleanup
849                 mov cx, P_CX
850                 push cx                         ; On stack: descriptor count
852                 lea cx,[ecx+ecx*2]              ; CX *= 3
854                 mov fs,P_ES
855                 mov si,P_DI
856                 mov di,trackbuf
857                 push di                         ; On stack: descriptor list address
858                 fs rep movsd                    ; Copy the list
860                 mov fs,P_DS
861                 mov si,P_SI
862                 mov di,TrampolineBuf
864                 ; Generate segment-loading instructions
865                 mov bx,0C08Eh                   ; MOV ES,AX
866                 mov cl,6                        ; 6 segment registers (incl CS)
867 .segtramp:
868                 mov al,0B8h
869                 stosb                           ; MOV AX,imm16 opcode
870                 fs movsw                        ; imm16
871                 mov ax,bx
872                 add bh,8
873                 stosw                           ; MOV xS,AX
874                 loop .segtramp
876                 ; Clobber the MOV CS,AX instruction.
877                 mov word [di-22], 9090h         ; NOP NOP
879                 ; Generate GPR-loading instructions
880                 mov ax,0B866h                   ; MOV EAX,imm32
881                 mov cl,8                        ; 8 GPRs
882 .gprtramp:
883                 stosw                           ; MOV ExX,imm32 opcode
884                 fs movsd                        ; imm32
885                 inc ah
886                 loop .gprtramp
888                 mov al,0EAh                     ; JMP FAR imm16:imm16 opcode
889                 stosb
890                 fs movsd                        ; CS:IP
892                 mov dword [EntryPoint],TrampolineBuf
893                 jmp replace_bootstrap
894 .error:
895                 stc
896                 ret
899 ; INT 22h AX=001Ch      Get pointer to auxillary data vector
901 comapi_getadv:
902                 mov P_ES,ds
903                 mov P_BX,adv0.data
904                 mov P_CX,ADV_LEN
905                 ret
908 ; INT 22h AX=001Dh      Write auxillary data vector
910 comapi_writeadv equ adv_write
912                 section .data
914 %macro          int21 2
915                 db %1
916                 dw %2
917 %endmacro
919 int21_table:
920                 int21   00h, comboot_return
921                 int21   01h, comboot_getkey
922                 int21   02h, comboot_writechr
923                 int21   04h, comboot_writeserial
924                 int21   08h, comboot_getkeynoecho
925                 int21   09h, comboot_writestr
926                 int21   0Bh, comboot_checkkey
927                 int21   30h, comboot_checkver
928                 int21   4Ch, comboot_return
929                 int21    -1, comboot_bogus
930 int21_count     equ ($-int21_table)/3
932                 align 2, db 0
933 int22_table:
934                 dw comapi_err           ; 0000 unimplemented syscall
935                 dw comapi_get_version   ; 0001 get SYSLINUX version
936                 dw comapi_writestr      ; 0002 write string
937                 dw comapi_run           ; 0003 run specified command
938                 dw comapi_run_default   ; 0004 run default command
939                 dw comapi_textmode      ; 0005 force text mode
940                 dw comapi_open          ; 0006 open file
941                 dw comapi_read          ; 0007 read file
942                 dw comapi_close         ; 0008 close file
943                 dw comapi_pxecall       ; 0009 call PXE stack
944                 dw comapi_derinfo       ; 000A derivative-specific info
945                 dw comapi_serialcfg     ; 000B get serial port config
946                 dw comapi_cleanup       ; 000C perform final cleanup
947                 dw comapi_chainboot     ; 000D clean up then bootstrap
948                 dw comapi_configfile    ; 000E get name of config file
949                 dw comapi_ipappend      ; 000F get ipappend strings
950                 dw comapi_dnsresolv     ; 0010 resolve hostname
951                 dw comapi_maxshuffle    ; 0011 maximum shuffle descriptors
952                 dw comapi_shuffle       ; 0012 cleanup, shuffle and boot
953                 dw comapi_idle          ; 0013 idle call
954                 dw comapi_localboot     ; 0014 local boot
955                 dw comapi_features      ; 0015 feature flags
956                 dw comapi_runkernel     ; 0016 run kernel image
957                 dw comapi_usingvga      ; 0017 report video mode change
958                 dw comapi_userfont      ; 0018 query custom font
959                 dw comapi_readdisk      ; 0019 read disk
960                 dw comapi_shufflepm     ; 001A cleanup, shuffle and boot to pm
961                 dw comapi_shufflerm     ; 001B cleanup, shuffle and boot to rm
962                 dw comapi_getadv        ; 001C get pointer to ADV
963                 dw comapi_writeadv      ; 001D write ADV to disk
964 int22_count     equ ($-int22_table)/2
966 APIKeyWait      db 0
967 APIKeyFlag      db 0
969 zero_string     db 0                    ; Empty, null-terminated string
972 ; This is the feature flag array for INT 22h AX=0015h
973 feature_flags:
974 %if IS_PXELINUX
975                 db 1                    ; Have local boot, idle not noop
976 %elif IS_ISOLINUX
977                 db 3                    ; Have local boot, idle is noop
978 %else
979                 db 2                    ; No local boot, idle is noop
980 %endif
981 feature_flags_len equ ($-feature_flags)
983 err_notdos      db ': attempted DOS system call', CR, LF, 0
984 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
986                 section .bss1
987 ConfigName      resb    FILENAME_MAX