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