[e1000e] Add e1000e driver
[gpxe.git] / contrib / errcode / errcode.py
blob7bc8d9e16f4e25ce1e56ed056154fb426301f13a
1 #!/usr/bin/env python
2 # Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 import sys
19 try:
20 import errcodedb
21 except ImportError:
22 sys.stderr.write('Please run this first: ./build_errcodedb.py >errcodedb.py\n')
23 sys.exit(1)
25 def to_pxenv_status(errno):
26 return errno & 0xff
28 def to_uniq(errno):
29 return (errno >> 8) & 0x1f
31 def to_errfile(errno):
32 return (errno >> 13) & 0x7ff
34 def to_posix_errno(errno):
35 return (errno >> 24) & 0x7f
37 def lookup_errno_component(defines, component):
38 if component in defines:
39 return defines[component]
40 else:
41 return '0x%x' % component
43 class Errcode(object):
44 def __init__(self, errno):
45 self.pxenv_status = to_pxenv_status(errno)
46 self.uniq = to_uniq(errno)
47 self.errfile = to_errfile(errno)
48 self.posix_errno = to_posix_errno(errno)
50 def rawstr(self):
51 return 'pxenv_status=0x%x uniq=%d errfile=0x%x posix_errno=0x%x' % (self.pxenv_status, self.uniq, self.errfile, self.posix_errno)
53 def prettystr(self):
54 return 'pxenv_status=%s uniq=%d errfile=%s posix_errno=%s' % (
55 lookup_errno_component(errcodedb.pxenv_status, self.pxenv_status),
56 self.uniq,
57 lookup_errno_component(errcodedb.errfile, self.errfile),
58 lookup_errno_component(errcodedb.posix_errno, self.posix_errno)
61 def __str__(self):
62 return self.prettystr()
64 def usage():
65 sys.stderr.write('usage: %s ERROR_NUMBER\n' % sys.argv[0])
66 sys.exit(1)
68 if __name__ == '__main__':
69 if len(sys.argv) != 2:
70 usage()
72 try:
73 errno = int(sys.argv[1], 16)
74 except ValueError:
75 usage()
77 print Errcode(errno)
78 sys.exit(0)