Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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:
|
||||
|
||||
@@ -58,7 +58,6 @@ To get qemu running is fairly simple:
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
+2
-8
@@ -45,7 +45,7 @@ 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
|
||||
noargs : blib $(BIN)/NIC $(BIN)/gpxe.dsk $(BIN)/gpxe.iso $(BIN)/gpxe.usb $(BIN)/undionly.kpxe
|
||||
@$(ECHO) '==========================================================='
|
||||
@$(ECHO)
|
||||
@$(ECHO) 'To create a bootable floppy, type'
|
||||
@@ -68,11 +68,6 @@ noargs : blib $(BIN)/NIC $(BIN)/gpxe.dsk $(BIN)/gpxe.iso $(BIN)/gpxe.usb
|
||||
@$(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.
|
||||
#
|
||||
@@ -151,9 +146,8 @@ 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
|
||||
|
||||
+11
-11
@@ -11,8 +11,8 @@ CLEANUP := $(BIN)/*.* # *.* to avoid catching the "CVS" directory
|
||||
#
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 9
|
||||
VERSION_PATCH = 3
|
||||
EXTRAVERSION =
|
||||
VERSION_PATCH = 4
|
||||
EXTRAVERSION =
|
||||
MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
||||
VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
|
||||
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
|
||||
@@ -30,7 +30,7 @@ install :
|
||||
|
||||
# Check for tools that can cause failed builds
|
||||
#
|
||||
.toolcheck : Makefile Config
|
||||
.toolcheck : Makefile
|
||||
@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'; \
|
||||
@@ -121,8 +121,8 @@ CFLAGS += $(SP_FLAGS)
|
||||
CFLAGS += -include compiler.h
|
||||
|
||||
# config/%.h files are generated from config.h using mkconfig.pl
|
||||
config/%.h : config.h
|
||||
$(MKCONFIG) $<
|
||||
config/%.h : config*.h
|
||||
$(MKCONFIG) config.h
|
||||
CLEANUP += config/*.h
|
||||
|
||||
# SRCDIRS lists all directories containing source files.
|
||||
@@ -179,7 +179,7 @@ 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' \
|
||||
@@ -205,7 +205,7 @@ $(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)
|
||||
-include $(AUTO_DEPS)
|
||||
autodeps :
|
||||
@$(ECHO) $(AUTO_DEPS)
|
||||
VERYCLEANUP += $(BIN)/deps
|
||||
@@ -278,8 +278,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
|
||||
@@ -371,7 +371,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
|
||||
#
|
||||
@@ -459,7 +459,7 @@ $(BIN)/deps/%.media.d : $(MAKEDEPS)
|
||||
MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
|
||||
mediadeps :
|
||||
@$(ECHO) $(MEDIA_DEPS)
|
||||
include $(MEDIA_DEPS)
|
||||
-include $(MEDIA_DEPS)
|
||||
|
||||
# The "allXXXs" targets for each suffix
|
||||
#
|
||||
|
||||
@@ -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.
|
||||
@@ -7,11 +7,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.
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Interrupt Descriptor Table (IDT) setup and interrupt handlers for GDB stub.
|
||||
*/
|
||||
|
||||
#include <virtaddr.h>
|
||||
|
||||
#define SIZEOF_I386_REGS 32
|
||||
#define SIZEOF_I386_FLAGS 4
|
||||
|
||||
/****************************************************************************
|
||||
* Interrupt Descriptor Table
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".data16"
|
||||
.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"
|
||||
.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"
|
||||
.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 <virtaddr.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 ) {
|
||||
int regnum = bp - hwbps;
|
||||
|
||||
/* Set breakpoint address */
|
||||
assert ( regnum >= 0 && 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 ) );
|
||||
}
|
||||
|
||||
__cdecl 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,
|
||||
};
|
||||
+53
-160
@@ -1,18 +1,58 @@
|
||||
/* A couple of routines to implement a low-overhead timer for drivers */
|
||||
|
||||
/*
|
||||
/*
|
||||
* 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 "timer.h"
|
||||
#include "latch.h"
|
||||
#include <io.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <stddef.h>
|
||||
#include <bits/timer2.h>
|
||||
#include <gpxe/timer.h>
|
||||
#include <io.h>
|
||||
|
||||
void __load_timer2(unsigned int ticks)
|
||||
/* Timers tick over at this rate */
|
||||
#define TIMER2_TICK_RATE 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
|
||||
@@ -35,162 +75,15 @@ void __load_timer2(unsigned int ticks)
|
||||
outb(ticks >> 8, TIMER2_PORT);
|
||||
}
|
||||
|
||||
static int __timer2_running(void)
|
||||
static int timer2_running(void)
|
||||
{
|
||||
return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_TSC_CURRTICKS)
|
||||
static void setup_timers(void)
|
||||
void i386_timer2_udelay(unsigned int usecs)
|
||||
{
|
||||
return;
|
||||
load_timer2((usecs * TIMER2_TICK_RATE)/USECS_IN_SEC);
|
||||
while (timer2_running())
|
||||
;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
#include <realmode.h>
|
||||
#include <bios.h>
|
||||
|
||||
/**************************************************************************
|
||||
* 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" ) : : );
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -194,8 +194,8 @@ userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
|
||||
|
||||
/* Collect any free blocks and update hidden memory region */
|
||||
ecollect_free();
|
||||
hide_region ( EXTMEM, user_to_phys ( bottom, -sizeof ( extmem ) ),
|
||||
user_to_phys ( top, 0 ) );
|
||||
hide_umalloc ( user_to_phys ( bottom, -sizeof ( extmem ) ),
|
||||
user_to_phys ( top, 0 ) );
|
||||
|
||||
return ( new_size ? new : UNOWHERE );
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -176,9 +176,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 +211,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 +357,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,
|
||||
@@ -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;
|
||||
@@ -708,6 +709,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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Etherboot routines for PCBIOS firmware.
|
||||
*
|
||||
* Body of routines taken from old pcbios.S
|
||||
*/
|
||||
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/timer.h>
|
||||
#include <stdio.h>
|
||||
#include <realmode.h>
|
||||
#include <bios.h>
|
||||
#include <bits/timer2.h>
|
||||
|
||||
/* A bit faster actually, but we don't care. */
|
||||
#define TIMER2_TICKS_PER_SEC 18
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
static tick_t bios_currticks ( void ) {
|
||||
static int 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) * (USECS_IN_SEC / TIMER2_TICKS_PER_SEC) );
|
||||
}
|
||||
|
||||
static int bios_ts_init(void)
|
||||
{
|
||||
DBG("BIOS timer installed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct timer bios_ts __timer ( 02 ) = {
|
||||
.init = bios_ts_init,
|
||||
.udelay = i386_timer2_udelay,
|
||||
.currticks = bios_currticks,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/timer.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <bits/cpu.h>
|
||||
#include <bits/timer2.h>
|
||||
#include <io.h>
|
||||
|
||||
|
||||
#define rdtsc(low,high) \
|
||||
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
|
||||
|
||||
#define rdtscll(val) \
|
||||
__asm__ __volatile__ ("rdtsc" : "=A" (val))
|
||||
|
||||
|
||||
/* Measure how many clocks we get in one microsecond */
|
||||
static inline uint64_t calibrate_tsc(void)
|
||||
{
|
||||
|
||||
uint64_t rdtsc_start;
|
||||
uint64_t rdtsc_end;
|
||||
|
||||
rdtscll(rdtsc_start);
|
||||
i386_timer2_udelay(USECS_IN_MSEC);
|
||||
rdtscll(rdtsc_end);
|
||||
|
||||
return (rdtsc_end - rdtsc_start) / USECS_IN_MSEC;
|
||||
}
|
||||
|
||||
static uint32_t clocks_per_usec = 0;
|
||||
|
||||
/* We measure time in microseconds. */
|
||||
static tick_t rdtsc_currticks(void)
|
||||
{
|
||||
uint64_t clocks;
|
||||
|
||||
/* Read the Time Stamp Counter */
|
||||
rdtscll(clocks);
|
||||
|
||||
return clocks / clocks_per_usec;
|
||||
}
|
||||
|
||||
static int rdtsc_ts_init(void)
|
||||
{
|
||||
|
||||
struct cpuinfo_x86 cpu_info;
|
||||
|
||||
get_cpuinfo(&cpu_info);
|
||||
if (cpu_info.features & X86_FEATURE_TSC) {
|
||||
clocks_per_usec= calibrate_tsc();
|
||||
if (clocks_per_usec) {
|
||||
DBG("RDTSC ticksource installed. CPU running at %ld Mhz\n",
|
||||
clocks_per_usec);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
DBG("RDTSC ticksource not available on this machine.\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
struct timer rdtsc_ts __timer (01) = {
|
||||
.init = rdtsc_ts_init,
|
||||
.udelay = generic_currticks_udelay,
|
||||
.currticks = rdtsc_currticks,
|
||||
};
|
||||
|
||||
@@ -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" ) : : );
|
||||
}
|
||||
@@ -26,159 +26,82 @@
|
||||
#define SMAP 0x534d4150
|
||||
|
||||
/****************************************************************************
|
||||
* Check for overlap
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* %si Pointer to hidden region descriptor
|
||||
* Returns:
|
||||
* CF set Region overlaps
|
||||
* CF clear No overlap
|
||||
* 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_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
|
||||
*/
|
||||
.section ".data16"
|
||||
.align 16
|
||||
.globl hidemem_base
|
||||
.globl hidemem_umalloc
|
||||
.globl hidemem_text
|
||||
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_text: .long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
.long 0xffffffff, 0xffffffff /* Changes at runtime */
|
||||
|
||||
.long 0xffffffff, 0xffffffff /* End of memory */
|
||||
memory_windows_end:
|
||||
|
||||
/****************************************************************************
|
||||
* Check for overflow/underflow
|
||||
* Truncate region to memory window
|
||||
*
|
||||
* Parameters:
|
||||
* %edx:%eax Region start
|
||||
* %ecx:%ebx Region end
|
||||
* %edx:%eax Start of region
|
||||
* %ecx:%ebx Length of region
|
||||
* %si Memory window
|
||||
* Returns:
|
||||
* CF set start < end
|
||||
* CF clear start >= end
|
||||
* %edx:%eax Start of windowed region
|
||||
* %ecx:%ebx Length of windowed region
|
||||
****************************************************************************
|
||||
*/
|
||||
.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
|
||||
|
||||
/****************************************************************************
|
||||
* Truncate towards end 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_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) */
|
||||
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 +110,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"
|
||||
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 +140,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"
|
||||
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,103 +171,289 @@ 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"
|
||||
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:
|
||||
get_underlying_e820:
|
||||
|
||||
/* If the requested region is in the cache, return it */
|
||||
cmpw %bx, underlying_e820_index
|
||||
jne 1f
|
||||
pushw %di
|
||||
pushw %si
|
||||
movw $underlying_e820_cache, %si
|
||||
movw $20, %cx
|
||||
rep movsb
|
||||
popw %si
|
||||
popw %di
|
||||
movw $20, %cx
|
||||
incw %bx
|
||||
movl %edx, %eax
|
||||
ret
|
||||
1:
|
||||
/* 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
|
||||
pushw %es
|
||||
pushw %di
|
||||
pushw %ds
|
||||
popw %es
|
||||
movw $underlying_e820_cache, %di
|
||||
movl $20, %ecx
|
||||
movl underlying_e820_ebx, %ebx
|
||||
stc
|
||||
pushfw
|
||||
lcall *%cs:int15_vector
|
||||
popw %di
|
||||
popw %es
|
||||
/* Check for error return from underlying e820 call */
|
||||
jc 1f /* CF set: error */
|
||||
cmpl $SMAP, %eax
|
||||
je 2f /* 'SMAP' missing: error */
|
||||
1: /* 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
|
||||
2: /* No error occurred */
|
||||
movl %ebx, underlying_e820_ebx
|
||||
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"
|
||||
underlying_e820_index:
|
||||
.word 0xffff /* Initialise to an invalid value */
|
||||
.size underlying_e820_index, . - underlying_e820_index
|
||||
|
||||
.section ".bss16"
|
||||
underlying_e820_ebx:
|
||||
.long 0
|
||||
.size underlying_e820_ebx, . - underlying_e820_ebx
|
||||
|
||||
.section ".bss16"
|
||||
underlying_e820_cache:
|
||||
.space 20
|
||||
.size underlying_e820_cache, . - underlying_e820_cache
|
||||
|
||||
/****************************************************************************
|
||||
* 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"
|
||||
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
|
||||
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"
|
||||
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
|
||||
subw $20, %sp
|
||||
movl $0xe820, %eax
|
||||
movl $SMAP, %edx
|
||||
movl $20, %ecx
|
||||
pushw %ss
|
||||
popw %es
|
||||
movw %sp, %di
|
||||
call get_nonempty_e820
|
||||
addr32 leal 20(%esp), %esp /* avoid changing flags */
|
||||
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
|
||||
@@ -356,39 +461,11 @@ real_ebx:
|
||||
*/
|
||||
.section ".text16"
|
||||
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
|
||||
|
||||
|
||||
@@ -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,7 @@
|
||||
#include <stdio.h>
|
||||
#include "realmode.h"
|
||||
#include "timer.h"
|
||||
#include "latch.h"
|
||||
#include "bios.h"
|
||||
#include <realmode.h>
|
||||
#include <bios.h>
|
||||
#include <gpxe/timer.h>
|
||||
|
||||
#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
|
||||
#define K_STATUS 0x64 /* keyboard status */
|
||||
@@ -13,6 +12,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
|
||||
@@ -131,6 +131,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" );
|
||||
|
||||
@@ -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_text );
|
||||
#define hidemem_text __use_data16 ( hidemem_text )
|
||||
|
||||
/** 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 _text[];
|
||||
extern char _end[];
|
||||
extern char _text16_size[];
|
||||
#define _text16_size ( ( unsigned int ) _text16_size )
|
||||
extern char _data16_size[];
|
||||
#define _data16_size ( ( unsigned int ) _data16_size )
|
||||
|
||||
/**
|
||||
* 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 ( _text ) );
|
||||
hide_region ( &hidemem_umalloc, start, end );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide .text and .data
|
||||
*
|
||||
*/
|
||||
void hide_text ( void ) {
|
||||
hide_region ( &hidemem_text, virt_to_phys ( _text ),
|
||||
virt_to_phys ( _end ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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 ( _text ), virt_to_phys ( _text ) );
|
||||
hide_text();
|
||||
|
||||
/* 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_size + 1024 - 1 ) >> 10 );
|
||||
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_size + 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 */
|
||||
|
||||
@@ -86,8 +86,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 +115,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;
|
||||
}
|
||||
|
||||
@@ -147,7 +160,7 @@ static int meme820 ( struct memory_map *memmap ) {
|
||||
"=b" ( next ), "=D" ( discard_D ),
|
||||
"=c" ( discard_c ), "=d" ( discard_d )
|
||||
: "a" ( 0xe820 ), "b" ( next ),
|
||||
"D" ( &__from_data16 ( e820buf ) ),
|
||||
"D" ( __from_data16 ( &e820buf ) ),
|
||||
"c" ( sizeof ( e820buf ) ),
|
||||
"d" ( SMAP )
|
||||
: "memory" );
|
||||
@@ -184,6 +197,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 +238,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 */
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/uuid.h>
|
||||
#include <realmode.h>
|
||||
#include <pnpbios.h>
|
||||
#include <smbios.h>
|
||||
@@ -51,7 +50,7 @@ struct smbios_entry {
|
||||
/** Checksum */
|
||||
uint8_t checksum;
|
||||
/** Length */
|
||||
uint8_t length;
|
||||
uint8_t len;
|
||||
/** Major version */
|
||||
uint8_t major;
|
||||
/** Minor version */
|
||||
@@ -67,7 +66,7 @@ struct smbios_entry {
|
||||
/** DMI checksum */
|
||||
uint8_t dmi_checksum;
|
||||
/** Structure table length */
|
||||
uint16_t smbios_length;
|
||||
uint16_t smbios_len;
|
||||
/** Structure table address */
|
||||
physaddr_t smbios_address;
|
||||
/** Number of SMBIOS structures */
|
||||
@@ -86,49 +85,37 @@ struct smbios {
|
||||
/** Start of SMBIOS structures */
|
||||
userptr_t address;
|
||||
/** Length of SMBIOS structures */
|
||||
size_t length;
|
||||
size_t len;
|
||||
/** 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;
|
||||
/** SMBIOS entry point descriptor */
|
||||
static struct smbios smbios = {
|
||||
.address = UNULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* Find SMBIOS
|
||||
*
|
||||
* @ret smbios SMBIOS entry point descriptor, or NULL if not found
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static struct smbios * find_smbios ( void ) {
|
||||
static struct smbios smbios = {
|
||||
.address = UNULL,
|
||||
};
|
||||
static int find_smbios ( void ) {
|
||||
union {
|
||||
struct smbios_entry entry;
|
||||
uint8_t bytes[256]; /* 256 is maximum length possible */
|
||||
} u;
|
||||
unsigned int offset;
|
||||
static unsigned int offset = 0;
|
||||
size_t len;
|
||||
unsigned int i;
|
||||
uint8_t sum;
|
||||
|
||||
/* Return cached result if available */
|
||||
/* Return cached result if avaiable */
|
||||
if ( smbios.address != UNULL )
|
||||
return &smbios;
|
||||
return 0;
|
||||
|
||||
/* Try to find SMBIOS */
|
||||
for ( offset = 0 ; offset < 0x10000 ; offset += 0x10 ) {
|
||||
for ( ; offset < 0x10000 ; offset += 0x10 ) {
|
||||
|
||||
/* Read start of header and verify signature */
|
||||
copy_from_real ( &u.entry, BIOS_SEG, offset,
|
||||
@@ -137,7 +124,7 @@ static struct smbios * find_smbios ( void ) {
|
||||
continue;
|
||||
|
||||
/* Read whole header and verify checksum */
|
||||
len = u.entry.length;
|
||||
len = u.entry.len;
|
||||
copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
|
||||
for ( i = 0 , sum = 0 ; i < len ; i++ ) {
|
||||
sum += u.bytes[i];
|
||||
@@ -149,32 +136,30 @@ static struct smbios * find_smbios ( void ) {
|
||||
}
|
||||
|
||||
/* Fill result structure */
|
||||
DBG ( "Found SMBIOS entry point at %04x:%04x\n",
|
||||
BIOS_SEG, offset );
|
||||
DBG ( "Found SMBIOS v%d.%d entry point at %04x:%04x\n",
|
||||
u.entry.major, u.entry.minor, BIOS_SEG, offset );
|
||||
smbios.address = phys_to_user ( u.entry.smbios_address );
|
||||
smbios.length = u.entry.smbios_length;
|
||||
smbios.len = u.entry.smbios_len;
|
||||
smbios.count = u.entry.smbios_count;
|
||||
return &smbios;
|
||||
return 0;
|
||||
}
|
||||
|
||||
DBG ( "No SMBIOS found\n" );
|
||||
return NULL;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
static size_t find_strings_terminator ( size_t offset ) {
|
||||
size_t max_offset = ( smbios.len - 2 );
|
||||
uint16_t nulnul;
|
||||
|
||||
for ( ; offset <= max_offset ; offset++ ) {
|
||||
copy_from_user ( &nulnul, smbios->address, offset, 2 );
|
||||
copy_from_user ( &nulnul, smbios.address, offset, 2 );
|
||||
if ( nulnul == 0 )
|
||||
return ( offset + 1 );
|
||||
}
|
||||
@@ -185,66 +170,52 @@ static size_t find_strings_terminator ( struct smbios *smbios,
|
||||
* 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
|
||||
* @v structure SMBIOS structure descriptor to fill in
|
||||
* @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;
|
||||
int find_smbios_structure ( unsigned int type,
|
||||
struct smbios_structure *structure ) {
|
||||
unsigned int count = 0;
|
||||
size_t offset = 0;
|
||||
size_t strings_offset;
|
||||
size_t terminator_offset;
|
||||
int rc;
|
||||
|
||||
/* Locate SMBIOS entry point */
|
||||
if ( ! ( smbios = find_smbios() ) )
|
||||
return -ENOENT;
|
||||
|
||||
/* Ensure that we have a usable strings descriptor buffer */
|
||||
if ( ! strings )
|
||||
strings = &temp_strings;
|
||||
/* Find SMBIOS */
|
||||
if ( ( rc = find_smbios() ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Scan through list of structures */
|
||||
while ( ( ( offset + sizeof ( header ) ) < smbios->length ) &&
|
||||
( count < smbios->count ) ) {
|
||||
while ( ( ( offset + sizeof ( structure->header ) ) < smbios.len )
|
||||
&& ( count < smbios.count ) ) {
|
||||
|
||||
/* Read next SMBIOS structure header */
|
||||
copy_from_user ( &header, smbios->address, offset,
|
||||
sizeof ( header ) );
|
||||
copy_from_user ( &structure->header, smbios.address, offset,
|
||||
sizeof ( structure->header ) );
|
||||
|
||||
/* Determine start and extent of strings block */
|
||||
strings_offset = ( offset + header.length );
|
||||
if ( strings_offset > smbios->length ) {
|
||||
strings_offset = ( offset + structure->header.len );
|
||||
if ( strings_offset > smbios.len ) {
|
||||
DBG ( "SMBIOS structure at offset %zx with length "
|
||||
"%x extends beyond SMBIOS\n", offset,
|
||||
header.length );
|
||||
structure->header.len );
|
||||
return -ENOENT;
|
||||
}
|
||||
terminator_offset =
|
||||
find_strings_terminator ( smbios, strings_offset );
|
||||
terminator_offset = find_strings_terminator ( 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 );
|
||||
structure->strings_len = ( 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 );
|
||||
DBG ( "SMBIOS structure at offset %zx has type %d, length %x, "
|
||||
"strings length %zx\n", offset, structure->header.type,
|
||||
structure->header.len, structure->strings_len );
|
||||
|
||||
/* 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 );
|
||||
if ( structure->header.type == type ) {
|
||||
structure->offset = offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -258,66 +229,62 @@ int find_smbios_structure ( unsigned int type, void *structure,
|
||||
}
|
||||
|
||||
/**
|
||||
* Find indexed string within SMBIOS structure
|
||||
* Copy SMBIOS structure
|
||||
*
|
||||
* @v strings SMBIOS strings descriptor
|
||||
* @v index String index
|
||||
* @v buffer Buffer for string
|
||||
* @v length Length of string buffer
|
||||
* @v structure SMBIOS structure descriptor
|
||||
* @v data Buffer to hold SMBIOS structure
|
||||
* @v len Length of 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;
|
||||
int read_smbios_structure ( struct smbios_structure *structure,
|
||||
void *data, size_t len ) {
|
||||
|
||||
assert ( smbios.address != UNULL );
|
||||
|
||||
if ( len > structure->header.len )
|
||||
len = structure->header.len;
|
||||
copy_from_user ( data, smbios.address, structure->offset, len );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find indexed string within SMBIOS structure
|
||||
*
|
||||
* @v structure SMBIOS structure descriptor
|
||||
* @v index String index
|
||||
* @v data Buffer for string
|
||||
* @v len Length of string buffer
|
||||
* @ret rc Length of string, or negative error
|
||||
*/
|
||||
int read_smbios_string ( struct smbios_structure *structure,
|
||||
unsigned int index, void *data, size_t len ) {
|
||||
size_t strings_start = ( structure->offset + structure->header.len );
|
||||
size_t strings_end = ( strings_start + structure->strings_len );
|
||||
size_t offset;
|
||||
size_t string_len;
|
||||
|
||||
/* Zero buffer. This ensures that a valid NUL terminator is
|
||||
* always present (unless length==0).
|
||||
*/
|
||||
memset ( buffer, 0, length );
|
||||
|
||||
assert ( smbios.address != UNULL );
|
||||
|
||||
/* String numbers start at 1 (0 is used to indicate "no string") */
|
||||
if ( ! index )
|
||||
return 0;
|
||||
return -ENOENT;
|
||||
|
||||
while ( offset < strings->length ) {
|
||||
for ( offset = strings_start ; offset < strings_end ;
|
||||
offset += ( string_len + 1 ) ) {
|
||||
/* 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 );
|
||||
string_len = strlen_user ( smbios.address, 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;
|
||||
if ( len > string_len )
|
||||
len = string_len;
|
||||
copy_from_user ( data, smbios.address, offset, len );
|
||||
return string_len;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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 <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <gpxe/settings.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/uuid.h>
|
||||
#include <smbios.h>
|
||||
|
||||
/**
|
||||
* Construct SMBIOS raw-data tag
|
||||
*
|
||||
* @v _type SMBIOS structure type number
|
||||
* @v _structure SMBIOS structure data type
|
||||
* @v _field Field within SMBIOS structure data type
|
||||
* @ret tag SMBIOS setting tag
|
||||
*/
|
||||
#define SMBIOS_RAW_TAG( _type, _structure, _field ) \
|
||||
( ( (_type) << 16 ) | \
|
||||
( offsetof ( _structure, _field ) << 8 ) | \
|
||||
( sizeof ( ( ( _structure * ) 0 )->_field ) ) )
|
||||
|
||||
/**
|
||||
* Construct SMBIOS string tag
|
||||
*
|
||||
* @v _type SMBIOS structure type number
|
||||
* @v _structure SMBIOS structure data type
|
||||
* @v _field Field within SMBIOS structure data type
|
||||
* @ret tag SMBIOS setting tag
|
||||
*/
|
||||
#define SMBIOS_STRING_TAG( _type, _structure, _field ) \
|
||||
( ( (_type) << 16 ) | \
|
||||
( offsetof ( _structure, _field ) << 8 ) )
|
||||
|
||||
/**
|
||||
* Store value of SMBIOS setting
|
||||
*
|
||||
* @v settings Settings block
|
||||
* @v setting Setting to store
|
||||
* @v data Setting data, or NULL to clear setting
|
||||
* @v len Length of setting data
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int smbios_store ( struct settings *settings __unused,
|
||||
struct setting *setting __unused,
|
||||
const void *data __unused, size_t len __unused ) {
|
||||
/* Cannot write data into SMBIOS */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch value of SMBIOS setting
|
||||
*
|
||||
* @v settings Settings block, or NULL to search all blocks
|
||||
* @v setting Setting to fetch
|
||||
* @v data Buffer to fill with setting data
|
||||
* @v len Length of buffer
|
||||
* @ret len Length of setting data, or negative error
|
||||
*/
|
||||
static int smbios_fetch ( struct settings *settings __unused,
|
||||
struct setting *setting,
|
||||
void *data, size_t len ) {
|
||||
struct smbios_structure structure;
|
||||
unsigned int tag_type;
|
||||
unsigned int tag_offset;
|
||||
unsigned int tag_len;
|
||||
int rc;
|
||||
|
||||
/* Split tag into type, offset and length */
|
||||
tag_type = ( setting->tag >> 16 );
|
||||
tag_offset = ( ( setting->tag >> 8 ) & 0xff );
|
||||
tag_len = ( setting->tag & 0xff );
|
||||
if ( ! tag_type )
|
||||
return -ENOENT;
|
||||
|
||||
/* Find SMBIOS structure */
|
||||
if ( ( rc = find_smbios_structure ( tag_type, &structure ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
{
|
||||
uint8_t buf[structure.header.len];
|
||||
|
||||
/* Read SMBIOS structure */
|
||||
if ( ( rc = read_smbios_structure ( &structure, buf,
|
||||
sizeof ( buf ) ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
if ( tag_len == 0 ) {
|
||||
/* String */
|
||||
return read_smbios_string ( &structure,
|
||||
buf[tag_offset],
|
||||
data, len );
|
||||
} else {
|
||||
/* Raw data */
|
||||
if ( len > tag_len )
|
||||
len = tag_len;
|
||||
memcpy ( data, &buf[tag_offset], len );
|
||||
return tag_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** SMBIOS settings operations */
|
||||
static struct settings_operations smbios_settings_operations = {
|
||||
.store = smbios_store,
|
||||
.fetch = smbios_fetch,
|
||||
};
|
||||
|
||||
/** SMBIOS settings */
|
||||
static struct settings smbios_settings = {
|
||||
.refcnt = NULL,
|
||||
.name = "smbios",
|
||||
.siblings = LIST_HEAD_INIT ( smbios_settings.siblings ),
|
||||
.children = LIST_HEAD_INIT ( smbios_settings.children ),
|
||||
.op = &smbios_settings_operations,
|
||||
};
|
||||
|
||||
/** Initialise SMBIOS settings */
|
||||
static void smbios_init ( void ) {
|
||||
int rc;
|
||||
|
||||
if ( ( rc = register_settings ( &smbios_settings, NULL ) ) != 0 ) {
|
||||
DBG ( "SMBIOS could not register settings: %s\n",
|
||||
strerror ( rc ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** SMBIOS settings initialiser */
|
||||
struct init_fn smbios_init_fn __init_fn ( INIT_NORMAL ) = {
|
||||
.initialise = smbios_init,
|
||||
};
|
||||
|
||||
/** UUID setting obtained via SMBIOS */
|
||||
struct setting uuid_setting __setting = {
|
||||
.name = "uuid",
|
||||
.description = "UUID",
|
||||
.tag = SMBIOS_RAW_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
|
||||
struct smbios_system_information, uuid ),
|
||||
.type = &setting_type_uuid,
|
||||
};
|
||||
|
||||
/** Other SMBIOS named settings */
|
||||
struct setting smbios_named_settings[] __setting = {
|
||||
{
|
||||
.name = "manufacturer",
|
||||
.description = "Manufacturer",
|
||||
.tag = SMBIOS_STRING_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
|
||||
struct smbios_system_information,
|
||||
manufacturer ),
|
||||
.type = &setting_type_string,
|
||||
},
|
||||
{
|
||||
.name = "product",
|
||||
.description = "Product name",
|
||||
.tag = SMBIOS_STRING_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
|
||||
struct smbios_system_information,
|
||||
product ),
|
||||
.type = &setting_type_string,
|
||||
},
|
||||
{
|
||||
.name = "serial",
|
||||
.description = "Serial number",
|
||||
.tag = SMBIOS_STRING_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
|
||||
struct smbios_system_information,
|
||||
serial ),
|
||||
.type = &setting_type_string,
|
||||
},
|
||||
};
|
||||
@@ -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,
|
||||
@@ -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,275 @@
|
||||
/*
|
||||
* 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 = setjmp ( 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, (int)avail_mem_top );
|
||||
|
||||
assert ( avail_mem_top != 0 );
|
||||
|
||||
com32_external_esp = phys_to_virt ( avail_mem_top );
|
||||
|
||||
/* Hook COMBOOT API interrupts */
|
||||
hook_comboot_interrupts( );
|
||||
|
||||
/* Temporarily de-register image, so that a "boot" command
|
||||
* doesn't throw us into an execution loop. Hold a reference
|
||||
* to avoid the image's being freed.
|
||||
*/
|
||||
image_get ( image );
|
||||
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" );
|
||||
break;
|
||||
|
||||
case COMBOOT_RETURN_RUN_KERNEL:
|
||||
DBGC ( image, "COM32 %p: returned to run kernel...\n", image );
|
||||
comboot_run_kernel ( );
|
||||
break;
|
||||
|
||||
case COMBOOT_RETURN_EXIT:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
comboot_force_text_mode ( );
|
||||
|
||||
DBGC ( image, "COM32 %p returned\n", image );
|
||||
|
||||
/* Re-register image and return */
|
||||
register_image ( image );
|
||||
image_put ( image );
|
||||
|
||||
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,312 @@
|
||||
/*
|
||||
* 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 = setjmp ( 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 );
|
||||
|
||||
/* Temporarily de-register image, so that a "boot" command
|
||||
* doesn't throw us into an execution loop. Hold a reference
|
||||
* to avoid the image's being freed.
|
||||
*/
|
||||
image_get ( image );
|
||||
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" );
|
||||
break;
|
||||
|
||||
case COMBOOT_RETURN_RUN_KERNEL:
|
||||
DBGC ( image, "COMBOOT %p: returned to run kernel...\n", image );
|
||||
comboot_run_kernel ( );
|
||||
break;
|
||||
|
||||
case COMBOOT_RETURN_EXIT:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
comboot_force_text_mode ( );
|
||||
|
||||
DBGC ( image, "COMBOOT %p returned\n", image );
|
||||
|
||||
/* Re-register image and return */
|
||||
register_image ( image );
|
||||
image_put ( image );
|
||||
|
||||
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,
|
||||
};
|
||||
@@ -277,9 +277,11 @@ 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 */
|
||||
DBGC ( image, "MULTIBOOT %p starting execution at %lx\n",
|
||||
image, entry );
|
||||
__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
|
||||
: : "a" ( MULTIBOOT_BOOTLOADER_MAGIC ),
|
||||
"b" ( virt_to_phys ( &mbinfo ) ),
|
||||
@@ -358,8 +360,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",
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -389,7 +389,6 @@ 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;
|
||||
|
||||
@@ -400,10 +399,8 @@ static int nbi_prepare_dhcp ( struct image *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 +429,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 ) ) {
|
||||
|
||||
@@ -84,6 +84,14 @@ 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;
|
||||
|
||||
/* There are no signature checks for PXE; we will accept anything */
|
||||
if ( ! image->type )
|
||||
image->type = &pxe_image_type;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
|
||||
#define ERRFILE_biosint ( ERRFILE_ARCH | ERRFILE_CORE | 0x00040000 )
|
||||
#define ERRFILE_int13 ( ERRFILE_ARCH | ERRFILE_CORE | 0x00050000 )
|
||||
#define ERRFILE_smbios_settings ( ERRFILE_ARCH | ERRFILE_CORE | 0x00060000 )
|
||||
|
||||
#define ERRFILE_bootsector ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 )
|
||||
#define ERRFILE_bzimage ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 )
|
||||
@@ -19,6 +20,10 @@
|
||||
#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_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,8 @@
|
||||
#ifndef BITS_TIMER2_H
|
||||
#define BITS_TIMER2_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void i386_timer2_udelay(unsigned int usecs);
|
||||
|
||||
#endif
|
||||
@@ -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,102 @@
|
||||
#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 dest;
|
||||
uint32_t src;
|
||||
uint32_t len;
|
||||
} comboot_shuffle_descriptor;
|
||||
|
||||
extern void hook_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 jmp_buf comboot_return;
|
||||
|
||||
/* Command line to execute when returning via comboot_return
|
||||
* with COMBOOT_RETURN_RUN_KERNEL
|
||||
*/
|
||||
extern char *comboot_kernel_cmdline;
|
||||
|
||||
/* Execute comboot_image_cmdline */
|
||||
extern void comboot_run_kernel ( );
|
||||
|
||||
extern void *com32_external_esp;
|
||||
|
||||
#define COMBOOT_RETURN_EXIT 1
|
||||
#define COMBOOT_RETURN_RUN_KERNEL 2
|
||||
|
||||
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 uint32_t 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 */
|
||||
@@ -69,8 +69,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
|
||||
|
||||
@@ -72,13 +72,46 @@ static inline void iounmap(void *virt_addr __unused)
|
||||
* 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))
|
||||
static inline __attribute__ (( always_inline )) unsigned long
|
||||
_readb ( volatile uint8_t *addr ) {
|
||||
unsigned long data = *addr;
|
||||
DBGIO ( "[%08lx] => %02lx\n", virt_to_phys ( addr ), data );
|
||||
return data;
|
||||
}
|
||||
static inline __attribute__ (( always_inline )) unsigned long
|
||||
_readw ( volatile uint16_t *addr ) {
|
||||
unsigned long data = *addr;
|
||||
DBGIO ( "[%08lx] => %04lx\n", virt_to_phys ( addr ), data );
|
||||
return data;
|
||||
}
|
||||
static inline __attribute__ (( always_inline )) unsigned long
|
||||
_readl ( volatile uint32_t *addr ) {
|
||||
unsigned long data = *addr;
|
||||
DBGIO ( "[%08lx] => %08lx\n", virt_to_phys ( addr ), data );
|
||||
return data;
|
||||
}
|
||||
#define readb( addr ) _readb ( ( volatile uint8_t * ) (addr) )
|
||||
#define readw( addr ) _readw ( ( volatile uint16_t * ) (addr) )
|
||||
#define readl( addr ) _readl ( ( 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))
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
_writeb ( unsigned long data, volatile uint8_t *addr ) {
|
||||
DBGIO ( "[%08lx] <= %02lx\n", virt_to_phys ( addr ), data );
|
||||
*addr = data;
|
||||
}
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
_writew ( unsigned long data, volatile uint16_t *addr ) {
|
||||
DBGIO ( "[%08lx] <= %04lx\n", virt_to_phys ( addr ), data );
|
||||
*addr = data;
|
||||
}
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
_writel ( unsigned long data, volatile uint32_t *addr ) {
|
||||
DBGIO ( "[%08lx] <= %08lx\n", virt_to_phys ( addr ), data );
|
||||
*addr = data;
|
||||
}
|
||||
#define writeb( b, addr ) _writeb ( (b), ( volatile uint8_t * ) (addr) )
|
||||
#define writew( b, addr ) _writew ( (b), ( volatile uint16_t * ) (addr) )
|
||||
#define writel( b, addr ) _writel ( (b), ( volatile uint32_t * ) (addr) )
|
||||
|
||||
#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
|
||||
#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef LATCH_H
|
||||
#define LATCH_H
|
||||
|
||||
#define TICKS_PER_SEC 18
|
||||
|
||||
/* For different calibrators of the TSC move the declaration of
|
||||
* sleep_latch and the definitions of it's length here...
|
||||
*/
|
||||
|
||||
extern unsigned long currticks ( void );
|
||||
|
||||
#endif /* LATCH_H */
|
||||
@@ -19,8 +19,8 @@
|
||||
#define __text16_array( variable,array ) variable array
|
||||
#define __use_data16( variable ) variable
|
||||
#define __use_text16( variable ) variable
|
||||
#define __from_data16( variable ) variable
|
||||
#define __from_text16( variable ) variable
|
||||
#define __from_data16( pointer ) pointer
|
||||
#define __from_text16( pointer ) pointer
|
||||
|
||||
/* Real-mode data and code segments */
|
||||
static inline __attribute__ (( always_inline )) unsigned int _rm_cs ( void ) {
|
||||
|
||||
Regular → Executable
+28
-6
@@ -51,15 +51,17 @@ extern char *text16;
|
||||
( * ( ( typeof ( _text16_ ## variable ) * ) \
|
||||
& ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )
|
||||
|
||||
#define __from_data16( variable ) \
|
||||
( * ( ( typeof ( variable ) * ) \
|
||||
( ( ( void * ) &(variable) ) - ( ( void * ) data16 ) ) ) )
|
||||
#define __from_data16( pointer ) \
|
||||
( ( unsigned int ) \
|
||||
( ( ( void * ) (pointer) ) - ( ( void * ) data16 ) ) )
|
||||
|
||||
#define __from_text16( variable ) \
|
||||
( * ( ( typeof ( variable ) * ) \
|
||||
( ( ( void * ) &(variable) ) - ( ( void * ) text16 ) ) ) )
|
||||
#define __from_text16( pointer ) \
|
||||
( ( unsigned int ) \
|
||||
( ( ( void * ) (pointer) ) - ( ( void * ) text16 ) ) )
|
||||
|
||||
/* Variables in librm.S, present in the normal data segment */
|
||||
extern uint16_t rm_sp;
|
||||
extern uint16_t rm_ss;
|
||||
extern uint16_t __data16 ( rm_cs );
|
||||
#define rm_cs __use_data16 ( rm_cs )
|
||||
extern uint16_t __text16 ( rm_ds );
|
||||
@@ -210,6 +212,23 @@ strlen_user ( userptr_t buffer, off_t offset ) {
|
||||
return strlen ( ( void * ) buffer + offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find character in user buffer
|
||||
*
|
||||
* @v buffer User buffer
|
||||
* @v offset Starting offset within buffer
|
||||
* @v c Character to search for
|
||||
* @v len Length of user buffer
|
||||
* @ret offset Offset of character, or <0 if not found
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) off_t
|
||||
memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) {
|
||||
void *found;
|
||||
|
||||
found = memchr ( ( ( void * ) buffer + offset ), c, len );
|
||||
return ( found ? ( found - ( void * ) buffer ) : -1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert virtual address to user buffer
|
||||
*
|
||||
@@ -260,6 +279,9 @@ user_to_phys ( userptr_t buffer, off_t offset ) {
|
||||
return virt_to_phys ( ( void * ) buffer + offset );
|
||||
}
|
||||
|
||||
extern uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size );
|
||||
extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
|
||||
|
||||
/* TEXT16_CODE: declare a fragment of code that resides in .text16 */
|
||||
#define TEXT16_CODE( asm_code_str ) \
|
||||
".section \".text16\", \"ax\", @progbits\n\t" \
|
||||
|
||||
@@ -30,5 +30,6 @@ extern void pxe_hook_int1a ( void );
|
||||
extern int pxe_unhook_int1a ( void );
|
||||
extern void pxe_init_structures ( void );
|
||||
extern int pxe_start_nbp ( void );
|
||||
extern __cdecl void pxe_api_call ( struct i386_all_regs *ix86 );
|
||||
|
||||
#endif /* _PXE_CALL_H */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define JBLEN 6
|
||||
typedef unsigned long jmp_buf[JBLEN];
|
||||
|
||||
extern int setjmp (jmp_buf env);
|
||||
extern void longjmp (jmp_buf env, int val);
|
||||
extern int __cdecl setjmp (jmp_buf env);
|
||||
extern void __cdecl longjmp (jmp_buf env, int val);
|
||||
|
||||
#endif /* ETHERBOOT_SETJMP_H */
|
||||
|
||||
@@ -13,11 +13,21 @@ struct smbios_header {
|
||||
/** Type */
|
||||
uint8_t type;
|
||||
/** Length */
|
||||
uint8_t length;
|
||||
uint8_t len;
|
||||
/** Handle */
|
||||
uint16_t handle;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
/** SMBIOS structure descriptor */
|
||||
struct smbios_structure {
|
||||
/** Copy of SMBIOS structure header */
|
||||
struct smbios_header header;
|
||||
/** Offset of structure within SMBIOS */
|
||||
size_t offset;
|
||||
/** Length of strings section */
|
||||
size_t strings_len;
|
||||
};
|
||||
|
||||
/** SMBIOS system information structure */
|
||||
struct smbios_system_information {
|
||||
/** SMBIOS structure header */
|
||||
@@ -39,13 +49,12 @@ struct smbios_system_information {
|
||||
/** SMBIOS system information structure type */
|
||||
#define SMBIOS_TYPE_SYSTEM_INFORMATION 1
|
||||
|
||||
struct smbios_strings;
|
||||
extern int find_smbios_structure ( unsigned int type,
|
||||
void *structure, size_t length,
|
||||
struct smbios_strings *strings );
|
||||
extern int find_smbios_string ( struct smbios_strings *strings,
|
||||
struct smbios_structure *structure );
|
||||
extern int read_smbios_structure ( struct smbios_structure *structure,
|
||||
void *data, size_t len );
|
||||
extern int read_smbios_string ( struct smbios_structure *structure,
|
||||
unsigned int index,
|
||||
char *buffer, size_t length );
|
||||
extern int smbios_get_uuid ( union uuid *uuid );
|
||||
void *data, size_t len );
|
||||
|
||||
#endif /* _SMBIOS_H */
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef _STDARG_H
|
||||
#define _STDARG_H
|
||||
|
||||
typedef void * va_list;
|
||||
|
||||
#define va_start( ap, last ) do { \
|
||||
ap = ( &last + 1 ); \
|
||||
} while ( 0 )
|
||||
|
||||
#define va_arg( ap, type ) ({ \
|
||||
type *_this = ap; \
|
||||
ap = ( _this + 1 ); \
|
||||
*(_this); \
|
||||
})
|
||||
|
||||
#define va_end( ap ) do { } while ( 0 )
|
||||
|
||||
#define va_copy( dest, src ) do { \
|
||||
dest = src; \
|
||||
} while ( 0 )
|
||||
|
||||
#endif /* _STDARG_H */
|
||||
@@ -325,15 +325,20 @@ static int int13_get_extended_parameters ( struct int13_drive *drive,
|
||||
static __cdecl void int13 ( struct i386_all_regs *ix86 ) {
|
||||
int command = ix86->regs.ah;
|
||||
unsigned int bios_drive = ix86->regs.dl;
|
||||
unsigned int original_bios_drive = bios_drive;
|
||||
struct int13_drive *drive;
|
||||
int status;
|
||||
|
||||
list_for_each_entry ( drive, &drives, list ) {
|
||||
if ( drive->drive > bios_drive )
|
||||
continue;
|
||||
if ( drive->drive < bios_drive ) {
|
||||
original_bios_drive--;
|
||||
|
||||
if ( bios_drive != drive->drive ) {
|
||||
/* Remap any accesses to this drive's natural number */
|
||||
if ( bios_drive == drive->natural_drive ) {
|
||||
DBG ( "INT 13,%04x (%02x) remapped to "
|
||||
"(%02x)\n", ix86->regs.ax,
|
||||
bios_drive, drive->drive );
|
||||
ix86->regs.dl = drive->drive;
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -393,13 +398,6 @@ static __cdecl void int13 ( struct i386_all_regs *ix86 ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remap BIOS drive */
|
||||
if ( bios_drive != original_bios_drive ) {
|
||||
DBG ( "INT 13,%04x (%02x) remapped to (%02x)\n",
|
||||
ix86->regs.ax, bios_drive, original_bios_drive );
|
||||
}
|
||||
ix86->regs.dl = original_bios_drive;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,19 +540,28 @@ void register_int13_drive ( struct int13_drive *drive ) {
|
||||
/* Give drive a default geometry if none specified */
|
||||
guess_int13_geometry ( drive );
|
||||
|
||||
/* Assign drive number if none specified, update BIOS drive count */
|
||||
/* Assign natural drive number */
|
||||
get_real ( num_drives, BDA_SEG, BDA_NUM_DRIVES );
|
||||
if ( ( drive->drive & 0xff ) == 0xff )
|
||||
drive->drive = num_drives;
|
||||
drive->drive |= 0x80;
|
||||
drive->natural_drive = ( num_drives | 0x80 );
|
||||
num_drives++;
|
||||
if ( num_drives <= ( drive->drive & 0x7f ) )
|
||||
num_drives = ( ( drive->drive & 0x7f ) + 1 );
|
||||
|
||||
/* Assign drive number */
|
||||
if ( ( drive->drive & 0xff ) == 0xff ) {
|
||||
/* Drive number == -1 => use natural drive number */
|
||||
drive->drive = drive->natural_drive;
|
||||
} else {
|
||||
/* Use specified drive number (+0x80 if necessary) */
|
||||
drive->drive |= 0x80;
|
||||
if ( num_drives <= ( drive->drive & 0x7f ) )
|
||||
num_drives = ( ( drive->drive & 0x7f ) + 1 );
|
||||
}
|
||||
|
||||
/* Update BIOS drive count */
|
||||
put_real ( num_drives, BDA_SEG, BDA_NUM_DRIVES );
|
||||
|
||||
DBG ( "Registered INT13 drive %02x with C/H/S geometry %d/%d/%d\n",
|
||||
drive->drive, drive->cylinders, drive->heads,
|
||||
drive->sectors_per_track );
|
||||
DBG ( "Registered INT13 drive %02x (naturally %02x) with C/H/S "
|
||||
"geometry %d/%d/%d\n", drive->drive, drive->natural_drive,
|
||||
drive->cylinders, drive->heads, drive->sectors_per_track );
|
||||
|
||||
/* Hook INT 13 vector if not already hooked */
|
||||
if ( list_empty ( &drives ) )
|
||||
|
||||
@@ -96,6 +96,8 @@ union pxenv_call {
|
||||
PXENV_EXIT_t ( * file_select ) ( struct s_PXENV_FILE_SELECT * );
|
||||
PXENV_EXIT_t ( * file_read ) ( struct s_PXENV_FILE_READ * );
|
||||
PXENV_EXIT_t ( * get_file_size ) ( struct s_PXENV_GET_FILE_SIZE * );
|
||||
PXENV_EXIT_t ( * file_exec ) ( struct s_PXENV_FILE_EXEC * );
|
||||
PXENV_EXIT_t ( * file_api_check ) ( struct s_PXENV_FILE_API_CHECK * );
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -294,6 +296,14 @@ __cdecl void pxe_api_call ( struct i386_all_regs *ix86 ) {
|
||||
pxenv_call.get_file_size = pxenv_get_file_size;
|
||||
param_len = sizeof ( pxenv_any.get_file_size );
|
||||
break;
|
||||
case PXENV_FILE_EXEC:
|
||||
pxenv_call.file_exec = pxenv_file_exec;
|
||||
param_len = sizeof ( pxenv_any.file_exec );
|
||||
break;
|
||||
case PXENV_FILE_API_CHECK:
|
||||
pxenv_call.file_api_check = pxenv_file_api_check;
|
||||
param_len = sizeof ( pxenv_any.file_api_check );
|
||||
break;
|
||||
default:
|
||||
DBG ( "PXENV_UNKNOWN_%hx", opcode );
|
||||
pxenv_call.unknown = pxenv_unknown;
|
||||
@@ -337,6 +347,9 @@ __cdecl void pxe_loader_call ( struct i386_all_regs *ix86 ) {
|
||||
/* Copy parameter block from caller */
|
||||
copy_from_user ( ¶ms, uparams, 0, sizeof ( params ) );
|
||||
|
||||
/* Fill in ROM segment address */
|
||||
ppxe.UNDIROMID.segment = ix86->segs.ds;
|
||||
|
||||
/* Set default status in case child routine fails to do so */
|
||||
params.Status = PXENV_STATUS_FAILURE;
|
||||
|
||||
@@ -427,12 +440,13 @@ int pxe_start_nbp ( void ) {
|
||||
__asm__ __volatile__ ( REAL_CODE ( "pushw %%cx\n\t"
|
||||
"pushw %%ax\n\t"
|
||||
"movw %%cx, %%es\n\t"
|
||||
"sti\n\t"
|
||||
"lcall $0, $0x7c00\n\t"
|
||||
"addw $4, %%sp\n\t" )
|
||||
: "=a" ( rc ), "=b" ( discard_b ),
|
||||
"=c" ( discard_c )
|
||||
: "a" ( & __from_text16 ( ppxe ) ),
|
||||
"b" ( & __from_text16 ( pxenv ) ),
|
||||
: "a" ( __from_text16 ( &ppxe ) ),
|
||||
"b" ( __from_text16 ( &pxenv ) ),
|
||||
"c" ( rm_cs )
|
||||
: "edx", "esi", "edi", "ebp", "memory" );
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ ppxe:
|
||||
.byte 0 /* StructCksum */
|
||||
.byte 0 /* StructRev */
|
||||
.byte 0 /* reserved_1 */
|
||||
.word 0, 0 /* UNDIROMID */
|
||||
.word undiheader, 0 /* UNDIROMID */
|
||||
.word 0, 0 /* BaseROMID */
|
||||
.word pxe_entry_sp, 0 /* EntryPointSP */
|
||||
.word pxe_entry_esp, 0 /* EntryPointESP */
|
||||
@@ -55,6 +55,11 @@ pxe_segments:
|
||||
.equ pxe_length, . - ppxe
|
||||
.size ppxe, . - ppxe
|
||||
|
||||
/* Define undiheader=0 as a weak symbol for non-ROM builds */
|
||||
.section ".weak"
|
||||
.weak undiheader
|
||||
undiheader:
|
||||
|
||||
/****************************************************************************
|
||||
* PXENV+ structure
|
||||
****************************************************************************
|
||||
@@ -98,6 +103,16 @@ pxenv:
|
||||
* none
|
||||
****************************************************************************
|
||||
*/
|
||||
/* Wyse Streaming Manager server (WLDRM13.BIN) assumes that
|
||||
* the PXENV+ entry point is at UNDI_CS:0000; apparently,
|
||||
* somebody at Wyse has difficulty distinguishing between the
|
||||
* words "may" and "must"...
|
||||
*/
|
||||
.section ".text16.null"
|
||||
.code16
|
||||
pxenv_null_entry:
|
||||
jmp pxenv_entry
|
||||
|
||||
.section ".text16"
|
||||
.code16
|
||||
pxenv_entry:
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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 helpers
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <realmode.h>
|
||||
#include <comboot.h>
|
||||
#include <assert.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
|
||||
static com32sys_t __bss16 ( com32_regs );
|
||||
#define com32_regs __use_data16 ( com32_regs )
|
||||
|
||||
static uint8_t __bss16 ( com32_int_vector );
|
||||
#define com32_int_vector __use_data16 ( com32_int_vector )
|
||||
|
||||
static uint32_t __bss16 ( com32_farcall_proc );
|
||||
#define com32_farcall_proc __use_data16 ( com32_farcall_proc )
|
||||
|
||||
uint16_t __bss16 ( com32_saved_sp );
|
||||
|
||||
/**
|
||||
* Interrupt call helper
|
||||
*/
|
||||
void __cdecl com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physaddr_t outregs_phys ) {
|
||||
|
||||
memcpy_user ( virt_to_user( &com32_regs ), 0,
|
||||
phys_to_user ( inregs_phys ), 0,
|
||||
sizeof(com32sys_t) );
|
||||
|
||||
com32_int_vector = interrupt;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE ( /* Save all registers */
|
||||
"pushal\n\t"
|
||||
"pushw %%ds\n\t"
|
||||
"pushw %%es\n\t"
|
||||
"pushw %%fs\n\t"
|
||||
"pushw %%gs\n\t"
|
||||
/* Mask off unsafe flags */
|
||||
"movl (com32_regs + 40), %%eax\n\t"
|
||||
"andl $0x200cd7, %%eax\n\t"
|
||||
"movl %%eax, (com32_regs + 40)\n\t"
|
||||
/* Load com32_regs into the actual registers */
|
||||
"movw %%sp, %%ss:(com32_saved_sp)\n\t"
|
||||
"movw $com32_regs, %%sp\n\t"
|
||||
"popw %%gs\n\t"
|
||||
"popw %%fs\n\t"
|
||||
"popw %%es\n\t"
|
||||
"popw %%ds\n\t"
|
||||
"popal\n\t"
|
||||
"popfl\n\t"
|
||||
"movw %%ss:(com32_saved_sp), %%sp\n\t"
|
||||
/* patch INT instruction */
|
||||
"pushw %%ax\n\t"
|
||||
"movb %%ss:(com32_int_vector), %%al\n\t"
|
||||
"movb %%al, %%cs:(com32_intcall_instr + 1)\n\t"
|
||||
/* perform a jump to avoid problems with cache
|
||||
* consistency in self-modifying code on some CPUs (486)
|
||||
*/
|
||||
"jmp 1f\n"
|
||||
"1:\n\t"
|
||||
"popw %%ax\n\t"
|
||||
"com32_intcall_instr:\n\t"
|
||||
/* INT instruction to be patched */
|
||||
"int $0xFF\n\t"
|
||||
/* Copy regs back to com32_regs */
|
||||
"movw %%sp, %%ss:(com32_saved_sp)\n\t"
|
||||
"movw $(com32_regs + 44), %%sp\n\t"
|
||||
"pushfl\n\t"
|
||||
"pushal\n\t"
|
||||
"pushw %%ds\n\t"
|
||||
"pushw %%es\n\t"
|
||||
"pushw %%fs\n\t"
|
||||
"pushw %%gs\n\t"
|
||||
"movw %%ss:(com32_saved_sp), %%sp\n\t"
|
||||
/* Restore registers */
|
||||
"popw %%gs\n\t"
|
||||
"popw %%fs\n\t"
|
||||
"popw %%es\n\t"
|
||||
"popw %%ds\n\t"
|
||||
"popal\n\t")
|
||||
: : );
|
||||
|
||||
if ( outregs_phys ) {
|
||||
memcpy_user ( phys_to_user ( outregs_phys ), 0,
|
||||
virt_to_user( &com32_regs ), 0,
|
||||
sizeof(com32sys_t) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Farcall helper
|
||||
*/
|
||||
void __cdecl com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t outregs_phys ) {
|
||||
|
||||
memcpy_user ( virt_to_user( &com32_regs ), 0,
|
||||
phys_to_user ( inregs_phys ), 0,
|
||||
sizeof(com32sys_t) );
|
||||
|
||||
com32_farcall_proc = proc;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE ( /* Save all registers */
|
||||
"pushal\n\t"
|
||||
"pushw %%ds\n\t"
|
||||
"pushw %%es\n\t"
|
||||
"pushw %%fs\n\t"
|
||||
"pushw %%gs\n\t"
|
||||
/* Mask off unsafe flags */
|
||||
"movl (com32_regs + 40), %%eax\n\t"
|
||||
"andl $0x200cd7, %%eax\n\t"
|
||||
"movl %%eax, (com32_regs + 40)\n\t"
|
||||
/* Load com32_regs into the actual registers */
|
||||
"movw %%sp, %%ss:(com32_saved_sp)\n\t"
|
||||
"movw $com32_regs, %%sp\n\t"
|
||||
"popw %%gs\n\t"
|
||||
"popw %%fs\n\t"
|
||||
"popw %%es\n\t"
|
||||
"popw %%ds\n\t"
|
||||
"popal\n\t"
|
||||
"popfl\n\t"
|
||||
"movw %%ss:(com32_saved_sp), %%sp\n\t"
|
||||
/* Call procedure */
|
||||
"lcall *%%ss:(com32_farcall_proc)\n\t"
|
||||
/* Copy regs back to com32_regs */
|
||||
"movw %%sp, %%ss:(com32_saved_sp)\n\t"
|
||||
"movw $(com32_regs + 44), %%sp\n\t"
|
||||
"pushfl\n\t"
|
||||
"pushal\n\t"
|
||||
"pushw %%ds\n\t"
|
||||
"pushw %%es\n\t"
|
||||
"pushw %%fs\n\t"
|
||||
"pushw %%gs\n\t"
|
||||
"movw %%ss:(com32_saved_sp), %%sp\n\t"
|
||||
/* Restore registers */
|
||||
"popw %%gs\n\t"
|
||||
"popw %%fs\n\t"
|
||||
"popw %%es\n\t"
|
||||
"popw %%ds\n\t"
|
||||
"popal\n\t")
|
||||
: : );
|
||||
|
||||
if ( outregs_phys ) {
|
||||
memcpy_user ( phys_to_user ( outregs_phys ), 0,
|
||||
virt_to_user( &com32_regs ), 0,
|
||||
sizeof(com32sys_t) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CDECL farcall helper
|
||||
*/
|
||||
int __cdecl com32_cfarcall ( uint32_t proc, physaddr_t stack, size_t stacksz ) {
|
||||
int32_t eax;
|
||||
|
||||
copy_user_to_rm_stack ( phys_to_user ( stack ), stacksz );
|
||||
com32_farcall_proc = proc;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE ( "lcall *%%ss:(com32_farcall_proc)\n\t" )
|
||||
: "=a" (eax)
|
||||
:
|
||||
: "ecx", "edx" );
|
||||
|
||||
remove_user_from_rm_stack ( 0, stacksz );
|
||||
|
||||
return eax;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.code32
|
||||
|
||||
.globl com32_farcall_wrapper
|
||||
com32_farcall_wrapper:
|
||||
|
||||
movl $com32_farcall, %eax
|
||||
jmp com32_wrapper
|
||||
|
||||
|
||||
.globl com32_cfarcall_wrapper
|
||||
com32_cfarcall_wrapper:
|
||||
|
||||
movl $com32_cfarcall, %eax
|
||||
jmp com32_wrapper
|
||||
|
||||
|
||||
.globl com32_intcall_wrapper
|
||||
com32_intcall_wrapper:
|
||||
|
||||
movl $com32_intcall, %eax
|
||||
/*jmp com32_wrapper*/ /* fall through */
|
||||
|
||||
com32_wrapper:
|
||||
|
||||
/* Switch to internal virtual address space */
|
||||
call _phys_to_virt
|
||||
|
||||
mov %eax, (com32_helper_function)
|
||||
|
||||
/* Save external COM32 stack pointer */
|
||||
movl %esp, (com32_external_esp)
|
||||
|
||||
/* Copy arguments to caller-save registers */
|
||||
movl 12(%esp), %eax
|
||||
movl 8(%esp), %ecx
|
||||
movl 4(%esp), %edx
|
||||
|
||||
/* Switch to internal stack */
|
||||
movl (com32_internal_esp), %esp
|
||||
|
||||
/* Copy arguments to internal stack */
|
||||
pushl %eax
|
||||
pushl %ecx
|
||||
pushl %edx
|
||||
|
||||
call *(com32_helper_function)
|
||||
|
||||
/* Clean up stack */
|
||||
addl $12, %esp
|
||||
|
||||
/* Save internal stack pointer and restore external stack pointer */
|
||||
movl %esp, (com32_internal_esp)
|
||||
movl (com32_external_esp), %esp
|
||||
|
||||
/* Switch to external flat physical address space */
|
||||
call _virt_to_phys
|
||||
|
||||
ret
|
||||
|
||||
|
||||
.data
|
||||
|
||||
/* Internal gPXE virtual address space %esp */
|
||||
.globl com32_internal_esp
|
||||
.lcomm com32_internal_esp, 4
|
||||
|
||||
/* External flat physical address space %esp */
|
||||
.globl com32_external_esp
|
||||
.lcomm com32_external_esp, 4
|
||||
|
||||
/* Function pointer of helper to call */
|
||||
.lcomm com32_helper_function, 4
|
||||
@@ -0,0 +1,598 @@
|
||||
/*
|
||||
* 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 API
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <realmode.h>
|
||||
#include <biosint.h>
|
||||
#include <console.h>
|
||||
#include <stdlib.h>
|
||||
#include <comboot.h>
|
||||
#include <bzimage.h>
|
||||
#include <pxe_call.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <gpxe/posix_io.h>
|
||||
#include <gpxe/process.h>
|
||||
#include <gpxe/serial.h>
|
||||
#include <gpxe/init.h>
|
||||
|
||||
/** The "SYSLINUX" version string */
|
||||
static char __data16_array ( syslinux_version, [] ) = "gPXE " VERSION;
|
||||
#define syslinux_version __use_data16 ( syslinux_version )
|
||||
|
||||
/** The "SYSLINUX" copyright string */
|
||||
static char __data16_array ( syslinux_copyright, [] ) = "http://etherboot.org";
|
||||
#define syslinux_copyright __use_data16 ( syslinux_copyright )
|
||||
|
||||
static char __data16_array ( syslinux_configuration_file, [] ) = "";
|
||||
#define syslinux_configuration_file __use_data16 ( syslinux_configuration_file )
|
||||
|
||||
/** Feature flags */
|
||||
static uint8_t __data16 ( comboot_feature_flags ) = COMBOOT_FEATURE_IDLE_LOOP;
|
||||
#define comboot_feature_flags __use_data16 ( comboot_feature_flags )
|
||||
|
||||
static struct segoff __text16 ( int20_vector );
|
||||
#define int20_vector __use_text16 ( int20_vector )
|
||||
|
||||
static struct segoff __text16 ( int21_vector );
|
||||
#define int21_vector __use_text16 ( int21_vector )
|
||||
|
||||
static struct segoff __text16 ( int22_vector );
|
||||
#define int22_vector __use_text16 ( int22_vector )
|
||||
|
||||
extern void int20_wrapper ( void );
|
||||
extern void int21_wrapper ( void );
|
||||
extern void int22_wrapper ( void );
|
||||
|
||||
/* setjmp/longjmp context buffer used to return after loading an image */
|
||||
jmp_buf comboot_return;
|
||||
|
||||
/* Command line to execute when returning via comboot_return
|
||||
* with COMBOOT_RETURN_RUN_KERNEL
|
||||
*/
|
||||
char *comboot_kernel_cmdline;
|
||||
|
||||
/* Mode flags set by INT 22h AX=0017h */
|
||||
static uint16_t comboot_graphics_mode = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Print a string with a particular terminator
|
||||
*/
|
||||
static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) {
|
||||
int i = 0;
|
||||
char c;
|
||||
userptr_t str = real_to_user ( segment, offset );
|
||||
for ( ; ; ) {
|
||||
copy_from_user ( &c, str, i, 1 );
|
||||
if ( c == terminator ) break;
|
||||
putchar ( c );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform a series of memory copies from a list in low memory
|
||||
*/
|
||||
static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsigned int count )
|
||||
{
|
||||
comboot_shuffle_descriptor shuf[COMBOOT_MAX_SHUFFLE_DESCRIPTORS];
|
||||
unsigned int i;
|
||||
|
||||
/* Copy shuffle descriptor list so it doesn't get overwritten */
|
||||
copy_from_user ( shuf, real_to_user ( list_segment, list_offset ), 0,
|
||||
count * sizeof( comboot_shuffle_descriptor ) );
|
||||
|
||||
/* Do the copies */
|
||||
for ( i = 0; i < count; i++ ) {
|
||||
userptr_t src_u = phys_to_user ( shuf[ i ].src );
|
||||
userptr_t dest_u = phys_to_user ( shuf[ i ].dest );
|
||||
|
||||
if ( shuf[ i ].src == 0xFFFFFFFF ) {
|
||||
/* Fill with 0 instead of copying */
|
||||
memset_user ( dest_u, 0, 0, shuf[ i ].len );
|
||||
} else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
|
||||
/* Copy new list of descriptors */
|
||||
count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
|
||||
assert ( count <= COMBOOT_MAX_SHUFFLE_DESCRIPTORS );
|
||||
copy_from_user ( shuf, src_u, 0, shuf[ i ].len );
|
||||
i = -1;
|
||||
} else {
|
||||
/* Regular copy */
|
||||
memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set default text mode
|
||||
*/
|
||||
void comboot_force_text_mode ( void ) {
|
||||
if ( comboot_graphics_mode & COMBOOT_VIDEO_VESA ) {
|
||||
/* Set VGA mode 3 via VESA VBE mode set */
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE (
|
||||
"mov $0x4F02, %%ax\n\t"
|
||||
"mov $0x03, %%bx\n\t"
|
||||
"int $0x10\n\t"
|
||||
)
|
||||
: : );
|
||||
} else if ( comboot_graphics_mode & COMBOOT_VIDEO_GRAPHICS ) {
|
||||
/* Set VGA mode 3 via standard VGA mode set */
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE (
|
||||
"mov $0x03, %%ax\n\t"
|
||||
"int $0x10\n\t"
|
||||
)
|
||||
: : );
|
||||
}
|
||||
|
||||
comboot_graphics_mode = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the kernel specified in comboot_kernel_cmdline
|
||||
*/
|
||||
void comboot_run_kernel ( )
|
||||
{
|
||||
char *initrd;
|
||||
|
||||
comboot_force_text_mode ( );
|
||||
|
||||
DBG ( "COMBOOT: executing image '%s'\n", comboot_kernel_cmdline );
|
||||
|
||||
/* Find initrd= parameter, if any */
|
||||
if ( ( initrd = strstr ( comboot_kernel_cmdline, "initrd=" ) ) ) {
|
||||
char old_char = '\0';
|
||||
char *initrd_end = strchr( initrd, ' ' );
|
||||
|
||||
/* Replace space after end of parameter
|
||||
* with a nul terminator if this is not
|
||||
* the last parameter
|
||||
*/
|
||||
if ( initrd_end ) {
|
||||
old_char = *initrd_end;
|
||||
*initrd_end = '\0';
|
||||
}
|
||||
|
||||
/* Replace = with space to get 'initrd filename'
|
||||
* command suitable for system()
|
||||
*/
|
||||
initrd[6] = ' ';
|
||||
|
||||
DBG( "COMBOOT: loading initrd '%s'\n", initrd );
|
||||
|
||||
system ( initrd );
|
||||
|
||||
/* Restore space after parameter */
|
||||
if ( initrd_end ) {
|
||||
*initrd_end = old_char;
|
||||
}
|
||||
|
||||
/* Restore = */
|
||||
initrd[6] = '=';
|
||||
}
|
||||
|
||||
/* Load kernel */
|
||||
DBG ( "COMBOOT: loading kernel '%s'\n", comboot_kernel_cmdline );
|
||||
system ( comboot_kernel_cmdline );
|
||||
|
||||
free ( comboot_kernel_cmdline );
|
||||
|
||||
/* Boot */
|
||||
system ( "boot" );
|
||||
|
||||
DBG ( "COMBOOT: back from executing command\n" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Terminate program interrupt handler
|
||||
*/
|
||||
static __cdecl void int20 ( struct i386_all_regs *ix86 __unused ) {
|
||||
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DOS-compatible API
|
||||
*/
|
||||
static __cdecl void int21 ( struct i386_all_regs *ix86 ) {
|
||||
ix86->flags |= CF;
|
||||
|
||||
switch ( ix86->regs.ah ) {
|
||||
case 0x00:
|
||||
case 0x4C: /* Terminate program */
|
||||
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
|
||||
break;
|
||||
|
||||
case 0x01: /* Get Key with Echo */
|
||||
case 0x08: /* Get Key without Echo */
|
||||
/* TODO: handle extended characters? */
|
||||
ix86->regs.al = getchar( );
|
||||
|
||||
/* Enter */
|
||||
if ( ix86->regs.al == 0x0A )
|
||||
ix86->regs.al = 0x0D;
|
||||
|
||||
if ( ix86->regs.ah == 0x01 )
|
||||
putchar ( ix86->regs.al );
|
||||
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x02: /* Write Character */
|
||||
putchar ( ix86->regs.dl );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x04: /* Write Character to Serial Port */
|
||||
serial_putc ( ix86->regs.dl );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x09: /* Write DOS String to Console */
|
||||
print_user_string ( ix86->segs.ds, ix86->regs.dx, '$' );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0B: /* Check Keyboard */
|
||||
if ( iskey() )
|
||||
ix86->regs.al = 0xFF;
|
||||
else
|
||||
ix86->regs.al = 0x00;
|
||||
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x30: /* Check DOS Version */
|
||||
/* Bottom halves all 0; top halves spell "SYSLINUX" */
|
||||
ix86->regs.eax = 0x59530000;
|
||||
ix86->regs.ebx = 0x4C530000;
|
||||
ix86->regs.ecx = 0x4E490000;
|
||||
ix86->regs.edx = 0x58550000;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
default:
|
||||
DBG ( "COMBOOT unknown int21 function %02x\n", ix86->regs.ah );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SYSLINUX API
|
||||
*/
|
||||
static __cdecl void int22 ( struct i386_all_regs *ix86 ) {
|
||||
ix86->flags |= CF;
|
||||
|
||||
switch ( ix86->regs.ax ) {
|
||||
case 0x0001: /* Get Version */
|
||||
|
||||
/* Number of INT 22h API functions available */
|
||||
ix86->regs.ax = 0x0018;
|
||||
|
||||
/* SYSLINUX version number */
|
||||
ix86->regs.ch = 0; /* major */
|
||||
ix86->regs.cl = 0; /* minor */
|
||||
|
||||
/* SYSLINUX derivative ID */
|
||||
ix86->regs.dl = BZI_LOADER_TYPE_GPXE;
|
||||
|
||||
/* SYSLINUX version and copyright strings */
|
||||
ix86->segs.es = rm_ds;
|
||||
ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
|
||||
ix86->regs.di = ( ( unsigned ) __from_data16 ( syslinux_copyright ) );
|
||||
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0002: /* Write String */
|
||||
print_user_string ( ix86->segs.es, ix86->regs.bx, '\0' );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0003: /* Run command */
|
||||
{
|
||||
userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
|
||||
int len = strlen_user ( cmd_u, 0 );
|
||||
char cmd[len + 1];
|
||||
copy_from_user ( cmd, cmd_u, 0, len + 1 );
|
||||
DBG ( "COMBOOT: executing command '%s'\n", cmd );
|
||||
|
||||
comboot_kernel_cmdline = strdup ( cmd );
|
||||
|
||||
DBG ( "COMBOOT: returning to run image...\n" );
|
||||
longjmp ( comboot_return, COMBOOT_RETURN_RUN_KERNEL );
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0004: /* Run default command */
|
||||
/* FIXME: just exit for now */
|
||||
longjmp ( comboot_return, COMBOOT_RETURN_EXIT );
|
||||
break;
|
||||
|
||||
case 0x0005: /* Force text mode */
|
||||
comboot_force_text_mode ( );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0006: /* Open file */
|
||||
{
|
||||
int fd;
|
||||
userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
|
||||
int len = strlen_user ( file_u, 0 );
|
||||
char file[len + 1];
|
||||
|
||||
copy_from_user ( file, file_u, 0, len + 1 );
|
||||
|
||||
if ( file[0] == '\0' ) {
|
||||
DBG ( "COMBOOT: attempted open with empty file name\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
DBG ( "COMBOOT: opening file '%s'\n", file );
|
||||
|
||||
fd = open ( file );
|
||||
|
||||
if ( fd < 0 ) {
|
||||
DBG ( "COMBOOT: error opening file %s\n", file );
|
||||
break;
|
||||
}
|
||||
|
||||
/* This relies on the fact that a gPXE POSIX fd will
|
||||
* always fit in 16 bits.
|
||||
*/
|
||||
#if (POSIX_FD_MAX > 65535)
|
||||
#error POSIX_FD_MAX too large
|
||||
#endif
|
||||
ix86->regs.si = (uint16_t) fd;
|
||||
|
||||
ix86->regs.cx = COMBOOT_FILE_BLOCKSZ;
|
||||
ix86->regs.eax = fsize ( fd );
|
||||
ix86->flags &= ~CF;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0007: /* Read file */
|
||||
{
|
||||
int fd = ix86->regs.si;
|
||||
int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ;
|
||||
int rc;
|
||||
fd_set fds;
|
||||
userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx );
|
||||
|
||||
/* Wait for data ready to read */
|
||||
FD_ZERO ( &fds );
|
||||
FD_SET ( fd, &fds );
|
||||
|
||||
select ( &fds, 1 );
|
||||
|
||||
rc = read_user ( fd, buf, 0, len );
|
||||
if ( rc < 0 ) {
|
||||
DBG ( "COMBOOT: read failed\n" );
|
||||
ix86->regs.si = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ix86->regs.ecx = rc;
|
||||
ix86->flags &= ~CF;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0008: /* Close file */
|
||||
{
|
||||
int fd = ix86->regs.si;
|
||||
close ( fd );
|
||||
ix86->flags &= ~CF;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0009: /* Call PXE Stack */
|
||||
pxe_api_call ( ix86 );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x000A: /* Get Derivative-Specific Information */
|
||||
|
||||
/* gPXE has its own derivative ID, so there is no defined
|
||||
* output here; just return AL for now */
|
||||
ix86->regs.al = BZI_LOADER_TYPE_GPXE;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x000B: /* Get Serial Console Configuration */
|
||||
/* FIXME: stub */
|
||||
ix86->regs.dx = 0;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x000E: /* Get configuration file name */
|
||||
/* FIXME: stub */
|
||||
ix86->segs.es = rm_ds;
|
||||
ix86->regs.bx = ( ( unsigned ) __from_data16 ( syslinux_configuration_file ) );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x000F: /* Get IPAPPEND strings */
|
||||
/* FIXME: stub */
|
||||
ix86->regs.cx = 0;
|
||||
ix86->segs.es = 0;
|
||||
ix86->regs.bx = 0;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0010: /* Resolve hostname */
|
||||
{
|
||||
userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
|
||||
int len = strlen_user ( hostname_u, 0 );
|
||||
char hostname[len];
|
||||
struct in_addr addr;
|
||||
|
||||
copy_from_user ( hostname, hostname_u, 0, len + 1 );
|
||||
|
||||
/* TODO:
|
||||
* "If the hostname does not contain a dot (.), the
|
||||
* local domain name is automatically appended."
|
||||
*/
|
||||
|
||||
comboot_resolv ( hostname, &addr );
|
||||
|
||||
ix86->regs.eax = addr.s_addr;
|
||||
ix86->flags &= ~CF;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0011: /* Maximum number of shuffle descriptors */
|
||||
ix86->regs.cx = COMBOOT_MAX_SHUFFLE_DESCRIPTORS;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0012: /* Cleanup, shuffle and boot */
|
||||
if ( ix86->regs.cx > COMBOOT_MAX_SHUFFLE_DESCRIPTORS )
|
||||
break;
|
||||
|
||||
/* Perform final cleanup */
|
||||
shutdown ( SHUTDOWN_BOOT );
|
||||
|
||||
/* Perform sequence of copies */
|
||||
shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
|
||||
|
||||
/* Jump to real-mode entry point */
|
||||
__asm__ __volatile__ (
|
||||
REAL_CODE (
|
||||
"pushw %0\n\t"
|
||||
"popw %%ds\n\t"
|
||||
"pushl %1\n\t"
|
||||
"lret\n\t"
|
||||
)
|
||||
:
|
||||
: "r" ( ix86->segs.ds ),
|
||||
"r" ( ix86->regs.ebp ),
|
||||
"d" ( ix86->regs.ebx ),
|
||||
"S" ( ix86->regs.esi ) );
|
||||
|
||||
assert ( 0 ); /* Execution should never reach this point */
|
||||
|
||||
break;
|
||||
|
||||
case 0x0013: /* Idle loop call */
|
||||
step ( );
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0015: /* Get feature flags */
|
||||
ix86->segs.es = rm_ds;
|
||||
ix86->regs.bx = ( ( unsigned ) __from_data16 ( &comboot_feature_flags ) );
|
||||
ix86->regs.cx = 1; /* Number of feature flag bytes */
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0016: /* Run kernel image */
|
||||
{
|
||||
userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
|
||||
userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
|
||||
int file_len = strlen_user ( file_u, 0 );
|
||||
int cmd_len = strlen_user ( cmd_u, 0 );
|
||||
char file[file_len + 1 + cmd_len + 7 + 1];
|
||||
char cmd[cmd_len + 1];
|
||||
|
||||
memcpy( file, "kernel ", 7 );
|
||||
copy_from_user ( file + 7, file_u, 0, file_len + 1 );
|
||||
copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
|
||||
strcat ( file, " " );
|
||||
strcat ( file, cmd );
|
||||
|
||||
DBG ( "COMBOOT: run kernel image '%s'\n", file );
|
||||
|
||||
comboot_kernel_cmdline = strdup ( file );
|
||||
|
||||
DBG ( "COMBOOT: returning to run image...\n" );
|
||||
longjmp ( comboot_return, COMBOOT_RETURN_RUN_KERNEL );
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0017: /* Report video mode change */
|
||||
comboot_graphics_mode = ix86->regs.bx;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
case 0x0018: /* Query custom font */
|
||||
/* FIXME: stub */
|
||||
ix86->regs.al = 0;
|
||||
ix86->segs.es = 0;
|
||||
ix86->regs.bx = 0;
|
||||
ix86->flags &= ~CF;
|
||||
break;
|
||||
|
||||
default:
|
||||
DBG ( "COMBOOT unknown int22 function %04x\n", ix86->regs.ax );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook BIOS interrupts related to COMBOOT API (INT 20h, 21h, 22h)
|
||||
*/
|
||||
void hook_comboot_interrupts ( ) {
|
||||
|
||||
__asm__ __volatile__ (
|
||||
TEXT16_CODE ( "\nint20_wrapper:\n\t"
|
||||
"pushl %0\n\t"
|
||||
"pushw %%cs\n\t"
|
||||
"call prot_call\n\t"
|
||||
"addw $4, %%sp\n\t"
|
||||
"iret\n\t" )
|
||||
: : "i" ( int20 ) );
|
||||
|
||||
hook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper,
|
||||
&int20_vector );
|
||||
|
||||
__asm__ __volatile__ (
|
||||
TEXT16_CODE ( "\nint21_wrapper:\n\t"
|
||||
"pushl %0\n\t"
|
||||
"pushw %%cs\n\t"
|
||||
"call prot_call\n\t"
|
||||
"addw $4, %%sp\n\t"
|
||||
"iret\n\t" )
|
||||
: : "i" ( int21 ) );
|
||||
|
||||
hook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper,
|
||||
&int21_vector );
|
||||
|
||||
__asm__ __volatile__ (
|
||||
TEXT16_CODE ( "\nint22_wrapper:\n\t"
|
||||
"pushl %0\n\t"
|
||||
"pushw %%cs\n\t"
|
||||
"call prot_call\n\t"
|
||||
"addw $4, %%sp\n\t"
|
||||
"iret\n\t" )
|
||||
: : "i" ( int22) );
|
||||
|
||||
hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper,
|
||||
&int22_vector );
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <errno.h>
|
||||
#include <comboot.h>
|
||||
#include <gpxe/in.h>
|
||||
#include <gpxe/list.h>
|
||||
#include <gpxe/process.h>
|
||||
#include <gpxe/resolv.h>
|
||||
|
||||
static int comboot_resolv_rc;
|
||||
static struct in_addr comboot_resolv_addr;
|
||||
|
||||
static void comboot_resolv_done ( struct resolv_interface *resolv,
|
||||
struct sockaddr *sa, int rc ) {
|
||||
struct sockaddr_in *sin;
|
||||
|
||||
resolv_unplug ( resolv );
|
||||
|
||||
if ( rc != 0 ) {
|
||||
comboot_resolv_rc = rc;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sa->sa_family != AF_INET ) {
|
||||
comboot_resolv_rc = -EAFNOSUPPORT;
|
||||
return;
|
||||
}
|
||||
|
||||
sin = ( ( struct sockaddr_in * ) sa );
|
||||
comboot_resolv_addr = sin->sin_addr;
|
||||
|
||||
comboot_resolv_rc = 0;
|
||||
}
|
||||
|
||||
static struct resolv_interface_operations comboot_resolv_ops = {
|
||||
.done = comboot_resolv_done,
|
||||
};
|
||||
|
||||
static struct resolv_interface comboot_resolver = {
|
||||
.intf = {
|
||||
.dest = &null_resolv.intf,
|
||||
.refcnt = NULL,
|
||||
},
|
||||
.op = &comboot_resolv_ops,
|
||||
};
|
||||
|
||||
int comboot_resolv ( const char *name, struct in_addr *address ) {
|
||||
int rc;
|
||||
|
||||
comboot_resolv_rc = -EINPROGRESS;
|
||||
|
||||
if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
while ( comboot_resolv_rc == -EINPROGRESS )
|
||||
step();
|
||||
|
||||
*address = comboot_resolv_addr;
|
||||
return comboot_resolv_rc;
|
||||
}
|
||||
+321
-144
@@ -17,6 +17,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
.arch i386
|
||||
.section ".prefix.lib", "awx", @progbits
|
||||
.section ".data16", "aw", @progbits
|
||||
|
||||
/**
|
||||
* High memory temporary load address
|
||||
*
|
||||
@@ -27,24 +31,173 @@
|
||||
* We use the start of an even megabyte so that we don't have to worry
|
||||
* about the current state of the A20 line.
|
||||
*
|
||||
* We use 4MB rather than 2MB because there is at least one commercial
|
||||
* PXE ROM ("Broadcom UNDI, PXE-2.1 (build 082) v2.0.4") which stores
|
||||
* data required by the UNDI ROM loader (yes, the ROM loader; that's
|
||||
* the component which should be impossible to damage short of
|
||||
* screwing with the MMU) around the 2MB mark. Sadly, this is not a
|
||||
* joke.
|
||||
*
|
||||
* We use 4MB rather than 2MB because some PXE stack / PMM BIOS
|
||||
* combinations are known to place data required by other UNDI ROMs
|
||||
* loader around the 2MB mark.
|
||||
*/
|
||||
#define HIGHMEM_LOADPOINT ( 4 << 20 )
|
||||
.globl HIGHMEM_LOADPOINT
|
||||
.equ HIGHMEM_LOADPOINT, ( 4 << 20 )
|
||||
|
||||
/* Image compression enabled */
|
||||
#define COMPRESS 1
|
||||
|
||||
#define CR0_PE 1
|
||||
|
||||
.arch i386
|
||||
.section ".prefix.lib", "awx", @progbits
|
||||
.section ".data16", "aw", @progbits
|
||||
/*****************************************************************************
|
||||
* Utility function: print character (with LF -> LF,CR translation)
|
||||
*
|
||||
* Parameters:
|
||||
* %al : character to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl print_character
|
||||
print_character:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
pushw %bx
|
||||
pushw %bp
|
||||
/* If %di is non-zero, write character to buffer and exit */
|
||||
testw %di, %di
|
||||
jz 1f
|
||||
movb %al, %ds:(%di)
|
||||
incw %di
|
||||
jmp 3f
|
||||
1: /* Print character */
|
||||
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
|
||||
movb $0x0e, %ah /* write char, tty mode */
|
||||
cmpb $0x0a, %al /* '\n'? */
|
||||
jne 2f
|
||||
int $0x10
|
||||
movb $0x0d, %al
|
||||
2: int $0x10
|
||||
/* Restore registers and return */
|
||||
3: popw %bp
|
||||
popw %bx
|
||||
popw %ax
|
||||
ret
|
||||
.size print_character, . - print_character
|
||||
|
||||
/*****************************************************************************
|
||||
* Utility function: print a NUL-terminated string
|
||||
*
|
||||
* Parameters:
|
||||
* %ds:si : string to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* %ds:si : character after terminating NUL
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl print_message
|
||||
print_message:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
/* Print string */
|
||||
1: lodsb
|
||||
testb %al, %al
|
||||
je 2f
|
||||
call print_character
|
||||
jmp 1b
|
||||
2: /* Restore registers and return */
|
||||
popw %ax
|
||||
ret
|
||||
.size print_message, . - print_message
|
||||
|
||||
/*****************************************************************************
|
||||
* Utility functions: print hex digit/byte/word/dword
|
||||
*
|
||||
* Parameters:
|
||||
* %al (low nibble) : digit to print
|
||||
* %al : byte to print
|
||||
* %ax : word to print
|
||||
* %eax : dword to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl print_hex_dword
|
||||
print_hex_dword:
|
||||
rorl $16, %eax
|
||||
call print_hex_word
|
||||
rorl $16, %eax
|
||||
/* Fall through */
|
||||
.size print_hex_dword, . - print_hex_dword
|
||||
.globl print_hex_word
|
||||
print_hex_word:
|
||||
xchgb %al, %ah
|
||||
call print_hex_byte
|
||||
xchgb %al, %ah
|
||||
/* Fall through */
|
||||
.size print_hex_word, . - print_hex_word
|
||||
.globl print_hex_byte
|
||||
print_hex_byte:
|
||||
rorb $4, %al
|
||||
call print_hex_nibble
|
||||
rorb $4, %al
|
||||
/* Fall through */
|
||||
.size print_hex_byte, . - print_hex_byte
|
||||
.globl print_hex_nibble
|
||||
print_hex_nibble:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
/* Print digit (technique by Norbert Juffa <norbert.juffa@amd.com> */
|
||||
andb $0x0f, %al
|
||||
cmpb $10, %al
|
||||
sbbb $0x69, %al
|
||||
das
|
||||
call print_character
|
||||
/* Restore registers and return */
|
||||
popw %ax
|
||||
ret
|
||||
.size print_hex_nibble, . - print_hex_nibble
|
||||
|
||||
/*****************************************************************************
|
||||
* Utility function: print PCI bus:dev.fn
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : PCI bus:dev.fn to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl print_pci_busdevfn
|
||||
print_pci_busdevfn:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
/* Print bus */
|
||||
xchgb %al, %ah
|
||||
call print_hex_byte
|
||||
/* Print ":" */
|
||||
movb $':', %al
|
||||
call print_character
|
||||
/* Print device */
|
||||
movb %ah, %al
|
||||
shrb $3, %al
|
||||
call print_hex_byte
|
||||
/* Print "." */
|
||||
movb $'.', %al
|
||||
call print_character
|
||||
/* Print function */
|
||||
movb %ah, %al
|
||||
andb $0x07, %al
|
||||
call print_hex_nibble
|
||||
/* Restore registers and return */
|
||||
popw %ax
|
||||
ret
|
||||
.size print_pci_busdevfn, . - print_pci_busdevfn
|
||||
|
||||
/****************************************************************************
|
||||
* pm_call (real-mode near call)
|
||||
@@ -70,13 +223,14 @@
|
||||
#ifndef KEEP_IT_REAL
|
||||
|
||||
/* GDT for protected-mode calls */
|
||||
.section ".data16"
|
||||
.section ".prefix.lib"
|
||||
.align 16
|
||||
pm_call_vars:
|
||||
gdt:
|
||||
gdt_limit: .word gdt_length - 1
|
||||
gdt_base: .long 0
|
||||
.word 0 /* padding */
|
||||
pm_cs: /* 16-bit protected-mode code segment */
|
||||
pm_cs: /* 16-bit protected-mode code segment */
|
||||
.equ PM_CS, pm_cs - gdt
|
||||
.word 0xffff, 0
|
||||
.byte 0, 0x9b, 0x00, 0
|
||||
@@ -92,18 +246,24 @@ gdt_end:
|
||||
.equ gdt_length, . - gdt
|
||||
.size gdt, . - gdt
|
||||
|
||||
.section ".data16"
|
||||
.section ".prefix.lib"
|
||||
.align 16
|
||||
pm_saved_gdt:
|
||||
.long 0, 0
|
||||
.size pm_saved_gdt, . - pm_saved_gdt
|
||||
|
||||
.equ pm_call_vars_size, . - pm_call_vars
|
||||
#define PM_CALL_VAR(x) ( -pm_call_vars_size + ( (x) - pm_call_vars ) )
|
||||
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
pm_call:
|
||||
/* Preserve registers, flags, GDT, and RM return point */
|
||||
/* Preserve registers, flags, and RM return point */
|
||||
pushw %bp
|
||||
movw %sp, %bp
|
||||
subw $pm_call_vars_size, %sp
|
||||
andw $0xfff0, %sp
|
||||
pushfl
|
||||
sgdt pm_saved_gdt
|
||||
pushw %gs
|
||||
pushw %fs
|
||||
pushw %es
|
||||
@@ -112,27 +272,43 @@ pm_call:
|
||||
pushw %cs
|
||||
pushw $99f
|
||||
|
||||
/* Set up local variable block, and preserve GDT */
|
||||
pushw %cx
|
||||
pushw %si
|
||||
pushw %di
|
||||
pushw %ss
|
||||
popw %es
|
||||
movw $pm_call_vars, %si
|
||||
leaw PM_CALL_VAR(pm_call_vars)(%bp), %di
|
||||
movw $pm_call_vars_size, %cx
|
||||
cs rep movsb
|
||||
popw %di
|
||||
popw %si
|
||||
popw %cx
|
||||
sgdt PM_CALL_VAR(pm_saved_gdt)(%bp)
|
||||
|
||||
/* Set up GDT bases */
|
||||
pushl %eax
|
||||
pushw %bx
|
||||
pushl %edi
|
||||
xorl %eax, %eax
|
||||
movw %ds, %ax
|
||||
movw %ss, %ax
|
||||
shll $4, %eax
|
||||
addl $gdt, %eax
|
||||
movl %eax, gdt_base
|
||||
movzwl %bp, %edi
|
||||
addr32 leal PM_CALL_VAR(gdt)(%eax, %edi), %eax
|
||||
movl %eax, PM_CALL_VAR(gdt_base)(%bp)
|
||||
movw %cs, %ax
|
||||
movw $pm_cs, %bx
|
||||
movw $PM_CALL_VAR(pm_cs), %di
|
||||
call set_seg_base
|
||||
movw %ss, %ax
|
||||
movw $pm_ss, %bx
|
||||
movw $PM_CALL_VAR(pm_ss), %di
|
||||
call set_seg_base
|
||||
popw %bx
|
||||
popl %edi
|
||||
popl %eax
|
||||
|
||||
/* Switch CPU to protected mode and load up segment registers */
|
||||
pushl %eax
|
||||
cli
|
||||
lgdt gdt
|
||||
lgdt PM_CALL_VAR(gdt)(%bp)
|
||||
movl %cr0, %eax
|
||||
orb $CR0_PE, %al
|
||||
movl %eax, %cr0
|
||||
@@ -168,18 +344,19 @@ pm_call:
|
||||
popw %es
|
||||
popw %fs
|
||||
popw %gs
|
||||
lgdt pm_saved_gdt
|
||||
lgdt PM_CALL_VAR(pm_saved_gdt)(%bp)
|
||||
popfl
|
||||
|
||||
movw %bp, %sp
|
||||
popw %bp
|
||||
ret
|
||||
.size pm_call, . - pm_call
|
||||
|
||||
set_seg_base:
|
||||
rolw $4, %ax
|
||||
movw %ax, 2(%bx)
|
||||
andw $0xfff0, 2(%bx)
|
||||
movb %al, 4(%bx)
|
||||
andb $0x0f, 4(%bx)
|
||||
movw %ax, 2(%bp,%di)
|
||||
andw $0xfff0, 2(%bp,%di)
|
||||
movb %al, 4(%bp,%di)
|
||||
andb $0x0f, 4(%bp,%di)
|
||||
ret
|
||||
.size set_seg_base, . - set_seg_base
|
||||
|
||||
@@ -196,7 +373,7 @@ set_seg_base:
|
||||
* %ecx : length
|
||||
* Returns:
|
||||
* %ds:esi : next source address
|
||||
* %ds:esi : next destination address
|
||||
* %es:edi : next destination address
|
||||
* Corrupts:
|
||||
* None
|
||||
****************************************************************************
|
||||
@@ -211,24 +388,57 @@ copy_bytes:
|
||||
.size copy_bytes, . - copy_bytes
|
||||
|
||||
/****************************************************************************
|
||||
* install_block (real-mode or 16-bit protected-mode near call)
|
||||
* install_block (real-mode near call)
|
||||
*
|
||||
* Install block to specified address
|
||||
*
|
||||
* Parameters:
|
||||
* %ds:esi : source address (must be a multiple of 16)
|
||||
* %es:edi : destination address
|
||||
* %esi : source physical address (must be a multiple of 16)
|
||||
* %edi : destination physical address (must be a multiple of 16)
|
||||
* %ecx : length of (decompressed) data
|
||||
* %edx : total length of block (including any uninitialised data portion)
|
||||
* Returns:
|
||||
* %ds:esi : next source address (will be a multiple of 16)
|
||||
* %esi : next source physical address (will be a multiple of 16)
|
||||
* Corrupts:
|
||||
* %edi, %ecx, %edx
|
||||
* none
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
install_block:
|
||||
|
||||
#ifdef KEEP_IT_REAL
|
||||
|
||||
/* Preserve registers */
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushl %ecx
|
||||
pushl %edi
|
||||
|
||||
/* Convert %esi and %edi to segment registers */
|
||||
shrl $4, %esi
|
||||
movw %si, %ds
|
||||
xorw %si, %si
|
||||
shrl $4, %edi
|
||||
movw %di, %es
|
||||
xorw %di, %di
|
||||
|
||||
#else /* KEEP_IT_REAL */
|
||||
|
||||
/* Call self in protected mode */
|
||||
pushw %ax
|
||||
movw $1f, %ax
|
||||
call pm_call
|
||||
popw %ax
|
||||
ret
|
||||
1:
|
||||
/* Preserve registers */
|
||||
pushl %ecx
|
||||
pushl %edi
|
||||
|
||||
#endif /* KEEP_IT_REAL */
|
||||
|
||||
|
||||
#if COMPRESS
|
||||
/* Decompress source to destination */
|
||||
call decompress16
|
||||
@@ -249,6 +459,28 @@ install_block:
|
||||
addl $0xf, %esi
|
||||
andl $~0xf, %esi
|
||||
|
||||
|
||||
#ifdef KEEP_IT_REAL
|
||||
|
||||
/* Convert %ds:esi back to a physical address */
|
||||
movzwl %ds, %cx
|
||||
shll $4, %ecx
|
||||
addl %ecx, %esi
|
||||
|
||||
/* Restore registers */
|
||||
popl %edi
|
||||
popl %ecx
|
||||
popw %es
|
||||
popw %ds
|
||||
|
||||
#else /* KEEP_IT_REAL */
|
||||
|
||||
/* Restore registers */
|
||||
popl %edi
|
||||
popl %ecx
|
||||
|
||||
#endif
|
||||
|
||||
ret
|
||||
.size install_block, . - install_block
|
||||
|
||||
@@ -270,6 +502,7 @@ install_block:
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl alloc_basemem
|
||||
alloc_basemem:
|
||||
/* FBMS => %ax as segment address */
|
||||
movw $0x40, %ax
|
||||
@@ -295,98 +528,16 @@ alloc_basemem:
|
||||
ret
|
||||
.size alloc_basemem, . - alloc_basemem
|
||||
|
||||
/****************************************************************************
|
||||
* install_basemem (real-mode near call)
|
||||
*
|
||||
* Install source block into base memory
|
||||
*
|
||||
* Parameters:
|
||||
* %esi : source physical address (must be a multiple of 16)
|
||||
* %es : destination segment address
|
||||
* %cx : length of (decompressed) data
|
||||
* %dx : total length of block (including any uninitialised data portion)
|
||||
* Returns:
|
||||
* %esi : next source physical address (will be a multiple of 16)
|
||||
* Corrupts:
|
||||
* %edi, %ecx, %edx
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
install_basemem:
|
||||
/* Preserve registers */
|
||||
pushw %ds
|
||||
|
||||
/* Preserve original %esi */
|
||||
pushl %esi
|
||||
|
||||
/* Install to specified address */
|
||||
shrl $4, %esi
|
||||
movw %si, %ds
|
||||
xorw %si, %si
|
||||
xorl %edi, %edi
|
||||
movzwl %cx, %ecx
|
||||
movzwl %dx, %edx
|
||||
call install_block
|
||||
|
||||
/* Fix up %esi for return */
|
||||
popl %ecx
|
||||
addl %ecx, %esi
|
||||
|
||||
/* Restore registers */
|
||||
popw %ds
|
||||
ret
|
||||
.size install_basemem, . - install_basemem
|
||||
|
||||
/****************************************************************************
|
||||
* install_highmem (real-mode near call)
|
||||
*
|
||||
* Install source block into high memory
|
||||
*
|
||||
* Parameters:
|
||||
* %esi : source physical address (must be a multiple of 16)
|
||||
* %edi : destination physical address
|
||||
* %ecx : length of (decompressed) data
|
||||
* %edx : total length of block (including any uninitialised data portion)
|
||||
* Returns:
|
||||
* %esi : next source physical address (will be a multiple of 16)
|
||||
* Corrupts:
|
||||
* %edi, %ecx, %edx
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef KEEP_IT_REAL
|
||||
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
install_highmem:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
|
||||
/* Install to specified address */
|
||||
movw $install_block, %ax
|
||||
call pm_call
|
||||
|
||||
/* Restore registers */
|
||||
popw %ax
|
||||
ret
|
||||
.size install_highmem, . - install_highmem
|
||||
|
||||
#endif /* KEEP_IT_REAL */
|
||||
|
||||
/****************************************************************************
|
||||
* install (real-mode near call)
|
||||
* install_prealloc (real-mode near call)
|
||||
*
|
||||
* Install all text and data segments.
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : .text16 segment address (install_prealloc only)
|
||||
* %bx : .data16 segment address (install_prealloc only)
|
||||
* none
|
||||
* Returns:
|
||||
* %ax : .text16 segment address
|
||||
* %bx : .data16 segment address
|
||||
* %edi : .text physical address (if applicable)
|
||||
* %ax : .text16 segment address
|
||||
* %bx : .data16 segment address
|
||||
* Corrupts:
|
||||
* none
|
||||
****************************************************************************
|
||||
@@ -395,38 +546,69 @@ install_highmem:
|
||||
.code16
|
||||
.globl install
|
||||
install:
|
||||
/* Preserve registers */
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
/* Allocate space for .text16 and .data16 */
|
||||
call alloc_basemem
|
||||
/* Image source = %cs:0000 */
|
||||
xorl %esi, %esi
|
||||
/* Image destination = HIGHMEM_LOADPOINT */
|
||||
movl $HIGHMEM_LOADPOINT, %edi
|
||||
/* Install text and data segments */
|
||||
call install_prealloc
|
||||
/* Restore registers and return */
|
||||
popl %edi
|
||||
popl %esi
|
||||
ret
|
||||
.size install, . - install
|
||||
|
||||
/****************************************************************************
|
||||
* install_prealloc (real-mode near call)
|
||||
*
|
||||
* Install all text and data segments.
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : .text16 segment address
|
||||
* %bx : .data16 segment address
|
||||
* %esi : Image source physical address (or zero for %cs:0000)
|
||||
* %edi : Decompression temporary area physical address
|
||||
* Corrupts:
|
||||
* none
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".prefix.lib"
|
||||
.code16
|
||||
.globl install_prealloc
|
||||
install_prealloc:
|
||||
/* Save registers */
|
||||
pushal
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushl %esi
|
||||
pushl %ecx
|
||||
pushl %edx
|
||||
|
||||
/* Sanity: clear the direction flag asap */
|
||||
cld
|
||||
|
||||
/* Calculate physical address of payload (i.e. first source) */
|
||||
xorl %esi, %esi
|
||||
testl %esi, %esi
|
||||
jnz 1f
|
||||
movw %cs, %si
|
||||
shll $4, %esi
|
||||
addl $_payload_offset, %esi
|
||||
1: addl $_payload_offset, %esi
|
||||
|
||||
/* Install .text16 */
|
||||
movw %ax, %es
|
||||
movw $_text16_size, %cx
|
||||
movw %cx, %dx
|
||||
call install_basemem
|
||||
|
||||
/* Install .data16 */
|
||||
movw %bx, %es
|
||||
movw $_data16_progbits_size, %cx
|
||||
movw $_data16_size, %dx
|
||||
call install_basemem
|
||||
/* Install .text16 and .data16 */
|
||||
pushl %edi
|
||||
movzwl %ax, %edi
|
||||
shll $4, %edi
|
||||
movl $_text16_size, %ecx
|
||||
movl %ecx, %edx
|
||||
call install_block /* .text16 */
|
||||
movzwl %bx, %edi
|
||||
shll $4, %edi
|
||||
movl $_data16_progbits_size, %ecx
|
||||
movl $_data16_size, %edx
|
||||
call install_block /* .data16 */
|
||||
popl %edi
|
||||
|
||||
/* Set up %ds for access to .data16 */
|
||||
movw %bx, %ds
|
||||
@@ -440,12 +622,9 @@ install_prealloc:
|
||||
* prior to reading the E820 memory map and relocating
|
||||
* properly.
|
||||
*/
|
||||
movl $HIGHMEM_LOADPOINT, %edi
|
||||
movl $_textdata_progbits_size, %ecx
|
||||
movl $_textdata_size, %edx
|
||||
pushl %edi
|
||||
call install_highmem
|
||||
popl %edi
|
||||
call install_block
|
||||
|
||||
/* Initialise librm at current location */
|
||||
movw %ax, (init_librm_vector+2)
|
||||
@@ -473,11 +652,9 @@ install_prealloc:
|
||||
|
||||
#endif
|
||||
/* Restore registers */
|
||||
popl %edx
|
||||
popl %ecx
|
||||
popl %esi
|
||||
popw %es
|
||||
popw %ds
|
||||
popal
|
||||
ret
|
||||
.size install_prealloc, . - install_prealloc
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
Description:
|
||||
|
||||
This is just a little bit of code and data that can get prepended
|
||||
to an Etherboot ROM image in order to allow LILO to load the
|
||||
result as if it were a Linux kernel image.
|
||||
to a ROM image in order to allow bootloaders to load the result
|
||||
as if it were a Linux kernel image.
|
||||
|
||||
A real Linux kernel image consists of a one-sector boot loader
|
||||
(to load the image from a floppy disk), followed a few sectors
|
||||
@@ -21,19 +21,16 @@
|
||||
contains some other parameters that aren't interesting in this
|
||||
case.
|
||||
|
||||
When LILO loads the sectors that comprise a kernel image, it doesn't
|
||||
execute the code in the first sector (since that code would try to
|
||||
load the image from a floppy disk.) The code in the first sector
|
||||
below doesn't expect to get executed (and prints an error message
|
||||
if it ever -is- executed.) LILO's only interested in knowing the
|
||||
number of setup sectors advertised in the table (at offset 497 in
|
||||
the first sector.)
|
||||
When a bootloader loads the sectors that comprise a kernel image,
|
||||
it doesn't execute the code in the first sector (since that code
|
||||
would try to load the image from a floppy disk.) The code in the
|
||||
first sector below doesn't expect to get executed (and prints an
|
||||
error message if it ever -is- executed.)
|
||||
|
||||
Etherboot doesn't require much in the way of setup code.
|
||||
Historically, the Linux kernel required at least 4 sectors of
|
||||
setup code. Current versions of LILO look at the byte at
|
||||
offset 497 in the first sector to indicate how many sectors
|
||||
of setup code are contained in the image.
|
||||
We don't require much in the way of setup code. Historically, the
|
||||
Linux kernel required at least 4 sectors of setup code.
|
||||
Therefore, at least 4 sectors must be present even though we don't
|
||||
use them.
|
||||
|
||||
*/
|
||||
|
||||
@@ -85,15 +82,25 @@ why: .ascii "This image cannot be loaded from a floppy disk.\r\n"
|
||||
why_end:
|
||||
|
||||
|
||||
/*
|
||||
The following header is documented in the Linux source code at
|
||||
Documentation/i386/boot.txt
|
||||
*/
|
||||
.org 497
|
||||
setup_sects:
|
||||
.byte SETUPSECS
|
||||
root_flags:
|
||||
.word 0
|
||||
syssize:
|
||||
.word _load_size_pgh - PREFIXPGH
|
||||
swap_dev:
|
||||
.word 0
|
||||
.long _load_size_pgh - PREFIXPGH
|
||||
|
||||
.section ".zinfo.fixup", "a" /* Compressor fixup information */
|
||||
.ascii "SUBL"
|
||||
.long syssize
|
||||
.long 16
|
||||
.long 0
|
||||
.previous
|
||||
|
||||
ram_size:
|
||||
.word 0
|
||||
vid_mode:
|
||||
@@ -102,44 +109,92 @@ root_dev:
|
||||
.word 0
|
||||
boot_flag:
|
||||
.word 0xAA55
|
||||
|
||||
|
||||
.org 512
|
||||
|
||||
.section ".zinfo.fixup", "a" /* Compressor fixup information */
|
||||
.ascii "SUBW"
|
||||
.long syssize
|
||||
.long 16
|
||||
jump:
|
||||
/* Manually specify a two-byte jmp instruction here rather
|
||||
* than leaving it up to the assembler. */
|
||||
.byte 0xeb
|
||||
.byte setup_code - header
|
||||
header:
|
||||
.byte 'H', 'd', 'r', 'S'
|
||||
version:
|
||||
.word 0x0207 /* 2.07 */
|
||||
realmode_swtch:
|
||||
.long 0
|
||||
.previous
|
||||
|
||||
/*
|
||||
We're now at the beginning of the second sector of the image -
|
||||
where the setup code goes.
|
||||
start_sys:
|
||||
.word 0
|
||||
kernel_version:
|
||||
.word 0
|
||||
type_of_loader:
|
||||
.byte 0
|
||||
loadflags:
|
||||
.byte 0
|
||||
setup_move_size:
|
||||
.word 0
|
||||
code32_start:
|
||||
.long 0
|
||||
ramdisk_image:
|
||||
.long 0
|
||||
ramdisk_size:
|
||||
.long 0
|
||||
bootsect_kludge:
|
||||
.long 0
|
||||
heap_end_ptr:
|
||||
.word 0
|
||||
pad1:
|
||||
.word 0
|
||||
cmd_line_ptr:
|
||||
.long 0
|
||||
initrd_addr_max:
|
||||
/* We don't use an initrd but some bootloaders (e.g. SYSLINUX) have
|
||||
* been known to require this field. Set the value to 2 GB. This
|
||||
* value is also used by the Linux kernel. */
|
||||
.long 0x7fffffff
|
||||
kernel_alignment:
|
||||
.long 0
|
||||
relocatable_kernel:
|
||||
.byte 0
|
||||
pad2:
|
||||
.byte 0, 0, 0
|
||||
cmdline_size:
|
||||
.long 0
|
||||
hardware_subarch:
|
||||
.long 0
|
||||
hardware_subarch_data:
|
||||
.byte 0, 0, 0, 0, 0, 0, 0, 0
|
||||
|
||||
We don't need to do too much setup for Etherboot.
|
||||
/*
|
||||
We don't need to do too much setup.
|
||||
|
||||
This code gets loaded at SETUPSEG:0. It wants to start
|
||||
executing the Etherboot image that's loaded at SYSSEG:0 and
|
||||
executing the image that's loaded at SYSSEG:0 and
|
||||
whose entry point is SYSSEG:0.
|
||||
*/
|
||||
setup_code:
|
||||
/* Etherboot expects to be contiguous in memory once loaded.
|
||||
* LILO doesn't do this, but since we don't need any
|
||||
* information that's left in the prefix, it doesn't matter:
|
||||
* we just have to ensure that %cs:0000 is where the start of
|
||||
* the Etherboot image *would* be.
|
||||
/* We expect to be contiguous in memory once loaded. The Linux image
|
||||
* boot process requires that setup code is loaded separately from
|
||||
* "non-real code". Since we don't need any information that's left
|
||||
* in the prefix, it doesn't matter: we just have to ensure that
|
||||
* %cs:0000 is where the start of the image *would* be.
|
||||
*/
|
||||
ljmp $(SYSSEG-(PREFIXSIZE/16)), $run_etherboot
|
||||
ljmp $(SYSSEG-(PREFIXSIZE/16)), $run_gpxe
|
||||
|
||||
|
||||
.org PREFIXSIZE
|
||||
/*
|
||||
We're now at the beginning of the kernel proper.
|
||||
*/
|
||||
run_etherboot:
|
||||
run_gpxe:
|
||||
/* Set up stack just below 0x7c00 */
|
||||
xorw %ax, %ax
|
||||
movw %ax, %ss
|
||||
movw $0x7c00, %sp
|
||||
|
||||
call install
|
||||
|
||||
/* Set up real-mode stack */
|
||||
movw %bx, %ss
|
||||
movw $_estack16, %sp
|
||||
|
||||
/* Jump to .text16 segment */
|
||||
pushw %ax
|
||||
pushw $1f
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
cld
|
||||
/* Print welcome message */
|
||||
movw $10f, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
.section ".prefix.data"
|
||||
10: .asciz "PXE->EB:"
|
||||
@@ -48,24 +49,23 @@
|
||||
*/
|
||||
detect_pxenv:
|
||||
/* Signature check */
|
||||
les pxenv_segoff, %di
|
||||
cmpl $0x4e455850, %es:(%di) /* 'PXEN' signature */
|
||||
les pxenv_segoff, %bx
|
||||
cmpl $0x4e455850, %es:(%bx) /* 'PXEN' signature */
|
||||
jne no_pxenv
|
||||
cmpw $0x2b56, %es:4(%di) /* 'V+' signature */
|
||||
cmpw $0x2b56, %es:4(%bx) /* 'V+' signature */
|
||||
jne no_pxenv
|
||||
/* Record entry point and UNDI segments */
|
||||
pushl %es:0x0a(%di) /* Entry point */
|
||||
pushl %es:0x0a(%bx) /* Entry point */
|
||||
popl entry_segoff
|
||||
pushw %es:0x24(%di) /* UNDI code segment */
|
||||
pushw %es:0x26(%di) /* UNDI code size */
|
||||
pushw %es:0x24(%bx) /* UNDI code segment */
|
||||
pushw %es:0x26(%bx) /* UNDI code size */
|
||||
popl undi_code_segoff
|
||||
pushw %es:0x20(%di) /* UNDI data segment */
|
||||
pushw %es:0x22(%di) /* UNDI data size */
|
||||
pushw %es:0x20(%bx) /* UNDI data segment */
|
||||
pushw %es:0x22(%bx) /* UNDI data size */
|
||||
popl undi_data_segoff
|
||||
/* Print "PXENV+ at <address>" */
|
||||
movw $10f, %si
|
||||
call print_message
|
||||
movw %bx, %di
|
||||
call print_segoff
|
||||
movb $',', %al
|
||||
call print_character
|
||||
@@ -86,20 +86,20 @@ no_pxenv:
|
||||
*/
|
||||
detect_ppxe:
|
||||
/* Signature check */
|
||||
les ppxe_segoff, %di
|
||||
cmpl $0x45585021, %es:(%di) /* '!PXE' signature */
|
||||
les ppxe_segoff, %bx
|
||||
cmpl $0x45585021, %es:(%bx) /* '!PXE' signature */
|
||||
jne no_ppxe
|
||||
/* Record structure address, entry point, and UNDI segments */
|
||||
pushw %es
|
||||
popw ppxe_segment
|
||||
movw %di, ppxe_offset
|
||||
pushl %es:0x10(%di) /* Entry point */
|
||||
movw %bx, ppxe_offset
|
||||
pushl %es:0x10(%bx) /* Entry point */
|
||||
popl entry_segoff
|
||||
pushw %es:0x30(%di) /* UNDI code segment */
|
||||
pushw %es:0x36(%di) /* UNDI code size */
|
||||
pushw %es:0x30(%bx) /* UNDI code segment */
|
||||
pushw %es:0x36(%bx) /* UNDI code size */
|
||||
popl undi_code_segoff
|
||||
pushw %es:0x28(%di) /* UNDI data segment */
|
||||
pushw %es:0x2e(%di) /* UNDI data size */
|
||||
pushw %es:0x28(%bx) /* UNDI data segment */
|
||||
pushw %es:0x2e(%bx) /* UNDI data size */
|
||||
popl undi_data_segoff
|
||||
/* Print "!PXE at <address>" */
|
||||
movw $10f, %si
|
||||
@@ -167,7 +167,7 @@ print_structure_information:
|
||||
/* Print entry point */
|
||||
movw $10f, %si
|
||||
call print_message
|
||||
les entry_segoff, %di
|
||||
les entry_segoff, %bx
|
||||
call print_segoff
|
||||
.section ".prefix.data"
|
||||
10: .asciz " entry point at "
|
||||
@@ -175,7 +175,7 @@ print_structure_information:
|
||||
/* Print UNDI code segment */
|
||||
movw $10f, %si
|
||||
call print_message
|
||||
les undi_code_segoff, %di
|
||||
les undi_code_segoff, %bx
|
||||
call print_segoff
|
||||
.section ".prefix.data"
|
||||
10: .asciz "\n UNDI code segment "
|
||||
@@ -183,7 +183,7 @@ print_structure_information:
|
||||
/* Print UNDI data segment */
|
||||
movw $10f, %si
|
||||
call print_message
|
||||
les undi_data_segoff, %di
|
||||
les undi_data_segoff, %bx
|
||||
call print_segoff
|
||||
.section ".prefix.data"
|
||||
10: .asciz ", data segment "
|
||||
@@ -271,8 +271,8 @@ unload_base_code:
|
||||
call print_pxe_error
|
||||
jmp 99f
|
||||
1: /* Free base memory used by PXE base code */
|
||||
movw %fs:(0x13), %si
|
||||
movw undi_fbms_start, %di
|
||||
movw undi_fbms_start, %ax
|
||||
movw %fs:(0x13), %bx
|
||||
call free_basemem
|
||||
99:
|
||||
|
||||
@@ -289,8 +289,8 @@ unload_undi:
|
||||
call print_pxe_error
|
||||
jmp 99f
|
||||
1: /* Free base memory used by UNDI */
|
||||
movw undi_fbms_start, %si
|
||||
movw undi_fbms_end, %di
|
||||
movw undi_fbms_end, %ax
|
||||
movw undi_fbms_start, %bx
|
||||
call free_basemem
|
||||
/* Clear UNDI_FL_STARTED */
|
||||
andw $~UNDI_FL_STARTED, flags
|
||||
@@ -320,119 +320,14 @@ print_free_basemem:
|
||||
finished:
|
||||
jmp run_etherboot
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print character (with LF -> LF,CR translation)
|
||||
*
|
||||
* Parameters:
|
||||
* %al : character to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_character:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
pushw %bx
|
||||
pushw %bp
|
||||
/* Print character */
|
||||
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
|
||||
movb $0x0e, %ah /* write char, tty mode */
|
||||
cmpb $0x0a, %al /* '\n'? */
|
||||
jne 1f
|
||||
int $0x10
|
||||
movb $0x0d, %al
|
||||
1: int $0x10
|
||||
/* Restore registers and return */
|
||||
popw %bp
|
||||
popw %bx
|
||||
popw %ax
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print a NUL-terminated string
|
||||
*
|
||||
* Parameters:
|
||||
* %ds:%si : string to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_message:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
pushw %si
|
||||
/* Print string */
|
||||
1: lodsb
|
||||
testb %al, %al
|
||||
je 2f
|
||||
call print_character
|
||||
jmp 1b
|
||||
2: /* Restore registers and return */
|
||||
popw %si
|
||||
popw %ax
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print hex digit
|
||||
*
|
||||
* Parameters:
|
||||
* %al (low nibble) : digit to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_hex_nibble:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
/* Print digit (technique by Norbert Juffa <norbert.juffa@amd.com> */
|
||||
andb $0x0f, %al
|
||||
cmpb $10, %al
|
||||
sbbb $0x69, %al
|
||||
das
|
||||
call print_character
|
||||
/* Restore registers and return */
|
||||
popw %ax
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print hex byte
|
||||
*
|
||||
* Parameters:
|
||||
* %al : byte to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_hex_byte:
|
||||
rorb $4, %al
|
||||
call print_hex_nibble
|
||||
rorb $4, %al
|
||||
call print_hex_nibble
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print hex word
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : word to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_hex_word:
|
||||
xchgb %al, %ah
|
||||
call print_hex_byte
|
||||
xchgb %al, %ah
|
||||
call print_hex_byte
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print segment:offset address
|
||||
*
|
||||
* Parameters:
|
||||
* %es:%di : segment:offset address to print
|
||||
* %es:%bx : segment:offset address to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* Nothing
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_segoff:
|
||||
@@ -443,7 +338,7 @@ print_segoff:
|
||||
call print_hex_word
|
||||
movb $':', %al
|
||||
call print_character
|
||||
movw %di, %ax
|
||||
movw %bx, %ax
|
||||
call print_hex_word
|
||||
/* Restore registers and return */
|
||||
popw %ax
|
||||
@@ -454,8 +349,9 @@ print_segoff:
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : word to print
|
||||
* %ds:di : output buffer (or %di=0 to print to console)
|
||||
* Returns:
|
||||
* Nothing
|
||||
* %ds:di : next character in output buffer (if applicable)
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_word:
|
||||
@@ -484,44 +380,11 @@ print_word:
|
||||
popw %ax
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: print PCI bus:dev.fn
|
||||
*
|
||||
* Parameters:
|
||||
* %ax : PCI bus:dev.fn to print
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
*/
|
||||
print_pci_busdevfn:
|
||||
/* Preserve registers */
|
||||
pushw %ax
|
||||
/* Print bus */
|
||||
xchgb %al, %ah
|
||||
call print_hex_byte
|
||||
/* Print ":" */
|
||||
movb $':', %al
|
||||
call print_character
|
||||
/* Print device */
|
||||
movb %ah, %al
|
||||
shrb $3, %al
|
||||
call print_hex_byte
|
||||
/* Print "." */
|
||||
movb $'.', %al
|
||||
call print_character
|
||||
/* Print function */
|
||||
movb %ah, %al
|
||||
andb $0x07, %al
|
||||
call print_hex_nibble
|
||||
/* Restore registers and return */
|
||||
popw %ax
|
||||
ret
|
||||
|
||||
/*****************************************************************************
|
||||
* Subroutine: zero 1kB block of base memory
|
||||
*
|
||||
* Parameters:
|
||||
* %si : block to zero (in kB)
|
||||
* %bx : block to zero (in kB)
|
||||
* Returns:
|
||||
* Nothing
|
||||
*****************************************************************************
|
||||
@@ -533,7 +396,7 @@ zero_kb:
|
||||
pushw %di
|
||||
pushw %es
|
||||
/* Zero block */
|
||||
movw %si, %ax
|
||||
movw %bx, %ax
|
||||
shlw $6, %ax
|
||||
movw %ax, %es
|
||||
movw $0x400, %cx
|
||||
@@ -551,33 +414,31 @@ zero_kb:
|
||||
* Subroutine: free and zero base memory
|
||||
*
|
||||
* Parameters:
|
||||
* %si : Expected current free base memory counter (in kB)
|
||||
* %di : Desired new free base memory counter (in kB)
|
||||
* %ax : Desired new free base memory counter (in kB)
|
||||
* %bx : Expected current free base memory counter (in kB)
|
||||
* %fs : BIOS data segment (0x40)
|
||||
* Returns:
|
||||
* %ax : Actual new free base memory counter (in kB)
|
||||
* None
|
||||
*
|
||||
* The base memory from %si kB to %di kB is unconditionally zeroed.
|
||||
* The base memory from %bx kB to %ax kB is unconditionally zeroed.
|
||||
* It will be freed if and only if the expected current free base
|
||||
* memory counter (%si) matches the actual current free base memory
|
||||
* memory counter (%bx) matches the actual current free base memory
|
||||
* counter in 0x40:0x13; if this does not match then the memory will
|
||||
* be leaked.
|
||||
*****************************************************************************
|
||||
*/
|
||||
free_basemem:
|
||||
/* Zero base memory */
|
||||
pushw %si
|
||||
1: cmpw %si, %di
|
||||
pushw %bx
|
||||
1: cmpw %bx, %ax
|
||||
je 2f
|
||||
call zero_kb
|
||||
incw %si
|
||||
incw %bx
|
||||
jmp 1b
|
||||
2: popw %si
|
||||
2: popw %bx
|
||||
/* Free base memory */
|
||||
movw %fs:(0x13), %ax /* Current FBMS to %ax */
|
||||
cmpw %ax, %si /* Update FBMS only if "old" value */
|
||||
cmpw %fs:(0x13), %bx /* Update FBMS only if "old" value */
|
||||
jne 1f /* is correct */
|
||||
movw %di, %ax
|
||||
1: movw %ax, %fs:(0x13)
|
||||
ret
|
||||
|
||||
|
||||
@@ -6,6 +6,22 @@
|
||||
* table so using a noticeable amount of stack space is a no-no.
|
||||
*/
|
||||
|
||||
#include <config/general.h>
|
||||
|
||||
#define PNP_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
|
||||
#define PMM_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'M' << 16 ) + ( 'M' << 24 ) )
|
||||
#define PCI_SIGNATURE ( 'P' + ( 'C' << 8 ) + ( 'I' << 16 ) + ( ' ' << 24 ) )
|
||||
#define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
|
||||
#define PNP_GET_BBS_VERSION 0x60
|
||||
#define PMM_ALLOCATE 0x0000
|
||||
|
||||
/* ROM banner timeout. Based on the configurable BANNER_TIMEOUT in
|
||||
* config.h, but converted to a number of (18Hz) timer ticks, and
|
||||
* doubled to allow for BIOSes that switch video modes immediately
|
||||
* beforehand, so rendering the message almost invisible to the user.
|
||||
*/
|
||||
#define ROM_BANNER_TIMEOUT ( 2 * ( 18 * BANNER_TIMEOUT ) / 10 )
|
||||
|
||||
.text
|
||||
.code16
|
||||
.arch i386
|
||||
@@ -15,7 +31,9 @@
|
||||
romheader:
|
||||
.word 0xAA55 /* BIOS extension signature */
|
||||
romheader_size: .byte _load_size_sect /* Size in 512-byte blocks */
|
||||
jmp init_vector /* Initialisation vector */
|
||||
jmp init /* Initialisation vector */
|
||||
checksum:
|
||||
.byte 0
|
||||
.org 0x16
|
||||
.word undiheader
|
||||
.org 0x18
|
||||
@@ -33,25 +51,31 @@ romheader_size: .byte _load_size_sect /* Size in 512-byte blocks */
|
||||
|
||||
pciheader:
|
||||
.ascii "PCIR" /* Signature */
|
||||
.word pci_vendor_id /* Vendor ID */
|
||||
.word pci_device_id /* Device ID */
|
||||
.word 0x0000 /* pointer to vital product data */
|
||||
.word pci_vendor_id /* Vendor identification */
|
||||
.word pci_device_id /* Device identification */
|
||||
.word 0x0000 /* Device list pointer */
|
||||
.word pciheader_len /* PCI data structure length */
|
||||
.byte 0x00 /* PCI data structure revision */
|
||||
.byte 0x02 /* Device Base Type code */
|
||||
.byte 0x00 /* Device Sub-Type code */
|
||||
.byte 0x00 /* Device Interface Type code */
|
||||
pciheader_size: .word _load_size_sect /* Image length same as offset 02h */
|
||||
.word 0x0001 /* revision level of code/data */
|
||||
.byte 0x00 /* code type */
|
||||
.byte 0x80 /* Flags (last PCI data structure) */
|
||||
.word 0x0000 /* reserved */
|
||||
.byte 0x03 /* PCI data structure revision */
|
||||
.byte 0x02, 0x00, 0x00 /* Class code */
|
||||
pciheader_image_length:
|
||||
.word _load_size_sect /* Image length */
|
||||
.word 0x0001 /* Revision level */
|
||||
.byte 0x00 /* Code type */
|
||||
.byte 0x80 /* Last image indicator */
|
||||
pciheader_runtime_length:
|
||||
.word _load_size_sect /* Maximum run-time image length */
|
||||
.word 0x0000 /* Configuration utility code header */
|
||||
.word 0x0000 /* DMTF CLP entry point */
|
||||
.equ pciheader_len, . - pciheader
|
||||
.size pciheader, . - pciheader
|
||||
|
||||
.section ".zinfo.fixup", "a" /* Compressor fixup information */
|
||||
.ascii "SUBW"
|
||||
.long pciheader_size
|
||||
.long pciheader_image_length
|
||||
.long 512
|
||||
.long 0
|
||||
.ascii "SUBW"
|
||||
.long pciheader_runtime_length
|
||||
.long 512
|
||||
.long 0
|
||||
.previous
|
||||
@@ -69,22 +93,36 @@ pnpheader:
|
||||
.byte 0x02 /* Device base type code */
|
||||
.byte 0x00 /* Device sub-type code */
|
||||
.byte 0x00 /* Device interface type code */
|
||||
.byte 0x54 /* Device indicator */
|
||||
.byte 0xf4 /* Device indicator */
|
||||
.word 0x0000 /* Boot connection vector */
|
||||
.word 0x0000 /* Disconnect vector */
|
||||
.word exec_vector /* Boot execution vector */
|
||||
.word bev_entry /* Boot execution vector */
|
||||
.word 0x0000 /* Reserved */
|
||||
.word 0x0000 /* Static resource information vector*/
|
||||
.equ pnpheader_len, . - pnpheader
|
||||
.size pnpheader, . - pnpheader
|
||||
|
||||
/* Manufacturer string */
|
||||
mfgstr:
|
||||
.asciz "http://etherboot.org"
|
||||
.size mfgstr, . - mfgstr
|
||||
|
||||
/* Product string
|
||||
*
|
||||
* Defaults to "gPXE". If the ROM image is writable at initialisation
|
||||
* time, it will be filled in to include the PCI bus:dev.fn number of
|
||||
* the card as well.
|
||||
*/
|
||||
prodstr:
|
||||
.asciz "gPXE"
|
||||
.ascii "gPXE"
|
||||
prodstr_separator:
|
||||
.byte 0
|
||||
.ascii "(PCI "
|
||||
prodstr_pci_id:
|
||||
.asciz "xx:xx.x)" /* Filled in by init code */
|
||||
.size prodstr, . - prodstr
|
||||
|
||||
|
||||
.globl undiheader
|
||||
undiheader:
|
||||
.ascii "UNDI" /* Signature */
|
||||
.byte undiheader_len /* Length of structure */
|
||||
@@ -95,63 +133,363 @@ undiheader:
|
||||
.word _data16_size /* Stack segment size */
|
||||
.word _data16_size /* Data segment size */
|
||||
.word _text16_size /* Code segment size */
|
||||
.ascii "PCIR" /* Bus type */
|
||||
.equ undiheader_len, . - undiheader
|
||||
.size undiheader, . - undiheader
|
||||
|
||||
/* Initialisation vector
|
||||
/* Initialisation (called once during POST)
|
||||
*
|
||||
* Determine whether or not this is a PnP system via a signature
|
||||
* check. If it is PnP, return to the PnP BIOS indicating that we are
|
||||
* a boot-capable device; the BIOS will call our boot execution vector
|
||||
* if it wants to boot us. If it is not PnP, hook INT 19.
|
||||
*/
|
||||
init_vector:
|
||||
pushw %si
|
||||
cmpw $'$'+'P'*256, %es:0(%di)
|
||||
jne notpnp
|
||||
cmpw $'n'+'P'*256, %es:2(%di)
|
||||
jne notpnp
|
||||
ispnp:
|
||||
movw $ispnp_message, %si
|
||||
jmp 99f
|
||||
notpnp:
|
||||
init:
|
||||
/* Preserve registers, clear direction flag, set %ds=%cs */
|
||||
pushaw
|
||||
pushw %ds
|
||||
pushw $0
|
||||
popw %ds
|
||||
pushw %es
|
||||
pushw %fs
|
||||
pushw %gs
|
||||
cld
|
||||
pushw %cs
|
||||
pushw $exec_vector
|
||||
popl ( 0x19 * 4 )
|
||||
popw %ds
|
||||
movw $notpnp_message, %si
|
||||
99:
|
||||
|
||||
/* Shuffle some registers around. We need %di available for
|
||||
* the print_xxx functions, and in a register that's
|
||||
* addressable from %es, so shuffle as follows:
|
||||
*
|
||||
* %di (pointer to PnP structure) => %bx
|
||||
* %bx (runtime segment address, for PCI 3.0) => %gs
|
||||
*/
|
||||
movw %bx, %gs
|
||||
movw %di, %bx
|
||||
|
||||
/* Print message as early as possible */
|
||||
movw $init_message, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
movw $0x20, %ax
|
||||
popw %si
|
||||
lret
|
||||
.size init_vector, . - init_vector
|
||||
call print_pci_busdevfn
|
||||
|
||||
ispnp_message:
|
||||
.asciz "gPXE detected PnP BIOS\r\n"
|
||||
.size ispnp_message, . - ispnp_message
|
||||
notpnp_message:
|
||||
.asciz "gPXE detected non-PnP BIOS\r\n"
|
||||
.size notpnp_message, . - notpnp_message
|
||||
/* Fill in product name string, if possible */
|
||||
movw $prodstr_pci_id, %di
|
||||
call print_pci_busdevfn
|
||||
movb $' ', prodstr_separator
|
||||
|
||||
/* Boot execution vector
|
||||
*pciheader_size
|
||||
* Called by the PnP BIOS when it wants to boot us, or via the hooked
|
||||
* INT 19 if we detected a non-PnP BIOS.
|
||||
*/
|
||||
exec_vector:
|
||||
/* Obtain a reasonably-sized stack */
|
||||
/* Print segment address */
|
||||
movb $' ', %al
|
||||
xorw %di, %di
|
||||
call print_character
|
||||
movw %cs, %ax
|
||||
call print_hex_word
|
||||
|
||||
/* Check for PCI BIOS version */
|
||||
pushl %ebx
|
||||
pushl %edx
|
||||
pushl %edi
|
||||
stc
|
||||
movw $0xb101, %ax
|
||||
int $0x1a
|
||||
jc 1f
|
||||
cmpl $PCI_SIGNATURE, %edx
|
||||
jne 1f
|
||||
testb %ah, %ah
|
||||
jnz 1f
|
||||
movw $init_message_pci, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
movb %bh, %al
|
||||
call print_hex_nibble
|
||||
movb $'.', %al
|
||||
call print_character
|
||||
movb %bl, %al
|
||||
call print_hex_byte
|
||||
cmpb $3, %bh
|
||||
jae 2f
|
||||
1: /* PCI <3.0: set %gs (runtime segment) = %cs (init-time segment) */
|
||||
pushw %cs
|
||||
popw %gs
|
||||
2: popl %edi
|
||||
popl %edx
|
||||
popl %ebx
|
||||
|
||||
/* Check for PnP BIOS */
|
||||
testw $0x0f, %bx /* PnP signature must be aligned - bochs */
|
||||
jnz no_bbs /* uses unalignment to indicate 'fake' PnP. */
|
||||
cmpl $PNP_SIGNATURE, %es:0(%bx)
|
||||
jne no_bbs
|
||||
/* Is PnP: print PnP message */
|
||||
movw $init_message_pnp, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
/* Check for BBS */
|
||||
pushw %es:0x1b(%bx) /* Real-mode data segment */
|
||||
pushw %ds /* &(bbs_version) */
|
||||
pushw $bbs_version
|
||||
pushw $PNP_GET_BBS_VERSION
|
||||
lcall *%es:0xd(%bx)
|
||||
addw $8, %sp
|
||||
testw %ax, %ax
|
||||
je got_bbs
|
||||
no_bbs: /* Not BBS-compliant - must hook INT 19 */
|
||||
movw $init_message_int19, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
xorw %ax, %ax
|
||||
movw %ax, %ss
|
||||
movw $0x7c00, %sp
|
||||
movw %ax, %es
|
||||
pushl %es:( 0x19 * 4 )
|
||||
popl orig_int19
|
||||
pushw %gs /* %gs contains runtime %cs */
|
||||
pushw $int19_entry
|
||||
popl %es:( 0x19 * 4 )
|
||||
jmp bbs_done
|
||||
got_bbs: /* BBS compliant - no need to hook INT 19 */
|
||||
movw $init_message_bbs, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
bbs_done:
|
||||
|
||||
/* Check for PMM */
|
||||
movw $( 0xe000 - 1 ), %bx
|
||||
pmm_scan:
|
||||
incw %bx
|
||||
jz no_pmm
|
||||
movw %bx, %es
|
||||
cmpl $PMM_SIGNATURE, %es:0
|
||||
jne pmm_scan
|
||||
xorw %dx, %dx
|
||||
xorw %si, %si
|
||||
movzbw %es:5, %cx
|
||||
1: es lodsb
|
||||
addb %al, %dl
|
||||
loop 1b
|
||||
jnz pmm_scan
|
||||
/* PMM found: print PMM message */
|
||||
movw $init_message_pmm, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
/* Try to allocate 2MB block via PMM */
|
||||
pushw $0x0006 /* Aligned, extended memory */
|
||||
pushl $0xffffffff /* No handle */
|
||||
pushl $( 0x00200000 / 16 ) /* 2MB in paragraphs */
|
||||
pushw $PMM_ALLOCATE
|
||||
lcall *%es:7
|
||||
addw $12, %sp
|
||||
movw %dx, %ax
|
||||
xorw %di, %di
|
||||
call print_hex_word
|
||||
movw %dx, ( image_source + 2 )
|
||||
testw %dx, %dx /* %ax==0 even on success, since align=2MB */
|
||||
jz no_pmm
|
||||
/* PMM allocation succeeded: copy ROM to PMM block */
|
||||
pushal /* PMM presence implies 1kB stack */
|
||||
xorw %ax, %ax
|
||||
movw %ax, %es
|
||||
movl image_source, %edi
|
||||
xorl %esi, %esi
|
||||
movzbl romheader_size, %ecx
|
||||
shll $9, %ecx
|
||||
addr32 rep movsb /* PMM presence implies flat real mode */
|
||||
movl %edi, decompress_to
|
||||
/* Shrink ROM and update checksum */
|
||||
xorw %bx, %bx
|
||||
xorw %si, %si
|
||||
movw $_prefix_size_sect, %cx
|
||||
movb %cl, romheader_size
|
||||
shlw $9, %cx
|
||||
1: lodsb
|
||||
addb %al, %bl
|
||||
loop 1b
|
||||
subb %bl, checksum
|
||||
popal
|
||||
no_pmm:
|
||||
|
||||
/* Copy self to option ROM space. Required for PCI3.0, which
|
||||
* loads us to a temporary location in low memory. Will be a
|
||||
* no-op for lower PCI versions.
|
||||
*/
|
||||
movb $' ', %al
|
||||
xorw %di, %di
|
||||
call print_character
|
||||
movw %gs, %ax
|
||||
call print_hex_word
|
||||
movzbw romheader_size, %cx
|
||||
shlw $9, %cx
|
||||
movw %ax, %es
|
||||
xorw %si, %si
|
||||
xorw %di, %di
|
||||
cs rep movsb
|
||||
|
||||
/* Prompt for POST-time shell */
|
||||
movw $init_message_prompt, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
/* Wait for Ctrl-B */
|
||||
movw $0xff02, %bx
|
||||
call wait_for_key
|
||||
/* Clear prompt */
|
||||
pushf
|
||||
movw $clear_message, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
popf
|
||||
jnz 1f
|
||||
/* Ctrl-B was pressed: invoke gPXE. The keypress will be
|
||||
* picked up by the initial shell prompt, and we will drop
|
||||
* into a shell.
|
||||
*/
|
||||
pushw %cs
|
||||
call exec
|
||||
1:
|
||||
/* Restore registers */
|
||||
popw %gs
|
||||
popw %fs
|
||||
popw %es
|
||||
popw %ds
|
||||
popaw
|
||||
|
||||
/* Indicate boot capability to PnP BIOS, if present */
|
||||
movw $0x20, %ax
|
||||
lret
|
||||
.size init, . - init
|
||||
|
||||
init_message:
|
||||
.asciz "gPXE (http://etherboot.org) - "
|
||||
.size init_message, . - init_message
|
||||
init_message_pci:
|
||||
.asciz " PCI"
|
||||
.size init_message_pci, . - init_message_pci
|
||||
init_message_pnp:
|
||||
.asciz " PnP"
|
||||
.size init_message_pnp, . - init_message_pnp
|
||||
init_message_bbs:
|
||||
.asciz " BBS"
|
||||
.size init_message_bbs, . - init_message_bbs
|
||||
init_message_pmm:
|
||||
.asciz " PMM"
|
||||
.size init_message_pmm, . - init_message_pmm
|
||||
init_message_int19:
|
||||
.asciz " INT19"
|
||||
.size init_message_int19, . - init_message_int19
|
||||
init_message_prompt:
|
||||
.asciz "\nPress Ctrl-B to configure gPXE..."
|
||||
.size init_message_prompt, . - init_message_prompt
|
||||
clear_message:
|
||||
.asciz "\r \n\n"
|
||||
.size clear_message, . - clear_message
|
||||
|
||||
/* ROM image location
|
||||
*
|
||||
* May be either within option ROM space, or within PMM-allocated block.
|
||||
*/
|
||||
image_source:
|
||||
.long 0
|
||||
.size image_source, . - image_source
|
||||
|
||||
/* Temporary decompression area
|
||||
*
|
||||
* May be either at HIGHMEM_LOADPOINT, or within PMM-allocated block.
|
||||
*/
|
||||
decompress_to:
|
||||
.long HIGHMEM_LOADPOINT
|
||||
.size decompress_to, . - decompress_to
|
||||
|
||||
/* BBS version
|
||||
*
|
||||
* Filled in by BBS BIOS. We ignore the value.
|
||||
*/
|
||||
bbs_version:
|
||||
.word 0
|
||||
.size bbs_version, . - bbs_version
|
||||
|
||||
/* Boot Execution Vector entry point
|
||||
*
|
||||
* Called by the PnP BIOS when it wants to boot us.
|
||||
*/
|
||||
bev_entry:
|
||||
pushw %cs
|
||||
call exec
|
||||
lret
|
||||
.size bev_entry, . - bev_entry
|
||||
|
||||
/* INT19 entry point
|
||||
*
|
||||
* Called via the hooked INT 19 if we detected a non-PnP BIOS. We
|
||||
* attempt to return via the original INT 19 vector (if we were able
|
||||
* to store it).
|
||||
*/
|
||||
int19_entry:
|
||||
pushw %cs
|
||||
popw %ds
|
||||
/* Prompt user to press B to boot */
|
||||
movw $int19_message_prompt, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
movw $prodstr, %si
|
||||
call print_message
|
||||
movw $int19_message_dots, %si
|
||||
call print_message
|
||||
movw $0xdf42, %bx
|
||||
call wait_for_key
|
||||
pushf
|
||||
movw $clear_message, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
popf
|
||||
jnz 1f
|
||||
/* Leave keypress in buffer and start gPXE. The keypress will
|
||||
* cause the usual initial Ctrl-B prompt to be skipped.
|
||||
*/
|
||||
pushw %cs
|
||||
call exec
|
||||
1: /* Try to call original INT 19 vector */
|
||||
movl %cs:orig_int19, %eax
|
||||
testl %eax, %eax
|
||||
je 2f
|
||||
ljmp *%cs:orig_int19
|
||||
2: /* No chained vector: issue INT 18 as a last resort */
|
||||
int $0x18
|
||||
.size int19_entry, . - int19_entry
|
||||
orig_int19:
|
||||
.long 0
|
||||
.size orig_int19, . - orig_int19
|
||||
|
||||
int19_message_prompt:
|
||||
.asciz "Press B to boot from "
|
||||
.size int19_message_prompt, . - int19_message_prompt
|
||||
int19_message_dots:
|
||||
.asciz "..."
|
||||
.size int19_message_dots, . - int19_message_dots
|
||||
|
||||
/* Execute as a boot device
|
||||
*
|
||||
*/
|
||||
exec: /* Set %ds = %cs */
|
||||
pushw %cs
|
||||
popw %ds
|
||||
|
||||
/* Print message as soon as possible */
|
||||
movw $prodstr, %si
|
||||
xorw %di, %di
|
||||
call print_message
|
||||
movw $exec_message, %si
|
||||
call print_message
|
||||
|
||||
call install
|
||||
/* Store magic word on BIOS stack and remember BIOS %ss:sp */
|
||||
pushl $STACK_MAGIC
|
||||
movw %ss, %dx
|
||||
movw %sp, %bp
|
||||
|
||||
/* Obtain a reasonably-sized temporary stack */
|
||||
xorw %ax, %ax
|
||||
movw %ax, %ss
|
||||
movw $0x7c00, %sp
|
||||
|
||||
/* Install gPXE */
|
||||
movl image_source, %esi
|
||||
movl decompress_to, %edi
|
||||
call alloc_basemem
|
||||
call install_prealloc
|
||||
|
||||
/* Set up real-mode stack */
|
||||
movw %bx, %ss
|
||||
@@ -162,18 +500,28 @@ exec_vector:
|
||||
pushw $1f
|
||||
lret
|
||||
.section ".text16", "awx", @progbits
|
||||
1:
|
||||
1: /* Call main() */
|
||||
pushl $main
|
||||
pushw %cs
|
||||
call prot_call
|
||||
popl %eax /* discard */
|
||||
/* No need to clean up stack; we are about to reload %ss:sp */
|
||||
|
||||
/* Restore BIOS stack */
|
||||
movw %dx, %ss
|
||||
movw %bp, %sp
|
||||
|
||||
/* Boot next device */
|
||||
/* Check magic word on BIOS stack */
|
||||
popl %eax
|
||||
cmpl $STACK_MAGIC, %eax
|
||||
jne 1f
|
||||
/* BIOS stack OK: return to caller */
|
||||
lret
|
||||
1: /* BIOS stack corrupt: use INT 18 */
|
||||
int $0x18
|
||||
.previous
|
||||
|
||||
exec_message:
|
||||
.asciz "gPXE starting boot\r\n"
|
||||
.asciz " starting execution\n"
|
||||
.size exec_message, . - exec_message
|
||||
|
||||
/* UNDI loader
|
||||
@@ -182,17 +530,24 @@ exec_message:
|
||||
*/
|
||||
undiloader:
|
||||
/* Save registers */
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushw %bx
|
||||
/* ROM segment address to %ds */
|
||||
pushw %cs
|
||||
popw %ds
|
||||
/* UNDI loader parameter structure address into %es:%di */
|
||||
movw %sp, %bx
|
||||
movw %ss:12(%bx), %di
|
||||
movw %ss:14(%bx), %es
|
||||
movw %ss:18(%bx), %di
|
||||
movw %ss:20(%bx), %es
|
||||
/* Install to specified real-mode addresses */
|
||||
pushw %di
|
||||
movw %es:12(%di), %bx
|
||||
movw %es:14(%di), %ax
|
||||
movl image_source, %esi
|
||||
movl decompress_to, %edi
|
||||
call install_prealloc
|
||||
popw %di
|
||||
/* Call UNDI loader C code */
|
||||
@@ -207,25 +562,72 @@ undiloader:
|
||||
/* Restore registers and return */
|
||||
popw %bx
|
||||
popw %es
|
||||
popw %ds
|
||||
popl %edi
|
||||
popl %esi
|
||||
lret
|
||||
.size undiloader, . - undiloader
|
||||
|
||||
/* Utility function: print string
|
||||
|
||||
/* Wait for key press specified by %bl (masked by %bh)
|
||||
*
|
||||
* Used by init and INT19 code when prompting user. If the specified
|
||||
* key is pressed, it is left in the keyboard buffer.
|
||||
*
|
||||
* Returns with ZF set iff specified key is pressed.
|
||||
*/
|
||||
print_message:
|
||||
wait_for_key:
|
||||
/* Preserve registers */
|
||||
pushw %cx
|
||||
pushw %ax
|
||||
pushw %bx
|
||||
pushw %bp
|
||||
movw $0x0007, %bx
|
||||
1: cs lodsb
|
||||
testb %al, %al
|
||||
je 2f
|
||||
movb $0x0e, %ah /* write char, tty mode */
|
||||
int $0x10
|
||||
1: /* Empty the keyboard buffer before waiting for input */
|
||||
movb $0x01, %ah
|
||||
int $0x16
|
||||
jz 2f
|
||||
xorw %ax, %ax
|
||||
int $0x16
|
||||
jmp 1b
|
||||
2: popw %bp
|
||||
popw %bx
|
||||
2: /* Wait for a key press */
|
||||
movw $ROM_BANNER_TIMEOUT, %cx
|
||||
3: decw %cx
|
||||
js 99f /* Exit with ZF clear */
|
||||
/* Wait for timer tick to be updated */
|
||||
call wait_for_tick
|
||||
/* Check to see if a key was pressed */
|
||||
movb $0x01, %ah
|
||||
int $0x16
|
||||
jz 3b
|
||||
/* Check to see if key was the specified key */
|
||||
andb %bh, %al
|
||||
cmpb %al, %bl
|
||||
je 99f /* Exit with ZF set */
|
||||
/* Not the specified key: remove from buffer and stop waiting */
|
||||
pushfw
|
||||
xorw %ax, %ax
|
||||
int $0x16
|
||||
popfw /* Exit with ZF clear */
|
||||
99: /* Restore registers and return */
|
||||
popw %ax
|
||||
popw %cx
|
||||
ret
|
||||
.size print_message, . - print_message
|
||||
.size wait_for_key, . - wait_for_key
|
||||
|
||||
/* Wait for timer tick
|
||||
*
|
||||
* Used by wait_for_key
|
||||
*/
|
||||
wait_for_tick:
|
||||
pushl %eax
|
||||
pushw %fs
|
||||
movw $0x40, %ax
|
||||
movw %ax, %fs
|
||||
movl %fs:(0x6c), %eax
|
||||
1: pushf
|
||||
sti
|
||||
hlt
|
||||
popf
|
||||
cmpl %fs:(0x6c), %eax
|
||||
je 1b
|
||||
popw %fs
|
||||
popl %eax
|
||||
ret
|
||||
.size wait_for_tick, . - wait_for_tick
|
||||
|
||||
@@ -30,6 +30,16 @@ SECTIONS {
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Weak symbols that need zero values if not otherwise defined
|
||||
*/
|
||||
|
||||
. = 0;
|
||||
.weak : AT ( 0 ) {
|
||||
*(.weak)
|
||||
}
|
||||
_assert = ASSERT ( ( . == 0 ), ".weak is non-zero length" );
|
||||
|
||||
/*
|
||||
* The prefix
|
||||
*/
|
||||
@@ -56,10 +66,12 @@ SECTIONS {
|
||||
. = _text16_link_addr;
|
||||
_text16 = .;
|
||||
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
/* We need to allow code at the NULL address in .text16 */
|
||||
|
||||
.text16 : AT ( _text16_load_offset + __text16 ) {
|
||||
__text16 = .;
|
||||
*(.text16.null)
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
*(.text16)
|
||||
*(.text16.*)
|
||||
_etext16_progbits = .;
|
||||
@@ -257,6 +269,8 @@ SECTIONS {
|
||||
/*
|
||||
* Values calculated to save code from doing it
|
||||
*/
|
||||
_prefix_size_pgh = ( ( _prefix_size + 15 ) / 16 );
|
||||
_prefix_size_sect = ( ( _prefix_size + 511 ) / 512 );
|
||||
_text16_size_pgh = ( ( _text16_size + 15 ) / 16 );
|
||||
_data16_size_pgh = ( ( _data16_size + 15 ) / 16 );
|
||||
|
||||
|
||||
Regular → Executable
+34
-11
@@ -50,6 +50,7 @@
|
||||
.section ".data16"
|
||||
.align 16
|
||||
gdt:
|
||||
gdtr: /* The first GDT entry is unused, the GDTR can fit here. */
|
||||
gdt_limit: .word gdt_length - 1
|
||||
gdt_base: .long 0
|
||||
.word 0 /* padding */
|
||||
@@ -127,7 +128,7 @@ init_librm:
|
||||
addr32 leal (%eax, %edi), %ebx
|
||||
movl %ebx, _text16
|
||||
|
||||
/* Store rm_ds and _data16, set up real_ds segment and set GDT base */
|
||||
/* Store rm_ds and _data16, set up real_ds segment */
|
||||
xorl %eax, %eax
|
||||
movw %ds, %ax
|
||||
movw %ax, %cs:rm_ds
|
||||
@@ -136,9 +137,12 @@ init_librm:
|
||||
call set_seg_base
|
||||
addr32 leal (%eax, %edi), %ebx
|
||||
movl %ebx, _data16
|
||||
addl $gdt, %eax
|
||||
|
||||
/* Set GDT and IDT base */
|
||||
movl %eax, gdt_base
|
||||
|
||||
addl $gdt, gdt_base
|
||||
call idt_init
|
||||
|
||||
/* Restore registers */
|
||||
negl %edi
|
||||
popl %ebx
|
||||
@@ -147,14 +151,16 @@ init_librm:
|
||||
|
||||
.section ".text16"
|
||||
.code16
|
||||
.weak idt_init
|
||||
set_seg_base:
|
||||
1: movw %ax, 2(%bx)
|
||||
rorl $16, %eax
|
||||
movb %al, 4(%bx)
|
||||
movb %ah, 7(%bx)
|
||||
roll $16, %eax
|
||||
idt_init: /* Reuse the return opcode here */
|
||||
ret
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* real_to_prot (real-mode near call, 32-bit virtual return address)
|
||||
*
|
||||
@@ -197,7 +203,8 @@ real_to_prot:
|
||||
|
||||
/* Switch to protected mode */
|
||||
cli
|
||||
data32 lgdt gdt
|
||||
data32 lgdt gdtr
|
||||
data32 lidt idtr
|
||||
movl %cr0, %eax
|
||||
orb $CR0_PE, %al
|
||||
movl %eax, %cr0
|
||||
@@ -232,6 +239,14 @@ real_to_prot:
|
||||
/* Return to virtual address */
|
||||
ret
|
||||
|
||||
/* Default IDTR with no interrupts */
|
||||
.section ".data16"
|
||||
.weak idtr
|
||||
idtr:
|
||||
rm_idtr:
|
||||
.word 0xffff /* limit */
|
||||
.long 0 /* base */
|
||||
|
||||
/****************************************************************************
|
||||
* prot_to_real (protected-mode near call, 32-bit real-mode return address)
|
||||
*
|
||||
@@ -300,6 +315,9 @@ p2r_jump_target:
|
||||
movw %bp, %ss
|
||||
movl %edx, %esp
|
||||
|
||||
/* Reset IDTR to the real-mode defaults */
|
||||
lidt rm_idtr
|
||||
|
||||
/* Return to real-mode address */
|
||||
data32 ret
|
||||
|
||||
@@ -318,7 +336,7 @@ rm_cs: .word 0
|
||||
.globl rm_ds
|
||||
.section ".text16.data"
|
||||
rm_ds: .word 0
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* prot_call (real-mode far call, 16-bit real-mode far return address)
|
||||
*
|
||||
@@ -354,7 +372,8 @@ rm_ds: .word 0
|
||||
*/
|
||||
|
||||
#define PC_OFFSET_GDT ( 0 )
|
||||
#define PC_OFFSET_IX86 ( PC_OFFSET_GDT + 8 /* pad to 8 to keep alignment */ )
|
||||
#define PC_OFFSET_IDT ( PC_OFFSET_GDT + 8 /* pad to 8 to keep alignment */ )
|
||||
#define PC_OFFSET_IX86 ( PC_OFFSET_IDT + 8 /* pad to 8 to keep alignment */ )
|
||||
#define PC_OFFSET_RETADDR ( PC_OFFSET_IX86 + SIZEOF_I386_ALL_REGS )
|
||||
#define PC_OFFSET_FUNCTION ( PC_OFFSET_RETADDR + 4 )
|
||||
#define PC_OFFSET_END ( PC_OFFSET_FUNCTION + 4 )
|
||||
@@ -372,8 +391,9 @@ prot_call:
|
||||
pushw %ds
|
||||
pushw %ss
|
||||
pushw %cs
|
||||
subw $8, %sp
|
||||
subw $16, %sp
|
||||
movw %sp, %bp
|
||||
sidt 8(%bp)
|
||||
sgdt (%bp)
|
||||
|
||||
/* For sanity's sake, clear the direction flag as soon as possible */
|
||||
@@ -402,10 +422,11 @@ prot_call:
|
||||
.section ".text16"
|
||||
.code16
|
||||
1:
|
||||
/* Reload GDT, restore registers and flags and return */
|
||||
/* Reload GDT and IDT, restore registers and flags and return */
|
||||
movw %sp, %bp
|
||||
lgdt (%bp)
|
||||
addw $12, %sp /* also skip %cs and %ss */
|
||||
lidt 8(%bp)
|
||||
addw $20, %sp /* also skip %cs and %ss */
|
||||
popw %ds
|
||||
popw %es
|
||||
popw %fs
|
||||
@@ -495,7 +516,7 @@ real_call:
|
||||
*/
|
||||
.section ".data16"
|
||||
rc_function: .word 0, 0
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Stored real-mode and protected-mode stack pointers
|
||||
*
|
||||
@@ -531,7 +552,9 @@ rc_function: .word 0, 0
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".data"
|
||||
.globl rm_sp
|
||||
rm_sp: .word 0
|
||||
.globl rm_ss
|
||||
rm_ss: .word 0
|
||||
pm_esp: .long _estack
|
||||
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* librm: a library for interfacing to real-mode code
|
||||
*
|
||||
* Michael Brown <mbrown@fensystems.co.uk>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <librm.h>
|
||||
|
||||
/*
|
||||
* This file provides functions for managing librm.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate space on the real-mode stack and copy data there from a
|
||||
* user buffer
|
||||
*
|
||||
* @v data User buffer
|
||||
* @v size Size of stack data
|
||||
* @ret sp New value of real-mode stack pointer
|
||||
*/
|
||||
uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
|
||||
userptr_t rm_stack;
|
||||
rm_sp -= size;
|
||||
rm_stack = real_to_user ( rm_ss, rm_sp );
|
||||
memcpy_user ( rm_stack, 0, data, 0, size );
|
||||
return rm_sp;
|
||||
};
|
||||
|
||||
/**
|
||||
* Deallocate space on the real-mode stack, optionally copying back
|
||||
* data to a user buffer.
|
||||
*
|
||||
* @v data User buffer
|
||||
* @v size Size of stack data
|
||||
*/
|
||||
void remove_user_from_rm_stack ( userptr_t data, size_t size ) {
|
||||
if ( data ) {
|
||||
userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
|
||||
memcpy_user ( rm_stack, 0, data, 0, size );
|
||||
}
|
||||
rm_sp += size;
|
||||
};
|
||||
+30
-4
@@ -51,6 +51,18 @@
|
||||
|
||||
/* @END serial.h */
|
||||
|
||||
/* @BEGIN general.h
|
||||
*
|
||||
* Timer configuration
|
||||
*
|
||||
*/
|
||||
#define TIMER_BIOS /* 18Hz BIOS timer */
|
||||
#define TIMER_RDTSC /* CPU TimeStamp Counter timer */
|
||||
#define BANNER_TIMEOUT 20 /* Tenths of a second for which the shell
|
||||
banner should appear */
|
||||
|
||||
/* @END general.h */
|
||||
|
||||
/* @BEGIN isa.h
|
||||
*
|
||||
* ISA probe address configuration
|
||||
@@ -64,6 +76,16 @@
|
||||
|
||||
/* @END isa.h */
|
||||
|
||||
/* @BEGIN general.h
|
||||
*
|
||||
* Network protocols
|
||||
*
|
||||
*/
|
||||
|
||||
#define NET_PROTO_IPV4 /* IPv4 protocol */
|
||||
|
||||
/* @END general.h */
|
||||
|
||||
/* @BEGIN general.h
|
||||
*
|
||||
* Download protocols
|
||||
@@ -101,9 +123,7 @@
|
||||
*
|
||||
*/
|
||||
#undef IMAGE_NBI /* NBI image support */
|
||||
#undef IMAGE_ELF64 /* ELF64 image support */
|
||||
#undef IMAGE_ELF /* ELF image support */
|
||||
#undef IMAGE_COFF /* COFF image support */
|
||||
#define IMAGE_ELF /* ELF image support */
|
||||
#undef IMAGE_FREEBSD /* FreeBSD kernel image support */
|
||||
#define IMAGE_MULTIBOOT /* MultiBoot image support */
|
||||
#undef IMAGE_AOUT /* a.out image support */
|
||||
@@ -111,6 +131,7 @@
|
||||
#define IMAGE_PXE /* PXE image support */
|
||||
#define IMAGE_SCRIPT /* gPXE script image support */
|
||||
#define IMAGE_BZIMAGE /* Linux bzImage image support */
|
||||
#define IMAGE_COMBOOT /* SYSLINUX COMBOOT image support */
|
||||
|
||||
/* @END general.h */
|
||||
|
||||
@@ -126,6 +147,7 @@
|
||||
#define ROUTE_CMD /* Routing table management commands */
|
||||
#define IMAGE_CMD /* Image management commands */
|
||||
#define DHCP_CMD /* DHCP management commands */
|
||||
#define SANBOOT_CMD /* SAN boot commands */
|
||||
|
||||
/* @END general.h */
|
||||
|
||||
@@ -144,6 +166,10 @@
|
||||
#undef BUILD_ID /* Include a custom build ID string,
|
||||
* e.g "test-foo" */
|
||||
#undef NULL_TRAP /* Attempt to catch NULL function calls */
|
||||
#undef DUMP_GDBSYM /* Dump GDB symbol table information */
|
||||
#undef GDBSERIAL /* Remote GDB debugging over serial */
|
||||
#undef GDBUDP /* Remote GDB debugging over UDP
|
||||
* (both may be set) */
|
||||
|
||||
/* @END general.h */
|
||||
|
||||
/* @TRYSOURCE config-local.h */
|
||||
|
||||
+49
-18
@@ -53,29 +53,42 @@
|
||||
#ifdef CONSOLE_FIRMWARE
|
||||
REQUIRE_OBJECT ( bios_console );
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_SERIAL
|
||||
REQUIRE_OBJECT ( serial );
|
||||
REQUIRE_OBJECT ( serial_console );
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_DIRECT_VGA
|
||||
REQUIRE_OBJECT ( video_subr );
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_BTEXT
|
||||
REQUIRE_OBJECT ( btext );
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_PC_KBD
|
||||
REQUIRE_OBJECT ( pc_kbd );
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_SYSLOG
|
||||
REQUIRE_OBJECT ( syslog );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in all requested protocols
|
||||
* Drag in all requested timers
|
||||
*/
|
||||
#ifdef TIMER_BIOS
|
||||
REQUIRE_OBJECT ( timer_bios );
|
||||
#endif
|
||||
#ifdef TIMER_RDTSC
|
||||
REQUIRE_OBJECT ( timer_rdtsc );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in all requested network protocols
|
||||
*
|
||||
*/
|
||||
#ifdef NET_PROTO_IPV4
|
||||
REQUIRE_OBJECT ( ipv4 );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in all requested download protocols
|
||||
*
|
||||
*/
|
||||
#ifdef DOWNLOAD_PROTO_TFTP
|
||||
@@ -101,13 +114,12 @@ REQUIRE_OBJECT ( slam );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in any required resolvers
|
||||
* Drag in all requested resolvers
|
||||
*
|
||||
*/
|
||||
#ifdef DNS_RESOLVER
|
||||
REQUIRE_OBJECT ( dns );
|
||||
#endif
|
||||
|
||||
#ifdef NMB_RESOLVER
|
||||
REQUIRE_OBJECT ( nmb );
|
||||
#endif
|
||||
@@ -119,14 +131,8 @@ REQUIRE_OBJECT ( nmb );
|
||||
#ifdef IMAGE_NBI
|
||||
REQUIRE_OBJECT ( nbi );
|
||||
#endif
|
||||
#ifdef IMAGE_ELF64
|
||||
REQUIRE_OBJECT ( elf64 );
|
||||
#endif
|
||||
#ifdef IMAGE_ELF
|
||||
REQUIRE_OBJECT ( elf );
|
||||
#endif
|
||||
#ifdef IMAGE_ELF
|
||||
REQUIRE_OBJECT ( coff );
|
||||
REQUIRE_OBJECT ( elfboot );
|
||||
#endif
|
||||
#ifdef IMAGE_FREEBSD
|
||||
REQUIRE_OBJECT ( freebsd );
|
||||
@@ -152,6 +158,14 @@ REQUIRE_OBJECT ( bzimage );
|
||||
#ifdef IMAGE_ELTORITO
|
||||
REQUIRE_OBJECT ( eltorito );
|
||||
#endif
|
||||
#ifdef IMAGE_COMBOOT
|
||||
REQUIRE_OBJECT ( comboot );
|
||||
REQUIRE_OBJECT ( com32 );
|
||||
REQUIRE_OBJECT ( comboot_call );
|
||||
REQUIRE_OBJECT ( com32_call );
|
||||
REQUIRE_OBJECT ( com32_wrapper );
|
||||
REQUIRE_OBJECT ( comboot_resolv );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in all requested commands
|
||||
@@ -178,6 +192,9 @@ REQUIRE_OBJECT ( image_cmd );
|
||||
#ifdef DHCP_CMD
|
||||
REQUIRE_OBJECT ( dhcp_cmd );
|
||||
#endif
|
||||
#ifdef SANBOOT_CMD
|
||||
REQUIRE_OBJECT ( sanboot_cmd );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in miscellaneous objects
|
||||
@@ -186,6 +203,20 @@ REQUIRE_OBJECT ( dhcp_cmd );
|
||||
#ifdef NULL_TRAP
|
||||
REQUIRE_OBJECT ( nulltrap );
|
||||
#endif
|
||||
#ifdef DUMP_GDBSYM
|
||||
REQUIRE_OBJECT ( gdbsym );
|
||||
#ifdef GDBSERIAL
|
||||
REQUIRE_OBJECT ( gdbidt );
|
||||
REQUIRE_OBJECT ( gdbserial );
|
||||
REQUIRE_OBJECT ( gdbstub_cmd );
|
||||
#endif
|
||||
#ifdef GDBUDP
|
||||
REQUIRE_OBJECT ( gdbidt );
|
||||
REQUIRE_OBJECT ( gdbudp );
|
||||
REQUIRE_OBJECT ( gdbstub_cmd );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drag in objects that are always required, but not dragged in via
|
||||
* symbol dependencies.
|
||||
*
|
||||
*/
|
||||
REQUIRE_OBJECT ( device );
|
||||
|
||||
+8
-6
@@ -88,9 +88,15 @@ static struct console_driver * has_input ( void ) {
|
||||
*/
|
||||
int getchar ( void ) {
|
||||
struct console_driver *console;
|
||||
int character = 256;
|
||||
int character;
|
||||
|
||||
while ( 1 ) {
|
||||
console = has_input();
|
||||
if ( console && console->getchar ) {
|
||||
character = console->getchar ();
|
||||
break;
|
||||
}
|
||||
|
||||
while ( character == 256 ) {
|
||||
/* Doze for a while (until the next interrupt). This works
|
||||
* fine, because the keyboard is interrupt-driven, and the
|
||||
* timer interrupt (approx. every 50msec) takes care of the
|
||||
@@ -105,10 +111,6 @@ int getchar ( void ) {
|
||||
* input.
|
||||
*/
|
||||
step();
|
||||
|
||||
console = has_input();
|
||||
if ( console && console->getchar )
|
||||
character = console->getchar ();
|
||||
}
|
||||
|
||||
/* CR -> LF translation */
|
||||
|
||||
+13
-5
@@ -20,6 +20,7 @@
|
||||
#include <gpxe/list.h>
|
||||
#include <gpxe/tables.h>
|
||||
#include <gpxe/device.h>
|
||||
#include <gpxe/init.h>
|
||||
|
||||
/**
|
||||
* @file
|
||||
@@ -68,13 +69,11 @@ static void rootdev_remove ( struct root_device *rootdev ) {
|
||||
/**
|
||||
* Probe all devices
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* This initiates probing for all devices in the system. After this
|
||||
* call, the device hierarchy will be populated, and all hardware
|
||||
* should be ready to use.
|
||||
*/
|
||||
int probe_devices ( void ) {
|
||||
static void probe_devices ( void ) {
|
||||
struct root_device *rootdev;
|
||||
int rc;
|
||||
|
||||
@@ -84,19 +83,28 @@ int probe_devices ( void ) {
|
||||
if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
|
||||
list_del ( &rootdev->dev.siblings );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all devices
|
||||
*
|
||||
*/
|
||||
void remove_devices ( void ) {
|
||||
static void remove_devices ( int flags ) {
|
||||
struct root_device *rootdev;
|
||||
struct root_device *tmp;
|
||||
|
||||
if ( flags & SHUTDOWN_KEEP_DEVICES ) {
|
||||
DBG ( "Refusing to remove devices on shutdown\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
|
||||
rootdev_remove ( rootdev );
|
||||
list_del ( &rootdev->dev.siblings );
|
||||
}
|
||||
}
|
||||
|
||||
struct startup_fn startup_devices __startup_fn ( STARTUP_NORMAL ) = {
|
||||
.startup = probe_devices,
|
||||
.shutdown = remove_devices,
|
||||
};
|
||||
|
||||
+96
-2
@@ -26,6 +26,7 @@
|
||||
#include <assert.h>
|
||||
#include <gpxe/tables.h>
|
||||
#include <gpxe/command.h>
|
||||
#include <gpxe/settings.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
@@ -86,6 +87,76 @@ int execv ( const char *command, char * const argv[] ) {
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand variables within command line
|
||||
*
|
||||
* @v command Command line
|
||||
* @ret expcmd Expanded command line
|
||||
*
|
||||
* The expanded command line is allocated with malloc() and the caller
|
||||
* must eventually free() it.
|
||||
*/
|
||||
static char * expand_command ( const char *command ) {
|
||||
char *expcmd;
|
||||
char *start;
|
||||
char *end;
|
||||
char *head;
|
||||
char *name;
|
||||
char *tail;
|
||||
int setting_len;
|
||||
int new_len;
|
||||
char *tmp;
|
||||
|
||||
/* Obtain temporary modifiable copy of command line */
|
||||
expcmd = strdup ( command );
|
||||
if ( ! expcmd )
|
||||
return NULL;
|
||||
|
||||
/* Expand while expansions remain */
|
||||
while ( 1 ) {
|
||||
|
||||
head = expcmd;
|
||||
|
||||
/* Locate opener */
|
||||
start = strstr ( expcmd, "${" );
|
||||
if ( ! start )
|
||||
break;
|
||||
*start = '\0';
|
||||
name = ( start + 2 );
|
||||
|
||||
/* Locate closer */
|
||||
end = strstr ( name, "}" );
|
||||
if ( ! end )
|
||||
break;
|
||||
*end = '\0';
|
||||
tail = ( end + 1 );
|
||||
|
||||
/* Determine setting length */
|
||||
setting_len = fetchf_named_setting ( name, NULL, 0 );
|
||||
if ( setting_len < 0 )
|
||||
setting_len = 0; /* Treat error as empty setting */
|
||||
|
||||
/* Read setting into temporary buffer */
|
||||
{
|
||||
char setting_buf[ setting_len + 1 ];
|
||||
|
||||
setting_buf[0] = '\0';
|
||||
fetchf_named_setting ( name, setting_buf,
|
||||
sizeof ( setting_buf ) );
|
||||
|
||||
/* Construct expanded string and discard old string */
|
||||
tmp = expcmd;
|
||||
new_len = asprintf ( &expcmd, "%s%s%s",
|
||||
head, setting_buf, tail );
|
||||
free ( tmp );
|
||||
if ( new_len < 0 )
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return expcmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split command line into argv array
|
||||
*
|
||||
@@ -135,8 +206,8 @@ int system ( const char *command ) {
|
||||
int argc;
|
||||
int rc = 0;
|
||||
|
||||
/* Obtain temporary modifiable copy of command line */
|
||||
args = strdup ( command );
|
||||
/* Perform variable expansion */
|
||||
args = expand_command ( command );
|
||||
if ( ! args )
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -157,3 +228,26 @@ int system ( const char *command ) {
|
||||
free ( args );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "echo" command
|
||||
*
|
||||
* @v argc Argument count
|
||||
* @v argv Argument list
|
||||
* @ret rc Exit code
|
||||
*/
|
||||
static int echo_exec ( int argc, char **argv ) {
|
||||
int i;
|
||||
|
||||
for ( i = 1 ; i < argc ; i++ ) {
|
||||
printf ( "%s%s", ( ( i == 1 ) ? "" : " " ), argv[i] );
|
||||
}
|
||||
printf ( "\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** "echo" command */
|
||||
struct command echo_command __command = {
|
||||
.name = "echo",
|
||||
.exec = echo_exec,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
* 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
|
||||
@@ -16,22 +16,31 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Linux initrd image format
|
||||
*
|
||||
* This file does nothing except provide a way to mark images as being
|
||||
* initrds. The actual processing is done in the Linux kernel image
|
||||
* code; this file exists so that we can include the "initrd" command
|
||||
* without necessarily dragging in the Linux image format.
|
||||
*
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <gpxe/serial.h>
|
||||
#include <gpxe/gdbstub.h>
|
||||
#include <gpxe/gdbserial.h>
|
||||
|
||||
#include <gpxe/image.h>
|
||||
#include <gpxe/initrd.h>
|
||||
struct gdb_transport serial_gdb_transport __gdb_transport;
|
||||
|
||||
/** Linux initrd image type */
|
||||
struct image_type initrd_image_type __image_type ( PROBE_NORMAL ) = {
|
||||
.name = "initrd",
|
||||
static size_t gdbserial_recv ( char *buf, size_t len ) {
|
||||
assert ( len > 0 );
|
||||
buf [ 0 ] = serial_getc();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void gdbserial_send ( const char *buf, size_t len ) {
|
||||
while ( len-- > 0 ) {
|
||||
serial_putc ( *buf++ );
|
||||
}
|
||||
}
|
||||
|
||||
struct gdb_transport serial_gdb_transport __gdb_transport = {
|
||||
.name = "serial",
|
||||
.recv = gdbserial_recv,
|
||||
.send = gdbserial_send,
|
||||
};
|
||||
|
||||
struct gdb_transport *gdbserial_configure ( void ) {
|
||||
return &serial_gdb_transport;
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* GDB stub for remote debugging
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <byteswap.h>
|
||||
#include <gpxe/gdbstub.h>
|
||||
#include "gdbmach.h"
|
||||
|
||||
enum {
|
||||
POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
|
||||
SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */
|
||||
};
|
||||
|
||||
struct gdbstub {
|
||||
struct gdb_transport *trans;
|
||||
int exit_handler; /* leave interrupt handler */
|
||||
|
||||
int signo;
|
||||
gdbreg_t *regs;
|
||||
|
||||
void ( * parse ) ( struct gdbstub *stub, char ch );
|
||||
uint8_t cksum1;
|
||||
|
||||
/* Buffer for payload data when parsing a packet. Once the
|
||||
* packet has been received, this buffer is used to hold
|
||||
* the reply payload. */
|
||||
char buf [ SIZEOF_PAYLOAD + 4 ]; /* $...PAYLOAD...#XX */
|
||||
char *payload; /* start of payload */
|
||||
int len; /* length of payload */
|
||||
};
|
||||
|
||||
/* Transports */
|
||||
static struct gdb_transport gdb_transport_start[0] __table_start ( struct gdb_transport, gdb_transports );
|
||||
static struct gdb_transport gdb_transport_end[0] __table_end ( struct gdb_transport, gdb_transports );
|
||||
|
||||
/* Packet parser states */
|
||||
static void gdbstub_state_new ( struct gdbstub *stub, char ch );
|
||||
static void gdbstub_state_data ( struct gdbstub *stub, char ch );
|
||||
static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch );
|
||||
static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch );
|
||||
static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch );
|
||||
|
||||
static uint8_t gdbstub_from_hex_digit ( char ch ) {
|
||||
return ( isdigit ( ch ) ? ch - '0' : tolower ( ch ) - 'a' + 0xa ) & 0xf;
|
||||
}
|
||||
|
||||
static uint8_t gdbstub_to_hex_digit ( uint8_t b ) {
|
||||
b &= 0xf;
|
||||
return ( b < 0xa ? '0' : 'a' - 0xa ) + b;
|
||||
}
|
||||
|
||||
/*
|
||||
* To make reading/writing device memory atomic, we check for
|
||||
* 2- or 4-byte aligned operations and handle them specially.
|
||||
*/
|
||||
|
||||
static void gdbstub_from_hex_buf ( char *dst, char *src, int lenbytes ) {
|
||||
if ( lenbytes == 2 && ( ( unsigned long ) dst & 0x1 ) == 0 ) {
|
||||
uint16_t i = gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
|
||||
gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
|
||||
gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
|
||||
gdbstub_from_hex_digit ( src [ 1 ] );
|
||||
* ( uint16_t * ) dst = cpu_to_le16 ( i );
|
||||
} else if ( lenbytes == 4 && ( ( unsigned long ) dst & 0x3 ) == 0 ) {
|
||||
uint32_t i = gdbstub_from_hex_digit ( src [ 6 ] ) << 28 |
|
||||
gdbstub_from_hex_digit ( src [ 7 ] ) << 24 |
|
||||
gdbstub_from_hex_digit ( src [ 4 ] ) << 20 |
|
||||
gdbstub_from_hex_digit ( src [ 5 ] ) << 16 |
|
||||
gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
|
||||
gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
|
||||
gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
|
||||
gdbstub_from_hex_digit ( src [ 1 ] );
|
||||
* ( uint32_t * ) dst = cpu_to_le32 ( i );
|
||||
} else {
|
||||
while ( lenbytes-- > 0 ) {
|
||||
*dst++ = gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
|
||||
gdbstub_from_hex_digit ( src [ 1 ] );
|
||||
src += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_to_hex_buf ( char *dst, char *src, int lenbytes ) {
|
||||
if ( lenbytes == 2 && ( ( unsigned long ) src & 0x1 ) == 0 ) {
|
||||
uint16_t i = cpu_to_le16 ( * ( uint16_t * ) src );
|
||||
dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
|
||||
dst [ 1 ] = gdbstub_to_hex_digit ( i );
|
||||
dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
|
||||
dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
|
||||
} else if ( lenbytes == 4 && ( ( unsigned long ) src & 0x3 ) == 0 ) {
|
||||
uint32_t i = cpu_to_le32 ( * ( uint32_t * ) src );
|
||||
dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
|
||||
dst [ 1 ] = gdbstub_to_hex_digit ( i );
|
||||
dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
|
||||
dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
|
||||
dst [ 4 ] = gdbstub_to_hex_digit ( i >> 20 );
|
||||
dst [ 5 ] = gdbstub_to_hex_digit ( i >> 16);
|
||||
dst [ 6 ] = gdbstub_to_hex_digit ( i >> 28 );
|
||||
dst [ 7 ] = gdbstub_to_hex_digit ( i >> 24 );
|
||||
} else {
|
||||
while ( lenbytes-- > 0 ) {
|
||||
*dst++ = gdbstub_to_hex_digit ( *src >> 4 );
|
||||
*dst++ = gdbstub_to_hex_digit ( *src );
|
||||
src++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t gdbstub_cksum ( char *data, int len ) {
|
||||
uint8_t cksum = 0;
|
||||
while ( len-- > 0 ) {
|
||||
cksum += ( uint8_t ) *data++;
|
||||
}
|
||||
return cksum;
|
||||
}
|
||||
|
||||
static void gdbstub_tx_packet ( struct gdbstub *stub ) {
|
||||
uint8_t cksum = gdbstub_cksum ( stub->payload, stub->len );
|
||||
stub->buf [ 0 ] = '$';
|
||||
stub->buf [ stub->len + 1 ] = '#';
|
||||
stub->buf [ stub->len + 2 ] = gdbstub_to_hex_digit ( cksum >> 4 );
|
||||
stub->buf [ stub->len + 3 ] = gdbstub_to_hex_digit ( cksum );
|
||||
stub->trans->send ( stub->buf, stub->len + 4 );
|
||||
stub->parse = gdbstub_state_wait_ack;
|
||||
}
|
||||
|
||||
/* GDB commands */
|
||||
static void gdbstub_send_ok ( struct gdbstub *stub ) {
|
||||
stub->payload [ 0 ] = 'O';
|
||||
stub->payload [ 1 ] = 'K';
|
||||
stub->len = 2;
|
||||
gdbstub_tx_packet ( stub );
|
||||
}
|
||||
|
||||
static void gdbstub_send_num_packet ( struct gdbstub *stub, char reply, int num ) {
|
||||
stub->payload [ 0 ] = reply;
|
||||
stub->payload [ 1 ] = gdbstub_to_hex_digit ( ( char ) num >> 4 );
|
||||
stub->payload [ 2 ] = gdbstub_to_hex_digit ( ( char ) num );
|
||||
stub->len = 3;
|
||||
gdbstub_tx_packet ( stub );
|
||||
}
|
||||
|
||||
/* Format is arg1,arg2,...,argn:data where argn are hex integers and data is not an argument */
|
||||
static int gdbstub_get_packet_args ( struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx ) {
|
||||
int i;
|
||||
char ch = 0;
|
||||
int argc = 0;
|
||||
unsigned long val = 0;
|
||||
for ( i = 1; i < stub->len && argc < nargs; i++ ) {
|
||||
ch = stub->payload [ i ];
|
||||
if ( ch == ':' ) {
|
||||
break;
|
||||
} else if ( ch == ',' ) {
|
||||
args [ argc++ ] = val;
|
||||
val = 0;
|
||||
} else {
|
||||
val = ( val << 4 ) | gdbstub_from_hex_digit ( ch );
|
||||
}
|
||||
}
|
||||
if ( stop_idx ) {
|
||||
*stop_idx = i;
|
||||
}
|
||||
if ( argc < nargs ) {
|
||||
args [ argc++ ] = val;
|
||||
}
|
||||
return ( ( i == stub->len || ch == ':' ) && argc == nargs );
|
||||
}
|
||||
|
||||
static void gdbstub_send_errno ( struct gdbstub *stub, int errno ) {
|
||||
gdbstub_send_num_packet ( stub, 'E', errno );
|
||||
}
|
||||
|
||||
static void gdbstub_report_signal ( struct gdbstub *stub ) {
|
||||
gdbstub_send_num_packet ( stub, 'S', stub->signo );
|
||||
}
|
||||
|
||||
static void gdbstub_read_regs ( struct gdbstub *stub ) {
|
||||
gdbstub_to_hex_buf ( stub->payload, ( char * ) stub->regs, GDBMACH_SIZEOF_REGS );
|
||||
stub->len = GDBMACH_SIZEOF_REGS * 2;
|
||||
gdbstub_tx_packet ( stub );
|
||||
}
|
||||
|
||||
static void gdbstub_write_regs ( struct gdbstub *stub ) {
|
||||
if ( stub->len != 1 + GDBMACH_SIZEOF_REGS * 2 ) {
|
||||
gdbstub_send_errno ( stub, POSIX_EINVAL );
|
||||
return;
|
||||
}
|
||||
gdbstub_from_hex_buf ( ( char * ) stub->regs, &stub->payload [ 1 ], GDBMACH_SIZEOF_REGS );
|
||||
gdbstub_send_ok ( stub );
|
||||
}
|
||||
|
||||
static void gdbstub_read_mem ( struct gdbstub *stub ) {
|
||||
unsigned long args [ 2 ];
|
||||
if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
|
||||
gdbstub_send_errno ( stub, POSIX_EINVAL );
|
||||
return;
|
||||
}
|
||||
args [ 1 ] = ( args [ 1 ] < SIZEOF_PAYLOAD / 2 ) ? args [ 1 ] : SIZEOF_PAYLOAD / 2;
|
||||
gdbstub_to_hex_buf ( stub->payload, ( char * ) args [ 0 ], args [ 1 ] );
|
||||
stub->len = args [ 1 ] * 2;
|
||||
gdbstub_tx_packet ( stub );
|
||||
}
|
||||
|
||||
static void gdbstub_write_mem ( struct gdbstub *stub ) {
|
||||
unsigned long args [ 2 ];
|
||||
int colon;
|
||||
if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], &colon ) ||
|
||||
colon >= stub->len || stub->payload [ colon ] != ':' ||
|
||||
( stub->len - colon - 1 ) % 2 != 0 ) {
|
||||
gdbstub_send_errno ( stub, POSIX_EINVAL );
|
||||
return;
|
||||
}
|
||||
gdbstub_from_hex_buf ( ( char * ) args [ 0 ], &stub->payload [ colon + 1 ], ( stub->len - colon - 1 ) / 2 );
|
||||
gdbstub_send_ok ( stub );
|
||||
}
|
||||
|
||||
static void gdbstub_continue ( struct gdbstub *stub, int single_step ) {
|
||||
gdbreg_t pc;
|
||||
if ( stub->len > 1 && gdbstub_get_packet_args ( stub, &pc, 1, NULL ) ) {
|
||||
gdbmach_set_pc ( stub->regs, pc );
|
||||
}
|
||||
gdbmach_set_single_step ( stub->regs, single_step );
|
||||
stub->exit_handler = 1;
|
||||
/* Reply will be sent when we hit the next breakpoint or interrupt */
|
||||
}
|
||||
|
||||
static void gdbstub_breakpoint ( struct gdbstub *stub ) {
|
||||
unsigned long args [ 3 ];
|
||||
int enable = stub->payload [ 0 ] == 'Z' ? 1 : 0;
|
||||
if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
|
||||
gdbstub_send_errno ( stub, POSIX_EINVAL );
|
||||
return;
|
||||
}
|
||||
if ( gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ], args [ 2 ], enable ) ) {
|
||||
gdbstub_send_ok ( stub );
|
||||
} else {
|
||||
/* Not supported */
|
||||
stub->len = 0;
|
||||
gdbstub_tx_packet ( stub );
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_rx_packet ( struct gdbstub *stub ) {
|
||||
switch ( stub->payload [ 0 ] ) {
|
||||
case '?':
|
||||
gdbstub_report_signal ( stub );
|
||||
break;
|
||||
case 'g':
|
||||
gdbstub_read_regs ( stub );
|
||||
break;
|
||||
case 'G':
|
||||
gdbstub_write_regs ( stub );
|
||||
break;
|
||||
case 'm':
|
||||
gdbstub_read_mem ( stub );
|
||||
break;
|
||||
case 'M':
|
||||
gdbstub_write_mem ( stub );
|
||||
break;
|
||||
case 'c': /* Continue */
|
||||
case 'k': /* Kill */
|
||||
case 's': /* Step */
|
||||
case 'D': /* Detach */
|
||||
gdbstub_continue ( stub, stub->payload [ 0 ] == 's' );
|
||||
if ( stub->payload [ 0 ] == 'D' ) {
|
||||
gdbstub_send_ok ( stub );
|
||||
}
|
||||
break;
|
||||
case 'Z': /* Insert breakpoint */
|
||||
case 'z': /* Remove breakpoint */
|
||||
gdbstub_breakpoint ( stub );
|
||||
break;
|
||||
default:
|
||||
stub->len = 0;
|
||||
gdbstub_tx_packet ( stub );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* GDB packet parser */
|
||||
static void gdbstub_state_new ( struct gdbstub *stub, char ch ) {
|
||||
if ( ch == '$' ) {
|
||||
stub->len = 0;
|
||||
stub->parse = gdbstub_state_data;
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_state_data ( struct gdbstub *stub, char ch ) {
|
||||
if ( ch == '#' ) {
|
||||
stub->parse = gdbstub_state_cksum1;
|
||||
} else if ( ch == '$' ) {
|
||||
stub->len = 0; /* retry new packet */
|
||||
} else {
|
||||
/* If the length exceeds our buffer, let the checksum fail */
|
||||
if ( stub->len < SIZEOF_PAYLOAD ) {
|
||||
stub->payload [ stub->len++ ] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch ) {
|
||||
stub->cksum1 = gdbstub_from_hex_digit ( ch ) << 4;
|
||||
stub->parse = gdbstub_state_cksum2;
|
||||
}
|
||||
|
||||
static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch ) {
|
||||
uint8_t their_cksum;
|
||||
uint8_t our_cksum;
|
||||
|
||||
stub->parse = gdbstub_state_new;
|
||||
their_cksum = stub->cksum1 + gdbstub_from_hex_digit ( ch );
|
||||
our_cksum = gdbstub_cksum ( stub->payload, stub->len );
|
||||
if ( their_cksum == our_cksum ) {
|
||||
stub->trans->send ( "+", 1 );
|
||||
if ( stub->len > 0 ) {
|
||||
gdbstub_rx_packet ( stub );
|
||||
}
|
||||
} else {
|
||||
stub->trans->send ( "-", 1 );
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch ) {
|
||||
if ( ch == '+' ) {
|
||||
stub->parse = gdbstub_state_new;
|
||||
} else if ( ch == '-' ) {
|
||||
gdbstub_tx_packet ( stub ); /* retransmit */
|
||||
} else if ( ch == '$' ) {
|
||||
/* GDB is reconnecting, drop our packet and listen to GDB */
|
||||
stub->trans->send ( "-", 1 );
|
||||
stub->parse = gdbstub_state_new;
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbstub_parse ( struct gdbstub *stub, char ch ) {
|
||||
stub->parse ( stub, ch );
|
||||
}
|
||||
|
||||
static struct gdbstub stub = {
|
||||
.parse = gdbstub_state_new
|
||||
};
|
||||
|
||||
void gdbstub_handler ( int signo, gdbreg_t *regs ) {
|
||||
char packet [ SIZEOF_PAYLOAD + 4 ];
|
||||
size_t len, i;
|
||||
|
||||
/* A transport must be set up */
|
||||
if ( !stub.trans ) {
|
||||
return;
|
||||
}
|
||||
|
||||
stub.signo = signo;
|
||||
stub.regs = regs;
|
||||
stub.exit_handler = 0;
|
||||
gdbstub_report_signal ( &stub );
|
||||
while ( !stub.exit_handler && ( len = stub.trans->recv ( packet, sizeof ( packet ) ) ) > 0 ) {
|
||||
for ( i = 0; i < len; i++ ) {
|
||||
gdbstub_parse ( &stub, packet [ i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct gdb_transport *find_gdb_transport ( const char *name ) {
|
||||
struct gdb_transport *trans;
|
||||
for ( trans = gdb_transport_start; trans < gdb_transport_end; trans++ ) {
|
||||
if ( strcmp ( trans->name, name ) == 0 ) {
|
||||
return trans;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gdbstub_start ( struct gdb_transport *trans ) {
|
||||
stub.trans = trans;
|
||||
stub.payload = &stub.buf [ 1 ];
|
||||
gdbmach_breakpoint();
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <byteswap.h>
|
||||
#include <bios.h>
|
||||
#include <gpxe/iobuf.h>
|
||||
#include <gpxe/in.h>
|
||||
#include <gpxe/if_arp.h>
|
||||
#include <gpxe/if_ether.h>
|
||||
#include <gpxe/ip.h>
|
||||
#include <gpxe/udp.h>
|
||||
#include <gpxe/netdevice.h>
|
||||
#include <gpxe/gdbstub.h>
|
||||
#include <gpxe/gdbudp.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* GDB over UDP transport
|
||||
*
|
||||
*/
|
||||
|
||||
enum {
|
||||
DEFAULT_PORT = 43770, /* UDP listen port */
|
||||
};
|
||||
|
||||
struct gdb_transport udp_gdb_transport __gdb_transport;
|
||||
|
||||
static struct net_device *netdev;
|
||||
static uint8_t dest_eth[ETH_ALEN];
|
||||
static struct sockaddr_in dest_addr;
|
||||
static struct sockaddr_in source_addr;
|
||||
|
||||
static void gdbudp_ensure_netdev_open ( struct net_device *netdev ) {
|
||||
/* The device may have been closed between breakpoints */
|
||||
assert ( netdev );
|
||||
netdev_open ( netdev );
|
||||
|
||||
/* Strictly speaking, we may need to close the device when leaving the interrupt handler */
|
||||
}
|
||||
|
||||
static size_t gdbudp_recv ( char *buf, size_t len ) {
|
||||
struct io_buffer *iob;
|
||||
struct ethhdr *ethhdr;
|
||||
struct arphdr *arphdr;
|
||||
struct iphdr *iphdr;
|
||||
struct udp_header *udphdr;
|
||||
size_t payload_len;
|
||||
|
||||
gdbudp_ensure_netdev_open ( netdev );
|
||||
|
||||
for ( ; ; ) {
|
||||
netdev_poll ( netdev );
|
||||
while ( ( iob = netdev_rx_dequeue ( netdev ) ) != NULL ) {
|
||||
/* Ethernet header */
|
||||
if ( iob_len ( iob ) < sizeof ( *ethhdr ) ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
ethhdr = iob->data;
|
||||
iob_pull ( iob, sizeof ( *ethhdr ) );
|
||||
|
||||
/* Handle ARP requests so the client can find our MAC */
|
||||
if ( ethhdr->h_protocol == htons ( ETH_P_ARP ) ) {
|
||||
arphdr = iob->data;
|
||||
if ( iob_len ( iob ) < sizeof ( *arphdr ) + 2 * ( ETH_ALEN + sizeof ( struct in_addr ) ) ||
|
||||
arphdr->ar_hrd != htons ( ARPHRD_ETHER ) ||
|
||||
arphdr->ar_pro != htons ( ETH_P_IP ) ||
|
||||
arphdr->ar_hln != ETH_ALEN ||
|
||||
arphdr->ar_pln != sizeof ( struct in_addr ) ||
|
||||
arphdr->ar_op != htons ( ARPOP_REQUEST ) ||
|
||||
* ( uint32_t * ) arp_target_pa ( arphdr ) != source_addr.sin_addr.s_addr ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
|
||||
/* Generate an ARP reply */
|
||||
arphdr->ar_op = htons ( ARPOP_REPLY );
|
||||
memswap ( arp_sender_pa ( arphdr ), arp_target_pa ( arphdr ), sizeof ( struct in_addr ) );
|
||||
memcpy ( arp_target_ha ( arphdr ), arp_sender_ha ( arphdr ), ETH_ALEN );
|
||||
memcpy ( arp_sender_ha ( arphdr ), netdev->ll_addr, ETH_ALEN );
|
||||
|
||||
/* Fix up ethernet header */
|
||||
ethhdr = iob_push ( iob, sizeof ( *ethhdr ) );
|
||||
memcpy ( ethhdr->h_dest, ethhdr->h_source, ETH_ALEN );
|
||||
memcpy ( ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
|
||||
|
||||
netdev_tx ( netdev, iob );
|
||||
continue; /* no need to free iob */
|
||||
}
|
||||
|
||||
if ( ethhdr->h_protocol != htons ( ETH_P_IP ) ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
|
||||
/* IP header */
|
||||
if ( iob_len ( iob ) < sizeof ( *iphdr ) ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
iphdr = iob->data;
|
||||
iob_pull ( iob, sizeof ( *iphdr ) );
|
||||
if ( iphdr->protocol != IP_UDP || iphdr->dest.s_addr != source_addr.sin_addr.s_addr ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
|
||||
/* UDP header */
|
||||
if ( iob_len ( iob ) < sizeof ( *udphdr ) ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
udphdr = iob->data;
|
||||
if ( udphdr->dest != source_addr.sin_port ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
|
||||
/* Learn the remote connection details */
|
||||
memcpy ( dest_eth, ethhdr->h_source, ETH_ALEN );
|
||||
dest_addr.sin_addr.s_addr = iphdr->src.s_addr;
|
||||
dest_addr.sin_port = udphdr->src;
|
||||
|
||||
/* Payload */
|
||||
payload_len = ntohs ( udphdr->len );
|
||||
if ( payload_len < sizeof ( *udphdr ) || payload_len > iob_len ( iob ) ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
payload_len -= sizeof ( *udphdr );
|
||||
iob_pull ( iob, sizeof ( *udphdr ) );
|
||||
if ( payload_len > len ) {
|
||||
goto bad_packet;
|
||||
}
|
||||
memcpy ( buf, iob->data, payload_len );
|
||||
|
||||
free_iob ( iob );
|
||||
return payload_len;
|
||||
|
||||
bad_packet:
|
||||
free_iob ( iob );
|
||||
}
|
||||
cpu_nap();
|
||||
}
|
||||
}
|
||||
|
||||
static void gdbudp_send ( const char *buf, size_t len ) {
|
||||
struct io_buffer *iob;
|
||||
struct ethhdr *ethhdr;
|
||||
struct iphdr *iphdr;
|
||||
struct udp_header *udphdr;
|
||||
|
||||
/* Check that we are connected */
|
||||
if ( dest_addr.sin_port == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
gdbudp_ensure_netdev_open ( netdev );
|
||||
|
||||
iob = alloc_iob ( sizeof ( *ethhdr ) + sizeof ( *iphdr ) + sizeof ( *udphdr ) + len );
|
||||
if ( !iob ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Payload */
|
||||
iob_reserve ( iob, sizeof ( *ethhdr ) + sizeof ( *iphdr ) + sizeof ( *udphdr ) );
|
||||
memcpy ( iob_put ( iob, len ), buf, len );
|
||||
|
||||
/* UDP header */
|
||||
udphdr = iob_push ( iob, sizeof ( *udphdr ) );
|
||||
udphdr->src = source_addr.sin_port;
|
||||
udphdr->dest = dest_addr.sin_port;
|
||||
udphdr->len = htons ( iob_len ( iob ) );
|
||||
udphdr->chksum = 0; /* optional and we are not using it */
|
||||
|
||||
/* IP header */
|
||||
iphdr = iob_push ( iob, sizeof ( *iphdr ) );
|
||||
memset ( iphdr, 0, sizeof ( *iphdr ) );
|
||||
iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
|
||||
iphdr->service = IP_TOS;
|
||||
iphdr->len = htons ( iob_len ( iob ) );
|
||||
iphdr->ttl = IP_TTL;
|
||||
iphdr->protocol = IP_UDP;
|
||||
iphdr->dest.s_addr = dest_addr.sin_addr.s_addr;
|
||||
iphdr->src.s_addr = source_addr.sin_addr.s_addr;
|
||||
iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
|
||||
|
||||
/* Ethernet header */
|
||||
ethhdr = iob_push ( iob, sizeof ( *ethhdr ) );
|
||||
memcpy ( ethhdr->h_dest, dest_eth, ETH_ALEN );
|
||||
memcpy ( ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
|
||||
ethhdr->h_protocol = htons ( ETH_P_IP );
|
||||
|
||||
netdev_tx ( netdev, iob );
|
||||
}
|
||||
|
||||
struct gdb_transport *gdbudp_configure ( const char *name, struct sockaddr_in *addr ) {
|
||||
struct settings *settings;
|
||||
|
||||
/* Release old network device */
|
||||
netdev_put ( netdev );
|
||||
|
||||
netdev = find_netdev ( name );
|
||||
if ( !netdev ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Hold network device */
|
||||
netdev_get ( netdev );
|
||||
|
||||
/* Source UDP port */
|
||||
source_addr.sin_port = ( addr && addr->sin_port ) ? addr->sin_port : htons ( DEFAULT_PORT );
|
||||
|
||||
/* Source IP address */
|
||||
if ( addr && addr->sin_addr.s_addr ) {
|
||||
source_addr.sin_addr.s_addr = addr->sin_addr.s_addr;
|
||||
} else {
|
||||
settings = netdev_settings ( netdev );
|
||||
fetch_ipv4_setting ( settings, &ip_setting, &source_addr.sin_addr );
|
||||
if ( source_addr.sin_addr.s_addr == 0 ) {
|
||||
netdev_put ( netdev );
|
||||
netdev = NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return &udp_gdb_transport;
|
||||
}
|
||||
|
||||
static int gdbudp_init ( int argc, char **argv ) {
|
||||
if ( argc != 1 ) {
|
||||
printf ( "udp: missing <interface> argument\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( !gdbudp_configure ( argv[0], NULL ) ) {
|
||||
printf ( "%s: device does not exist or has no IP address\n", argv[0] );
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct gdb_transport udp_gdb_transport __gdb_transport = {
|
||||
.name = "udp",
|
||||
.init = gdbudp_init,
|
||||
.send = gdbudp_send,
|
||||
.recv = gdbudp_recv,
|
||||
};
|
||||
+1
-1
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
#include <console.h>
|
||||
#include <latch.h>
|
||||
#include <gpxe/process.h>
|
||||
#include <gpxe/keys.h>
|
||||
#include <gpxe/timer.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
|
||||
+118
-49
@@ -123,44 +123,37 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in an IP address within iBFT from DHCP option
|
||||
* Fill in an IP address within iBFT from configuration setting
|
||||
*
|
||||
* @v ipaddr IP address field
|
||||
* @v setting Configuration setting
|
||||
* @v tag DHCP option tag
|
||||
*/
|
||||
static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
|
||||
unsigned int tag ) {
|
||||
struct in_addr in;
|
||||
find_global_dhcp_ipv4_option ( tag, &in );
|
||||
struct setting *setting ) {
|
||||
struct in_addr in = { 0 };
|
||||
fetch_ipv4_setting ( NULL, setting, &in );
|
||||
ibft_set_ipaddr ( ipaddr, in );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in a string field within iBFT
|
||||
* Allocate a string within iBFT
|
||||
*
|
||||
* @v strings iBFT string block descriptor
|
||||
* @v string String field
|
||||
* @v data String to fill in
|
||||
* @v len Length of string to fill in
|
||||
* @v string String field to fill in
|
||||
* @v len Length of string to allocate (excluding NUL)
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ibft_set_string ( struct ibft_string_block *strings,
|
||||
struct ibft_string *string,
|
||||
const void *data, size_t len ) {
|
||||
static int ibft_alloc_string ( struct ibft_string_block *strings,
|
||||
struct ibft_string *string, size_t len ) {
|
||||
char *dest;
|
||||
char *end;
|
||||
unsigned int remaining;
|
||||
|
||||
dest = ( ( ( char * ) strings->table ) + strings->offset );
|
||||
end = ( ( ( char * ) strings->table ) + strings->table->acpi.length );
|
||||
remaining = ( end - dest );
|
||||
|
||||
remaining = ( strings->table->acpi.length - strings->offset );
|
||||
if ( len >= remaining )
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy ( dest, data, len );
|
||||
dest[len] = '\0';
|
||||
|
||||
string->offset = strings->offset;
|
||||
string->length = len;
|
||||
strings->offset += ( len + 1 );
|
||||
@@ -168,27 +161,57 @@ static int ibft_set_string ( struct ibft_string_block *strings,
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in a string field within iBFT from DHCP option
|
||||
* Fill in a string field within iBFT
|
||||
*
|
||||
* @v strings iBFT string block descriptor
|
||||
* @v string String field
|
||||
* @v tag DHCP option tag
|
||||
* @v data String to fill in, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ibft_set_string ( struct ibft_string_block *strings,
|
||||
struct ibft_string *string, const char *data ) {
|
||||
char *dest;
|
||||
int rc;
|
||||
|
||||
if ( ! data )
|
||||
return 0;
|
||||
|
||||
if ( ( rc = ibft_alloc_string ( strings, string,
|
||||
strlen ( data ) ) ) != 0 )
|
||||
return rc;
|
||||
dest = ( ( ( char * ) strings->table ) + string->offset );
|
||||
strcpy ( dest, data );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in a string field within iBFT from configuration setting
|
||||
*
|
||||
* @v strings iBFT string block descriptor
|
||||
* @v string String field
|
||||
* @v setting Configuration setting
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ibft_set_string_option ( struct ibft_string_block *strings,
|
||||
struct ibft_string *string,
|
||||
unsigned int tag ) {
|
||||
struct dhcp_option *option;
|
||||
struct setting *setting ) {
|
||||
int len;
|
||||
char *dest;
|
||||
int rc;
|
||||
|
||||
option = find_global_dhcp_option ( tag );
|
||||
if ( ! option ) {
|
||||
len = fetch_setting_len ( NULL, setting );
|
||||
if ( len < 0 ) {
|
||||
string->offset = 0;
|
||||
string->length = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ibft_set_string ( strings, string, option->data.string,
|
||||
option->len );
|
||||
if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
|
||||
return rc;
|
||||
dest = ( ( ( char * ) strings->table ) + string->offset );
|
||||
fetch_string_setting ( NULL, setting, dest, ( len + 1 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,20 +225,20 @@ static int ibft_set_string_option ( struct ibft_string_block *strings,
|
||||
static int ibft_fill_nic ( struct ibft_nic *nic,
|
||||
struct ibft_string_block *strings,
|
||||
struct net_device *netdev ) {
|
||||
struct in_addr netmask_addr;
|
||||
struct in_addr netmask_addr = { 0 };
|
||||
unsigned int netmask_count = 0;
|
||||
int rc;
|
||||
|
||||
/* Extract values from DHCP configuration */
|
||||
ibft_set_ipaddr_option ( &nic->ip_address, DHCP_EB_YIADDR );
|
||||
ibft_set_ipaddr_option ( &nic->gateway, DHCP_ROUTERS );
|
||||
ibft_set_ipaddr_option ( &nic->dns[0], DHCP_DNS_SERVERS );
|
||||
ibft_set_ipaddr_option ( &nic->ip_address, &ip_setting );
|
||||
ibft_set_ipaddr_option ( &nic->gateway, &gateway_setting );
|
||||
ibft_set_ipaddr_option ( &nic->dns[0], &dns_setting );
|
||||
if ( ( rc = ibft_set_string_option ( strings, &nic->hostname,
|
||||
DHCP_HOST_NAME ) ) != 0 )
|
||||
&hostname_setting ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Derive subnet mask prefix from subnet mask */
|
||||
find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask_addr );
|
||||
fetch_ipv4_setting ( NULL, &netmask_setting, &netmask_addr );
|
||||
while ( netmask_addr.s_addr ) {
|
||||
if ( netmask_addr.s_addr & 0x1 )
|
||||
netmask_count++;
|
||||
@@ -244,13 +267,68 @@ static int ibft_fill_initiator ( struct ibft_initiator *initiator,
|
||||
int rc;
|
||||
|
||||
if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
|
||||
initiator_iqn,
|
||||
strlen ( initiator_iqn ) ) ) != 0)
|
||||
initiator_iqn ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in Target CHAP portion of iBFT
|
||||
*
|
||||
* @v target Target portion of iBFT
|
||||
* @v strings iBFT string block descriptor
|
||||
* @v iscsi iSCSI session
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ibft_fill_target_chap ( struct ibft_target *target,
|
||||
struct ibft_string_block *strings,
|
||||
struct iscsi_session *iscsi ) {
|
||||
int rc;
|
||||
|
||||
if ( ! iscsi->initiator_username )
|
||||
return 0;
|
||||
assert ( iscsi->initiator_password );
|
||||
|
||||
target->chap_type = IBFT_CHAP_ONE_WAY;
|
||||
if ( ( rc = ibft_set_string ( strings, &target->chap_name,
|
||||
iscsi->initiator_username ) ) != 0 )
|
||||
return rc;
|
||||
if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
|
||||
iscsi->initiator_password ) ) != 0 )
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in Target Reverse CHAP portion of iBFT
|
||||
*
|
||||
* @v target Target portion of iBFT
|
||||
* @v strings iBFT string block descriptor
|
||||
* @v iscsi iSCSI session
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ibft_fill_target_reverse_chap ( struct ibft_target *target,
|
||||
struct ibft_string_block *strings,
|
||||
struct iscsi_session *iscsi ) {
|
||||
int rc;
|
||||
|
||||
if ( ! iscsi->target_username )
|
||||
return 0;
|
||||
assert ( iscsi->target_password );
|
||||
assert ( iscsi->initiator_username );
|
||||
assert ( iscsi->initiator_password );
|
||||
|
||||
target->chap_type = IBFT_CHAP_MUTUAL;
|
||||
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_name,
|
||||
iscsi->target_username ) ) != 0 )
|
||||
return rc;
|
||||
if ( ( rc = ibft_set_string ( strings, &target->reverse_chap_secret,
|
||||
iscsi->target_password ) ) != 0 )
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in Target portion of iBFT
|
||||
*
|
||||
@@ -270,22 +348,13 @@ static int ibft_fill_target ( struct ibft_target *target,
|
||||
ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
|
||||
target->socket = ntohs ( sin_target->sin_port );
|
||||
if ( ( rc = ibft_set_string ( strings, &target->target_name,
|
||||
iscsi->target_iqn,
|
||||
strlen ( iscsi->target_iqn ) ) ) != 0 )
|
||||
iscsi->target_iqn ) ) != 0 )
|
||||
return rc;
|
||||
if ( ( rc = ibft_fill_target_chap ( target, strings, iscsi ) ) != 0 )
|
||||
return rc;
|
||||
if ( ( rc = ibft_fill_target_reverse_chap ( target, strings,
|
||||
iscsi ) ) != 0 )
|
||||
return rc;
|
||||
if ( iscsi->username ) {
|
||||
if ( ( rc = ibft_set_string ( strings, &target->chap_name,
|
||||
iscsi->username,
|
||||
strlen ( iscsi->username ) ))!=0)
|
||||
return rc;
|
||||
}
|
||||
if ( iscsi->password ) {
|
||||
if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
|
||||
iscsi->password,
|
||||
strlen ( iscsi->password ) ))!=0)
|
||||
return rc;
|
||||
target->chap_type = IBFT_CHAP_ONE_WAY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-10
@@ -79,17 +79,14 @@ void startup ( void ) {
|
||||
startup_fn->startup();
|
||||
}
|
||||
|
||||
/* Probe for all devices. Treated separately because nothing
|
||||
* else will drag in device.o
|
||||
*/
|
||||
probe_devices();
|
||||
|
||||
started = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down gPXE
|
||||
*
|
||||
* @v flags Shutdown behaviour flags
|
||||
*
|
||||
* This function reverses the actions of startup(), and leaves gPXE in
|
||||
* a state ready to be removed from memory. You may call startup()
|
||||
* again after calling shutdown().
|
||||
@@ -97,20 +94,17 @@ void startup ( void ) {
|
||||
* Call this function only once, before either exiting main() or
|
||||
* starting up a non-returnable image.
|
||||
*/
|
||||
void shutdown ( void ) {
|
||||
void shutdown ( int flags ) {
|
||||
struct startup_fn *startup_fn;
|
||||
|
||||
if ( ! started )
|
||||
return;
|
||||
|
||||
/* Remove all devices */
|
||||
remove_devices();
|
||||
|
||||
/* Call registered shutdown functions (in reverse order) */
|
||||
for ( startup_fn = startup_fns_end - 1 ; startup_fn >= startup_fns ;
|
||||
startup_fn-- ) {
|
||||
if ( startup_fn->shutdown )
|
||||
startup_fn->shutdown();
|
||||
startup_fn->shutdown ( flags );
|
||||
}
|
||||
|
||||
started = 0;
|
||||
|
||||
+32
-4
@@ -14,27 +14,55 @@ Literature dealing with the network protocols:
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gpxe/init.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/shell.h>
|
||||
#include <gpxe/shell_banner.h>
|
||||
#include <usr/autoboot.h>
|
||||
|
||||
#define NORMAL "\033[0m"
|
||||
#define BOLD "\033[1m"
|
||||
#define CYAN "\033[36m"
|
||||
|
||||
static struct feature features[0] __table_start ( struct feature, features );
|
||||
static struct feature features_end[0] __table_end ( struct feature, features );
|
||||
|
||||
/**
|
||||
* Main entry point
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
__cdecl int main ( void ) {
|
||||
struct feature *feature;
|
||||
|
||||
initialise();
|
||||
startup();
|
||||
|
||||
if ( shell_banner() )
|
||||
/* Print welcome banner */
|
||||
printf ( NORMAL "\n\n\n" BOLD "gPXE " VERSION
|
||||
NORMAL " -- Open Source Boot Firmware -- "
|
||||
CYAN "http://etherboot.org" NORMAL "\n"
|
||||
"Features:" );
|
||||
for ( feature = features ; feature < features_end ; feature++ )
|
||||
printf ( " %s", feature->name );
|
||||
printf ( "\n" );
|
||||
|
||||
/* Prompt for shell */
|
||||
if ( shell_banner() ) {
|
||||
/* User wants shell; just give them a shell */
|
||||
shell();
|
||||
else
|
||||
} else {
|
||||
/* User doesn't want shell; try booting. If booting
|
||||
* fails, offer a second chance to enter the shell for
|
||||
* diagnostics.
|
||||
*/
|
||||
autoboot();
|
||||
|
||||
shutdown();
|
||||
if ( shell_banner() )
|
||||
shell();
|
||||
}
|
||||
|
||||
shutdown ( SHUTDOWN_EXIT | shutdown_exit_flags );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-14
@@ -4,20 +4,8 @@ MISC Support Routines
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <byteswap.h>
|
||||
#include <latch.h>
|
||||
#include <gpxe/in.h>
|
||||
|
||||
/**************************************************************************
|
||||
SLEEP
|
||||
**************************************************************************/
|
||||
unsigned int sleep(unsigned int secs)
|
||||
{
|
||||
unsigned long tmo;
|
||||
|
||||
for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; ) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#include <gpxe/timer.h>
|
||||
|
||||
/**************************************************************************
|
||||
INET_ATON - Convert an ascii x.x.x.x to binary form
|
||||
@@ -81,7 +69,7 @@ unsigned long strtoul ( const char *p, char **endp, int base ) {
|
||||
charval = ( charval - 'a' + 10 );
|
||||
} else if ( charval >= 'A' ) {
|
||||
charval = ( charval - 'A' + 10 );
|
||||
} else {
|
||||
} else if ( charval <= '9' ) {
|
||||
charval = ( charval - '0' );
|
||||
}
|
||||
if ( charval >= ( unsigned int ) base )
|
||||
|
||||
+10
-3
@@ -24,6 +24,7 @@
|
||||
#include <gpxe/keys.h>
|
||||
#include <gpxe/job.h>
|
||||
#include <gpxe/monojob.h>
|
||||
#include <gpxe/timer.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
@@ -62,9 +63,11 @@ struct job_interface monojob = {
|
||||
int monojob_wait ( const char *string ) {
|
||||
int key;
|
||||
int rc;
|
||||
tick_t last_progress_dot;
|
||||
|
||||
printf ( "%s... ", string );
|
||||
printf ( "%s.", string );
|
||||
monojob_rc = -EINPROGRESS;
|
||||
last_progress_dot = currticks();
|
||||
while ( monojob_rc == -EINPROGRESS ) {
|
||||
step();
|
||||
if ( iskey() ) {
|
||||
@@ -78,14 +81,18 @@ int monojob_wait ( const char *string ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ( currticks() - last_progress_dot ) > TICKS_PER_SEC ) {
|
||||
printf ( "." );
|
||||
last_progress_dot = currticks();
|
||||
}
|
||||
}
|
||||
rc = monojob_rc;
|
||||
|
||||
done:
|
||||
if ( rc ) {
|
||||
printf ( "%s\n", strerror ( rc ) );
|
||||
printf ( " %s\n", strerror ( rc ) );
|
||||
} else {
|
||||
printf ( "ok\n" );
|
||||
printf ( " ok\n" );
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user