ISOLINUX: Change DriveNo -> DriveNumber
[profile/ivi/syslinux.git] / comboot.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2007 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.
10 ;;
11 ;; -----------------------------------------------------------------------
12
13 ;;
14 ;; comboot.inc
15 ;;
16 ;; Common code for running a COMBOOT image
17 ;;
18
19                 section .text
20
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]
61
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
67
68 ;
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.
72 ;
73 is_comboot_image:
74                 and dx,dx
75                 jnz comboot_too_large
76                 cmp ax,0ff00h           ; Max size in bytes
77                 jae comboot_too_large
78
79                 push si                 ; Save file handle
80
81                 call make_plain_cmdline
82
83                 call comboot_setup_api
84
85                 mov cx,comboot_seg
86                 mov es,cx
87
88                 xor di,di
89                 mov cx,64               ; 256 bytes (size of PSP)
90                 xor eax,eax             ; Clear PSP
91                 rep stosd
92
93                 mov word [es:0], 020CDh ; INT 20h instruction
94                 ; First non-free paragraph
95                 ; This is valid because comboot_seg == real_mode_seg
96                 ; == the highest segment used by all derivatives
97                 int 12h                 ; Get DOS memory size
98                 shl ax,6                ; Kilobytes -> paragraphs
99                 mov word [es:02h],ax
100
101 %ifndef DEPEND
102 %if real_mode_seg != comboot_seg
103 %error "This code assumes real_mode_seg == comboot_seg"
104 %endif
105 %endif
106                 ; Copy the command line from high memory
107                 mov si,cmd_line_here
108                 mov cx,125              ; Max cmdline len (minus space and CR)
109                 mov di,081h             ; Offset in PSP for command line
110                 mov al,' '              ; DOS command lines begin with a space
111                 stosb
112
113 .loop:          es lodsb
114                 and al,al
115                 jz .done
116                 stosb
117                 loop .loop
118 .done:
119
120                 mov al,0Dh              ; CR after last character
121                 stosb
122                 mov ax,di
123                 sub al,82h              ; Include space but not CR
124                 mov [es:80h],al         ; Store command line length
125
126                 ; Now actually load the file...
127                 pop si                  ; File handle
128                 mov bx,100h             ; Load at <seg>:0100h
129                 mov cx,0FF00h >> SECTOR_SHIFT
130                                         ; Absolute maximum # of sectors
131                 call getfssec
132
133                 ; And invoke the program...
134                 mov ax,es
135                 mov ds,ax
136                 mov ss,ax
137                 xor sp,sp
138                 push word 0             ; Return to address 0 -> exit
139
140                 jmp comboot_seg:100h    ; Run it
141
142 ; Proper return vector
143 comboot_return: cli                     ; Don't trust anyone
144                 push enter_command      ; Normal return to command prompt
145                 jmp comboot_exit
146
147 ;
148 ; Set up the COMBOOT API interrupt vectors.  This is also used
149 ; by the COM32 code.
150 ;
151 comboot_setup_api:
152                 mov di,4*0x20           ; DOS interrupt vectors
153                 mov eax,comboot_return  ; INT 20h = exit
154                 stosd
155                 mov ax,comboot_int21    ; INT 21h = DOS-compatible syscalls
156                 stosd
157                 mov ax,comboot_int22    ; INT 22h = proprietary syscalls
158                 stosd
159                 mov ax,comboot_bogus
160                 mov cx,29               ; All remaining DOS vectors
161                 rep stosd
162                 ret
163
164 ; INT 21h: generic DOS system call
165 comboot_int21:  cli
166                 push ds
167                 push es
168                 push fs
169                 push gs
170                 pushad
171                 cld
172                 mov bp,cs
173                 mov ds,bp
174                 mov es,bp
175                 mov bp,sp                       ; Set up stack frame
176
177                 call adjust_screen              ; The COMBOOT program might have changed the screen
178
179                 mov cx,int21_count
180                 mov si,int21_table
181 .again:         lodsb
182                 cmp al,P_AH
183                 lodsw
184                 loopne .again
185                 ; The last function in the list is the
186                 ; "no such function" function
187                 clc
188                 call ax                 ; Call the invoked function
189 comboot_resume:
190                 mov bp,sp               ; In case the function clobbers BP
191                 setc P_FLAGSL           ; Propagate CF->error
192                 popad
193                 pop gs
194                 pop fs
195                 pop es
196                 pop ds
197                 iret
198
199 ; Attempted to execute non-21h DOS system call
200 comboot_bogus:  cli                     ; Don't trust anyone
201                 mov cx,err_notdos
202                 push enter_command
203                 jmp comboot_exit_msg
204
205 ;
206 ; Generic COMBOOT return to command line code
207 ;  stack -> where to go next
208 ;     CX -> message (for _msg version)
209 ;
210 comboot_exit:
211                 xor cx,cx
212 comboot_exit_msg:
213                 pop bx                  ; Return address
214                 RESET_STACK_AND_SEGS AX
215                 call adjust_screen      ; The COMBOOT program might have changed the screen
216                 jcxz .nomsg
217                 mov si,KernelCName
218                 call cwritestr
219                 mov si,cx
220                 call cwritestr
221 .nomsg:
222                 jmp bx
223
224 ;
225 ; INT 21h system calls
226 ;
227 comboot_getkey:                         ; 01 = get key with echo
228                 call vgashowcursor
229                 call comboot_getchar
230                 call vgahidecursor
231                 call writechr
232                 clc
233                 ret
234
235 comboot_writechr:                       ; 02 = writechr
236                 mov al,P_DL
237                 call writechr
238                 clc
239                 ret
240
241 comboot_writeserial:                    ; 04 = write serial port
242                 mov al,P_DL
243                 call write_serial
244                 clc
245                 ret
246
247 comboot_getkeynoecho:                   ; 08 = get key w/o echo
248                 call comboot_getchar
249                 clc
250                 ret
251
252 comboot_writestr:                       ; 09 = write DOS string
253                 mov es,P_DS
254                 mov si,P_DX
255 .loop:          es lodsb
256                 cmp al,'$'              ; End string with $ - bizarre
257                 je .done
258                 call writechr
259                 jmp short .loop
260 .done:          clc
261                 ret
262
263 comboot_checkkey:                       ; 0B = check keyboard status
264                 cmp byte [APIKeyFlag],00h
265                 jnz .waiting
266                 call pollchar
267 .waiting:       setz al
268                 dec al                  ; AL = 0FFh if present, 0 if not
269                 mov P_AL,al
270                 clc
271                 ret
272
273 comboot_checkver:                       ; 30 = check DOS version
274                 ; We return 0 in all DOS-compatible version registers,
275                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
276                 mov P_EAX,'SY' << 16
277                 mov P_EBX,'SL' << 16
278                 mov P_ECX,'IN' << 16
279                 mov P_EDX,'UX' << 16
280                 ret
281
282 comboot_getchar:
283                 cmp byte [APIKeyFlag],00h
284                 jne .queued
285                 call getchar            ; If not queued get input
286                 and al,al               ; Function key?  (CF <- 0)
287                 jnz .done
288                 mov [APIKeyWait],ah     ; High part of key
289                 inc byte [APIKeyFlag]   ; Set flag
290 .done:          mov P_AL,al
291                 ret
292 .queued:        mov al,[APIKeyWait]
293                 dec byte [APIKeyFlag]
294                 jmp .done
295
296 ;
297 ; INT 22h - SYSLINUX-specific system calls
298 ;           System call number in ax
299 ;
300 comboot_int22:
301                 cli
302                 push ds
303                 push es
304                 push fs
305                 push gs
306                 pushad
307                 cld
308                 mov bp,cs
309                 mov ds,bp
310                 mov es,bp
311                 mov bp,sp                       ; Set up stack frame
312
313                 call adjust_screen              ; The COMBOOT program might have changed the screen
314
315                 cmp ax,int22_count
316                 jb .ok
317                 xor ax,ax                       ; Function 0 -> unimplemented
318 .ok:
319                 xchg ax,bx
320                 add bx,bx                       ; CF <- 0
321                 call [bx+int22_table]
322                 jmp comboot_resume              ; On return
323
324 ;
325 ; INT 22h AX=0000h      Unimplemented call
326 ;
327 comapi_err:
328                 stc
329                 ret
330
331 ;
332 ; INT 22h AX=0001h      Get SYSLINUX version
333 ;
334 comapi_get_version:
335                 ; Number of API functions supported
336                 mov P_AX,int22_count
337                 ; SYSLINUX version
338                 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
339                 ; SYSLINUX derivative ID byte
340                 mov P_DX,my_id
341                 ; For future use
342                 mov P_BX,cs     ; cs == 0
343
344                 mov P_ES,ds
345                 ; ES:SI -> version banner
346                 mov P_SI,syslinux_banner
347                 ; ES:DI -> copyright string
348                 mov P_DI,copyright_str
349
350 comapi_nop:
351                 clc
352                 ret
353
354 ;
355 ; INT 22h AX=0002h      Write string
356 ;
357 ; Write null-terminated string in ES:BX
358 ;
359 comapi_writestr:
360                 mov ds,P_ES
361                 mov si,P_BX
362                 call writestr
363                 clc
364                 ret
365
366 ;
367 ; INT 22h AX=0003h      Run command
368 ;
369 ; Terminates the COMBOOT program and executes the command line in
370 ; ES:BX as if it had been entered by the user.
371 ;
372 comapi_run:
373                 mov ds,P_ES
374                 mov si,P_BX
375                 mov di,command_line
376                 call strcpy
377                 push load_kernel                ; Run a new kernel
378                 jmp comboot_exit                ; Terminate task, clean up
379
380 ;
381 ; INT 22h AX=0004h      Run default command
382 ;
383 ; Terminates the COMBOOT program and executes the default command line
384 ; as if a timeout had happened or the user pressed <Enter>.
385 ;
386 comapi_run_default:
387                 push auto_boot
388                 jmp comboot_exit
389
390 ;
391 ; INT 22h AX=0005h      Force text mode
392 ;
393 ; Puts the video in standard text mode
394 ;
395 comapi_textmode:
396                 call vgaclearmode
397                 clc
398                 ret
399
400 ;
401 ; INT 22h AX=0006h      Open file
402 ;
403 comapi_open:
404                 push ds
405                 mov ds,P_ES
406                 mov si,P_SI
407                 mov di,InitRD
408                 call mangle_name
409                 pop ds
410                 call searchdir
411                 jz comapi_err
412                 mov P_AX,ax
413                 mov P_HAX,dx
414                 mov P_CX,SECTOR_SIZE
415                 mov P_SI,si
416                 clc
417                 ret
418
419 ;
420 ; INT 22h AX=0007h      Read file
421 ;
422 comapi_read:
423                 mov es,P_ES
424                 mov bx,P_BX
425                 mov si,P_SI
426                 mov cx,P_CX
427                 call getfssec
428                 jnc .noteof
429                 xor si,si               ; SI <- 0 on EOF, CF <- 0
430 .noteof:        mov P_SI,si
431                 ret
432
433 ;
434 ; INT 22h AX=0008h      Close file
435 ;
436 comapi_close:
437                 mov si,P_SI
438                 call close_file
439                 clc
440                 ret
441
442 ;
443 ; INT 22h AX=0009h      Call PXE stack
444 ;
445 %if IS_PXELINUX
446 comapi_pxecall:
447                 mov bx,P_BX
448                 mov es,P_ES
449                 mov di,P_DI
450                 call pxenv
451                 mov P_AX,ax
452                 clc
453                 ret
454 %else
455 comapi_pxecall  equ comapi_err                  ; Not available
456 %endif
457
458 ;
459 ; INT 22h AX=000Ah      Get Derivative-Specific Info
460 ;
461 comapi_derinfo:
462                 mov P_AL,my_id
463 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
464                 mov al,[DriveNumber]
465                 mov P_DL,al
466                 mov P_ES,cs
467                 mov P_BX,PartInfo
468                 mov P_CL,SECTOR_SHIFT
469 %elif IS_PXELINUX
470                 mov ax,[APIVer]
471                 mov P_DX,ax
472                 mov ax,[StrucPtr]
473                 mov P_BX,ax
474                 mov ax,[StrucPtr+2]
475                 mov P_ES,ax
476                 mov ax,[InitStack]
477                 mov P_SI,ax
478                 mov ax,[InitStack+2]
479                 mov P_FS,ax
480 %elif IS_ISOLINUX
481                 mov al,[DriveNumber]
482                 mov P_DL,al
483                 mov P_ES,cs
484                 mov P_BX,spec_packet
485                 mov P_CL,SECTOR_SHIFT
486 %endif
487                 clc
488                 ret
489
490 ;
491 ; INT 22h AX=000Bh      Get Serial Console Configuration
492 ;
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
509
510 ;
511 ; INT 22h AX=000Ch      Perform final cleanup
512 ;
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
532
533 ;
534 ; INT 22h AX=000Dh      Clean up then replace bootstrap
535 ;
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
549
550
551 ;
552 ; INT 22h AX=000Eh      Get configuration file name
553 ;
554 comapi_configfile:
555                 mov P_ES,cs
556                 mov P_BX,ConfigName
557                 clc
558                 ret
559
560 ;
561 ; INT 22h AX=000Fh      Get IPAPPEND strings
562 ;
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
570
571                 section .data
572                 alignb 2, db 0
573 IPAppends       dw IPOption
574                 dw BOOTIFStr
575 numIPAppends    equ ($-IPAppends)/2
576
577 %else
578 comapi_ipappend equ comapi_err
579 %endif
580
581                 section .text
582
583 ;
584 ; INT 22h AX=0010h      Resolve hostname
585 ;
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                 ret
593 %else
594 comapi_dnsresolv equ comapi_err
595 %endif
596
597                 section .text
598
599 ;
600 ; INT 22h AX=0011h      Maximum number of shuffle descriptors
601 ;
602 comapi_maxshuffle:
603                 mov P_CX,(2*trackbufsize)/12
604                 ret
605
606 ;
607 ; INT 22h AX=0012h      Cleanup, shuffle and boot
608 ;
609 comapi_shuffle:
610                 cmp P_CX,(2*trackbufsize)/12
611                 ja .error
612
613                 call comapi_cleanup
614
615                 mov cx, P_CX
616                 push cx                         ; On stack: descriptor count
617
618                 lea cx,[ecx+ecx*2]              ; CX *= 3
619
620                 mov fs,P_ES
621                 mov si,P_DI
622                 mov di,trackbuf
623                 push di                         ; On stack: descriptor list address
624                 fs rep movsd                    ; Copy the list
625
626                 mov eax,P_EBP
627                 mov [EntryPoint],eax            ; CS:IP entry point
628                 mov esi,P_ESI
629                 mov edx,P_EBX
630                 mov bx,P_DS
631                 jmp replace_bootstrap
632 .error:
633                 stc
634                 ret
635
636 ;
637 ; INT 22h AX=0013h      Idle call
638 ;
639 ;
640 ; *** FIX THIS ***
641 ; The idle call seems to have detrimental effects on some machines when
642 ; called from a COM32 context (WHY?) --  disable it for now.
643 ;
644 %if 0 ; def HAVE_IDLE
645
646 comapi_idle:
647                 DO_IDLE
648                 clc
649                 ret
650
651 %else
652
653 comapi_idle     equ comapi_err
654
655 %endif
656
657 ;
658 ; INT 22h AX=0014h      Local boot
659 ;
660 %if IS_PXELINUX || IS_ISOLINUX
661 comapi_localboot:
662                 mov ax,P_DX
663                 jmp local_boot
664 %else
665 comapi_localboot equ comapi_err
666 %endif
667
668 ;
669 ; INT 22h AX=0015h      Feature flags
670 ;
671 comapi_features:
672                 mov P_ES,cs
673                 mov P_BX,feature_flags
674                 mov P_CX,feature_flags_len
675                 clc
676                 ret
677
678 ;
679 ; INT 22h AX=0016h      Run kernel image
680 ;
681 comapi_runkernel:
682                 mov al,P_DL
683                 cmp al,VK_TYPES-1
684                 ja .error
685                 mov [KernelType],al
686                 push ds
687                 mov ds,P_DS
688                 mov si,P_SI
689                 mov di,KernelName
690                 call mangle_name
691                 pop ds
692                 call searchdir
693                 jz comapi_err
694
695                 ; The kernel image was found, so we can load it...
696                 mov [Kernel_SI],si
697                 mov [Kernel_EAX],ax
698                 mov [Kernel_EAX+2],dx
699
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
713
714 %if IS_PXELINUX
715                 mov al,P_CL
716                 mov [IPAppend],al
717 %endif
718
719                 call comboot_exit
720
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
738
739 .error          equ comapi_shuffle.error
740
741 ;
742 ; INT 22h AX=0017h  Report video mode change
743 ;
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
762
763 ;
764 ; INT 22h AX=0018h  Query custom font
765 ;
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
773
774 .done:          ; CF=0 here
775                 mov P_AL,al
776                 ret
777
778 ;
779 ; INT 22h AX=0019h  Read disk
780 ;
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
799
800 ;
801 ; INT 22h AX=001Ah      Cleanup, shuffle and boot to flat protected mode
802 ;
803 comapi_shufflepm:
804                 cmp P_CX,(2*trackbufsize)/12
805                 ja .error
806
807                 call comapi_cleanup
808
809                 mov cx, P_CX
810                 push cx                         ; On stack: descriptor count
811
812                 lea cx,[ecx+ecx*2]              ; CX *= 3
813
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
819
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
832
833                 mov dword [EntryPoint],trampoline_to_pm
834                 xor bx,bx                       ; DS on entry
835                 jmp replace_bootstrap
836 .error:
837                 stc
838                 ret
839
840 ;
841 ; INT 22h AX=001Bh      Cleanup, shuffle and boot with register setting
842 ;
843 comapi_shufflerm:
844                 cmp P_CX,(2*trackbufsize)/12
845                 ja .error
846
847                 call comapi_cleanup
848
849                 mov cx, P_CX
850                 push cx                         ; On stack: descriptor count
851
852                 lea cx,[ecx+ecx*2]              ; CX *= 3
853
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
859
860                 mov fs,P_DS
861                 mov si,P_SI
862                 mov di,TrampolineBuf
863
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
875
876                 ; Clobber the MOV CS,AX instruction.
877                 mov word [di-22], 9090h         ; NOP NOP
878
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
887
888                 mov al,0EAh                     ; JMP FAR imm16:imm16 opcode
889                 stosb
890                 fs movsd                        ; CS:IP
891
892                 mov dword [EntryPoint],TrampolineBuf
893                 jmp replace_bootstrap
894 .error:
895                 stc
896                 ret
897
898                 section .data
899
900 %macro          int21 2
901                 db %1
902                 dw %2
903 %endmacro
904
905 int21_table:
906                 int21   00h, comboot_return
907                 int21   01h, comboot_getkey
908                 int21   02h, comboot_writechr
909                 int21   04h, comboot_writeserial
910                 int21   08h, comboot_getkeynoecho
911                 int21   09h, comboot_writestr
912                 int21   0Bh, comboot_checkkey
913                 int21   30h, comboot_checkver
914                 int21   4Ch, comboot_return
915                 int21    -1, comboot_bogus
916 int21_count     equ ($-int21_table)/3
917
918                 align 2, db 0
919 int22_table:
920                 dw comapi_err           ; 0000 unimplemented syscall
921                 dw comapi_get_version   ; 0001 get SYSLINUX version
922                 dw comapi_writestr      ; 0002 write string
923                 dw comapi_run           ; 0003 run specified command
924                 dw comapi_run_default   ; 0004 run default command
925                 dw comapi_textmode      ; 0005 force text mode
926                 dw comapi_open          ; 0006 open file
927                 dw comapi_read          ; 0007 read file
928                 dw comapi_close         ; 0008 close file
929                 dw comapi_pxecall       ; 0009 call PXE stack
930                 dw comapi_derinfo       ; 000A derivative-specific info
931                 dw comapi_serialcfg     ; 000B get serial port config
932                 dw comapi_cleanup       ; 000C perform final cleanup
933                 dw comapi_chainboot     ; 000D clean up then bootstrap
934                 dw comapi_configfile    ; 000E get name of config file
935                 dw comapi_ipappend      ; 000F get ipappend strings
936                 dw comapi_dnsresolv     ; 0010 resolve hostname
937                 dw comapi_maxshuffle    ; 0011 maximum shuffle descriptors
938                 dw comapi_shuffle       ; 0012 cleanup, shuffle and boot
939                 dw comapi_idle          ; 0013 idle call
940                 dw comapi_localboot     ; 0014 local boot
941                 dw comapi_features      ; 0015 feature flags
942                 dw comapi_runkernel     ; 0016 run kernel image
943                 dw comapi_usingvga      ; 0017 report video mode change
944                 dw comapi_userfont      ; 0018 query custom font
945                 dw comapi_readdisk      ; 0019 read disk
946                 dw comapi_shufflepm     ; 001A cleanup, shuffle and boot to pm
947                 dw comapi_shufflerm     ; 001B cleanup, shuffle and boot to rm
948 int22_count     equ ($-int22_table)/2
949
950 APIKeyWait      db 0
951 APIKeyFlag      db 0
952
953 zero_string     db 0                    ; Empty, null-terminated string
954
955 ;
956 ; This is the feature flag array for INT 22h AX=0015h
957 feature_flags:
958 %if IS_PXELINUX
959                 db 1                    ; Have local boot, idle not noop
960 %elif IS_ISOLINUX
961                 db 3                    ; Have local boot, idle is noop
962 %else
963                 db 2                    ; No local boot, idle is noop
964 %endif
965 feature_flags_len equ ($-feature_flags)
966
967 err_notdos      db ': attempted DOS system call', CR, LF, 0
968 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
969
970                 section .bss1
971 ConfigName      resb    FILENAME_MAX