Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / interface / pxe / pxe_entry.S
1 /*
2  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  */
20
21 FILE_LICENCE ( GPL2_OR_LATER )
22
23         .arch i386
24
25 /****************************************************************************
26  * !PXE structure
27  ****************************************************************************
28  */
29         .section ".text16.data", "aw", @progbits
30         .globl ppxe
31         .align 16
32 ppxe:
33         .ascii "!PXE"                   /* Signature */
34         .byte pxe_length                /* StructLength */
35         .byte 0                         /* StructCksum */
36         .byte 0                         /* StructRev */
37         .byte 0                         /* reserved_1 */
38         .word undiheader, 0             /* UNDIROMID */
39         .word 0, 0                      /* BaseROMID */
40         .word pxe_entry_sp, 0           /* EntryPointSP */
41         .word pxe_entry_esp, 0          /* EntryPointESP */
42         .word -1, -1                    /* StatusCallout */
43         .byte 0                         /* reserved_2 */
44         .byte SegDescCnt                /* SegDescCnt */
45         .word 0                         /* FirstSelector */
46 pxe_segments:
47         .word 0, 0, 0, _data16_memsz    /* Stack */
48         .word 0, 0, 0, _data16_memsz    /* UNDIData */
49         .word 0, 0, 0, _text16_memsz    /* UNDICode */
50         .word 0, 0, 0, _text16_memsz    /* UNDICodeWrite */
51         .word 0, 0, 0, 0                /* BC_Data */
52         .word 0, 0, 0, 0                /* BC_Code */
53         .word 0, 0, 0, 0                /* BC_CodeWrite */
54         .equ    SegDescCnt, ( ( . - pxe_segments ) / 8 )
55         .equ    pxe_length, . - ppxe
56         .size   ppxe, . - ppxe
57
58         /* Define undiheader=0 as a weak symbol for non-ROM builds */
59         .section ".weak", "a", @nobits
60         .weak   undiheader
61 undiheader:
62
63 /****************************************************************************
64  * PXENV+ structure
65  ****************************************************************************
66  */
67         .section ".text16.data", "aw", @progbits
68         .globl pxenv
69         .align 16
70 pxenv:
71         .ascii "PXENV+"                 /* Signature */
72         .word 0x0201                    /* Version */
73         .byte pxenv_length              /* Length */
74         .byte 0                         /* Checksum */
75         .word pxenv_entry, 0            /* RMEntry */
76         .long 0                         /* PMEntry */
77         .word 0                         /* PMSelector */
78         .word 0                         /* StackSeg */
79         .word _data16_memsz             /* StackSize */
80         .word 0                         /* BC_CodeSeg */
81         .word 0                         /* BC_CodeSize */
82         .word 0                         /* BC_DataSeg */
83         .word 0                         /* BC_DataSize */
84         .word 0                         /* UNDIDataSeg */
85         .word _data16_memsz             /* UNDIDataSize */
86         .word 0                         /* UNDICodeSeg */
87         .word _text16_memsz             /* UNDICodeSize */
88         .word ppxe, 0                   /* PXEPtr */
89         .equ    pxenv_length, . - pxenv
90         .size   pxenv, . - pxenv
91  
92 /****************************************************************************
93  * pxenv_entry (16-bit far call)
94  *
95  * PXE API call PXENV+ entry point
96  *
97  * Parameters:
98  *   %es:di : Far pointer to PXE parameter structure
99  *   %bx : PXE API call
100  * Returns:
101  *   %ax : PXE exit status
102  * Corrupts:
103  *   none
104  ****************************************************************************
105  */
106         /* Wyse Streaming Manager server (WLDRM13.BIN) assumes that
107          * the PXENV+ entry point is at UNDI_CS:0000; apparently,
108          * somebody at Wyse has difficulty distinguishing between the
109          * words "may" and "must"...
110          */
111         .section ".text16.null", "ax", @progbits
112         .code16
113 pxenv_null_entry:
114         jmp     pxenv_entry
115
116         .section ".text16", "ax", @progbits
117         .code16
118 pxenv_entry:
119         pushl   $pxe_api_call
120         pushw   %cs
121         call    prot_call
122         addl    $4, %esp
123         lret
124         .size   pxenv_entry, . - pxenv_entry
125
126 /****************************************************************************
127  * pxe_entry
128  *
129  * PXE API call !PXE entry point
130  *
131  * Parameters:
132  *   stack : Far pointer to PXE parameter structure
133  *   stack : PXE API call
134  * Returns:
135  *   %ax : PXE exit status
136  * Corrupts:
137  *   none
138  ****************************************************************************
139  */
140         .section ".text16", "ax", @progbits
141         .code16
142 pxe_entry:
143 pxe_entry_sp:
144         /* Preserve original %esp */
145         pushl   %esp
146         /* Zero high word of %esp to allow use of common code */
147         movzwl  %sp, %esp
148         jmp     pxe_entry_common
149 pxe_entry_esp:
150         /* Preserve %esp to match behaviour of pxe_entry_sp */
151         pushl   %esp
152 pxe_entry_common:
153         /* Save PXENV+ API call registers */
154         pushw   %es
155         pushw   %di
156         pushw   %bx
157         /* Load !PXE parameters from stack into PXENV+ registers */
158         addr32 movw     18(%esp), %bx
159         movw    %bx, %es
160         addr32 movw     16(%esp), %di
161         addr32 movw     14(%esp), %bx
162         /* Make call as for PXENV+ */
163         pushw   %cs
164         call    pxenv_entry
165         /* Restore PXENV+ registers */
166         popw    %bx
167         popw    %di
168         popw    %es
169         /* Restore original %esp and return */
170         popl    %esp
171         lret
172         .size   pxe_entry, . - pxe_entry
173
174 /****************************************************************************
175  * pxe_int_1a
176  *
177  * PXE INT 1A handler
178  *
179  * Parameters:
180  *   %ax : 0x5650
181  * Returns:
182  *   %ax : 0x564e
183  *   %es:bx : Far pointer to the PXENV+ structure
184  *   %edx : Physical address of the PXENV+ structure
185  *   CF cleared
186  * Corrupts:
187  *   none
188  ****************************************************************************
189  */
190         .section ".text16", "ax", @progbits
191         .code16
192         .globl  pxe_int_1a
193 pxe_int_1a:
194         pushfw
195         cmpw    $0x5650, %ax
196         jne     1f
197         /* INT 1A,5650 - PXE installation check */
198         xorl    %edx, %edx
199         movw    %cs, %dx
200         movw    %dx, %es
201         movw    $pxenv, %bx
202         shll    $4, %edx
203         addl    $pxenv, %edx
204         movw    $0x564e, %ax
205         pushw   %bp
206         movw    %sp, %bp
207         andb    $~0x01, 8(%bp)  /* Clear CF on return */
208         popw    %bp
209         popfw
210         iret
211 1:      /* INT 1A,other - pass through */
212         popfw
213         ljmp    *%cs:pxe_int_1a_vector
214
215         .section ".text16.data", "aw", @progbits
216         .globl  pxe_int_1a_vector
217 pxe_int_1a_vector:      .long 0