Browse Source

[exeprefix] Add .exe prefix

An iPXE .exe image can be loaded from DOS.  Tested using bin/ipxe.exe
to load a Linux kernel and simple initramfs from within MS-DOS 6.22.
(EDD must be disabled using the "edd=off" kernel parameter, since the
loaded kernel image has already overwritten parts of DOS' INT 13
wrapper.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
f9e3581175
2 changed files with 158 additions and 0 deletions
  1. 2
    0
      src/arch/i386/Makefile.pcbios
  2. 156
    0
      src/arch/i386/prefix/exeprefix.S

+ 2
- 0
src/arch/i386/Makefile.pcbios View File

@@ -24,6 +24,7 @@ MEDIA		+= dsk
24 24
 MEDIA		+= nbi
25 25
 MEDIA		+= hd
26 26
 MEDIA		+= raw
27
+MEDIA		+= exe
27 28
 
28 29
 # Padding rules
29 30
 #
@@ -31,6 +32,7 @@ PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff $@
31 32
 PAD_mrom	= $(PAD_rom)
32 33
 PAD_dsk		= $(PERL) $(PADIMG) --blksize=512 $@
33 34
 PAD_hd		= $(PERL) $(PADIMG) --blksize=32768 $@
35
+PAD_exe		= $(PERL) $(PADIMG) --blksize=512 $@
34 36
 
35 37
 # Finalisation rules
36 38
 #

+ 156
- 0
src/arch/i386/prefix/exeprefix.S View File

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

Loading…
Cancel
Save