Core: opendir/readdir/closedir stuff added
[profile/ivi/syslinux.git] / core / comboot.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;;   Copyright 2009 Intel Corporation; author: H. Peter Anvin
5 ;;
6 ;;   This program is free software; you can redistribute it and/or modify
7 ;;   it under the terms of the GNU General Public License as published by
8 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;;   (at your option) any later version; incorporated herein by reference.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;;
15 ;; comboot.inc
16 ;;
17 ;; Common code for running a COMBOOT image
18 ;;
19
20                 section .text16
21
22 ; Parameter registers definition; this is the definition
23 ; of the stack frame used by INT 21h and INT 22h.
24 %define         P_FLAGS         word [bp+44]
25 %define         P_FLAGSL        byte [bp+44]
26 %define         P_FLAGSH        byte [bp+45]
27 %define         P_CS            word [bp+42]
28 %define         P_IP            word [bp+40]
29 %define         P_CSIP          dword [bp+40]
30 %define         P_DS            word [bp+38]
31 %define         P_ES            word [bp+36]
32 %define         P_FS            word [bp+34]
33 %define         P_GS            word [bp+32]
34 %define         P_EAX           dword [bp+28]
35 %define         P_AX            word [bp+28]
36 %define         P_HAX           word [bp+30]
37 %define         P_AL            byte [bp+28]
38 %define         P_AH            byte [bp+29]
39 %define         P_ECX           dword [bp+24]
40 %define         P_CX            word [bp+24]
41 %define         P_HCX           word [bp+26]
42 %define         P_CL            byte [bp+24]
43 %define         P_CH            byte [bp+25]
44 %define         P_EDX           dword [bp+20]
45 %define         P_DX            word [bp+20]
46 %define         P_HDX           word [bp+22]
47 %define         P_DL            byte [bp+20]
48 %define         P_DH            byte [bp+21]
49 %define         P_EBX           dword [bp+16]
50 %define         P_BX            word [bp+16]
51 %define         P_HBX           word [bp+18]
52 %define         P_BL            byte [bp+16]
53 %define         P_BH            byte [bp+17]
54 %define         P_EBP           dword [bp+8]
55 %define         P_BP            word [bp+8]
56 %define         P_HBP           word [bp+10]
57 %define         P_ESI           dword [bp+4]
58 %define         P_SI            word [bp+4]
59 %define         P_HSI           word [bp+6]
60 %define         P_EDI           dword [bp]
61 %define         P_DI            word [bp]
62 %define         P_HDI           word [bp+2]
63
64 ; Looks like a COMBOOT image but too large
65 comboot_too_large:
66                 pm_call close_file
67                 mov si,err_comlarge
68                 call writestr
69                 jmp enter_command
70
71 ;
72 ; Load a COMBOOT image.  A COMBOOT image is basically a DOS .COM file,
73 ; except that it may, of course, not contain any DOS system calls.  We
74 ; do, however, allow the execution of INT 20h to return to SYSLINUX.
75 ;
76 is_comboot_image:
77                 push si                 ; Save file handle
78
79                 call make_plain_cmdline
80
81                 call comboot_setup_api
82
83                 mov cx,comboot_seg
84                 mov es,cx
85
86                 xor di,di
87                 mov cx,64               ; 256 bytes (size of PSP)
88                 xor eax,eax             ; Clear PSP
89                 rep stosd
90
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
98
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
110
111 .loop:          es lodsb
112                 and al,al
113                 jz .done
114                 stosb
115                 loop .loop
116 .done:
117
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
123
124                 ; Now actually load the file...
125                 pop si                  ; File handle
126                 mov bx,100h             ; Load at <seg>:0100h
127                 mov cx,10000h >> SECTOR_SHIFT
128                                         ; Absolute maximum # of sectors
129                 pm_call getfssec
130                 cmp ecx,65536-256-2     ; Maximum size
131                 ja comboot_too_large
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 ; Note: this gets invoked both via INT 21h and directly via INT 20h.
144 ; We don't need to cld explicitly here, because comboot_exit does that
145 ; when invoking RESET_STACK_AND_SEGS.
146 comboot_return: cli                     ; May not have a safe stack
147                 push enter_command      ; Normal return to command prompt
148                 jmp comboot_exit
149
150 ;
151 ; Set up the COMBOOT API interrupt vectors.  This is now done at
152 ; initialization time.
153 ;
154 comboot_setup_api:
155                 mov di,DOSErrTramp      ; Error trampolines
156                 mov cx,32
157                 push cx
158                 mov eax,02EB206Ah       ; push 20h; jmp $+4
159 .loop1:         stosd
160                 inc ah
161                 loop .loop1
162                 dec di
163                 mov byte [di-1],0E9h
164                 mov ax,comboot_bogus-2
165                 sub ax,di
166                 stosw
167
168                 pop cx                  ; CX <- 32
169                 mov si,4*20h            ; DOS interrupt vectors
170                 mov bx,comboot_vectors
171                 mov di,DOSSaveVectors
172 .loop2:
173                 movsd
174                 movzx eax,word [bx]
175                 inc bx
176                 inc bx
177                 mov [si-4],eax
178                 loop .loop2
179                 ret
180
181 ;
182 ; Restore the original state of the COMBOOT API vectors
183 ;
184 comboot_cleanup_api:
185                 pusha
186                 mov si,DOSSaveVectors
187                 mov di,4*20h
188                 mov cx,20h
189                 rep movsd               ; Restore DOS-range vectors
190                 popa
191                 ret
192
193                 section .bss16
194                 alignb 4
195 DOSSaveVectors  resd 32
196
197                 section .data16
198 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
199
200 comboot_vectors:
201                 dw comboot_return       ; INT 20 = exit
202                 dw comboot_int21        ; INT 21 = DOS-compatible system calls
203                 dw comboot_int22        ; INT 22 = native system calls
204                 dw comboot_err(23h)     ; INT 23 = DOS Ctrl-C handler
205                 dw comboot_err(24h)     ; INT 24 = DOS critical error handler
206                 dw comboot_err(25h)     ; INT 25 = DOS absolute disk read
207                 dw comboot_err(26h)     ; INT 26 = DOS absolute disk write
208                 dw comboot_err(27h)     ; INT 27 = DOS TSR
209                 dw comboot_int28        ; INT 28 = DOS idle interrupt
210                 dw comboot_int29        ; INT 29 = DOS fast console output
211                 dw comboot_err(2Ah)     ; INT 2A = DOS network API (NetBIOS)
212                 dw comboot_err(2Bh)     ; INT 2B = DOS reserved
213                 dw comboot_err(2Ch)     ; INT 2C = DOS reserved
214                 dw comboot_iret         ; INT 2D = DOS reserved, AMIS
215                 dw comboot_err(2Eh)     ; INT 2E = DOS run command
216                 dw comboot_iret         ; INT 2F = DOS multiplex interrupt
217                 dw comboot_err(30h)     ; INT 30 = DOS CP/M system calls
218                 dw comboot_err(31h)     ; INT 31 = DPMI
219                 dw comboot_err(32h)     ; INT 32 = DOS reserved
220                 dw comboot_iret         ; INT 33 = DOS mouse API
221                 dw comboot_err(34h)     ; INT 34 = DOS FPU emulation
222                 dw comboot_err(35h)     ; INT 35 = DOS FPU emulation
223                 dw comboot_err(36h)     ; INT 36 = DOS FPU emulation
224                 dw comboot_err(37h)     ; INT 37 = DOS FPU emulation
225                 dw comboot_err(38h)     ; INT 38 = DOS FPU emulation
226                 dw comboot_err(39h)     ; INT 39 = DOS FPU emulation
227                 dw comboot_err(3Ah)     ; INT 3A = DOS FPU emulation
228                 dw comboot_err(3Bh)     ; INT 3B = DOS FPU emulation
229                 dw comboot_err(3Ch)     ; INT 3C = DOS FPU emulation
230                 dw comboot_err(3Dh)     ; INT 3D = DOS FPU emulation
231                 dw comboot_err(3Eh)     ; INT 3E = DOS FPU emulation
232                 dw comboot_err(3Fh)     ; INT 3F = DOS overlay manager
233
234                 section .text16
235
236 ; INT 21h: generic DOS system call
237 comboot_int21:  sti
238                 push ds
239                 push es
240                 push fs
241                 push gs
242                 pushad
243                 cld
244                 mov bp,cs
245                 mov ds,bp
246                 mov es,bp
247                 mov bp,sp                       ; Set up stack frame
248
249                 call adjust_screen              ; The COMBOOT program might have changed the screen
250
251                 mov cx,int21_count
252                 mov si,int21_table
253 .again:         lodsb
254                 cmp al,P_AH
255                 lodsw
256                 loopne .again
257                 ; The last function in the list is the
258                 ; "no such function" function
259                 clc
260                 call ax                 ; Call the invoked function
261 comboot_resume:
262                 mov bp,sp               ; In case the function clobbers BP
263                 setc P_FLAGSL           ; Propagate CF->error
264                 popad
265                 pop gs
266                 pop fs
267                 pop es
268                 pop ds
269 comboot_iret:
270                 iret
271
272 comboot_bad_int21:
273                 mov ax,P_AX
274                 push P_CSIP
275                 push 21h
276                 ; Fall through
277
278 ; Attempted to execute invalid DOS system call
279 ; The interrupt number is on the stack.
280 comboot_bogus:  pop dx                  ; Interrupt number
281                 pop edi                 ; CS:IP
282                 mov cx,err_notdos
283                 push comboot_bogus_tail
284                 jmp comboot_exit_msg
285 comboot_bogus_tail:
286                 xchg ax,dx
287                 call writehex2          ; Interrupt number
288                 mov al,' '
289                 call writechr
290                 xchg ax,dx
291                 call writehex4          ; Function number (AX)
292                 mov al,' '
293                 call writechr
294                 mov eax,edi
295                 call writehex8          ; CS:IP of the origin
296                 call crlf
297                 jmp enter_command
298
299 ;
300 ; Generic COMBOOT return to command line code
301 ;  stack -> where to go next
302 ;     CX -> message (for _msg version)
303 ;
304 comboot_exit:
305                 xor cx,cx
306 comboot_exit_msg:
307                 pop bx                  ; Return address
308                 RESET_STACK_AND_SEGS SI ; Contains sti, cld
309                 call adjust_screen      ; The COMBOOT program might have changed the screen
310                 jcxz .nomsg
311                 mov si,KernelCName
312                 call writestr
313                 mov si,cx
314                 call writestr
315 .nomsg:
316                 jmp bx
317
318 ;
319 ; INT 21h system calls
320 ;
321 comboot_getkey:                         ; 01 = get key with echo
322                 call vgashowcursor
323                 call comboot_getchar
324                 call vgahidecursor
325                 call writechr
326                 clc
327                 ret
328
329 comboot_writechr:                       ; 02 = writechr
330                 mov al,P_DL
331                 call writechr
332                 clc
333                 ret
334
335 comboot_writeserial:                    ; 04 = write serial port
336                 mov al,P_DL
337                 call write_serial
338                 clc
339                 ret
340
341 comboot_getkeynoecho:                   ; 08 = get key w/o echo
342                 call comboot_getchar
343                 clc
344                 ret
345
346 comboot_writestr:                       ; 09 = write DOS string
347                 mov es,P_DS
348                 mov si,P_DX
349 .loop:          es lodsb
350                 cmp al,'$'              ; End string with $ - bizarre
351                 je .done
352                 call writechr
353                 jmp short .loop
354 .done:          clc
355                 ret
356
357 comboot_checkkey:                       ; 0B = check keyboard status
358                 cmp byte [APIKeyFlag],00h
359                 jnz .waiting
360                 call pollchar
361 .waiting:       setz al
362                 dec al                  ; AL = 0FFh if present, 0 if not
363                 mov P_AL,al
364                 clc
365                 ret
366
367 comboot_checkver:                       ; 30 = check DOS version
368                 ; We return 0 in all DOS-compatible version registers,
369                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
370                 mov P_EAX,'SY' << 16
371                 mov P_EBX,'SL' << 16
372                 mov P_ECX,'IN' << 16
373                 mov P_EDX,'UX' << 16
374                 ret
375
376 comboot_getchar:
377                 cmp byte [APIKeyFlag],00h
378                 jne .queued
379                 call getchar            ; If not queued get input
380                 and al,al               ; Function key?  (CF <- 0)
381                 jnz .done
382                 mov [APIKeyWait],ah     ; High part of key
383                 inc byte [APIKeyFlag]   ; Set flag
384 .done:          mov P_AL,al
385                 ret
386 .queued:        mov al,[APIKeyWait]
387                 dec byte [APIKeyFlag]
388                 jmp .done
389
390 ;
391 ; INT 28h - DOS idle
392 ;
393 comboot_int28:
394                 sti
395                 cld
396                 call do_idle
397                 iret
398
399 ;
400 ; INT 29h - DOS fast write character
401 ;
402 comboot_int29:
403                 sti
404                 cld
405                 call writechr                   ; Preserves registers!
406                 iret
407
408 ;
409 ; INT 22h - SYSLINUX-specific system calls
410 ;           System call number in ax
411 ;
412 comboot_int22:
413                 sti
414                 push ds
415                 push es
416                 push fs
417                 push gs
418                 pushad
419                 cld
420                 mov bp,cs
421                 mov ds,bp
422                 mov es,bp
423                 mov bp,sp                       ; Set up stack frame
424
425                 call adjust_screen              ; The COMBOOT program might have changed the screen
426
427                 cmp ax,int22_count
428                 jb .ok
429                 xor ax,ax                       ; Function 0 -> unimplemented
430 .ok:
431                 xchg ax,bx
432                 add bx,bx                       ; CF <- 0
433                 call [bx+int22_table]
434                 jmp comboot_resume              ; On return
435
436 ;
437 ; INT 22h AX=0000h      Unimplemented call
438 ;
439 comapi_err:
440                 stc
441                 ret
442
443 ;
444 ; INT 22h AX=0001h      Get SYSLINUX version
445 ;
446 comapi_get_version:
447                 ; Number of API functions supported
448                 mov P_AX,int22_count
449                 ; SYSLINUX version
450                 mov P_CX,(VERSION_MAJOR << 8)+VERSION_MINOR
451                 ; SYSLINUX derivative ID byte
452                 mov P_DX,my_id
453                 ; For future use
454                 mov P_BX,cs     ; cs == 0
455
456                 mov P_ES,ds
457                 ; ES:SI -> version banner
458                 mov P_SI,syslinux_banner
459                 ; ES:DI -> copyright string
460                 mov P_DI,copyright_str
461
462 comapi_nop:
463                 clc
464                 ret
465
466 ;
467 ; INT 22h AX=0002h      Write string
468 ;
469 ; Write null-terminated string in ES:BX
470 ;
471 comapi_writestr:
472                 mov ds,P_ES
473                 mov si,P_BX
474                 call writestr
475                 clc
476                 ret
477
478 ;
479 ; INT 22h AX=0003h      Run command
480 ;
481 ; Terminates the COMBOOT program and executes the command line in
482 ; ES:BX as if it had been entered by the user.
483 ;
484 comapi_run:
485                 mov ds,P_ES
486                 mov si,P_BX
487                 mov di,command_line
488                 call strcpy
489                 push load_kernel                ; Run a new kernel
490                 jmp comboot_exit                ; Terminate task, clean up
491
492 ;
493 ; INT 22h AX=0004h      Run default command
494 ;
495 ; Terminates the COMBOOT program and executes the default command line
496 ; as if a timeout had happened or the user pressed <Enter>.
497 ;
498 comapi_run_default:
499                 push auto_boot
500                 jmp comboot_exit
501
502 ;
503 ; INT 22h AX=0005h      Force text mode
504 ;
505 ; Puts the video in standard text mode
506 ;
507 comapi_textmode:
508                 call vgaclearmode
509                 clc
510                 ret
511
512 ;
513 ; INT 22h AX=0006h      Open file
514 ;
515 comapi_open:
516                 push ds
517                 mov ds,P_ES
518                 mov si,P_SI
519                 mov di,InitRD
520                 pm_call mangle_name
521                 pop ds
522                 pm_call searchdir
523                 jz comapi_err
524                 mov P_EAX,eax
525                 mov P_CX,SECTOR_SIZE
526                 mov P_SI,si
527                 clc
528                 ret
529
530 ;
531 ; INT 22h AX=0007h      Read file
532 ;
533 comapi_read:
534                 mov es,P_ES
535                 mov bx,P_BX
536                 mov si,P_SI
537                 mov cx,P_CX
538                 pm_call getfssec
539                 jnc .noteof
540                 xor si,si               ; SI <- 0 on EOF, CF <- 0
541 .noteof:        mov P_SI,si
542                 mov P_ECX,ecx
543                 ret
544
545 ;
546 ; INT 22h AX=0008h      Close file
547 ;
548 comapi_close:
549                 mov si,P_SI
550                 pm_call close_file
551                 clc
552                 ret
553
554 ;
555 ; INT 22h AX=0009h      Call PXE stack
556 ;
557 %if IS_PXELINUX
558 comapi_pxecall:
559                 mov bx,P_BX
560                 mov es,P_ES
561                 mov di,P_DI
562                 call pxenv
563                 mov ax,[PXEStatus]
564                 mov P_AX,ax
565                 ret
566 %else
567 comapi_pxecall  equ comapi_err                  ; Not available
568 %endif
569
570 ;
571 ; INT 22h AX=000Ah      Get Derivative-Specific Info
572 ;
573 comapi_derinfo:
574                 mov P_AL,my_id
575 %if IS_PXELINUX
576                 mov ax,[APIVer]
577                 mov P_DX,ax
578                 mov ax,[StrucPtr]
579                 mov P_BX,ax
580                 mov ax,[StrucPtr+2]
581                 mov P_ES,ax
582                 mov ax,[InitStack]
583                 mov P_SI,ax
584                 mov ax,[InitStack+2]
585                 mov P_FS,ax
586 %else
587                 ; Physical medium...
588
589                 mov P_CL,SECTOR_SHIFT
590                 mov al,[DriveNumber]
591                 mov P_DL,al
592                 mov P_FS,cs
593                 mov P_SI,OrigESDI
594 %if IS_SYSLINUX || IS_EXTLINUX
595                 mov P_ES,cs
596                 mov P_BX,PartInfo
597 %elif IS_ISOLINUX
598                 mov P_ES,cs
599                 mov P_BX,spec_packet
600                 mov ax,[BIOSType]
601                 sub ax,bios_cdrom
602                 shr ax,2
603                 mov P_CH,al             ; Mode (el torito/cbios/ebios)
604 %endif
605 %endif
606                 clc
607                 ret
608
609 ;
610 ; INT 22h AX=000Bh      Get Serial Console Configuration
611 ;
612 comapi_serialcfg:
613                 mov ax,[SerialPort]
614                 mov P_DX,ax
615                 mov ax,[BaudDivisor]
616                 mov P_CX,ax
617                 mov ax,[FlowControl]
618                 or al,ah
619                 mov ah,[FlowIgnore]
620                 shr ah,4
621                 test byte [DisplayCon],01h
622                 jnz .normalconsole
623                 or ah,80h
624 .normalconsole:
625                 mov P_BX,ax
626                 clc
627                 ret
628
629 ;
630 ; INT 22h AX=000Ch      Perform final cleanup
631 ;
632 comapi_cleanup:
633 %if IS_PXELINUX
634                 ; Unload PXE if requested
635                 test dl,3
636                 setnz [KeepPXE]
637                 sub bp,sp               ; unload_pxe may move the stack around
638                 call unload_pxe
639                 add bp,sp               ; restore frame pointer...
640 %elif IS_SYSLINUX || IS_EXTLINUX
641                 ; Restore original FDC table
642                 mov eax,[OrigFDCTabPtr]
643                 mov [fdctab],eax
644 %endif
645                 call cleanup_hardware
646                 clc
647                 ret
648
649 ;
650 ; INT 22h AX=000Dh      Clean up then replace bootstrap
651 ;
652 comapi_chainboot:
653                 call comapi_cleanup
654                 mov eax,P_EDI
655                 mov [trackbuf+4],eax            ; Copy from
656                 mov eax,P_ECX
657                 mov [trackbuf+8],eax            ; Total bytes
658                 mov eax,7C00h
659                 mov [trackbuf],eax              ; Copy to
660                 push eax                        ; Entry point on stack
661                 mov esi,P_ESI
662                 mov edx,P_EBX
663                 mov bx,P_DS
664                 jmp replace_bootstrap_one
665
666 ;
667 ; INT 22h AX=000Eh      Get configuration file name
668 ;
669 comapi_configfile:
670                 mov P_ES,cs
671                 mov P_BX,ConfigName
672                 clc
673                 ret
674
675 ;
676 ; INT 22h AX=000Fh      Get IPAPPEND strings
677 ;
678 comapi_ipappend:
679                 mov P_ES,cs
680                 mov P_CX,numIPAppends
681                 mov P_BX,IPAppends
682                 clc
683                 ret
684
685 ;
686 ; INT 22h AX=0010h      Resolve hostname
687 ;
688 %if IS_PXELINUX
689                 extern pxe_dns_resolv
690 comapi_dnsresolv:
691                 mov ds,P_ES
692                 mov si,P_BX
693                 pm_call pxe_dns_resolv
694                 mov P_EAX,eax
695                 clc
696                 ret
697 %else
698 comapi_dnsresolv equ comapi_err
699 %endif
700
701                 section .text16
702
703 ;
704 ; INT 22h AX=0011h      Obsolete
705 ;
706
707 ;
708 ; INT 22h AX=0012h      Obsolete
709 ;
710
711 ;
712 ; INT 22h AX=0013h      Idle call
713 ;
714 comapi_idle:
715                 call do_idle
716                 clc
717                 ret
718
719 ;
720 ; INT 22h AX=0014h      Local boot
721 ;
722 %if HAS_LOCALBOOT
723 comapi_localboot:
724                 mov ax,P_DX
725                 jmp local_boot
726 %else
727 comapi_localboot equ comapi_err
728 %endif ; HAS_LOCALBOOT
729
730 ;
731 ; INT 22h AX=0015h      Feature flags
732 ;
733 comapi_features:
734                 mov P_ES,cs
735                 mov P_BX,feature_flags
736                 mov P_CX,feature_flags_len
737                 clc
738                 ret
739
740 ;
741 ; INT 22h AX=0016h      Run kernel image
742 ;
743 comapi_runkernel:
744                 mov al,P_DL
745                 cmp al,VK_TYPES-1
746                 ja .error
747                 mov [KernelType],al
748                 push ds
749                 mov ds,P_DS
750                 mov si,P_SI
751                 mov di,KernelName
752                 pm_call mangle_name
753                 pop ds
754                 pm_call searchdir
755                 jz comapi_err
756
757                 ; The kernel image was found, so we can load it...
758                 mov [Kernel_SI],si
759                 mov [Kernel_EAX],eax
760
761                 ; It's not just possible, but quite likely, that ES:BX
762                 ; points into real_mode_seg or xfer_buf_seg, so we
763                 ; need to exercise some special care here... use
764                 ; trackbuf as an intermediary
765                 push ds
766                 mov ds,P_ES
767                 mov si,P_BX
768                 mov di,trackbuf
769                 call strcpy
770                 pop ds
771
772 %if IS_PXELINUX
773                 mov al,P_CL
774                 mov [IPAppend],al
775 %endif
776
777                 call comboot_exit
778
779 .finish:
780                 ; Copy the command line into its proper place
781                 push es
782                 mov dx,real_mode_seg
783                 mov es,dx
784                 mov si,trackbuf
785                 mov di,cmd_line_here
786                 call strcpy
787                 mov byte [es:di-1],' '          ; Simulate APPEND
788                 pop es
789                 mov [CmdLinePtr],di
790                 mov word [CmdOptPtr],zero_string
791                 jmp kernel_good_saved
792
793 .error          equ comapi_usingvga.error
794
795 ;
796 ; INT 22h AX=0017h  Report video mode change
797 ;
798 comapi_usingvga:
799                 mov ax,P_BX
800                 cmp ax,0Fh              ; Unknown flags = failure
801                 ja .error
802                 mov [UsingVGA],al
803                 mov cx,P_CX
804                 mov dx,P_DX
805                 mov [GXPixCols],cx
806                 mov [GXPixRows],dx
807                 test al,08h
808                 jnz .notext
809                 call adjust_screen
810 .notext:
811                 clc
812                 ret
813 .error:
814                 stc
815                 ret
816
817 ;
818 ; INT 22h AX=0018h  Query custom font
819 ;
820 comapi_userfont:
821                 mov al,[UserFont]
822                 and al,al
823                 jz .done
824                 mov al,[VGAFontSize]
825                 mov P_ES,aux_seg
826                 mov P_BX,aux.fontbuf
827
828 .done:          ; CF=0 here
829                 mov P_AL,al
830                 ret
831
832 ;
833 ; INT 22h AX=0019h  Read disk
834 ;
835 %if IS_SYSLINUX || IS_ISOLINUX || IS_EXTLINUX
836 comapi_readdisk:
837                 mov esi,P_ESI           ; Enforce ESI == EDI == 0, these
838                 or esi,P_EDI            ; are reserved for future expansion
839                 jnz .err
840                 mov eax,P_EDX
841                 mov es,P_ES
842                 mov bx,P_BX
843                 mov bp,P_CX             ; WE CANNOT use P_* after touching bp!
844                 call getlinsec
845                 clc
846                 ret
847 .err:
848                 stc
849                 ret
850 %else
851 comapi_readdisk equ comapi_err
852 %endif
853
854 ;
855 ; INT 22h AX=001Ah      Obsolete
856 ;
857
858 ;
859 ; INT 22h AX=001Bh      Obsolete
860 ;
861
862 ;
863 ; INT 22h AX=001Ch      Get pointer to auxillary data vector
864 ;
865 comapi_getadv:
866                 mov P_ES,ds
867                 mov P_BX,adv0.data
868                 mov P_CX,ADV_LEN
869                 ret
870
871 ;
872 ; INT 22h AX=001Dh      Write auxillary data vector
873 ;
874 comapi_writeadv equ adv_write
875
876 ;
877 ; INT 22h AX=001Eh      Keyboard remapping table
878 comapi_kbdtable:
879                 cmp P_DX,0
880                 jne .err
881                 mov P_AX,1                      ; Version
882                 mov P_CX,256                    ; Length
883                 mov P_ES,cs
884                 mov P_BX,KbdMap
885                 ret
886 .err:
887                 stc
888                 ret
889
890 ;
891 ; INT 22h AX=001Fh      Get current working directory
892 ;
893 comapi_getcwd:
894                 mov P_ES,cs
895                 mov P_BX,CurrentDirName
896                 clc
897                 ret
898
899 ;
900 ; INT 22h AX=0020h      Open directory
901 ;
902 %if IS_SYSLINUX
903 comapi_opendir:
904                 mov es,P_ES
905                 mov si,P_SI
906                 mov di,InitRD
907                 pm_call opendir
908                 jz comapi_err   ; Didn't find a directory
909                 cmp eax,0
910                 jz comapi_err   ; Found nothing
911                 mov P_EAX,eax
912                 mov P_CX,SECTOR_SIZE
913                 mov P_SI,si
914                 clc
915                 ret
916 %else
917 comapi_opendir  equ comapi_err
918 %endif
919
920 ;
921 ; INT 22h AX=0021h      Read directory
922 ;
923 %if IS_SYSLINUX
924 comapi_readdir:
925                 mov esi,P_ESI       ; The address of DIR structure
926                 pm_call readdir
927                 mov P_EAX,eax       ; The address of newly read dirent structure
928                 ret
929 %else
930 comapi_readdir  equ comapi_err
931 %endif
932
933 ;
934 ; INT 22h AX=0022h      Close directory
935 ;
936 comapi_closedir equ comapi_close
937
938 ;
939 ; INT 22h AX=0023h      Query shuffler size
940 ;
941 comapi_shufsize:
942                 mov P_CX,bcopyxx_safe
943                 ret
944
945 ;
946 ; INT 22h AX=0024h      Cleanup, shuffle and boot raw
947 ;
948 comapi_shufraw:
949                 call comapi_cleanup
950                 mov edi,P_EDI
951                 mov esi,P_ESI
952                 mov ecx,P_ECX
953                 jmp shuffle_and_boot_raw
954
955                 section .data16
956
957 %macro          int21 2
958                 db %1
959                 dw %2
960 %endmacro
961
962 int21_table:
963                 int21   00h, comboot_return
964                 int21   01h, comboot_getkey
965                 int21   02h, comboot_writechr
966                 int21   04h, comboot_writeserial
967                 int21   08h, comboot_getkeynoecho
968                 int21   09h, comboot_writestr
969                 int21   0Bh, comboot_checkkey
970                 int21   30h, comboot_checkver
971                 int21   4Ch, comboot_return
972                 int21    -1, comboot_bad_int21
973 int21_count     equ ($-int21_table)/3
974
975                 alignz 2
976 int22_table:
977                 dw comapi_err           ; 0000 unimplemented syscall
978                 dw comapi_get_version   ; 0001 get SYSLINUX version
979                 dw comapi_writestr      ; 0002 write string
980                 dw comapi_run           ; 0003 run specified command
981                 dw comapi_run_default   ; 0004 run default command
982                 dw comapi_textmode      ; 0005 force text mode
983                 dw comapi_open          ; 0006 open file
984                 dw comapi_read          ; 0007 read file
985                 dw comapi_close         ; 0008 close file
986                 dw comapi_pxecall       ; 0009 call PXE stack
987                 dw comapi_derinfo       ; 000A derivative-specific info
988                 dw comapi_serialcfg     ; 000B get serial port config
989                 dw comapi_cleanup       ; 000C perform final cleanup
990                 dw comapi_err           ; 000D clean up then bootstrap
991                 dw comapi_configfile    ; 000E get name of config file
992                 dw comapi_ipappend      ; 000F get ipappend strings
993                 dw comapi_dnsresolv     ; 0010 resolve hostname
994                 dw comapi_err           ; 0011 maximum shuffle descriptors
995                 dw comapi_err           ; 0012 cleanup, shuffle and boot
996                 dw comapi_idle          ; 0013 idle call
997                 dw comapi_localboot     ; 0014 local boot
998                 dw comapi_features      ; 0015 feature flags
999                 dw comapi_runkernel     ; 0016 run kernel image
1000                 dw comapi_usingvga      ; 0017 report video mode change
1001                 dw comapi_userfont      ; 0018 query custom font
1002                 dw comapi_readdisk      ; 0019 read disk
1003                 dw comapi_err           ; 001A cleanup, shuffle and boot to pm
1004                 dw comapi_err           ; 001B cleanup, shuffle and boot to rm
1005                 dw comapi_getadv        ; 001C get pointer to ADV
1006                 dw comapi_writeadv      ; 001D write ADV to disk
1007                 dw comapi_kbdtable      ; 001E keyboard remapping table
1008                 dw comapi_getcwd        ; 001F get current working directory
1009                 dw comapi_opendir       ; 0020 open directory
1010                 dw comapi_readdir       ; 0021 read directory
1011                 dw comapi_closedir      ; 0022 close directory
1012                 dw comapi_shufsize      ; 0023 query shuffler size
1013                 dw comapi_shufraw       ; 0024 cleanup, shuffle and boot raw
1014 int22_count     equ ($-int22_table)/2
1015
1016 APIKeyWait      db 0
1017 APIKeyFlag      db 0
1018
1019 zero_string     db 0                    ; Empty, null-terminated string
1020
1021 ;
1022 ; This is the feature flag array for INT 22h AX=0015h
1023 ;
1024 ; Note: PXELINUX clears the idle is noop flag if appropriate
1025 ; in pxe_detect_nic_type
1026 ;
1027 feature_flags:
1028                 db 1                    ; Have local boot, idle is not noop
1029 feature_flags_len equ ($-feature_flags)
1030
1031 err_notdos      db ': attempted DOS system call INT ',0
1032 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
1033
1034                 section .bss16
1035                 alignb 4
1036 DOSErrTramp     resd    33              ; Error trampolines
1037
1038                 global ConfigName, CurrentDirName
1039 ConfigName      resb    FILENAME_MAX
1040 CurrentDirName  resb    FILENAME_MAX