Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e103495563 | ||
|
|
518cd2f192 | ||
|
|
afe59d4636 | ||
|
|
b9d791f4d1 | ||
|
|
4f3bab1a55 | ||
|
|
43834f5d25 | ||
|
|
784d3f336e | ||
|
|
6a3f5d6db7 | ||
|
|
4dd746a725 | ||
|
|
78d426d196 | ||
|
|
9937bf13c9 | ||
|
|
e950dc04ba | ||
|
|
b4d3d686cc | ||
|
|
a3219b24a8 | ||
|
|
5de8305feb | ||
|
|
991f907d5b | ||
|
|
aaa26f3bd3 | ||
|
|
b5577553e5 | ||
|
|
dd44a7c314 | ||
|
|
7b1a5a7997 | ||
|
|
3206e470d0 | ||
|
|
6de4db5da0 | ||
|
|
bea828b9ed | ||
|
|
54840039f6 | ||
|
|
67ee41ad6d | ||
|
|
cff419148c | ||
|
|
06b5132fdc | ||
|
|
dbbd81c140 | ||
|
|
5026a35fef | ||
|
|
7f903f03af | ||
|
|
14eafc5b8d | ||
|
|
8904cd55f1 | ||
|
|
349868b8fd | ||
|
|
7bc4093e1a | ||
|
|
b08e255ef1 | ||
|
|
78a57a6f76 | ||
|
|
24e948f030 | ||
|
|
076154a1c6 | ||
|
|
f16668dd60 | ||
|
|
79867d34ee | ||
|
|
c9e5b12473 | ||
|
|
ce2aa66d39 | ||
|
|
8ae1cac050 | ||
|
|
46da51703a | ||
|
|
816a32aaee | ||
|
|
ef70f87997 | ||
|
|
d900ae05d7 | ||
|
|
4e6b62c946 | ||
|
|
8e960eb67c | ||
|
|
5a99c586cf | ||
|
|
750c19466a | ||
|
|
e9c10ca158 | ||
|
|
56066a6085 | ||
|
|
881f1f59ef | ||
|
|
ff2b308506 | ||
|
|
4b276b8df9 | ||
|
|
dbe84c5aad | ||
|
|
0171098212 | ||
|
|
4502c04360 | ||
|
|
6711ce18a7 | ||
|
|
e65afc4b10 | ||
|
|
d2b0081740 | ||
|
|
b111bdfb00 | ||
|
|
52c596bafb | ||
|
|
d10a7e7739 | ||
|
|
a128973ecb | ||
|
|
1284773363 | ||
|
|
027c72e0d0 | ||
|
|
f1d17ae2be | ||
|
|
ce9690ca39 | ||
|
|
3f814f08e5 | ||
|
|
773d9631ef | ||
|
|
76d05a4da0 | ||
|
|
cf53998901 | ||
|
|
6941793416 | ||
|
|
d230b53df2 | ||
|
|
b4a95a8974 | ||
|
|
7be5fa82e3 | ||
|
|
d7de30e5e4 | ||
|
|
08f6d22410 | ||
|
|
aa86afe890 | ||
|
|
cced04ef3b | ||
|
|
8fd81349b3 | ||
|
|
48b2f70ee4 | ||
|
|
ba1016f378 | ||
|
|
3e220aa73e | ||
|
|
fb72336fe6 | ||
|
|
765efac771 | ||
|
|
314779eb36 | ||
|
|
85e5e25c52 | ||
|
|
21cfab4fb8 | ||
|
|
53a7dd26cd | ||
|
|
8674bc05a0 | ||
|
|
57bbf0ec98 | ||
|
|
1941c933f8 | ||
|
|
1206999288 | ||
|
|
ce0a0ccf5c | ||
|
|
b0d2c9a4d5 | ||
|
|
29480dd715 | ||
|
|
045a22764a | ||
|
|
3a799e99ca | ||
|
|
4d7c650164 | ||
|
|
708e6e0613 | ||
|
|
74b7bc0954 | ||
|
|
7166bc7b2d | ||
|
|
e78bcb6175 | ||
|
|
02a0215873 | ||
|
|
8e8a348fd4 | ||
|
|
246ddf5ee4 | ||
|
|
a2686a55c4 | ||
|
|
b48f37e69a | ||
|
|
14a739ba6a | ||
|
|
d3d8f20626 | ||
|
|
fc49421c7e | ||
|
|
5dd5107976 | ||
|
|
0ebbbb95fa | ||
|
|
7d36a1b7b0 | ||
|
|
3f85626fa9 | ||
|
|
d9b3d09910 | ||
|
|
b59e0cc56e | ||
|
|
849e4b12d6 | ||
|
|
dc60c24146 | ||
|
|
446b6d5fdd | ||
|
|
fca2dcabb8 | ||
|
|
ab96932ab3 | ||
|
|
0a8a17e669 | ||
|
|
85f82f09e9 | ||
|
|
cc93556725 | ||
|
|
c661945e82 | ||
|
|
54fbd11221 | ||
|
|
464bf35cc0 | ||
|
|
8a80e7ace1 | ||
|
|
1b3edd9e11 | ||
|
|
2ca2607b1b | ||
|
|
125c6d66a8 | ||
|
|
9e5fd8ec59 | ||
|
|
c0ec00f47f | ||
|
|
9a35830d1f | ||
|
|
663904a7bc | ||
|
|
830e19eb54 | ||
|
|
0de5f7af6d | ||
|
|
d9751edafa | ||
|
|
dd34500188 | ||
|
|
180d99fc22 | ||
|
|
9a52ba0cfa | ||
|
|
46f43d8ea7 | ||
|
|
43aa69d7b3 | ||
|
|
ed196a3ed2 | ||
|
|
29e6f9835e | ||
|
|
aa95744915 | ||
|
|
5e6b82104d | ||
|
|
32bc76f902 | ||
|
|
467c4f77c3 | ||
|
|
0a6c66a830 | ||
|
|
621101c36a | ||
|
|
1bc2adea9a | ||
|
|
664f4cf365 | ||
|
|
df033de24f | ||
|
|
7a4c129af7 | ||
|
|
3fe6bede74 | ||
|
|
d4c8273569 | ||
|
|
bcc70d6b99 | ||
|
|
612f4e7a99 | ||
|
|
cbf9003d66 | ||
|
|
85f09b5fc0 | ||
|
|
22979c511e | ||
|
|
d9c38d14d6 | ||
|
|
5600955bdd | ||
|
|
7982e79d3c | ||
|
|
04f3206581 | ||
|
|
58dd6e04c5 | ||
|
|
744b98d273 | ||
|
|
c99b16c974 | ||
|
|
3a505dfc35 | ||
|
|
6b9cc25556 | ||
|
|
832668105e | ||
|
|
64e5ca0582 | ||
|
|
81d92c6d34 | ||
|
|
54c024e0af | ||
|
|
d4e152e766 | ||
|
|
07e8f18f33 | ||
|
|
831e4cfc27 | ||
|
|
6554b79ff9 | ||
|
|
667819becc | ||
|
|
c0835339d0 | ||
|
|
658c6dba59 | ||
|
|
16f1e35775 | ||
|
|
e6f276ece3 | ||
|
|
f945d6d201 | ||
|
|
941b4c2adb | ||
|
|
8a4ccebec9 | ||
|
|
fd67452807 | ||
|
|
e226a8d8d9 | ||
|
|
8c7deba349 | ||
|
|
aef6d0df5c | ||
|
|
992bbf309c | ||
|
|
8e38669d54 | ||
|
|
a1e11a6beb | ||
|
|
1641b5d39b | ||
|
|
ee2df1d6d6 | ||
|
|
8956a36be5 | ||
|
|
b40b4f2dbf | ||
|
|
0b5c39d167 | ||
|
|
2e812235f4 | ||
|
|
ac663cf509 | ||
|
|
13d09e6719 | ||
|
|
3029eb0e84 | ||
|
|
5c695db474 | ||
|
|
98abd48a26 | ||
|
|
3f80f9e1a6 | ||
|
|
cdd619d11f | ||
|
|
96ea558e98 | ||
|
|
e817a347fb | ||
|
|
a2588547f9 | ||
|
|
f0b942ef42 | ||
|
|
160b950af8 | ||
|
|
19a0452205 | ||
|
|
521549d900 | ||
|
|
9dccbc0af2 | ||
|
|
91802c6e85 | ||
|
|
afe1323c76 | ||
|
|
9b01a9fd9c | ||
|
|
60c3b69c31 | ||
|
|
8c3e95ce42 | ||
|
|
df02c54f86 | ||
|
|
76f6cad8af | ||
|
|
e899f100ca | ||
|
|
e8b6077566 | ||
|
|
6f87d622e1 | ||
|
|
1dda75c9cd | ||
|
|
040f7cdf3a | ||
|
|
0015601f0b | ||
|
|
50dc9344b7 | ||
|
|
e3c5507178 | ||
|
|
39047c5636 | ||
|
|
2d41dead08 | ||
|
|
6eaefa16a8 | ||
|
|
601d244a8e | ||
|
|
6936c40fef | ||
|
|
e2d5788716 | ||
|
|
9d72636da1 | ||
|
|
3392cfa7df | ||
|
|
fa880ec70a | ||
|
|
b45b39260c | ||
|
|
c24bc349ea | ||
|
|
9c71949d1f | ||
|
|
539f94b980 | ||
|
|
aa8d972581 | ||
|
|
fed106b7fb | ||
|
|
887d77c27a | ||
|
|
35b7658877 | ||
|
|
b350b10b35 | ||
|
|
9d44a06188 | ||
|
|
4011f9d956 | ||
|
|
8b20e5d2b7 | ||
|
|
e13d793160 | ||
|
|
a2f9bf70d7 | ||
|
|
ca0b0f0616 | ||
|
|
0fd1e54026 | ||
|
|
0e408658b9 | ||
|
|
6df82b1a9d | ||
|
|
8223084afc | ||
|
|
18aa0e79d2 | ||
|
|
a30c70727a | ||
|
|
c0beec8baf | ||
|
|
2e03610c0d | ||
|
|
6de45ad4ae | ||
|
|
99251f5b32 | ||
|
|
e8b22f203f | ||
|
|
aa28544373 | ||
|
|
2539f5fa4a | ||
|
|
179fa70d34 | ||
|
|
fc0c40a5b0 | ||
|
|
32e34683c0 | ||
|
|
cb6fea0690 | ||
|
|
bd5189a96d | ||
|
|
d5732b0272 | ||
|
|
07581d3faa | ||
|
|
de7be480d6 | ||
|
|
f58cc3fca8 | ||
|
|
d5e07dfe92 | ||
|
|
82baea0a4b | ||
|
|
4815188dfc | ||
|
|
0ffc3f6285 | ||
|
|
2090aade04 | ||
|
|
30fb3b3810 | ||
|
|
f6f6f626f7 | ||
|
|
0c7618771e | ||
|
|
320b072c7a | ||
|
|
9737095d49 | ||
|
|
23bca8f9d8 | ||
|
|
8f8f5acf09 | ||
|
|
a1d0f6ed2e | ||
|
|
ff2b6a512d | ||
|
|
5d4839b577 | ||
|
|
7ad2f652b4 | ||
|
|
8332ddf556 | ||
|
|
f178436bb1 | ||
|
|
ed73d53503 | ||
|
|
50babca5da | ||
|
|
481a21798d | ||
|
|
193426d960 | ||
|
|
12a37ab99e | ||
|
|
6f73bb5e00 | ||
|
|
e6cd16946a | ||
|
|
8f4c2b4a4c | ||
|
|
fe1f017bde | ||
|
|
4cc786de81 | ||
|
|
594c672b75 | ||
|
|
34a06b6ba7 | ||
|
|
702e0be44e | ||
|
|
764e2cc68c | ||
|
|
833447392d | ||
|
|
6b58992318 | ||
|
|
c302eeda5a | ||
|
|
f493283c74 | ||
|
|
03c80c12b8 | ||
|
|
4e033c774b | ||
|
|
bb41ec385c | ||
|
|
21e9e801e2 | ||
|
|
6f39dfe6c0 | ||
|
|
34c1a5b91d | ||
|
|
997bccc64e | ||
|
|
d474386336 | ||
|
|
22d00797f1 | ||
|
|
4f05d2fca7 | ||
|
|
0436e417bc | ||
|
|
4f2861a376 | ||
|
|
14c080020f | ||
|
|
4847d97372 | ||
|
|
dbe9269f3a | ||
|
|
2df682c5be | ||
|
|
3ad348e55a | ||
|
|
227bb05a50 | ||
|
|
4fbbf651d7 | ||
|
|
d51d80f785 | ||
|
|
fdb8481de1 | ||
|
|
25450dc59c | ||
|
|
1152b78ec1 | ||
|
|
1719b105cd | ||
|
|
ce51128534 | ||
|
|
e9e1da131a | ||
|
|
7eb555a8ae | ||
|
|
fe79edfc3d | ||
|
|
578b056730 | ||
|
|
3715c8c721 | ||
|
|
5504fa9047 | ||
|
|
19386ec2c8 | ||
|
|
6e670b5f38 | ||
|
|
9ec3ff95f0 | ||
|
|
59b5465b30 | ||
|
|
27731d975e | ||
|
|
4c75e9ded4 | ||
|
|
2596a9aa9c | ||
|
|
b7882065f5 | ||
|
|
2b9e7a4767 | ||
|
|
14fe4d4ba5 | ||
|
|
ddf5c8d4d3 | ||
|
|
0ea821c7b7 | ||
|
|
0d91c37ce5 | ||
|
|
cd0e9bcd22 | ||
|
|
a71b4df1c9 | ||
|
|
31c6df5365 | ||
|
|
ac28d054c8 | ||
|
|
4c85017968 | ||
|
|
031b30898a | ||
|
|
c3811d4a13 | ||
|
|
50810955e9 | ||
|
|
5d36ec6721 | ||
|
|
32e8ab4df0 | ||
|
|
3a2c8a2690 | ||
|
|
2456b9b4ba | ||
|
|
1e5c2d48cb | ||
|
|
81d92d5181 | ||
|
|
798ddf884f | ||
|
|
72c1bb8224 | ||
|
|
aa160211c2 | ||
|
|
77a5cc6b13 | ||
|
|
fe3162ab1c | ||
|
|
db5f64ecdc | ||
|
|
b5215803f0 | ||
|
|
5102033215 | ||
|
|
4180815a90 | ||
|
|
04bc50f025 | ||
|
|
831db76ff7 | ||
|
|
f866b17998 | ||
|
|
842165ef76 | ||
|
|
1a68d3fef3 | ||
|
|
d615b00443 | ||
|
|
75965c9c6e | ||
|
|
c899bdc5a8 | ||
|
|
7cd08434ea | ||
|
|
fd0aef9ee1 | ||
|
|
f3aef4d98d | ||
|
|
711a59cf03 | ||
|
|
f43a7e349a | ||
|
|
fbf9295cbb | ||
|
|
ce298a9628 | ||
|
|
43b04236ec | ||
|
|
30cd348689 | ||
|
|
7d01bf663e | ||
|
|
78281b09e6 | ||
|
|
1dcc60e5ad | ||
|
|
00ed567069 | ||
|
|
eec9814a0e | ||
|
|
3430226d40 | ||
|
|
1ba959c6b3 | ||
|
|
d72bf13b78 | ||
|
|
c9fb012d4f | ||
|
|
35a5836677 | ||
|
|
e55bab3ce3 | ||
|
|
a176a24ac0 | ||
|
|
3475b693b7 | ||
|
|
fbb6a3fd65 | ||
|
|
b107637008 | ||
|
|
feade5da6e | ||
|
|
aa74a7d53c | ||
|
|
af466aedf1 | ||
|
|
7a4e212fe2 | ||
|
|
978996cdae | ||
|
|
4b267ed713 | ||
|
|
d810dc5be2 | ||
|
|
61ee294875 | ||
|
|
d62e89d776 | ||
|
|
83617e5b1c | ||
|
|
96edbd128f | ||
|
|
92d15eff30 | ||
|
|
ee5bdb0d75 | ||
|
|
7234f91bf8 | ||
|
|
8f00c84828 | ||
|
|
c06e6d0635 | ||
|
|
dbf8a02e8f | ||
|
|
23e077666b | ||
|
|
978865da2f | ||
|
|
2af6c8d130 | ||
|
|
ee4206a8a7 | ||
|
|
1741e3e761 | ||
|
|
8fceee785f | ||
|
|
65c0974d1f | ||
|
|
e5cea13e51 | ||
|
|
a462c96ffc | ||
|
|
8afb36c3bc | ||
|
|
bb32b8999c | ||
|
|
a9b62cfe8c | ||
|
|
1edbcd4246 | ||
|
|
720e256c50 | ||
|
|
0fbe484566 | ||
|
|
aec9b8a41b | ||
|
|
eae6ac3d0b | ||
|
|
cf03304620 | ||
|
|
acfa14423e | ||
|
|
260b93bb72 | ||
|
|
a48b4d9948 | ||
|
|
e97ae4a788 | ||
|
|
7067142fb4 | ||
|
|
af1c6b869c | ||
|
|
070cbebc26 | ||
|
|
2652abdc5f | ||
|
|
03398e3389 | ||
|
|
e2613e8896 | ||
|
|
6fe585642a | ||
|
|
5a08b434c7 | ||
|
|
08b19abf94 | ||
|
|
66d9a411f7 | ||
|
|
3bf7105cab | ||
|
|
9c86a39551 | ||
|
|
297002d7bd | ||
|
|
3e781eb87f | ||
|
|
1dd3f88964 | ||
|
|
12f203c606 | ||
|
|
fad35829eb | ||
|
|
06e8a70488 | ||
|
|
8de54ef9aa | ||
|
|
b62f2325ba | ||
|
|
b08a6f5300 | ||
|
|
4704abbc50 | ||
|
|
3dd897f986 | ||
|
|
1935439f86 | ||
|
|
379c37bafb | ||
|
|
a1572e0ab0 | ||
|
|
4006d229e5 | ||
|
|
844828cb15 | ||
|
|
bc3f0a25c6 | ||
|
|
6570203571 | ||
|
|
03d1fc1da3 | ||
|
|
396dc6e797 | ||
|
|
ea5ad4be91 | ||
|
|
563955ce37 | ||
|
|
604c934981 | ||
|
|
b87904ab20 |
@@ -25,9 +25,10 @@ To get bochs running is fairly simple:
|
||||
|
||||
3. Configure bochs with
|
||||
pushd bochs
|
||||
./configure --enable-all-optimisations --enable-pci --enable-pnic \
|
||||
--enable-debugger --enable-magic-breakpoints \
|
||||
--enable-disasm --enable-show-ips --enable-ne2000
|
||||
./configure --enable-all-optimisations --enable-show-ips \
|
||||
--enable-cpu-level=6 \
|
||||
--enable-pci --enable-pnic --enable-ne2000 \
|
||||
--enable-debugger --enable-disasm
|
||||
popd
|
||||
|
||||
4. Build bochs:
|
||||
|
||||
+11
-19
@@ -1,5 +1,5 @@
|
||||
Running Etherboot within qemu
|
||||
=============================
|
||||
Running gPXE within qemu
|
||||
========================
|
||||
|
||||
Michael Brown <mbrown@fensystems.co.uk>
|
||||
|
||||
@@ -9,13 +9,10 @@ To get qemu running is fairly simple:
|
||||
make
|
||||
|
||||
2. Get the qemu source code:
|
||||
cvs -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu \
|
||||
login
|
||||
cvs -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu \
|
||||
co qemu
|
||||
svn co svn://svn.savannah.nongnu.org/qemu/trunk qemu
|
||||
|
||||
2a. Patch the qemu code. There is currently a bug that causes qemu to
|
||||
execute Etherboot incredibly slowly. The bug seems to be related
|
||||
execute gPXE incredibly slowly. The bug seems to be related
|
||||
to the relative prioritisation of CPU and I/O operations within
|
||||
qemu. This patch (which I found via Google) isn't a proper fix,
|
||||
but it does work around the problem:
|
||||
@@ -23,13 +20,9 @@ To get qemu running is fairly simple:
|
||||
|
||||
3. Configure qemu with
|
||||
pushd qemu
|
||||
./configure --enable-system
|
||||
./configure --target-list=i386-softmmu,x86_64-softmmu
|
||||
popd
|
||||
|
||||
Note that qemu will not compile with gcc4; if your system's
|
||||
default compiler is gcc4 then specify the path to gcc3 using
|
||||
e.g. --cc=gcc-3.3.6
|
||||
|
||||
4. Build qemu:
|
||||
make -C qemu
|
||||
|
||||
@@ -44,7 +37,7 @@ To get qemu running is fairly simple:
|
||||
range dynamic-bootp 10.254.254.1 10.254.254.1;
|
||||
}
|
||||
You will also need to add in any of your usual declarations for
|
||||
Etherboot, e.g. 'filename "vmlinuz.ltsp";'. Note that this setup
|
||||
gPXE, e.g. 'filename "vmlinuz.ltsp";'. Note that this setup
|
||||
assumes that your DHCP server, TFTP server etc. all live on the
|
||||
machine you are using for running qemu. If not, then you're on
|
||||
your own.
|
||||
@@ -52,19 +45,18 @@ To get qemu running is fairly simple:
|
||||
7. As root, restart dhcpd
|
||||
/etc/init.d/dhcpd restart
|
||||
|
||||
8. Build Etherboot floppy disk images and pad to 1.44MB
|
||||
8. Build gPXE floppy disk images and pad to 1.44MB
|
||||
pushd ../../src
|
||||
make bin/rtl8139.pdsk
|
||||
popd
|
||||
|
||||
9. Start qemu
|
||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
||||
./qemu/i386-softmmu/qemu -L qemu/pc-bios \
|
||||
-net nic,model=rtl8139 -net tap,ifname=tap0 \
|
||||
-boot a -fda ../../src/bin/rtl8139.pdsk
|
||||
|
||||
You should see qemu start up, load up Etherboot and attempt to boot
|
||||
from the network.
|
||||
You should see qemu start up, load up gPXE and attempt to boot from
|
||||
the network.
|
||||
|
||||
|
||||
|
||||
@@ -72,8 +64,8 @@ Serial console
|
||||
==============
|
||||
|
||||
You can use the program "serial-console" to obtain a virtual serial
|
||||
console for Etherboot running within qemu. Run "./serial-console" on
|
||||
a spare tty (e.g. a separate xterm window) before starting qemu, and
|
||||
console for gPXE running within qemu. Run "./serial-console" on a
|
||||
spare tty (e.g. a separate xterm window) before starting qemu, and
|
||||
ensure that you have enabled CONSOLE_SERIAL in config.h.
|
||||
|
||||
When serial-console starts, it will print out the message "Slave pty
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
Index: memory/memory.cc
|
||||
===================================================================
|
||||
RCS file: /cvsroot/bochs/bochs/memory/memory.cc,v
|
||||
retrieving revision 1.71
|
||||
diff -u -r1.71 memory.cc
|
||||
--- memory/memory.cc 18 Oct 2008 18:10:14 -0000 1.71
|
||||
+++ memory/memory.cc 21 Oct 2008 19:47:07 -0000
|
||||
@@ -172,7 +172,11 @@
|
||||
break;
|
||||
|
||||
case 0x0: // Writes to ROM, Inhibit
|
||||
- BX_DEBUG(("Write to ROM ignored: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
|
||||
+ if ((a20addr & 0xfffe0000) == 0x000e0000) {
|
||||
+ BX_DEBUG(("Write to ROM ignored: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
|
||||
+ } else {
|
||||
+ BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ] = *data_ptr;
|
||||
+ }
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -224,8 +224,8 @@ if ( -t STDIN ) {
|
||||
$restore_termios = POSIX::Termios->new;
|
||||
$termios->getattr ( fileno(STDIN) );
|
||||
$restore_termios->getattr ( fileno(STDIN) );
|
||||
$termios->setlflag ( $termios->getlflag &
|
||||
~(ICANON) & ~(ECHO) );
|
||||
$termios->setlflag ( $termios->getlflag & ~(ICANON) & ~(ECHO) );
|
||||
$termios->setiflag ( $termios->getiflag & ~(ICRNL) );
|
||||
$termios->setattr ( fileno(STDIN), TCSANOW );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
Error Code Lookup for gPXE
|
||||
==========================
|
||||
This program looks up gPXE error codes so you can locate the line of source
|
||||
code which produced the error.
|
||||
|
||||
Setup
|
||||
-----
|
||||
You must run:
|
||||
./build_errcodedb.py >errcodedb.py
|
||||
|
||||
This extracts error code definitions from the gPXE source code and produces a
|
||||
"database" which is used by the main program.
|
||||
|
||||
Once you have done this errcode.py and errcodedb.py are the only files you
|
||||
need. They are now independent of the gPXE source code and can be moved
|
||||
anywhere.
|
||||
|
||||
[OPTIONAL]
|
||||
A PHP script is provided as a web interface. First edit errcode.php to point
|
||||
$ERRCODE_PATH to the errcode.py script. Then move errcode.php to a location
|
||||
visible from your web server.
|
||||
|
||||
[OPTIONAL]
|
||||
A simple IRC bot is provided. Edit gpxebot.py to fill in the IRC details.
|
||||
|
||||
Usage
|
||||
-----
|
||||
Looking up error codes on the command-line:
|
||||
./errcode.py 0x12345678
|
||||
|
||||
Further information
|
||||
-------------------
|
||||
See http://etherboot.org/.
|
||||
|
||||
Released under the GPL and written by Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
import sys
|
||||
import re
|
||||
|
||||
pxenv_status_files = ('../../src/include/errno.h', )
|
||||
errfile_files = ('../../src/include/gpxe/errfile.h',
|
||||
'../../src/arch/i386/include/bits/errfile.h')
|
||||
posix_errno_files = ('../../src/include/errno.h', )
|
||||
|
||||
PXENV_STATUS_RE = re.compile(r'^#define\s+(PXENV_STATUS_[^\s]+)\s+(.+)$', re.M)
|
||||
ERRFILE_RE = re.compile(r'^#define\s+(ERRFILE_[^\s]+)\s+(.+)$', re.M)
|
||||
POSIX_ERRNO_RE = re.compile(r'^#define\s+(E[A-Z0-9]+)\s+(?:\\\n)?.*(0x[0-9a-f]+).*$', re.M)
|
||||
|
||||
def err(msg):
|
||||
sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
|
||||
sys.exit(1)
|
||||
|
||||
def to_pxenv_status(errno):
|
||||
return errno & 0xff
|
||||
|
||||
def to_errfile(errno):
|
||||
return (errno >> 13) & 0x7ff
|
||||
|
||||
def to_posix_errno(errno):
|
||||
return (errno >> 24) & 0x7f
|
||||
|
||||
def load_header_file(filename, regexp):
|
||||
defines = {}
|
||||
data = open(filename, 'r').read()
|
||||
for m in regexp.finditer(data):
|
||||
key, val = m.groups()
|
||||
defines[key] = val
|
||||
return defines
|
||||
|
||||
def evaluate(defines, expr):
|
||||
pyexpr = ''
|
||||
for token in expr.split():
|
||||
if token in '()':
|
||||
pass
|
||||
elif token.startswith('/*') or token.startswith('//'):
|
||||
break
|
||||
elif token.startswith('0x') or token == '|':
|
||||
pyexpr += token
|
||||
else:
|
||||
if token in defines:
|
||||
pyexpr += '0x%x' % defines[token]
|
||||
else:
|
||||
return -1
|
||||
if not re.match(r'^[0-9a-zA-Z_|]+$', pyexpr):
|
||||
err('invalid expression')
|
||||
return eval(pyexpr)
|
||||
|
||||
def build(filenames, regexp, selector):
|
||||
unevaluated = {}
|
||||
for filename in filenames:
|
||||
unevaluated.update(load_header_file(filename, regexp))
|
||||
|
||||
evaluated = {}
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for key in list(unevaluated.keys()):
|
||||
val = evaluate(evaluated, unevaluated[key])
|
||||
if val != -1:
|
||||
del unevaluated[key]
|
||||
evaluated[key] = val
|
||||
changed = True
|
||||
if unevaluated:
|
||||
err('unable to evaluate all #defines')
|
||||
|
||||
lookup = {}
|
||||
for key, val in evaluated.iteritems():
|
||||
lookup[selector(val)] = key
|
||||
return lookup
|
||||
|
||||
print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE, to_pxenv_status))
|
||||
print 'errfile =', repr(build(errfile_files, ERRFILE_RE, to_errfile))
|
||||
print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE, to_posix_errno))
|
||||
@@ -0,0 +1,83 @@
|
||||
<?
|
||||
/*
|
||||
* Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
// The path to the errcode.py script.
|
||||
$ERRCODE_PATH = './errcode.py';
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>gPXE Error Code Lookup</title>
|
||||
<style>
|
||||
body, pre, div, form, p, h2, b, tt {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
body {
|
||||
padding: 0.5em;
|
||||
width: 750px;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
pre {
|
||||
margin: 0.2em;
|
||||
padding: 0.1em;
|
||||
background-color: #ddd;
|
||||
}
|
||||
form {
|
||||
margin: 0.2em;
|
||||
}
|
||||
div {
|
||||
margin: 0.2em;
|
||||
padding: 0.4em;
|
||||
border: 1px dashed black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?
|
||||
if (!empty($_REQUEST['e']) && preg_match('/^(0x)?[0-9a-f]{8}$/', $_REQUEST['e'])) {
|
||||
?>
|
||||
<pre>
|
||||
<?
|
||||
system($ERRCODE_PATH . " " . $_REQUEST['e']);
|
||||
?>
|
||||
</pre>
|
||||
<?
|
||||
}
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<label for="e">Error code:</label>
|
||||
<input type="text" name="e" id="e" value="0x12345678"></input>
|
||||
<input type="submit" value="Lookup"></input>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<h2>Hint:</h2>
|
||||
<p>
|
||||
Firefox users can right-click on the <b>Error code</b>
|
||||
text box and select <b>Add a Keyword for this Search...</b>.
|
||||
Set <b>name</b> to <tt>gPXE Error Code Lookup</tt> and
|
||||
<b>keyword</b> to <tt>gxpe</tt> Then you can look up error
|
||||
codes by typing something like the following in your address
|
||||
bar: <tt>gpxe 0x3c018003</tt>
|
||||
<p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
import sys
|
||||
|
||||
try:
|
||||
import errcodedb
|
||||
except ImportError:
|
||||
sys.stderr.write('Please run this first: ./build_errcodedb.py >errcodedb.py\n')
|
||||
sys.exit(1)
|
||||
|
||||
def to_pxenv_status(errno):
|
||||
return errno & 0xff
|
||||
|
||||
def to_uniq(errno):
|
||||
return (errno >> 8) & 0x1f
|
||||
|
||||
def to_errfile(errno):
|
||||
return (errno >> 13) & 0x7ff
|
||||
|
||||
def to_posix_errno(errno):
|
||||
return (errno >> 24) & 0x7f
|
||||
|
||||
def lookup_errno_component(defines, component):
|
||||
if component in defines:
|
||||
return defines[component]
|
||||
else:
|
||||
return '0x%x' % component
|
||||
|
||||
class Errcode(object):
|
||||
def __init__(self, errno):
|
||||
self.pxenv_status = to_pxenv_status(errno)
|
||||
self.uniq = to_uniq(errno)
|
||||
self.errfile = to_errfile(errno)
|
||||
self.posix_errno = to_posix_errno(errno)
|
||||
|
||||
def rawstr(self):
|
||||
return 'pxenv_status=0x%x uniq=%d errfile=0x%x posix_errno=0x%x' % (self.pxenv_status, self.uniq, self.errfile, self.posix_errno)
|
||||
|
||||
def prettystr(self):
|
||||
return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
|
||||
lookup_errno_component(errcodedb.pxenv_status, self.pxenv_status),
|
||||
self.uniq,
|
||||
lookup_errno_component(errcodedb.errfile, self.errfile),
|
||||
lookup_errno_component(errcodedb.posix_errno, self.posix_errno)
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.prettystr()
|
||||
|
||||
def usage():
|
||||
sys.stderr.write('usage: %s ERROR_NUMBER\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
usage()
|
||||
|
||||
try:
|
||||
errno = int(sys.argv[1], 16)
|
||||
except ValueError:
|
||||
usage()
|
||||
|
||||
print Errcode(errno)
|
||||
sys.exit(0)
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
import re
|
||||
import socket
|
||||
import errcode
|
||||
|
||||
HOST = 'irc.freenode.net'
|
||||
PORT = 6667
|
||||
NICK = 'gpxebot'
|
||||
CHAN = '#etherboot'
|
||||
NICKSERV_PASSWORD = None
|
||||
IDENT = 'gpxebot'
|
||||
REALNAME = 'gPXE bot'
|
||||
|
||||
ERRCODE_RE = re.compile(r'(errcode|Error)\s+((0x)?[0-9a-fA-F]{8})')
|
||||
|
||||
NO_ARGS = -1
|
||||
|
||||
handlers = {}
|
||||
|
||||
def nick_from_mask(mask):
|
||||
return (mask.find('!') > -1 and mask.split('!', 1)[0]) or mask
|
||||
|
||||
def autojoin():
|
||||
del handlers['376']
|
||||
if NICKSERV_PASSWORD:
|
||||
pmsg('nickserv', 'identify %s' % NICKSERV_PASSWORD)
|
||||
if CHAN:
|
||||
cmd('JOIN %s' % CHAN)
|
||||
|
||||
def ping(_, arg):
|
||||
cmd('PONG %s' % arg)
|
||||
|
||||
def privmsg(_, target, msg):
|
||||
if target == CHAN:
|
||||
replyto = target
|
||||
if msg.find(NICK) == -1:
|
||||
return
|
||||
elif target == NICK:
|
||||
replyto = nick_from_mask(who)
|
||||
m = ERRCODE_RE.search(msg)
|
||||
if m:
|
||||
try:
|
||||
pmsg(replyto, str(errcode.Errcode(int(m.groups()[1], 16))))
|
||||
except ValueError:
|
||||
pass
|
||||
if msg.find('help') > -1:
|
||||
pmsg(replyto, 'I look up gPXE error codes. Message me like this:')
|
||||
pmsg(replyto, 'errcode 0x12345678 OR Error 0x12345678')
|
||||
|
||||
def add_handler(command, handler, nargs):
|
||||
handlers[command] = (handler, nargs)
|
||||
|
||||
def cmd(msg):
|
||||
sock.sendall('%s\r\n' % msg)
|
||||
|
||||
def pmsg(target, msg):
|
||||
cmd('PRIVMSG %s :%s' % (target, msg))
|
||||
|
||||
def dispatch(args):
|
||||
command = args[0]
|
||||
if command in handlers:
|
||||
h = handlers[command]
|
||||
if h[1] == NO_ARGS:
|
||||
h[0]()
|
||||
elif len(args) == h[1]:
|
||||
h[0](*args)
|
||||
|
||||
def parse(line):
|
||||
if line[0] == ':':
|
||||
who, line = line.split(None, 1)
|
||||
who = who[1:]
|
||||
else:
|
||||
who = None
|
||||
args = []
|
||||
while line and line[0] != ':' and line.find(' ') != -1:
|
||||
fields = line.split(None, 1)
|
||||
if len(fields) == 1:
|
||||
fields.append(None)
|
||||
arg, line = fields
|
||||
args.append(arg)
|
||||
if line:
|
||||
if line[0] == ':':
|
||||
args.append(line[1:])
|
||||
else:
|
||||
args.append(line)
|
||||
return who, args
|
||||
|
||||
add_handler('376', autojoin, NO_ARGS)
|
||||
add_handler('PING', ping, 2)
|
||||
add_handler('PRIVMSG', privmsg, 3)
|
||||
|
||||
sock = socket.socket()
|
||||
sock.connect((HOST, PORT))
|
||||
cmd('NICK %s' % NICK)
|
||||
cmd('USER %s none none :%s' % (IDENT, REALNAME))
|
||||
|
||||
rbuf = ''
|
||||
while True:
|
||||
r = sock.recv(4096)
|
||||
if not r:
|
||||
break
|
||||
rbuf += r
|
||||
|
||||
while rbuf.find('\r\n') != -1:
|
||||
line, rbuf = rbuf.split('\r\n', 1)
|
||||
if not line:
|
||||
continue
|
||||
who, args = parse(line)
|
||||
dispatch(args)
|
||||
@@ -0,0 +1,4 @@
|
||||
#!gpxe
|
||||
dhcp net0
|
||||
imgload img1
|
||||
boot img1
|
||||
@@ -0,0 +1,8 @@
|
||||
#!gpxe
|
||||
ifopen net0
|
||||
set net0/ip 10.0.2.15
|
||||
set net0/netmask 255.255.255.0
|
||||
set net0/gateway 10.0.2.2
|
||||
set net0/dns 10.0.2.3
|
||||
kernel http://etherboot.org/gtest/gtest.gpxe
|
||||
boot gtest.gpxe
|
||||
@@ -1,37 +0,0 @@
|
||||
## Makefile for use with gnu make and MinGW32 gnu gcc
|
||||
|
||||
TARGET=wol
|
||||
|
||||
CC=gcc
|
||||
LD=gcc
|
||||
|
||||
CPPFLAGS= -Wall -O2
|
||||
LFLAGS= -s
|
||||
|
||||
#LIBFILES= -lwsock
|
||||
#LIBPATH= -L/usr/lib
|
||||
|
||||
ICON=$(TARGET).ico
|
||||
OBJS=$(TARGET).o
|
||||
RESF=$(TARGET).rc
|
||||
|
||||
#RESNAME=$(TARGET).res
|
||||
#BINNAME=$(TARGET).exe
|
||||
BINNAME=$(TARGET)
|
||||
|
||||
$(BINNAME): $(OBJS) $(RESNAME)
|
||||
$(LD) $(LFLAGS) -o $@ $^ $(LIBPATH) $(LIBFILES)
|
||||
|
||||
%.res:%.rc
|
||||
windres -I rc -O coff -i $< -o $@
|
||||
|
||||
%.rc:Makefile
|
||||
@echo 100 ICON "$(ICON)" > $@
|
||||
|
||||
dist:$(BINNAME)
|
||||
rm -f $(OBJS) $(RESNAME) $(RESF)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(RESNAME) $(RESF)
|
||||
rm -f $(BINNAME)
|
||||
|
||||
@@ -1,3 +1,40 @@
|
||||
Here are two programs to send Wake-On-LAN packets to a dormant workstation
|
||||
using the WOL feature. Please contact the respective authors for any
|
||||
queries.
|
||||
From level42@sympatico.ca Tue Mar 18 04:35:31 2008
|
||||
Date: Mon, 17 Mar 2008 23:47:39 -0400
|
||||
From: Bill <level42@sympatico.ca>
|
||||
To: etherboot-developers@lists.sourceforge.net
|
||||
Subject: [Etherboot-developers] WOL Routine
|
||||
|
||||
Attached is a WOL routine that can be used to wake a remote server from
|
||||
gpxe. I put wol.c in src/usr and wol.h in src/include/usr. This is really
|
||||
in improved replacement of that in contrib\wakeonlan\wakeserver.patch. This
|
||||
version will no longer work since the eth_transmit routine no longer works
|
||||
with the newer driver arhitecture such as the e1000 driver.
|
||||
|
||||
Please consider adding it to gpxe preferrably in the main src directory or
|
||||
in the contrib directory.
|
||||
|
||||
Thank you
|
||||
|
||||
|
||||
[ Part 2, Text/PLAIN (Name: "wol.c") 109 lines. ]
|
||||
[ Unable to print this part. ]
|
||||
|
||||
|
||||
[ Part 3, Text/PLAIN (Name: "wol.h") 12 lines. ]
|
||||
[ Unable to print this part. ]
|
||||
|
||||
|
||||
[ Part 4: "Attached Text" ]
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This SF.net email is sponsored by: Microsoft
|
||||
Defy all challenges. Microsoft(R) Visual Studio 2008.
|
||||
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
|
||||
|
||||
[ Part 5: "Attached Text" ]
|
||||
|
||||
_______________________________________________
|
||||
Etherboot-developers mailing list
|
||||
Etherboot-developers@lists.sourceforge.net
|
||||
https://lists.sourceforge.net/lists/listinfo/etherboot-developers
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# maclist - mac addresses for wakeonlan
|
||||
00:BA:BE:FA:CE:00 mainframe
|
||||
00:11:22:33:44:5A maschine1
|
||||
00:11:22:33:44:B5 maschine2
|
||||
00:11:22:33:44:5C maschine3
|
||||
0A:BB:CC:DD:EE:F9 macintosh
|
||||
1A:BB:CC:DD:E6:FF
|
||||
3A:BB:CC:DD:EE:F5 testpc
|
||||
3A:BB:CC:DD:EE:F6 123.45.6.7
|
||||
@@ -1,172 +0,0 @@
|
||||
#!/perl/bin/perl -w
|
||||
# Magic Packet for the Web
|
||||
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
|
||||
# Steve_Marfisi@3com.com on the Netboot mailing list
|
||||
# modified to work with web by G. Knauf <info@gknw.de>
|
||||
# Released under GNU Public License
|
||||
#
|
||||
use CGI qw(:standard); # import shortcuts
|
||||
use Socket;
|
||||
|
||||
$ver = 'v0.52 © gk 2003-Apr-24 11:00:00';
|
||||
|
||||
# Defaults - Modify to point to the location of your mac file
|
||||
$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
|
||||
$maclist = "$www/maclist.txt";
|
||||
# Defaults - Modify to fit to your network
|
||||
$defbc = '255.255.255.255';
|
||||
$port = 60000;
|
||||
|
||||
MAIN:
|
||||
{
|
||||
# Read in all the variables set by the form
|
||||
if (param()) {
|
||||
&process_form();
|
||||
} else {
|
||||
&print_form();
|
||||
}
|
||||
}
|
||||
|
||||
sub process_form {
|
||||
# Print the header
|
||||
print header();
|
||||
print start_html("Mp-Form - send Magic Packets");
|
||||
# If defined new mac save it
|
||||
if (defined(param("mac"))) {
|
||||
print h1("Result of adding an entry to the maclist");
|
||||
print '<HR><H3><TT>';
|
||||
&add_entry();
|
||||
print '</TT></H3><HR>';
|
||||
print '<FORM method="POST"><input type="submit" value="ok"></FORM>';
|
||||
} else {
|
||||
# send magic packets to selected macs
|
||||
print h1("Result of sending magic packets to multiple PCs");
|
||||
print '<HR><H3><TT>';
|
||||
if (param("all")) {
|
||||
&process_file(S);
|
||||
} else {
|
||||
for (param()) {
|
||||
my ($brc,$mac) = split(/-/,param($_));
|
||||
&send_broadcast_packet(inet_aton($brc),$mac);
|
||||
}
|
||||
}
|
||||
print '</TT></H3><HR>';
|
||||
print '<FORM><input type="button" value="back" onClick="history.back()"></FORM>';
|
||||
}
|
||||
# Close the document cleanly.
|
||||
print end_html;
|
||||
}
|
||||
|
||||
sub print_form {
|
||||
# Print the header
|
||||
print header();
|
||||
print start_html("Mp-Form - send Magic Packets");
|
||||
print h1("Form for sending magic packets to multiple PCs");
|
||||
print <<ENDOFTEXT;
|
||||
<HR>
|
||||
<FORM method="POST">
|
||||
<H2>Select the destination mac addresses:</H2>
|
||||
<TABLE BORDER COLS=3 WIDTH="80%">
|
||||
<TR>
|
||||
<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
|
||||
</TR>
|
||||
ENDOFTEXT
|
||||
# build up table with mac addresses
|
||||
&process_file(R);
|
||||
# print rest of the form
|
||||
print <<ENDOFTEXT;
|
||||
</TABLE>
|
||||
<P><B><FONT SIZE="+1">
|
||||
Press <input type="submit" value="wakeup"> to send the magic packets to your selections.
|
||||
Press <input type="reset" value="clear"> to reset the form.
|
||||
</FONT></B>
|
||||
</FORM>
|
||||
<HR>
|
||||
<FORM method="POST">
|
||||
<H2>Enter new destination mac address:</H2>
|
||||
<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc">
|
||||
<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size="17" maxlength="17">
|
||||
<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size="40" maxlength="40">
|
||||
<P><B><FONT SIZE="+1">
|
||||
Press <input type="submit" value="save"> to add the entry to your maclist.
|
||||
Press <input type="reset" value="clear"> to reset the form.
|
||||
</FONT></B>
|
||||
</FORM>
|
||||
<HR>
|
||||
$ver
|
||||
ENDOFTEXT
|
||||
# Close the document cleanly.
|
||||
print end_html;
|
||||
}
|
||||
|
||||
sub send_broadcast_packet {
|
||||
my ($nbc,$mac) = @_;
|
||||
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print "Malformed MAC address $mac<BR>\n";
|
||||
return;
|
||||
}
|
||||
printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
|
||||
# Remove colons
|
||||
$mac =~ tr/://d;
|
||||
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
|
||||
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
|
||||
# Create socket
|
||||
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
|
||||
# Enable broadcast
|
||||
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
|
||||
# Send the wakeup packet
|
||||
defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
|
||||
close(S);
|
||||
}
|
||||
|
||||
sub process_file {
|
||||
unless (open(F, $maclist)) {
|
||||
print "Error reading $maclist: $!\n";
|
||||
} else {
|
||||
while (<F>) {
|
||||
next if (/^\s*#|^\s*;/); # skip comments
|
||||
my ($mac, $ip) = split;
|
||||
next if (!defined($mac) or $mac eq '');
|
||||
$mac = uc($mac);
|
||||
my $bc = $defbc;
|
||||
($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
|
||||
my $nbc = inet_aton($bc);
|
||||
if ($_[0] eq 'S') {
|
||||
&send_broadcast_packet($nbc, $mac);
|
||||
} else {
|
||||
my $hbc = sprintf("0x%08X", unpack('N',$nbc));
|
||||
print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
|
||||
print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
|
||||
$ip = ' ' if (!defined($ip) or $ip eq '');
|
||||
print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
|
||||
print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
|
||||
}
|
||||
}
|
||||
close(F);
|
||||
}
|
||||
}
|
||||
|
||||
sub add_entry {
|
||||
if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
|
||||
print "Malformed broadcast address ",param("brc"),"\n";
|
||||
return;
|
||||
}
|
||||
if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print "Malformed MAC address ",param("mac"),"\n";
|
||||
return;
|
||||
}
|
||||
unless (open(F, ">> $maclist")) {
|
||||
print "Error writing $maclist: $!\n";
|
||||
} else {
|
||||
#my $nbc = inet_aton(param("brc"));
|
||||
#my $hbc = sprintf("0x%8X", unpack('N',$nbc));
|
||||
#print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
close(F);
|
||||
print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
mp-form.pl - Send magic packets with your web server
|
||||
|
||||
This is my trial of waking up PCs with a form via web server.
|
||||
The perl script reads in a text file which contains lines of the form
|
||||
aa:bb:cc:dd:ee:ff 12.34.56.78 or
|
||||
aa:bb:cc:dd:ee:ff foo.bar.com
|
||||
aa:bb:cc:dd:ee:ff
|
||||
The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package.
|
||||
The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both
|
||||
modules should belong to your perl distribution. The script runs with linux as well as
|
||||
with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with
|
||||
Perl build #333 and earlier I got an error from the Socket.pm.
|
||||
This script uses only broadcast so you don't need root rights to use it.
|
||||
|
||||
To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755
|
||||
to the script. Modify the lines which point to the location of the maclist. If you do not
|
||||
have a maclist, the form could save new entries to a list (with unix perhaps you have to
|
||||
create an empty file). Check also the first line of mp-form.pl and modify it to point to
|
||||
your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
|
||||
|
||||
Older version: If you have problems running the script with CGI.pm you could try the older
|
||||
version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl
|
||||
from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using
|
||||
CGI.pm consumes much memory. The older version is also included in the zip archive.
|
||||
|
||||
Homepage of the script: http://www.gknw.de/mpform.html
|
||||
@@ -1,171 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
# Magic Packet for the Web
|
||||
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
|
||||
# Steve_Marfisi@3com.com on the Netboot mailing list
|
||||
# modified to work with web by G. Knauf <info@gknw.de>
|
||||
# Released under GNU Public License
|
||||
#
|
||||
require "cgi-lib.pl";
|
||||
use Socket;
|
||||
|
||||
$ver = 'v0.52 © gk 2003-Apr-24 11:00:00';
|
||||
|
||||
# Defaults - Modify to point to the location of your mac file
|
||||
$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
|
||||
$maclist = "$www/maclist.txt";
|
||||
# Defaults - Modify to fit to your network
|
||||
$defbc = '255.255.255.255';
|
||||
$port = 60000;
|
||||
|
||||
MAIN:
|
||||
{
|
||||
# Read in all the variables set by the form
|
||||
if (&ReadParse(*input)) {
|
||||
&process_form();
|
||||
} else {
|
||||
&print_form();
|
||||
}
|
||||
}
|
||||
|
||||
sub process_form {
|
||||
# Print the header
|
||||
print &PrintHeader();
|
||||
# If defined new mac save it
|
||||
if (defined($input{'mac'})) {
|
||||
print &HtmlTop("Result of adding an entry to the maclist");
|
||||
print '<HR><H3><TT>';
|
||||
&add_entry;
|
||||
print '</TT></H3><HR>';
|
||||
print '<FORM method="POST"><input type=submit value="ok"></FORM>';
|
||||
} else {
|
||||
# send magic packets to selected macs
|
||||
print &HtmlTop("Result of sending magic packets to multiple PCs");
|
||||
print '<HR><H3><TT>';
|
||||
if (defined($input{'all'})) {
|
||||
&process_file(S);
|
||||
} else {
|
||||
foreach $x (keys %input) {
|
||||
my ($brc,$mac) = split(/-/,$input{$x});
|
||||
&send_broadcast_packet(inet_aton($brc),$mac);
|
||||
}
|
||||
}
|
||||
print '</TT></H3><HR>';
|
||||
print '<form><input type=button value="back" onClick="history.back()"></FORM>';
|
||||
}
|
||||
# Close the document cleanly.
|
||||
print &HtmlBot;
|
||||
exit;
|
||||
}
|
||||
|
||||
sub print_form {
|
||||
print &PrintHeader();
|
||||
print &HtmlTop("Form for sending magic packets to multiple PCs");
|
||||
# Print out the body of the form
|
||||
print <<ENDOFTEXT;
|
||||
<HR>
|
||||
<FORM method="POST">
|
||||
<H2> Select the destination mac addresses: </H2>
|
||||
<TABLE BORDER COLS=3 WIDTH="80%">
|
||||
<TR>
|
||||
<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
|
||||
<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
|
||||
</TR>
|
||||
ENDOFTEXT
|
||||
# build up table with mac addresses
|
||||
&process_file;
|
||||
# print rest of the form
|
||||
print <<ENDOFTEXT;
|
||||
</TABLE>
|
||||
<P><B><FONT SIZE="+1">
|
||||
Press <input type="submit" value="wakeup"> to send the magic packets to your selections.
|
||||
Press <input type="reset" value="clear"> to reset the form.
|
||||
</FONT></B>
|
||||
</FORM>
|
||||
<HR>
|
||||
<FORM method="POST">
|
||||
<H2>Enter new destination mac address:</H2>
|
||||
<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc">
|
||||
<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size=17 maxlength=17>
|
||||
<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size=40 maxlength=40>
|
||||
<P><B><FONT SIZE="+1">
|
||||
Press <input type="submit" value="save"> to add the entry to your maclist.
|
||||
Press <input type="reset" value="clear"> to reset the form.
|
||||
</FONT></B>
|
||||
</FORM>
|
||||
<HR>
|
||||
$ver
|
||||
ENDOFTEXT
|
||||
# Close the document cleanly.
|
||||
print &HtmlBot;
|
||||
}
|
||||
|
||||
sub send_broadcast_packet {
|
||||
my ($nbc,$mac) = @_;
|
||||
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print "Malformed MAC address $mac<BR>\n";
|
||||
return;
|
||||
}
|
||||
printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
|
||||
# Remove colons
|
||||
$mac =~ tr/://d;
|
||||
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
|
||||
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
|
||||
# Create socket
|
||||
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
|
||||
# Enable broadcast
|
||||
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
|
||||
# Send the wakeup packet
|
||||
defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
|
||||
close(S);
|
||||
}
|
||||
|
||||
sub process_file {
|
||||
unless (open(F, $maclist)) {
|
||||
print "Error reading $maclist: $!\n";
|
||||
} else {
|
||||
while (<F>) {
|
||||
next if (/^\s*#|^\s*;/); # skip comments
|
||||
my ($mac, $ip) = split;
|
||||
next if (!defined($mac) or $mac eq '');
|
||||
$mac = uc($mac);
|
||||
my $bc = $defbc;
|
||||
($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
|
||||
my $nbc = inet_aton($bc);
|
||||
if ($_[0] eq 'S') {
|
||||
&send_broadcast_packet($nbc, $mac);
|
||||
} else {
|
||||
my $hbc = sprintf("0x%08X", unpack('N',$nbc));
|
||||
print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
|
||||
print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
|
||||
$ip = ' ' if (!defined($ip) or $ip eq '');
|
||||
print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
|
||||
print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
|
||||
}
|
||||
}
|
||||
close(F);
|
||||
}
|
||||
}
|
||||
|
||||
sub add_entry {
|
||||
if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
|
||||
print "Malformed broadcast address ",param("brc"),"\n";
|
||||
return;
|
||||
}
|
||||
if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print "Malformed MAC address ",param("mac"),"\n";
|
||||
return;
|
||||
}
|
||||
unless (open(F, ">> $maclist")) {
|
||||
print "Error writing $maclist: $!\n";
|
||||
} else {
|
||||
#my $nbc = inet_aton(param("brc"));
|
||||
#my $hbc = sprintf("0x%8X", unpack('N',$nbc));
|
||||
#print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
close(F);
|
||||
print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
mp-form.pl - Send magic packets with your web server
|
||||
|
||||
This is my trial of waking up PCs with a form via web server.
|
||||
The perl script reads in a text file which contains lines of the form
|
||||
aa:bb:cc:dd:ee:ff 12.34.56.78 or
|
||||
aa:bb:cc:dd:ee:ff foo.bar.com
|
||||
aa:bb:cc:dd:ee:ff
|
||||
optional a broadcast address mask can be prefixed:
|
||||
192.168.1.255-aa:bb:cc:dd:ee:ff
|
||||
|
||||
The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package.
|
||||
The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both
|
||||
modules should belong to your perl distribution. The script runs with linux as well as
|
||||
with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with
|
||||
Perl build #333 and earlier I got an error from the Socket.pm. You should also update
|
||||
your Perl to minimum #331 from CPAN: http://www.cpan.org/ports/index.html#netware.
|
||||
This script uses only broadcast so you don't need root rights to use it.
|
||||
|
||||
To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755
|
||||
to the script. Modify the lines which point to the location of the maclist. If you do not
|
||||
have a maclist, the form could save new entries to a list (with unix perhaps you have to
|
||||
create an empty file). Check also the first line of mp-form.pl and modify it to point to
|
||||
your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
|
||||
|
||||
Older version: If you have problems running the script with CGI.pm you could try the older
|
||||
version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl
|
||||
from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using
|
||||
CGI.pm consumes much memory. The older version is also included in the zip archive.
|
||||
|
||||
A modified version of the original script is now also included which runs with older
|
||||
Getopt::Std.pm as shipped with NetWare. This script you could use from command line
|
||||
or from cron. With NetWare copy the script to /perl/scripts; then call from console with:
|
||||
perl wakeup.pl <parameters>.
|
||||
|
||||
Homepage of the script: http://www.gknw.de/mpform.html
|
||||
@@ -1,116 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# If called as wake.pl -f file it reads lines of the form
|
||||
#
|
||||
# aa:bb:cc:dd:ee;ff 12.34.56.78 or
|
||||
# aa:bb:cc:dd:ee:ff foo.bar.com
|
||||
# aa:bb:cc:dd:ee:ff
|
||||
#
|
||||
# which are MAC addresses and hostnames of NICs to send a wakeup packet.
|
||||
# In the first two cases, unicast is used (and root permission may be
|
||||
# required if the ARP cache needs to be injected with a mapping).
|
||||
# In the third case, broadcast is used, and anybody can run the command.
|
||||
# Comments in the file start with #.
|
||||
#
|
||||
# Or MAC addresses can be specified on the command line
|
||||
#
|
||||
# wake.pl aa.bb.cc.dd.ee.ff
|
||||
#
|
||||
# Or both can be used:
|
||||
#
|
||||
# wake.pl -f addresses.cfg 11:22:33:44:55:66
|
||||
#
|
||||
# This program may have to be run with superuser privilege because it
|
||||
# may need to inject an ARP entry into the cache.
|
||||
# Be careful, you could corrupt valid entries if those NICs are
|
||||
# already active.
|
||||
#
|
||||
# Perl version by ken_yap@users.sourceforge.net after DOS/Windows C version posted by
|
||||
# Steve_Marfisi@3com.com on the Netboot mailing list
|
||||
# Released under GNU Public License, 2000-01-08
|
||||
# Added switch -q for quiet mode, changed Getopt usage to work with older versions,
|
||||
# added switch -u for unicast mode, now default is always broadcast mode,
|
||||
# added switch -s for seach pattern so you could filter entries from file.
|
||||
# Guenter.Knauf@dialup.soco.de, 2000-10-14
|
||||
#
|
||||
use Getopt::Std;
|
||||
use Socket;
|
||||
|
||||
getopts('quf:s:');
|
||||
if (defined($opt_f)) {
|
||||
unless (open(F, $opt_f)) {
|
||||
print STDERR "open: $opt_f: $!\n";
|
||||
} else {
|
||||
while (<F>) {
|
||||
next if /^\s*#/; # skip comments
|
||||
($mac, $ip) = split;
|
||||
next if !defined($mac) or $mac eq '';
|
||||
next if defined($opt_s) and (!/$opt_s/);
|
||||
if (!defined($ip) or $ip eq '' or !$opt_u) {
|
||||
&send_broadcast_packet($mac);
|
||||
} else {
|
||||
&send_unicast_packet($mac, $ip);
|
||||
}
|
||||
}
|
||||
close(F);
|
||||
}
|
||||
}
|
||||
while (@ARGV) {
|
||||
send_broadcast_packet(shift(@ARGV));
|
||||
}
|
||||
|
||||
sub send_broadcast_packet {
|
||||
($mac) = @_;
|
||||
|
||||
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print STDERR "Malformed MAC address $mac\n";
|
||||
return;
|
||||
}
|
||||
# Remove colons
|
||||
$mac =~ tr/://d;
|
||||
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
|
||||
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
|
||||
# Create socket
|
||||
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
|
||||
or die "socket: $!\n";
|
||||
# Enable broadcast
|
||||
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1)
|
||||
or die "setsockopt: $!\n";
|
||||
# Send the wakeup packet
|
||||
if (!$opt_q) {
|
||||
print "Sending wakeup packet to MAC address $mac";
|
||||
print " ($ip)" if (defined($ip));
|
||||
print "\n";
|
||||
}
|
||||
defined(send(S, $magic, 0, sockaddr_in(0x2fff, INADDR_BROADCAST)))
|
||||
or print STDERR "send: $!\n";
|
||||
close(S);
|
||||
}
|
||||
|
||||
sub send_unicast_packet {
|
||||
($mac, $ip) = @_;
|
||||
|
||||
if (!defined($iaddr = inet_aton($ip))) {
|
||||
print STDERR "Cannot resolve $ip\n";
|
||||
return;
|
||||
}
|
||||
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print STDERR "Malformed MAC address $mac\n";
|
||||
return;
|
||||
}
|
||||
# Inject entry into ARP table, in case it's not there already
|
||||
system("arp -s $ip $mac") == 0
|
||||
or print STDERR "Warning: arp command failed, you need to be root\n";
|
||||
# Remove colons
|
||||
$mac =~ tr/://d;
|
||||
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
|
||||
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
|
||||
# Create socket
|
||||
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
|
||||
or die "socket: $!\n";
|
||||
# Send the wakeup packet
|
||||
print "Sending wakeup packet to $ip at MAC address $mac\n" if (!$opt_q);
|
||||
defined(send(S, $magic, 0, sockaddr_in(0x2fff, $iaddr)))
|
||||
or print STDERR "send: $!\n";
|
||||
close(S);
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
To: etherboot-developers@lists.sourceforge.net
|
||||
X-face: #Qvg5o3u!)WoVDDi4-bFy`fl@""4^pm68%_,`puon{0Q6lQ-O,)3D.J.":A&^,#4O2vc8`?
|
||||
3^1lhBh=EQH,"Qq*e1vY":she&t^8:!&Fb32Ed:nM2Y<E9|i[+z20G?CO=E=-IWv;bL"=Y`+`q,ML6
|
||||
,!Me?==j&In1
|
||||
Mime-Version: 1.0
|
||||
Content-Type: multipart/mixed ;
|
||||
boundary="==_Exmh_-19971541890"
|
||||
From: Tilmann Bubeck <bubeck@think-at-work.de>
|
||||
Message-Id: <20010219195622.C97A84ABD8@chaos.think-at-work.de>
|
||||
Subject: [Etherboot-developers] Wake-on-LAN patch
|
||||
Sender: etherboot-developers-admin@lists.sourceforge.net
|
||||
Errors-To: etherboot-developers-admin@lists.sourceforge.net
|
||||
X-BeenThere: etherboot-developers@lists.sourceforge.net
|
||||
X-Mailman-Version: 2.0
|
||||
Precedence: bulk
|
||||
List-Help: <mailto:etherboot-developers-request@lists.sourceforge.net?subject=help>
|
||||
List-Post: <mailto:etherboot-developers@lists.sourceforge.net>
|
||||
List-Subscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
|
||||
<mailto:etherboot-developers-request@lists.sourceforge.net?subject=subscribe>
|
||||
List-Id: Discussion list for Etherboot developers <etherboot-developers.lists.sourceforge.net>
|
||||
List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
|
||||
<mailto:etherboot-developers-request@lists.sourceforge.net?subject=unsubscribe>
|
||||
List-Archive: <http://lists.sourceforge.net/archives//etherboot-developers/>
|
||||
Date: Mon, 19 Feb 2001 20:56:22 +0100
|
||||
Status: RO
|
||||
Content-Length: 5351
|
||||
Lines: 152
|
||||
|
||||
This is a multipart MIME message.
|
||||
|
||||
--==_Exmh_-19971541890
|
||||
Content-Type: text/plain; charset=us-ascii
|
||||
|
||||
|
||||
Hello!
|
||||
|
||||
please find enclosed a patch to optionally enable etherboot to start the
|
||||
server it is booting from by sending a magic wake-on-lan packet to the
|
||||
sleeping server first.
|
||||
|
||||
This is very important for an etherboot-server, which is not running all the
|
||||
time and is not easily accessible from the etherboot machine (e.g. because it
|
||||
is installed in the basement of the house and one must climb several stairs to
|
||||
switch the server on...)
|
||||
|
||||
Are the authors of etherboot willing to accept this patch for inclusion?
|
||||
Please note, that the wake-on-lan code is only compiled in, when setting
|
||||
appropriate flags in src/Config.
|
||||
|
||||
If you don't want to include the patch, should I change anything of the
|
||||
implementation or do you dislike the idea at all?
|
||||
|
||||
Thanks!
|
||||
Till
|
||||
|
||||
+-------+--------------------------------------------------------------+
|
||||
| | dr. tilmann bubeck think@work it consulting |
|
||||
| | professional services |
|
||||
| think | cell.: +49 172 8842972 widmaierstrasse 58 |
|
||||
| @work | fax : +49 711 7227734 70567 stuttgart |
|
||||
| | email: bubeck@think-at-work.de http://www.think-at-work.de |
|
||||
+-------+ -------------------------------------------------------------+
|
||||
|
||||
|
||||
--==_Exmh_-19971541890
|
||||
Content-Type: application/x-patch ; name="etherboot-4.7.17-wol.patch"
|
||||
Content-Description: etherboot-4.7.17-wol.patch
|
||||
Content-Disposition: attachment; filename="etherboot-4.7.17-wol.patch"
|
||||
|
||||
diff -r -u etherboot-4.7.17/src/Config etherboot-4.7.17-wol/src/Config
|
||||
--- etherboot-4.7.17/src/Config Sat Jan 6 16:25:23 2001
|
||||
+++ etherboot-4.7.17-wol/src/Config Mon Feb 19 20:28:00 2001
|
||||
@@ -113,6 +113,16 @@
|
||||
# -DINTERNAL_BOOTP_DATA
|
||||
# - define if the area 0x93C00-0x93FFF is not available
|
||||
# for use for bootpd_data by the loader for some reason
|
||||
+# -DWAKEUP_SERVER
|
||||
+# - define this for sending a Wake-On-LAN (WOL)
|
||||
+# "Magic Packet" to a sleeping server, before trying
|
||||
+# a etherboot. Useful if your server is soft-off all
|
||||
+# the time and must be switched on when booting a
|
||||
+# client. Define SERVER_MAC with the MAC address of the
|
||||
+# server to wakeup. CAUTION! This MAC address is
|
||||
+# stored in the rom image. The rom is therefore not
|
||||
+# generic anymore but tailored for a specific
|
||||
+# server!
|
||||
|
||||
# These default settings compile Etherboot with a small number of options.
|
||||
# You may wish to enable more of the features if the size of your ROM allows.
|
||||
@@ -142,6 +152,10 @@
|
||||
|
||||
# These flags affect the loader that is prepended to the Etherboot image
|
||||
LCONFIG+= -DMOVEROM
|
||||
+
|
||||
+# Include code for sending a Wake-On-LAN (WOL) "Magic Packet" to a sleeping
|
||||
+# server, before trying a etherboot.
|
||||
+CFLAGS32+= -DWAKEUP_SERVER -DSERVER_MAC=0x00,0x01,0x02,0xDA,0xDF,0x77
|
||||
|
||||
# you should normally not need to change these
|
||||
RM= rm -f
|
||||
diff -r -u etherboot-4.7.17/src/main.c etherboot-4.7.17-wol/src/main.c
|
||||
--- etherboot-4.7.17/src/main.c Fri Jan 5 12:45:29 2001
|
||||
+++ etherboot-4.7.17-wol/src/main.c Thu Feb 8 20:46:59 2001
|
||||
@@ -137,6 +137,7 @@
|
||||
* declarations, but in this case I like to see main() as the first
|
||||
* routine.
|
||||
*/
|
||||
+static void wakeup_server(void) ;
|
||||
static int bootp(void);
|
||||
static int rarp(void);
|
||||
static void load(void);
|
||||
@@ -217,6 +218,11 @@
|
||||
rfc951_sleep(++card_retries);
|
||||
}
|
||||
#endif
|
||||
+
|
||||
+#ifdef WAKEUP_SERVER
|
||||
+ wakeup_server();
|
||||
+#endif
|
||||
+
|
||||
while (1) {
|
||||
/* -1: timeout or ESC
|
||||
-2: error return from loader
|
||||
@@ -650,6 +656,46 @@
|
||||
return (0);
|
||||
}
|
||||
#endif /* DOWNLOAD_PROTO_TFTP */
|
||||
+
|
||||
+#ifdef WAKEUP_SERVER
|
||||
+#ifndef SERVER_MAC
|
||||
+#error "Please define SERVER_MAC to the MAC address of the sleeping server"
|
||||
+#endif
|
||||
+
|
||||
+/**************************************************************************
|
||||
+WOL - Wake up a sleeping server by transmitting a Wake-On-LAN (WOL) "Magic
|
||||
+ Packet", used for restarting machines that have been soft-powered-down
|
||||
+ (ACPI D3-warm state). It currently generates the standard AMD Magic
|
||||
+ Packet format.
|
||||
+**************************************************************************/
|
||||
+static void wakeup_server(void)
|
||||
+{
|
||||
+ unsigned char data[100];
|
||||
+ int i, len, retry;
|
||||
+ char server_adr[] = { SERVER_MAC };
|
||||
+ unsigned long time;
|
||||
+
|
||||
+ /* build "Magic Packet" */
|
||||
+ len = 0;
|
||||
+ data[len++] = 0xff;
|
||||
+ data[len++] = 0xff;
|
||||
+ data[len++] = 0xff;
|
||||
+ data[len++] = 0xff;
|
||||
+ data[len++] = 0xff;
|
||||
+ data[len++] = 0xff;
|
||||
+ for ( i = 0; i < 16; i++ ) {
|
||||
+ memcpy(&data[len], server_adr, 6);
|
||||
+ len += 6;
|
||||
+ }
|
||||
+
|
||||
+ printf("Sending Wake-On-LAN (WOL) \"Magic Packet\" to server %b:%b:%b:%b:%b:%b...",
|
||||
+ server_adr[0], server_adr[1], server_adr[2],
|
||||
+ server_adr[3], server_adr[4], server_adr[5]);
|
||||
+
|
||||
+ eth_transmit(broadcast, 0x0842, len, data);
|
||||
+ printf("done\n");
|
||||
+}
|
||||
+#endif
|
||||
|
||||
#ifdef RARP_NOT_BOOTP
|
||||
/**************************************************************************
|
||||
|
||||
--==_Exmh_-19971541890--
|
||||
|
||||
|
||||
|
||||
_______________________________________________
|
||||
Etherboot-developers mailing list
|
||||
Etherboot-developers@lists.sourceforge.net
|
||||
http://lists.sourceforge.net/lists/listinfo/etherboot-developers
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# If called as wakeup.pl -f file it reads lines of the form
|
||||
#
|
||||
# aa:bb:cc:dd:ee;ff 12.34.56.78 or
|
||||
# aa:bb:cc:dd:ee:ff foo.bar.com
|
||||
# aa:bb:cc:dd:ee:ff
|
||||
#
|
||||
# which are MAC addresses and hostnames of NICs to send a wakeup packet.
|
||||
# Broadcast is used to send the magic packets, so anybody can run the command.
|
||||
# Notice that many routers do NOT forward broadcasts automatically!!
|
||||
# Comments in the file start with #.
|
||||
#
|
||||
# Or MAC addresses can be specified on the command line
|
||||
#
|
||||
# wakeup.pl aa.bb.cc.dd.ee.ff
|
||||
#
|
||||
# Or both can be used:
|
||||
#
|
||||
# wakeup.pl -f addresses.cfg 11:22:33:44:55:66
|
||||
#
|
||||
# Use option -b to specify broadcast mask.
|
||||
# Use option -d for screen output.
|
||||
#
|
||||
# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
|
||||
# Steve_Marfisi@3com.com on the Netboot mailing list
|
||||
# Released under GNU Public License, 2000-01-08
|
||||
# Modified for use with NetWare by gk@gknw.de, 2000-09-18
|
||||
# With NetWare you have to use Socket.NLP from NetWare Perl #334 or higher!
|
||||
# You could download Socket.NLP #334 from: http://www.gknw.de/mpform.html
|
||||
#
|
||||
|
||||
use Getopt::Std;
|
||||
use Socket;
|
||||
|
||||
getopts('b:df:p:q');
|
||||
|
||||
$brc = $opt_b || '255.255.255.255';
|
||||
$port = $opt_p || 60000;
|
||||
die "Malformed broadcast address: $brc!\n" if ($brc !~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/);
|
||||
|
||||
if (defined($opt_f)) {
|
||||
unless (open(F, $opt_f)) {
|
||||
print "open: $opt_f: $!\n";
|
||||
} else {
|
||||
print "Using file $opt_f...\n" if ($opt_d);
|
||||
while (<F>) {
|
||||
next if /^\s*#/; # skip comments
|
||||
my ($mac, $ip) = split;
|
||||
next if !defined($mac) or $mac eq '';
|
||||
&send_broadcast_packet($mac,$ip);
|
||||
}
|
||||
close(F);
|
||||
}
|
||||
}
|
||||
while (@ARGV) {
|
||||
send_broadcast_packet(shift(@ARGV));
|
||||
}
|
||||
|
||||
sub send_broadcast_packet {
|
||||
my ($mac,$ip) = @_;
|
||||
if ($mac =~ /-/) {
|
||||
($bc,$mac) = split(/-/,$mac);
|
||||
} else {
|
||||
$bc = $brc;
|
||||
}
|
||||
if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
|
||||
print "Malformed MAC address $mac\n";
|
||||
return;
|
||||
}
|
||||
my $nbc = inet_aton($bc);
|
||||
# Remove colons
|
||||
$mac =~ tr/://d;
|
||||
# Magic packet is 6 bytes of FF followed by the MAC address 16 times
|
||||
$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
|
||||
# Create socket
|
||||
socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
|
||||
# Enable broadcast
|
||||
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
|
||||
# Send the wakeup packet
|
||||
printf("$0: Sending wakeup packet to %04X:%08X-%s %s\n",$port,unpack('N',$nbc),uc($mac),$ip) if ($opt_d);
|
||||
defined(send(S, $magic, 0, sockaddr_in($port, $nbc)))
|
||||
or print "send: $!\n";
|
||||
close(S);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
# maclist - mac addresses for wakeonlan
|
||||
00:BA:BE:FA:CE:00 mainframe
|
||||
00:11:22:33:44:5A maschine1
|
||||
00:11:22:33:44:B5 maschine2
|
||||
00:11:22:33:44:5C maschine3
|
||||
0A:BB:CC:DD:EE:F9 macintosh
|
||||
1A:BB:CC:DD:E6:FF
|
||||
3A:BB:CC:DD:EE:F5 testpc
|
||||
3A:BB:CC:DD:EE:F6 123.45.6.7
|
||||
+90
-356
@@ -1,374 +1,108 @@
|
||||
/*****************************************************************************
|
||||
/*
|
||||
* Copyright (C) 2008 William Stewart.
|
||||
*
|
||||
* wol.c - Wake-On-LAN utility to wake a networked PC
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* by R. Edwards (bob@cs.anu.edu.au), January 2000
|
||||
* (in_ether routine adapted from net-tools-1.51/lib/ether.c by
|
||||
* Fred N. van Kempen)
|
||||
* added file input, some minor changes for compiling for NetWare
|
||||
* added switches -q and -d=<ms>, added Win32 target support
|
||||
* by G. Knauf (gk@gknw.de), 30-Jan-2001
|
||||
* added switches -b=<bcast> and -p=<port>
|
||||
* by G. Knauf (gk@gknw.de), 10-Okt-2001
|
||||
* added OS/2 target support
|
||||
* by G. Knauf (gk@gknw.de), 24-May-2002
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* This utility allows a PC with WOL configured to be powered on by
|
||||
* sending a "Magic Packet" to it's network adaptor (see:
|
||||
* http://www.amd.com/products/npd/overview/20212.html).
|
||||
* Only the ethernet dest address needs to be given to make this work.
|
||||
* Current version uses a UDP broadcast to send out the Magic Packet.
|
||||
*
|
||||
* compile with: gcc -Wall -o wol wol.c
|
||||
* with Solaris: (g)cc -o wol wol.c -lsocket -lnsl
|
||||
* with MingW32: gcc -Wall -o wol wol.c -lwsock32
|
||||
*
|
||||
* usage: wol <dest address>
|
||||
* where <dest address> is in [ddd.ddd.ddd.ddd-]xx:xx:xx:xx:xx:xx format.
|
||||
* or: wol [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<File name>
|
||||
* where <File name> is a file containing one dest address per line,
|
||||
* optional followed by a hostname or ip separated by a blank.
|
||||
* -b sets optional broadcast address, -p sets optional port,
|
||||
* -q supresses output, -d=<ms> delays ms milliseconds between sending.
|
||||
*
|
||||
* Released under GNU Public License January, 2000.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#define VERSION "1.12.2 (c) G.Knauf http://www.gknw.de/"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef WATTCP
|
||||
#define strncasecmp strnicmp
|
||||
#include <ctype.h>
|
||||
#include <dos.h>
|
||||
#include <tcp.h>
|
||||
#else
|
||||
#ifdef WIN32 /* Win32 platform */
|
||||
#define USE_WINSOCKAPI
|
||||
#define delay Sleep
|
||||
#if (defined(__LCC__) || defined(__BORLANDC__))
|
||||
#define strncasecmp strnicmp
|
||||
#else
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
#elif defined(N_PLAT_NLM) /* NetWare platform */
|
||||
#ifdef __NOVELL_LIBC__
|
||||
#include <ctype.h>
|
||||
#else
|
||||
extern int isdigit(int c); /* no ctype.h for NW3.x */
|
||||
#include <nwthread.h>
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
#elif defined(__OS2__) /* OS/2 platform */
|
||||
#ifdef __EMX__
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
extern int DosSleep(long t);
|
||||
#define delay DosSleep
|
||||
#else /* all other platforms */
|
||||
#define delay(t) usleep(t*1000)
|
||||
#endif
|
||||
#ifndef N_PLAT_NLM /* ! NetWare platform */
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
#ifndef WIN32 /* ! Win32 platform */
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef USE_WINSOCKAPI /* Winsock2 platforms */
|
||||
#ifdef N_PLAT_NLM /* NetWare platform */
|
||||
#include <ws2nlm.h>
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#define close(s) { \
|
||||
closesocket(s); \
|
||||
WSACleanup(); \
|
||||
}
|
||||
#else /* Socket platforms */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#if defined(__OS2__) && !defined(__EMX__)
|
||||
#include <utils.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <byteswap.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <gpxe/if_ether.h>
|
||||
#include <gpxe/iobuf.h>
|
||||
#include <usr/ifmgmt.h>
|
||||
#include <usr/wol.h>
|
||||
#include <timer.h>
|
||||
|
||||
#endif
|
||||
/** @file
|
||||
*
|
||||
* Wake on lan
|
||||
*
|
||||
*/
|
||||
|
||||
static int read_file (char *destfile);
|
||||
static int in_ether (char *bufp, unsigned char *addr);
|
||||
static int send_wol (char *dest, char *host);
|
||||
/**
|
||||
* Boot from a network device
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
#define WOL_MSG_LEN (6 + 16*6)
|
||||
|
||||
void wakeup_server(char *server_adr)
|
||||
{
|
||||
int rc, i,j;
|
||||
unsigned char *buf;
|
||||
uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
unsigned int len;
|
||||
struct io_buffer *iobuf;
|
||||
struct ethhdr *ethhdr;
|
||||
struct net_device *netdev;
|
||||
|
||||
for_each_netdev ( netdev ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
char *progname;
|
||||
int quiet = 0;
|
||||
int twait = 0;
|
||||
unsigned int port = 60000;
|
||||
unsigned long bcast = 0xffffffff;
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
int cmdindx = 0;
|
||||
progname = argv[0];
|
||||
|
||||
if (argc > 1) {
|
||||
/* parse input parameters */
|
||||
for (argc--, argv++; *argv; argc--, argv++) {
|
||||
char *bp;
|
||||
char *ep;
|
||||
|
||||
if (strncasecmp (*argv, "-", 1) == 0) {
|
||||
if (strncasecmp (*argv, "-F=", 3) == 0) {
|
||||
bp = *argv + 3;
|
||||
read_file (bp);
|
||||
} else if (strncasecmp (*argv, "-B=", 3) == 0) {
|
||||
bp = *argv + 3;
|
||||
bcast = inet_addr(bp);
|
||||
if (bcast == -1) {
|
||||
fprintf (stderr, "%s: expected address argument at %s\n", progname, *argv);
|
||||
exit (1);
|
||||
}
|
||||
} else if (strncasecmp (*argv, "-D=", 3) == 0) {
|
||||
bp = *argv + 3;
|
||||
twait = strtol (bp, &ep, 0);
|
||||
if (ep == bp || *ep != '\0') {
|
||||
fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
|
||||
exit (1);
|
||||
}
|
||||
} else if (strncasecmp (*argv, "-P=", 3) == 0) {
|
||||
bp = *argv + 3;
|
||||
port = strtol (bp, &ep, 0);
|
||||
if (ep == bp || *ep != '\0') {
|
||||
fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
|
||||
exit (1);
|
||||
}
|
||||
} else if (strncasecmp (*argv, "-Q", 2) == 0) {
|
||||
quiet = 1;
|
||||
} else if (strncasecmp (*argv, "-V", 2) == 0) {
|
||||
fprintf (stderr, "\r%s Version %s\n", progname, VERSION);
|
||||
exit (0);
|
||||
} else {
|
||||
fprintf (stderr, "\r%s: invalid or unknown option %s\n", progname, *argv);
|
||||
exit (1);
|
||||
}
|
||||
} else {
|
||||
send_wol (*argv, "");
|
||||
}
|
||||
cmdindx++;
|
||||
if (netdev == NULL)
|
||||
{
|
||||
printf("Could not find netdev\n");
|
||||
return;
|
||||
}
|
||||
return (0);
|
||||
} else {
|
||||
/* No arguments given -> usage message */
|
||||
fprintf (stderr, "\rUsage: %s [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<file> | <dest>\n", progname);
|
||||
fprintf (stderr, " need at least hardware address or file option\n");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Open device and display device status */
|
||||
if ( (ifopen ( netdev ) ) != 0 )
|
||||
{
|
||||
printf("Could not open netdev\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create outgoing I/O buffer */
|
||||
iobuf = alloc_iob ((ETH_HLEN + WOL_MSG_LEN)*2);
|
||||
if (!iobuf)
|
||||
{
|
||||
printf("Could not allocate iob\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ethhdr = iob_put(iobuf, sizeof(*ethhdr));
|
||||
|
||||
/* Build Ethernet header */
|
||||
memcpy (ethhdr->h_dest, eth_broadcast, ETH_ALEN );
|
||||
memcpy (ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
|
||||
ethhdr->h_protocol = htons (0x0842);
|
||||
|
||||
buf = iob_put (iobuf, WOL_MSG_LEN);
|
||||
|
||||
static int in_ether (char *bufp, unsigned char *addr) {
|
||||
|
||||
char c, *orig;
|
||||
int i;
|
||||
unsigned char *ptr = addr;
|
||||
unsigned val;
|
||||
|
||||
i = 0;
|
||||
orig = bufp;
|
||||
while ((*bufp != '\0') && (i < 6)) {
|
||||
val = 0;
|
||||
c = *bufp++;
|
||||
if (isdigit(c))
|
||||
val = c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
val = c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
val = c - 'A' + 10;
|
||||
else {
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
|
||||
#endif
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
val <<= 4;
|
||||
c = *bufp;
|
||||
if (isdigit(c))
|
||||
val |= c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
val |= c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
val |= c - 'A' + 10;
|
||||
else if (c == ':' || c == 0)
|
||||
val >>= 4;
|
||||
else {
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
|
||||
#endif
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
if (c != 0)
|
||||
bufp++;
|
||||
*ptr++ = (unsigned char) (val & 0377);
|
||||
i++;
|
||||
|
||||
/* We might get a semicolon here - not required. */
|
||||
if (*bufp == ':') {
|
||||
if (i == 6) {
|
||||
; /* nothing */
|
||||
}
|
||||
bufp++;
|
||||
}
|
||||
}
|
||||
if (bufp - orig != 17) {
|
||||
return (-1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
} /* in_ether */
|
||||
|
||||
|
||||
static int read_file (char *destfile) {
|
||||
|
||||
FILE *pfile = NULL;
|
||||
char dest[64];
|
||||
char host[32];
|
||||
char buffer[512];
|
||||
|
||||
pfile = fopen (destfile, "r+");
|
||||
|
||||
if (pfile) {
|
||||
while (fgets (buffer, 511, pfile) != NULL) {
|
||||
if (buffer[0] != '#' && buffer[0] != ';') {
|
||||
dest[0] = host[0] = '\0';
|
||||
sscanf (buffer, "%s %s", dest, host);
|
||||
send_wol (dest, host);
|
||||
}
|
||||
}
|
||||
fclose (pfile);
|
||||
return (0);
|
||||
} else {
|
||||
fprintf (stderr, "\r%s: destfile '%s' not found\n", progname, destfile);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int send_wol (char *dest, char *host) {
|
||||
|
||||
int i, j;
|
||||
int packet;
|
||||
struct sockaddr_in sap;
|
||||
unsigned char ethaddr[8];
|
||||
unsigned char *ptr;
|
||||
unsigned char buf [128];
|
||||
unsigned long bc;
|
||||
char mask[32];
|
||||
char *tmp;
|
||||
#ifdef USE_WINSOCKAPI
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
#endif
|
||||
#ifdef WATTCP
|
||||
static udp_Socket sock;
|
||||
udp_Socket *s;
|
||||
#else
|
||||
int optval = 1;
|
||||
#endif
|
||||
|
||||
/* Fetch the broascast address if present. */
|
||||
if ((tmp = strstr(dest,"-"))) {
|
||||
printf("found: %s\n", tmp);
|
||||
tmp[0] = 32;
|
||||
sscanf (dest, "%s %s", mask, dest);
|
||||
bc = inet_addr(mask);
|
||||
printf("bc: string %s address %08lX\n", mask, bc);
|
||||
if (bc == -1) {
|
||||
fprintf (stderr, "\r%s: expected address argument at %s\n", progname, mask);
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
bc = bcast;
|
||||
|
||||
/* Fetch the hardware address. */
|
||||
if (in_ether (dest, ethaddr) < 0) {
|
||||
fprintf (stderr, "\r%s: invalid hardware address\n", progname);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifdef USE_WINSOCKAPI
|
||||
/* I would like to have Socket Vers. 1.1 */
|
||||
wVersionRequested = MAKEWORD(1, 1);
|
||||
err = WSAStartup (wVersionRequested, &wsaData);
|
||||
if (err != 0) {
|
||||
fprintf (stderr, "\r%s: couldn't init Winsock Version 1.1\n", progname);
|
||||
WSACleanup ();
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* setup the packet socket */
|
||||
#ifdef WATTCP
|
||||
sock_init();
|
||||
s = &sock;
|
||||
if (!udp_open( s, 0, bc, port, NULL )) {
|
||||
#else
|
||||
if ((packet = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
#endif
|
||||
fprintf (stderr, "\r%s: socket failed\n", progname);
|
||||
#ifdef USE_WINSOCKAPI
|
||||
WSACleanup ();
|
||||
#endif
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifndef WATTCP
|
||||
/* Set socket options */
|
||||
if (setsockopt (packet, SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof (optval)) < 0) {
|
||||
fprintf (stderr, "\r%s: setsocket failed %s\n", progname, strerror (errno));
|
||||
close (packet);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set up broadcast address */
|
||||
sap.sin_family = AF_INET;
|
||||
sap.sin_addr.s_addr = bc; /* broadcast address */
|
||||
sap.sin_port = htons(port);
|
||||
#endif
|
||||
|
||||
/* Build the message to send - 6 x 0xff then 16 x dest address */
|
||||
ptr = buf;
|
||||
for (i = 0; i < 6; i++)
|
||||
*ptr++ = 0xff;
|
||||
for (j = 0; j < 16; j++)
|
||||
/* Build the message to send - 6 x 0xff then 16 x dest address */
|
||||
len =0;
|
||||
for (i = 0; i < 6; i++)
|
||||
*ptr++ = ethaddr [i];
|
||||
buf[len++] = 0xff;
|
||||
for (j = 0; j < 16; j++)
|
||||
for (i = 0; i < 6; i++)
|
||||
buf[len++] = server_adr[i];
|
||||
|
||||
/* Send the packet out */
|
||||
#ifdef WATTCP
|
||||
sock_write( s, buf, 102 );
|
||||
sock_close( s );
|
||||
#else
|
||||
if (sendto (packet, (char *)buf, 102, 0, (struct sockaddr *)&sap, sizeof (sap)) < 0) {
|
||||
fprintf (stderr, "\r%s: sendto failed, %s\n", progname, strerror(errno));
|
||||
close (packet);
|
||||
return (-1);
|
||||
}
|
||||
close (packet);
|
||||
#endif
|
||||
if (!quiet) fprintf (stderr, "\r%s: packet sent to %04X:%08lX-%s %s\n",
|
||||
progname, port, (unsigned long)htonl(bc), dest, host);
|
||||
if (twait > 0 ) {
|
||||
delay (twait);
|
||||
}
|
||||
return (0);
|
||||
rc = netdev_tx (netdev, iobuf);
|
||||
|
||||
if (rc !=0)
|
||||
printf("Failed to transmit WOL packet\n");
|
||||
|
||||
/* Give the controller a chance to send it before checking */
|
||||
mdelay(100);
|
||||
|
||||
netdev_poll(netdev);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _USR_WOL_H
|
||||
#define _USR_WOL_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Wakeon lan
|
||||
*
|
||||
*/
|
||||
|
||||
extern void wakeup_server(char *);
|
||||
|
||||
#endif /* _USR_WOL_H */
|
||||
@@ -2,3 +2,4 @@
|
||||
.echocheck
|
||||
TAGS*
|
||||
bin*
|
||||
config-local.h
|
||||
|
||||
-381
@@ -1,381 +0,0 @@
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
#
|
||||
# IMPORTANT!
|
||||
#
|
||||
# The use of this file to set options that affect only single object
|
||||
# files is deprecated, because changing anything in this file results
|
||||
# in a complete rebuild, which is slow. All options are gradually
|
||||
# being migrated to config.h, which does not suffer from this problem.
|
||||
#
|
||||
# Only options that affect the entire build (e.g. overriding the $(CC)
|
||||
# Makefile variable) should be placed in here.
|
||||
#
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
|
||||
|
||||
#
|
||||
# Config for Etherboot/32
|
||||
#
|
||||
#
|
||||
# Do not delete the tag OptionDescription and /OptionDescription
|
||||
# It is used to automatically generate the documentation.
|
||||
#
|
||||
# @OptionDescription@
|
||||
# User interaction options:
|
||||
#
|
||||
# -DASK_BOOT=n
|
||||
# Ask "Boot from (N)etwork ... or (Q)uit? "
|
||||
# at startup, timeout after n seconds (0 = no timeout).
|
||||
# If unset or negative, don't ask and boot immediately
|
||||
# using the default.
|
||||
# -DBOOT_FIRST
|
||||
# -DBOOT_SECOND
|
||||
# -DBOOT_THIRD
|
||||
# On timeout or Return key from previous
|
||||
# question, selects the order to try to boot from
|
||||
# various devices.
|
||||
# (alternatives: BOOT_NIC, BOOT_DISK,
|
||||
# BOOT_FLOPPY, BOOT_NOTHING)
|
||||
# See etherboot.h for prompt and answer strings.
|
||||
# BOOT_DISK and BOOT_FLOPPY work only where a driver
|
||||
# exists, e.g. in LinuxBIOS.
|
||||
# They have no effect on PCBIOS.
|
||||
# -DBOOT_INDEX The device to boot from 0 == any device.
|
||||
# 1 == The first nic found.
|
||||
# 2 == The second nic found
|
||||
# ...
|
||||
# BOOT_INDEX only applies to the BOOT_FIRST. BOOT_SECOND
|
||||
# and BOOT_THIRD search through all of the boot devices.
|
||||
# -DBAR_PROGRESS
|
||||
# Use rotating bar instead of sequential dots
|
||||
# to indicate an IP packet transmitted.
|
||||
#
|
||||
# Boot order options:
|
||||
#
|
||||
# -DBOOT_CLASS_FIRST
|
||||
# -DBOOT_CLASS_SECOND
|
||||
# -DBOOT_CLASS_THIRD
|
||||
# Select the priority of the boot classes
|
||||
# Valid values are:
|
||||
# BOOT_NIC
|
||||
# BOOT_DISK
|
||||
# BOOT_FLOPPY
|
||||
# BOOT_DISK and BOOT_FLOPPY work only where a driver exists,
|
||||
# e.g. in LinuxBIOS. They have no effect on PCBIOS.
|
||||
#
|
||||
# Boot autoconfiguration protocol options:
|
||||
#
|
||||
# -DALTERNATE_DHCP_PORTS_1067_1068
|
||||
# Use ports 1067 and 1068 for DHCP instead of 67 and 68.
|
||||
# As these ports are non-standard, you need to configure
|
||||
# your DHCP server to use them. This option gets around
|
||||
# existing DHCP servers which cannot be touched, for
|
||||
# one reason or another, at the cost of non-standard
|
||||
# boot images.
|
||||
# -DNO_DHCP_SUPPORT
|
||||
# Use BOOTP instead of DHCP.
|
||||
# -DRARP_NOT_BOOTP
|
||||
# Use RARP instead of BOOTP/DHCP.
|
||||
# -DREQUIRE_VCI_ETHERBOOT
|
||||
# Require an encapsulated Vendor Class Identifier
|
||||
# of "Etherboot" in the DHCP reply
|
||||
# Requires DHCP support.
|
||||
# -DDHCP_CLIENT_ID=\"Identifier\"
|
||||
# -DDHCP_CLIENT_ID_LEN=<Client ID length in octets>
|
||||
# -DDHCP_CLIENT_ID_TYPE=<Client ID type>
|
||||
# Specify a RFC2132 Client Identifier option, length and type.
|
||||
# Requires DHCP support.
|
||||
# -DDHCP_USER_CLASS=\"UserClass\"
|
||||
# -DDHCP_USER_CLASS_LEN=<User Class length in octets>
|
||||
# Specify a RFC3004 User Class option and length. Use this
|
||||
# option to set a UC (or multiple UCs) rather than munge the
|
||||
# client Vendor Class ID.
|
||||
# Requires DHCP support.
|
||||
# -DALLOW_ONLY_ENCAPSULATED
|
||||
# Ignore Etherboot-specific options that are not within
|
||||
# the Etherboot encapsulated options field. This option
|
||||
# should be enabled unless you have a legacy DHCP server
|
||||
# configuration from the bad old days before the use of
|
||||
# encapsulated Etherboot options.
|
||||
# -DDEFAULT_BOOTFILE=\"default_bootfile_name\"
|
||||
# Define a default bootfile for the case where your DHCP
|
||||
# server does not provide the information. Example:
|
||||
# -DDEFAULT_BOOTFILE="tftp:///tftpboot/kernel"
|
||||
# If you do not specify this option, then DHCP offers that
|
||||
# do not specify bootfiles will be ignored.
|
||||
#
|
||||
# NIC tuning parameters:
|
||||
#
|
||||
# -DALLMULTI
|
||||
# Turns on multicast reception in the NICs.
|
||||
#
|
||||
# Boot tuning parameters:
|
||||
#
|
||||
# -DCONGESTED
|
||||
# Turns on packet retransmission. Use it on a
|
||||
# congested network, where the normal operation
|
||||
# can't boot the image.
|
||||
# -DBACKOFF_LIMIT
|
||||
# Sets the maximum RFC951 backoff exponent to n.
|
||||
# Do not set this unreasonably low, because on networks
|
||||
# with many machines they can saturate the link
|
||||
# (the delay corresponding to the exponent is a random
|
||||
# time in the range 0..3.5*2^n seconds). Use 5 for a
|
||||
# VERY small network (max. 2 minutes delay), 7 for a
|
||||
# medium sized network (max. 7.5 minutes delay) or 10
|
||||
# for a really huge network with many clients, frequent
|
||||
# congestions (max. 1 hour delay). On average the
|
||||
# delay time will be half the maximum value. If in
|
||||
# doubt about the consequences, use a larger value.
|
||||
# Also keep in mind that the number of retransmissions
|
||||
# is not changed by this setting, so the default of 20
|
||||
# may no longer be appropriate. You might need to set
|
||||
# MAX_ARP_RETRIES, MAX_BOOTP_RETRIES, MAX_TFTP_RETRIES
|
||||
# and MAX_RPC_RETRIES to a larger value.
|
||||
# -DTIMEOUT=n
|
||||
# Use with care!! See above.
|
||||
# Sets the base of RFC2131 sleep interval to n.
|
||||
# This can be used with -DBACKOFF_LIMIT=0 to get a small
|
||||
# and constant (predictable) retry interval for embedded
|
||||
# devices. This is to achieve short boot delays if both
|
||||
# the DHCP Server and the embedded device will be powered
|
||||
# on the same time. Otherwise if the DHCP server is ready
|
||||
# the client could sleep the next exponentially timeout,
|
||||
# e.g. 70 seconds or more. This is not what you want.
|
||||
# n should be a multiple of TICKS_PER_SEC (18).
|
||||
#
|
||||
# Boot device options:
|
||||
#
|
||||
# -DTRY_FLOPPY_FIRST
|
||||
# If > 0, tries that many times to read the boot
|
||||
# sector from a floppy drive before booting from
|
||||
# ROM. If successful, does a local boot.
|
||||
# It assumes the floppy is bootable.
|
||||
# -DEXIT_IF_NO_OFFER
|
||||
# If no IP offer is obtained, exit and
|
||||
# let the BIOS continue.
|
||||
# The accessibility of the TFTP server has no effect,
|
||||
# so configure your DHCP/BOOTP server properly.
|
||||
# You should probably reduce MAX_BOOTP_RETRIES
|
||||
# to a small number like 3.
|
||||
#
|
||||
# Boot image options:
|
||||
#
|
||||
# -DFREEBSD_KERNEL_ENV
|
||||
# Pass in FreeBSD kernel environment
|
||||
# -DAOUT_LYNX_KDI
|
||||
# Add Lynx a.out KDI support
|
||||
# -DMULTICAST_LEVEL1
|
||||
# Support for sending multicast packets
|
||||
# -DMULTICAST_LEVEL2
|
||||
# Support for receiving multicast packets
|
||||
#
|
||||
# Interface export options:
|
||||
#
|
||||
# -DPXE_EXPORT
|
||||
# Export a PXE API interface. This is work in
|
||||
# progress. Note that you won't be able to load
|
||||
# PXE NBPs unless you also use -DPXE_IMAGE.
|
||||
# -DPXE_STRICT
|
||||
# Strict(er) compliance with the PXE
|
||||
# specification as published by Intel. This may
|
||||
# or may not be a good thing depending on your
|
||||
# view of the spec...
|
||||
# -DPXE_DHCP_STRICT
|
||||
# Strict compliance of the DHCP request packets
|
||||
# with the PXE specification as published by
|
||||
# Intel. This may or may not be a good thing
|
||||
# depending on your view of whether requesting
|
||||
# vendor options which don't actually exist is
|
||||
# pointless or not. You probably want this
|
||||
# option if you intend to use Windows RIS or
|
||||
# similar.
|
||||
#
|
||||
# Obscure options you probably don't need to touch:
|
||||
#
|
||||
# -DZPXE_SUFFIX_STRIP
|
||||
# If the last 5 characters of the filename passed to Etherboot is
|
||||
# ".zpxe" then strip it off. This is useful in cases where a DHCP server
|
||||
# is not able to be configured to support conditionals. The way it works
|
||||
# is that the DHCP server is configured with a filename like
|
||||
# "foo.nbi.zpxe" so that when PXE asks for a filename it gets that, and
|
||||
# loads Etherboot from that file. Etherboot then starts up and once
|
||||
# again asks the DHCP server for a filename and once again gets
|
||||
# foo.nbi.zpxe, but with this option turned on loads "foo.nbi" instead.
|
||||
# This allows people to use Etherboot who might not otherwise be able to
|
||||
# because their DHCP servers won't let them.
|
||||
#
|
||||
# -DPOWERSAVE
|
||||
# Halt the processor when waiting for keyboard input
|
||||
# which saves power while waiting for user interaction.
|
||||
# Good for compute clusters and VMware emulation.
|
||||
# But may not work for all CPUs.
|
||||
#
|
||||
# @/OptionDescription@
|
||||
|
||||
# These default settings compile Etherboot with a small number of options.
|
||||
# You may wish to enable more of the features if the size of your ROM allows.
|
||||
|
||||
|
||||
# For prompting and default on timeout
|
||||
# CFLAGS+= -DASK_BOOT=3 -DBOOT_FIRST=BOOT_NIC
|
||||
# If you would like to attempt to boot from other devices as well as the network.
|
||||
# CFLAGS+= -DBOOT_SECOND=BOOT_FLOPPY
|
||||
# CFLAGS+= -DBOOT_THIRD=BOOT_DISK
|
||||
# CFLAGS+= -DBOOT_INDEX=0
|
||||
|
||||
# If you prefer the old style rotating bar progress display
|
||||
# CFLAGS+= -DBAR_PROGRESS
|
||||
|
||||
# Show size indicator
|
||||
# CFLAGS+= -DSIZEINDICATOR
|
||||
|
||||
# Enabling this creates non-standard images which use ports 1067 and 1068
|
||||
# for DHCP/BOOTP
|
||||
# CFLAGS+= -DALTERNATE_DHCP_PORTS_1067_1068
|
||||
|
||||
# Enabling this makes the boot ROM require a Vendor Class Identifier
|
||||
# of "Etherboot" in the Vendor Encapsulated Options
|
||||
# This can be used to reject replies from servers other than the one
|
||||
# we want to give out addresses to us, but it will prevent Etherboot
|
||||
# from getting an IP lease until you have configured DHCPD correctly
|
||||
# CFLAGS+= -DREQUIRE_VCI_ETHERBOOT
|
||||
|
||||
# EXPERIMENTAL! Set DHCP_CLIENT_ID to create a Client Identifier (DHCP
|
||||
# option 61, see RFC2132 section 9.14) when Etherboot sends the DHCP
|
||||
# DISCOVER and REQUEST packets. This ID must UNIQUELY identify each
|
||||
# client on your local network. Set DHCP_CLIENT_ID_TYPE to the
|
||||
# appropriate hardware type as described in RFC2132 / RFC1700; this
|
||||
# almost certainly means using '1' if the Client ID is an Ethernet MAC
|
||||
# address and '0' otherwise. Set DHCP_CLIENT_ID_LEN to the length of
|
||||
# the Client ID in octets (this is not a null terminated C string, do
|
||||
# NOT add 1 for a terminator and do NOT add an extra 1 for the
|
||||
# hardware type octet). Note that to identify your client using the
|
||||
# normal default MAC address of your NIC, you do NOT need to set this
|
||||
# option, as the MAC address is automatically used in the
|
||||
# hwtype/chaddr field; note also that this field only sets the DHCP
|
||||
# option: it does NOT change the MAC address used by the client.
|
||||
|
||||
# CFLAGS+= -DDHCP_CLIENT_ID="'C','L','I','E','N','T','0','0','1'" \
|
||||
# -DDHCP_CLIENT_ID_LEN=9 -DDHCP_CLIENT_ID_TYPE=0
|
||||
|
||||
# CFLAGS+= -DDHCP_CLIENT_ID="0xDE,0xAD,0xBE,0xEF,0xDE,0xAD" \
|
||||
# -DDHCP_CLIENT_ID_LEN=6 -DDHCP_CLIENT_ID_TYPE=1
|
||||
|
||||
# EXPERIMENTAL! Set DHCP_USER_CLASS to create a User Class option (see
|
||||
# RFC3004) when Etherboot sends the DHCP DISCOVER and REQUEST packets.
|
||||
# This can be used for classification of clients, typically so that a
|
||||
# DHCP server can send an appropriately tailored reply. Normally, a
|
||||
# string identifies a class of to which this client instance belongs
|
||||
# which is useful in your network, such as a department ('FINANCE' or
|
||||
# 'MARKETING') or hardware type ('THINCLIENT' or 'KIOSK'). Set
|
||||
# DHCP_USER_CLASS_LEN to the length of DHCP_USER_CLASS in octets.
|
||||
# This is NOT a null terminated C string, do NOT add 1 for a
|
||||
# terminator. RFC3004 advises how to lay out multiple User Class
|
||||
# options by using an octet for the length of each string, as in this
|
||||
# example. It is, of course, up to the server to parse this.
|
||||
|
||||
# CFLAGS+= -DDHCP_USER_CLASS="'T','E','S','T','C','L','A','S','S'" \
|
||||
# -DDHCP_USER_CLASS_LEN=9
|
||||
|
||||
# CFLAGS+= -DDHCP_USER_CLASS="5,'A','L','P','H','A',4,'B','E','T','A'" \
|
||||
# -DDHCP_USER_CLASS_LEN=11
|
||||
|
||||
# Enabling this causes Etherboot to ignore Etherboot-specific options
|
||||
# that are not within an Etherboot encapsulated options field.
|
||||
# This option should be enabled unless you have a legacy DHCP server
|
||||
# configuration from the bad old days before the use of
|
||||
# encapsulated Etherboot options.
|
||||
# CFLAGS+= -DALLOW_ONLY_ENCAPSULATED
|
||||
|
||||
# Disable DHCP support
|
||||
# CFLAGS+= -DNO_DHCP_SUPPORT
|
||||
|
||||
# Specify a default bootfile to be used if the DHCP server does not
|
||||
# provide the information. If you do not specify this option, then
|
||||
# DHCP offers that do not contain bootfiles will be ignored.
|
||||
# CFLAGS+= -DDEFAULT_BOOTFILE=\"tftp:///tftpboot/kernel\"
|
||||
|
||||
# Limit the delay on packet loss/congestion to a more bearable value. See
|
||||
# description above. If unset, do not limit the delay between resend.
|
||||
# CFLAGS+= -DBACKOFF_LIMIT=5 -DCONGESTED
|
||||
|
||||
# More optional features
|
||||
# CFLAGS+= -DTRY_FLOPPY_FIRST=4
|
||||
# CFLAGS+= -DEXIT_IF_NO_OFFER
|
||||
|
||||
|
||||
# Multicast Support
|
||||
# CFLAGS+= -DALLMULTI -DMULTICAST_LEVEL1 -DMULTICAST_LEVEL2
|
||||
|
||||
# Etherboot as a PXE network protocol ROM
|
||||
# CFLAGS+= -DPXE_IMAGE -DPXE_EXPORT
|
||||
# Etherboot stricter as a PXE network protocol ROM
|
||||
# CFLAGS+= -DPXE_DHCP_STRICT
|
||||
|
||||
# Support for PXE emulation. Works only with FreeBSD to load the kernel
|
||||
# via pxeboot, use only with DOWNLOAD_PROTO_NFS
|
||||
# CFLAGS+= -DFREEBSD_PXEEMU
|
||||
|
||||
|
||||
|
||||
# Garbage from Makefile.main temporarily placed here until a home can
|
||||
# be found for it.
|
||||
|
||||
# NS8390 options:
|
||||
# -DINCLUDE_NE - Include NE1000/NE2000 support
|
||||
# -DNE_SCAN=list - Probe for NE base address using list of
|
||||
# comma separated hex addresses
|
||||
# -DINCLUDE_3C503 - Include 3c503 support
|
||||
# -DT503_SHMEM - Use 3c503 shared memory mode (off by default)
|
||||
# -DINCLUDE_WD - Include Western Digital/SMC support
|
||||
# -DWD_DEFAULT_MEM- Default memory location for WD/SMC cards
|
||||
# -DWD_790_PIO - Read/write to WD/SMC 790 cards in PIO mode (default
|
||||
# is to use shared memory) Try this if you get "Bogus
|
||||
# packet, ignoring" messages, common on ISA/PCI hybrid
|
||||
# systems.
|
||||
# -DCOMPEX_RL2000_FIX
|
||||
#
|
||||
# If you have a Compex RL2000 PCI 32-bit (11F6:1401),
|
||||
# and the bootrom hangs in "Probing...[NE*000/PCI]",
|
||||
# try enabling this fix... it worked for me :).
|
||||
# In the first packet write somehow it somehow doesn't
|
||||
# get back the expected data so it is stuck in a loop.
|
||||
# I didn't bother to investigate what or why because it works
|
||||
# when I interrupt the loop if it takes more then COMPEX_RL2000_TRIES.
|
||||
# The code will notify if it does a abort.
|
||||
# SomniOne - somnione@gmx.net
|
||||
#
|
||||
# 3C90X options:
|
||||
# Warning Warning Warning
|
||||
# If you use any of the XCVR options below, please do not complain about
|
||||
# the behaviour with Linux drivers to the kernel developers. You are
|
||||
# on your own if you do this. Please read 3c90x.txt to understand
|
||||
# what they do. If you don't understand them, ask for help on the
|
||||
# Etherboot mailing list. And please document what you did to the NIC
|
||||
# on the NIC so that people after you won't get nasty surprises.
|
||||
#
|
||||
# -DCFG_3C90X_PRESERVE_XCVR - Reset the transceiver type to the value it
|
||||
# had initially just before the loaded code is started.
|
||||
# -DCFG_3C90X_XCVR - Hardcode the tranceiver type Etherboot uses.
|
||||
# -DCFG_3C90X_BOOTROM_FIX - If you have a 3c905B with buggy ROM
|
||||
# interface, setting this option might "fix" it. Use
|
||||
# with caution and read the docs in 3c90x.txt!
|
||||
#
|
||||
# See the documentation file 3c90x.txt for more details.
|
||||
#
|
||||
# CS89X0 (optional) options:
|
||||
# -DISA_PROBE_ADDRS=list
|
||||
# Probe for CS89x0 base address using list of
|
||||
# comma separated hex addresses; increasing the
|
||||
# address by one (0x300 -> 0x301) will force a
|
||||
# more aggressive probing algorithm. This might
|
||||
# be neccessary after a soft-reset of the NIC.
|
||||
|
||||
|
||||
CFLAGS_3c503 = -DINCLUDE_3C503 # -DT503_SHMEM
|
||||
CFLAGS_ne = -DINCLUDE_NE -DNE_SCAN=0x300,0x280,0x320,0x340,0x380
|
||||
CFLAGS_ns8390 = -DINCLUDE_NS8390 # NE2000/PCI!
|
||||
CFLAGS_wd = -DINCLUDE_WD -DWD_DEFAULT_MEM=0xCC000
|
||||
+75
-128
@@ -1,19 +1,17 @@
|
||||
# Location to place generated files
|
||||
###############################################################################
|
||||
#
|
||||
BIN := bin
|
||||
|
||||
# Initialise variables that get added to throughout the various Makefiles
|
||||
# Initialise various variables
|
||||
#
|
||||
MAKEDEPS := Makefile .toolcheck .echocheck
|
||||
SRCDIRS :=
|
||||
SRCS :=
|
||||
NON_AUTO_SRCS :=
|
||||
DRIVERS :=
|
||||
ROMS :=
|
||||
MEDIA :=
|
||||
NON_AUTO_MEDIA :=
|
||||
|
||||
# Locations of utilities
|
||||
CLEANUP :=
|
||||
CFLAGS :=
|
||||
ASFLAGS :=
|
||||
LDFLAGS :=
|
||||
MAKEDEPS := Makefile
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Locations of tools
|
||||
#
|
||||
HOST_CC := gcc
|
||||
RM := rm -f
|
||||
@@ -35,114 +33,20 @@ NM := $(CROSS_COMPILE)nm
|
||||
OBJDUMP := $(CROSS_COMPILE)objdump
|
||||
PARSEROM := $(PERL) ./util/parserom.pl
|
||||
MAKEROM := $(PERL) ./util/makerom.pl
|
||||
MKCONFIG := $(PERL) ./util/mkconfig.pl
|
||||
SYMCHECK := $(PERL) ./util/symcheck.pl
|
||||
SORTOBJDUMP := $(PERL) ./util/sortobjdump.pl
|
||||
NRV2B := ./util/nrv2b
|
||||
ZBIN := ./util/zbin
|
||||
ELF2EFI32 := ./util/elf2efi32
|
||||
ELF2EFI64 := ./util/elf2efi64
|
||||
EFIROM := ./util/efirom
|
||||
DOXYGEN := doxygen
|
||||
|
||||
# If invoked with no build target, print out a helpfully suggestive
|
||||
# message.
|
||||
###############################################################################
|
||||
#
|
||||
noargs : blib $(BIN)/NIC $(BIN)/gpxe.dsk $(BIN)/gpxe.iso $(BIN)/gpxe.usb
|
||||
@$(ECHO) '==========================================================='
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable floppy, type'
|
||||
@$(ECHO) ' cat $(BIN)/gpxe.dsk > /dev/fd0'
|
||||
@$(ECHO) 'where /dev/fd0 is your floppy drive. This will erase any'
|
||||
@$(ECHO) 'data already on the disk.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable USB key, type'
|
||||
@$(ECHO) ' cat $(BIN)/gpxe.usb > /dev/sdX'
|
||||
@$(ECHO) 'where /dev/sdX is your USB key, and is *not* a real hard'
|
||||
@$(ECHO) 'disk on your system. This will erase any data already on'
|
||||
@$(ECHO) 'the USB key.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable CD-ROM, burn the ISO image '
|
||||
@$(ECHO) '$(BIN)/gpxe.iso to a blank CD-ROM.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'These images contain drivers for all supported cards. You'
|
||||
@$(ECHO) 'can build more customised images, and ROM images, using'
|
||||
@$(ECHO) ' make bin/<rom-name>.<output-format>'
|
||||
@$(ECHO)
|
||||
@$(ECHO) '==========================================================='
|
||||
|
||||
# Grab the central Config file.
|
||||
#
|
||||
MAKEDEPS += Config
|
||||
include Config
|
||||
|
||||
# If no architecture is specified in Config or on the command-line,
|
||||
# use that of the build machine.
|
||||
#
|
||||
ARCH ?= $(shell uname -m | sed -e s,i[3456789]86,i386,)
|
||||
|
||||
# handle x86_64 like i386, but set -m32 option for 32bit code only
|
||||
ifeq ($(ARCH),x86_64)
|
||||
ARCH := i386
|
||||
CFLAGS += -m32
|
||||
ASFLAGS += --32
|
||||
LDFLAGS += -m elf_i386
|
||||
endif
|
||||
|
||||
# Drag in architecture-specific Config
|
||||
#
|
||||
MAKEDEPS += arch/$(ARCH)/Config
|
||||
include arch/$(ARCH)/Config
|
||||
|
||||
# Common flags
|
||||
#
|
||||
CFLAGS += -I include -I arch/$(ARCH)/include -I . -DARCH=$(ARCH)
|
||||
CFLAGS += -Os -ffreestanding
|
||||
CFLAGS += -Wall -W
|
||||
CFLAGS += -g
|
||||
CFLAGS += $(EXTRA_CFLAGS)
|
||||
ASFLAGS += $(EXTRA_ASFLAGS)
|
||||
LDFLAGS += $(EXTRA_LDFLAGS)
|
||||
|
||||
# Embedded image, if present
|
||||
#
|
||||
EMBEDDED_IMAGE ?= /dev/null
|
||||
|
||||
ifneq ($(NO_WERROR),1)
|
||||
CFLAGS += -Werror
|
||||
endif
|
||||
|
||||
# CFLAGS for specific object types
|
||||
#
|
||||
CFLAGS_c +=
|
||||
CFLAGS_S += -DASSEMBLY
|
||||
|
||||
# Base object name of the current target
|
||||
#
|
||||
OBJECT = $(firstword $(subst ., ,$(@F)))
|
||||
|
||||
# CFLAGS for specific object files. You can define
|
||||
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
|
||||
# compiling bin/rtl8139.o.
|
||||
#
|
||||
OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
|
||||
$(BIN)/%.flags :
|
||||
@$(ECHO) $(OBJ_CFLAGS)
|
||||
|
||||
# Rules for specific object types.
|
||||
#
|
||||
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
|
||||
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
|
||||
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
|
||||
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
|
||||
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
|
||||
|
||||
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
|
||||
ASSEMBLE_S = $(AS) $(ASFLAGS)
|
||||
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
|
||||
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
|
||||
|
||||
DEBUG_TARGETS += dbg%.o c s
|
||||
|
||||
# SRCDIRS lists all directories containing source files.
|
||||
#
|
||||
SRCDIRS :=
|
||||
SRCDIRS += libgcc
|
||||
SRCDIRS += core
|
||||
SRCDIRS += proto
|
||||
@@ -151,13 +55,12 @@ SRCDIRS += image
|
||||
SRCDIRS += drivers/bus
|
||||
SRCDIRS += drivers/net
|
||||
SRCDIRS += drivers/net/e1000
|
||||
SRCDIRS += drivers/net/phantom
|
||||
SRCDIRS += drivers/block
|
||||
SRCDIRS += drivers/scsi
|
||||
SRCDIRS += drivers/ata
|
||||
SRCDIRS += drivers/nvs
|
||||
SRCDIRS += drivers/bitbash
|
||||
SRCDIRS += drivers/infiniband
|
||||
SRCDIRS += interface/pxe
|
||||
SRCDIRS += interface/pxe interface/efi interface/smbios
|
||||
SRCDIRS += tests
|
||||
SRCDIRS += crypto crypto/axtls crypto/matrixssl
|
||||
SRCDIRS += hci hci/commands hci/tui
|
||||
@@ -167,25 +70,69 @@ SRCDIRS += usr
|
||||
# NON_AUTO_SRCS lists files that are excluded from the normal
|
||||
# automatic build system.
|
||||
#
|
||||
NON_AUTO_SRCS += core/elf_loader.c
|
||||
NON_AUTO_SRCS :=
|
||||
NON_AUTO_SRCS += drivers/net/prism2.c
|
||||
|
||||
# Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
|
||||
# the automatic build system and varies by target; it includes the
|
||||
# "-p 0x1234,0x5678" string to set the PCI IDs.
|
||||
###############################################################################
|
||||
#
|
||||
FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
|
||||
-i$(IDENT) -s 0 $@
|
||||
|
||||
# Some ROMs require specific flags to be passed to makerom.pl
|
||||
# Default build target: build the most common targets and print out a
|
||||
# helpfully suggestive message
|
||||
#
|
||||
MAKEROM_FLAGS_3c503 = -3
|
||||
all : bin/blib.a bin/gpxe.dsk bin/gpxe.iso bin/gpxe.usb bin/undionly.kpxe
|
||||
@$(ECHO) '==========================================================='
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable floppy, type'
|
||||
@$(ECHO) ' cat bin/gpxe.dsk > /dev/fd0'
|
||||
@$(ECHO) 'where /dev/fd0 is your floppy drive. This will erase any'
|
||||
@$(ECHO) 'data already on the disk.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable USB key, type'
|
||||
@$(ECHO) ' cat bin/gpxe.usb > /dev/sdX'
|
||||
@$(ECHO) 'where /dev/sdX is your USB key, and is *not* a real hard'
|
||||
@$(ECHO) 'disk on your system. This will erase any data already on'
|
||||
@$(ECHO) 'the USB key.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable CD-ROM, burn the ISO image '
|
||||
@$(ECHO) 'bin/gpxe.iso to a blank CD-ROM.'
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'These images contain drivers for all supported cards. You'
|
||||
@$(ECHO) 'can build more customised images, and ROM images, using'
|
||||
@$(ECHO) ' make bin/<rom-name>.<output-format>'
|
||||
@$(ECHO)
|
||||
@$(ECHO) '==========================================================='
|
||||
|
||||
# Drag in architecture-specific Makefile
|
||||
###############################################################################
|
||||
#
|
||||
# Build targets that do nothing but might be tried by users
|
||||
#
|
||||
configure :
|
||||
@$(ECHO) "No configuration needed."
|
||||
|
||||
install :
|
||||
@$(ECHO) "No installation required."
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Version number calculations
|
||||
#
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 9
|
||||
VERSION_PATCH = 7
|
||||
EXTRAVERSION =
|
||||
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
||||
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
|
||||
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
|
||||
-DVERSION_MINOR=$(VERSION_MINOR) \
|
||||
-DVERSION_PATCH=$(VERSION_PATCH) \
|
||||
-DVERSION=\"$(VERSION)\"
|
||||
IDENT = '$(@F) $(VERSION) (GPL) etherboot.org'
|
||||
version :
|
||||
@$(ECHO) $(VERSION)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Drag in the bulk of the build system
|
||||
#
|
||||
MAKEDEPS += arch/$(ARCH)/Makefile
|
||||
include arch/$(ARCH)/Makefile
|
||||
|
||||
# Drag in the automatic build system and other housekeeping functions
|
||||
MAKEDEPS += Makefile.housekeeping
|
||||
include Makefile.housekeeping
|
||||
|
||||
+382
-127
@@ -1,50 +1,10 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
#
|
||||
# This file contains various boring housekeeping functions that would
|
||||
# otherwise seriously clutter up the main Makefile.
|
||||
|
||||
# Objects to be removed by "make clean"
|
||||
###############################################################################
|
||||
#
|
||||
CLEANUP := $(BIN)/*.* # *.* to avoid catching the "CVS" directory
|
||||
|
||||
# Version number calculations
|
||||
#
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 9
|
||||
VERSION_PATCH = 3
|
||||
EXTRAVERSION =
|
||||
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
||||
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
|
||||
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
|
||||
-DVERSION_MINOR=$(VERSION_MINOR) \
|
||||
-DVERSION=\"$(VERSION)\"
|
||||
IDENT = '$(@F) $(VERSION) (GPL) etherboot.org'
|
||||
version :
|
||||
@$(ECHO) $(VERSION)
|
||||
|
||||
configure :
|
||||
@$(ECHO) "No configuration needed."
|
||||
|
||||
install :
|
||||
@$(ECHO) "No installation required. Generated images will be placed in the" $(BIN) "directory."
|
||||
|
||||
# Check for tools that can cause failed builds
|
||||
#
|
||||
.toolcheck : Makefile Config
|
||||
@if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
|
||||
$(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
|
||||
$(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
|
||||
$(ECHO) 'Your Perl version has a Unicode handling bug'; \
|
||||
$(ECHO) 'Execute this command before compiling Etherboot:'; \
|
||||
$(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@$(TOUCH) $@
|
||||
VERYCLEANUP += .toolcheck
|
||||
|
||||
# Find a usable "echo -e" substitute.
|
||||
#
|
||||
TAB := $(shell $(PRINTF) '\t')
|
||||
@@ -58,16 +18,16 @@ ECHO_E_BIN_ECHO_TAB := $(shell $(ECHO_E_BIN_ECHO) '\t')
|
||||
ECHO_E_BIN_ECHO_E_TAB := $(shell $(ECHO_E_BIN_ECHO_E) '\t')
|
||||
|
||||
ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
|
||||
ECHO_E ?= $(ECHO_E_ECHO)
|
||||
ECHO_E := $(ECHO_E_ECHO)
|
||||
endif
|
||||
ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
|
||||
ECHO_E ?= $(ECHO_E_ECHO_E)
|
||||
ECHO_E := $(ECHO_E_ECHO_E)
|
||||
endif
|
||||
ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
|
||||
ECHO_E ?= $(ECHO_E_BIN_ECHO)
|
||||
ECHO_E := $(ECHO_E_BIN_ECHO)
|
||||
endif
|
||||
ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
|
||||
ECHO_E ?= $(ECHO_E_BIN_ECHO_E)
|
||||
ECHO_E := $(ECHO_E_BIN_ECHO_E)
|
||||
endif
|
||||
|
||||
.echocheck :
|
||||
@@ -86,20 +46,51 @@ else
|
||||
@$(ECHO) "No usable \"echo -e\" substitute found"
|
||||
@exit 1
|
||||
endif
|
||||
MAKEDEPS += .echocheck
|
||||
VERYCLEANUP += .echocheck
|
||||
|
||||
echo :
|
||||
@$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
|
||||
|
||||
# Build verbosity
|
||||
###############################################################################
|
||||
#
|
||||
ifeq ($(V),1)
|
||||
Q =
|
||||
QM = @\#
|
||||
else
|
||||
Q = @
|
||||
QM = @
|
||||
endif
|
||||
# Determine host OS
|
||||
#
|
||||
HOST_OS := $(shell uname -s)
|
||||
hostos :
|
||||
@$(ECHO) $(HOST_OS)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Check for tools that can cause failed builds
|
||||
#
|
||||
.toolcheck :
|
||||
@if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
|
||||
$(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
|
||||
$(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
|
||||
$(ECHO) 'Your Perl version has a Unicode handling bug'; \
|
||||
$(ECHO) 'Execute this command before compiling Etherboot:'; \
|
||||
$(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@$(TOUCH) $@
|
||||
MAKEDEPS += .toolcheck
|
||||
VERYCLEANUP += .toolcheck
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Check for various tool workarounds
|
||||
#
|
||||
|
||||
# Make syntax does not allow use of comma or space in certain places.
|
||||
# This ugly workaround is suggested in the manual.
|
||||
#
|
||||
COMMA := ,
|
||||
EMPTY :=
|
||||
SPACE := $(EMPTY) $(EMPTY)
|
||||
|
||||
# Check for an old version of gas (binutils 2.9.1)
|
||||
#
|
||||
@@ -112,18 +103,154 @@ oldgas :
|
||||
# default, even when -ffreestanding is specified. We therefore need
|
||||
# to disable -fstack-protector if the compiler supports it.
|
||||
#
|
||||
SP_TEST = $(CC) -fno-stack-protector -x c -E - < /dev/null >/dev/null 2>&1
|
||||
SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
|
||||
-o /dev/null >/dev/null 2>&1
|
||||
SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
|
||||
CFLAGS += $(SP_FLAGS)
|
||||
|
||||
# compiler.h is needed for our linking and debugging system
|
||||
###############################################################################
|
||||
#
|
||||
CFLAGS += -include compiler.h
|
||||
# Build verbosity
|
||||
#
|
||||
ifeq ($(V),1)
|
||||
Q :=
|
||||
QM := @\#
|
||||
else
|
||||
Q := @
|
||||
QM := @
|
||||
endif
|
||||
|
||||
# config/%.h files are generated from config.h using mkconfig.pl
|
||||
config/%.h : config.h
|
||||
$(MKCONFIG) $<
|
||||
CLEANUP += config/*.h
|
||||
###############################################################################
|
||||
#
|
||||
# Set BIN according to whatever was specified on the command line as
|
||||
# the build target.
|
||||
#
|
||||
|
||||
# Determine how many different BIN directories are mentioned in the
|
||||
# make goals.
|
||||
#
|
||||
BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
|
||||
BIN_GOAL_BINS := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
|
||||
NUM_BINS := $(words $(sort $(BIN_GOAL_BINS)))
|
||||
|
||||
ifeq ($(NUM_BINS),0)
|
||||
|
||||
# No BIN directory was specified. Set BIN to "bin" as a sensible
|
||||
# default.
|
||||
|
||||
BIN := bin
|
||||
|
||||
else # NUM_BINS == 0
|
||||
|
||||
ifeq ($(NUM_BINS),1)
|
||||
|
||||
# If exactly one BIN directory was specified, set BIN to match this
|
||||
# directory.
|
||||
#
|
||||
BIN := $(firstword $(BIN_GOAL_BINS))
|
||||
|
||||
else # NUM_BINS == 1
|
||||
|
||||
# More than one BIN directory was specified. We cannot handle the
|
||||
# latter case within a single make invocation, so set up recursive
|
||||
# targets for each BIN directory.
|
||||
#
|
||||
# Leave $(BIN) undefined. This has implications for any target that
|
||||
# depends on $(BIN); such targets should be made conditional upon the
|
||||
# existence of $(BIN).
|
||||
#
|
||||
$(BIN_GOALS) : % : BIN_RECURSE
|
||||
$(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
|
||||
.PHONY : BIN_RECURSE
|
||||
|
||||
endif # NUM_BINS == 1
|
||||
endif # NUM_BINS == 0
|
||||
|
||||
ifdef BIN
|
||||
|
||||
# Create $(BIN) directory if it doesn't exist yet
|
||||
#
|
||||
ifeq ($(wildcard $(BIN)),)
|
||||
$(shell $(MKDIR) -p $(BIN))
|
||||
endif
|
||||
|
||||
# Target to allow e.g. "make bin-efi arch"
|
||||
#
|
||||
$(BIN) :
|
||||
@# Do nothing, silently
|
||||
.PHONY : $(BIN)
|
||||
|
||||
# Remove everything in $(BIN) for a "make clean"
|
||||
#
|
||||
CLEANUP += $(BIN)/*.* # Avoid picking up directories
|
||||
|
||||
endif # defined(BIN)
|
||||
|
||||
# Determine whether or not we need to include the dependency files
|
||||
#
|
||||
NO_DEP_TARGETS := $(BIN) clean veryclean
|
||||
ifeq ($(MAKECMDGOALS),)
|
||||
NEED_DEPS := 1
|
||||
endif
|
||||
ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
|
||||
NEED_DEPS := 1
|
||||
endif
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Select build architecture and platform based on $(BIN)
|
||||
#
|
||||
# BIN has the form bin[-[arch-]platform]
|
||||
|
||||
ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
|
||||
PLATFORMS := $(patsubst config/defaults/%.h,%,\
|
||||
$(wildcard config/defaults/*.h))
|
||||
archs :
|
||||
@$(ECHO) $(ARCHS)
|
||||
|
||||
platforms :
|
||||
@$(ECHO) $(PLATFORMS)
|
||||
|
||||
ifdef BIN
|
||||
|
||||
# Determine architecture portion of $(BIN), if present
|
||||
BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
|
||||
$(patsubst bin-$(A)-%,$(A),\
|
||||
$(filter bin-$(A)-%,$(BIN)))))
|
||||
|
||||
# Determine platform portion of $(BIN), if present
|
||||
ifeq ($(BIN_ARCH),)
|
||||
BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
|
||||
else
|
||||
BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
|
||||
endif
|
||||
|
||||
# Determine build architecture
|
||||
DEFAULT_ARCH := i386
|
||||
ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
|
||||
CFLAGS += -DARCH=$(ARCH)
|
||||
arch :
|
||||
@$(ECHO) $(ARCH)
|
||||
.PHONY : arch
|
||||
|
||||
# Determine build platform
|
||||
DEFAULT_PLATFORM := pcbios
|
||||
PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
|
||||
CFLAGS += -DPLATFORM=$(PLATFORM)
|
||||
platform :
|
||||
@$(ECHO) $(PLATFORM)
|
||||
|
||||
endif # defined(BIN)
|
||||
|
||||
# Include architecture-specific Makefile
|
||||
ifdef ARCH
|
||||
MAKEDEPS += arch/$(ARCH)/Makefile
|
||||
include arch/$(ARCH)/Makefile
|
||||
endif
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Source file handling
|
||||
|
||||
# SRCDIRS lists all directories containing source files.
|
||||
srcdirs :
|
||||
@@ -144,6 +271,64 @@ AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
|
||||
autosrcs :
|
||||
@$(ECHO) $(AUTO_SRCS)
|
||||
|
||||
# Just about everything else in this section depends upon having
|
||||
# $(BIN) set
|
||||
|
||||
ifdef BIN
|
||||
|
||||
# Common flags
|
||||
#
|
||||
CFLAGS += -I include -I arch/$(ARCH)/include -I .
|
||||
CFLAGS += -Os -ffreestanding
|
||||
CFLAGS += -Wall -W -Wformat-nonliteral
|
||||
CFLAGS += -g
|
||||
CFLAGS += $(EXTRA_CFLAGS)
|
||||
ASFLAGS += $(EXTRA_ASFLAGS)
|
||||
LDFLAGS += $(EXTRA_LDFLAGS)
|
||||
|
||||
# Inhibit -Werror if NO_WERROR is specified on make command line
|
||||
#
|
||||
ifneq ($(NO_WERROR),1)
|
||||
CFLAGS += -Werror
|
||||
ASFLAGS += --fatal-warnings
|
||||
endif
|
||||
|
||||
# compiler.h is needed for our linking and debugging system
|
||||
#
|
||||
CFLAGS += -include compiler.h
|
||||
|
||||
# CFLAGS for specific object types
|
||||
#
|
||||
CFLAGS_c +=
|
||||
CFLAGS_S += -DASSEMBLY
|
||||
|
||||
# Base object name of the current target
|
||||
#
|
||||
OBJECT = $(firstword $(subst ., ,$(@F)))
|
||||
|
||||
# CFLAGS for specific object files. You can define
|
||||
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
|
||||
# compiling bin/rtl8139.o.
|
||||
#
|
||||
OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
|
||||
$(BIN)/%.flags :
|
||||
@$(ECHO) $(OBJ_CFLAGS)
|
||||
|
||||
# Rules for specific object types.
|
||||
#
|
||||
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
|
||||
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
|
||||
RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
|
||||
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
|
||||
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
|
||||
|
||||
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
|
||||
ASSEMBLE_S = $(AS) $(ASFLAGS)
|
||||
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
|
||||
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
|
||||
|
||||
DEBUG_TARGETS += dbg%.o c s
|
||||
|
||||
# We automatically generate rules for any file mentioned in AUTO_SRCS
|
||||
# using the following set of templates. It would be cleaner to use
|
||||
# $(eval ...), but this function exists only in GNU make >= 3.80.
|
||||
@@ -157,7 +342,7 @@ autosrcs :
|
||||
#
|
||||
define src_template
|
||||
|
||||
@$(ECHO) "Generating Makefile rules for $(1)"
|
||||
@$(ECHO) " [DEPS] $(1)"
|
||||
@$(MKDIR) -p $(dir $(2))
|
||||
@$(RM) $(2)
|
||||
@$(TOUCH) $(2)
|
||||
@@ -179,16 +364,16 @@ endef
|
||||
define obj_template
|
||||
|
||||
@$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
|
||||
-Wno-error -M $(1) -MT "$(4)_DEPS" -MG -MP | \
|
||||
-Wno-error -MM $(1) -MT "$(4)_DEPS" -MG -MP | \
|
||||
sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
|
||||
@$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
|
||||
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
|
||||
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
|
||||
'\n\t$$(RULE_$(3))\n' \
|
||||
'\nBOBJS += $$(BIN)/$(4).o\n' \
|
||||
$(foreach TGT,$(DEBUG_TARGETS), \
|
||||
$(if $(RULE_$(3)_to_$(TGT)), \
|
||||
'\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
|
||||
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
|
||||
'\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
|
||||
'\n\t$$(RULE_$(3)_to_$(TGT))\n' \
|
||||
'\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
|
||||
'\n$(2) : $$($(4)_DEPS)\n' \
|
||||
@@ -205,7 +390,11 @@ $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
|
||||
# Calculate and include the list of Makefile rules files
|
||||
#
|
||||
AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
|
||||
include $(AUTO_DEPS)
|
||||
ifdef NEED_DEPS
|
||||
ifneq ($(AUTO_DEPS),)
|
||||
-include $(AUTO_DEPS)
|
||||
endif
|
||||
endif
|
||||
autodeps :
|
||||
@$(ECHO) $(AUTO_DEPS)
|
||||
VERYCLEANUP += $(BIN)/deps
|
||||
@@ -220,13 +409,31 @@ drivers :
|
||||
roms :
|
||||
@$(ECHO) $(ROMS)
|
||||
|
||||
# Embedded binary
|
||||
$(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
|
||||
$(QM)$(ECHO) " [COPY] $@"
|
||||
$(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
|
||||
# List of embedded images included in the last build of embedded.o.
|
||||
# This is needed in order to correctly rebuild embedded.o whenever the
|
||||
# list of objects changes.
|
||||
#
|
||||
EMBEDDED_LIST := $(BIN)/.embedded.list
|
||||
ifeq ($(wildcard $(EMBEDDED_LIST)),)
|
||||
EMBEDDED_LIST_IMAGE :=
|
||||
else
|
||||
EMBEDDED_LIST_IMAGE := $(shell cat $(EMBEDDED_LIST))
|
||||
endif
|
||||
ifneq ($(EMBEDDED_LIST_IMAGE),$(EMBEDDED_IMAGE))
|
||||
$(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
|
||||
endif
|
||||
|
||||
$(BIN)/embed.o: $(BIN)/embedimg.bin
|
||||
CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
|
||||
$(EMBEDDED_LIST) :
|
||||
|
||||
VERYCLEANUP += $(EMBEDDED_LIST)
|
||||
|
||||
EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
|
||||
EMBED_ALL := $(foreach i,$(shell seq 1 $(words $(EMBEDDED_FILES))),\
|
||||
EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
|
||||
\"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
|
||||
|
||||
$(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
|
||||
CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
|
||||
|
||||
# Generate the NIC file from the parsed source files. The NIC file is
|
||||
# only for rom-o-matic.
|
||||
@@ -237,7 +444,7 @@ $(BIN)/NIC : $(AUTO_DEPS)
|
||||
'it is only for rom-o-matic' >> $@
|
||||
@$(ECHO) >> $@
|
||||
@perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
|
||||
CLEANUP += $(BIN)/NIC
|
||||
CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
|
||||
|
||||
# Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
|
||||
# derive the variables:
|
||||
@@ -278,8 +485,8 @@ TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
|
||||
#
|
||||
TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
|
||||
TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
|
||||
TGT_LD_IDS = $(if $(TGT_PCI_VENDOR),pci_vendor_id=$(TGT_PCI_VENDOR)) \
|
||||
$(if $(TGT_PCI_DEVICE),pci_device_id=$(TGT_PCI_DEVICE))
|
||||
TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
|
||||
pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
|
||||
|
||||
# Calculate linker flags based on link-time options for the current
|
||||
# target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
|
||||
@@ -305,7 +512,6 @@ TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
|
||||
# Calculate list of debugging versions of objects to be included in
|
||||
# the target.
|
||||
#
|
||||
COMMA := ,
|
||||
DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
|
||||
DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
|
||||
DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
|
||||
@@ -342,8 +548,13 @@ $(BIN)/%.info :
|
||||
# in order to correctly rebuild blib whenever the list of objects
|
||||
# changes.
|
||||
#
|
||||
BLIB_LIST = $(BIN)/.blib.list
|
||||
ifneq ($(shell cat $(BLIB_LIST)),$(BLIB_OBJS))
|
||||
BLIB_LIST := $(BIN)/.blib.list
|
||||
ifeq ($(wildcard $(BLIB_LIST)),)
|
||||
BLIB_LIST_OBJS :=
|
||||
else
|
||||
BLIB_LIST_OBJS := $(shell cat $(BLIB_LIST))
|
||||
endif
|
||||
ifneq ($(BLIB_LIST_OBJS),$(BLIB_OBJS))
|
||||
$(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
|
||||
endif
|
||||
|
||||
@@ -371,7 +582,7 @@ $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
|
||||
$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
|
||||
|
||||
# Keep intermediate object file (useful for debugging)
|
||||
.SECONDARY : $(BIN)/%.tmp
|
||||
.PRECIOUS : $(BIN)/%.tmp
|
||||
|
||||
# Show a linker map for the specified target
|
||||
#
|
||||
@@ -396,10 +607,6 @@ $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
|
||||
$(QM)$(ECHO) " [ZBIN] $@"
|
||||
$(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
|
||||
|
||||
# Build bochs symbol table
|
||||
$(BIN)/%.bxs : $(BIN)/%.tmp
|
||||
$(NM) $< | cut -d" " -f1,3 > $@
|
||||
|
||||
# Rules for each media format. These are generated and placed in an
|
||||
# external Makefile fragment. We could do this via $(eval ...), but
|
||||
# that would require make >= 3.80.
|
||||
@@ -435,7 +642,7 @@ automedia :
|
||||
#
|
||||
define media_template
|
||||
|
||||
@$(ECHO) "Generating Makefile rules for $(1) media"
|
||||
@$(ECHO) " [MEDIADEPS] $(1)"
|
||||
@$(MKDIR) -p $(dir $(2))
|
||||
@$(RM) $(2)
|
||||
@$(TOUCH) $(2)
|
||||
@@ -459,7 +666,20 @@ $(BIN)/deps/%.media.d : $(MAKEDEPS)
|
||||
MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
|
||||
mediadeps :
|
||||
@$(ECHO) $(MEDIA_DEPS)
|
||||
include $(MEDIA_DEPS)
|
||||
ifdef NEED_DEPS
|
||||
ifneq ($(MEDIA_DEPS),)
|
||||
-include $(MEDIA_DEPS)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Wrap up binary blobs (for embedded images)
|
||||
#
|
||||
$(BIN)/%.o : payload/%.img
|
||||
$(QM)echo " [WRAP] $@"
|
||||
$(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
|
||||
--defsym obj_$*=0
|
||||
|
||||
BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
|
||||
|
||||
# The "allXXXs" targets for each suffix
|
||||
#
|
||||
@@ -472,15 +692,23 @@ allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%
|
||||
$(BIN)/etherboot.% : $(BIN)/gpxe.%
|
||||
ln -sf $(notdir $<) $@
|
||||
|
||||
# Wrap up binary blobs
|
||||
endif # defined(BIN)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
$(BIN)/%.o : payload/%.img
|
||||
$(QM)echo " [WRAP] $@"
|
||||
$(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
|
||||
--defsym obj_$*=0
|
||||
# Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
|
||||
# the automatic build system and varies by target; it includes the
|
||||
# "-p 0x1234,0x5678" string to set the PCI IDs.
|
||||
#
|
||||
FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
|
||||
-i$(IDENT) -s 0 $@
|
||||
|
||||
BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
|
||||
# Some ROMs require specific flags to be passed to makerom.pl
|
||||
#
|
||||
MAKEROM_FLAGS_3c503 = -3
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# The compression utilities
|
||||
#
|
||||
$(NRV2B) : util/nrv2b.c $(MAKEDEPS)
|
||||
@@ -494,6 +722,29 @@ $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
|
||||
$(Q)$(HOST_CC) -O2 -o $@ $<
|
||||
CLEANUP += $(ZBIN)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# The EFI image converter
|
||||
#
|
||||
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
|
||||
$(QM)$(ECHO) " [HOSTCC] $@"
|
||||
$(Q)$(HOST_CC) -DMDE_CPU_IA32 -idirafter include -O2 \
|
||||
-o $@ $< -lbfd -liberty
|
||||
CLEANUP += $(ELF2EFI32)
|
||||
|
||||
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
|
||||
$(QM)$(ECHO) " [HOSTCC] $@"
|
||||
$(Q)$(HOST_CC) -DMDE_CPU_X64 -idirafter include -O2 \
|
||||
-o $@ $< -lbfd -liberty
|
||||
CLEANUP += $(ELF2EFI64)
|
||||
|
||||
$(EFIROM) : util/efirom.c $(MAKEDEPS)
|
||||
$(QM)$(ECHO) " [HOSTCC] $@"
|
||||
$(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
|
||||
CLEANUP += $(EFIROM)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Auto-incrementing build serial number. Append "bs" to your list of
|
||||
# build targets to get a serial number printed at the end of the
|
||||
# build. Enable -DBUILD_SERIAL in order to see it when the code runs.
|
||||
@@ -517,27 +768,30 @@ bs : $(BUILDSERIAL_NOW)
|
||||
@$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
|
||||
@$(ECHO) "Build serial number is $(shell cat $<)"
|
||||
|
||||
# List of available architectures
|
||||
###############################################################################
|
||||
#
|
||||
ARCHS = $(filter-out CVS,$(patsubst arch/%,%,$(wildcard arch/*)))
|
||||
archs :
|
||||
@$(ECHO) $(ARCHS)
|
||||
|
||||
OTHER_ARCHS = $(filter-out $(ARCH),$(ARCHS))
|
||||
otherarchs :
|
||||
@$(ECHO) $(OTHER_ARCHS)
|
||||
|
||||
# Build the TAGS file for emacs
|
||||
# Build the TAGS file(s) for emacs
|
||||
#
|
||||
TAGS : TAGS.$(ARCH)
|
||||
TAGS :
|
||||
ctags -e -R -f $@ --exclude=bin
|
||||
|
||||
TAGS.$(ARCH) :
|
||||
ctags -e -R -f $@ --exclude=bin \
|
||||
$(foreach ARCH,$(OTHER_ARCHS),--exclude=arch/$(ARCH))
|
||||
CLEANUP += TAGS*
|
||||
CLEANUP += TAGS
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Force rebuild for any given target
|
||||
#
|
||||
%.rebuild :
|
||||
rm -f $*
|
||||
$(Q)$(MAKE) $*
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Symbol table checks
|
||||
#
|
||||
|
||||
ifdef BIN
|
||||
|
||||
SYMTAB = $(BIN)/symtab
|
||||
$(SYMTAB) : $(BLIB)
|
||||
$(OBJDUMP) -w -t $< > $@
|
||||
@@ -547,14 +801,27 @@ CLEANUP += $(BIN)/symtab
|
||||
symcheck : $(SYMTAB)
|
||||
$(SYMCHECK) $<
|
||||
|
||||
# Force rebuild for any given target
|
||||
#
|
||||
$(BIN)/%.rebuild :
|
||||
rm -f $(BIN)/$*
|
||||
$(MAKE) $(MAKEFLAGS) $(BIN)/$*
|
||||
endif # defined(BIN)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Build bochs symbol table
|
||||
#
|
||||
|
||||
ifdef BIN
|
||||
|
||||
$(BIN)/%.bxs : $(BIN)/%.tmp
|
||||
$(NM) $< | cut -d" " -f1,3 > $@
|
||||
|
||||
endif # defined(BIN)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Documentation
|
||||
#
|
||||
|
||||
ifdef BIN
|
||||
|
||||
$(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
|
||||
$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
|
||||
-e 's{\@BIN\@}{$(BIN)}; ' \
|
||||
@@ -578,6 +845,10 @@ docview :
|
||||
$(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
|
||||
fi
|
||||
|
||||
endif # defined(BIN)
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Clean-up
|
||||
#
|
||||
clean :
|
||||
@@ -585,19 +856,3 @@ clean :
|
||||
|
||||
veryclean : clean
|
||||
$(RM) -r $(VERYCLEANUP)
|
||||
|
||||
# Make clean tarballs for release
|
||||
|
||||
tarball : ../VERSION
|
||||
($(ECHO) -n $(VERSION) ''; date -u +'%Y-%m-%d') > ../VERSION
|
||||
$(RM) -r /tmp/$(USER)/gpxe-$(VERSION)
|
||||
mkdir -p /tmp/$(USER)/gpxe-$(VERSION)
|
||||
cp -rP .. /tmp/$(USER)/gpxe-$(VERSION)
|
||||
( cd /tmp/$(USER)/gpxe-$(VERSION)/src ; $(MAKE) veryclean ; $(RM) -r bin/deps )
|
||||
( cd /tmp/$(USER); tar cf /tmp/$(USER)/gpxe-$(VERSION).tar --exclude ".git*" --exclude "#*" \
|
||||
--exclude "*~" gpxe-$(VERSION) )
|
||||
bzip2 -9 < /tmp/$(USER)/gpxe-$(VERSION).tar > /tmp/$(USER)/gpxe-$(VERSION).tar.bz2
|
||||
gzip -9 < /tmp/$(USER)/gpxe-$(VERSION).tar > /tmp/$(USER)/gpxe-$(VERSION).tar.gz
|
||||
$(RM) -r /tmp/$(USER)/gpxe-$(VERSION)
|
||||
$(RM) /tmp/$(USER)/gpxe-$(VERSION).tar
|
||||
( cd /tmp/$(USER) ; tar -zxf /tmp/$(USER)/gpxe-$(VERSION).tar.gz )
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
Changes should be committed to the CVS HEAD only when they are in a
|
||||
working state. The definition of "working" is somewhat liquid; a good
|
||||
guiding principle is that anyone checking out HEAD should receive a
|
||||
checkout of working software.
|
||||
|
||||
When you want to work on changes that are likely to temporarily break
|
||||
large swathes of code, you should probably work on a private branch.
|
||||
Since CVS branching and merging is something of a black art, here are
|
||||
some simple step-by-step instructions for creating and using a branch.
|
||||
|
||||
To create your private branch:
|
||||
|
||||
# Get most up-to-date tree before branching
|
||||
cvs update
|
||||
# Create a branch called "my-branch"
|
||||
cvs tag -b my-branch
|
||||
# Switch working copy to the "my-branch" branch
|
||||
cvs update -r my-branch
|
||||
|
||||
At this point you'll be on a branch called "my-branch". Any changes
|
||||
you make will not affect people working on HEAD, or on other branches.
|
||||
|
||||
Use name for your branch that is both descriptive and unique.
|
||||
Starting the branch name with your SourceForge username
|
||||
(e.g. "mcb30-realmode-redesign") is a good idea.
|
||||
|
||||
When you want to merge the changes on your branch back into HEAD, do
|
||||
the following:
|
||||
|
||||
# Ensure there are no not-yet-checked-in modifications in your tree)
|
||||
cvs -q update
|
||||
# Tag the merge point in the "my-branch" branch
|
||||
cvs tag -c my-branch-merge-1
|
||||
# Switch working copy back to HEAD
|
||||
cvs update -A
|
||||
# Merge changes from the branch
|
||||
cvs update -j my-branch
|
||||
# Commit merged changes to HEAD
|
||||
cvs commit
|
||||
|
||||
If you then want to continue working further on the "my-branch" branch,
|
||||
do the following
|
||||
|
||||
# Switch working copy back to the "my-branch" branch
|
||||
cvs update -r my-branch
|
||||
|
||||
and then when you want to merge some more changes back to HEAD:
|
||||
|
||||
# Ensure there are no not-yet-checked-in modifications in your tree)
|
||||
cvs -q update
|
||||
# Tag the merge point in the "my-branch" branch
|
||||
cvs tag -c my-branch-merge-2
|
||||
# Switch working copy back to HEAD
|
||||
cvs update -A
|
||||
# Merge changes from the branch
|
||||
cvs update -j my-branch-merge-1 -j my-branch
|
||||
# Commit merged changes to HEAD
|
||||
cvs commit
|
||||
|
||||
Note that the format of the "merge changes from the branch" command has
|
||||
changed, because this time you need to only merge changes since the last
|
||||
merge point.
|
||||
|
||||
When you have finished with your branch and merged all the changes
|
||||
back to HEAD, simply stop using the branch.
|
||||
@@ -1,148 +0,0 @@
|
||||
# -*- makefile -*-
|
||||
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
#
|
||||
# IMPORTANT!
|
||||
#
|
||||
# The use of this file to set options that affect only single object
|
||||
# files is deprecated, because changing anything in this file results
|
||||
# in a complete rebuild, which is slow. All options are gradually
|
||||
# being migrated to config.h, which does not suffer from this problem.
|
||||
#
|
||||
# Only options that affect the entire build (e.g. overriding the $(CC)
|
||||
# Makefile variable) should be placed in here.
|
||||
#
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
|
||||
|
||||
# Config for i386 Etherboot
|
||||
#
|
||||
# Do not delete the tag OptionDescription and /OptionDescription
|
||||
# It is used to automatically generate the documentation.
|
||||
#
|
||||
# @OptionDescrition@
|
||||
#
|
||||
# BIOS interface options:
|
||||
#
|
||||
# -DPCBIOS
|
||||
# Compile in support for the normal pcbios
|
||||
# -DLINUXBIOS
|
||||
# Compile in support for LinuxBIOS
|
||||
# -DBBS_BUT_NOT_PNP_COMPLIANT
|
||||
# Some BIOSes claim to be PNP but they don't conform
|
||||
# to the BBS spec which specifies that ES:DI must
|
||||
# point to the string $PnP on entry. This option
|
||||
# works around those. This option must be added to
|
||||
# LCONFIG.
|
||||
# -DNO_DELAYED_INT
|
||||
# Take control as soon as BIOS detects the ROM.
|
||||
# Normally hooks onto INT18H or INT19H. Use only if you
|
||||
# have a very non-conformant BIOS as it bypasses
|
||||
# BIOS initialisation of devices. This only works for
|
||||
# legacy ROMs, i.e. PCI_PNP_HEADER not defined.
|
||||
# This option was formerly called NOINT19H.
|
||||
# -DBOOT_INT18H
|
||||
# Etherboot normally hooks onto INT19H for legacy ROMs.
|
||||
# You can choose to hook onto INT18H (BASIC interpreter
|
||||
# entry point) instead. This entry point is used when
|
||||
# all boot devices have been exhausted. This option must
|
||||
# be added to LCONFIG.
|
||||
# -DCONFIG_PCI_DIRECT
|
||||
# Define this for PCI BIOSes that do not implement
|
||||
# BIOS32 or not correctly. Normally not needed.
|
||||
# Only works for BIOSes of a certain era.
|
||||
# -DCONFIG_TSC_CURRTICKS
|
||||
# Uses the processor time stamp counter instead of reading
|
||||
# the BIOS time counter. This allows Etherboot to work
|
||||
# even without a BIOS. This only works on late model
|
||||
# 486s and above.
|
||||
# -DCONFIG_NO_TIMER2
|
||||
# Some systems do not have timer2 implemented.
|
||||
# If you have a RTC this will allow you to roughly calibrate
|
||||
# it using outb instructions.
|
||||
#
|
||||
# Extended cpu options
|
||||
|
||||
# -DCONFIG_X86_64
|
||||
# Compile in support for booting x86_64 64bit binaries.
|
||||
#
|
||||
# PXE loader options:
|
||||
#
|
||||
# -DPXELOADER_KEEP_ALL
|
||||
# Prevent PXE loader (prefix) from unloading the
|
||||
# PXE stack. You will want to use this if, for
|
||||
# example, you are booting via PXE-on-floppy.
|
||||
# You may want to use it under certain
|
||||
# circumstances when using the Etherboot UNDI
|
||||
# driver; these are complex and best practice is
|
||||
# not yet established.
|
||||
#
|
||||
# Obscure options you probably don't need to touch:
|
||||
#
|
||||
# -DIGNORE_E820_MAP
|
||||
# Ignore the memory map returned by the E820 BIOS
|
||||
# call. May be necessary on some buggy BIOSes.
|
||||
# -DT503_AUI
|
||||
# Use AUI by default on 3c503 cards.
|
||||
# -DFLATTEN_REAL_MODE
|
||||
# Use 4GB segment limits when calling out to or
|
||||
# returning to real-mode code. This is necessary to
|
||||
# work around some buggy code (e.g. OpenBSD's pxeboot)
|
||||
# that uses flat real-mode without being sufficiently
|
||||
# paranoid about the volatility of its segment limits.
|
||||
|
||||
#
|
||||
# @/OptionDescription@
|
||||
|
||||
# BIOS select don't change unless you know what you are doing
|
||||
# CFLAGS+= -DPCBIOS
|
||||
|
||||
# Compile in k8/hammer support
|
||||
# CFLAGS+= -DCONFIG_X86_64
|
||||
|
||||
# Options to make a version of Etherboot that will work under linuxBIOS.
|
||||
# CFLAGS+= -DLINUXBIOS -DCONFIG_TSC_CURRTICKS -DCONSOLE_SERIAL -DCOMCONSOLE=0x3f8 -DCOMPRESERVE -DCONFIG_PCI_DIRECT -DELF_IMAGE
|
||||
|
||||
# These options affect the loader that is prepended to the Etherboot image
|
||||
# LCONFIG+= -DBBS_BUT_NOT_PNP_COMPLIANT
|
||||
# LCONFIG+= -DBOOT_INT18H
|
||||
|
||||
# Produce code that will work with OpenBSD's pxeboot
|
||||
# CFLAGS+= -DFLATTEN_REAL_MODE
|
||||
|
||||
CFLAGS+= -fstrength-reduce -fomit-frame-pointer -march=i386
|
||||
# Squeeze the code in as little space as possible.
|
||||
# gcc3 needs a different syntax to gcc2 if you want to avoid spurious warnings.
|
||||
GCC_VERSION = $(subst ., ,$(shell $(CC) -dumpversion))
|
||||
GCC_MAJORVERSION = $(firstword $(GCC_VERSION))
|
||||
ifeq ($(GCC_MAJORVERSION),2)
|
||||
CFLAGS+= -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
else
|
||||
CFLAGS+= -falign-jumps=1 -falign-loops=1 -falign-functions=1
|
||||
endif
|
||||
|
||||
# this is almost always a win. the kernel uses it, too.
|
||||
CFLAGS+= -mpreferred-stack-boundary=2
|
||||
|
||||
# use regparm for all functions - C functions called from assembly (or
|
||||
# vice versa) need __cdecl now
|
||||
CFLAGS+= -mregparm=3
|
||||
|
||||
# use -mrtd (same __cdecl requirements as above)
|
||||
CFLAGS+= -mrtd
|
||||
|
||||
# this is the logical complement to -mregparm=3.
|
||||
# it doesn't currently buy us anything, but if anything ever tries
|
||||
# to return small structures, let's be prepared
|
||||
CFLAGS+= -freg-struct-return
|
||||
|
||||
LDFLAGS+= -N --no-check-sections
|
||||
|
||||
ifeq "$(shell uname -s)" "FreeBSD"
|
||||
CFLAGS+= -DIMAGE_FREEBSD -DELF_IMAGE -DAOUT_IMAGE
|
||||
endif
|
||||
|
||||
# An alternate location for isolinux.bin can be set here
|
||||
# ISOLINUX_BIN=/path/to/isolinux.bin
|
||||
+74
-66
@@ -1,3 +1,59 @@
|
||||
# Force i386-only instructions
|
||||
#
|
||||
CFLAGS += -march=i386
|
||||
|
||||
# Code size reduction.
|
||||
#
|
||||
CFLAGS += -fstrength-reduce -fomit-frame-pointer
|
||||
|
||||
# Code size reduction. gcc3 needs a different syntax to gcc2 if you
|
||||
# want to avoid spurious warnings.
|
||||
#
|
||||
GCC_VERSION := $(subst ., ,$(shell $(CC) -dumpversion))
|
||||
GCC_MAJOR := $(firstword $(GCC_VERSION))
|
||||
ifeq ($(GCC_MAJOR),2)
|
||||
CFLAGS += -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
else
|
||||
CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1
|
||||
endif
|
||||
|
||||
# Code size reduction. This is almost always a win. The kernel uses it, too.
|
||||
#
|
||||
CFLAGS += -mpreferred-stack-boundary=2
|
||||
|
||||
# Code size reduction. Use regparm for all functions - C functions
|
||||
# called from assembly (or vice versa) need __asmcall now
|
||||
#
|
||||
CFLAGS += -mregparm=3
|
||||
|
||||
# Code size reduction. Use -mrtd (same __asmcall requirements as above)
|
||||
CFLAGS += -mrtd
|
||||
|
||||
# Code size reduction. This is the logical complement to -mregparm=3.
|
||||
# It doesn't currently buy us anything, but if anything ever tries to
|
||||
# return small structures, let's be prepared
|
||||
#
|
||||
CFLAGS += -freg-struct-return
|
||||
|
||||
# Force 32-bit code even on an x86-64 machine
|
||||
#
|
||||
CFLAGS += -m32
|
||||
ASFLAGS += --32
|
||||
ifeq ($(HOST_OS),FreeBSD)
|
||||
LDFLAGS += -m elf_i386_fbsd
|
||||
else
|
||||
LDFLAGS += -m elf_i386
|
||||
endif
|
||||
|
||||
# EFI requires -fshort-wchar, and nothing else currently uses wchar_t
|
||||
#
|
||||
CFLAGS += -fshort-wchar
|
||||
|
||||
# We need to undefine the default macro "i386" when compiling .S
|
||||
# files, otherwise ".arch i386" translates to ".arch 1"...
|
||||
#
|
||||
CFLAGS += -Ui386
|
||||
|
||||
# Locations of utilities
|
||||
#
|
||||
ISOLINUX_BIN = /usr/lib/syslinux/isolinux.bin
|
||||
@@ -7,11 +63,11 @@ ISOLINUX_BIN = /usr/lib/syslinux/isolinux.bin
|
||||
SRCDIRS += arch/i386/core arch/i386/transitions arch/i386/prefix
|
||||
SRCDIRS += arch/i386/firmware/pcbios
|
||||
SRCDIRS += arch/i386/image
|
||||
SRCDIRS += arch/i386/drivers/bus
|
||||
SRCDIRS += arch/i386/drivers
|
||||
SRCDIRS += arch/i386/drivers/net
|
||||
SRCDIRS += arch/i386/drivers/disk
|
||||
SRCDIRS += arch/i386/interface/pcbios
|
||||
SRCDIRS += arch/i386/interface/pxe
|
||||
SRCDIRS += arch/i386/interface/syslinux
|
||||
|
||||
# The various xxx_loader.c files are #included into core/loader.c and
|
||||
# should not be compiled directly.
|
||||
@@ -22,85 +78,37 @@ NON_AUTO_SRCS += arch/i386/core/wince_loader.c
|
||||
|
||||
# unnrv2b.S is used to generate a 16-bit as well as a 32-bit object.
|
||||
#
|
||||
OBJS_unnrv2b = unnrv2b unnrv2b16
|
||||
CFLAGS_unnrv2b16 = -DCODE16
|
||||
OBJS_unnrv2b = unnrv2b unnrv2b16
|
||||
CFLAGS_unnrv2b16 = -DCODE16
|
||||
|
||||
# We need to undefine the default macro "i386" when compiling .S
|
||||
# files, otherwise ".arch i386" translates to ".arch 1"...
|
||||
# Include common x86 Makefile
|
||||
#
|
||||
CFLAGS_S += -Ui386
|
||||
MAKEDEPS += arch/x86/Makefile
|
||||
include arch/x86/Makefile
|
||||
|
||||
# The i386 linker script
|
||||
# Include platform-specific Makefile
|
||||
#
|
||||
LDSCRIPT = arch/i386/scripts/i386.lds
|
||||
|
||||
# Media types.
|
||||
#
|
||||
MEDIA += rom
|
||||
MEDIA += pxe
|
||||
MEDIA += kpxe
|
||||
MEDIA += elf
|
||||
MEDIA += elfd
|
||||
MEDIA += lmelf
|
||||
MEDIA += lmelfd
|
||||
MEDIA += lkrn
|
||||
MEDIA += bImage
|
||||
MEDIA += dsk
|
||||
MEDIA += nbi
|
||||
MEDIA += hd
|
||||
MEDIA += raw
|
||||
MEDIA += com
|
||||
MEDIA += exe
|
||||
|
||||
# Special target for building Master Boot Record binary
|
||||
$(BIN)/mbr.bin : $(BIN)/mbr.o
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
MAKEDEPS += arch/i386/Makefile.$(PLATFORM)
|
||||
include arch/i386/Makefile.$(PLATFORM)
|
||||
|
||||
# Some suffixes (e.g. %.fd0) are generated directly from other
|
||||
# finished files (e.g. %.dsk), rather than having their own prefix.
|
||||
|
||||
# rule to write disk images to /dev/fd0
|
||||
NON_AUTO_MEDIA += fd0
|
||||
NON_AUTO_MEDIA += fd0
|
||||
%fd0 : %dsk
|
||||
dd if=$< bs=512 conv=sync of=/dev/fd0
|
||||
sync
|
||||
$(QM)$(ECHO) " [DD] $@"
|
||||
$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
|
||||
$(Q)sync
|
||||
|
||||
# rule to create padded disk images
|
||||
NON_AUTO_MEDIA += pdsk
|
||||
NON_AUTO_MEDIA += pdsk
|
||||
%pdsk : %dsk
|
||||
cp $< $@
|
||||
$(PERL) ./util/dskpad.pl $@
|
||||
|
||||
# rule to make a non-emulation ISO boot image
|
||||
NON_AUTO_MEDIA += iso
|
||||
%iso: %lkrn util/geniso
|
||||
ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
|
||||
|
||||
# rule to make a floppy emulation ISO boot image
|
||||
NON_AUTO_MEDIA += liso
|
||||
%liso: %lkrn util/genliso
|
||||
bash util/genliso $@ $<
|
||||
|
||||
# rule to make a USB disk image
|
||||
$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
NON_AUTO_MEDIA += usb
|
||||
%usb: $(BIN)/usbdisk.bin %hd
|
||||
cat $^ > $@
|
||||
$(QM)$(ECHO) " [DSKPAD] $@"
|
||||
$(Q)cp $< $@
|
||||
$(Q)$(PERL) ./util/dskpad.pl $@
|
||||
|
||||
# Add NON_AUTO_MEDIA to the media list, so that they show up in the
|
||||
# output of "make"
|
||||
#
|
||||
MEDIA += $(NON_AUTO_MEDIA)
|
||||
|
||||
# Shortcut to allow typing just
|
||||
# make bin-kir/%
|
||||
# rather than
|
||||
# make -f arch/i386/kir-Makefile bin-kir/%
|
||||
# for building a KEEP_IT_REAL flavour.
|
||||
#
|
||||
$(BIN)-kir/% : kir-target
|
||||
$(MAKE) -f arch/i386/kir-Makefile $(MAKECMDGOALS)
|
||||
|
||||
.PHONY : kir-target
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
# Specify EFI image builder
|
||||
#
|
||||
ELF2EFI = $(ELF2EFI32)
|
||||
|
||||
# Include generic EFI Makefile
|
||||
#
|
||||
MAKEDEPS += arch/x86/Makefile.efi
|
||||
include arch/x86/Makefile.efi
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
# The i386 linker script
|
||||
#
|
||||
LDSCRIPT = arch/i386/scripts/i386.lds
|
||||
|
||||
# Stop ld from complaining about our customised linker script
|
||||
#
|
||||
LDFLAGS += -N --no-check-sections
|
||||
|
||||
# Media types.
|
||||
#
|
||||
MEDIA += rom
|
||||
MEDIA += pxe
|
||||
MEDIA += kpxe
|
||||
MEDIA += kkpxe
|
||||
MEDIA += elf
|
||||
MEDIA += elfd
|
||||
MEDIA += lmelf
|
||||
MEDIA += lmelfd
|
||||
MEDIA += lkrn
|
||||
MEDIA += bImage
|
||||
MEDIA += dsk
|
||||
MEDIA += nbi
|
||||
MEDIA += hd
|
||||
MEDIA += raw
|
||||
MEDIA += com
|
||||
MEDIA += exe
|
||||
|
||||
# rule to make a non-emulation ISO boot image
|
||||
NON_AUTO_MEDIA += iso
|
||||
%iso: %lkrn util/geniso
|
||||
$(QM)$(ECHO) " [GENISO] $@"
|
||||
$(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
|
||||
|
||||
# rule to make a floppy emulation ISO boot image
|
||||
NON_AUTO_MEDIA += liso
|
||||
%liso: %lkrn util/genliso
|
||||
$(QM)$(ECHO) " [GENLISO] $@"
|
||||
$(Q)bash util/genliso $@ $<
|
||||
|
||||
# Special target for building Master Boot Record binary
|
||||
$(BIN)/mbr.bin : $(BIN)/mbr.o
|
||||
$(QM)$(ECHO) " [OBJCOPY] $@"
|
||||
$(Q)$(OBJCOPY) -O binary $< $@
|
||||
|
||||
# rule to make a USB disk image
|
||||
$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
|
||||
$(QM)$(ECHO) " [OBJCOPY] $@"
|
||||
$(Q)$(OBJCOPY) -O binary $< $@
|
||||
|
||||
NON_AUTO_MEDIA += usb
|
||||
%usb: $(BIN)/usbdisk.bin %hd
|
||||
$(QM)$(ECHO) " [FINISH] $@"
|
||||
$(Q)cat $^ > $@
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <realmode.h>
|
||||
|
||||
void __asmcall _dump_regs ( struct i386_all_regs *ix86 ) {
|
||||
|
||||
__asm__ __volatile__ (
|
||||
TEXT16_CODE ( ".globl dump_regs\n\t"
|
||||
"\ndump_regs:\n\t"
|
||||
"pushl $_dump_regs\n\t"
|
||||
"pushw %%cs\n\t"
|
||||
"call prot_call\n\t"
|
||||
"addr32 leal 4(%%esp), %%esp\n\t"
|
||||
"ret\n\t" ) : : );
|
||||
|
||||
printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
|
||||
"ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
|
||||
"CS=%04x SS=%04x DS=%04x ES=%04x FS=%04x GS=%04x\n",
|
||||
ix86->regs.eax, ix86->regs.ebx, ix86->regs.ecx,
|
||||
ix86->regs.edx, ix86->regs.esi, ix86->regs.edi,
|
||||
ix86->regs.ebp, ix86->regs.esp,
|
||||
ix86->segs.cs, ix86->segs.ss, ix86->segs.ds,
|
||||
ix86->segs.es, ix86->segs.fs, ix86->segs.gs );
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Interrupt Descriptor Table (IDT) setup and interrupt handlers for GDB stub.
|
||||
*/
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
#define SIZEOF_I386_REGS 32
|
||||
#define SIZEOF_I386_FLAGS 4
|
||||
|
||||
/****************************************************************************
|
||||
* Interrupt Descriptor Table
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".data16", "aw", @progbits
|
||||
.globl idtr
|
||||
idtr:
|
||||
idt_limit:
|
||||
.word idt_length - 1
|
||||
idt_base:
|
||||
.long 0
|
||||
|
||||
/* IDT entries have the following format:
|
||||
* offset_lo, segment selector, flags, offset_hi
|
||||
*
|
||||
* Since it is not possible to specify relocations in arbitrary
|
||||
* expressions like (int_overflow & 0xffff), we initialise the
|
||||
* IDT with entries in an incorrect format.
|
||||
*
|
||||
* The entries are shuffled into the correct format in init_librm().
|
||||
*/
|
||||
#define IDT_ENTRY_EMPTY(name) .word 0, 0, 0, 0
|
||||
#define IDT_ENTRY_PRESENT(name) \
|
||||
.long int_##name; \
|
||||
.word 0x8e00, VIRTUAL_CS
|
||||
|
||||
.align 16
|
||||
idt:
|
||||
IDT_ENTRY_PRESENT(divide_error)
|
||||
IDT_ENTRY_PRESENT(debug_trap)
|
||||
IDT_ENTRY_EMPTY(non_maskable_interrupt)
|
||||
IDT_ENTRY_PRESENT(breakpoint)
|
||||
IDT_ENTRY_PRESENT(overflow)
|
||||
IDT_ENTRY_PRESENT(bound_range_exceeded)
|
||||
IDT_ENTRY_PRESENT(invalid_opcode)
|
||||
IDT_ENTRY_EMPTY(device_not_available)
|
||||
IDT_ENTRY_PRESENT(double_fault)
|
||||
IDT_ENTRY_EMPTY(coprocessor_segment_overrun)
|
||||
IDT_ENTRY_PRESENT(invalid_tss)
|
||||
IDT_ENTRY_PRESENT(segment_not_present)
|
||||
IDT_ENTRY_PRESENT(stack_segment_fault)
|
||||
IDT_ENTRY_PRESENT(general_protection)
|
||||
IDT_ENTRY_PRESENT(page_fault)
|
||||
idt_end:
|
||||
.equ idt_length, idt_end - idt
|
||||
|
||||
/* The IDT entries are fixed up (once) in init_librm() */
|
||||
idt_fixed:
|
||||
.byte 0
|
||||
|
||||
/****************************************************************************
|
||||
* idt_init (real-mode near call, 16-bit real-mode near return address)
|
||||
*
|
||||
* Initialise the IDT, called from init_librm.
|
||||
*
|
||||
* Parameters:
|
||||
* %eax : IDT base address
|
||||
*
|
||||
* Destroys %ax, %bx, and %di.
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16", "ax", @progbits
|
||||
.code16
|
||||
.globl idt_init
|
||||
idt_init:
|
||||
movl %eax, idt_base
|
||||
addl $idt, idt_base
|
||||
|
||||
/* IDT entries are only fixed up once */
|
||||
movb idt_fixed, %al
|
||||
orb %al, %al
|
||||
jnz 2f
|
||||
movb $1, idt_fixed
|
||||
|
||||
/* Shuffle IDT entries into the correct format */
|
||||
movb $(idt_length / 8), %al
|
||||
movw $idt, %bx
|
||||
or %al, %al
|
||||
jz 2f
|
||||
1:
|
||||
movw 2(%bx), %di
|
||||
xchg %di, 6(%bx)
|
||||
movw %di, 2(%bx)
|
||||
addw $8, %bx
|
||||
dec %al
|
||||
jnz 1b
|
||||
2:
|
||||
ret
|
||||
|
||||
/****************************************************************************
|
||||
* Interrupt handlers
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text", "ax", @progbits
|
||||
.code32
|
||||
|
||||
/* POSIX signal numbers for reporting traps to GDB */
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGBUS 7
|
||||
#define SIGFPE 8
|
||||
#define SIGSEGV 11
|
||||
#define SIGSTKFLT 16
|
||||
|
||||
int_divide_error:
|
||||
pushl $SIGFPE
|
||||
jmp do_interrupt
|
||||
|
||||
int_debug_trap:
|
||||
int_breakpoint:
|
||||
pushl $SIGTRAP
|
||||
jmp do_interrupt
|
||||
|
||||
int_overflow:
|
||||
int_bound_range_exceeded:
|
||||
pushl $SIGSTKFLT
|
||||
jmp do_interrupt
|
||||
|
||||
int_invalid_opcode:
|
||||
pushl $SIGILL
|
||||
jmp do_interrupt
|
||||
|
||||
int_double_fault:
|
||||
movl $SIGBUS, (%esp)
|
||||
jmp do_interrupt
|
||||
|
||||
int_invalid_tss:
|
||||
int_segment_not_present:
|
||||
int_stack_segment_fault:
|
||||
int_general_protection:
|
||||
int_page_fault:
|
||||
movl $SIGSEGV, (%esp)
|
||||
jmp do_interrupt
|
||||
|
||||
/* When invoked, the stack contains: eflags, cs, eip, signo. */
|
||||
#define IH_OFFSET_GDB_REGS ( 0 )
|
||||
#define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
|
||||
#define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
|
||||
#define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
|
||||
#define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
|
||||
#define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
|
||||
#define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
|
||||
#define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
|
||||
#define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
|
||||
#define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
|
||||
|
||||
/* We also access the stack whilst still storing or restoring
|
||||
* the register snapshot. Since ESP is in flux, we need
|
||||
* special offsets.
|
||||
*/
|
||||
#define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
|
||||
#define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
|
||||
#define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
|
||||
#define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
|
||||
do_interrupt:
|
||||
/* Store CPU state in GDB register snapshot */
|
||||
pushw $0
|
||||
pushw %gs
|
||||
pushw $0
|
||||
pushw %fs
|
||||
pushw $0
|
||||
pushw %es
|
||||
pushw $0
|
||||
pushw %ds
|
||||
pushw $0
|
||||
pushw %ss
|
||||
pushw $0
|
||||
pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
|
||||
pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
|
||||
pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
|
||||
pushl %edi
|
||||
pushl %esi
|
||||
pushl %ebp
|
||||
leal IH_OFFSET_FLUX_END(%esp), %edi
|
||||
pushl %edi /* old ESP */
|
||||
pushl %ebx
|
||||
pushl %edx
|
||||
pushl %ecx
|
||||
pushl %eax
|
||||
|
||||
/* Call GDB stub exception handler */
|
||||
pushl %esp
|
||||
pushl (IH_OFFSET_SIGNO + 4)(%esp)
|
||||
call gdbmach_handler
|
||||
addl $8, %esp
|
||||
|
||||
/* Restore CPU state from GDB register snapshot */
|
||||
popl %eax
|
||||
popl %ecx
|
||||
popl %edx
|
||||
popl %ebx
|
||||
addl $4, %esp /* Changing ESP currently not supported */
|
||||
popl %ebp
|
||||
popl %esi
|
||||
popl %edi
|
||||
popl IH_OFFSET_FLUX_OLD_EIP(%esp)
|
||||
popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
|
||||
popl IH_OFFSET_FLUX_OLD_CS(%esp)
|
||||
popl %ss
|
||||
popl %ds
|
||||
popl %es
|
||||
popl %fs
|
||||
popl %gs
|
||||
|
||||
addl $4, %esp /* drop signo */
|
||||
iret
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/gdbstub.h>
|
||||
#include <gdbmach.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* GDB architecture-specific bits for i386
|
||||
*
|
||||
*/
|
||||
|
||||
enum {
|
||||
DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
|
||||
DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
|
||||
};
|
||||
|
||||
/** Hardware breakpoint, fields stored in x86 bit pattern form */
|
||||
struct hwbp {
|
||||
int type; /* type (1=write watchpoint, 3=access watchpoint) */
|
||||
unsigned long addr; /* linear address */
|
||||
size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
|
||||
int enabled;
|
||||
};
|
||||
|
||||
static struct hwbp hwbps [ 4 ];
|
||||
static gdbreg_t dr7 = DR7_CLEAR;
|
||||
|
||||
static struct hwbp *gdbmach_find_hwbp ( int type, unsigned long addr, size_t len ) {
|
||||
struct hwbp *available = NULL;
|
||||
unsigned int i;
|
||||
for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) {
|
||||
if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) {
|
||||
return &hwbps [ i ];
|
||||
}
|
||||
if ( !hwbps [ i ].enabled ) {
|
||||
available = &hwbps [ i ];
|
||||
}
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
static void gdbmach_commit_hwbp ( struct hwbp *bp ) {
|
||||
unsigned int regnum = bp - hwbps;
|
||||
|
||||
/* Set breakpoint address */
|
||||
assert ( regnum < ( sizeof hwbps / sizeof hwbps [ 0 ] ) );
|
||||
switch ( regnum ) {
|
||||
case 0:
|
||||
__asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) );
|
||||
break;
|
||||
case 1:
|
||||
__asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) );
|
||||
break;
|
||||
case 2:
|
||||
__asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) );
|
||||
break;
|
||||
case 3:
|
||||
__asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set type */
|
||||
dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) );
|
||||
dr7 |= bp->type << ( 16 + 4 * regnum );
|
||||
|
||||
/* Set length */
|
||||
dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) );
|
||||
dr7 |= bp->len << ( 18 + 4 * regnum );
|
||||
|
||||
/* Set/clear local enable bit */
|
||||
dr7 &= ~( 0x3 << 2 * regnum );
|
||||
dr7 |= bp->enabled << 2 * regnum;
|
||||
}
|
||||
|
||||
int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ) {
|
||||
struct hwbp *bp;
|
||||
|
||||
/* Check and convert breakpoint type to x86 type */
|
||||
switch ( type ) {
|
||||
case GDBMACH_WATCH:
|
||||
type = 0x1;
|
||||
break;
|
||||
case GDBMACH_AWATCH:
|
||||
type = 0x3;
|
||||
break;
|
||||
default:
|
||||
return 0; /* unsupported breakpoint type */
|
||||
}
|
||||
|
||||
/* Only lengths 1, 2, and 4 are supported */
|
||||
if ( len != 2 && len != 4 ) {
|
||||
len = 1;
|
||||
}
|
||||
len--; /* convert to x86 breakpoint length bit pattern */
|
||||
|
||||
/* Calculate linear address by adding segment base */
|
||||
addr += virt_offset;
|
||||
|
||||
/* Set up the breakpoint */
|
||||
bp = gdbmach_find_hwbp ( type, addr, len );
|
||||
if ( !bp ) {
|
||||
return 0; /* ran out of hardware breakpoints */
|
||||
}
|
||||
bp->type = type;
|
||||
bp->addr = addr;
|
||||
bp->len = len;
|
||||
bp->enabled = enable;
|
||||
gdbmach_commit_hwbp ( bp );
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void gdbmach_disable_hwbps ( void ) {
|
||||
/* Store and clear hardware breakpoints */
|
||||
__asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) );
|
||||
}
|
||||
|
||||
static void gdbmach_enable_hwbps ( void ) {
|
||||
/* Clear breakpoint status register */
|
||||
__asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) );
|
||||
|
||||
/* Restore hardware breakpoints */
|
||||
__asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) );
|
||||
}
|
||||
|
||||
__asmcall void gdbmach_handler ( int signo, gdbreg_t *regs ) {
|
||||
gdbmach_disable_hwbps();
|
||||
gdbstub_handler ( signo, regs );
|
||||
gdbmach_enable_hwbps();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <console.h>
|
||||
#include <realmode.h>
|
||||
|
||||
extern char __text[];
|
||||
extern char __rodata[];
|
||||
extern char __data[];
|
||||
extern char __bss[];
|
||||
extern char __text16[];
|
||||
extern char __data16[];
|
||||
|
||||
|
||||
static void gdb_symbol_line ( void ) {
|
||||
printf ( "Commands to start up gdb:\n\n" );
|
||||
printf ( "gdb\n" );
|
||||
printf ( "target remote localhost:1234\n" );
|
||||
printf ( "set confirm off\n" );
|
||||
printf ( "add-symbol-file symbols %#lx", virt_to_phys ( __text ) );
|
||||
printf ( " -s .rodata %#lx", virt_to_phys ( __rodata ) );
|
||||
printf ( " -s .data %#lx", virt_to_phys ( __data ) );
|
||||
printf ( " -s .bss %#lx", virt_to_phys ( __bss ) );
|
||||
printf ( " -s .text16 %#x", ( ( rm_cs << 4 ) + (int)__text16 ) );
|
||||
printf ( " -s .data16 %#x", ( ( rm_ds << 4 ) + (int)__data16 ) );
|
||||
printf ( "\n" );
|
||||
printf ( "add-symbol-file symbols 0\n" );
|
||||
printf ( "set confirm on\n" );
|
||||
getkey();
|
||||
}
|
||||
|
||||
struct startup_fn gdb_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
|
||||
.startup = gdb_symbol_line,
|
||||
};
|
||||
@@ -1,196 +0,0 @@
|
||||
/* A couple of routines to implement a low-overhead timer for drivers */
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#include "timer.h"
|
||||
#include "latch.h"
|
||||
#include <io.h>
|
||||
#include <gpxe/init.h>
|
||||
|
||||
void __load_timer2(unsigned int ticks)
|
||||
{
|
||||
/*
|
||||
* Now let's take care of PPC channel 2
|
||||
*
|
||||
* Set the Gate high, program PPC channel 2 for mode 0,
|
||||
* (interrupt on terminal count mode), binary count,
|
||||
* load 5 * LATCH count, (LSB and MSB) to begin countdown.
|
||||
*
|
||||
* Note some implementations have a bug where the high bits byte
|
||||
* of channel 2 is ignored.
|
||||
*/
|
||||
/* Set up the timer gate, turn off the speaker */
|
||||
/* Set the Gate high, disable speaker */
|
||||
outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB);
|
||||
/* binary, mode 0, LSB/MSB, Ch 2 */
|
||||
outb(TIMER2_SEL|WORD_ACCESS|MODE0|BINARY_COUNT, TIMER_MODE_PORT);
|
||||
/* LSB of ticks */
|
||||
outb(ticks & 0xFF, TIMER2_PORT);
|
||||
/* MSB of ticks */
|
||||
outb(ticks >> 8, TIMER2_PORT);
|
||||
}
|
||||
|
||||
static int __timer2_running(void)
|
||||
{
|
||||
return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_TSC_CURRTICKS)
|
||||
static void setup_timers(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void load_timer2(unsigned int ticks)
|
||||
{
|
||||
return __load_timer2(ticks);
|
||||
}
|
||||
|
||||
int timer2_running(void)
|
||||
{
|
||||
return __timer2_running();
|
||||
}
|
||||
|
||||
void ndelay(unsigned int nsecs)
|
||||
{
|
||||
waiton_timer2((nsecs * CLOCK_TICK_RATE)/1000000000);
|
||||
}
|
||||
void udelay(unsigned int usecs)
|
||||
{
|
||||
waiton_timer2((usecs * TICKS_PER_MS)/1000);
|
||||
}
|
||||
#endif /* !defined(CONFIG_TSC_CURRTICKS) */
|
||||
|
||||
#if defined(CONFIG_TSC_CURRTICKS)
|
||||
|
||||
#define rdtsc(low,high) \
|
||||
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
|
||||
|
||||
#define rdtscll(val) \
|
||||
__asm__ __volatile__ ("rdtsc" : "=A" (val))
|
||||
|
||||
|
||||
/* Number of clock ticks to time with the rtc */
|
||||
#define LATCH 0xFF
|
||||
|
||||
#define LATCHES_PER_SEC ((CLOCK_TICK_RATE + (LATCH/2))/LATCH)
|
||||
#define TICKS_PER_LATCH ((LATCHES_PER_SEC + (TICKS_PER_SEC/2))/TICKS_PER_SEC)
|
||||
|
||||
static void sleep_latch(void)
|
||||
{
|
||||
__load_timer2(LATCH);
|
||||
while(__timer2_running());
|
||||
}
|
||||
|
||||
/* ------ Calibrate the TSC -------
|
||||
* Time how long it takes to excute a loop that runs in known time.
|
||||
* And find the convertion needed to get to CLOCK_TICK_RATE
|
||||
*/
|
||||
|
||||
|
||||
static unsigned long long calibrate_tsc(void)
|
||||
{
|
||||
unsigned long startlow, starthigh;
|
||||
unsigned long endlow, endhigh;
|
||||
|
||||
rdtsc(startlow,starthigh);
|
||||
sleep_latch();
|
||||
rdtsc(endlow,endhigh);
|
||||
|
||||
/* 64-bit subtract - gcc just messes up with long longs */
|
||||
__asm__("subl %2,%0\n\t"
|
||||
"sbbl %3,%1"
|
||||
:"=a" (endlow), "=d" (endhigh)
|
||||
:"g" (startlow), "g" (starthigh),
|
||||
"0" (endlow), "1" (endhigh));
|
||||
|
||||
/* Error: ECPUTOOFAST */
|
||||
if (endhigh)
|
||||
goto bad_ctc;
|
||||
|
||||
endlow *= TICKS_PER_LATCH;
|
||||
return endlow;
|
||||
|
||||
/*
|
||||
* The CTC wasn't reliable: we got a hit on the very first read,
|
||||
* or the CPU was so fast/slow that the quotient wouldn't fit in
|
||||
* 32 bits..
|
||||
*/
|
||||
bad_ctc:
|
||||
printf("bad_ctc\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long clocks_per_tick;
|
||||
static void setup_timers(void)
|
||||
{
|
||||
if (!clocks_per_tick) {
|
||||
clocks_per_tick = calibrate_tsc();
|
||||
/* Display the CPU Mhz to easily test if the calibration was bad */
|
||||
printf("CPU %ld Mhz\n", (clocks_per_tick/1000 * TICKS_PER_SEC)/1000);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long currticks(void)
|
||||
{
|
||||
unsigned long clocks_high, clocks_low;
|
||||
unsigned long currticks;
|
||||
/* Read the Time Stamp Counter */
|
||||
rdtsc(clocks_low, clocks_high);
|
||||
|
||||
/* currticks = clocks / clocks_per_tick; */
|
||||
__asm__("divl %1"
|
||||
:"=a" (currticks)
|
||||
:"r" (clocks_per_tick), "0" (clocks_low), "d" (clocks_high));
|
||||
|
||||
|
||||
return currticks;
|
||||
}
|
||||
|
||||
static unsigned long long timer_timeout;
|
||||
static int __timer_running(void)
|
||||
{
|
||||
unsigned long long now;
|
||||
rdtscll(now);
|
||||
return now < timer_timeout;
|
||||
}
|
||||
|
||||
void udelay(unsigned int usecs)
|
||||
{
|
||||
unsigned long long now;
|
||||
rdtscll(now);
|
||||
timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
|
||||
while(__timer_running());
|
||||
}
|
||||
void ndelay(unsigned int nsecs)
|
||||
{
|
||||
unsigned long long now;
|
||||
rdtscll(now);
|
||||
timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
|
||||
while(__timer_running());
|
||||
}
|
||||
|
||||
void load_timer2(unsigned int timer2_ticks)
|
||||
{
|
||||
unsigned long long now;
|
||||
unsigned long clocks;
|
||||
rdtscll(now);
|
||||
clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
|
||||
timer_timeout = now + clocks;
|
||||
}
|
||||
|
||||
int timer2_running(void)
|
||||
{
|
||||
return __timer_running();
|
||||
}
|
||||
|
||||
#endif /* RTC_CURRTICKS */
|
||||
|
||||
struct init_fn timer_init_fn __init_fn ( INIT_NORMAL ) = {
|
||||
.initialise = setup_timers,
|
||||
};
|
||||
@@ -16,6 +16,7 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <gpxe/io.h>
|
||||
#include <pic8259.h>
|
||||
|
||||
/** @file
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
*
|
||||
* RDTSC timer
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <gpxe/timer.h>
|
||||
#include <gpxe/timer2.h>
|
||||
|
||||
/**
|
||||
* Number of TSC ticks per microsecond
|
||||
*
|
||||
* This is calibrated on the first use of the timer.
|
||||
*/
|
||||
static unsigned long rdtsc_ticks_per_usec;
|
||||
|
||||
/**
|
||||
* Delay for a fixed number of microseconds
|
||||
*
|
||||
* @v usecs Number of microseconds for which to delay
|
||||
*/
|
||||
static void rdtsc_udelay ( unsigned long usecs ) {
|
||||
unsigned long start;
|
||||
unsigned long elapsed;
|
||||
|
||||
/* Sanity guard, since we may divide by this */
|
||||
if ( ! usecs )
|
||||
usecs = 1;
|
||||
|
||||
start = currticks();
|
||||
if ( rdtsc_ticks_per_usec ) {
|
||||
/* Already calibrated; busy-wait until done */
|
||||
do {
|
||||
elapsed = ( currticks() - start );
|
||||
} while ( elapsed < ( usecs * rdtsc_ticks_per_usec ) );
|
||||
} else {
|
||||
/* Not yet calibrated; use timer2 and calibrate
|
||||
* based on result.
|
||||
*/
|
||||
timer2_udelay ( usecs );
|
||||
elapsed = ( currticks() - start );
|
||||
rdtsc_ticks_per_usec = ( elapsed / usecs );
|
||||
DBG ( "RDTSC timer calibrated: %ld ticks in %ld usecs "
|
||||
"(%ld MHz)\n", elapsed, usecs,
|
||||
( rdtsc_ticks_per_usec << TSC_SHIFT ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of ticks per second
|
||||
*
|
||||
* @ret ticks_per_sec Number of ticks per second
|
||||
*/
|
||||
static unsigned long rdtsc_ticks_per_sec ( void ) {
|
||||
|
||||
/* Calibrate timer, if not already done */
|
||||
if ( ! rdtsc_ticks_per_usec )
|
||||
udelay ( 1 );
|
||||
|
||||
/* Sanity check */
|
||||
assert ( rdtsc_ticks_per_usec != 0 );
|
||||
|
||||
return ( rdtsc_ticks_per_usec * 1000 * 1000 );
|
||||
}
|
||||
|
||||
PROVIDE_TIMER ( rdtsc, udelay, rdtsc_udelay );
|
||||
PROVIDE_TIMER_INLINE ( rdtsc, currticks );
|
||||
PROVIDE_TIMER ( rdtsc, ticks_per_sec, rdtsc_ticks_per_sec );
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <io.h>
|
||||
#include <gpxe/io.h>
|
||||
#include <registers.h>
|
||||
#include <gpxe/memmap.h>
|
||||
|
||||
@@ -18,8 +18,8 @@ extern char _max_align[];
|
||||
#define max_align ( ( unsigned int ) _max_align )
|
||||
|
||||
/* Linker symbols */
|
||||
extern char _text[];
|
||||
extern char _end[];
|
||||
extern char _textdata[];
|
||||
extern char _etextdata[];
|
||||
|
||||
/* within 1MB of 4GB is too close.
|
||||
* MAX_ADDR is the maximum address we can easily do DMA to.
|
||||
@@ -39,7 +39,7 @@ extern char _end[];
|
||||
* address space, and returns the physical address of the new location
|
||||
* to the prefix in %edi.
|
||||
*/
|
||||
__cdecl void relocate ( struct i386_all_regs *ix86 ) {
|
||||
__asmcall void relocate ( struct i386_all_regs *ix86 ) {
|
||||
struct memory_map memmap;
|
||||
unsigned long start, end, size, padded_size;
|
||||
unsigned long new_start, new_end;
|
||||
@@ -47,8 +47,8 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
|
||||
|
||||
/* Get memory map and current location */
|
||||
get_memmap ( &memmap );
|
||||
start = virt_to_phys ( _text );
|
||||
end = virt_to_phys ( _end );
|
||||
start = virt_to_phys ( _textdata );
|
||||
end = virt_to_phys ( _etextdata );
|
||||
size = ( end - start );
|
||||
padded_size = ( size + max_align - 1 );
|
||||
|
||||
@@ -93,11 +93,16 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
|
||||
/* If last byte that might be used (r_end-1)
|
||||
* is in an odd megabyte, round down r_end to
|
||||
* the top of the next even megabyte.
|
||||
*
|
||||
* Make sure that we don't accidentally wrap
|
||||
* r_end below 0.
|
||||
*/
|
||||
r_end = ( r_end - 1 ) & ~0xfffff;
|
||||
DBG ( "...end truncated to %lx "
|
||||
"(avoid ending in odd megabyte)\n",
|
||||
r_end );
|
||||
if ( r_end >= 1 ) {
|
||||
r_end = ( r_end - 1 ) & ~0xfffff;
|
||||
DBG ( "...end truncated to %lx "
|
||||
"(avoid ending in odd megabyte)\n",
|
||||
r_end );
|
||||
}
|
||||
} else if ( ( r_end - size ) & 0x100000 ) {
|
||||
/* If the last byte that might be used
|
||||
* (r_end-1) is in an even megabyte, but the
|
||||
@@ -108,7 +113,7 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
|
||||
* Make sure that we don't accidentally wrap
|
||||
* r_end below 0.
|
||||
*/
|
||||
if ( r_end > 0x100000 ) {
|
||||
if ( r_end >= 0x100000 ) {
|
||||
r_end = ( r_end - 0x100000 ) & ~0xfffff;
|
||||
DBG ( "...end truncated to %lx "
|
||||
"(avoid starting in odd megabyte)\n",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Internal stack
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".stack"
|
||||
.section ".stack", "aw", @nobits
|
||||
.align 8
|
||||
.globl _stack
|
||||
_stack:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Internal stack
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".stack16"
|
||||
.section ".stack16", "aw", @nobits
|
||||
.align 8
|
||||
.globl _stack16
|
||||
_stack16:
|
||||
|
||||
@@ -1,325 +0,0 @@
|
||||
#include "virtaddr.h"
|
||||
|
||||
.equ MSR_K6_EFER, 0xC0000080
|
||||
.equ EFER_LME, 0x00000100
|
||||
.equ X86_CR4_PAE, 0x00000020
|
||||
.equ CR0_PG, 0x80000000
|
||||
|
||||
#ifdef GAS291
|
||||
#define DATA32 data32;
|
||||
#define ADDR32 addr32;
|
||||
#define LJMPI(x) ljmp x
|
||||
#else
|
||||
#define DATA32 data32
|
||||
#define ADDR32 addr32
|
||||
/* newer GAS295 require #define LJMPI(x) ljmp *x */
|
||||
#define LJMPI(x) ljmp x
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NOTE: if you write a subroutine that is called from C code (gcc/egcs),
|
||||
* then you only have to take care of %ebx, %esi, %edi and %ebp. These
|
||||
* registers must not be altered under any circumstance. All other registers
|
||||
* may be clobbered without any negative side effects. If you don't follow
|
||||
* this rule then you'll run into strange effects that only occur on some
|
||||
* gcc versions (because the register allocator may use different registers).
|
||||
*
|
||||
* All the data32 prefixes for the ljmp instructions are necessary, because
|
||||
* the assembler emits code with a relocation address of 0. This means that
|
||||
* all destinations are initially negative, which the assembler doesn't grok,
|
||||
* because for some reason negative numbers don't fit into 16 bits. The addr32
|
||||
* prefixes are there for the same reasons, because otherwise the memory
|
||||
* references are only 16 bit wide. Theoretically they are all superfluous.
|
||||
* One last note about prefixes: the data32 prefixes on all call _real_to_prot
|
||||
* instructions could be removed if the _real_to_prot function is changed to
|
||||
* deal correctly with 16 bit return addresses. I tried it, but failed.
|
||||
*/
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.code32
|
||||
|
||||
/* This is a struct os_entry_regs */
|
||||
.globl os_regs
|
||||
os_regs: .space 56
|
||||
|
||||
/**************************************************************************
|
||||
XSTART32 - Transfer control to the kernel just loaded
|
||||
**************************************************************************/
|
||||
.globl xstart32
|
||||
xstart32:
|
||||
/* Save the callee save registers */
|
||||
movl %ebp, os_regs + 32
|
||||
movl %esi, os_regs + 36
|
||||
movl %edi, os_regs + 40
|
||||
movl %ebx, os_regs + 44
|
||||
|
||||
/* save the return address */
|
||||
popl %eax
|
||||
movl %eax, os_regs + 48
|
||||
|
||||
/* save the stack pointer */
|
||||
movl %esp, os_regs + 52
|
||||
|
||||
/* Get the new destination address */
|
||||
popl %ecx
|
||||
|
||||
/* Store the physical address of xend on the stack */
|
||||
movl $xend32, %ebx
|
||||
addl virt_offset, %ebx
|
||||
pushl %ebx
|
||||
|
||||
/* Store the destination address on the stack */
|
||||
pushl $PHYSICAL_CS
|
||||
pushl %ecx
|
||||
|
||||
/* Cache virt_offset */
|
||||
movl virt_offset, %ebp
|
||||
|
||||
/* Switch to using physical addresses */
|
||||
call _virt_to_phys
|
||||
|
||||
/* Save the target stack pointer */
|
||||
movl %esp, os_regs + 12(%ebp)
|
||||
leal os_regs(%ebp), %esp
|
||||
|
||||
/* Store the pointer to os_regs */
|
||||
movl %esp, os_regs_ptr(%ebp)
|
||||
|
||||
/* Load my new registers */
|
||||
popal
|
||||
movl (-32 + 12)(%esp), %esp
|
||||
|
||||
/* Jump to the new kernel
|
||||
* The lret switches to a flat code segment
|
||||
*/
|
||||
lret
|
||||
|
||||
.balign 4
|
||||
.globl xend32
|
||||
xend32:
|
||||
/* Fixup %eflags */
|
||||
nop
|
||||
cli
|
||||
cld
|
||||
|
||||
/* Load %esp with &os_regs + virt_offset */
|
||||
.byte 0xbc /* movl $0, %esp */
|
||||
os_regs_ptr:
|
||||
.long 0
|
||||
|
||||
/* Save the result registers */
|
||||
addl $32, %esp
|
||||
pushal
|
||||
|
||||
/* Compute virt_offset */
|
||||
movl %esp, %ebp
|
||||
subl $os_regs, %ebp
|
||||
|
||||
/* Load the stack pointer and convert it to physical address */
|
||||
movl 52(%esp), %esp
|
||||
addl %ebp, %esp
|
||||
|
||||
/* Enable the virtual addresses */
|
||||
leal _phys_to_virt(%ebp), %eax
|
||||
call *%eax
|
||||
|
||||
/* Restore the callee save registers */
|
||||
movl os_regs + 32, %ebp
|
||||
movl os_regs + 36, %esi
|
||||
movl os_regs + 40, %edi
|
||||
movl os_regs + 44, %ebx
|
||||
movl os_regs + 48, %edx
|
||||
movl os_regs + 52, %esp
|
||||
|
||||
/* Get the C return value */
|
||||
movl os_regs + 28, %eax
|
||||
|
||||
jmpl *%edx
|
||||
|
||||
#ifdef CONFIG_X86_64
|
||||
.arch sledgehammer
|
||||
/**************************************************************************
|
||||
XSTART_lm - Transfer control to the kernel just loaded in long mode
|
||||
**************************************************************************/
|
||||
.globl xstart_lm
|
||||
xstart_lm:
|
||||
/* Save the callee save registers */
|
||||
pushl %ebp
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
pushl %ebx
|
||||
|
||||
/* Cache virt_offset && (virt_offset & 0xfffff000) */
|
||||
movl virt_offset, %ebp
|
||||
movl %ebp, %ebx
|
||||
andl $0xfffff000, %ebx
|
||||
|
||||
/* Switch to using physical addresses */
|
||||
call _virt_to_phys
|
||||
|
||||
/* Initialize the page tables */
|
||||
/* Level 4 */
|
||||
leal 0x23 + pgt_level3(%ebx), %eax
|
||||
leal pgt_level4(%ebx), %edi
|
||||
movl %eax, (%edi)
|
||||
|
||||
/* Level 3 */
|
||||
leal 0x23 + pgt_level2(%ebx), %eax
|
||||
leal pgt_level3(%ebx), %edi
|
||||
movl %eax, 0x00(%edi)
|
||||
addl $4096, %eax
|
||||
movl %eax, 0x08(%edi)
|
||||
addl $4096, %eax
|
||||
movl %eax, 0x10(%edi)
|
||||
addl $4096, %eax
|
||||
movl %eax, 0x18(%edi)
|
||||
|
||||
/* Level 2 */
|
||||
movl $0xe3, %eax
|
||||
leal pgt_level2(%ebx), %edi
|
||||
leal 16384(%edi), %esi
|
||||
pgt_level2_loop:
|
||||
movl %eax, (%edi)
|
||||
addl $8, %edi
|
||||
addl $0x200000, %eax
|
||||
cmp %esi, %edi
|
||||
jne pgt_level2_loop
|
||||
|
||||
/* Point at the x86_64 page tables */
|
||||
leal pgt_level4(%ebx), %edi
|
||||
movl %edi, %cr3
|
||||
|
||||
|
||||
/* Setup for the return from 64bit mode */
|
||||
/* 64bit align the stack */
|
||||
movl %esp, %ebx /* original stack pointer + 16 */
|
||||
andl $0xfffffff8, %esp
|
||||
|
||||
/* Save original stack pointer + 16 */
|
||||
pushl %ebx
|
||||
|
||||
/* Save virt_offset */
|
||||
pushl %ebp
|
||||
|
||||
/* Setup for the jmp to 64bit long mode */
|
||||
leal start_lm(%ebp), %eax
|
||||
movl %eax, 0x00 + start_lm_addr(%ebp)
|
||||
movl $LM_CODE_SEG, %eax
|
||||
movl %eax, 0x04 + start_lm_addr(%ebp)
|
||||
|
||||
/* Setup for the jump out of 64bit long mode */
|
||||
leal end_lm(%ebp), %eax
|
||||
movl %eax, 0x00 + end_lm_addr(%ebp)
|
||||
movl $FLAT_CODE_SEG, %eax
|
||||
movl %eax, 0x04 + end_lm_addr(%ebp)
|
||||
|
||||
/* Enable PAE mode */
|
||||
movl %cr4, %eax
|
||||
orl $X86_CR4_PAE, %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
/* Enable long mode */
|
||||
movl $MSR_K6_EFER, %ecx
|
||||
rdmsr
|
||||
orl $EFER_LME, %eax
|
||||
wrmsr
|
||||
|
||||
/* Start paging, entering 32bit compatiblity mode */
|
||||
movl %cr0, %eax
|
||||
orl $CR0_PG, %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* Enter 64bit long mode */
|
||||
ljmp *start_lm_addr(%ebp)
|
||||
.code64
|
||||
start_lm:
|
||||
/* Load 64bit data segments */
|
||||
movl $LM_DATA_SEG, %eax
|
||||
movl %eax, %ds
|
||||
movl %eax, %es
|
||||
movl %eax, %ss
|
||||
|
||||
andq $0xffffffff, %rbx
|
||||
/* Get the address to jump to */
|
||||
movl 20(%rbx), %edx
|
||||
andq $0xffffffff, %rdx
|
||||
|
||||
/* Get the argument pointer */
|
||||
movl 24(%rbx), %ebx
|
||||
andq $0xffffffff, %rbx
|
||||
|
||||
/* Jump to the 64bit code */
|
||||
call *%rdx
|
||||
|
||||
/* Preserve the result */
|
||||
movl %eax, %edx
|
||||
|
||||
/* Fixup %eflags */
|
||||
cli
|
||||
cld
|
||||
|
||||
/* Switch to 32bit compatibility mode */
|
||||
ljmp *end_lm_addr(%rip)
|
||||
|
||||
.code32
|
||||
end_lm:
|
||||
/* Disable paging */
|
||||
movl %cr0, %eax
|
||||
andl $~CR0_PG, %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* Disable long mode */
|
||||
movl $MSR_K6_EFER, %ecx
|
||||
rdmsr
|
||||
andl $~EFER_LME, %eax
|
||||
wrmsr
|
||||
|
||||
/* Disable PAE */
|
||||
movl %cr4, %eax
|
||||
andl $~X86_CR4_PAE, %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
/* Compute virt_offset */
|
||||
popl %ebp
|
||||
|
||||
/* Compute the original stack pointer + 16 */
|
||||
popl %ebx
|
||||
movl %ebx, %esp
|
||||
|
||||
/* Enable the virtual addresses */
|
||||
leal _phys_to_virt(%ebp), %eax
|
||||
call *%eax
|
||||
|
||||
/* Restore the callee save registers */
|
||||
popl %ebx
|
||||
popl %esi
|
||||
popl %edi
|
||||
popl %ebp
|
||||
|
||||
/* Get the C return value */
|
||||
movl %edx, %eax
|
||||
|
||||
/* Return */
|
||||
ret
|
||||
|
||||
.arch i386
|
||||
#endif /* CONFIG_X86_64 */
|
||||
|
||||
#ifdef CONFIG_X86_64
|
||||
.section ".bss"
|
||||
.p2align 12
|
||||
/* Include a dummy space in case we are loaded badly aligned */
|
||||
.space 4096
|
||||
/* Reserve enough space for a page table convering 4GB with 2MB pages */
|
||||
pgt_level4:
|
||||
.space 4096
|
||||
pgt_level3:
|
||||
.space 4096
|
||||
pgt_level2:
|
||||
.space 16384
|
||||
start_lm_addr:
|
||||
.space 8
|
||||
end_lm_addr:
|
||||
.space 8
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* arch/i386/core/i386_timer.c
|
||||
*
|
||||
* Use the "System Timer 2" to implement the udelay callback in
|
||||
* the BIOS timer driver. Also used to calibrate the clock rate
|
||||
* in the RTDSC timer driver.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <gpxe/timer2.h>
|
||||
#include <gpxe/io.h>
|
||||
|
||||
/* Timers tick over at this rate */
|
||||
#define TIMER2_TICKS_PER_SEC 1193180U
|
||||
|
||||
/* Parallel Peripheral Controller Port B */
|
||||
#define PPC_PORTB 0x61
|
||||
|
||||
/* Meaning of the port bits */
|
||||
#define PPCB_T2OUT 0x20 /* Bit 5 */
|
||||
#define PPCB_SPKR 0x02 /* Bit 1 */
|
||||
#define PPCB_T2GATE 0x01 /* Bit 0 */
|
||||
|
||||
/* Ports for the 8254 timer chip */
|
||||
#define TIMER2_PORT 0x42
|
||||
#define TIMER_MODE_PORT 0x43
|
||||
|
||||
/* Meaning of the mode bits */
|
||||
#define TIMER0_SEL 0x00
|
||||
#define TIMER1_SEL 0x40
|
||||
#define TIMER2_SEL 0x80
|
||||
#define READBACK_SEL 0xC0
|
||||
|
||||
#define LATCH_COUNT 0x00
|
||||
#define LOBYTE_ACCESS 0x10
|
||||
#define HIBYTE_ACCESS 0x20
|
||||
#define WORD_ACCESS 0x30
|
||||
|
||||
#define MODE0 0x00
|
||||
#define MODE1 0x02
|
||||
#define MODE2 0x04
|
||||
#define MODE3 0x06
|
||||
#define MODE4 0x08
|
||||
#define MODE5 0x0A
|
||||
|
||||
#define BINARY_COUNT 0x00
|
||||
#define BCD_COUNT 0x01
|
||||
|
||||
static void load_timer2 ( unsigned int ticks ) {
|
||||
/*
|
||||
* Now let's take care of PPC channel 2
|
||||
*
|
||||
* Set the Gate high, program PPC channel 2 for mode 0,
|
||||
* (interrupt on terminal count mode), binary count,
|
||||
* load 5 * LATCH count, (LSB and MSB) to begin countdown.
|
||||
*
|
||||
* Note some implementations have a bug where the high bits byte
|
||||
* of channel 2 is ignored.
|
||||
*/
|
||||
/* Set up the timer gate, turn off the speaker */
|
||||
/* Set the Gate high, disable speaker */
|
||||
outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB);
|
||||
/* binary, mode 0, LSB/MSB, Ch 2 */
|
||||
outb(TIMER2_SEL|WORD_ACCESS|MODE0|BINARY_COUNT, TIMER_MODE_PORT);
|
||||
/* LSB of ticks */
|
||||
outb(ticks & 0xFF, TIMER2_PORT);
|
||||
/* MSB of ticks */
|
||||
outb(ticks >> 8, TIMER2_PORT);
|
||||
}
|
||||
|
||||
static int timer2_running ( void ) {
|
||||
return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
|
||||
}
|
||||
|
||||
void timer2_udelay ( unsigned long usecs ) {
|
||||
load_timer2 ( ( usecs * TIMER2_TICKS_PER_SEC ) / ( 1000 * 1000 ) );
|
||||
while (timer2_running()) {
|
||||
/* Do nothing */
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "stddef.h"
|
||||
#include "string.h"
|
||||
#include "io.h"
|
||||
#include <gpxe/io.h>
|
||||
#include "console.h"
|
||||
#include <gpxe/init.h>
|
||||
#include "vga.h"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "virtaddr.h"
|
||||
#include "librm.h"
|
||||
|
||||
.arch i386
|
||||
.text
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <gpxe/io.h>
|
||||
#include <gpxe/x86_io.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* gPXE I/O API for x86
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read 64-bit qword from memory-mapped device
|
||||
*
|
||||
* @v io_addr I/O address
|
||||
* @ret data Value read
|
||||
*
|
||||
* This routine uses MMX instructions.
|
||||
*/
|
||||
static uint64_t x86_readq ( volatile uint64_t *io_addr ) {
|
||||
uint64_t data;
|
||||
__asm__ __volatile__ ( "pushl %%edx\n\t"
|
||||
"pushl %%eax\n\t"
|
||||
"movq (%1), %%mm0\n\t"
|
||||
"movq %%mm0, (%%esp)\n\t"
|
||||
"popl %%eax\n\t"
|
||||
"popl %%edx\n\t"
|
||||
"emms\n\t"
|
||||
: "=A" ( data ) : "r" ( io_addr ) );
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write 64-bit qword to memory-mapped device
|
||||
*
|
||||
* @v data Value to write
|
||||
* @v io_addr I/O address
|
||||
*
|
||||
* This routine uses MMX instructions.
|
||||
*/
|
||||
static void x86_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
|
||||
__asm__ __volatile__ ( "pushl %%edx\n\t"
|
||||
"pushl %%eax\n\t"
|
||||
"movq (%%esp), %%mm0\n\t"
|
||||
"movq %%mm0, (%1)\n\t"
|
||||
"popl %%eax\n\t"
|
||||
"popl %%edx\n\t"
|
||||
"emms\n\t"
|
||||
: : "A" ( data ), "r" ( io_addr ) );
|
||||
}
|
||||
|
||||
PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
|
||||
PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
|
||||
PROVIDE_IOAPI_INLINE ( x86, ioremap );
|
||||
PROVIDE_IOAPI_INLINE ( x86, iounmap );
|
||||
PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
|
||||
PROVIDE_IOAPI_INLINE ( x86, readb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, readw );
|
||||
PROVIDE_IOAPI_INLINE ( x86, readl );
|
||||
PROVIDE_IOAPI ( x86, readq, x86_readq );
|
||||
PROVIDE_IOAPI_INLINE ( x86, writeb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, writew );
|
||||
PROVIDE_IOAPI_INLINE ( x86, writel );
|
||||
PROVIDE_IOAPI ( x86, writeq, x86_writeq );
|
||||
PROVIDE_IOAPI_INLINE ( x86, inb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, inw );
|
||||
PROVIDE_IOAPI_INLINE ( x86, inl );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outw );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outl );
|
||||
PROVIDE_IOAPI_INLINE ( x86, insb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, insw );
|
||||
PROVIDE_IOAPI_INLINE ( x86, insl );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outsb );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outsw );
|
||||
PROVIDE_IOAPI_INLINE ( x86, outsl );
|
||||
PROVIDE_IOAPI_INLINE ( x86, iodelay );
|
||||
PROVIDE_IOAPI_INLINE ( x86, mb );
|
||||
@@ -10,11 +10,9 @@
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".text16", "ax", @progbits
|
||||
.section ".data16", "aw", @progbits
|
||||
.code16
|
||||
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
.globl undiisr
|
||||
undiisr:
|
||||
|
||||
@@ -75,7 +73,7 @@ exit: /* Restore registers and return */
|
||||
popw %ds
|
||||
iret
|
||||
|
||||
.section ".data16"
|
||||
.section ".data16", "aw", @progbits
|
||||
undinet_params:
|
||||
status: .word 0
|
||||
funcflag: .word 0
|
||||
|
||||
@@ -93,8 +93,8 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
|
||||
"lcall *%c2\n\t"
|
||||
"addw $4, %%sp\n\t" )
|
||||
: "=a" ( exit )
|
||||
: "a" ( & __from_data16 ( undi_loader ) ),
|
||||
"p" ( & __from_data16 ( undi_loader_entry ) )
|
||||
: "a" ( __from_data16 ( &undi_loader ) ),
|
||||
"p" ( __from_data16 ( &undi_loader_entry ) )
|
||||
: "ebx", "ecx", "edx", "esi", "edi", "ebp" );
|
||||
|
||||
/* UNDI API calls may rudely change the status of A20 and not
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <biosint.h>
|
||||
#include <pnpbios.h>
|
||||
#include <basemem_packet.h>
|
||||
#include <gpxe/io.h>
|
||||
#include <gpxe/iobuf.h>
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <gpxe/if_ether.h>
|
||||
@@ -176,9 +177,9 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
|
||||
"addw $6, %%sp\n\t" )
|
||||
: "=a" ( exit ), "=b" ( discard_b ),
|
||||
"=D" ( discard_D )
|
||||
: "p" ( &__from_data16 ( undinet_entry_point )),
|
||||
: "p" ( __from_data16 ( &undinet_entry_point )),
|
||||
"b" ( function ),
|
||||
"D" ( &__from_data16 ( undinet_params ) )
|
||||
"D" ( __from_data16 ( &undinet_params ) )
|
||||
: "ecx", "edx", "esi", "ebp" );
|
||||
|
||||
/* UNDI API calls may rudely change the status of A20 and not
|
||||
@@ -211,7 +212,7 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
|
||||
if ( rc != 0 ) {
|
||||
SEGOFF16_t rm_params = {
|
||||
.segment = rm_ds,
|
||||
.offset = (intptr_t) &__from_data16 ( undinet_params ),
|
||||
.offset = __from_data16 ( &undinet_params ),
|
||||
};
|
||||
|
||||
DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
|
||||
@@ -357,17 +358,14 @@ static int undinet_transmit ( struct net_device *netdev,
|
||||
/* Create PXENV_UNDI_TRANSMIT data structure */
|
||||
memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
|
||||
undi_transmit.DestAddr.segment = rm_ds;
|
||||
undi_transmit.DestAddr.offset
|
||||
= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
|
||||
undi_transmit.DestAddr.offset = __from_data16 ( &undinet_tbd );
|
||||
undi_transmit.TBD.segment = rm_ds;
|
||||
undi_transmit.TBD.offset
|
||||
= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
|
||||
undi_transmit.TBD.offset = __from_data16 ( &undinet_tbd );
|
||||
|
||||
/* Create PXENV_UNDI_TBD data structure */
|
||||
undinet_tbd.ImmedLength = len;
|
||||
undinet_tbd.Xmit.segment = rm_ds;
|
||||
undinet_tbd.Xmit.offset
|
||||
= ( ( unsigned ) & __from_data16 ( basemem_packet ) );
|
||||
undinet_tbd.Xmit.offset = __from_data16 ( basemem_packet );
|
||||
|
||||
/* Issue PXE API call */
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
|
||||
@@ -484,8 +482,7 @@ static void undinet_poll ( struct net_device *netdev ) {
|
||||
undi_isr.Frame.offset, frag_len );
|
||||
if ( iob_len ( iobuf ) == len ) {
|
||||
/* Whole packet received; deliver it */
|
||||
netdev_rx ( netdev, iobuf );
|
||||
iobuf = NULL;
|
||||
netdev_rx ( netdev, iob_disown ( iobuf ) );
|
||||
/* Etherboot 5.4 fails to return all packets
|
||||
* under mild load; pretend it retriggered.
|
||||
*/
|
||||
@@ -543,9 +540,13 @@ static int undinet_open ( struct net_device *netdev ) {
|
||||
undinet_call ( undinic, PXENV_UNDI_SET_STATION_ADDRESS,
|
||||
&undi_set_address, sizeof ( undi_set_address ) );
|
||||
|
||||
/* Open NIC */
|
||||
/* Open NIC. We ask for promiscuous operation, since it's the
|
||||
* only way to ask for all multicast addresses. On any
|
||||
* switched network, it shouldn't really make a difference to
|
||||
* performance.
|
||||
*/
|
||||
memset ( &undi_open, 0, sizeof ( undi_open ) );
|
||||
undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST );
|
||||
undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST | FLTR_PRMSCS );
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_OPEN, &undi_open,
|
||||
sizeof ( undi_open ) ) ) != 0 )
|
||||
goto err;
|
||||
@@ -668,15 +669,19 @@ int undinet_probe ( struct undi_device *undi ) {
|
||||
undi->flags |= UNDI_FL_STARTED;
|
||||
|
||||
/* Bring up UNDI stack */
|
||||
memset ( &undi_startup, 0, sizeof ( undi_startup ) );
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP, &undi_startup,
|
||||
sizeof ( undi_startup ) ) ) != 0 )
|
||||
goto err_undi_startup;
|
||||
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
|
||||
&undi_initialize,
|
||||
sizeof ( undi_initialize ) ) ) != 0 )
|
||||
goto err_undi_initialize;
|
||||
if ( ! ( undi->flags & UNDI_FL_INITIALIZED ) ) {
|
||||
memset ( &undi_startup, 0, sizeof ( undi_startup ) );
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP,
|
||||
&undi_startup,
|
||||
sizeof ( undi_startup ) ) ) != 0 )
|
||||
goto err_undi_startup;
|
||||
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
|
||||
if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
|
||||
&undi_initialize,
|
||||
sizeof ( undi_initialize ))) != 0 )
|
||||
goto err_undi_initialize;
|
||||
}
|
||||
undi->flags |= UNDI_FL_INITIALIZED;
|
||||
|
||||
/* Get device information */
|
||||
memset ( &undi_info, 0, sizeof ( undi_info ) );
|
||||
@@ -699,7 +704,7 @@ int undinet_probe ( struct undi_device *undi ) {
|
||||
&undi_iface,
|
||||
sizeof ( undi_iface ) ) ) != 0 )
|
||||
goto err_undi_get_iface_info;
|
||||
DBGC ( undinic, "UNDINIC %p has type %s and link speed %ld\n",
|
||||
DBGC ( undinic, "UNDINIC %p has type %s and link speed %d\n",
|
||||
undinic, undi_iface.IfaceType, undi_iface.LinkSpeed );
|
||||
if ( strncmp ( ( ( char * ) undi_iface.IfaceType ), "Etherboot",
|
||||
sizeof ( undi_iface.IfaceType ) ) == 0 ) {
|
||||
@@ -708,6 +713,9 @@ int undinet_probe ( struct undi_device *undi ) {
|
||||
undinic->hacks |= UNDI_HACK_EB54;
|
||||
}
|
||||
|
||||
/* Mark as link up; we don't handle link state */
|
||||
netdev_link_up ( netdev );
|
||||
|
||||
/* Register network device */
|
||||
if ( ( rc = register_netdev ( netdev ) ) != 0 )
|
||||
goto err_register;
|
||||
@@ -727,11 +735,13 @@ int undinet_probe ( struct undi_device *undi ) {
|
||||
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
|
||||
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
|
||||
sizeof ( undi_cleanup ) );
|
||||
undi->flags &= ~UNDI_FL_INITIALIZED;
|
||||
err_undi_startup:
|
||||
/* Unhook UNDI stack */
|
||||
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
|
||||
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
|
||||
sizeof ( stop_undi ) );
|
||||
undi->flags &= ~UNDI_FL_STARTED;
|
||||
err_start_undi:
|
||||
netdev_nullify ( netdev );
|
||||
netdev_put ( netdev );
|
||||
@@ -754,19 +764,26 @@ void undinet_remove ( struct undi_device *undi ) {
|
||||
/* Unregister net device */
|
||||
unregister_netdev ( netdev );
|
||||
|
||||
/* Shut down UNDI stack */
|
||||
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
|
||||
undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
|
||||
sizeof ( undi_shutdown ) );
|
||||
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
|
||||
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
|
||||
sizeof ( undi_cleanup ) );
|
||||
/* If we are preparing for an OS boot, or if we cannot exit
|
||||
* via the PXE stack, then shut down the PXE stack.
|
||||
*/
|
||||
if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
|
||||
|
||||
/* Unhook UNDI stack */
|
||||
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
|
||||
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
|
||||
sizeof ( stop_undi ) );
|
||||
undi->flags &= ~UNDI_FL_STARTED;
|
||||
/* Shut down UNDI stack */
|
||||
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
|
||||
undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
|
||||
sizeof ( undi_shutdown ) );
|
||||
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
|
||||
undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
|
||||
sizeof ( undi_cleanup ) );
|
||||
undi->flags &= ~UNDI_FL_INITIALIZED;
|
||||
|
||||
/* Unhook UNDI stack */
|
||||
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
|
||||
undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
|
||||
sizeof ( stop_undi ) );
|
||||
undi->flags &= ~UNDI_FL_STARTED;
|
||||
}
|
||||
|
||||
/* Clear entry point */
|
||||
memset ( &undinet_entry_point, 0, sizeof ( undinet_entry_point ) );
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <gpxe/device.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <undi.h>
|
||||
#include <undinet.h>
|
||||
#include <undipreload.h>
|
||||
@@ -107,3 +108,20 @@ struct root_device undi_root_device __root_device = {
|
||||
.dev = { .name = "UNDI" },
|
||||
.driver = &undi_root_driver,
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepare for exit
|
||||
*
|
||||
* @v flags Shutdown flags
|
||||
*/
|
||||
static void undionly_shutdown ( int flags ) {
|
||||
/* If we are shutting down to boot an OS, clear the "keep PXE
|
||||
* stack" flag.
|
||||
*/
|
||||
if ( flags & SHUTDOWN_BOOT )
|
||||
preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
|
||||
}
|
||||
|
||||
struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
|
||||
.shutdown = undionly_shutdown,
|
||||
};
|
||||
|
||||
@@ -52,7 +52,7 @@ static int undirom_parse_pxeromid ( struct undi_rom *undirom,
|
||||
sizeof ( undi_rom_id ) );
|
||||
if ( undi_rom_id.Signature != UNDI_ROM_ID_SIGNATURE ) {
|
||||
DBGC ( undirom, "UNDIROM %p has bad PXE ROM ID signature "
|
||||
"%08lx\n", undirom, undi_rom_id.Signature );
|
||||
"%08x\n", undirom, undi_rom_id.Signature );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ static int undirom_parse_pcirheader ( struct undi_rom *undirom,
|
||||
sizeof ( pcir_header ) );
|
||||
if ( pcir_header.signature != PCIR_SIGNATURE ) {
|
||||
DBGC ( undirom, "UNDIROM %p has bad PCI expansion header "
|
||||
"signature %08lx\n", undirom, pcir_header.signature );
|
||||
"signature %08x\n", undirom, pcir_header.signature );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ static void undirom_probe_all_roms ( void ) {
|
||||
|
||||
DBG ( "Scanning for PXE expansion ROMs\n" );
|
||||
|
||||
/* Scan through expansion ROM region at 2kB intervals */
|
||||
/* Scan through expansion ROM region at 512 byte intervals */
|
||||
for ( rom_segment = 0xc000 ; rom_segment < 0x10000 ;
|
||||
rom_segment += 0x80 ) {
|
||||
rom_segment += 0x20 ) {
|
||||
undirom_probe ( rom_segment );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/* Etherboot routines for PCBIOS firmware.
|
||||
*
|
||||
* Body of routines taken from old pcbios.S
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <realmode.h>
|
||||
#include <bios.h>
|
||||
|
||||
#define CF ( 1 << 0 )
|
||||
|
||||
/**************************************************************************
|
||||
CURRTICKS - Get Time
|
||||
Use direct memory access to BIOS variables, longword 0040:006C (ticks
|
||||
today) and byte 0040:0070 (midnight crossover flag) instead of calling
|
||||
timeofday BIOS interrupt.
|
||||
**************************************************************************/
|
||||
#if defined(CONFIG_TSC_CURRTICKS)
|
||||
#undef CONFIG_BIOS_CURRTICKS
|
||||
#else
|
||||
#define CONFIG_BIOS_CURRTICKS 1
|
||||
#endif
|
||||
#if defined(CONFIG_BIOS_CURRTICKS)
|
||||
unsigned long currticks ( void ) {
|
||||
static uint32_t days = 0;
|
||||
uint32_t ticks;
|
||||
uint8_t midnight;
|
||||
|
||||
/* Re-enable interrupts so that the timer interrupt can occur
|
||||
*/
|
||||
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
|
||||
"nop\n\t"
|
||||
"nop\n\t"
|
||||
"cli\n\t" ) : : );
|
||||
|
||||
get_real ( ticks, BDA_SEG, 0x006c );
|
||||
get_real ( midnight, BDA_SEG, 0x0070 );
|
||||
|
||||
if ( midnight ) {
|
||||
midnight = 0;
|
||||
put_real ( midnight, BDA_SEG, 0x0070 );
|
||||
days += 0x1800b0;
|
||||
}
|
||||
return ( days + ticks );
|
||||
}
|
||||
#endif /* CONFIG_BIOS_CURRTICKS */
|
||||
|
||||
/**************************************************************************
|
||||
CPU_NAP - Save power by halting the CPU until the next interrupt
|
||||
**************************************************************************/
|
||||
void cpu_nap ( void ) {
|
||||
__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
|
||||
"hlt\n\t"
|
||||
"cli\n\t" ) : : );
|
||||
}
|
||||
@@ -193,13 +193,14 @@ static const char *ansi_input = "";
|
||||
* dense range, so subtracting a constant and treating them as offsets
|
||||
* into an array works efficiently.
|
||||
*/
|
||||
#define BIOS_KEY_MIN 0x47
|
||||
#define BIOS_KEY_MIN 0x42
|
||||
|
||||
/** Offset into list of interesting BIOS scancodes */
|
||||
#define BIOS_KEY(scancode) ( (scancode) - BIOS_KEY_MIN )
|
||||
|
||||
/** Mapping from BIOS scan codes to ANSI escape sequences */
|
||||
static const char *ansi_sequences[] = {
|
||||
[ BIOS_KEY ( 0x42 ) ] = "[19~", /* F8 (required for PXE) */
|
||||
[ BIOS_KEY ( 0x47 ) ] = "[H", /* Home */
|
||||
[ BIOS_KEY ( 0x48 ) ] = "[A", /* Up arrow */
|
||||
[ BIOS_KEY ( 0x4b ) ] = "[D", /* Left arrow */
|
||||
@@ -222,6 +223,7 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
|
||||
sizeof ( ansi_sequences[0] ) ) ) {
|
||||
return ansi_sequences[bios_key];
|
||||
}
|
||||
DBG ( "Unrecognised BIOS scancode %02x\n", scancode );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,167 +18,107 @@
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".text16", "ax", @progbits
|
||||
.section ".data16", "aw", @progbits
|
||||
.section ".text16.data", "aw", @progbits
|
||||
.code16
|
||||
|
||||
#define SMAP 0x534d4150
|
||||
|
||||
/****************************************************************************
|
||||
* Check for overlap
|
||||
/* Most documentation refers to the E820 buffer as being 20 bytes, and
|
||||
* the API makes it perfectly legitimate to pass only a 20-byte buffer
|
||||
* and expect to get valid data. However, some morons at ACPI decided
|
||||
* to extend the data structure by adding an extra "extended
|
||||
* attributes" field and by including critical information within this
|
||||
* field, such as whether or not the region is enabled. A caller who
|
||||
* passes in only a 20-byte buffer therefore risks getting very, very
|
||||
* misleading information.
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* %si Pointer to hidden region descriptor
|
||||
* Returns:
|
||||
* CF set Region overlaps
|
||||
* CF clear No overlap
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
check_overlap:
|
||||
/* If start >= hidden_end, there is no overlap. */
|
||||
testl %edx, %edx
|
||||
jnz no_overlap
|
||||
cmpl 4(%si), %eax
|
||||
jae no_overlap
|
||||
/* If end <= hidden_start, there is no overlap; equivalently,
|
||||
* if end > hidden_start, there is overlap.
|
||||
*/
|
||||
testl %ecx, %ecx
|
||||
jnz overlap
|
||||
cmpl 0(%si), %ebx
|
||||
ja overlap
|
||||
no_overlap:
|
||||
clc
|
||||
ret
|
||||
overlap:
|
||||
stc
|
||||
ret
|
||||
.size check_overlap, . - check_overlap
|
||||
* I have personally witnessed an HP BIOS that returns a value of
|
||||
* 0x0009 in the extended attributes field. If we don't pass this
|
||||
* value through to the caller, 32-bit WinPE will die, usually with a
|
||||
* PAGE_FAULT_IN_NONPAGED_AREA blue screen of death.
|
||||
*
|
||||
* Allow a ridiculously large maximum value (64 bytes) for the E820
|
||||
* buffer as a guard against insufficiently creative idiots in the
|
||||
* future.
|
||||
*/
|
||||
#define E820MAXSIZE 64
|
||||
|
||||
/****************************************************************************
|
||||
* Check for overflow/underflow
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* Returns:
|
||||
* CF set start < end
|
||||
* CF clear start >= end
|
||||
* Allowed memory windows
|
||||
*
|
||||
* There are two ways to view this list. The first is as a list of
|
||||
* (non-overlapping) allowed memory regions, sorted by increasing
|
||||
* address. The second is as a list of (non-overlapping) hidden
|
||||
* memory regions, again sorted by increasing address. The second
|
||||
* view is offset by half an entry from the first: think about this
|
||||
* for a moment and it should make sense.
|
||||
*
|
||||
* xxx_memory_window is used to indicate an "allowed region"
|
||||
* structure, hidden_xxx_memory is used to indicate a "hidden region"
|
||||
* structure. Each structure is 16 bytes in length.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
check_overflow:
|
||||
pushl %ecx
|
||||
pushl %ebx
|
||||
subl %eax, %ebx
|
||||
sbbl %edx, %ecx
|
||||
popl %ebx
|
||||
popl %ecx
|
||||
ret
|
||||
.size check_overflow, . - check_overflow
|
||||
|
||||
/****************************************************************************
|
||||
* Truncate towards start of region
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* %si Pointer to hidden region descriptor
|
||||
* Returns:
|
||||
* %edx:%eax Modified region start
|
||||
* %ecx:%ebx Modified region end
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
truncate_to_start:
|
||||
/* If overlaps, set region end = hidden region start */
|
||||
call check_overlap
|
||||
jnc 99f
|
||||
movl 0(%si), %ebx
|
||||
xorl %ecx, %ecx
|
||||
/* If region end < region start, set region end = region start */
|
||||
call check_overflow
|
||||
jnc 1f
|
||||
movl %eax, %ebx
|
||||
movl %edx, %ecx
|
||||
1: stc
|
||||
99: ret
|
||||
.size truncate_to_start, . - truncate_to_start
|
||||
.section ".data16", "aw", @progbits
|
||||
.align 16
|
||||
.globl hidemem_base
|
||||
.globl hidemem_umalloc
|
||||
.globl hidemem_textdata
|
||||
memory_windows:
|
||||
base_memory_window: .long 0x00000000, 0x00000000 /* Start of memory */
|
||||
|
||||
hidemem_base: .long 0x000a0000, 0x00000000 /* Changes at runtime */
|
||||
ext_memory_window: .long 0x000a0000, 0x00000000 /* 640kB mark */
|
||||
|
||||
hidemem_umalloc: .long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
.long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
|
||||
hidemem_textdata: .long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
.long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
|
||||
.long 0xffffffff, 0xffffffff /* End of memory */
|
||||
memory_windows_end:
|
||||
|
||||
/****************************************************************************
|
||||
* Truncate towards end of region
|
||||
* Truncate region to memory window
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* %si Pointer to hidden region descriptor
|
||||
* %edx:%eax Start of region
|
||||
* %ecx:%ebx Length of region
|
||||
* %si Memory window
|
||||
* Returns:
|
||||
* %edx:%eax Modified region start
|
||||
* %ecx:%ebx Modified region end
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
* %edx:%eax Start of windowed region
|
||||
* %ecx:%ebx Length of windowed region
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
truncate_to_end:
|
||||
/* If overlaps, set region start = hidden region end */
|
||||
call check_overlap
|
||||
jnc 99f
|
||||
movl 4(%si), %eax
|
||||
xorl %edx, %edx
|
||||
/* If region start > region end, set region start = region end */
|
||||
call check_overflow
|
||||
jnc 1f
|
||||
movl %ebx, %eax
|
||||
movl %ecx, %edx
|
||||
1: stc
|
||||
99: ret
|
||||
.size truncate_to_end, . - truncate_to_end
|
||||
|
||||
/****************************************************************************
|
||||
* Truncate region
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region length (*not* region end)
|
||||
* %bp truncate_to_start or truncate_to_end
|
||||
* Returns:
|
||||
* %edx:%eax Modified region start
|
||||
* %ecx:%ebx Modified region length
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
truncate:
|
||||
pushw %si
|
||||
pushfw
|
||||
/* Convert (start,len) to (start,end) */
|
||||
.section ".text16", "ax", @progbits
|
||||
window_region:
|
||||
/* Convert (start,len) to (start, end) */
|
||||
addl %eax, %ebx
|
||||
adcl %edx, %ecx
|
||||
/* Hide all hidden regions, truncating as directed */
|
||||
movw $hidden_regions, %si
|
||||
1: call *%bp
|
||||
jnc 2f
|
||||
popfw /* If CF was set, set stored CF in flags word on stack */
|
||||
stc
|
||||
pushfw
|
||||
2: addw $8, %si
|
||||
cmpl $0, 0(%si)
|
||||
jne 1b
|
||||
/* Convert modified (start,end) back to (start,len) */
|
||||
/* Truncate to window start */
|
||||
cmpl 4(%si), %edx
|
||||
jne 1f
|
||||
cmpl 0(%si), %eax
|
||||
1: jae 2f
|
||||
movl 4(%si), %edx
|
||||
movl 0(%si), %eax
|
||||
2: /* Truncate to window end */
|
||||
cmpl 12(%si), %ecx
|
||||
jne 1f
|
||||
cmpl 8(%si), %ebx
|
||||
1: jbe 2f
|
||||
movl 12(%si), %ecx
|
||||
movl 8(%si), %ebx
|
||||
2: /* Convert (start, end) back to (start, len) */
|
||||
subl %eax, %ebx
|
||||
sbbl %edx, %ecx
|
||||
popfw
|
||||
popw %si
|
||||
/* If length is <0, set length to 0 */
|
||||
jae 1f
|
||||
xorl %ebx, %ebx
|
||||
xorl %ecx, %ecx
|
||||
ret
|
||||
.size truncate, . - truncate
|
||||
.size window_region, . - window_region
|
||||
|
||||
/****************************************************************************
|
||||
* Patch "memory above 1MB" figure
|
||||
@@ -187,21 +127,19 @@ truncate:
|
||||
* %ax Memory above 1MB, in 1kB blocks
|
||||
* Returns:
|
||||
* %ax Modified memory above 1M in 1kB blocks
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
patch_1m:
|
||||
pushal
|
||||
/* Convert to (start,len) format and call truncate */
|
||||
movw $truncate_to_start, %bp
|
||||
xorl %ecx, %ecx
|
||||
movzwl %ax, %ebx
|
||||
shll $10, %ebx
|
||||
xorl %edx, %edx
|
||||
movl $0x100000, %eax
|
||||
call truncate
|
||||
movw $ext_memory_window, %si
|
||||
call window_region
|
||||
/* Convert back to "memory above 1MB" format and return via %ax */
|
||||
pushfw
|
||||
shrl $10, %ebx
|
||||
@@ -219,20 +157,18 @@ patch_1m:
|
||||
* %bx Memory above 16MB, in 64kB blocks
|
||||
* Returns:
|
||||
* %bx Modified memory above 16M in 64kB blocks
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
patch_16m:
|
||||
pushal
|
||||
/* Convert to (start,len) format and call truncate */
|
||||
movw $truncate_to_start, %bp
|
||||
xorl %ecx, %ecx
|
||||
shll $16, %ebx
|
||||
xorl %edx, %edx
|
||||
movl $0x1000000, %eax
|
||||
call truncate
|
||||
movw $ext_memory_window, %si
|
||||
call window_region
|
||||
/* Convert back to "memory above 16MB" format and return via %bx */
|
||||
pushfw
|
||||
shrl $16, %ebx
|
||||
@@ -252,143 +188,318 @@ patch_16m:
|
||||
* Returns:
|
||||
* %ax Modified memory between 1MB and 16MB, in 1kB blocks
|
||||
* %bx Modified memory above 16MB, in 64kB blocks
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
patch_1m_16m:
|
||||
call patch_1m
|
||||
jc 1f
|
||||
call patch_16m
|
||||
ret
|
||||
1: /* 1m region was truncated; kill the 16m region */
|
||||
/* If 1M region is no longer full-length, kill off the 16M region */
|
||||
cmpw $( 15 * 1024 ), %ax
|
||||
je 1f
|
||||
xorw %bx, %bx
|
||||
ret
|
||||
1: ret
|
||||
.size patch_1m_16m, . - patch_1m_16m
|
||||
|
||||
/****************************************************************************
|
||||
* Patch E820 memory map entry
|
||||
* Get underlying e820 memory region to underlying_e820 buffer
|
||||
*
|
||||
* Parameters:
|
||||
* %es:di Pointer to E820 memory map descriptor
|
||||
* %bp truncate_to_start or truncate_to_end
|
||||
* As for INT 15,e820
|
||||
* Returns:
|
||||
* %es:di Pointer to now-modified E820 memory map descriptor
|
||||
* CF set Region was truncated
|
||||
* CF clear Region was not truncated
|
||||
* As for INT 15,e820
|
||||
*
|
||||
* Wraps the underlying INT 15,e820 call so that the continuation
|
||||
* value (%ebx) is a 16-bit simple sequence counter (with the high 16
|
||||
* bits ignored), and termination is always via CF=1 rather than
|
||||
* %ebx=0.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
patch_e820:
|
||||
.section ".text16", "ax", @progbits
|
||||
get_underlying_e820:
|
||||
|
||||
/* If the requested region is in the cache, return it */
|
||||
cmpw %bx, underlying_e820_index
|
||||
jne 2f
|
||||
pushw %di
|
||||
pushw %si
|
||||
movw $underlying_e820_cache, %si
|
||||
cmpl underlying_e820_cache_size, %ecx
|
||||
jbe 1f
|
||||
movl underlying_e820_cache_size, %ecx
|
||||
1: pushl %ecx
|
||||
rep movsb
|
||||
popl %ecx
|
||||
popw %si
|
||||
popw %di
|
||||
incw %bx
|
||||
movl %edx, %eax
|
||||
ret
|
||||
2:
|
||||
/* If the requested region is earlier than the cached region,
|
||||
* invalidate the cache.
|
||||
*/
|
||||
cmpw %bx, underlying_e820_index
|
||||
jbe 1f
|
||||
movw $0xffff, underlying_e820_index
|
||||
1:
|
||||
/* If the cache is invalid, reset the underlying %ebx */
|
||||
cmpw $0xffff, underlying_e820_index
|
||||
jne 1f
|
||||
andl $0, underlying_e820_ebx
|
||||
1:
|
||||
/* If the cache is valid but the continuation value is zero,
|
||||
* this means that the previous underlying call returned with
|
||||
* %ebx=0. Return with CF=1 in this case.
|
||||
*/
|
||||
cmpw $0xffff, underlying_e820_index
|
||||
je 1f
|
||||
cmpl $0, underlying_e820_ebx
|
||||
jne 1f
|
||||
stc
|
||||
ret
|
||||
1:
|
||||
/* Get the next region into the cache */
|
||||
pushl %eax
|
||||
pushl %ebx
|
||||
pushl %ecx
|
||||
pushl %edx
|
||||
pushl %esi /* Some implementations corrupt %esi, so we */
|
||||
pushl %edi /* preserve %esi, %edi and %ebp to be paranoid */
|
||||
pushl %ebp
|
||||
pushw %es
|
||||
pushw %ds
|
||||
popw %es
|
||||
movw $underlying_e820_cache, %di
|
||||
cmpl $E820MAXSIZE, %ecx
|
||||
jbe 1f
|
||||
movl $E820MAXSIZE, %ecx
|
||||
1: movl underlying_e820_ebx, %ebx
|
||||
stc
|
||||
pushfw
|
||||
lcall *%cs:int15_vector
|
||||
popw %es
|
||||
popl %ebp
|
||||
popl %edi
|
||||
popl %esi
|
||||
/* Check for error return from underlying e820 call */
|
||||
jc 2f /* CF set: error */
|
||||
cmpl $SMAP, %eax
|
||||
je 3f /* 'SMAP' missing: error */
|
||||
2: /* An error occurred: return values returned by underlying e820 call */
|
||||
stc /* Force CF set if SMAP was missing */
|
||||
addr32 leal 16(%esp), %esp /* avoid changing other flags */
|
||||
ret
|
||||
3: /* No error occurred */
|
||||
movl %ebx, underlying_e820_ebx
|
||||
movl %ecx, underlying_e820_cache_size
|
||||
popl %edx
|
||||
popl %ecx
|
||||
popl %ebx
|
||||
popl %eax
|
||||
/* Mark cache as containing this result */
|
||||
incw underlying_e820_index
|
||||
|
||||
/* Loop until found */
|
||||
jmp get_underlying_e820
|
||||
.size get_underlying_e820, . - get_underlying_e820
|
||||
|
||||
.section ".data16", "aw", @progbits
|
||||
underlying_e820_index:
|
||||
.word 0xffff /* Initialise to an invalid value */
|
||||
.size underlying_e820_index, . - underlying_e820_index
|
||||
|
||||
.section ".bss16", "aw", @nobits
|
||||
underlying_e820_ebx:
|
||||
.long 0
|
||||
.size underlying_e820_ebx, . - underlying_e820_ebx
|
||||
|
||||
.section ".bss16", "aw", @nobits
|
||||
underlying_e820_cache:
|
||||
.space E820MAXSIZE
|
||||
.size underlying_e820_cache, . - underlying_e820_cache
|
||||
|
||||
.section ".bss16", "aw", @nobits
|
||||
underlying_e820_cache_size:
|
||||
.long 0
|
||||
.size underlying_e820_cache_size, . - underlying_e820_cache_size
|
||||
|
||||
/****************************************************************************
|
||||
* Get windowed e820 region, without empty region stripping
|
||||
*
|
||||
* Parameters:
|
||||
* As for INT 15,e820
|
||||
* Returns:
|
||||
* As for INT 15,e820
|
||||
*
|
||||
* Wraps the underlying INT 15,e820 call so that each underlying
|
||||
* region is returned N times, windowed to fit within N visible-memory
|
||||
* windows. Termination is always via CF=1.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16", "ax", @progbits
|
||||
get_windowed_e820:
|
||||
|
||||
/* Preserve registers */
|
||||
pushl %esi
|
||||
pushw %bp
|
||||
|
||||
/* Split %ebx into %si:%bx, store original %bx in %bp */
|
||||
pushl %ebx
|
||||
popw %bp
|
||||
popw %si
|
||||
|
||||
/* %si == 0 => start of memory_windows list */
|
||||
testw %si, %si
|
||||
jne 1f
|
||||
movw $memory_windows, %si
|
||||
1:
|
||||
/* Get (cached) underlying e820 region to buffer */
|
||||
call get_underlying_e820
|
||||
jc 99f /* Abort on error */
|
||||
|
||||
/* Preserve registers */
|
||||
pushal
|
||||
/* start => %edx:%eax, len => %ecx:%ebx */
|
||||
movl %es:0(%di), %eax
|
||||
movl %es:4(%di), %edx
|
||||
movl %es:8(%di), %ebx
|
||||
movl %es:12(%di), %ecx
|
||||
call truncate
|
||||
/* Truncate region to current window */
|
||||
call window_region
|
||||
1: /* Store modified values in e820 map entry */
|
||||
movl %eax, %es:0(%di)
|
||||
movl %edx, %es:4(%di)
|
||||
movl %ebx, %es:8(%di)
|
||||
movl %ecx, %es:12(%di)
|
||||
/* Restore registers */
|
||||
popal
|
||||
|
||||
/* Derive continuation value for next call */
|
||||
addw $16, %si
|
||||
cmpw $memory_windows_end, %si
|
||||
jne 1f
|
||||
/* End of memory windows: reset %si and allow %bx to continue */
|
||||
xorw %si, %si
|
||||
jmp 2f
|
||||
1: /* More memory windows to go: restore original %bx */
|
||||
movw %bp, %bx
|
||||
2: /* Construct %ebx from %si:%bx */
|
||||
pushw %si
|
||||
pushw %bx
|
||||
popl %ebx
|
||||
|
||||
98: /* Clear CF */
|
||||
clc
|
||||
99: /* Restore registers and return */
|
||||
popw %bp
|
||||
popl %esi
|
||||
ret
|
||||
.size patch_e820, . - patch_e820
|
||||
.size get_windowed_e820, . - get_windowed_e820
|
||||
|
||||
/****************************************************************************
|
||||
* Split E820 memory map entry if necessary
|
||||
* Get windowed e820 region, with empty region stripping
|
||||
*
|
||||
* Parameters:
|
||||
* As for INT 15,e820
|
||||
* Returns:
|
||||
* As for INT 15,e820
|
||||
*
|
||||
* Calls the underlying INT 15,e820 and returns a modified memory map.
|
||||
* Regions will be split around any hidden regions.
|
||||
* Wraps the underlying INT 15,e820 call so that each underlying
|
||||
* region is returned up to N times, windowed to fit within N
|
||||
* visible-memory windows. Empty windows are never returned.
|
||||
* Termination is always via CF=1.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
split_e820:
|
||||
pushw %si
|
||||
pushw %bp
|
||||
/* Caller's %bx => %si, real %ebx to %ebx, call previous handler */
|
||||
pushfw
|
||||
movw %bx, %si
|
||||
testl %ebx, %ebx
|
||||
jnz 1f
|
||||
movl %ebx, %cs:real_ebx
|
||||
1: movl %cs:real_ebx, %ebx
|
||||
lcall *%cs:int15_vector
|
||||
pushfw
|
||||
/* Edit result */
|
||||
pushw %ds
|
||||
pushw %cs:rm_ds
|
||||
popw %ds
|
||||
movw $truncate_to_start, %bp
|
||||
incw %si
|
||||
jns 2f
|
||||
movw $truncate_to_end, %bp
|
||||
2: call patch_e820
|
||||
jnc 3f
|
||||
xorw $0x8000, %si
|
||||
3: testw %si, %si
|
||||
js 4f
|
||||
movl %ebx, %cs:real_ebx
|
||||
testl %ebx, %ebx
|
||||
jz 5f
|
||||
4: movw %si, %bx
|
||||
5: popw %ds
|
||||
/* Restore flags returned by previous handler and return */
|
||||
popfw
|
||||
popw %bp
|
||||
popw %si
|
||||
ret
|
||||
.size split_e820, . - split_e820
|
||||
.section ".text16", "ax", @progbits
|
||||
get_nonempty_e820:
|
||||
|
||||
.section ".text16.data"
|
||||
real_ebx:
|
||||
.long 0
|
||||
.size real_ebx, . - real_ebx
|
||||
/* Record entry parameters */
|
||||
pushl %eax
|
||||
pushl %ecx
|
||||
pushl %edx
|
||||
|
||||
/* Get next windowed region */
|
||||
call get_windowed_e820
|
||||
jc 99f /* abort on error */
|
||||
|
||||
/* If region is non-empty, finish here */
|
||||
cmpl $0, %es:8(%di)
|
||||
jne 98f
|
||||
cmpl $0, %es:12(%di)
|
||||
jne 98f
|
||||
|
||||
/* Region was empty: restore entry parameters and go to next region */
|
||||
popl %edx
|
||||
popl %ecx
|
||||
popl %eax
|
||||
jmp get_nonempty_e820
|
||||
|
||||
98: /* Clear CF */
|
||||
clc
|
||||
99: /* Return values from underlying call */
|
||||
addr32 leal 12(%esp), %esp /* avoid changing flags */
|
||||
ret
|
||||
.size get_nonempty_e820, . - get_nonempty_e820
|
||||
|
||||
/****************************************************************************
|
||||
* Get mangled e820 region, with empty region stripping
|
||||
*
|
||||
* Parameters:
|
||||
* As for INT 15,e820
|
||||
* Returns:
|
||||
* As for INT 15,e820
|
||||
*
|
||||
* Wraps the underlying INT 15,e820 call so that underlying regions
|
||||
* are windowed to the allowed memory regions. Empty regions are
|
||||
* stripped from the map. Termination is always via %ebx=0.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16", "ax", @progbits
|
||||
get_mangled_e820:
|
||||
|
||||
/* Get a nonempty region */
|
||||
call get_nonempty_e820
|
||||
jc 99f /* Abort on error */
|
||||
|
||||
/* Peek ahead to see if there are any further nonempty regions */
|
||||
pushal
|
||||
pushw %es
|
||||
movw %sp, %bp
|
||||
subw %cx, %sp
|
||||
movl $0xe820, %eax
|
||||
movl $SMAP, %edx
|
||||
pushw %ss
|
||||
popw %es
|
||||
movw %sp, %di
|
||||
call get_nonempty_e820
|
||||
movw %bp, %sp
|
||||
popw %es
|
||||
popal
|
||||
jnc 99f /* There are further nonempty regions */
|
||||
|
||||
/* No futher nonempty regions: zero %ebx and clear CF */
|
||||
xorl %ebx, %ebx
|
||||
|
||||
99: /* Return */
|
||||
ret
|
||||
.size get_mangled_e820, . - get_mangled_e820
|
||||
|
||||
/****************************************************************************
|
||||
* INT 15,e820 handler
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
int15_e820:
|
||||
pushl %eax
|
||||
pushl %ecx
|
||||
pushl %edx
|
||||
call split_e820
|
||||
pushfw
|
||||
/* If we've hit an error, exit immediately */
|
||||
jc 99f
|
||||
/* If region is non-empty, return this region */
|
||||
pushl %eax
|
||||
movl %es:8(%di), %eax
|
||||
orl %es:12(%di), %eax
|
||||
popl %eax
|
||||
jnz 99f
|
||||
/* Region is empty. If this is not the end of the map,
|
||||
* skip over this region.
|
||||
*/
|
||||
testl %ebx, %ebx
|
||||
jz 1f
|
||||
popfw
|
||||
popl %edx
|
||||
popl %ecx
|
||||
popl %eax
|
||||
jmp int15_e820
|
||||
1: /* Region is empty and this is the end of the map. Return
|
||||
* with CF set to avoid placing an empty region at the end of
|
||||
* the map.
|
||||
*/
|
||||
popfw
|
||||
stc
|
||||
pushfw
|
||||
99: /* Restore flags from original INT 15,e820 call and return */
|
||||
popfw
|
||||
addr32 leal 12(%esp), %esp /* avoid changing flags */
|
||||
pushw %ds
|
||||
pushw %cs:rm_ds
|
||||
popw %ds
|
||||
call get_mangled_e820
|
||||
popw %ds
|
||||
lret $2
|
||||
.size int15_e820, . - int15_e820
|
||||
|
||||
@@ -396,7 +507,7 @@ int15_e820:
|
||||
* INT 15,e801 handler
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
int15_e801:
|
||||
/* Call previous handler */
|
||||
pushfw
|
||||
@@ -422,7 +533,7 @@ int15_e801:
|
||||
* INT 15,88 handler
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
int15_88:
|
||||
/* Call previous handler */
|
||||
pushfw
|
||||
@@ -443,7 +554,7 @@ int15_88:
|
||||
* INT 15 handler
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".text16"
|
||||
.section ".text16", "ax", @progbits
|
||||
.globl int15
|
||||
int15:
|
||||
/* See if we want to intercept this call */
|
||||
@@ -466,7 +577,7 @@ int15:
|
||||
ljmp *%cs:int15_vector
|
||||
.size int15, . - int15
|
||||
|
||||
.section ".text16.data"
|
||||
.section ".text16.data", "aw", @progbits
|
||||
.globl int15_vector
|
||||
int15_vector:
|
||||
.long 0
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <realmode.h>
|
||||
#include <biosint.h>
|
||||
|
||||
/** Assembly routine in inline asm */
|
||||
extern void int15_fakee820();
|
||||
|
||||
/** Original INT 15 handler */
|
||||
static struct segoff __text16 ( real_int15_vector );
|
||||
#define real_int15_vector __use_text16 ( real_int15_vector )
|
||||
|
||||
/** An INT 15,e820 memory map entry */
|
||||
struct e820_entry {
|
||||
/** Start of region */
|
||||
uint64_t start;
|
||||
/** Length of region */
|
||||
uint64_t len;
|
||||
/** Type of region */
|
||||
uint32_t type;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
#define E820_TYPE_RAM 1 /**< Normal memory */
|
||||
#define E820_TYPE_RSVD 2 /**< Reserved and unavailable */
|
||||
#define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
|
||||
#define E820_TYPE_NVS 4 /**< ACPI NVS memory */
|
||||
|
||||
/** Fake e820 map */
|
||||
static struct e820_entry __text16_array ( e820map, [] ) __used = {
|
||||
{ 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
|
||||
{ 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
|
||||
{ 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
|
||||
{ 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
|
||||
{ 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
|
||||
{ 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
|
||||
{ 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
|
||||
{ 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
|
||||
{0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
|
||||
};
|
||||
#define e820map __use_text16 ( e820map )
|
||||
|
||||
void fake_e820 ( void ) {
|
||||
__asm__ __volatile__ (
|
||||
TEXT16_CODE ( "\nint15_fakee820:\n\t"
|
||||
"pushfw\n\t"
|
||||
"cmpl $0xe820, %%eax\n\t"
|
||||
"jne 99f\n\t"
|
||||
"cmpl $0x534d4150, %%edx\n\t"
|
||||
"jne 99f\n\t"
|
||||
"pushaw\n\t"
|
||||
"leaw e820map(%%bx), %%si\n\t"
|
||||
"cs rep movsb\n\t"
|
||||
"popaw\n\t"
|
||||
"movl %%edx, %%eax\n\t"
|
||||
"addl $20, %%ebx\n\t"
|
||||
"cmpl %0, %%ebx\n\t"
|
||||
"jne 1f\n\t"
|
||||
"xorl %%ebx,%%ebx\n\t"
|
||||
"\n1:\n\t"
|
||||
"popfw\n\t"
|
||||
"clc\n\t"
|
||||
"lret $2\n\t"
|
||||
"\n99:\n\t"
|
||||
"popfw\n\t"
|
||||
"ljmp *%%cs:real_int15_vector\n\t" )
|
||||
: : "i" ( sizeof ( e820map ) ) );
|
||||
|
||||
hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
|
||||
&real_int15_vector );
|
||||
}
|
||||
|
||||
void unfake_e820 ( void ) {
|
||||
unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
|
||||
&real_int15_vector );
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include "realmode.h"
|
||||
#include "timer.h"
|
||||
#include "latch.h"
|
||||
#include "bios.h"
|
||||
#include <realmode.h>
|
||||
#include <bios.h>
|
||||
#include <gpxe/io.h>
|
||||
#include <gpxe/timer.h>
|
||||
|
||||
#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
|
||||
#define K_STATUS 0x64 /* keyboard status */
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#define KC_CMD_WIN 0xd0 /* read output port */
|
||||
#define KC_CMD_WOUT 0xd1 /* write output port */
|
||||
#define KC_CMD_NULL 0xff /* null command ("pulse nothing") */
|
||||
#define KB_SET_A20 0xdf /* enable A20,
|
||||
enable output buffer full interrupt
|
||||
enable data line
|
||||
@@ -48,9 +49,9 @@ static void empty_8042 ( void ) {
|
||||
time = currticks() + TICKS_PER_SEC; /* max wait of 1 second */
|
||||
while ( ( inb ( K_CMD ) & ( K_IBUF_FUL | K_OBUF_FUL ) ) &&
|
||||
currticks() < time ) {
|
||||
SLOW_DOWN_IO;
|
||||
( void ) inb ( K_RDWR );
|
||||
SLOW_DOWN_IO;
|
||||
iodelay();
|
||||
( void ) inb_p ( K_RDWR );
|
||||
iodelay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ static int gateA20_is_set ( int retries ) {
|
||||
/* Avoid false negatives */
|
||||
test_pattern++;
|
||||
|
||||
SLOW_DOWN_IO;
|
||||
iodelay();
|
||||
|
||||
/* Always retry at least once, to avoid false negatives */
|
||||
} while ( retries-- >= 0 );
|
||||
@@ -131,6 +132,8 @@ void gateA20_set ( void ) {
|
||||
empty_8042();
|
||||
outb ( KB_SET_A20, K_RDWR );
|
||||
empty_8042();
|
||||
outb ( KC_CMD_NULL, K_CMD );
|
||||
empty_8042();
|
||||
if ( gateA20_is_set ( A20_KBC_RETRIES ) ) {
|
||||
DBG ( "Enabled gate A20 using "
|
||||
"keyboard controller\n" );
|
||||
@@ -143,9 +146,9 @@ void gateA20_set ( void ) {
|
||||
scp_a = inb ( SCP_A );
|
||||
scp_a &= ~0x01; /* Avoid triggering a reset */
|
||||
scp_a |= 0x02; /* Enable A20 */
|
||||
SLOW_DOWN_IO;
|
||||
iodelay();
|
||||
outb ( scp_a, SCP_A );
|
||||
SLOW_DOWN_IO;
|
||||
iodelay();
|
||||
if ( gateA20_is_set ( A20_SCPA_RETRIES ) ) {
|
||||
DBG ( "Enabled gate A20 using "
|
||||
"Fast Gate A20\n" );
|
||||
|
||||
@@ -15,17 +15,23 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <realmode.h>
|
||||
#include <biosint.h>
|
||||
#include <basemem.h>
|
||||
#include <fakee820.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/memmap.h>
|
||||
#include <gpxe/hidemem.h>
|
||||
|
||||
/** Set to true if you want to test a fake E820 map */
|
||||
#define FAKE_E820 0
|
||||
|
||||
/** Alignment for hidden memory regions */
|
||||
#define ALIGN_HIDDEN 4096 /* 4kB page alignment should be enough */
|
||||
|
||||
/**
|
||||
* A hidden region of Etherboot
|
||||
* A hidden region of gPXE
|
||||
*
|
||||
* This represents a region that will be edited out of the system's
|
||||
* memory map.
|
||||
@@ -34,24 +40,23 @@
|
||||
* changed.
|
||||
*/
|
||||
struct hidden_region {
|
||||
/* Physical start address */
|
||||
physaddr_t start;
|
||||
/* Physical end address */
|
||||
physaddr_t end;
|
||||
/** Physical start address */
|
||||
uint64_t start;
|
||||
/** Physical end address */
|
||||
uint64_t end;
|
||||
};
|
||||
|
||||
/**
|
||||
* List of hidden regions
|
||||
*
|
||||
* Must be terminated by a zero entry.
|
||||
*/
|
||||
struct hidden_region __data16_array ( hidden_regions, [] ) = {
|
||||
[TEXT] = { 0, 0 },
|
||||
[BASEMEM] = { ( 640 * 1024 ), ( 640 * 1024 ) },
|
||||
[EXTMEM] = { 0, 0 },
|
||||
{ 0, 0, } /* Terminator */
|
||||
};
|
||||
#define hidden_regions __use_data16 ( hidden_regions )
|
||||
/** Hidden base memory */
|
||||
extern struct hidden_region __data16 ( hidemem_base );
|
||||
#define hidemem_base __use_data16 ( hidemem_base )
|
||||
|
||||
/** Hidden umalloc memory */
|
||||
extern struct hidden_region __data16 ( hidemem_umalloc );
|
||||
#define hidemem_umalloc __use_data16 ( hidemem_umalloc )
|
||||
|
||||
/** Hidden text memory */
|
||||
extern struct hidden_region __data16 ( hidemem_textdata );
|
||||
#define hidemem_textdata __use_data16 ( hidemem_textdata )
|
||||
|
||||
/** Assembly routine in e820mangler.S */
|
||||
extern void int15();
|
||||
@@ -60,14 +65,23 @@ extern void int15();
|
||||
extern struct segoff __text16 ( int15_vector );
|
||||
#define int15_vector __use_text16 ( int15_vector )
|
||||
|
||||
/* The linker defines these symbols for us */
|
||||
extern char _textdata[];
|
||||
extern char _etextdata[];
|
||||
extern char _text16_memsz[];
|
||||
#define _text16_memsz ( ( unsigned int ) _text16_memsz )
|
||||
extern char _data16_memsz[];
|
||||
#define _data16_memsz ( ( unsigned int ) _data16_memsz )
|
||||
|
||||
/**
|
||||
* Hide region of memory from system memory map
|
||||
*
|
||||
* @v region Hidden memory region
|
||||
* @v start Start of region
|
||||
* @v end End of region
|
||||
*/
|
||||
void hide_region ( unsigned int region_id, physaddr_t start, physaddr_t end ) {
|
||||
struct hidden_region *region = &hidden_regions[region_id];
|
||||
static void hide_region ( struct hidden_region *region,
|
||||
physaddr_t start, physaddr_t end ) {
|
||||
|
||||
/* Some operating systems get a nasty shock if a region of the
|
||||
* E820 map seems to start on a non-page boundary. Make life
|
||||
@@ -76,21 +90,7 @@ void hide_region ( unsigned int region_id, physaddr_t start, physaddr_t end ) {
|
||||
region->start = ( start & ~( ALIGN_HIDDEN - 1 ) );
|
||||
region->end = ( ( end + ALIGN_HIDDEN - 1 ) & ~( ALIGN_HIDDEN - 1 ) );
|
||||
|
||||
DBG ( "Hiding region %d [%lx,%lx)\n",
|
||||
region_id, region->start, region->end );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide Etherboot text
|
||||
*
|
||||
*/
|
||||
static void hide_text ( void ) {
|
||||
|
||||
/* The linker defines these symbols for us */
|
||||
extern char _text[];
|
||||
extern char _end[];
|
||||
|
||||
hide_region ( TEXT, virt_to_phys ( _text ), virt_to_phys ( _end ) );
|
||||
DBG ( "Hiding region [%llx,%llx)\n", region->start, region->end );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,25 @@ void hide_basemem ( void ) {
|
||||
* hide_region(), because we don't want this rounded to the
|
||||
* nearest page boundary.
|
||||
*/
|
||||
hidden_regions[BASEMEM].start = ( get_fbms() * 1024 );
|
||||
hidemem_base.start = ( get_fbms() * 1024 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide umalloc() region
|
||||
*
|
||||
*/
|
||||
void hide_umalloc ( physaddr_t start, physaddr_t end ) {
|
||||
assert ( end <= virt_to_phys ( _textdata ) );
|
||||
hide_region ( &hidemem_umalloc, start, end );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide .text and .data
|
||||
*
|
||||
*/
|
||||
void hide_textdata ( void ) {
|
||||
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
|
||||
virt_to_phys ( _etextdata ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,14 +130,54 @@ void hide_basemem ( void ) {
|
||||
* returned by the BIOS.
|
||||
*/
|
||||
static void hide_etherboot ( void ) {
|
||||
struct memory_map memmap;
|
||||
unsigned int rm_ds_top;
|
||||
unsigned int rm_cs_top;
|
||||
unsigned int fbms;
|
||||
|
||||
/* Dump memory map before mangling */
|
||||
DBG ( "Hiding gPXE from system memory map\n" );
|
||||
get_memmap ( &memmap );
|
||||
|
||||
/* Hook in fake E820 map, if we're testing one */
|
||||
if ( FAKE_E820 ) {
|
||||
DBG ( "Hooking in fake E820 map\n" );
|
||||
fake_e820();
|
||||
get_memmap ( &memmap );
|
||||
}
|
||||
|
||||
/* Initialise the hidden regions */
|
||||
hide_text();
|
||||
hide_basemem();
|
||||
hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) );
|
||||
hide_textdata();
|
||||
|
||||
/* Some really moronic BIOSes bring up the PXE stack via the
|
||||
* UNDI loader entry point and then don't bother to unload it
|
||||
* before overwriting the code and data segments. If this
|
||||
* happens, we really don't want to leave INT 15 hooked,
|
||||
* because that will cause any loaded OS to die horribly as
|
||||
* soon as it attempts to fetch the system memory map.
|
||||
*
|
||||
* We use a heuristic to guess whether or not we are being
|
||||
* loaded sensibly.
|
||||
*/
|
||||
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_memsz + 1024 - 1 ) >> 10 );
|
||||
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_memsz + 1024 - 1 ) >> 10 );
|
||||
fbms = get_fbms();
|
||||
if ( ( rm_cs_top < fbms ) && ( rm_ds_top < fbms ) ) {
|
||||
DBG ( "Detected potentially unsafe UNDI load at CS=%04x "
|
||||
"DS=%04x FBMS=%dkB\n", rm_cs, rm_ds, fbms );
|
||||
DBG ( "Disabling INT 15 memory hiding\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Hook INT 15 */
|
||||
hook_bios_interrupt ( 0x15, ( unsigned int ) int15,
|
||||
&int15_vector );
|
||||
|
||||
/* Dump memory map after mangling */
|
||||
DBG ( "Hidden gPXE from system memory map\n" );
|
||||
get_memmap ( &memmap );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +186,7 @@ static void hide_etherboot ( void ) {
|
||||
* Uninstalls the INT 15 handler installed by hide_etherboot(), if
|
||||
* possible.
|
||||
*/
|
||||
static void unhide_etherboot ( void ) {
|
||||
static void unhide_etherboot ( int flags __unused ) {
|
||||
|
||||
/* If we have more than one hooked interrupt at this point, it
|
||||
* means that some other vector is still hooked, in which case
|
||||
@@ -147,6 +205,10 @@ static void unhide_etherboot ( void ) {
|
||||
*/
|
||||
unhook_bios_interrupt ( 0x15, ( unsigned int ) int15,
|
||||
&int15_vector );
|
||||
|
||||
/* Unhook fake E820 map, if used */
|
||||
if ( FAKE_E820 )
|
||||
unfake_e820();
|
||||
}
|
||||
|
||||
/** Hide Etherboot startup function */
|
||||
|
||||
@@ -41,6 +41,8 @@ struct e820_entry {
|
||||
uint64_t len;
|
||||
/** Type of region */
|
||||
uint32_t type;
|
||||
/** Extended attributes (optional) */
|
||||
uint32_t attrs;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
#define E820_TYPE_RAM 1 /**< Normal memory */
|
||||
@@ -48,6 +50,12 @@ struct e820_entry {
|
||||
#define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
|
||||
#define E820_TYPE_NVS 4 /**< ACPI NVS memory */
|
||||
|
||||
#define E820_ATTR_ENABLED 0x00000001UL
|
||||
#define E820_ATTR_NONVOLATILE 0x00000002UL
|
||||
#define E820_ATTR_UNKNOWN 0xfffffffcUL
|
||||
|
||||
#define E820_MIN_SIZE 20
|
||||
|
||||
/** Buffer for INT 15,e820 calls */
|
||||
static struct e820_entry __bss16 ( e820buf );
|
||||
#define e820buf __use_data16 ( e820buf )
|
||||
@@ -86,8 +94,20 @@ static unsigned int extmemsize_e801 ( void ) {
|
||||
}
|
||||
|
||||
extmem = ( extmem_1m_to_16m_k + ( extmem_16m_plus_64k * 64 ) );
|
||||
DBG ( "INT 15,e801 extended memory size %d+64*%d=%d kB\n",
|
||||
extmem_1m_to_16m_k, extmem_16m_plus_64k, extmem );
|
||||
DBG ( "INT 15,e801 extended memory size %d+64*%d=%d kB "
|
||||
"[100000,%llx)\n", extmem_1m_to_16m_k, extmem_16m_plus_64k,
|
||||
extmem, ( 0x100000 + ( ( ( uint64_t ) extmem ) * 1024 ) ) );
|
||||
|
||||
/* Sanity check. Some BIOSes report the entire 4GB address
|
||||
* space as available, which cannot be correct (since that
|
||||
* would leave no address space available for 32-bit PCI
|
||||
* BARs).
|
||||
*/
|
||||
if ( extmem == ( 0x400000 - 0x400 ) ) {
|
||||
DBG ( "INT 15,e801 reported whole 4GB; assuming insane\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return extmem;
|
||||
}
|
||||
|
||||
@@ -103,7 +123,8 @@ static unsigned int extmemsize_88 ( void ) {
|
||||
__asm__ __volatile__ ( REAL_CODE ( "int $0x15" )
|
||||
: "=a" ( extmem ) : "a" ( 0x8800 ) );
|
||||
|
||||
DBG ( "INT 15,88 extended memory size %d kB\n", extmem );
|
||||
DBG ( "INT 15,88 extended memory size %d kB [100000, %x)\n",
|
||||
extmem, ( 0x100000 + ( extmem * 1024 ) ) );
|
||||
return extmem;
|
||||
}
|
||||
|
||||
@@ -135,39 +156,84 @@ static int meme820 ( struct memory_map *memmap ) {
|
||||
struct memory_region *region = memmap->regions;
|
||||
uint32_t next = 0;
|
||||
uint32_t smap;
|
||||
size_t size;
|
||||
unsigned int flags;
|
||||
unsigned int discard_c, discard_d, discard_D;
|
||||
unsigned int discard_D;
|
||||
|
||||
/* Clear the E820 buffer. Do this once before starting,
|
||||
* rather than on each call; some BIOSes rely on the contents
|
||||
* being preserved between calls.
|
||||
*/
|
||||
memset ( &e820buf, 0, sizeof ( e820buf ) );
|
||||
|
||||
do {
|
||||
__asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
|
||||
/* Some BIOSes corrupt %esi for fun. Guard against
|
||||
* this by telling gcc that all non-output registers
|
||||
* may be corrupted.
|
||||
*/
|
||||
__asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t"
|
||||
"stc\n\t"
|
||||
"int $0x15\n\t"
|
||||
"pushfw\n\t"
|
||||
"popw %w0\n\t" )
|
||||
: "=r" ( flags ), "=a" ( smap ),
|
||||
"=b" ( next ), "=D" ( discard_D ),
|
||||
"=c" ( discard_c ), "=d" ( discard_d )
|
||||
"popw %%dx\n\t"
|
||||
"popl %%ebp\n\t" )
|
||||
: "=a" ( smap ), "=b" ( next ),
|
||||
"=c" ( size ), "=d" ( flags ),
|
||||
"=D" ( discard_D )
|
||||
: "a" ( 0xe820 ), "b" ( next ),
|
||||
"D" ( &__from_data16 ( e820buf ) ),
|
||||
"D" ( __from_data16 ( &e820buf ) ),
|
||||
"c" ( sizeof ( e820buf ) ),
|
||||
"d" ( SMAP )
|
||||
: "memory" );
|
||||
: "esi", "memory" );
|
||||
|
||||
if ( smap != SMAP ) {
|
||||
DBG ( "INT 15,e820 failed SMAP signature check\n" );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if ( size < E820_MIN_SIZE ) {
|
||||
DBG ( "INT 15,e820 returned only %zd bytes\n", size );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( flags & CF ) {
|
||||
DBG ( "INT 15,e820 terminated on CF set\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
DBG ( "INT 15,e820 region [%llx,%llx) type %d\n",
|
||||
/* If first region is not RAM, assume map is invalid */
|
||||
if ( ( memmap->count == 0 ) &&
|
||||
( e820buf.type != E820_TYPE_RAM ) ) {
|
||||
DBG ( "INT 15,e820 failed, first entry not RAM\n" );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
DBG ( "INT 15,e820 region [%llx,%llx) type %d",
|
||||
e820buf.start, ( e820buf.start + e820buf.len ),
|
||||
( int ) e820buf.type );
|
||||
if ( size > offsetof ( typeof ( e820buf ), attrs ) ) {
|
||||
DBG ( " (%s", ( ( e820buf.attrs & E820_ATTR_ENABLED )
|
||||
? "enabled" : "disabled" ) );
|
||||
if ( e820buf.attrs & E820_ATTR_NONVOLATILE )
|
||||
DBG ( ", non-volatile" );
|
||||
if ( e820buf.attrs & E820_ATTR_UNKNOWN )
|
||||
DBG ( ", other [%08x]", e820buf.attrs );
|
||||
DBG ( ")" );
|
||||
}
|
||||
DBG ( "\n" );
|
||||
|
||||
/* Discard non-RAM regions */
|
||||
if ( e820buf.type != E820_TYPE_RAM )
|
||||
continue;
|
||||
|
||||
/* Check extended attributes, if present */
|
||||
if ( size > offsetof ( typeof ( e820buf ), attrs ) ) {
|
||||
if ( ! ( e820buf.attrs & E820_ATTR_ENABLED ) )
|
||||
continue;
|
||||
if ( e820buf.attrs & E820_ATTR_NONVOLATILE )
|
||||
continue;
|
||||
}
|
||||
|
||||
region->start = e820buf.start;
|
||||
region->end = e820buf.start + e820buf.len;
|
||||
region++;
|
||||
@@ -184,6 +250,28 @@ static int meme820 ( struct memory_map *memmap ) {
|
||||
}
|
||||
} while ( next != 0 );
|
||||
|
||||
/* Sanity checks. Some BIOSes report complete garbage via INT
|
||||
* 15,e820 (especially at POST time), despite passing the
|
||||
* signature checks. We currently check for a base memory
|
||||
* region (starting at 0) and at least one high memory region
|
||||
* (starting at 0x100000).
|
||||
*/
|
||||
if ( memmap->count < 2 ) {
|
||||
DBG ( "INT 15,e820 returned only %d regions; assuming "
|
||||
"insane\n", memmap->count );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( memmap->regions[0].start != 0 ) {
|
||||
DBG ( "INT 15,e820 region 0 starts at %llx (expected 0); "
|
||||
"assuming insane\n", memmap->regions[0].start );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( memmap->regions[1].start != 0x100000 ) {
|
||||
DBG ( "INT 15,e820 region 1 starts at %llx (expected 100000); "
|
||||
"assuming insane\n", memmap->regions[0].start );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -203,7 +291,8 @@ void get_memmap ( struct memory_map *memmap ) {
|
||||
|
||||
/* Get base and extended memory sizes */
|
||||
basemem = basememsize();
|
||||
DBG ( "FBMS base memory size %d kB\n", basemem );
|
||||
DBG ( "FBMS base memory size %d kB [0,%x)\n",
|
||||
basemem, ( basemem * 1024 ) );
|
||||
extmem = extmemsize();
|
||||
|
||||
/* Try INT 15,e820 first */
|
||||
|
||||
@@ -1,323 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/uuid.h>
|
||||
#include <realmode.h>
|
||||
#include <pnpbios.h>
|
||||
#include <smbios.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* System Management BIOS
|
||||
*
|
||||
*/
|
||||
|
||||
/** Signature for SMBIOS entry point */
|
||||
#define SMBIOS_SIGNATURE \
|
||||
( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '_' << 24 ) )
|
||||
|
||||
/**
|
||||
* SMBIOS entry point
|
||||
*
|
||||
* This is the single table which describes the list of SMBIOS
|
||||
* structures. It is located by scanning through the BIOS segment.
|
||||
*/
|
||||
struct smbios_entry {
|
||||
/** Signature
|
||||
*
|
||||
* Must be equal to SMBIOS_SIGNATURE
|
||||
*/
|
||||
uint32_t signature;
|
||||
/** Checksum */
|
||||
uint8_t checksum;
|
||||
/** Length */
|
||||
uint8_t length;
|
||||
/** Major version */
|
||||
uint8_t major;
|
||||
/** Minor version */
|
||||
uint8_t minor;
|
||||
/** Maximum structure size */
|
||||
uint16_t max;
|
||||
/** Entry point revision */
|
||||
uint8_t revision;
|
||||
/** Formatted area */
|
||||
uint8_t formatted[5];
|
||||
/** DMI Signature */
|
||||
uint8_t dmi_signature[5];
|
||||
/** DMI checksum */
|
||||
uint8_t dmi_checksum;
|
||||
/** Structure table length */
|
||||
uint16_t smbios_length;
|
||||
/** Structure table address */
|
||||
physaddr_t smbios_address;
|
||||
/** Number of SMBIOS structures */
|
||||
uint16_t smbios_count;
|
||||
/** BCD revision */
|
||||
uint8_t bcd_revision;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
/**
|
||||
* SMBIOS entry point descriptor
|
||||
*
|
||||
* This contains the information from the SMBIOS entry point that we
|
||||
* care about.
|
||||
*/
|
||||
struct smbios {
|
||||
/** Start of SMBIOS structures */
|
||||
userptr_t address;
|
||||
/** Length of SMBIOS structures */
|
||||
size_t length;
|
||||
/** Number of SMBIOS structures */
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
/**
|
||||
* SMBIOS strings descriptor
|
||||
*
|
||||
* This is returned as part of the search for an SMBIOS structure, and
|
||||
* contains the information needed for extracting the strings within
|
||||
* the "unformatted" portion of the structure.
|
||||
*/
|
||||
struct smbios_strings {
|
||||
/** Start of strings data */
|
||||
userptr_t data;
|
||||
/** Length of strings data */
|
||||
size_t length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find SMBIOS
|
||||
*
|
||||
* @ret smbios SMBIOS entry point descriptor, or NULL if not found
|
||||
*/
|
||||
static struct smbios * find_smbios ( void ) {
|
||||
static struct smbios smbios = {
|
||||
.address = UNULL,
|
||||
};
|
||||
union {
|
||||
struct smbios_entry entry;
|
||||
uint8_t bytes[256]; /* 256 is maximum length possible */
|
||||
} u;
|
||||
unsigned int offset;
|
||||
size_t len;
|
||||
unsigned int i;
|
||||
uint8_t sum;
|
||||
|
||||
/* Return cached result if available */
|
||||
if ( smbios.address != UNULL )
|
||||
return &smbios;
|
||||
|
||||
/* Try to find SMBIOS */
|
||||
for ( offset = 0 ; offset < 0x10000 ; offset += 0x10 ) {
|
||||
|
||||
/* Read start of header and verify signature */
|
||||
copy_from_real ( &u.entry, BIOS_SEG, offset,
|
||||
sizeof ( u.entry ));
|
||||
if ( u.entry.signature != SMBIOS_SIGNATURE )
|
||||
continue;
|
||||
|
||||
/* Read whole header and verify checksum */
|
||||
len = u.entry.length;
|
||||
copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
|
||||
for ( i = 0 , sum = 0 ; i < len ; i++ ) {
|
||||
sum += u.bytes[i];
|
||||
}
|
||||
if ( sum != 0 ) {
|
||||
DBG ( "SMBIOS at %04x:%04x has bad checksum %02x\n",
|
||||
BIOS_SEG, offset, sum );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Fill result structure */
|
||||
DBG ( "Found SMBIOS entry point at %04x:%04x\n",
|
||||
BIOS_SEG, offset );
|
||||
smbios.address = phys_to_user ( u.entry.smbios_address );
|
||||
smbios.length = u.entry.smbios_length;
|
||||
smbios.count = u.entry.smbios_count;
|
||||
return &smbios;
|
||||
}
|
||||
|
||||
DBG ( "No SMBIOS found\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find SMBIOS strings terminator
|
||||
*
|
||||
* @v smbios SMBIOS entry point descriptor
|
||||
* @v offset Offset to start of strings
|
||||
* @ret offset Offset to strings terminator, or 0 if not found
|
||||
*/
|
||||
static size_t find_strings_terminator ( struct smbios *smbios,
|
||||
size_t offset ) {
|
||||
size_t max_offset = ( smbios->length - 2 );
|
||||
uint16_t nulnul;
|
||||
|
||||
for ( ; offset <= max_offset ; offset++ ) {
|
||||
copy_from_user ( &nulnul, smbios->address, offset, 2 );
|
||||
if ( nulnul == 0 )
|
||||
return ( offset + 1 );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find specific structure type within SMBIOS
|
||||
*
|
||||
* @v type Structure type to search for
|
||||
* @v structure Buffer to fill in with structure
|
||||
* @v length Length of buffer
|
||||
* @v strings Strings descriptor to fill in, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int find_smbios_structure ( unsigned int type, void *structure,
|
||||
size_t length, struct smbios_strings *strings ) {
|
||||
struct smbios *smbios;
|
||||
struct smbios_header header;
|
||||
struct smbios_strings temp_strings;
|
||||
unsigned int count = 0;
|
||||
size_t offset = 0;
|
||||
size_t strings_offset;
|
||||
size_t terminator_offset;
|
||||
|
||||
/* Locate SMBIOS entry point */
|
||||
if ( ! ( smbios = find_smbios() ) )
|
||||
return -ENOENT;
|
||||
|
||||
/* Ensure that we have a usable strings descriptor buffer */
|
||||
if ( ! strings )
|
||||
strings = &temp_strings;
|
||||
|
||||
/* Scan through list of structures */
|
||||
while ( ( ( offset + sizeof ( header ) ) < smbios->length ) &&
|
||||
( count < smbios->count ) ) {
|
||||
|
||||
/* Read next SMBIOS structure header */
|
||||
copy_from_user ( &header, smbios->address, offset,
|
||||
sizeof ( header ) );
|
||||
|
||||
/* Determine start and extent of strings block */
|
||||
strings_offset = ( offset + header.length );
|
||||
if ( strings_offset > smbios->length ) {
|
||||
DBG ( "SMBIOS structure at offset %zx with length "
|
||||
"%x extends beyond SMBIOS\n", offset,
|
||||
header.length );
|
||||
return -ENOENT;
|
||||
}
|
||||
terminator_offset =
|
||||
find_strings_terminator ( smbios, strings_offset );
|
||||
if ( ! terminator_offset ) {
|
||||
DBG ( "SMBIOS structure at offset %zx has "
|
||||
"unterminated strings section\n", offset );
|
||||
return -ENOENT;
|
||||
}
|
||||
strings->data = userptr_add ( smbios->address,
|
||||
strings_offset );
|
||||
strings->length = ( terminator_offset - strings_offset );
|
||||
|
||||
DBG ( "SMBIOS structure at offset %zx has type %d, "
|
||||
"length %x, strings length %zx\n",
|
||||
offset, header.type, header.length, strings->length );
|
||||
|
||||
/* If this is the structure we want, return */
|
||||
if ( header.type == type ) {
|
||||
if ( length > header.length )
|
||||
length = header.length;
|
||||
copy_from_user ( structure, smbios->address,
|
||||
offset, length );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Move to next SMBIOS structure */
|
||||
offset = ( terminator_offset + 1 );
|
||||
count++;
|
||||
}
|
||||
|
||||
DBG ( "SMBIOS structure type %d not found\n", type );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find indexed string within SMBIOS structure
|
||||
*
|
||||
* @v strings SMBIOS strings descriptor
|
||||
* @v index String index
|
||||
* @v buffer Buffer for string
|
||||
* @v length Length of string buffer
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int find_smbios_string ( struct smbios_strings *strings, unsigned int index,
|
||||
char *buffer, size_t length ) {
|
||||
size_t offset = 0;
|
||||
size_t string_len;
|
||||
|
||||
/* Zero buffer. This ensures that a valid NUL terminator is
|
||||
* always present (unless length==0).
|
||||
*/
|
||||
memset ( buffer, 0, length );
|
||||
|
||||
/* String numbers start at 1 (0 is used to indicate "no string") */
|
||||
if ( ! index )
|
||||
return 0;
|
||||
|
||||
while ( offset < strings->length ) {
|
||||
/* Get string length. This is known safe, since the
|
||||
* smbios_strings struct is constructed so as to
|
||||
* always end on a string boundary.
|
||||
*/
|
||||
string_len = strlen_user ( strings->data, offset );
|
||||
if ( --index == 0 ) {
|
||||
/* Copy string, truncating as necessary. */
|
||||
if ( string_len >= length )
|
||||
string_len = ( length - 1 );
|
||||
copy_from_user ( buffer, strings->data,
|
||||
offset, string_len );
|
||||
return 0;
|
||||
}
|
||||
offset += ( string_len + 1 );
|
||||
}
|
||||
|
||||
DBG ( "SMBIOS string index %d not found\n", index );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UUID from SMBIOS
|
||||
*
|
||||
* @v uuid UUID to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int smbios_get_uuid ( union uuid *uuid ) {
|
||||
struct smbios_system_information sysinfo;
|
||||
int rc;
|
||||
|
||||
if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION,
|
||||
&sysinfo, sizeof ( sysinfo ),
|
||||
NULL ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
memcpy ( uuid, sysinfo.uuid, sizeof ( *uuid ) );
|
||||
DBG ( "SMBIOS found UUID %s\n", uuid_ntoa ( uuid ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/segment.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/initrd.h>
|
||||
#include <gpxe/cpio.h>
|
||||
#include <gpxe/features.h>
|
||||
|
||||
@@ -76,6 +75,8 @@ struct bzimage_exec_context {
|
||||
size_t rm_heap;
|
||||
/** Command line (offset from rm_kernel) */
|
||||
size_t rm_cmdline;
|
||||
/** Command line maximum length */
|
||||
size_t cmdline_size;
|
||||
/** Video mode */
|
||||
unsigned int vid_mode;
|
||||
/** Memory limit */
|
||||
@@ -162,8 +163,8 @@ static int bzimage_set_cmdline ( struct image *image,
|
||||
|
||||
/* Copy command line down to real-mode portion */
|
||||
cmdline_len = ( strlen ( cmdline ) + 1 );
|
||||
if ( cmdline_len > BZI_CMDLINE_SIZE )
|
||||
cmdline_len = BZI_CMDLINE_SIZE;
|
||||
if ( cmdline_len > exec_ctx->cmdline_size )
|
||||
cmdline_len = exec_ctx->cmdline_size;
|
||||
copy_to_user ( exec_ctx->rm_kernel, exec_ctx->rm_cmdline,
|
||||
cmdline, cmdline_len );
|
||||
DBGC ( image, "bzImage %p command line \"%s\"\n", image, cmdline );
|
||||
@@ -186,8 +187,8 @@ static size_t bzimage_load_initrd ( struct image *image,
|
||||
struct cpio_header cpio;
|
||||
size_t offset = 0;
|
||||
|
||||
/* Ignore images which aren't initrds */
|
||||
if ( initrd->type != &initrd_image_type )
|
||||
/* Do not include kernel image itself as an initrd */
|
||||
if ( initrd == image )
|
||||
return 0;
|
||||
|
||||
/* Create cpio header before non-prebuilt images */
|
||||
@@ -320,6 +321,12 @@ static int bzimage_exec ( struct image *image ) {
|
||||
} else {
|
||||
exec_ctx.mem_limit = BZI_INITRD_MAX;
|
||||
}
|
||||
if ( bzhdr.version >= 0x0206 ) {
|
||||
exec_ctx.cmdline_size = bzhdr.cmdline_size;
|
||||
} else {
|
||||
exec_ctx.cmdline_size = BZI_CMDLINE_SIZE;
|
||||
}
|
||||
DBG ( "cmdline_size = %zd\n", exec_ctx.cmdline_size );
|
||||
|
||||
/* Parse command line for bootloader parameters */
|
||||
if ( ( rc = bzimage_parse_cmdline ( image, &exec_ctx, cmdline ) ) != 0)
|
||||
@@ -341,7 +348,7 @@ static int bzimage_exec ( struct image *image ) {
|
||||
sizeof ( bzhdr ) );
|
||||
|
||||
/* Prepare for exiting */
|
||||
shutdown();
|
||||
shutdown ( SHUTDOWN_BOOT );
|
||||
|
||||
DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
|
||||
"(stack %04x:%04zx)\n", image,
|
||||
@@ -393,7 +400,7 @@ static int bzimage_load_header ( struct image *image,
|
||||
copy_from_user ( bzhdr, image->data, BZI_HDR_OFFSET,
|
||||
sizeof ( *bzhdr ) );
|
||||
if ( bzhdr->header != BZI_SIGNATURE ) {
|
||||
DBGC ( image, "bzImage %p bad signature %08lx\n",
|
||||
DBGC ( image, "bzImage %p bad signature %08x\n",
|
||||
image, bzhdr->header );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
@@ -406,7 +413,9 @@ static int bzimage_load_header ( struct image *image,
|
||||
}
|
||||
|
||||
/* Calculate load address and size of real-mode portion */
|
||||
load_ctx->rm_kernel_seg = 0x1000; /* place RM kernel at 1000:0000 */
|
||||
load_ctx->rm_kernel_seg = ( ( bzhdr->loadflags & BZI_LOAD_HIGH ) ?
|
||||
0x1000 : /* 1000:0000 (bzImage) */
|
||||
0x9000 ); /* 9000:0000 (zImage) */
|
||||
load_ctx->rm_kernel = real_to_user ( load_ctx->rm_kernel_seg, 0 );
|
||||
load_ctx->rm_filesz =
|
||||
( ( bzhdr->setup_sects ? bzhdr->setup_sects : 4 ) + 1 ) << 9;
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* SYSLINUX COM32 image format
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <realmode.h>
|
||||
#include <basemem.h>
|
||||
#include <comboot.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/segment.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/memmap.h>
|
||||
|
||||
struct image_type com32_image_type __image_type ( PROBE_NORMAL );
|
||||
|
||||
/**
|
||||
* Execute COMBOOT image
|
||||
*
|
||||
* @v image COM32 image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int com32_exec ( struct image *image ) {
|
||||
struct memory_map memmap;
|
||||
unsigned int i;
|
||||
int state;
|
||||
uint32_t avail_mem_top;
|
||||
|
||||
state = rmsetjmp ( comboot_return );
|
||||
|
||||
switch ( state ) {
|
||||
case 0: /* First time through; invoke COM32 program */
|
||||
|
||||
/* Get memory map */
|
||||
get_memmap ( &memmap );
|
||||
|
||||
/* Find end of block covering COM32 image loading area */
|
||||
for ( i = 0, avail_mem_top = 0 ; i < memmap.count ; i++ ) {
|
||||
if ( (memmap.regions[i].start <= COM32_START_PHYS) &&
|
||||
(memmap.regions[i].end > COM32_START_PHYS + image->len) ) {
|
||||
avail_mem_top = memmap.regions[i].end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DBGC ( image, "COM32 %p: available memory top = 0x%x\n",
|
||||
image, avail_mem_top );
|
||||
|
||||
assert ( avail_mem_top != 0 );
|
||||
|
||||
com32_external_esp = phys_to_virt ( avail_mem_top );
|
||||
|
||||
/* Hook COMBOOT API interrupts */
|
||||
hook_comboot_interrupts();
|
||||
|
||||
/* Unregister image, so that a "boot" command doesn't
|
||||
* throw us into an execution loop. We never
|
||||
* reregister ourselves; COMBOOT images expect to be
|
||||
* removed on exit.
|
||||
*/
|
||||
unregister_image ( image );
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"movl %%esp, (com32_internal_esp)\n\t" /* Save internal virtual address space ESP */
|
||||
"movl (com32_external_esp), %%esp\n\t" /* Switch to COM32 ESP (top of available memory) */
|
||||
"call _virt_to_phys\n\t" /* Switch to flat physical address space */
|
||||
"pushl %0\n\t" /* Pointer to CDECL helper function */
|
||||
"pushl %1\n\t" /* Pointer to FAR call helper function */
|
||||
"pushl %2\n\t" /* Size of low memory bounce buffer */
|
||||
"pushl %3\n\t" /* Pointer to low memory bounce buffer */
|
||||
"pushl %4\n\t" /* Pointer to INT call helper function */
|
||||
"pushl %5\n\t" /* Pointer to the command line arguments */
|
||||
"pushl $6\n\t" /* Number of additional arguments */
|
||||
"call *%6\n\t" /* Execute image */
|
||||
"call _phys_to_virt\n\t" /* Switch back to internal virtual address space */
|
||||
"movl (com32_internal_esp), %%esp\n\t" /* Switch back to internal stack */
|
||||
:
|
||||
:
|
||||
/* %0 */ "r" ( virt_to_phys ( com32_cfarcall_wrapper ) ),
|
||||
/* %1 */ "r" ( virt_to_phys ( com32_farcall_wrapper ) ),
|
||||
/* %2 */ "r" ( get_fbms() * 1024 - (COM32_BOUNCE_SEG << 4) ),
|
||||
/* %3 */ "i" ( COM32_BOUNCE_SEG << 4 ),
|
||||
/* %4 */ "r" ( virt_to_phys ( com32_intcall_wrapper ) ),
|
||||
/* %5 */ "r" ( virt_to_phys ( image->cmdline ) ),
|
||||
/* %6 */ "r" ( COM32_START_PHYS )
|
||||
:
|
||||
"memory" );
|
||||
DBGC ( image, "COM32 %p: returned\n", image );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT:
|
||||
DBGC ( image, "COM32 %p: exited\n", image );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT_RUN_KERNEL:
|
||||
DBGC ( image, "COM32 %p: exited to run kernel %p\n",
|
||||
image, comboot_replacement_image );
|
||||
image->replacement = comboot_replacement_image;
|
||||
comboot_replacement_image = NULL;
|
||||
image_autoload ( image->replacement );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT_COMMAND:
|
||||
DBGC ( image, "COM32 %p: exited after executing command\n",
|
||||
image );
|
||||
break;
|
||||
|
||||
default:
|
||||
assert ( 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
unhook_comboot_interrupts();
|
||||
comboot_force_text_mode();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image name extension
|
||||
*
|
||||
* @v image COM32 image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int com32_identify ( struct image *image ) {
|
||||
const char *ext;
|
||||
static const uint8_t magic[] = { 0xB8, 0xFF, 0x4C, 0xCD, 0x21 };
|
||||
uint8_t buf[5];
|
||||
|
||||
if ( image->len >= 5 ) {
|
||||
/* Check for magic number
|
||||
* mov eax,21cd4cffh
|
||||
* B8 FF 4C CD 21
|
||||
*/
|
||||
copy_from_user ( buf, image->data, 0, sizeof(buf) );
|
||||
if ( ! memcmp ( buf, magic, sizeof(buf) ) ) {
|
||||
DBGC ( image, "COM32 %p: found magic number\n",
|
||||
image );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Magic number not found; check filename extension */
|
||||
|
||||
ext = strrchr( image->name, '.' );
|
||||
|
||||
if ( ! ext ) {
|
||||
DBGC ( image, "COM32 %p: no extension\n",
|
||||
image );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
++ext;
|
||||
|
||||
if ( strcasecmp( ext, "c32" ) ) {
|
||||
DBGC ( image, "COM32 %p: unrecognized extension %s\n",
|
||||
image, ext );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load COM32 image into memory
|
||||
* @v image COM32 image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_load_image ( struct image *image ) {
|
||||
size_t filesz, memsz;
|
||||
userptr_t buffer;
|
||||
int rc;
|
||||
|
||||
filesz = image->len;
|
||||
memsz = filesz;
|
||||
buffer = phys_to_user ( COM32_START_PHYS );
|
||||
if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
|
||||
DBGC ( image, "COM32 %p: could not prepare segment: %s\n",
|
||||
image, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Copy image to segment */
|
||||
memcpy_user ( buffer, 0, image->data, 0, filesz );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare COM32 low memory bounce buffer
|
||||
* @v image COM32 image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_prepare_bounce_buffer ( struct image * image ) {
|
||||
unsigned int seg;
|
||||
userptr_t seg_userptr;
|
||||
size_t filesz, memsz;
|
||||
int rc;
|
||||
|
||||
seg = COM32_BOUNCE_SEG;
|
||||
seg_userptr = real_to_user ( seg, 0 );
|
||||
|
||||
/* Ensure the entire 64k segment is free */
|
||||
memsz = 0xFFFF;
|
||||
filesz = 0;
|
||||
|
||||
/* Prepare, verify, and load the real-mode segment */
|
||||
if ( ( rc = prep_segment ( seg_userptr, filesz, memsz ) ) != 0 ) {
|
||||
DBGC ( image, "COM32 %p: could not prepare bounce buffer segment: %s\n",
|
||||
image, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load COM32 image into memory
|
||||
*
|
||||
* @v image COM32 image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int com32_load ( struct image *image ) {
|
||||
int rc;
|
||||
|
||||
DBGC ( image, "COM32 %p: name '%s', cmdline '%s'\n",
|
||||
image, image->name, image->cmdline );
|
||||
|
||||
/* Check if this is a COMBOOT image */
|
||||
if ( ( rc = com32_identify ( image ) ) != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* This is a COM32 image, valid or otherwise */
|
||||
if ( ! image->type )
|
||||
image->type = &com32_image_type;
|
||||
|
||||
/* Load image */
|
||||
if ( ( rc = comboot_load_image ( image ) ) != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Prepare bounce buffer segment */
|
||||
if ( ( rc = comboot_prepare_bounce_buffer ( image ) ) != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** SYSLINUX COM32 image type */
|
||||
struct image_type com32_image_type __image_type ( PROBE_NORMAL ) = {
|
||||
.name = "COM32",
|
||||
.load = com32_load,
|
||||
.exec = com32_exec,
|
||||
};
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* SYSLINUX COMBOOT (16-bit) image format
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <realmode.h>
|
||||
#include <basemem.h>
|
||||
#include <comboot.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/segment.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/features.h>
|
||||
|
||||
FEATURE ( FEATURE_IMAGE, "COMBOOT", DHCP_EB_FEATURE_COMBOOT, 1 );
|
||||
|
||||
struct image_type comboot_image_type __image_type ( PROBE_NORMAL );
|
||||
|
||||
/**
|
||||
* COMBOOT PSP, copied to offset 0 of code segment
|
||||
*/
|
||||
struct comboot_psp {
|
||||
/** INT 20 instruction, executed if COMBOOT image returns with RET */
|
||||
uint16_t int20;
|
||||
/** Segment of first non-free paragraph of memory */
|
||||
uint16_t first_non_free_para;
|
||||
};
|
||||
|
||||
/** Offset in PSP of command line */
|
||||
#define COMBOOT_PSP_CMDLINE_OFFSET 0x81
|
||||
|
||||
/** Maximum length of command line in PSP
|
||||
* (127 bytes minus space and CR) */
|
||||
#define COMBOOT_MAX_CMDLINE_LEN 125
|
||||
|
||||
|
||||
/**
|
||||
* Copy command line to PSP
|
||||
*
|
||||
* @v image COMBOOT image
|
||||
*/
|
||||
static void comboot_copy_cmdline ( struct image * image, userptr_t seg_userptr ) {
|
||||
const char *cmdline = ( image->cmdline ? image->cmdline : "" );
|
||||
int cmdline_len = strlen ( cmdline );
|
||||
if( cmdline_len > COMBOOT_MAX_CMDLINE_LEN )
|
||||
cmdline_len = COMBOOT_MAX_CMDLINE_LEN;
|
||||
uint8_t len_byte = cmdline_len;
|
||||
char spc = ' ', cr = '\r';
|
||||
|
||||
/* Copy length to byte before command line */
|
||||
copy_to_user ( seg_userptr, COMBOOT_PSP_CMDLINE_OFFSET - 1,
|
||||
&len_byte, 1 );
|
||||
|
||||
/* Command line starts with space */
|
||||
copy_to_user ( seg_userptr,
|
||||
COMBOOT_PSP_CMDLINE_OFFSET,
|
||||
&spc, 1 );
|
||||
|
||||
/* Copy command line */
|
||||
copy_to_user ( seg_userptr,
|
||||
COMBOOT_PSP_CMDLINE_OFFSET + 1,
|
||||
cmdline, cmdline_len );
|
||||
|
||||
/* Command line ends with CR */
|
||||
copy_to_user ( seg_userptr,
|
||||
COMBOOT_PSP_CMDLINE_OFFSET + cmdline_len + 1,
|
||||
&cr, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize PSP
|
||||
*
|
||||
* @v image COMBOOT image
|
||||
* @v seg_userptr segment to initialize
|
||||
*/
|
||||
static void comboot_init_psp ( struct image * image, userptr_t seg_userptr ) {
|
||||
struct comboot_psp psp;
|
||||
|
||||
/* Fill PSP */
|
||||
|
||||
/* INT 20h instruction, byte order reversed */
|
||||
psp.int20 = 0x20CD;
|
||||
|
||||
/* get_fbms() returns BIOS free base memory counter, which is in
|
||||
* kilobytes; x * 1024 / 16 == x * 64 == x << 6 */
|
||||
psp.first_non_free_para = get_fbms() << 6;
|
||||
|
||||
DBGC ( image, "COMBOOT %p: first non-free paragraph = 0x%x\n",
|
||||
image, psp.first_non_free_para );
|
||||
|
||||
/* Copy the PSP to offset 0 of segment.
|
||||
* The rest of the PSP was already zeroed by
|
||||
* comboot_prepare_segment. */
|
||||
copy_to_user ( seg_userptr, 0, &psp, sizeof( psp ) );
|
||||
|
||||
/* Copy the command line to the PSP */
|
||||
comboot_copy_cmdline ( image, seg_userptr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute COMBOOT image
|
||||
*
|
||||
* @v image COMBOOT image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_exec ( struct image *image ) {
|
||||
userptr_t seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
|
||||
int state;
|
||||
|
||||
state = rmsetjmp ( comboot_return );
|
||||
|
||||
switch ( state ) {
|
||||
case 0: /* First time through; invoke COMBOOT program */
|
||||
|
||||
/* Initialize PSP */
|
||||
comboot_init_psp ( image, seg_userptr );
|
||||
|
||||
/* Hook COMBOOT API interrupts */
|
||||
hook_comboot_interrupts();
|
||||
|
||||
DBGC ( image, "executing 16-bit COMBOOT image at %4x:0100\n",
|
||||
COMBOOT_PSP_SEG );
|
||||
|
||||
/* Unregister image, so that a "boot" command doesn't
|
||||
* throw us into an execution loop. We never
|
||||
* reregister ourselves; COMBOOT images expect to be
|
||||
* removed on exit.
|
||||
*/
|
||||
unregister_image ( image );
|
||||
|
||||
/* Store stack segment at 0x38 and stack pointer at 0x3A
|
||||
* in the PSP and jump to the image */
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE ( /* Save return address with segment on old stack */
|
||||
"popw %%ax\n\t"
|
||||
"pushw %%cs\n\t"
|
||||
"pushw %%ax\n\t"
|
||||
/* Set DS=ES=segment with image */
|
||||
"movw %w0, %%ds\n\t"
|
||||
"movw %w0, %%es\n\t"
|
||||
/* Set SS:SP to new stack (end of image segment) */
|
||||
"movw %w0, %%ss\n\t"
|
||||
"xor %%sp, %%sp\n\t"
|
||||
"pushw $0\n\t"
|
||||
"pushw %w0\n\t"
|
||||
"pushw $0x100\n\t"
|
||||
/* Zero registers (some COM files assume GP regs are 0) */
|
||||
"xorw %%ax, %%ax\n\t"
|
||||
"xorw %%bx, %%bx\n\t"
|
||||
"xorw %%cx, %%cx\n\t"
|
||||
"xorw %%dx, %%dx\n\t"
|
||||
"xorw %%si, %%si\n\t"
|
||||
"xorw %%di, %%di\n\t"
|
||||
"xorw %%bp, %%bp\n\t"
|
||||
"lret\n\t" )
|
||||
: : "r" ( COMBOOT_PSP_SEG ) : "eax" );
|
||||
DBGC ( image, "COMBOOT %p: returned\n", image );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT:
|
||||
DBGC ( image, "COMBOOT %p: exited\n", image );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT_RUN_KERNEL:
|
||||
DBGC ( image, "COMBOOT %p: exited to run kernel %p\n",
|
||||
image, comboot_replacement_image );
|
||||
image->replacement = comboot_replacement_image;
|
||||
comboot_replacement_image = NULL;
|
||||
image_autoload ( image->replacement );
|
||||
break;
|
||||
|
||||
case COMBOOT_EXIT_COMMAND:
|
||||
DBGC ( image, "COMBOOT %p: exited after executing command\n",
|
||||
image );
|
||||
break;
|
||||
|
||||
default:
|
||||
assert ( 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
unhook_comboot_interrupts();
|
||||
comboot_force_text_mode();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image name extension
|
||||
*
|
||||
* @v image COMBOOT image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_identify ( struct image *image ) {
|
||||
const char *ext;
|
||||
|
||||
ext = strrchr( image->name, '.' );
|
||||
|
||||
if ( ! ext ) {
|
||||
DBGC ( image, "COMBOOT %p: no extension\n",
|
||||
image );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
++ext;
|
||||
|
||||
if ( strcasecmp( ext, "com" ) && strcasecmp( ext, "cbt" ) ) {
|
||||
DBGC ( image, "COMBOOT %p: unrecognized extension %s\n",
|
||||
image, ext );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load COMBOOT image into memory, preparing a segment and returning it
|
||||
* @v image COMBOOT image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_prepare_segment ( struct image *image )
|
||||
{
|
||||
userptr_t seg_userptr;
|
||||
size_t filesz, memsz;
|
||||
int rc;
|
||||
|
||||
/* Load image in segment */
|
||||
seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
|
||||
|
||||
/* Allow etra 0x100 bytes before image for PSP */
|
||||
filesz = image->len + 0x100;
|
||||
|
||||
/* Ensure the entire 64k segment is free */
|
||||
memsz = 0xFFFF;
|
||||
|
||||
/* Prepare, verify, and load the real-mode segment */
|
||||
if ( ( rc = prep_segment ( seg_userptr, filesz, memsz ) ) != 0 ) {
|
||||
DBGC ( image, "COMBOOT %p: could not prepare segment: %s\n",
|
||||
image, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Zero PSP */
|
||||
memset_user ( seg_userptr, 0, 0, 0x100 );
|
||||
|
||||
/* Copy image to segment:0100 */
|
||||
memcpy_user ( seg_userptr, 0x100, image->data, 0, image->len );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load COMBOOT image into memory
|
||||
*
|
||||
* @v image COMBOOT image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int comboot_load ( struct image *image ) {
|
||||
int rc;
|
||||
|
||||
DBGC ( image, "COMBOOT %p: name '%s'\n",
|
||||
image, image->name );
|
||||
|
||||
/* Check if this is a COMBOOT image */
|
||||
if ( ( rc = comboot_identify ( image ) ) != 0 ) {
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* This is a 16-bit COMBOOT image, valid or otherwise */
|
||||
if ( ! image->type )
|
||||
image->type = &comboot_image_type;
|
||||
|
||||
/* Sanity check for filesize */
|
||||
if( image->len >= 0xFF00 ) {
|
||||
DBGC( image, "COMBOOT %p: image too large\n",
|
||||
image );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Prepare segment and load image */
|
||||
if ( ( rc = comboot_prepare_segment ( image ) ) != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** SYSLINUX COMBOOT (16-bit) image type */
|
||||
struct image_type comboot_image_type __image_type ( PROBE_NORMAL ) = {
|
||||
.name = "COMBOOT",
|
||||
.load = comboot_load,
|
||||
.exec = comboot_exec,
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <elf.h>
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/elf.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/init.h>
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* ELF bootable image
|
||||
*
|
||||
*/
|
||||
|
||||
FEATURE ( FEATURE_IMAGE, "ELF", DHCP_EB_FEATURE_ELF, 1 );
|
||||
|
||||
struct image_type elfboot_image_type __image_type ( PROBE_NORMAL );
|
||||
|
||||
/**
|
||||
* Execute ELF image
|
||||
*
|
||||
* @v image ELF image
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int elfboot_exec ( struct image *image ) {
|
||||
physaddr_t entry = image->priv.phys;
|
||||
|
||||
/* An ELF image has no callback interface, so we need to shut
|
||||
* down before invoking it.
|
||||
*/
|
||||
shutdown ( SHUTDOWN_BOOT );
|
||||
|
||||
/* Jump to OS with flat physical addressing */
|
||||
DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );
|
||||
__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
|
||||
: : "D" ( entry )
|
||||
: "eax", "ebx", "ecx", "edx", "esi", "ebp",
|
||||
"memory" );
|
||||
|
||||
DBGC ( image, "ELF %p returned\n", image );
|
||||
|
||||
/* It isn't safe to continue after calling shutdown() */
|
||||
while ( 1 ) {}
|
||||
|
||||
return -ECANCELED; /* -EIMPOSSIBLE, anyone? */
|
||||
}
|
||||
|
||||
/**
|
||||
* Load ELF image into memory
|
||||
*
|
||||
* @v image ELF file
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int elfboot_load ( struct image *image ) {
|
||||
Elf32_Ehdr ehdr;
|
||||
static const uint8_t e_ident[] = {
|
||||
[EI_MAG0] = ELFMAG0,
|
||||
[EI_MAG1] = ELFMAG1,
|
||||
[EI_MAG2] = ELFMAG2,
|
||||
[EI_MAG3] = ELFMAG3,
|
||||
[EI_CLASS] = ELFCLASS32,
|
||||
[EI_DATA] = ELFDATA2LSB,
|
||||
[EI_VERSION] = EV_CURRENT,
|
||||
};
|
||||
int rc;
|
||||
|
||||
/* Read ELF header */
|
||||
copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
|
||||
if ( memcmp ( ehdr.e_ident, e_ident, sizeof ( e_ident ) ) != 0 ) {
|
||||
DBG ( "Invalid ELF identifier\n" );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* This is an ELF image, valid or otherwise */
|
||||
if ( ! image->type )
|
||||
image->type = &elfboot_image_type;
|
||||
|
||||
/* Load the image using core ELF support */
|
||||
if ( ( rc = elf_load ( image ) ) != 0 ) {
|
||||
DBGC ( image, "ELF %p could not load: %s\n",
|
||||
image, strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** ELF image type */
|
||||
struct image_type elfboot_image_type __image_type ( PROBE_NORMAL ) = {
|
||||
.name = "ELF",
|
||||
.load = elfboot_load,
|
||||
.exec = elfboot_exec,
|
||||
};
|
||||
@@ -220,7 +220,7 @@ multiboot_build_module_list ( struct image *image,
|
||||
|
||||
/* Dump module configuration */
|
||||
for ( i = 0 ; i < count ; i++ ) {
|
||||
DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n",
|
||||
DBGC ( image, "MULTIBOOT %p module %d is [%x,%x)\n",
|
||||
image, i, modules[i].mod_start,
|
||||
modules[i].mod_end );
|
||||
}
|
||||
@@ -277,14 +277,18 @@ static int multiboot_exec ( struct image *image ) {
|
||||
/* Multiboot images may not return and have no callback
|
||||
* interface, so shut everything down prior to booting the OS.
|
||||
*/
|
||||
shutdown();
|
||||
shutdown ( SHUTDOWN_BOOT );
|
||||
|
||||
/* Jump to OS with flat physical addressing */
|
||||
__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
|
||||
DBGC ( image, "MULTIBOOT %p starting execution at %lx\n",
|
||||
image, entry );
|
||||
__asm__ __volatile__ ( PHYS_CODE ( "pushl %%ebp\n\t"
|
||||
"call *%%edi\n\t"
|
||||
"popl %%ebp\n\t" )
|
||||
: : "a" ( MULTIBOOT_BOOTLOADER_MAGIC ),
|
||||
"b" ( virt_to_phys ( &mbinfo ) ),
|
||||
"D" ( entry )
|
||||
: "ecx", "edx", "esi", "ebp", "memory" );
|
||||
: "ecx", "edx", "esi", "memory" );
|
||||
|
||||
DBGC ( image, "MULTIBOOT %p returned\n", image );
|
||||
|
||||
@@ -358,8 +362,11 @@ static int multiboot_load_raw ( struct image *image,
|
||||
|
||||
/* Verify and prepare segment */
|
||||
offset = ( hdr->offset - hdr->mb.header_addr + hdr->mb.load_addr );
|
||||
filesz = ( hdr->mb.load_end_addr - hdr->mb.load_addr );
|
||||
memsz = ( hdr->mb.bss_end_addr - hdr->mb.load_addr );
|
||||
filesz = ( hdr->mb.load_end_addr ?
|
||||
( hdr->mb.load_end_addr - hdr->mb.load_addr ) :
|
||||
( image->len - offset ) );
|
||||
memsz = ( hdr->mb.bss_end_addr ?
|
||||
( hdr->mb.bss_end_addr - hdr->mb.load_addr ) : filesz );
|
||||
buffer = phys_to_user ( hdr->mb.load_addr );
|
||||
if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
|
||||
DBGC ( image, "MULTIBOOT %p could not prepare segment: %s\n",
|
||||
@@ -411,7 +418,7 @@ static int multiboot_load ( struct image *image ) {
|
||||
image );
|
||||
return rc;
|
||||
}
|
||||
DBGC ( image, "MULTIBOOT %p found header with flags %08lx\n",
|
||||
DBGC ( image, "MULTIBOOT %p found header with flags %08x\n",
|
||||
image, hdr.mb.flags );
|
||||
|
||||
/* This is a multiboot image, valid or otherwise */
|
||||
@@ -420,7 +427,7 @@ static int multiboot_load ( struct image *image ) {
|
||||
|
||||
/* Abort if we detect flags that we cannot support */
|
||||
if ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) {
|
||||
DBGC ( image, "MULTIBOOT %p flags %08lx not supported\n",
|
||||
DBGC ( image, "MULTIBOOT %p flags %08x not supported\n",
|
||||
image, ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <gpxe/segment.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/fakedhcp.h>
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/features.h>
|
||||
|
||||
@@ -366,22 +366,6 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess boot network device
|
||||
*
|
||||
* @ret netdev Boot network device
|
||||
*/
|
||||
static struct net_device * guess_boot_netdev ( void ) {
|
||||
struct net_device *boot_netdev;
|
||||
|
||||
/* Just use the first network device */
|
||||
for_each_netdev ( boot_netdev ) {
|
||||
return boot_netdev;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare DHCP parameter block for NBI image
|
||||
*
|
||||
@@ -389,21 +373,18 @@ static struct net_device * guess_boot_netdev ( void ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int nbi_prepare_dhcp ( struct image *image ) {
|
||||
struct dhcp_packet dhcppkt;
|
||||
struct net_device *boot_netdev;
|
||||
int rc;
|
||||
|
||||
boot_netdev = guess_boot_netdev();
|
||||
boot_netdev = last_opened_netdev();
|
||||
if ( ! boot_netdev ) {
|
||||
DBGC ( image, "NBI %p could not identify a network device\n",
|
||||
image );
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if ( ( rc = create_dhcp_response ( boot_netdev, DHCPACK, NULL,
|
||||
basemem_packet,
|
||||
sizeof ( basemem_packet ),
|
||||
&dhcppkt ) ) != 0 ) {
|
||||
if ( ( rc = create_fakedhcpack ( boot_netdev, basemem_packet,
|
||||
sizeof ( basemem_packet ) ) ) != 0 ) {
|
||||
DBGC ( image, "NBI %p failed to build DHCP packet\n", image );
|
||||
return rc;
|
||||
}
|
||||
@@ -432,7 +413,7 @@ static int nbi_exec ( struct image *image ) {
|
||||
/* Shut down now if NBI image will not return */
|
||||
may_return = NBI_PROGRAM_RETURNS ( imgheader.flags );
|
||||
if ( ! may_return )
|
||||
shutdown();
|
||||
shutdown ( SHUTDOWN_BOOT );
|
||||
|
||||
/* Execute NBI image */
|
||||
if ( NBI_LINEAR_EXEC_ADDR ( imgheader.flags ) ) {
|
||||
|
||||
@@ -42,18 +42,14 @@ struct image_type pxe_image_type __image_type ( PROBE_PXE );
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int pxe_exec ( struct image *image ) {
|
||||
struct net_device *netdev;
|
||||
int rc;
|
||||
|
||||
/* Ensure that PXE stack is ready to use */
|
||||
pxe_init_structures();
|
||||
pxe_hook_int1a();
|
||||
|
||||
/* Arbitrarily pick the first open network device to use for PXE */
|
||||
for_each_netdev ( netdev ) {
|
||||
pxe_set_netdev ( netdev );
|
||||
break;
|
||||
}
|
||||
/* Arbitrarily pick the most recently opened network device */
|
||||
pxe_set_netdev ( last_opened_netdev() );
|
||||
|
||||
/* Many things will break if pxe_netdev is NULL */
|
||||
if ( ! pxe_netdev ) {
|
||||
@@ -84,6 +80,20 @@ int pxe_load ( struct image *image ) {
|
||||
size_t memsz = image->len;
|
||||
int rc;
|
||||
|
||||
/* Images too large to fit in base memory cannot be PXE
|
||||
* images. We include this check to help prevent unrecognised
|
||||
* images from being marked as PXE images, since PXE images
|
||||
* have no signature we can check against.
|
||||
*/
|
||||
if ( filesz > ( 0xa0000 - 0x7c00 ) )
|
||||
return -ENOEXEC;
|
||||
|
||||
/* Rejecting zero-length images is also useful, since these
|
||||
* end up looking to the user like bugs in gPXE.
|
||||
*/
|
||||
if ( ! filesz )
|
||||
return -ENOEXEC;
|
||||
|
||||
/* There are no signature checks for PXE; we will accept anything */
|
||||
if ( ! image->type )
|
||||
image->type = &pxe_image_type;
|
||||
|
||||
@@ -5,7 +5,4 @@
|
||||
#define BDA_FBMS 0x0013
|
||||
#define BDA_NUM_DRIVES 0x0075
|
||||
|
||||
extern unsigned long currticks ( void );
|
||||
extern void cpu_nap ( void );
|
||||
|
||||
#endif /* BIOS_H */
|
||||
|
||||
@@ -6,9 +6,22 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <realmode.h>
|
||||
|
||||
struct segoff;
|
||||
|
||||
extern int hooked_bios_interrupts;
|
||||
/**
|
||||
* Hooked interrupt count
|
||||
*
|
||||
* At exit, after unhooking all possible interrupts, this counter
|
||||
* should be examined. If it is non-zero, it means that we failed to
|
||||
* unhook at least one interrupt vector, and so must not free up the
|
||||
* memory we are using. (Note that this also implies that we should
|
||||
* re-hook INT 15 in order to hide ourselves from the memory map).
|
||||
*/
|
||||
extern uint16_t __text16 ( hooked_bios_interrupts );
|
||||
#define hooked_bios_interrupts __use_text16 ( hooked_bios_interrupts )
|
||||
|
||||
extern void hook_bios_interrupt ( unsigned int interrupt, unsigned int handler,
|
||||
struct segoff *chain_vector );
|
||||
extern int unhook_bios_interrupt ( unsigned int interrupt,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define ETHERBOOT_BITS_BYTESWAP_H
|
||||
|
||||
static inline __attribute__ ((always_inline, const)) uint16_t
|
||||
__i386_bswap_16(uint16_t x)
|
||||
__bswap_variable_16(uint16_t x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0\n\t"
|
||||
: "=q" (x)
|
||||
@@ -11,7 +11,7 @@ __i386_bswap_16(uint16_t x)
|
||||
}
|
||||
|
||||
static inline __attribute__ ((always_inline, const)) uint32_t
|
||||
__i386_bswap_32(uint32_t x)
|
||||
__bswap_variable_32(uint32_t x)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0\n\t"
|
||||
"rorl $16,%0\n\t"
|
||||
@@ -22,7 +22,7 @@ __i386_bswap_32(uint32_t x)
|
||||
}
|
||||
|
||||
static inline __attribute__ ((always_inline, const)) uint64_t
|
||||
__i386_bswap_64(uint64_t x)
|
||||
__bswap_variable_64(uint64_t x)
|
||||
{
|
||||
union {
|
||||
uint64_t qword;
|
||||
@@ -30,47 +30,12 @@ __i386_bswap_64(uint64_t x)
|
||||
} u;
|
||||
|
||||
u.qword = x;
|
||||
u.dword[0] = __i386_bswap_32(u.dword[0]);
|
||||
u.dword[1] = __i386_bswap_32(u.dword[1]);
|
||||
u.dword[0] = __bswap_variable_32(u.dword[0]);
|
||||
u.dword[1] = __bswap_variable_32(u.dword[1]);
|
||||
__asm__("xchgl %0,%1"
|
||||
: "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
|
||||
: "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
|
||||
return u.qword;
|
||||
}
|
||||
|
||||
#define __bswap_constant_16(x) \
|
||||
((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
|
||||
(((uint16_t)(x) & 0xff00) >> 8)))
|
||||
|
||||
#define __bswap_constant_32(x) \
|
||||
((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
|
||||
(((uint32_t)(x) & 0x0000ff00U) << 8) | \
|
||||
(((uint32_t)(x) & 0x00ff0000U) >> 8) | \
|
||||
(((uint32_t)(x) & 0xff000000U) >> 24)))
|
||||
|
||||
#define __bswap_constant_64(x) \
|
||||
((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
|
||||
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
|
||||
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
|
||||
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
|
||||
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
|
||||
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
|
||||
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
|
||||
(((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))
|
||||
|
||||
#define __bswap_16(x) \
|
||||
((uint16_t)(__builtin_constant_p(x) ? \
|
||||
__bswap_constant_16(x) : \
|
||||
__i386_bswap_16(x)))
|
||||
|
||||
#define __bswap_32(x) \
|
||||
((uint32_t)(__builtin_constant_p(x) ? \
|
||||
__bswap_constant_32(x) : \
|
||||
__i386_bswap_32(x)))
|
||||
|
||||
#define __bswap_64(x) \
|
||||
((uint64_t)(__builtin_constant_p(x) ? \
|
||||
__bswap_constant_64(x) : \
|
||||
__i386_bswap_64(x)))
|
||||
|
||||
#endif /* ETHERBOOT_BITS_BYTESWAP_H */
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef _BITS_COMPILER_H
|
||||
#define _BITS_COMPILER_H
|
||||
|
||||
#ifndef ASSEMBLY
|
||||
|
||||
/** Declare a function with standard calling conventions */
|
||||
#define __asmcall __attribute__ (( cdecl, regparm(0) ))
|
||||
|
||||
/**
|
||||
* Declare a function with libgcc implicit linkage
|
||||
*
|
||||
* It seems as though gcc expects its implicit arithmetic functions to
|
||||
* be cdecl, even if -mrtd is specified. This is somewhat
|
||||
* inconsistent; for example, if -mregparm=3 is used then the implicit
|
||||
* functions do become regparm(3).
|
||||
*
|
||||
* The implicit calls to memcpy() and memset() which gcc can generate
|
||||
* do not seem to have this inconsistency; -mregparm and -mrtd affect
|
||||
* them in the same way as any other function.
|
||||
*/
|
||||
#define __libgcc __attribute__ (( cdecl ))
|
||||
|
||||
#endif /* ASSEMBLY */
|
||||
|
||||
#endif /* _BITS_COMPILER_H */
|
||||
@@ -1,91 +0,0 @@
|
||||
#ifndef I386_BITS_ELF_H
|
||||
#define I386_BITS_ELF_H
|
||||
|
||||
#include "cpu.h"
|
||||
|
||||
#ifdef CONFIG_X86_64
|
||||
/* ELF Defines for the 64bit version of the current architecture */
|
||||
#define EM_CURRENT_64 EM_X86_64
|
||||
#define EM_CURRENT_64_PRESENT ( \
|
||||
CPU_FEATURE_P(cpu_info.x86_capability, LM) && \
|
||||
CPU_FEATURE_P(cpu_info.x86_capability, PAE) && \
|
||||
CPU_FEATURE_P(cpu_info.x86_capability, PSE))
|
||||
|
||||
#define ELF_CHECK_X86_64_ARCH(x) \
|
||||
(EM_CURRENT_64_PRESENT && ((x).e_machine == EM_X86_64))
|
||||
#define __unused_i386
|
||||
#else
|
||||
#define ELF_CHECK_X86_64_ARCH(x) 0
|
||||
#define __unused_i386 __unused
|
||||
#endif
|
||||
|
||||
|
||||
/* ELF Defines for the current architecture */
|
||||
#define EM_CURRENT EM_386
|
||||
#define ELFDATA_CURRENT ELFDATA2LSB
|
||||
|
||||
#define ELF_CHECK_I386_ARCH(x) \
|
||||
(((x).e_machine == EM_386) || ((x).e_machine == EM_486))
|
||||
|
||||
#define ELF_CHECK_ARCH(x) \
|
||||
((ELF_CHECK_I386_ARCH(x) || ELF_CHECK_X86_64_ARCH(x)) && \
|
||||
((x).e_entry <= 0xffffffffUL))
|
||||
|
||||
#ifdef IMAGE_FREEBSD
|
||||
/*
|
||||
* FreeBSD has this rather strange "feature" of its design.
|
||||
* At some point in its evolution, FreeBSD started to rely
|
||||
* externally on private/static/debug internal symbol information.
|
||||
* That is, some of the interfaces that software uses to access
|
||||
* and work with the FreeBSD kernel are made available not
|
||||
* via the shared library symbol information (the .DYNAMIC section)
|
||||
* but rather the debug symbols. This means that any symbol, not
|
||||
* just publicly defined symbols can be (and are) used by system
|
||||
* tools to make the system work. (such as top, swapinfo, swapon,
|
||||
* etc)
|
||||
*
|
||||
* Even worse, however, is the fact that standard ELF loaders do
|
||||
* not know how to load the symbols since they are not within
|
||||
* an ELF PT_LOAD section. The kernel needs these symbols to
|
||||
* operate so the following changes/additions to the boot
|
||||
* loading of EtherBoot have been made to get the kernel to load.
|
||||
* All of the changes are within IMAGE_FREEBSD such that the
|
||||
* extra/changed code only compiles when FREEBSD support is
|
||||
* enabled.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Section header for FreeBSD (debug symbol kludge!) support
|
||||
*/
|
||||
typedef struct {
|
||||
Elf32_Word sh_name; /* Section name (index into the
|
||||
section header string table). */
|
||||
Elf32_Word sh_type; /* Section type. */
|
||||
Elf32_Word sh_flags; /* Section flags. */
|
||||
Elf32_Addr sh_addr; /* Address in memory image. */
|
||||
Elf32_Off sh_offset; /* Offset in file. */
|
||||
Elf32_Size sh_size; /* Size in bytes. */
|
||||
Elf32_Word sh_link; /* Index of a related section. */
|
||||
Elf32_Word sh_info; /* Depends on section type. */
|
||||
Elf32_Size sh_addralign; /* Alignment in bytes. */
|
||||
Elf32_Size sh_entsize; /* Size of each entry in section. */
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
|
||||
/*
|
||||
* Module information subtypes (for the metadata that we need to build)
|
||||
*/
|
||||
#define MODINFO_END 0x0000 /* End of list */
|
||||
#define MODINFO_NAME 0x0001 /* Name of module (string) */
|
||||
#define MODINFO_TYPE 0x0002 /* Type of module (string) */
|
||||
#define MODINFO_METADATA 0x8000 /* Module-specfic */
|
||||
|
||||
#define MODINFOMD_SSYM 0x0003 /* start of symbols */
|
||||
#define MODINFOMD_ESYM 0x0004 /* end of symbols */
|
||||
|
||||
#endif /* IMAGE_FREEBSD */
|
||||
|
||||
#endif /* I386_BITS_ELF_H */
|
||||
@@ -1,5 +0,0 @@
|
||||
#define ARCH_ELF_CLASS ELFCLASS32
|
||||
#define ARCH_ELF_DATA ELFDATA2LSB
|
||||
#define ARCH_ELF_MACHINE_OK(x) ((x)==EM_386 || (x)==EM_486)
|
||||
typedef Elf32_Ehdr Elf_ehdr;
|
||||
typedef Elf32_Phdr Elf_phdr;
|
||||
@@ -3,7 +3,4 @@
|
||||
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
|
||||
#define le32_to_cpup(x) (*(uint32_t *)(x))
|
||||
#define cpu_to_le16p(x) (*(uint16_t*)(x))
|
||||
|
||||
#endif /* ETHERBOOT_BITS_ENDIAN_H */
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define ERRFILE_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
|
||||
#define ERRFILE_memtop_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
|
||||
#define ERRFILE_memmap ( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 )
|
||||
#define ERRFILE_pnpbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 )
|
||||
#define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
|
||||
#define ERRFILE_bios_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
|
||||
#define ERRFILE_biosint ( ERRFILE_ARCH | ERRFILE_CORE | 0x00040000 )
|
||||
#define ERRFILE_int13 ( ERRFILE_ARCH | ERRFILE_CORE | 0x00050000 )
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
#define ERRFILE_multiboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00030000 )
|
||||
#define ERRFILE_nbi ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00040000 )
|
||||
#define ERRFILE_pxe_image ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00050000 )
|
||||
#define ERRFILE_elfboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00060000 )
|
||||
#define ERRFILE_comboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00070000 )
|
||||
#define ERRFILE_com32 ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00080000 )
|
||||
#define ERRFILE_comboot_resolv ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00090000 )
|
||||
#define ERRFILE_comboot_call ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x000a0000 )
|
||||
|
||||
#define ERRFILE_undi ( ERRFILE_ARCH | ERRFILE_NET | 0x00000000 )
|
||||
#define ERRFILE_undiload ( ERRFILE_ARCH | ERRFILE_NET | 0x00010000 )
|
||||
@@ -26,6 +31,9 @@
|
||||
#define ERRFILE_undionly ( ERRFILE_ARCH | ERRFILE_NET | 0x00030000 )
|
||||
#define ERRFILE_undirom ( ERRFILE_ARCH | ERRFILE_NET | 0x00040000 )
|
||||
|
||||
#define ERRFILE_timer_rdtsc ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00000000 )
|
||||
#define ERRFILE_timer_bios ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00010000 )
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _BITS_ERRFILE_H */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _BITS_IO_H
|
||||
#define _BITS_IO_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* i386-specific I/O API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/x86_io.h>
|
||||
|
||||
#endif /* _BITS_IO_H */
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _BITS_NAP_H
|
||||
#define _BITS_NAP_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* i386-specific CPU sleeping API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/bios_nap.h>
|
||||
#include <gpxe/efi/efix86_nap.h>
|
||||
|
||||
#endif /* _BITS_MAP_H */
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _BITS_SMBIOS_H
|
||||
#define _BITS_SMBIOS_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* i386-specific SMBIOS API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/bios_smbios.h>
|
||||
|
||||
#endif /* _BITS_SMBIOS_H */
|
||||
@@ -1,18 +1,18 @@
|
||||
#ifndef _BITS_STDINT_H
|
||||
#define _BITS_STDINT_H
|
||||
|
||||
typedef typeof(sizeof(int)) size_t;
|
||||
typedef signed long ssize_t;
|
||||
typedef unsigned int size_t;
|
||||
typedef signed int ssize_t;
|
||||
typedef signed long off_t;
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed long int32_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed long long int64_t;
|
||||
|
||||
typedef unsigned long physaddr_t;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _BITS_TIMER_H
|
||||
#define _BITS_TIMER_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* i386-specific timer API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/bios_timer.h>
|
||||
#include <gpxe/rdtsc_timer.h>
|
||||
|
||||
#endif /* _BITS_TIMER_H */
|
||||
@@ -1,6 +1,12 @@
|
||||
#ifndef _BITS_UACCESS_H
|
||||
#define _BITS_UACCESS_H
|
||||
|
||||
#include <realmode.h>
|
||||
/** @file
|
||||
*
|
||||
* i386-specific user access API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
#endif /* _BITS_UACCESS_H */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _BITS_UMALLOC_H
|
||||
#define _BITS_UMALLOC_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* i386-specific user memory allocation API implementations
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gpxe/memtop_umalloc.h>
|
||||
|
||||
#endif /* _BITS_UMALLOC_H */
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef _I386_UUID_H
|
||||
#define _I386_UUID_H
|
||||
|
||||
#include <smbios.h>
|
||||
|
||||
static inline int get_uuid ( union uuid *uuid ) {
|
||||
return smbios_get_uuid ( uuid );
|
||||
}
|
||||
|
||||
#endif /* _I386_UUID_H */
|
||||
@@ -62,6 +62,14 @@ struct bzimage_header {
|
||||
uint32_t cmd_line_ptr;
|
||||
/** Highest legal initrd address */
|
||||
uint32_t initrd_addr_max;
|
||||
/** Physical addr alignment required for kernel */
|
||||
uint32_t kernel_alignment;
|
||||
/** Whether kernel is relocatable or not */
|
||||
uint8_t relocatable_kernel;
|
||||
/** Unused */
|
||||
uint8_t pad2[3];
|
||||
/** Maximum size of the kernel command line */
|
||||
uint32_t cmdline_size;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
/** Offset of bzImage header within kernel image */
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
#ifndef COMBOOT_H
|
||||
#define COMBOOT_H
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* SYSLINUX COMBOOT
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <gpxe/in.h>
|
||||
|
||||
/** Segment used for COMBOOT PSP and image */
|
||||
#define COMBOOT_PSP_SEG 0x07C0
|
||||
|
||||
/** Entry point address of COM32 images */
|
||||
#define COM32_START_PHYS 0x101000
|
||||
|
||||
/** COM32 bounce buffer segment */
|
||||
#define COM32_BOUNCE_SEG 0x07C0
|
||||
|
||||
/** Size of SYSLINUX file block in bytes */
|
||||
#define COMBOOT_FILE_BLOCKSZ 512
|
||||
|
||||
/** COMBOOT feature flags (INT 22h AX=15h) */
|
||||
#define COMBOOT_FEATURE_LOCAL_BOOT (1 << 0)
|
||||
#define COMBOOT_FEATURE_IDLE_LOOP (1 << 1)
|
||||
|
||||
/** Maximum number of shuffle descriptors for
|
||||
* shuffle and boot functions
|
||||
* (INT 22h AX=0012h, 001Ah, 001Bh)
|
||||
*/
|
||||
#define COMBOOT_MAX_SHUFFLE_DESCRIPTORS 682
|
||||
|
||||
typedef union {
|
||||
uint32_t l;
|
||||
uint16_t w[2];
|
||||
uint8_t b[4];
|
||||
} com32_reg32_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t gs; /* Offset 0 */
|
||||
uint16_t fs; /* Offset 2 */
|
||||
uint16_t es; /* Offset 4 */
|
||||
uint16_t ds; /* Offset 6 */
|
||||
|
||||
com32_reg32_t edi; /* Offset 8 */
|
||||
com32_reg32_t esi; /* Offset 12 */
|
||||
com32_reg32_t ebp; /* Offset 16 */
|
||||
com32_reg32_t _unused_esp; /* Offset 20 */
|
||||
com32_reg32_t ebx; /* Offset 24 */
|
||||
com32_reg32_t edx; /* Offset 28 */
|
||||
com32_reg32_t ecx; /* Offset 32 */
|
||||
com32_reg32_t eax; /* Offset 36 */
|
||||
|
||||
com32_reg32_t eflags; /* Offset 40 */
|
||||
} com32sys_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t eax; /* Offset 0 */
|
||||
uint32_t ecx; /* Offset 4 */
|
||||
uint32_t edx; /* Offset 8 */
|
||||
uint32_t ebx; /* Offset 12 */
|
||||
uint32_t esp; /* Offset 16 */
|
||||
uint32_t ebp; /* Offset 20 */
|
||||
uint32_t esi; /* Offset 24 */
|
||||
uint32_t edi; /* Offset 28 */
|
||||
|
||||
uint32_t eip; /* Offset 32 */
|
||||
} syslinux_pm_regs;
|
||||
|
||||
typedef struct {
|
||||
uint16_t es; /* Offset 0 */
|
||||
uint16_t _unused_cs; /* Offset 2 */
|
||||
uint16_t ds; /* Offset 4 */
|
||||
uint16_t ss; /* Offset 6 */
|
||||
uint16_t fs; /* Offset 8 */
|
||||
uint16_t gs; /* Offset 10 */
|
||||
|
||||
uint32_t eax; /* Offset 12 */
|
||||
uint32_t ecx; /* Offset 16 */
|
||||
uint32_t edx; /* Offset 20 */
|
||||
uint32_t ebx; /* Offset 24 */
|
||||
uint32_t esp; /* Offset 28 */
|
||||
uint32_t ebp; /* Offset 32 */
|
||||
uint32_t esi; /* Offset 36 */
|
||||
uint32_t edi; /* Offset 40 */
|
||||
|
||||
uint16_t ip; /* Offset 44 */
|
||||
uint16_t cs; /* Offset 46 */
|
||||
} syslinux_rm_regs;
|
||||
|
||||
typedef struct {
|
||||
uint32_t dest;
|
||||
uint32_t src;
|
||||
uint32_t len;
|
||||
} comboot_shuffle_descriptor;
|
||||
|
||||
extern void hook_comboot_interrupts ( );
|
||||
extern void unhook_comboot_interrupts ( );
|
||||
|
||||
/* These are not the correct prototypes, but it doens't matter,
|
||||
* as we only ever get the address of these functions;
|
||||
* they are only called from COM32 code running in PHYS_CODE
|
||||
*/
|
||||
extern void com32_intcall_wrapper ( );
|
||||
extern void com32_farcall_wrapper ( );
|
||||
extern void com32_cfarcall_wrapper ( );
|
||||
|
||||
/* Resolve a hostname to an (IPv4) address */
|
||||
extern int comboot_resolv ( const char *name, struct in_addr *address );
|
||||
|
||||
/* setjmp/longjmp context buffer used to return after loading an image */
|
||||
extern rmjmp_buf comboot_return;
|
||||
|
||||
/* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
|
||||
extern struct image *comboot_replacement_image;
|
||||
|
||||
extern void *com32_external_esp;
|
||||
|
||||
#define COMBOOT_EXIT 1
|
||||
#define COMBOOT_EXIT_RUN_KERNEL 2
|
||||
#define COMBOOT_EXIT_COMMAND 3
|
||||
|
||||
extern void comboot_force_text_mode ( void );
|
||||
|
||||
#define COMBOOT_VIDEO_GRAPHICS 0x01
|
||||
#define COMBOOT_VIDEO_NONSTANDARD 0x02
|
||||
#define COMBOOT_VIDEO_VESA 0x04
|
||||
#define COMBOOT_VIDEO_NOTEXT 0x08
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef _FAKEE820_H
|
||||
#define _FAKEE820_H
|
||||
|
||||
extern void fake_e820 ( void );
|
||||
extern void unfake_e820 ( void );
|
||||
|
||||
#endif /* _FAKEE820_H */
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef GDBMACH_H
|
||||
#define GDBMACH_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* GDB architecture specifics
|
||||
*
|
||||
* This file declares functions for manipulating the machine state and
|
||||
* debugging context.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned long gdbreg_t;
|
||||
|
||||
/* The register snapshot, this must be in sync with interrupt handler and the
|
||||
* GDB protocol. */
|
||||
enum {
|
||||
GDBMACH_EAX,
|
||||
GDBMACH_ECX,
|
||||
GDBMACH_EDX,
|
||||
GDBMACH_EBX,
|
||||
GDBMACH_ESP,
|
||||
GDBMACH_EBP,
|
||||
GDBMACH_ESI,
|
||||
GDBMACH_EDI,
|
||||
GDBMACH_EIP,
|
||||
GDBMACH_EFLAGS,
|
||||
GDBMACH_CS,
|
||||
GDBMACH_SS,
|
||||
GDBMACH_DS,
|
||||
GDBMACH_ES,
|
||||
GDBMACH_FS,
|
||||
GDBMACH_GS,
|
||||
GDBMACH_NREGS,
|
||||
GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
|
||||
};
|
||||
|
||||
/* Breakpoint types */
|
||||
enum {
|
||||
GDBMACH_BPMEM,
|
||||
GDBMACH_BPHW,
|
||||
GDBMACH_WATCH,
|
||||
GDBMACH_RWATCH,
|
||||
GDBMACH_AWATCH,
|
||||
};
|
||||
|
||||
static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
|
||||
regs [ GDBMACH_EIP ] = pc;
|
||||
}
|
||||
|
||||
static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
|
||||
regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
|
||||
regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
|
||||
}
|
||||
|
||||
static inline void gdbmach_breakpoint ( void ) {
|
||||
__asm__ __volatile__ ( "int $3\n" );
|
||||
}
|
||||
|
||||
extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable );
|
||||
|
||||
#endif /* GDBMACH_H */
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef _GPXE_BIOS_NAP_H
|
||||
#define _GPXE_BIOS_NAP_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* BIOS CPU sleeping
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef NAP_PCBIOS
|
||||
#define NAP_PREFIX_pcbios
|
||||
#else
|
||||
#define NAP_PREFIX_pcbios __pcbios_
|
||||
#endif
|
||||
|
||||
#endif /* _GPXE_BIOS_NAP_H */
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef _GPXE_BIOS_SMBIOS_H
|
||||
#define _GPXE_BIOS_SMBIOS_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Standard PC-BIOS SMBIOS interface
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef SMBIOS_PCBIOS
|
||||
#define SMBIOS_PREFIX_pcbios
|
||||
#else
|
||||
#define SMBIOS_PREFIX_pcbios __pcbios_
|
||||
#endif
|
||||
|
||||
#endif /* _GPXE_BIOS_SMBIOS_H */
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef _GPXE_BIOS_TIMER_H
|
||||
#define _GPXE_BIOS_TIMER_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* BIOS timer
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef TIMER_PCBIOS
|
||||
#define TIMER_PREFIX_pcbios
|
||||
#else
|
||||
#define TIMER_PREFIX_pcbios __pcbios_
|
||||
#endif
|
||||
|
||||
#include <gpxe/timer2.h>
|
||||
|
||||
/**
|
||||
* Delay for a fixed number of microseconds
|
||||
*
|
||||
* @v usecs Number of microseconds for which to delay
|
||||
*/
|
||||
static inline __always_inline void
|
||||
TIMER_INLINE ( pcbios, udelay ) ( unsigned long usecs ) {
|
||||
/* BIOS timer is not high-resolution enough for udelay(), so
|
||||
* we use timer2
|
||||
*/
|
||||
timer2_udelay ( usecs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of ticks per second
|
||||
*
|
||||
* @ret ticks_per_sec Number of ticks per second
|
||||
*/
|
||||
static inline __always_inline unsigned long
|
||||
TIMER_INLINE ( pcbios, ticks_per_sec ) ( void ) {
|
||||
/* BIOS timer ticks over at 18.2 ticks per second */
|
||||
return 18;
|
||||
}
|
||||
|
||||
#endif /* _GPXE_BIOS_TIMER_H */
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef _GPXE_MEMTOP_UMALLOC_H
|
||||
#define _GPXE_MEMTOP_UMALLOC_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* External memory allocation
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef UMALLOC_MEMTOP
|
||||
#define UMALLOC_PREFIX_memtop
|
||||
#else
|
||||
#define UMALLOC_PREFIX_memtop __memtop_
|
||||
#endif
|
||||
|
||||
#endif /* _GPXE_MEMTOP_UMALLOC_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef _GPXE_RDTSC_TIMER_H
|
||||
#define _GPXE_RDTSC_TIMER_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* RDTSC timer
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef TIMER_RDTSC
|
||||
#define TIMER_PREFIX_rdtsc
|
||||
#else
|
||||
#define TIMER_PREFIX_rdtsc __rdtsc_
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RDTSC values can easily overflow an unsigned long. We discard the
|
||||
* low-order bits in order to obtain sensibly-scaled values.
|
||||
*/
|
||||
#define TSC_SHIFT 8
|
||||
|
||||
/**
|
||||
* Get current system time in ticks
|
||||
*
|
||||
* @ret ticks Current time, in ticks
|
||||
*/
|
||||
static inline __always_inline unsigned long
|
||||
TIMER_INLINE ( rdtsc, currticks ) ( void ) {
|
||||
unsigned long ticks;
|
||||
|
||||
__asm__ __volatile__ ( "rdtsc\n\t"
|
||||
"shrdl %1, %%edx, %%eax\n\t"
|
||||
: "=a" ( ticks ) : "i" ( TSC_SHIFT ) : "edx" );
|
||||
return ticks;
|
||||
}
|
||||
|
||||
#endif /* _GPXE_RDTSC_TIMER_H */
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _GPXE_TIMER2_H
|
||||
#define _GPXE_TIMER2_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Timer chip control
|
||||
*
|
||||
*/
|
||||
|
||||
extern void timer2_udelay ( unsigned long usecs );
|
||||
|
||||
#endif /* _GPXE_TIMER2_H */
|
||||
@@ -0,0 +1,151 @@
|
||||
#ifndef _GPXE_X86_IO_H
|
||||
#define _GPXE_X86_IO_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* gPXE I/O API for x86
|
||||
*
|
||||
* i386 uses direct pointer dereferences for accesses to memory-mapped
|
||||
* I/O space, and the inX/outX instructions for accesses to
|
||||
* port-mapped I/O space.
|
||||
*
|
||||
* 64-bit atomic accesses (readq() and writeq()) use MMX instructions,
|
||||
* and will crash original Pentium and earlier CPUs. Fortunately, no
|
||||
* hardware that requires atomic 64-bit accesses will physically fit
|
||||
* into a machine with such an old CPU anyway.
|
||||
*/
|
||||
|
||||
#ifdef IOAPI_X86
|
||||
#define IOAPI_PREFIX_x86
|
||||
#else
|
||||
#define IOAPI_PREFIX_x86 __x86_
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Memory space mappings
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Physical<->Bus and Bus<->I/O address mappings
|
||||
*
|
||||
*/
|
||||
|
||||
static inline __always_inline unsigned long
|
||||
IOAPI_INLINE ( x86, phys_to_bus ) ( unsigned long phys_addr ) {
|
||||
return phys_addr;
|
||||
}
|
||||
|
||||
static inline __always_inline unsigned long
|
||||
IOAPI_INLINE ( x86, bus_to_phys ) ( unsigned long bus_addr ) {
|
||||
return bus_addr;
|
||||
}
|
||||
|
||||
static inline __always_inline void *
|
||||
IOAPI_INLINE ( x86, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
|
||||
return phys_to_virt ( bus_addr );
|
||||
}
|
||||
|
||||
static inline __always_inline void
|
||||
IOAPI_INLINE ( x86, iounmap ) ( volatile const void *io_addr __unused ) {
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
static inline __always_inline unsigned long
|
||||
IOAPI_INLINE ( x86, io_to_bus ) ( volatile const void *io_addr ) {
|
||||
return virt_to_phys ( io_addr );
|
||||
}
|
||||
|
||||
/*
|
||||
* MMIO reads and writes up to 32 bits
|
||||
*
|
||||
*/
|
||||
|
||||
#define X86_READX( _api_func, _type ) \
|
||||
static inline __always_inline _type \
|
||||
IOAPI_INLINE ( x86, _api_func ) ( volatile _type *io_addr ) { \
|
||||
return *io_addr; \
|
||||
}
|
||||
X86_READX ( readb, uint8_t );
|
||||
X86_READX ( readw, uint16_t );
|
||||
X86_READX ( readl, uint32_t );
|
||||
|
||||
#define X86_WRITEX( _api_func, _type ) \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( x86, _api_func ) ( _type data, \
|
||||
volatile _type *io_addr ) { \
|
||||
*io_addr = data; \
|
||||
}
|
||||
X86_WRITEX ( writeb, uint8_t );
|
||||
X86_WRITEX ( writew, uint16_t );
|
||||
X86_WRITEX ( writel, uint32_t );
|
||||
|
||||
/*
|
||||
* PIO reads and writes up to 32 bits
|
||||
*
|
||||
*/
|
||||
|
||||
#define X86_INX( _insn_suffix, _type, _reg_prefix ) \
|
||||
static inline __always_inline _type \
|
||||
IOAPI_INLINE ( x86, in ## _insn_suffix ) ( volatile _type *io_addr ) { \
|
||||
_type data; \
|
||||
__asm__ __volatile__ ( "in" #_insn_suffix " %w1, %" _reg_prefix "0" \
|
||||
: "=a" ( data ) : "Nd" ( io_addr ) ); \
|
||||
return data; \
|
||||
} \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( x86, ins ## _insn_suffix ) ( volatile _type *io_addr, \
|
||||
_type *data, \
|
||||
unsigned int count ) { \
|
||||
unsigned int discard_D; \
|
||||
__asm__ __volatile__ ( "rep ins" #_insn_suffix \
|
||||
: "=D" ( discard_D ) \
|
||||
: "d" ( io_addr ), "c" ( count ), \
|
||||
"0" ( data ) ); \
|
||||
}
|
||||
X86_INX ( b, uint8_t, "b" );
|
||||
X86_INX ( w, uint16_t, "w" );
|
||||
X86_INX ( l, uint32_t, "k" );
|
||||
|
||||
#define X86_OUTX( _insn_suffix, _type, _reg_prefix ) \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( x86, out ## _insn_suffix ) ( _type data, \
|
||||
volatile _type *io_addr ) { \
|
||||
__asm__ __volatile__ ( "out" #_insn_suffix " %" _reg_prefix "0, %w1" \
|
||||
: : "a" ( data ), "Nd" ( io_addr ) ); \
|
||||
} \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( x86, outs ## _insn_suffix ) ( volatile _type *io_addr, \
|
||||
const _type *data, \
|
||||
unsigned int count ) { \
|
||||
unsigned int discard_S; \
|
||||
__asm__ __volatile__ ( "rep outs" #_insn_suffix \
|
||||
: "=S" ( discard_S ) \
|
||||
: "d" ( io_addr ), "c" ( count ), \
|
||||
"0" ( data ) ); \
|
||||
}
|
||||
X86_OUTX ( b, uint8_t, "b" );
|
||||
X86_OUTX ( w, uint16_t, "w" );
|
||||
X86_OUTX ( l, uint32_t, "k" );
|
||||
|
||||
/*
|
||||
* Slow down I/O
|
||||
*
|
||||
*/
|
||||
|
||||
static inline __always_inline void
|
||||
IOAPI_INLINE ( x86, iodelay ) ( void ) {
|
||||
__asm__ __volatile__ ( "outb %al, $0x80" );
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory barrier
|
||||
*
|
||||
*/
|
||||
|
||||
static inline __always_inline void
|
||||
IOAPI_INLINE ( x86, mb ) ( void ) {
|
||||
__asm__ __volatile__ ( "lock; addl $0, 0(%%esp)" : : : "memory" );
|
||||
}
|
||||
|
||||
#endif /* _GPXE_X86_IO_H */
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <gpxe/list.h>
|
||||
#include <realmode.h>
|
||||
|
||||
struct block_device;
|
||||
|
||||
@@ -69,8 +70,20 @@ struct int13_drive {
|
||||
/** Underlying block device */
|
||||
struct block_device *blockdev;
|
||||
|
||||
/** BIOS drive number (0x80-0xff) */
|
||||
/** BIOS in-use drive number (0x80-0xff) */
|
||||
unsigned int drive;
|
||||
/** BIOS natural drive number (0x80-0xff)
|
||||
*
|
||||
* This is the drive number that would have been assigned by
|
||||
* 'naturally' appending the drive to the end of the BIOS
|
||||
* drive list.
|
||||
*
|
||||
* If the emulated drive replaces a preexisting drive, this is
|
||||
* the drive number that the preexisting drive gets remapped
|
||||
* to.
|
||||
*/
|
||||
unsigned int natural_drive;
|
||||
|
||||
/** Number of cylinders
|
||||
*
|
||||
* The cylinder number field in an INT 13 call is ten bits
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
#ifndef ETHERBOOT_IO_H
|
||||
#define ETHERBOOT_IO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "virtaddr.h"
|
||||
|
||||
/* virt_to_bus converts an addresss inside of etherboot [_start, _end]
|
||||
* into a memory access cards can use.
|
||||
*/
|
||||
#define virt_to_bus virt_to_phys
|
||||
|
||||
|
||||
/* bus_to_virt reverses virt_to_bus, the address must be output
|
||||
* from virt_to_bus to be valid. This function does not work on
|
||||
* all bus addresses.
|
||||
*/
|
||||
#define bus_to_virt phys_to_virt
|
||||
|
||||
/* ioremap converts a random 32bit bus address into something
|
||||
* etherboot can access.
|
||||
*/
|
||||
static inline void *ioremap(unsigned long bus_addr, unsigned long length __unused)
|
||||
{
|
||||
return bus_to_virt(bus_addr);
|
||||
}
|
||||
|
||||
/* iounmap cleans up anything ioremap had to setup */
|
||||
static inline void iounmap(void *virt_addr __unused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file contains the definitions for the x86 IO instructions
|
||||
* inb/inw/inl/outb/outw/outl and the "string versions" of the same
|
||||
* (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
|
||||
* versions of the single-IO instructions (inb_p/inw_p/..).
|
||||
*
|
||||
* This file is not meant to be obfuscating: it's just complicated
|
||||
* to (a) handle it all in a way that makes gcc able to optimize it
|
||||
* as well as possible and (b) trying to avoid writing the same thing
|
||||
* over and over again with slight variations and possibly making a
|
||||
* mistake somewhere.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Thanks to James van Artsdalen for a better timing-fix than
|
||||
* the two short jumps: using outb's to a nonexistent port seems
|
||||
* to guarantee better timings even on fast machines.
|
||||
*
|
||||
* On the other hand, I'd like to be sure of a non-existent port:
|
||||
* I feel a bit unsafe about using 0x80 (should be safe, though)
|
||||
*
|
||||
* Linus
|
||||
*/
|
||||
|
||||
#ifdef SLOW_IO_BY_JUMPING
|
||||
#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
|
||||
#else
|
||||
#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
|
||||
#endif
|
||||
|
||||
#ifdef REALLY_SLOW_IO
|
||||
#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
|
||||
#else
|
||||
#define SLOW_DOWN_IO __SLOW_DOWN_IO
|
||||
#endif
|
||||
|
||||
/*
|
||||
* readX/writeX() are used to access memory mapped devices. On some
|
||||
* architectures the memory mapped IO stuff needs to be accessed
|
||||
* differently. On the x86 architecture, we just read/write the
|
||||
* memory location directly.
|
||||
*/
|
||||
#define readb(addr) (*(volatile uint8_t *) (addr))
|
||||
#define readw(addr) (*(volatile uint16_t *) (addr))
|
||||
#define readl(addr) (*(volatile uint32_t *) (addr))
|
||||
|
||||
#define writeb(b,addr) ((*(volatile uint8_t *) (addr)) = (b))
|
||||
#define writew(b,addr) ((*(volatile uint16_t *) (addr)) = (b))
|
||||
#define writel(b,addr) ((*(volatile uint32_t *) (addr)) = (b))
|
||||
|
||||
#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
|
||||
#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
|
||||
|
||||
/*
|
||||
* Force strict CPU ordering.
|
||||
* And yes, this is required on UP too when we're talking
|
||||
* to devices.
|
||||
*
|
||||
* For now, "wmb()" doesn't actually do anything, as all
|
||||
* Intel CPU's follow what Intel calls a *Processor Order*,
|
||||
* in which all writes are seen in the program order even
|
||||
* outside the CPU.
|
||||
*
|
||||
* I expect future Intel CPU's to have a weaker ordering,
|
||||
* but I'd also expect them to finally get their act together
|
||||
* and add some real memory barriers if so.
|
||||
*
|
||||
* Some non intel clones support out of order store. wmb() ceases to be a
|
||||
* nop for these.
|
||||
*/
|
||||
|
||||
#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
|
||||
#define rmb() mb()
|
||||
#define wmb() mb();
|
||||
|
||||
|
||||
/*
|
||||
* Talk about misusing macros..
|
||||
*/
|
||||
|
||||
#define __OUT1(s,x) \
|
||||
extern void __out##s(unsigned x value, unsigned short port); \
|
||||
extern inline void __out##s(unsigned x value, unsigned short port) {
|
||||
|
||||
#define __OUT2(s,s1,s2) \
|
||||
__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
|
||||
|
||||
#define __OUT(s,s1,x) \
|
||||
__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
|
||||
__OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
|
||||
__OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
|
||||
__OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
|
||||
|
||||
#define __IN1(s,x) \
|
||||
extern unsigned x __in##s(unsigned short port); \
|
||||
extern inline unsigned x __in##s(unsigned short port) { unsigned x _v;
|
||||
|
||||
#define __IN2(s,s1,s2) \
|
||||
__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
|
||||
|
||||
#define __IN(s,s1,x,i...) \
|
||||
__IN1(s,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
|
||||
__IN1(s##c,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
|
||||
__IN1(s##_p,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
|
||||
__IN1(s##c_p,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
|
||||
|
||||
#define __INS(s) \
|
||||
extern void ins##s(unsigned short port, void * addr, unsigned long count); \
|
||||
extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
|
||||
{ __asm__ __volatile__ ("cld ; rep ; ins" #s \
|
||||
: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
|
||||
|
||||
#define __OUTS(s) \
|
||||
extern void outs##s(unsigned short port, const void * addr, unsigned long count); \
|
||||
extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
|
||||
{ __asm__ __volatile__ ("cld ; rep ; outs" #s \
|
||||
: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
|
||||
|
||||
__IN(b,"", char)
|
||||
__IN(w,"",short)
|
||||
__IN(l,"", long)
|
||||
|
||||
__OUT(b,"b",char)
|
||||
__OUT(w,"w",short)
|
||||
__OUT(l,,int)
|
||||
|
||||
__INS(b)
|
||||
__INS(w)
|
||||
__INS(l)
|
||||
|
||||
__OUTS(b)
|
||||
__OUTS(w)
|
||||
__OUTS(l)
|
||||
|
||||
/*
|
||||
* Note that due to the way __builtin_constant_p() works, you
|
||||
* - can't use it inside a inline function (it will never be true)
|
||||
* - you don't have to worry about side effects within the __builtin..
|
||||
*/
|
||||
#define outb(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outbc((val),(port)) : \
|
||||
__outb((val),(port)))
|
||||
|
||||
#define inb(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inbc(port) : \
|
||||
__inb(port))
|
||||
|
||||
#define outb_p(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outbc_p((val),(port)) : \
|
||||
__outb_p((val),(port)))
|
||||
|
||||
#define inb_p(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inbc_p(port) : \
|
||||
__inb_p(port))
|
||||
|
||||
#define outw(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outwc((val),(port)) : \
|
||||
__outw((val),(port)))
|
||||
|
||||
#define inw(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inwc(port) : \
|
||||
__inw(port))
|
||||
|
||||
#define outw_p(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outwc_p((val),(port)) : \
|
||||
__outw_p((val),(port)))
|
||||
|
||||
#define inw_p(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inwc_p(port) : \
|
||||
__inw_p(port))
|
||||
|
||||
#define outl(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outlc((val),(port)) : \
|
||||
__outl((val),(port)))
|
||||
|
||||
#define inl(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inlc(port) : \
|
||||
__inl(port))
|
||||
|
||||
#define outl_p(val,port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__outlc_p((val),(port)) : \
|
||||
__outl_p((val),(port)))
|
||||
|
||||
#define inl_p(port) \
|
||||
((__builtin_constant_p((port)) && (port) < 256) ? \
|
||||
__inlc_p(port) : \
|
||||
__inl_p(port))
|
||||
|
||||
#endif /* ETHERBOOT_IO_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user