~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/arch/x86/prefix/exeprefix.S

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

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