installer: fix 0 used as NULL
[syslinux/sherbszt.git] / core / comboot.inc
blob63394350e96f342b95730f196b095d35da003f36
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;;   Copyright 2009-2010 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.
12 ;; -----------------------------------------------------------------------
15 ;; comboot.inc
17 ;; Common code for running a COMBOOT image
19                 section .text16
21 ; Parameter registers definition; this is the definition
22 ; of the stack frame used by INT 21h and INT 22h.
23 %define         P_FLAGS         word [bp+44]
24 %define         P_FLAGSL        byte [bp+44]
25 %define         P_FLAGSH        byte [bp+45]
26 %define         P_CS            word [bp+42]
27 %define         P_IP            word [bp+40]
28 %define         P_CSIP          dword [bp+40]
29 %define         P_DS            word [bp+38]
30 %define         P_ES            word [bp+36]
31 %define         P_FS            word [bp+34]
32 %define         P_GS            word [bp+32]
33 %define         P_EAX           dword [bp+28]
34 %define         P_AX            word [bp+28]
35 %define         P_HAX           word [bp+30]
36 %define         P_AL            byte [bp+28]
37 %define         P_AH            byte [bp+29]
38 %define         P_ECX           dword [bp+24]
39 %define         P_CX            word [bp+24]
40 %define         P_HCX           word [bp+26]
41 %define         P_CL            byte [bp+24]
42 %define         P_CH            byte [bp+25]
43 %define         P_EDX           dword [bp+20]
44 %define         P_DX            word [bp+20]
45 %define         P_HDX           word [bp+22]
46 %define         P_DL            byte [bp+20]
47 %define         P_DH            byte [bp+21]
48 %define         P_EBX           dword [bp+16]
49 %define         P_BX            word [bp+16]
50 %define         P_HBX           word [bp+18]
51 %define         P_BL            byte [bp+16]
52 %define         P_BH            byte [bp+17]
53 %define         P_EBP           dword [bp+8]
54 %define         P_BP            word [bp+8]
55 %define         P_HBP           word [bp+10]
56 %define         P_ESI           dword [bp+4]
57 %define         P_SI            word [bp+4]
58 %define         P_HSI           word [bp+6]
59 %define         P_EDI           dword [bp]
60 %define         P_DI            word [bp]
61 %define         P_HDI           word [bp+2]
64 ; Set up the COMBOOT API interrupt vectors.  This is now done at
65 ; initialization time.
67 comboot_setup_api:
68                 mov di,DOSErrTramp      ; Error trampolines
69                 mov cx,32
70                 push cx
71                 mov eax,02EB206Ah       ; push 20h; jmp $+4
72 .loop1:         stosd
73                 inc ah
74                 loop .loop1
75                 dec di
76                 mov byte [di-1],0E9h
77                 mov ax,comboot_bogus-2
78                 sub ax,di
79                 stosw
81                 pop cx                  ; CX <- 32
82                 mov si,4*20h            ; DOS interrupt vectors
83                 mov bx,comboot_vectors
84                 mov di,DOSSaveVectors
85 .loop2:
86                 movsd
87                 movzx eax,word [bx]
88                 inc bx
89                 inc bx
90                 mov [si-4],eax
91                 loop .loop2
92                 ret
95 ; Restore the original state of the COMBOOT API vectors, and free
96 ; any low memory allocated by the comboot module.
98                 global comboot_cleanup_api:function hidden
99 comboot_cleanup_api:
100                 pusha
101                 mov si,DOSSaveVectors
102                 mov di,4*20h
103                 mov cx,20h
104                 rep movsd               ; Restore DOS-range vectors
105                 popa
106                 ret
108                 section .bss16
109                 alignb 4
110 DOSSaveVectors  resd 32
112                 section .data16
113 %define comboot_err(x) (DOSErrTramp+4*((x)-20h))
115 comboot_vectors:
116                 dw comboot_return       ; INT 20 = exit
117                 dw comboot_err(21h)     ; INT 21 = DOS-compatible system calls
118                 dw comboot_int22        ; INT 22 = native system calls
119                 dw comboot_err(23h)     ; INT 23 = DOS Ctrl-C handler
120                 dw comboot_err(24h)     ; INT 24 = DOS critical error handler
121                 dw comboot_err(25h)     ; INT 25 = DOS absolute disk read
122                 dw comboot_err(26h)     ; INT 26 = DOS absolute disk write
123                 dw comboot_err(27h)     ; INT 27 = DOS TSR
124                 dw comboot_int28        ; INT 28 = DOS idle interrupt
125                 dw comboot_int29        ; INT 29 = DOS fast console output
126                 dw comboot_err(2Ah)     ; INT 2A = DOS network API (NetBIOS)
127                 dw comboot_err(2Bh)     ; INT 2B = DOS reserved
128                 dw comboot_err(2Ch)     ; INT 2C = DOS reserved
129                 dw comboot_iret         ; INT 2D = DOS reserved, AMIS
130                 dw comboot_err(2Eh)     ; INT 2E = DOS run command
131                 dw comboot_iret         ; INT 2F = DOS multiplex interrupt
132                 dw comboot_err(30h)     ; INT 30 = DOS CP/M system calls
133                 dw comboot_err(31h)     ; INT 31 = DPMI
134                 dw comboot_err(32h)     ; INT 32 = DOS reserved
135                 dw comboot_iret         ; INT 33 = DOS mouse API
136                 dw comboot_err(34h)     ; INT 34 = DOS FPU emulation
137                 dw comboot_err(35h)     ; INT 35 = DOS FPU emulation
138                 dw comboot_err(36h)     ; INT 36 = DOS FPU emulation
139                 dw comboot_err(37h)     ; INT 37 = DOS FPU emulation
140                 dw comboot_err(38h)     ; INT 38 = DOS FPU emulation
141                 dw comboot_err(39h)     ; INT 39 = DOS FPU emulation
142                 dw comboot_err(3Ah)     ; INT 3A = DOS FPU emulation
143                 dw comboot_err(3Bh)     ; INT 3B = DOS FPU emulation
144                 dw comboot_err(3Ch)     ; INT 3C = DOS FPU emulation
145                 dw comboot_err(3Dh)     ; INT 3D = DOS FPU emulation
146                 dw comboot_err(3Eh)     ; INT 3E = DOS FPU emulation
147                 dw comboot_err(3Fh)     ; INT 3F = DOS overlay manager
149                 section .text16
151 comboot_resume:
152                 mov bp,sp               ; In case the function clobbers BP
153                 setc P_FLAGSL           ; Propagate CF->error
154                 popad
155                 pop gs
156                 pop fs
157                 pop es
158                 pop ds
159 comboot_iret:
160                 iret
162 comboot_bad_int21:
163                 mov ax,P_AX
164                 push P_CSIP
165                 push 21h
166                 ; Fall through
168 ; Attempted to execute invalid DOS system call
169 ; The interrupt number is on the stack.
170 comboot_bogus:  pop dx                  ; Interrupt number
171                 pop edi                 ; CS:IP
172                 mov cx,err_notdos
173                 push comboot_bogus_tail
174                 jmp comboot_exit_msg
175 comboot_bogus_tail:
176                 xchg ax,dx
177                 pm_call pm_writehex2            ; Interrupt number
178                 mov al,' '
179                 pm_call pm_writechr
180                 xchg ax,dx
181                 pm_call pm_writehex4            ; Function number (AX)
182                 mov al,' '
183                 pm_call pm_writechr
184                 mov eax,edi
185                 pm_call pm_writehex8            ; CS:IP of the origin
186                 pm_call crlf
187                 jmp kaboom
189 ; Proper return vector
190 ; Note: this gets invoked directly via INT 20h.
191 ; We don't need to cld explicitly here, because comboot_exit does that
192 ; when invoking RESET_STACK_AND_SEGS.
193 comboot_return:
194                 cli                     ; May not have a safe stack
195                 push enter_command      ; Normal return to command prompt
196                 ; jmp comboot_exit
199 ; Generic COMBOOT return to command line code
200 ;  stack -> where to go next
201 ;     CX -> message (for _msg version)
203                 extern comboot_cleanup_lowmem
204 comboot_exit:
205                 xor cx,cx
206 comboot_exit_msg:
207                 pop bx                  ; Return address
208                 RESET_STACK_AND_SEGS si ; Contains sti, cld
209                 pm_call comboot_cleanup_lowmem
210                 pm_call pm_adjust_screen; The COMBOOT program might have change the screen
211                 jcxz .nomsg
212                 mov si,KernelName
213                 pm_call pm_writestr
214                 mov si,cx
215                 pm_call pm_writestr
216 .nomsg:
217                 jmp bx
220 ; INT 21h system calls
222 comboot_getkey:                         ; 01 = get key with echo
223                 pm_call vgashowcursor
224                 call comboot_getchar
225                 pm_call vgahidecursor
226                 pm_call pm_writechr
227                 clc
228                 ret
230 comboot_writechr:                       ; 02 = writechr
231                 mov al,P_DL
232                 pm_call pm_writechr
233                 clc
234                 ret
236 comboot_writeserial:                    ; 04 = write serial port
237                 mov al,P_DL
238                 pm_call pm_write_serial
239                 clc
240                 ret
242 comboot_getkeynoecho:                   ; 08 = get key w/o echo
243                 call comboot_getchar
244                 clc
245                 ret
247 comboot_writestr:                       ; 09 = write DOS string
248                 mov es,P_DS
249                 mov si,P_DX
250 .loop:          es lodsb
251                 cmp al,'$'              ; End string with $ - bizarre
252                 je .done
253                 pm_call pm_writechr
254                 jmp short .loop
255 .done:          clc
256                 ret
258 comboot_checkkey:                       ; 0B = check keyboard status
259                 cmp byte [APIKeyFlag],00h
260                 jnz .waiting
261                 pm_call pm_pollchar
262 .waiting:       setz al
263                 dec al                  ; AL = 0FFh if present, 0 if not
264                 mov P_AL,al
265                 clc
266                 ret
268 comboot_checkver:                       ; 30 = check DOS version
269                 ; We return 0 in all DOS-compatible version registers,
270                 ; but the high part of eax-ebx-ecx-edx spell "SYSLINUX"
271                 mov P_EAX,'SY' << 16
272                 mov P_EBX,'SL' << 16
273                 mov P_ECX,'IN' << 16
274                 mov P_EDX,'UX' << 16
275                 ret
277 comboot_getchar:
278                 cmp byte [APIKeyFlag],00h
279                 jne .queued
280                 pm_call pm_getchar      ; If not queued get input
281                 and al,al               ; Function key?  (CF <- 0)
282                 jnz .done
283                 mov [APIKeyWait],ah     ; High part of key
284                 inc byte [APIKeyFlag]   ; Set flag
285 .done:          mov P_AL,al
286                 ret
287 .queued:        mov al,[APIKeyWait]
288                 dec byte [APIKeyFlag]
289                 jmp .done
292 ; INT 28h - DOS idle
294 comboot_int28:
295                 sti
296                 cld
297                 extern __idle
298                 pm_call __idle
299                 iret
302 ; INT 29h - DOS fast write character
304 comboot_int29:
305                 sti
306                 cld
307                 pm_call pm_writechr
308                 iret
311 ; INT 22h - SYSLINUX-specific system calls
312 ;           System call number in ax
314 comboot_int22:
315                 sti
316                 push ds
317                 push es
318                 push fs
319                 push gs
320                 pushad
321                 cld
322                 mov bp,cs
323                 mov ds,bp
324                 mov es,bp
325                 mov bp,sp                       ; Set up stack frame
327                 pm_call pm_adjust_screen        ; The COMBOOT program might hav changed the screen
329                 cmp ax,int22_count
330                 jb .ok
331                 xor ax,ax                       ; Function 0 -> unimplemented
332 .ok:
333                 xchg ax,bx
334                 add bx,bx                       ; CF <- 0
335                 call [bx+int22_table]
336                 jmp comboot_resume              ; On return
339 ; INT 22h AX=0000h      Unimplemented call
341 comapi_err:
342                 stc
343                 ret
346 ; INT 22h AX=001Ch      Get pointer to auxillary data vector
348 comapi_getadv:
349                 mov P_ES,ds
350                 mov P_BX,adv0.data
351                 mov P_CX,ADV_LEN
352                 ret
355 ; INT 22h AX=001Dh      Write auxillary data vector
357 comapi_writeadv equ adv_write
360 ; INT 22h AX=0024h      Cleanup, shuffle and boot raw
362 comapi_shufraw:
363 %if IS_PXELINUX
364                 ; Unload PXE if requested
365                 test dl,3
366                 setnz [KeepPXE]
367                 sub bp,sp               ; unload_pxe may move the stack around
368                 pm_call unload_pxe
369                 add bp,sp               ; restore frame pointer...
370 %elif IS_SYSLINUX || IS_EXTLINUX
371                 ; Restore original FDC table
372                 mov eax,[OrigFDCTabPtr]
373                 mov [fdctab],eax
374 %endif
375                 pm_call cleanup_hardware
376                 mov edi,P_EDI
377                 mov esi,P_ESI
378                 mov ecx,P_ECX
379                 jmp shuffle_and_boot_raw
382 ; INT 22h AX=0025h      Initialize the ADV structure
384 comapi_initadv:
385                 call adv_init
386                 ret
388                 section .data16
390                 alignz 2
391 int22_table:
392                 dw comapi_err           ; 0000 unimplemented syscall
393                 dw comapi_err           ; 0001 get SYSLINUX version
394                 dw comapi_err           ; 0002 write string
395                 dw comapi_err           ; 0003 run specified command
396                 dw comapi_err           ; 0004 run default command
397                 dw comapi_err           ; 0005 force text mode
398                 dw comapi_err           ; 0006 open file
399                 dw comapi_err           ; 0007 read file
400                 dw comapi_err           ; 0008 close file
401                 dw comapi_err           ; 0009 call PXE stack
402                 dw comapi_err           ; 000A derivative-specific info
403                 dw comapi_err           ; 000B get serial port config
404                 dw comapi_err           ; 000C perform final cleanup
405                 dw comapi_err           ; 000D clean up then bootstrap
406                 dw comapi_err           ; 000E get name of config file
407                 dw comapi_err           ; 000F get ipappend strings
408                 dw comapi_err           ; 0010 resolve hostname
409                 dw comapi_err           ; 0011 maximum shuffle descriptors
410                 dw comapi_err           ; 0012 cleanup, shuffle and boot
411                 dw comapi_err           ; 0013 idle call
412                 dw comapi_err           ; 0014 local boot
413                 dw comapi_err           ; 0015 feature flags
414                 dw comapi_err           ; 0016 run kernel image
415                 dw comapi_err           ; 0017 report video mode change
416                 dw comapi_err           ; 0018 query custom font
417                 dw comapi_err           ; 0019 read disk
418                 dw comapi_err           ; 001A cleanup, shuffle and boot to pm
419                 dw comapi_err           ; 001B cleanup, shuffle and boot to rm
420                 dw comapi_getadv        ; 001C get pointer to ADV
421                 dw comapi_writeadv      ; 001D write ADV to disk
422                 dw comapi_err           ; 001E keyboard remapping table
423                 dw comapi_err           ; 001F get current working directory
424                 dw comapi_err           ; 0020 open directory
425                 dw comapi_err           ; 0021 read directory
426                 dw comapi_err           ; 0022 close directory
427                 dw comapi_err           ; 0023 query shuffler size
428                 dw comapi_shufraw       ; 0024 cleanup, shuffle and boot raw
429                 dw comapi_initadv       ; 0025 initialize adv structure
430 int22_count     equ ($-int22_table)/2
432 APIKeyWait      db 0
433 APIKeyFlag      db 0
435 zero_string     db 0                    ; Empty, null-terminated string
437 err_notdos      db ': attempted DOS system call INT ',0
438 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
440                 section .bss16
441                 alignb 4
442 DOSErrTramp     resd    33              ; Error trampolines
444 %ifndef HAVE_CURRENTDIRNAME
445                 global CurrentDirName:data hidden
446 CurrentDirName  resb    FILENAME_MAX
447 %endif