These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / prefix / exeprefix.S
1 /*
2  * Copyright (C) 2011 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  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  *
23  */
24
25 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
26
27 /* Initial temporary stack size */
28 #define EXE_STACK_SIZE 0x400
29
30 /* Temporary decompression area (avoid DOS high memory area) */
31 #define EXE_DECOMPRESS_ADDRESS 0x110000
32
33 /* Fields within the Program Segment Prefix */
34 #define PSP_CMDLINE_LEN 0x80
35 #define PSP_CMDLINE_START 0x81
36
37         .text
38         .arch i386
39         .org 0
40         .code16
41         .section ".prefix", "awx", @progbits
42
43 signature:
44         /* "MZ" signature */
45         .ascii  "MZ"
46
47 last_block:
48         /* Number of bytes in last block that are really used */
49         .word   0
50
51 blocks:
52         /* Number of 512-byte blocks */
53         .word   0
54         .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
55         .ascii  "ADDW"
56         .long   blocks
57         .long   512
58         .long   0
59         .previous
60
61 num_reloc:
62         /* Number of relocation entries stored after the header */
63         .word   0
64
65 header_pgh:
66         /* Number of paragraphs in the header */
67         .word   ( ( _exe_start - signature ) / 16 )
68
69 min_bss_pgh:
70         /* Minimum number of paragraphs of additional (BSS) memory */
71         .word   ( EXE_STACK_SIZE / 16 )
72
73 max_bss_pgh:
74         /* Maximum number of paragraphs of additional (BSS) memory */
75         .word   ( EXE_STACK_SIZE / 16 )
76
77 init_ss:
78         /* Initial stack segment (relative to start of executable) */
79         .word   -( ( _exe_start - signature ) / 16 )
80         .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
81         .ascii  "ADDW"
82         .long   init_ss
83         .long   16
84         .long   0
85         .previous
86
87 init_sp:
88         /* Initial stack pointer */
89         .word   EXE_STACK_SIZE
90
91 checksum:
92         /* Checksum (ignored) */
93         .word   0
94
95 init_ip:
96         /* Initial instruction pointer */
97         .word   _exe_start
98
99 init_cs:
100         /* Initial code segment (relative to start of executable) */
101         .word   -( ( _exe_start - signature ) / 16 )
102
103 reloc_table:
104         /* Relocation table offset */
105         .word   0
106
107 overlay:
108         /* Overlay number */
109         .word   0
110
111         .align 16, 0
112
113         .globl  _exe_start
114 _exe_start:
115         /* Install iPXE.  Use a fixed temporary decompression area to
116          * avoid trashing the DOS high memory area.
117          */
118         call    alloc_basemem
119         xorl    %esi, %esi
120         movl    $EXE_DECOMPRESS_ADDRESS, %edi
121         orl     $0xffffffff, %ebp       /* Allow arbitrary relocation */
122         call    install_prealloc
123
124         /* Set up real-mode stack */
125         movw    %bx, %ss
126         movw    $_estack16, %sp
127
128         /* Jump to .text16 segment */
129         pushw   %ax
130         pushw   $1f
131         lret
132         .section ".text16", "awx", @progbits
133 1:
134         /* Terminate command line with a NUL */
135         movzbw  PSP_CMDLINE_LEN, %si
136         movb    $0, PSP_CMDLINE_START(%si)
137
138         /* Calculate command line physical address */
139         xorl    %esi, %esi
140         movw    %ds, %si
141         shll    $4, %esi
142         addl    $PSP_CMDLINE_START, %esi
143
144         /* Set up %ds for access to .data16 */
145         movw    %bx, %ds
146
147         /* Record command line address */
148         movl    %esi, cmdline_phys
149
150         /* Run iPXE */
151         pushl   $main
152         pushw   %cs
153         call    prot_call
154         popl    %ecx /* discard */
155
156         /* Uninstall iPXE */
157         call    uninstall
158
159         /* Exit back to DOS.  This is very unlikely to work */
160         movw    $0x4c00, %ax
161         int     $0x21