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