core: VFS cleanups: add a persistent generic struct file
[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 comapi_dnsresolv:
690                 mov ds,P_ES
691                 mov si,P_BX
692                 call dns_resolv
693                 mov P_EAX,eax
694                 clc
695                 ret
696 %else
697 comapi_dnsresolv equ comapi_err
698 %endif
699
700                 section .text16
701
702 ;
703 ; INT 22h AX=0011h      Obsolete
704 ;
705
706 ;
707 ; INT 22h AX=0012h      Obsolete
708 ;
709
710 ;
711 ; INT 22h AX=0013h      Idle call
712 ;
713 comapi_idle:
714                 call do_idle
715                 clc
716                 ret
717
718 ;
719 ; INT 22h AX=0014h      Local boot
720 ;
721 %if HAS_LOCALBOOT
722 comapi_localboot:
723                 mov ax,P_DX
724                 jmp local_boot
725 %else
726 comapi_localboot equ comapi_err
727 %endif ; HAS_LOCALBOOT
728
729 ;
730 ; INT 22h AX=0015h      Feature flags
731 ;
732 comapi_features:
733                 mov P_ES,cs
734                 mov P_BX,feature_flags
735                 mov P_CX,feature_flags_len
736                 clc
737                 ret
738
739 ;
740 ; INT 22h AX=0016h      Run kernel image
741 ;
742 comapi_runkernel:
743                 mov al,P_DL
744                 cmp al,VK_TYPES-1
745                 ja .error
746                 mov [KernelType],al
747                 push ds
748                 mov ds,P_DS
749                 mov si,P_SI
750                 mov di,KernelName
751                 pm_call mangle_name
752                 pop ds
753                 pm_call searchdir
754                 jz comapi_err
755
756                 ; The kernel image was found, so we can load it...
757                 mov [Kernel_SI],si
758                 mov [Kernel_EAX],eax
759
760                 ; It's not just possible, but quite likely, that ES:BX
761                 ; points into real_mode_seg or xfer_buf_seg, so we
762                 ; need to exercise some special care here... use
763                 ; trackbuf as an intermediary
764                 push ds
765                 mov ds,P_ES
766                 mov si,P_BX
767                 mov di,trackbuf
768                 call strcpy
769                 pop ds
770
771 %if IS_PXELINUX
772                 mov al,P_CL
773                 mov [IPAppend],al
774 %endif
775
776                 call comboot_exit
777
778 .finish:
779                 ; Copy the command line into its proper place
780                 push es
781                 mov dx,real_mode_seg
782                 mov es,dx
783                 mov si,trackbuf
784                 mov di,cmd_line_here
785                 call strcpy
786                 mov byte [es:di-1],' '          ; Simulate APPEND
787                 pop es
788                 mov [CmdLinePtr],di
789                 mov word [CmdOptPtr],zero_string
790                 jmp kernel_good_saved
791
792 .error          equ comapi_usingvga.error
793
794 ;
795 ; INT 22h AX=0017h  Report video mode change
796 ;
797 comapi_usingvga:
798                 mov ax,P_BX
799                 cmp ax,0Fh              ; Unknown flags = failure
800                 ja .error
801                 mov [UsingVGA],al
802                 mov cx,P_CX
803                 mov dx,P_DX
804                 mov [GXPixCols],cx
805                 mov [GXPixRows],dx
806                 test al,08h
807                 jnz .notext
808                 call adjust_screen
809 .notext:
810                 clc
811                 ret
812 .error:
813                 stc
814                 ret
815
816 ;
817 ; INT 22h AX=0018h  Query custom font
818 ;
819 comapi_userfont:
820                 mov al,[UserFont]
821                 and al,al
822                 jz .done
823                 mov al,[VGAFontSize]
824                 mov P_ES,aux_seg
825                 mov P_BX,aux.fontbuf
826
827 .done:          ; CF=0 here
828                 mov P_AL,al
829                 ret
830
831 ;
832 ; INT 22h AX=0019h  Read disk
833 ;
834 %if IS_SYSLINUX || IS_ISOLINUX || IS_EXTLINUX
835 comapi_readdisk:
836                 mov esi,P_ESI           ; Enforce ESI == EDI == 0, these
837                 or esi,P_EDI            ; are reserved for future expansion
838                 jnz .err
839                 mov eax,P_EDX
840                 mov es,P_ES
841                 mov bx,P_BX
842                 mov bp,P_CX             ; WE CANNOT use P_* after touching bp!
843                 call getlinsec
844                 clc
845                 ret
846 .err:
847                 stc
848                 ret
849 %else
850 comapi_readdisk equ comapi_err
851 %endif
852
853 ;
854 ; INT 22h AX=001Ah      Obsolete
855 ;
856
857 ;
858 ; INT 22h AX=001Bh      Obsolete
859 ;
860
861 ;
862 ; INT 22h AX=001Ch      Get pointer to auxillary data vector
863 ;
864 comapi_getadv:
865                 mov P_ES,ds
866                 mov P_BX,adv0.data
867                 mov P_CX,ADV_LEN
868                 ret
869
870 ;
871 ; INT 22h AX=001Dh      Write auxillary data vector
872 ;
873 comapi_writeadv equ adv_write
874
875 ;
876 ; INT 22h AX=001Eh      Keyboard remapping table
877 comapi_kbdtable:
878                 cmp P_DX,0
879                 jne .err
880                 mov P_AX,1                      ; Version
881                 mov P_CX,256                    ; Length
882                 mov P_ES,cs
883                 mov P_BX,KbdMap
884                 ret
885 .err:
886                 stc
887                 ret
888
889 ;
890 ; INT 22h AX=001Fh      Get current working directory
891 ;
892 comapi_getcwd:
893                 mov P_ES,cs
894                 mov P_BX,CurrentDirName
895                 clc
896                 ret
897
898 ;
899 ; INT 22h AX=0020h      Open directory
900 ;
901 %if IS_SYSLINUX
902 comapi_opendir:
903                 push ds
904                 mov ds,P_ES
905                 mov si,P_SI
906                 mov di,InitRD
907                 pm_call mangle_name
908                 pop ds
909                 pm_call searchdir
910                 jz comapi_err   ; Didn't find a directory
911                 mov eax,[si]     ; the sector number where the dir stores
912                 cmp eax,0
913                 jz comapi_err   ; Found nothing
914                 mov P_EAX,eax
915                 mov P_CX,SECTOR_SIZE
916                 mov P_SI,si
917                 clc
918                 ret
919 %else
920 comapi_opendir  equ comapi_err
921 %endif
922
923 ;
924 ; INT 22h AX=0021h      Read directory
925 ;
926 %if IS_SYSLINUX
927 comapi_readdir:
928                 mov es,P_ES
929                 mov di,P_DI
930                 mov si,P_SI
931                 pm_call vfat_readdir
932                 mov P_EAX,eax
933                 mov P_DL,dl
934                 mov P_EBX,ebx
935                 mov P_SI,si
936                 ret
937 %else
938 comapi_readdir  equ comapi_err
939 %endif
940
941 ;
942 ; INT 22h AX=0022h      Close directory
943 ;
944 comapi_closedir equ comapi_close
945
946 ;
947 ; INT 22h AX=0023h      Query shuffler size
948 ;
949 comapi_shufsize:
950                 mov P_CX,bcopyxx_safe
951                 ret
952
953 ;
954 ; INT 22h AX=0024h      Cleanup, shuffle and boot raw
955 ;
956 comapi_shufraw:
957                 call comapi_cleanup
958                 mov edi,P_EDI
959                 mov esi,P_ESI
960                 mov ecx,P_ECX
961                 jmp shuffle_and_boot_raw
962
963                 section .data16
964
965 %macro          int21 2
966                 db %1
967                 dw %2
968 %endmacro
969
970 int21_table:
971                 int21   00h, comboot_return
972                 int21   01h, comboot_getkey
973                 int21   02h, comboot_writechr
974                 int21   04h, comboot_writeserial
975                 int21   08h, comboot_getkeynoecho
976                 int21   09h, comboot_writestr
977                 int21   0Bh, comboot_checkkey
978                 int21   30h, comboot_checkver
979                 int21   4Ch, comboot_return
980                 int21    -1, comboot_bad_int21
981 int21_count     equ ($-int21_table)/3
982
983                 alignz 2
984 int22_table:
985                 dw comapi_err           ; 0000 unimplemented syscall
986                 dw comapi_get_version   ; 0001 get SYSLINUX version
987                 dw comapi_writestr      ; 0002 write string
988                 dw comapi_run           ; 0003 run specified command
989                 dw comapi_run_default   ; 0004 run default command
990                 dw comapi_textmode      ; 0005 force text mode
991                 dw comapi_open          ; 0006 open file
992                 dw comapi_read          ; 0007 read file
993                 dw comapi_close         ; 0008 close file
994                 dw comapi_pxecall       ; 0009 call PXE stack
995                 dw comapi_derinfo       ; 000A derivative-specific info
996                 dw comapi_serialcfg     ; 000B get serial port config
997                 dw comapi_cleanup       ; 000C perform final cleanup
998                 dw comapi_err           ; 000D clean up then bootstrap
999                 dw comapi_configfile    ; 000E get name of config file
1000                 dw comapi_ipappend      ; 000F get ipappend strings
1001                 dw comapi_dnsresolv     ; 0010 resolve hostname
1002                 dw comapi_err           ; 0011 maximum shuffle descriptors
1003                 dw comapi_err           ; 0012 cleanup, shuffle and boot
1004                 dw comapi_idle          ; 0013 idle call
1005                 dw comapi_localboot     ; 0014 local boot
1006                 dw comapi_features      ; 0015 feature flags
1007                 dw comapi_runkernel     ; 0016 run kernel image
1008                 dw comapi_usingvga      ; 0017 report video mode change
1009                 dw comapi_userfont      ; 0018 query custom font
1010                 dw comapi_readdisk      ; 0019 read disk
1011                 dw comapi_err           ; 001A cleanup, shuffle and boot to pm
1012                 dw comapi_err           ; 001B cleanup, shuffle and boot to rm
1013                 dw comapi_getadv        ; 001C get pointer to ADV
1014                 dw comapi_writeadv      ; 001D write ADV to disk
1015                 dw comapi_kbdtable      ; 001E keyboard remapping table
1016                 dw comapi_getcwd        ; 001F get current working directory
1017                 dw comapi_opendir       ; 0020 open directory
1018                 dw comapi_readdir       ; 0021 read directory
1019                 dw comapi_closedir      ; 0022 close directory
1020                 dw comapi_shufsize      ; 0023 query shuffler size
1021                 dw comapi_shufraw       ; 0024 cleanup, shuffle and boot raw
1022 int22_count     equ ($-int22_table)/2
1023
1024 APIKeyWait      db 0
1025 APIKeyFlag      db 0
1026
1027 zero_string     db 0                    ; Empty, null-terminated string
1028
1029 ;
1030 ; This is the feature flag array for INT 22h AX=0015h
1031 ;
1032 ; Note: PXELINUX clears the idle is noop flag if appropriate
1033 ; in pxe_detect_nic_type
1034 ;
1035 feature_flags:
1036                 db 1                    ; Have local boot, idle is not noop
1037 feature_flags_len equ ($-feature_flags)
1038
1039 err_notdos      db ': attempted DOS system call INT ',0
1040 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
1041
1042                 section .bss16
1043                 alignb 4
1044 DOSErrTramp     resd    33              ; Error trampolines
1045
1046                 global ConfigName, CurrentDirName
1047 ConfigName      resb    FILENAME_MAX
1048 CurrentDirName  resb    FILENAME_MAX