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