New API call: cleanup, shuffle and boot to flat protected mode
[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                 setc P_FLAGSL           ; Propagate CF->error
191                 popad
192                 pop gs
193                 pop fs
194                 pop es
195                 pop ds
196                 iret
197
198 ; Attempted to execute non-21h DOS system call
199 comboot_bogus:  cli                     ; Don't trust anyone
200                 mov cx,err_notdos
201                 push enter_command
202                 jmp comboot_exit_msg
203
204 ;
205 ; Generic COMBOOT return to command line code
206 ;  stack -> where to go next
207 ;     CX -> message (for _msg version)
208 ;
209 comboot_exit:
210                 xor cx,cx
211 comboot_exit_msg:
212                 pop bx                  ; Return address
213                 RESET_STACK_AND_SEGS AX
214                 call adjust_screen      ; The COMBOOT program might have changed the screen
215                 jcxz .nomsg
216                 mov si,KernelCName
217                 call cwritestr
218                 mov si,cx
219                 call cwritestr
220 .nomsg:
221                 jmp bx
222
223 ;
224 ; INT 21h system calls
225 ;
226 comboot_getkey:                         ; 01 = get key with echo
227                 call vgashowcursor
228                 call comboot_getchar
229                 call vgahidecursor
230                 call writechr
231                 clc
232                 ret
233
234 comboot_writechr:                       ; 02 = writechr
235                 mov al,P_DL
236                 call writechr
237                 clc
238                 ret
239
240 comboot_writeserial:                    ; 04 = write serial port
241                 mov al,P_DL
242                 call write_serial
243                 clc
244                 ret
245
246 comboot_getkeynoecho:                   ; 08 = get key w/o echo
247                 call comboot_getchar
248                 clc
249                 ret
250
251 comboot_writestr:                       ; 09 = write DOS string
252                 mov es,P_DS
253                 mov si,P_DX
254 .loop:          es lodsb
255                 cmp al,'$'              ; End string with $ - bizarre
256                 je .done
257                 call writechr
258                 jmp short .loop
259 .done:          clc
260                 ret
261
262 comboot_checkkey:                       ; 0B = check keyboard status
263                 cmp byte [APIKeyFlag],00h
264                 jnz .waiting
265                 call pollchar
266 .waiting:       setz al
267                 dec al                  ; AL = 0FFh if present, 0 if not
268                 mov P_AL,al
269                 clc
270                 ret
271
272 comboot_checkver:                       ; 30 = check DOS version
273                 ; We return 0 in all DOS-compatible version registers,
274                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
275                 mov P_EAX,'SY' << 16
276                 mov P_EBX,'SL' << 16
277                 mov P_ECX,'IN' << 16
278                 mov P_EDX,'UX' << 16
279                 ret
280
281 comboot_getchar:
282                 cmp byte [APIKeyFlag],00h
283                 jne .queued
284                 call getchar            ; If not queued get input
285                 and al,al               ; Function key?  (CF <- 0)
286                 jnz .done
287                 mov [APIKeyWait],ah     ; High part of key
288                 inc byte [APIKeyFlag]   ; Set flag
289 .done:          mov P_AL,al
290                 ret
291 .queued:        mov al,[APIKeyWait]
292                 dec byte [APIKeyFlag]
293                 jmp .done
294
295 ;
296 ; INT 22h - SYSLINUX-specific system calls
297 ;           System call number in ax
298 ;
299 comboot_int22:
300                 cli
301                 push ds
302                 push es
303                 push fs
304                 push gs
305                 pushad
306                 cld
307                 mov bp,cs
308                 mov ds,bp
309                 mov es,bp
310                 mov bp,sp                       ; Set up stack frame
311
312                 call adjust_screen              ; The COMBOOT program might have changed the screen
313
314                 cmp ax,int22_count
315                 jb .ok
316                 xor ax,ax                       ; Function 0 -> unimplemented
317 .ok:
318                 xchg ax,bx
319                 add bx,bx                       ; CF <- 0
320                 call [bx+int22_table]
321                 jmp comboot_resume              ; On return
322
323 ;
324 ; INT 22h AX=0000h      Unimplemented call
325 ;
326 comapi_err:
327                 stc
328                 ret
329
330 ;
331 ; INT 22h AX=0001h      Get SYSLINUX version
332 ;
333 comapi_get_version:
334                 ; Number of API functions supported
335                 mov P_AX,int22_count
336                 ; SYSLINUX version
337                 mov P_CX,(VER_MAJOR << 8)+VER_MINOR
338                 ; SYSLINUX derivative ID byte
339                 mov P_DX,my_id
340                 ; For future use
341                 mov P_BX,cs     ; cs == 0
342
343                 mov P_ES,ds
344                 ; ES:SI -> version banner
345                 mov P_SI,syslinux_banner
346                 ; ES:DI -> copyright string
347                 mov P_DI,copyright_str
348
349 comapi_nop:
350                 clc
351                 ret
352
353 ;
354 ; INT 22h AX=0002h      Write string
355 ;
356 ; Write null-terminated string in ES:BX
357 ;
358 comapi_writestr:
359                 mov ds,P_ES
360                 mov si,P_BX
361                 call writestr
362                 clc
363                 ret
364
365 ;
366 ; INT 22h AX=0003h      Run command
367 ;
368 ; Terminates the COMBOOT program and executes the command line in
369 ; ES:BX as if it had been entered by the user.
370 ;
371 comapi_run:
372                 mov ds,P_ES
373                 mov si,P_BX
374                 mov di,command_line
375                 call strcpy
376                 push load_kernel                ; Run a new kernel
377                 jmp comboot_exit                ; Terminate task, clean up
378
379 ;
380 ; INT 22h AX=0004h      Run default command
381 ;
382 ; Terminates the COMBOOT program and executes the default command line
383 ; as if a timeout had happened or the user pressed <Enter>.
384 ;
385 comapi_run_default:
386                 push auto_boot
387                 jmp comboot_exit
388
389 ;
390 ; INT 22h AX=0005h      Force text mode
391 ;
392 ; Puts the video in standard text mode
393 ;
394 comapi_textmode:
395                 call vgaclearmode
396                 clc
397                 ret
398
399 ;
400 ; INT 22h AX=0006h      Open file
401 ;
402 comapi_open:
403                 push ds
404                 mov ds,P_ES
405                 mov si,P_SI
406                 mov di,InitRD
407                 call mangle_name
408                 pop ds
409                 call searchdir
410                 jz comapi_err
411                 mov P_AX,ax
412                 mov P_HAX,dx
413                 mov P_CX,SECTOR_SIZE
414                 mov P_SI,si
415                 clc
416                 ret
417
418 ;
419 ; INT 22h AX=0007h      Read file
420 ;
421 comapi_read:
422                 mov es,P_ES
423                 mov bx,P_BX
424                 mov si,P_SI
425                 mov cx,P_CX
426                 call getfssec
427                 jnc .noteof
428                 xor si,si               ; SI <- 0 on EOF, CF <- 0
429 .noteof:        mov P_SI,si
430                 ret
431
432 ;
433 ; INT 22h AX=0008h      Close file
434 ;
435 comapi_close:
436                 ; Do nothing for now.  Eventually implement
437                 ; an internal API for this.
438                 clc
439                 ret
440
441 ;
442 ; INT 22h AX=0009h      Call PXE stack
443 ;
444 %if IS_PXELINUX
445 comapi_pxecall:
446                 mov bx,P_BX
447                 mov es,P_ES
448                 mov di,P_DI
449                 call pxenv
450                 mov P_AX,ax
451                 clc
452                 ret
453 %else
454 comapi_pxecall  equ comapi_err                  ; Not available
455 %endif
456
457 ;
458 ; INT 22h AX=000Ah      Get Derivative-Specific Info
459 ;
460 comapi_derinfo:
461                 mov P_AL,my_id
462 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
463                 mov al,[DriveNumber]
464                 mov P_DL,al
465                 mov P_ES,cs
466                 mov P_BX,PartInfo
467                 mov P_CL,SECTOR_SHIFT
468 %elif IS_PXELINUX
469                 mov ax,[APIVer]
470                 mov P_DX,ax
471                 mov ax,[StrucPtr]
472                 mov P_BX,ax
473                 mov ax,[StrucPtr+2]
474                 mov P_ES,ax
475                 mov ax,[InitStack]
476                 mov P_SI,ax
477                 mov ax,[InitStack+2]
478                 mov P_FS,ax
479 %elif IS_ISOLINUX
480                 mov al,[DriveNo]
481                 mov P_DL,al
482                 mov P_ES,cs
483                 mov P_BX,spec_packet
484                 mov P_CL,SECTOR_SHIFT
485 %endif
486                 clc
487                 ret
488
489 ;
490 ; INT 22h AX=000Bh      Get Serial Console Configuration
491 ;
492 comapi_serialcfg:
493                 mov ax,[SerialPort]
494                 mov P_DX,ax
495                 mov ax,[BaudDivisor]
496                 mov P_CX,ax
497                 mov ax,[FlowControl]
498                 or al,ah
499                 mov ah,[FlowIgnore]
500                 shr ah,4
501                 test byte [DisplayCon],01h
502                 jnz .normalconsole
503                 or ah,80h
504 .normalconsole:
505                 mov P_BX,ax
506                 clc
507                 ret
508
509 ;
510 ; INT 22h AX=000Ch      Perform final cleanup
511 ;
512 comapi_cleanup:
513 %if IS_PXELINUX
514                 ; Unload PXE if requested
515                 test dl,3
516                 setnz [KeepPXE]
517                 sub bp,sp               ; unload_pxe may move the stack around
518                 call unload_pxe
519                 add bp,sp               ; restore frame pointer...
520 %elif IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
521                 ; Restore original FDC table
522                 mov eax,[OrigFDCTabPtr]
523                 mov [fdctab],eax
524 %endif
525                 ; Reset the floppy disk subsystem
526                 xor ax,ax
527                 xor dx,dx
528                 int 13h
529                 clc
530                 ret
531
532 ;
533 ; INT 22h AX=000Dh      Clean up then replace bootstrap
534 ;
535 comapi_chainboot:
536                 call comapi_cleanup
537                 mov eax,P_EDI
538                 mov [trackbuf+4],eax            ; Copy from
539                 mov eax,P_ECX
540                 mov [trackbuf+8],eax            ; Total bytes
541                 mov eax,7C00h
542                 mov [trackbuf],eax              ; Copy to
543                 mov [EntryPoint],eax            ; CS:IP entry point
544                 mov esi,P_ESI
545                 mov edx,P_EBX
546                 mov bx,P_DS
547                 jmp replace_bootstrap_one
548
549
550 ;
551 ; INT 22h AX=000Eh      Get configuration file name
552 ;
553 comapi_configfile:
554                 mov P_ES,cs
555                 mov P_BX,ConfigName
556                 clc
557                 ret
558
559 ;
560 ; INT 22h AX=000Fh      Get IPAPPEND strings
561 ;
562 %if IS_PXELINUX
563 comapi_ipappend:
564                 mov P_ES,cs
565                 mov P_CX,numIPAppends
566                 mov P_BX,IPAppends
567                 clc
568                 ret
569
570                 section .data
571                 alignb 2, db 0
572 IPAppends       dw IPOption
573                 dw BOOTIFStr
574 numIPAppends    equ ($-IPAppends)/2
575
576 %else
577 comapi_ipappend equ comapi_err
578 %endif
579
580                 section .text
581
582 ;
583 ; INT 22h AX=0010h      Resolve hostname
584 ;
585 %if IS_PXELINUX
586 comapi_dnsresolv:
587                 mov ds,P_ES
588                 mov si,P_BX
589                 call dns_resolv
590                 mov P_EAX,eax
591                 ret
592 %else
593 comapi_dnsresolv equ comapi_err
594 %endif
595
596                 section .text
597
598 ;
599 ; INT 22h AX=0011h      Maximum number of shuffle descriptors
600 ;
601 comapi_maxshuffle:
602                 mov P_CX,(2*trackbufsize)/12
603                 ret
604
605 ;
606 ; INT 22h AX=0012h      Cleanup, shuffle and boot
607 ;
608 comapi_shuffle:
609                 call comapi_cleanup
610                 mov cx,P_CX
611                 cmp cx,(2*trackbufsize)/12
612                 ja .error
613
614                 push cx                         ; On stack: descriptor count
615
616                 lea cx,[ecx+ecx*2]              ; CX *= 3
617
618                 mov fs,P_ES
619                 mov si,P_DI
620                 mov di,trackbuf
621                 push di                         ; On stack: descriptor list address
622                 fs rep movsd                    ; Copy the list
623
624                 mov eax,P_EBP
625                 mov [EntryPoint],eax            ; CS:IP entry point
626                 mov esi,P_ESI
627                 mov edx,P_EBX
628                 mov bx,P_DS
629                 jmp replace_bootstrap
630 .error:
631                 stc
632                 ret
633
634 ;
635 ; INT 22h AX=0013h      Idle call
636 ;
637 ;
638 ; *** FIX THIS ***
639 ; The idle call seems to have detrimental effects on some machines when
640 ; called from a COM32 context (WHY?) --  disable it for now.
641 ;
642 %if 0 ; def HAVE_IDLE
643
644 comapi_idle:
645                 DO_IDLE
646                 clc
647                 ret
648
649 %else
650
651 comapi_idle     equ comapi_err
652
653 %endif
654
655 ;
656 ; INT 22h AX=0014h      Local boot
657 ;
658 %if IS_PXELINUX || IS_ISOLINUX
659 comapi_localboot:
660                 mov ax,P_DX
661                 jmp local_boot
662 %else
663 comapi_localboot equ comapi_err
664 %endif
665
666 ;
667 ; INT 22h AX=0015h      Feature flags
668 ;
669 comapi_features:
670                 mov P_ES,cs
671                 mov P_BX,feature_flags
672                 mov P_CX,feature_flags_len
673                 clc
674                 ret
675
676 ;
677 ; INT 22h AX=0016h      Run kernel image
678 ;
679 comapi_runkernel:
680                 mov al,P_DL
681                 cmp al,VK_TYPES-1
682                 ja .error
683                 mov [KernelType],al
684                 push ds
685                 mov ds,P_DS
686                 mov si,P_SI
687                 mov di,KernelName
688                 call mangle_name
689                 pop ds
690                 call searchdir
691                 jz comapi_err
692
693                 ; The kernel image was found, so we can load it...
694                 mov [Kernel_SI],si
695                 mov [Kernel_EAX],ax
696                 mov [Kernel_EAX+2],dx
697
698                 ; It's not just possible, but quite likely, that ES:BX
699                 ; points into real_mode_seg, so we need to exercise some
700                 ; special care here... use xfer_buf_seg as an intermediary
701                 push ds
702                 push es
703                 mov ax,xfer_buf_seg
704                 mov ds,P_ES
705                 mov si,P_BX
706                 mov es,ax
707                 xor di,di
708                 call strcpy
709                 pop es
710                 pop ds
711
712 %if IS_PXELINUX
713                 mov al,P_CL
714                 mov [IPAppend],al
715 %endif
716
717                 call comboot_exit
718
719 .finish:
720                 ; Copy the command line into its proper place
721                 push ds
722                 push es
723                 mov ax,xfer_buf_seg
724                 mov dx,real_mode_seg
725                 mov ds,ax
726                 mov es,dx
727                 xor si,si
728                 mov di,cmd_line_here
729                 call strcpy
730                 mov byte [es:di-1],' '          ; Simulate APPEND
731                 pop es
732                 pop ds
733                 mov [CmdLinePtr],di
734                 mov word [CmdOptPtr],zero_string
735                 jmp kernel_good_saved
736
737 .error          equ comapi_shuffle.error
738
739 ;
740 ; INT 22h AX=0017h  Report video mode change
741 ;
742 comapi_usingvga:
743                 mov ax,P_BX
744                 cmp ax,0Fh              ; Unknown flags = failure
745                 ja .error
746                 mov [UsingVGA],al
747                 mov cx,P_CX
748                 mov dx,P_DX
749                 mov [GXPixCols],cx
750                 mov [GXPixRows],dx
751                 test al,08h
752                 jnz .notext
753                 call adjust_screen
754 .notext:
755                 clc
756                 ret
757 .error:
758                 stc
759                 ret
760
761 ;
762 ; INT 22h AX=0018h  Query custom font
763 ;
764 comapi_userfont:
765                 mov al,[UserFont]
766                 and al,al
767                 jz .done
768                 mov al,[VGAFontSize]
769                 mov P_ES,ds
770                 mov P_BX,vgafontbuf
771
772 .done:          ; CF=0 here
773                 mov P_AL,al
774                 ret
775
776 ;
777 ; INT 22h AX=0019h  Read disk
778 ;
779 %if IS_SYSLINUX || IS_MDSLINUX || IS_ISOLINUX || IS_EXTLINUX
780 comapi_readdisk:
781                 mov esi,P_ESI           ; Enforce ESI == EDI == 0, these
782                 or esi,P_EDI            ; are reserved for future expansion
783                 jnz .err
784                 mov eax,P_EDX
785                 mov es,P_ES
786                 mov bx,P_BX
787                 mov bp,P_CX             ; WE CANNOT use P_* after touching bp!
788                 call getlinsec
789                 clc
790                 ret
791 .err:
792                 stc
793                 ret
794 %else
795 comapi_readdisk equ comapi_err
796 %endif
797
798 ;
799 ; INT 22h AX=001Ah      Cleanup, shuffle and boot to flat protected mode
800 ;
801 comapi_shufflepm:
802                 call comapi_cleanup
803                 mov cx,P_CX
804                 cmp cx,(2*trackbufsize)/12
805                 ja .error
806
807                 push cx                         ; On stack: descriptor count
808
809                 lea cx,[ecx+ecx*2]              ; CX *= 3
810
811                 mov fs,P_ES
812                 mov si,P_DI
813                 mov di,trackbuf
814                 push di                         ; On stack: descriptor list address
815                 fs rep movsd                    ; Copy the list
816
817                 mov fs,P_DS
818                 mov si,P_SI
819                 xor edi,edi
820                 mov di,PMTrampolineBuf
821                 mov al,0B8h                     ; MOV EAX opcode
822                 mov cx,9
823 .maketramp:
824                 stosb                           ; MOV opcode
825                 inc ax                          ; Next register opcode
826                 movsd                           ; immediate value
827                 loop .maketramp
828                 mov byte [di-9],0E9h            ; Last opcode is JMP
829                 sub dword [di-8],edi            ; Make JMP target relative
830
831                 mov dword [EntryPoint],trampoline_to_pm
832                 xor bx,bx                       ; DS on entry
833                 jmp replace_bootstrap
834 .error:
835                 stc
836                 ret
837
838                 section .data
839
840 %macro          int21 2
841                 db %1
842                 dw %2
843 %endmacro
844
845 int21_table:
846                 int21   00h, comboot_return
847                 int21   01h, comboot_getkey
848                 int21   02h, comboot_writechr
849                 int21   04h, comboot_writeserial
850                 int21   08h, comboot_getkeynoecho
851                 int21   09h, comboot_writestr
852                 int21   0Bh, comboot_checkkey
853                 int21   30h, comboot_checkver
854                 int21   4Ch, comboot_return
855                 int21    -1, comboot_bogus
856 int21_count     equ ($-int21_table)/3
857
858                 align 2, db 0
859 int22_table:
860                 dw comapi_err           ; 0000 unimplemented syscall
861                 dw comapi_get_version   ; 0001 get SYSLINUX version
862                 dw comapi_writestr      ; 0002 write string
863                 dw comapi_run           ; 0003 run specified command
864                 dw comapi_run_default   ; 0004 run default command
865                 dw comapi_textmode      ; 0005 force text mode
866                 dw comapi_open          ; 0006 open file
867                 dw comapi_read          ; 0007 read file
868                 dw comapi_close         ; 0008 close file
869                 dw comapi_pxecall       ; 0009 call PXE stack
870                 dw comapi_derinfo       ; 000A derivative-specific info
871                 dw comapi_serialcfg     ; 000B get serial port config
872                 dw comapi_cleanup       ; 000C perform final cleanup
873                 dw comapi_chainboot     ; 000D clean up then bootstrap
874                 dw comapi_configfile    ; 000E get name of config file
875                 dw comapi_ipappend      ; 000F get ipappend strings
876                 dw comapi_dnsresolv     ; 0010 resolve hostname
877                 dw comapi_maxshuffle    ; 0011 maximum shuffle descriptors
878                 dw comapi_shuffle       ; 0012 cleanup, shuffle and boot
879                 dw comapi_idle          ; 0013 idle call
880                 dw comapi_localboot     ; 0014 local boot
881                 dw comapi_features      ; 0015 feature flags
882                 dw comapi_runkernel     ; 0016 run kernel image
883                 dw comapi_usingvga      ; 0017 report video mode change
884                 dw comapi_userfont      ; 0018 query custom font
885                 dw comapi_readdisk      ; 0019 read disk
886                 dw comapi_shufflepm     ; 001A cleanup, shuffle and boot to pm
887 int22_count     equ ($-int22_table)/2
888
889 APIKeyWait      db 0
890 APIKeyFlag      db 0
891
892 zero_string     db 0                    ; Empty, null-terminated string
893
894 ;
895 ; This is the feature flag array for INT 22h AX=0015h
896 feature_flags:
897 %if IS_PXELINUX
898                 db 1                    ; Have local boot, idle not noop
899 %elif IS_ISOLINUX
900                 db 3                    ; Have local boot, idle is noop
901 %else
902                 db 2                    ; No local boot, idle is noop
903 %endif
904 feature_flags_len equ ($-feature_flags)
905
906                 section .latebss
907 ConfigName      resb    FILENAME_MAX