Skip to content

Commit fac651c

Browse files
committed
[pxe] Add memtest.0 target which can be loaded as a PXE NBP
Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent ac60212 commit fac651c

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ OBJS= head.o reloc.o main.o test.o init.o lib.o patn.o screen_buffer.o \
2020
smp.o vmem.o random.o
2121

2222

23-
all: memtest.bin memtest
23+
all: memtest.bin memtest memtest.0
2424

2525
# Link it statically once so I know I don't have undefined
2626
# symbols and then link it dynamically so I have full
@@ -45,10 +45,17 @@ bootsect.s: bootsect.S config.h defs.h
4545
setup.s: setup.S config.h defs.h
4646
$(CC) -E -traditional $< -o $@
4747

48+
pxe.s: pxe.S config.h defs.h
49+
$(CC) -E -traditional $< -o $@
50+
4851
memtest.bin: memtest_shared.bin bootsect.o setup.o memtest.bin.lds
4952
$(LD) -T memtest.bin.lds bootsect.o setup.o -b binary \
5053
memtest_shared.bin -o memtest.bin
5154

55+
memtest.0: memtest_shared.bin pxe.o setup.o memtest.bin.lds
56+
$(LD) -T memtest.bin.lds pxe.o setup.o -b binary \
57+
memtest_shared.bin -o memtest.0
58+
5259
reloc.o: reloc.c
5360
$(CC) -c $(CFLAGS) -fno-strict-aliasing reloc.c
5461

@@ -64,7 +71,7 @@ build_number:
6471

6572
clean:
6673
rm -f *.o *.s *.iso memtest.bin memtest memtest_shared \
67-
memtest_shared.bin memtest.iso
74+
memtest_shared.bin memtest.iso memtest.0
6875

6976
iso:
7077
make all

pxe.S

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* pxe.S Copyright (C) 2012 Michael Brown <mcb30@ipxe.org>
3+
*
4+
* pxe.S is loaded at 0x7c00 by the PXE ROM. It copies the 32-bit
5+
* portion to 0x10000 and jumps into setup.S.
6+
*/
7+
8+
#include "defs.h"
9+
10+
#define RMSIZE (0x200 + 0x200*SETUPSECS)
11+
12+
#define PXENV_ENTRY 0x0a
13+
#define PXENV_UNDI_SHUTDOWN 0x0005
14+
15+
.code16
16+
.section ".bootsect", "ax", @progbits
17+
.org 0
18+
_pxe:
19+
20+
.globl _main
21+
_main:
22+
/* Canonicalise addresses */
23+
ljmp $BOOTSEG, $pxe_start
24+
25+
pxe_start:
26+
/* Store PXENV+ entry point */
27+
movl %es:PXENV_ENTRY(%bx), %eax
28+
movl %eax, %cs:pxenv_vector
29+
30+
/* Copy 32-bit portion to TSTLOAD:0000. Perform copy in
31+
* reverse in 1kB blocks, since regions will overlap and we
32+
* need to copy more than the 64kB real-mode segment limit.
33+
*/
34+
movw $_syssize, %bx /* Length is _syssize (paragraphs) */
35+
addw $63, %bx
36+
andw $~63, %bx /* Round up to nearest kB */
37+
movw $(BOOTSEG + (RMSIZE >> 4)), %ax
38+
addw %bx, %ax
39+
movw %ax, %ds
40+
movw $TSTLOAD, %ax
41+
addw %bx, %ax
42+
movw %ax, %es
43+
1: movw %ds, %ax /* Decrement %ds and %es by 1kB */
44+
subw $64, %ax
45+
movw %ax, %ds
46+
movw %es, %ax
47+
subw $64, %ax
48+
movw %ax, %es
49+
movw $256, %cx /* Copy 1kB block */
50+
xorw %si, %si
51+
xorw %di, %di
52+
cld
53+
rep movsl
54+
subw $64, %bx
55+
jnz 1b
56+
57+
/* Set up %ds and %es for access to local variables */
58+
movw %cs, %ax
59+
movw %ax, %ds
60+
movw %ax, %es
61+
62+
/* Shutdown NIC */
63+
movw $PXENV_UNDI_SHUTDOWN, %bx
64+
movw $pxenv_undi_shutdown, %di
65+
lcall *pxenv_vector
66+
67+
/* Jump to setup.S */
68+
ljmp $(BOOTSEG + 0x20), $0
69+
70+
pxenv_vector:
71+
.word 0,0
72+
73+
pxenv_undi_shutdown:
74+
.word 0 /* Status */
75+
76+
.org 512
77+
_epxe:

0 commit comments

Comments
 (0)