Index: kernel/tools/amd64/decpt.py
===================================================================
--- kernel/tools/amd64/decpt.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/amd64/decpt.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+"""
+Decode 64-bit address into components
+"""
+import sys
+
+def main():
+    if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
+        print "%s 0x..." % sys.argv[0]
+        sys.exit(1)
+    
+    address = int(sys.argv[1],16)
+    offset = address & 0xfff
+    ptl3 = (address >> 12) & 0x1ff
+    ptl2 = (address >> 21) & 0x1ff
+    ptl1 = (address >> 30) & 0x1ff
+    ptl0 = (address >> 39) & 0x1ff
+    print "Ptl0:   %3d" % ptl0
+    print "Ptl1:   %3d" % ptl1
+    print "Ptl2:   %3d" % ptl2
+    print "Ptl3:   %3d" % ptl3
+    print "Offset: 0x%x" % offset
+
+if __name__ == '__main__':
+    main()
Index: kernel/tools/amd64/gencontext.c
===================================================================
--- kernel/tools/amd64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/amd64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdint.h>
+
+typedef uint64_t uint64_t;
+typedef uint64_t ipl_t;
+typedef uint64_t uintptr_t;
+
+#define __amd64_TYPES_H__
+#include "../../arch/amd64/include/context.h"
+
+#define FILENAME "../../arch/amd64/include/context_offset.h"
+
+int main(void)
+{
+	FILE *f;
+	struct context ctx;
+	struct context *pctx = &ctx;
+
+	struct interrupt_context ictx;
+	struct interrupt_context *ipctx = &ictx;
+
+	f = fopen(FILENAME,"w");
+	if (!f) {
+		perror(FILENAME);
+		return 1;
+	}
+
+	fprintf(f, "/* This file is automatically generated by %s. */\n", __FILE__);	
+
+	fprintf(f,"#define OFFSET_SP  0x%x\n", ((int) &pctx->sp) - (int) pctx);
+	fprintf(f,"#define OFFSET_PC  0x%x\n", ((int) &pctx->pc) - (int) pctx);
+	fprintf(f,"#define OFFSET_RBX 0x%x\n", ((int) &pctx->rbx) - (int) pctx);
+	fprintf(f,"#define OFFSET_RBP 0x%x\n", ((int) &pctx->rbp) - (int) pctx);
+	fprintf(f,"#define OFFSET_R12 0x%x\n", ((int) &pctx->r12) - (int) pctx);
+	fprintf(f,"#define OFFSET_R13 0x%x\n", ((int) &pctx->r13) - (int) pctx);
+	fprintf(f,"#define OFFSET_R14 0x%x\n", ((int) &pctx->r14) - (int) pctx);
+	fprintf(f,"#define OFFSET_R15 0x%x\n", ((int) &pctx->r15) - (int) pctx);
+	fprintf(f,"#define OFFSET_IPL 0x%x\n", ((int) &pctx->ipl) - (int) pctx);
+
+	fclose(f);
+
+	return 0;
+}
Index: kernel/tools/config.py
===================================================================
--- kernel/tools/config.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/config.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,494 @@
+#!/usr/bin/env python
+"""
+Kernel configuration script
+"""
+import sys
+import os
+import re
+import commands
+
+INPUT = 'kernel.config'
+OUTPUT = 'Makefile.config'
+TMPOUTPUT = 'Makefile.config.tmp'
+
+class DefaultDialog:
+    "Wrapper dialog that tries to return default values"
+    def __init__(self, dlg):
+        self.dlg = dlg
+
+    def set_title(self,text):
+        self.dlg.set_title(text)
+        
+    def yesno(self, text, default=None):
+        if default is not None:
+            return default
+        return self.dlg.yesno(text, default)
+    def noyes(self, text, default=None):
+        if default is not None:
+            return default
+        return self.dlg.noyes(text, default)
+    
+    def choice(self, text, choices, defopt=None):
+        if defopt is not None:
+            return choices[defopt][0]
+        return self.dlg.choice(text, choices, defopt)
+
+class NoDialog:
+    def __init__(self):
+        self.printed = None
+        self.title = 'HelenOS Configuration'
+
+    def print_title(self):
+        if not self.printed:
+            sys.stdout.write("\n*** %s ***\n" % self.title)
+            self.printed = True
+
+    def set_title(self, text):
+        self.title = text
+        self.printed = False
+    
+    def noyes(self, text, default=None):
+        if not default:
+            default = 'n'
+        return self.yesno(text, default)
+    
+    def yesno(self, text, default=None):
+        self.print_title()
+        
+        if default != 'n':
+            default = 'y'
+        while 1:
+            sys.stdout.write("%s (y/n)[%s]: " % (text,default))
+            inp = sys.stdin.readline()
+            if not inp:
+                raise EOFError
+            inp = inp.strip().lower()
+            if not inp:
+                return default
+            if inp == 'y':
+                return 'y'
+            elif inp == 'n':
+                return 'n'
+
+    def _print_choice(self, text, choices, defopt):
+        sys.stdout.write('%s:\n' % text)
+        for i,(text,descr) in enumerate(choices):
+            sys.stdout.write('\t%2d. %s\n' % (i, descr))
+        if defopt is not None:
+            sys.stdout.write('Enter choice number[%d]: ' % defopt)
+        else:
+            sys.stdout.write('Enter choice number: ')
+
+    def menu(self, text, choices, button, defopt=None):
+        self.title = 'Main menu'
+        menu = []
+        for key, descr in choices:
+            txt = key + (45-len(key))*' ' + ': ' + descr
+            menu.append((key, txt))
+            
+        return self.choice(text, [button] + menu)
+        
+    def choice(self, text, choices, defopt=None):
+        self.print_title()
+        while 1:
+            self._print_choice(text, choices, defopt)
+            inp = sys.stdin.readline()
+            if not inp:
+                raise EOFError
+            if not inp.strip():
+                if defopt is not None:
+                    return choices[defopt][0]
+                continue
+            try:
+                number = int(inp.strip())
+            except ValueError:
+                continue
+            if number < 0 or number >= len(choices):
+                continue
+            return choices[number][0]
+
+
+def eof_checker(fnc):
+    def wrapper(self, *args, **kw):
+        try:
+            return fnc(self, *args, **kw)
+        except EOFError:
+            return getattr(self.bckdialog,fnc.func_name)(*args, **kw)
+    return wrapper
+
+class Dialog(NoDialog):
+    def __init__(self):
+        NoDialog.__init__(self)
+        self.dlgcmd = os.environ.get('DIALOG','dialog')
+        self.title = ''
+        self.backtitle = 'HelenOS Kernel Configuration'
+        
+        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
+            raise NotImplementedError
+        
+        self.bckdialog = NoDialog()
+
+    def set_title(self,text):
+        self.title = text
+        self.bckdialog.set_title(text)
+        
+    def calldlg(self,*args,**kw):
+        "Wrapper for calling 'dialog' program"
+        indesc, outdesc = os.pipe()
+        pid = os.fork()
+        if not pid:
+            os.close(2)
+            os.dup(outdesc)
+            os.close(indesc)
+            
+            dlgargs = [self.dlgcmd,'--title',self.title,
+                       '--backtitle', self.backtitle]
+            for key,val in kw.items():
+                dlgargs.append('--'+key)
+                dlgargs.append(val)
+            dlgargs += args            
+            os.execlp(self.dlgcmd,*dlgargs)
+
+        os.close(outdesc)
+        
+        try:
+            errout = os.fdopen(indesc,'r')
+            data = errout.read()
+            errout.close()
+            pid,status = os.wait()
+        except:
+            os.system('reset') # Reset terminal
+            raise
+        
+        if not os.WIFEXITED(status):
+            os.system('reset') # Reset terminal
+            raise EOFError
+        
+        status = os.WEXITSTATUS(status)
+        if status == 255:
+            raise EOFError
+        return status,data
+        
+    def yesno(self, text, default=None):
+        if text[-1] not in ('?',':'):
+            text = text + ':'
+        width = '50'
+        height = '5'
+        if len(text) < 48:
+            text = ' '*int(((48-len(text))/2)) + text
+        else:
+            width = '0'
+            height = '0'
+        if default == 'n':
+            res,data = self.calldlg('--defaultno','--yesno',text,height,width)
+        else:
+            res,data = self.calldlg('--yesno',text,height,width)
+
+        if res == 0:
+            return 'y'
+        return 'n'
+    yesno = eof_checker(yesno)
+
+    def menu(self, text, choices, button, defopt=None):
+        self.title = 'Main menu'
+        text = text + ':'
+        width = '70'
+        height = str(8 + len(choices))
+        args = []
+        for key,val in choices:
+            args.append(key)
+            args.append(val)
+
+        kw = {}
+        if defopt:
+            kw['default-item'] = choices[defopt][0] 
+        res,data = self.calldlg('--ok-label','Change',
+                                '--extra-label',button[1],
+                                '--extra-button',
+                                '--menu',text,height,width,
+                                str(len(choices)),*args,**kw)
+        if res == 3:
+            return button[0]
+        if res == 1: # Cancel
+            sys.exit(1)
+        elif res:
+            print data
+            raise EOFError
+        return data
+    menu = eof_checker(menu)
+    
+    def choice(self, text, choices, defopt=None):
+        text = text + ':'
+        width = '50'
+        height = str(8 + len(choices))
+        args = []
+        for key,val in choices:
+            args.append(key)
+            args.append(val)
+
+        kw = {}
+        if defopt:
+            kw['default-item'] = choices[defopt][0] 
+        res,data = self.calldlg('--nocancel','--menu',text,height,width,
+                                str(len(choices)),*args, **kw)
+        if res:
+            print data
+            raise EOFError
+        return data
+    choice = eof_checker(choice)
+    
+def read_defaults(fname,defaults):
+    "Read saved values from last configuration run"
+    f = file(fname,'r')
+    for line in f:
+        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
+        if res:
+            defaults[res.group(1)] = res.group(2)
+    f.close()
+
+def check_condition(text, defaults, asked_names):
+    seen_vars = [ x[0] for x in asked_names ]
+    ctype = 'cnf'
+    if ')|' in text or '|(' in text:
+        ctype = 'dnf'
+    
+    if ctype == 'cnf':
+        conds = text.split('&')
+    else:
+        conds = text.split('|')
+
+    for cond in conds:
+        if cond.startswith('(') and cond.endswith(')'):
+            cond = cond[1:-1]
+            
+        inside = check_inside(cond, defaults, ctype, seen_vars)
+        
+        if ctype == 'cnf' and not inside:
+            return False
+        if ctype == 'dnf' and inside:
+            return True
+
+    if ctype == 'cnf':
+        return True
+    return False
+
+def check_inside(text, defaults, ctype, seen_vars):
+    """
+    Check that the condition specified on input line is True
+
+    only CNF is supported
+    """
+    if ctype == 'cnf':
+        conds = text.split('|')
+    else:
+        conds = text.split('&')
+    for cond in conds:
+        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
+        if not res:
+            raise RuntimeError("Invalid condition: %s" % cond)
+        condname = res.group(1)
+        oper = res.group(2)
+        condval = res.group(3)
+        if condname not in seen_vars:
+            varval = ''
+##             raise RuntimeError("Variable %s not defined before being asked." %\
+##                                condname)
+        elif not defaults.has_key(condname):
+            raise RuntimeError("Condition var %s does not exist: %s" % \
+                               (condname,text))
+        else:
+            varval = defaults[condname]
+        if ctype == 'cnf':
+            if oper == '=' and  condval == varval:
+                return True
+            if oper == '!=' and condval != varval:
+                return True
+        else:
+            if oper== '=' and condval != varval:
+                return False
+            if oper== '!=' and condval == varval:
+                return False
+    if ctype=='cnf':
+        return False
+    return True
+
+def parse_config(input, output, dlg, defaults={}, askonly=None):
+    "Parse configuration file and create Makefile.config on the fly"
+    def ask_the_question(dialog):
+        "Ask question based on the type of variables to ask"
+        # This is quite a hack, this thingy is written just to
+        # have access to local variables..
+        if vartype == 'y/n':
+            return dialog.yesno(comment, default)
+        elif vartype == 'n/y':
+            return dialog.noyes(comment, default)
+        elif vartype == 'choice':
+            defopt = None
+            if default is not None:
+                for i,(key,val) in enumerate(choices):
+                    if key == default:
+                        defopt = i
+                        break
+            return dialog.choice(comment, choices, defopt)
+        else:
+            raise RuntimeError("Bad method: %s" % vartype)
+
+    
+    f = file(input, 'r')
+    outf = file(output, 'w')
+
+    outf.write('#########################################\n')
+    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
+    outf.write('#########################################\n\n')
+
+    asked_names = []
+
+    comment = ''
+    default = None
+    choices = []
+    for line in f:
+        if line.startswith('%'):
+            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
+            if not res:
+                raise RuntimeError('Invalid command: %s' % line)
+            if res.group(1):
+                if not check_condition(res.group(1), defaults,
+                                       asked_names):
+                    continue
+            args = res.group(2).strip().split(' ')
+            cmd = args[0].lower()
+            args = args[1:]
+            if cmd == 'saveas':
+                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
+            elif cmd == 'shellcmd':
+                varname = args[0]
+                args = args[1:]
+                for i,arg in enumerate(args):
+                    if arg.startswith('$'):
+                        args[i] = defaults[arg[1:]]
+                data,status = commands.getstatusoutput(' '.join(args))
+                if status:
+                    raise RuntimeError('Error running: %s' % ' '.join(args))
+                outf.write('%s = %s\n' % (varname,data.strip()))
+            continue
+            
+        if line.startswith('!'):
+            # Ask a question
+            res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
+            if not res:
+                raise RuntimeError("Weird line: %s" % line)
+            varname = res.group(2)
+            vartype = res.group(3)
+
+            default = defaults.get(varname,None)
+            
+            if res.group(1):
+                if not check_condition(res.group(1), defaults,
+                                       asked_names):
+                    if default is not None:
+                        outf.write('#!# %s = %s\n' % (varname, default))
+                    # Clear cumulated values
+                    comment = ''
+                    default = None
+                    choices = []
+                    continue
+                
+            asked_names.append((varname,comment))
+
+            if default is None or not askonly or askonly == varname:
+                default = ask_the_question(dlg)
+            else:
+                default = ask_the_question(DefaultDialog(dlg))
+
+            outf.write('%s = %s\n' % (varname, default))
+            # Remeber the selected value
+            defaults[varname] = default
+            # Clear cumulated values
+            comment = ''
+            default = None
+            choices = []
+            continue
+        
+        if line.startswith('@'):
+            # Add new line into the 'choice array' 
+            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
+            if not res:
+                raise RuntimeError("Bad line: %s" % line)
+            if res.group(1):
+                if not check_condition(res.group(1),defaults,
+                                       asked_names):
+                    continue
+            choices.append((res.group(2), res.group(3)))
+            continue
+
+        # All other things print to output file
+        outf.write(line)
+        if re.match(r'^#[^#]', line):
+            # Last comment before question will be displayed to the user
+            comment = line[1:].strip()
+        elif line.startswith('## '):
+            # Set title of the dialog window
+            dlg.set_title(line[2:].strip())
+
+    outf.write('\n')
+    outf.write('REVISION = %s\n' % commands.getoutput('svnversion . 2> /dev/null'))
+    outf.write('TIMESTAMP = %s\n' % commands.getoutput('date "+%Y-%m-%d %H:%M:%S"'))
+    outf.close()
+    f.close()
+    return asked_names
+
+def main():
+    defaults = {}
+    try:
+        dlg = Dialog()
+    except NotImplementedError:
+        dlg = NoDialog()
+
+    if len(sys.argv) >= 2 and sys.argv[1]=='default':
+        defmode = True
+    else:
+        defmode = False
+
+    # Default run will update the configuration file
+    # with newest options
+    if os.path.exists(OUTPUT):
+        read_defaults(OUTPUT, defaults)
+
+	# Get ARCH from command line if specified	
+    if len(sys.argv) >= 3:
+        defaults['ARCH'] = sys.argv[2]
+
+    # Dry run only with defaults
+    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
+    # If not in default mode, present selection of all possibilities
+    if not defmode:
+        defopt = 0
+        while 1:
+            # varnames contains variable names that were in the
+            # last question set
+            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
+            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
+            if res == 'save':
+                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
+                break
+            # transfer description back to varname
+            for i,(vname,descr) in enumerate(varnames):
+                if res == descr:
+                    defopt = i
+                    break
+            # Ask the user a simple question, produce output
+            # as if the user answered all the other questions
+            # with default answer
+            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
+                                    askonly=varnames[i][0])
+        
+    
+    if os.path.exists(OUTPUT):
+        os.unlink(OUTPUT)
+    os.rename(TMPOUTPUT, OUTPUT)
+    
+    if not defmode and dlg.yesno('Rebuild kernel?') == 'y':
+        os.execlp('make','make','clean','build')
+
+if __name__ == '__main__':
+    main()
Index: kernel/tools/genmap.py
===================================================================
--- kernel/tools/genmap.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/genmap.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+import sys
+import struct
+import re
+
+MAXSTRING=63
+symtabfmt = "<Q%ds" % (MAXSTRING+1)
+
+
+funcline = re.compile(r'([0-9a-f]+)\s+[lg]\s+.\s+\.text\s+([0-9a-f]+)\s+(.*)$')
+bssline = re.compile(r'([0-9a-f]+)\s+[lg]\s+[a-zA-Z]\s+\.bss\s+([0-9a-f]+)\s+(.*)$')
+dataline = re.compile(r'([0-9a-f]+)\s+[lg]\s+[a-zA-Z]\s+\.data\s+([0-9a-f]+)\s+(.*)$')
+fileexp = re.compile(r'([^\s]+):\s+file format')
+def read_obdump(inp):
+    funcs = {}
+    data = {}
+    bss ={}
+    fname = ''
+    for line in inp:
+        line = line.strip()
+        res = funcline.match(line)
+        if res:
+            funcs.setdefault(fname,[]).append((int(res.group(1),16),
+                                               res.group(3)))
+            continue
+        res = bssline.match(line)
+        if res:
+            start = int(res.group(1),16)
+            end = int(res.group(2),16)
+            if end:
+                bss.setdefault(fname,[]).append((start,res.group(3)))
+        res = dataline.match(line)
+        if res:
+            start = int(res.group(1),16)
+            end = int(res.group(2),16)
+            if end:
+                data.setdefault(fname,[]).append((start,res.group(3)))
+        res = fileexp.match(line)
+        if res:
+            fname = res.group(1)
+            continue
+
+    return {
+        'text' : funcs,
+        'bss' : bss,
+        'data' : data
+        }
+
+startfile = re.compile(r'\.(text|bss|data)\s+(0x[0-9a-f]+)\s+0x[0-9a-f]+\s+(.*)$')
+def generate(kmapf, obmapf, out):
+    obdump = read_obdump(obmapf)    
+
+    def sorter(x,y):
+        return cmp(x[0],y[0])
+
+    for line in kmapf:
+        line = line.strip()
+        res = startfile.match(line)
+
+        if res and obdump[res.group(1)].has_key(res.group(3)):
+            offset = int(res.group(2),16)
+            fname = res.group(3)
+            symbols = obdump[res.group(1)][fname]
+            symbols.sort(sorter)
+            for addr,symbol in symbols:                
+                value = fname + ':' + symbol
+                data = struct.pack(symtabfmt,addr+offset,value[:MAXSTRING])
+                out.write(data)
+                
+    out.write(struct.pack(symtabfmt,0,''))
+
+def main():
+    if len(sys.argv) != 4:
+        print "Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0]
+        sys.exit(1)
+
+    kmapf = open(sys.argv[1],'r')
+    obmapf = open(sys.argv[2],'r')
+    out = open(sys.argv[3],'w')
+    generate(kmapf,obmapf,out)
+    kmapf.close()
+    obmapf.close()
+    out.close()
+
+if __name__ == '__main__':
+    main()
Index: kernel/tools/ia32/decpt.py
===================================================================
--- kernel/tools/ia32/decpt.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/ia32/decpt.py	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+"""
+Decode 32-bit address into PTE components
+"""
+import sys
+
+def main():
+    if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
+        print "%s 0x..." % sys.argv[0]
+        sys.exit(1)
+    
+    address = int(sys.argv[1],16)
+    offset = address & 0xfff
+    ptl1 = (address >> 12) & 0x3ff
+    ptl0 = (address >> 22) & 0x3ff
+    print "Ptl0:   %3d" % ptl0
+    print "Ptl1:   %3d" % ptl1
+    print "Offset: 0x%x" % offset
+
+if __name__ == '__main__':
+    main()
Index: kernel/tools/mips32/gencontext.c
===================================================================
--- kernel/tools/mips32/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/mips32/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <stdint.h>
+
+typedef uint32_t uint32_t;
+typedef uint32_t ipl_t;
+typedef uint32_t uintptr_t;
+
+#define __mips32_TYPES_H__
+#include "../../arch/mips32/include/context.h"
+#include "../../arch/mips32/include/exception.h"
+
+#define FILENAME "../../arch/mips32/include/context_offset.h"
+
+int main(void)
+{
+	FILE *f;
+	struct context *pctx = NULL;
+	struct exception_regdump *edmp = NULL;
+	
+
+	f = fopen(FILENAME,"w");
+	if (!f) {
+		perror(FILENAME);
+		return 1;
+	}
+
+	fprintf(f, "/* This file is automatically generated by %s. */\n", __FILE__);	
+
+	fprintf(f,"/* struct context */\n");
+
+	fprintf(f,"#define OFFSET_SP      0x%x\n", ((int) &pctx->sp) - (int) pctx);
+	fprintf(f,"#define OFFSET_PC      0x%x\n", ((int) &pctx->pc) - (int) pctx);
+	fprintf(f,"#define OFFSET_S0      0x%x\n", ((int) &pctx->s0) - (int) pctx);
+	fprintf(f,"#define OFFSET_S1      0x%x\n", ((int) &pctx->s1) - (int) pctx);
+	fprintf(f,"#define OFFSET_S2      0x%x\n", ((int) &pctx->s2) - (int) pctx);
+	fprintf(f,"#define OFFSET_S3      0x%x\n", ((int) &pctx->s3) - (int) pctx);
+	fprintf(f,"#define OFFSET_S4      0x%x\n", ((int) &pctx->s4) - (int) pctx);
+	fprintf(f,"#define OFFSET_S5      0x%x\n", ((int) &pctx->s5) - (int) pctx);
+	fprintf(f,"#define OFFSET_S6      0x%x\n", ((int) &pctx->s6) - (int) pctx);
+	fprintf(f,"#define OFFSET_S7      0x%x\n", ((int) &pctx->s7) - (int) pctx);
+	fprintf(f,"#define OFFSET_S8      0x%x\n", ((int) &pctx->s8) - (int) pctx);
+	fprintf(f,"#define OFFSET_GP      0x%x\n", ((int) &pctx->gp) - (int) pctx);
+
+	fprintf(f,"\n\n/* struct register_dump */\n");
+	fprintf(f,"#define EOFFSET_AT     0x%x\n", ((int) &edmp->at) - (int) edmp);
+	fprintf(f,"#define EOFFSET_V0     0x%x\n", ((int) &edmp->v0) - (int) edmp);
+	fprintf(f,"#define EOFFSET_V1     0x%x\n", ((int) &edmp->v1) - (int) edmp);
+	fprintf(f,"#define EOFFSET_A0     0x%x\n", ((int) &edmp->a0) - (int) edmp);
+	fprintf(f,"#define EOFFSET_A1     0x%x\n", ((int) &edmp->a1) - (int) edmp);
+	fprintf(f,"#define EOFFSET_A2     0x%x\n", ((int) &edmp->a2) - (int) edmp);
+	fprintf(f,"#define EOFFSET_A3     0x%x\n", ((int) &edmp->a3) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T0     0x%x\n", ((int) &edmp->t0) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T1     0x%x\n", ((int) &edmp->t1) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T2     0x%x\n", ((int) &edmp->t2) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T3     0x%x\n", ((int) &edmp->t3) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T4     0x%x\n", ((int) &edmp->t4) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T5     0x%x\n", ((int) &edmp->t5) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T6     0x%x\n", ((int) &edmp->t6) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T7     0x%x\n", ((int) &edmp->t7) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S0     0x%x\n", ((int) &edmp->s0) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S1     0x%x\n", ((int) &edmp->s1) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S2     0x%x\n", ((int) &edmp->s2) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S3     0x%x\n", ((int) &edmp->s3) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S4     0x%x\n", ((int) &edmp->s4) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S5     0x%x\n", ((int) &edmp->s5) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S6     0x%x\n", ((int) &edmp->s6) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S7     0x%x\n", ((int) &edmp->s7) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T8     0x%x\n", ((int) &edmp->t8) - (int) edmp);
+	fprintf(f,"#define EOFFSET_T9     0x%x\n", ((int) &edmp->t9) - (int) edmp);
+	fprintf(f,"#define EOFFSET_GP     0x%x\n", ((int) &edmp->gp) - (int) edmp);
+	fprintf(f,"#define EOFFSET_SP     0x%x\n", ((int) &edmp->sp) - (int) edmp);
+	fprintf(f,"#define EOFFSET_S8     0x%x\n", ((int) &edmp->s8) - (int) edmp);
+	fprintf(f,"#define EOFFSET_RA     0x%x\n", ((int) &edmp->ra) - (int) edmp);
+	fprintf(f,"#define EOFFSET_LO     0x%x\n", ((int) &edmp->lo) - (int) edmp);
+	fprintf(f,"#define EOFFSET_HI     0x%x\n", ((int) &edmp->hi) - (int) edmp);
+	fprintf(f,"#define EOFFSET_STATUS 0x%x\n", ((int) &edmp->status) - (int) edmp);
+	fprintf(f,"#define EOFFSET_EPC    0x%x\n", ((int) &edmp->epc) - (int) edmp);
+
+	fprintf(f,"#define REGISTER_SPACE %d\n", sizeof(*edmp));
+
+	fclose(f);
+
+	return 0;
+}
Index: kernel/tools/ppc32/gencontext.c
===================================================================
--- kernel/tools/ppc32/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/ppc32/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdint.h>
+
+typedef uint32_t uint32_t;
+typedef uint64_t uint64_t;
+typedef uint32_t ipl_t;
+typedef uint32_t uintptr_t;
+
+#define __ppc32_TYPES_H__
+#include "../../arch/ppc32/include/context.h"
+#include "../../arch/ppc32/include/fpu_context.h"
+
+#define FILENAME "../../arch/ppc32/include/context_offset.h"
+
+int main(void)
+{
+	FILE *f;
+	struct context *pctx = NULL;
+	struct fpu_context *fpctx = NULL;
+	
+
+	f = fopen(FILENAME,"w");
+	if (!f) {
+		perror(FILENAME);
+		return 1;
+	}
+
+	fprintf(f, "/* This file is automatically generated by %s. */\n", __FILE__);	
+
+	fprintf(f,"/* struct context */\n");
+
+	fprintf(f,"#define OFFSET_SP    0x%x\n", ((int) &pctx->sp) - (int) pctx);
+	fprintf(f,"#define OFFSET_PC    0x%x\n", ((int) &pctx->pc) - (int) pctx);
+	fprintf(f,"#define OFFSET_R2    0x%x\n", ((int) &pctx->r2) - (int) pctx);
+	fprintf(f,"#define OFFSET_R13   0x%x\n", ((int) &pctx->r13) - (int) pctx);
+	fprintf(f,"#define OFFSET_R14   0x%x\n", ((int) &pctx->r14) - (int) pctx);
+	fprintf(f,"#define OFFSET_R15   0x%x\n", ((int) &pctx->r15) - (int) pctx);
+	fprintf(f,"#define OFFSET_R16   0x%x\n", ((int) &pctx->r16) - (int) pctx);
+	fprintf(f,"#define OFFSET_R17   0x%x\n", ((int) &pctx->r17) - (int) pctx);
+	fprintf(f,"#define OFFSET_R18   0x%x\n", ((int) &pctx->r18) - (int) pctx);
+	fprintf(f,"#define OFFSET_R19   0x%x\n", ((int) &pctx->r19) - (int) pctx);
+	fprintf(f,"#define OFFSET_R20   0x%x\n", ((int) &pctx->r20) - (int) pctx);
+	fprintf(f,"#define OFFSET_R21   0x%x\n", ((int) &pctx->r21) - (int) pctx);
+	fprintf(f,"#define OFFSET_R22   0x%x\n", ((int) &pctx->r22) - (int) pctx);
+	fprintf(f,"#define OFFSET_R23   0x%x\n", ((int) &pctx->r23) - (int) pctx);
+	fprintf(f,"#define OFFSET_R24   0x%x\n", ((int) &pctx->r24) - (int) pctx);
+	fprintf(f,"#define OFFSET_R25   0x%x\n", ((int) &pctx->r25) - (int) pctx);
+	fprintf(f,"#define OFFSET_R26   0x%x\n", ((int) &pctx->r26) - (int) pctx);
+	fprintf(f,"#define OFFSET_R27   0x%x\n", ((int) &pctx->r27) - (int) pctx);
+	fprintf(f,"#define OFFSET_R28   0x%x\n", ((int) &pctx->r28) - (int) pctx);
+	fprintf(f,"#define OFFSET_R29   0x%x\n", ((int) &pctx->r29) - (int) pctx);
+	fprintf(f,"#define OFFSET_R30   0x%x\n", ((int) &pctx->r30) - (int) pctx);
+	fprintf(f,"#define OFFSET_R31   0x%x\n", ((int) &pctx->r31) - (int) pctx);
+	fprintf(f,"#define OFFSET_CR    0x%x\n", ((int) &pctx->cr) - (int) pctx);
+	
+	fprintf(f,"\n");
+
+	fprintf(f,"#define OFFSET_FR14  0x%x\n", ((int) &fpctx->fr14) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR15  0x%x\n", ((int) &fpctx->fr15) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR16  0x%x\n", ((int) &fpctx->fr16) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR17  0x%x\n", ((int) &fpctx->fr17) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR18  0x%x\n", ((int) &fpctx->fr18) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR19  0x%x\n", ((int) &fpctx->fr19) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR20  0x%x\n", ((int) &fpctx->fr20) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR21  0x%x\n", ((int) &fpctx->fr21) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR22  0x%x\n", ((int) &fpctx->fr22) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR23  0x%x\n", ((int) &fpctx->fr23) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR24  0x%x\n", ((int) &fpctx->fr24) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR25  0x%x\n", ((int) &fpctx->fr25) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR26  0x%x\n", ((int) &fpctx->fr26) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR27  0x%x\n", ((int) &fpctx->fr27) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR28  0x%x\n", ((int) &fpctx->fr28) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR29  0x%x\n", ((int) &fpctx->fr29) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR30  0x%x\n", ((int) &fpctx->fr30) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR31  0x%x\n", ((int) &fpctx->fr31) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FPSCR 0x%x\n", ((int) &fpctx->fpscr) - (int) fpctx);
+	
+	fclose(f);
+
+	return 0;
+}
Index: kernel/tools/ppc64/gencontext.c
===================================================================
--- kernel/tools/ppc64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/ppc64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdint.h>
+
+typedef uint32_t uint32_t;
+typedef uint64_t uint64_t;
+typedef uint64_t ipl_t;
+typedef uint64_t uintptr_t;
+
+#define __ppc64_TYPES_H__
+#include "../../arch/ppc64/include/context.h"
+#include "../../arch/ppc64/include/fpu_context.h"
+
+#define FILENAME "../../arch/ppc64/include/context_offset.h"
+
+int main(void)
+{
+	FILE *f;
+	struct context *pctx = NULL;
+	struct fpu_context *fpctx = NULL;
+	
+
+	f = fopen(FILENAME,"w");
+	if (!f) {
+		perror(FILENAME);
+		return 1;
+	}
+
+	fprintf(f, "/* This file is automatically generated by %s. */\n", __FILE__);	
+
+	fprintf(f,"/* struct context */\n");
+
+	fprintf(f,"#define OFFSET_SP    0x%x\n", ((int) &pctx->sp) - (int) pctx);
+	fprintf(f,"#define OFFSET_PC    0x%x\n", ((int) &pctx->pc) - (int) pctx);
+	fprintf(f,"#define OFFSET_R2    0x%x\n", ((int) &pctx->r2) - (int) pctx);
+	fprintf(f,"#define OFFSET_R13   0x%x\n", ((int) &pctx->r13) - (int) pctx);
+	fprintf(f,"#define OFFSET_R14   0x%x\n", ((int) &pctx->r14) - (int) pctx);
+	fprintf(f,"#define OFFSET_R15   0x%x\n", ((int) &pctx->r15) - (int) pctx);
+	fprintf(f,"#define OFFSET_R16   0x%x\n", ((int) &pctx->r16) - (int) pctx);
+	fprintf(f,"#define OFFSET_R17   0x%x\n", ((int) &pctx->r17) - (int) pctx);
+	fprintf(f,"#define OFFSET_R18   0x%x\n", ((int) &pctx->r18) - (int) pctx);
+	fprintf(f,"#define OFFSET_R19   0x%x\n", ((int) &pctx->r19) - (int) pctx);
+	fprintf(f,"#define OFFSET_R20   0x%x\n", ((int) &pctx->r20) - (int) pctx);
+	fprintf(f,"#define OFFSET_R21   0x%x\n", ((int) &pctx->r21) - (int) pctx);
+	fprintf(f,"#define OFFSET_R22   0x%x\n", ((int) &pctx->r22) - (int) pctx);
+	fprintf(f,"#define OFFSET_R23   0x%x\n", ((int) &pctx->r23) - (int) pctx);
+	fprintf(f,"#define OFFSET_R24   0x%x\n", ((int) &pctx->r24) - (int) pctx);
+	fprintf(f,"#define OFFSET_R25   0x%x\n", ((int) &pctx->r25) - (int) pctx);
+	fprintf(f,"#define OFFSET_R26   0x%x\n", ((int) &pctx->r26) - (int) pctx);
+	fprintf(f,"#define OFFSET_R27   0x%x\n", ((int) &pctx->r27) - (int) pctx);
+	fprintf(f,"#define OFFSET_R28   0x%x\n", ((int) &pctx->r28) - (int) pctx);
+	fprintf(f,"#define OFFSET_R29   0x%x\n", ((int) &pctx->r29) - (int) pctx);
+	fprintf(f,"#define OFFSET_R30   0x%x\n", ((int) &pctx->r30) - (int) pctx);
+	fprintf(f,"#define OFFSET_R31   0x%x\n", ((int) &pctx->r31) - (int) pctx);
+	fprintf(f,"#define OFFSET_CR    0x%x\n", ((int) &pctx->cr) - (int) pctx);
+	
+	fprintf(f,"\n");
+
+	fprintf(f,"#define OFFSET_FR14  0x%x\n", ((int) &fpctx->fr14) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR15  0x%x\n", ((int) &fpctx->fr15) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR16  0x%x\n", ((int) &fpctx->fr16) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR17  0x%x\n", ((int) &fpctx->fr17) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR18  0x%x\n", ((int) &fpctx->fr18) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR19  0x%x\n", ((int) &fpctx->fr19) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR20  0x%x\n", ((int) &fpctx->fr20) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR21  0x%x\n", ((int) &fpctx->fr21) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR22  0x%x\n", ((int) &fpctx->fr22) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR23  0x%x\n", ((int) &fpctx->fr23) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR24  0x%x\n", ((int) &fpctx->fr24) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR25  0x%x\n", ((int) &fpctx->fr25) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR26  0x%x\n", ((int) &fpctx->fr26) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR27  0x%x\n", ((int) &fpctx->fr27) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR28  0x%x\n", ((int) &fpctx->fr28) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR29  0x%x\n", ((int) &fpctx->fr29) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR30  0x%x\n", ((int) &fpctx->fr30) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FR31  0x%x\n", ((int) &fpctx->fr31) - (int) fpctx);
+	fprintf(f,"#define OFFSET_FPSCR 0x%x\n", ((int) &fpctx->fpscr) - (int) fpctx);
+	
+	fclose(f);
+
+	return 0;
+}
Index: kernel/tools/sparc64/gencontext.c
===================================================================
--- kernel/tools/sparc64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/tools/sparc64/gencontext.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdint.h>
+
+typedef uint64_t uint64_t;
+typedef uint64_t ipl_t;
+typedef uint64_t uintptr_t;
+
+#define __sparc64_TYPES_H__
+#define __ALIGN_H__
+
+#include "../../arch/sparc64/include/stack.h"
+#include "../../arch/sparc64/include/context.h"
+
+#define FILENAME "../../arch/sparc64/include/context_offset.h"
+
+int main(void)
+{
+	FILE *f;
+	struct context *pctx = NULL;
+	
+
+	f = fopen(FILENAME,"w");
+	if (!f) {
+		perror(FILENAME);
+		return 1;
+	}
+
+	fprintf(f, "/* This file is automatically generated by %s. */\n", __FILE__);	
+
+	fprintf(f,"/* struct context */\n");
+	fprintf(f,"#define OFFSET_SP       0x%x\n", ((int) &pctx->sp) - (int) pctx);
+	fprintf(f,"#define OFFSET_PC       0x%x\n", ((int) &pctx->pc) - (int) pctx);
+	fprintf(f,"#define OFFSET_I0       0x%x\n", ((int) &pctx->i0) - (int) pctx);
+	fprintf(f,"#define OFFSET_I1       0x%x\n", ((int) &pctx->i1) - (int) pctx);
+	fprintf(f,"#define OFFSET_I2       0x%x\n", ((int) &pctx->i2) - (int) pctx);
+	fprintf(f,"#define OFFSET_I3       0x%x\n", ((int) &pctx->i3) - (int) pctx);
+	fprintf(f,"#define OFFSET_I4       0x%x\n", ((int) &pctx->i4) - (int) pctx);
+	fprintf(f,"#define OFFSET_I5       0x%x\n", ((int) &pctx->i5) - (int) pctx);
+	fprintf(f,"#define OFFSET_FP       0x%x\n", ((int) &pctx->fp) - (int) pctx);
+	fprintf(f,"#define OFFSET_I7       0x%x\n", ((int) &pctx->i7) - (int) pctx);
+	fprintf(f,"#define OFFSET_L0       0x%x\n", ((int) &pctx->l0) - (int) pctx);
+	fprintf(f,"#define OFFSET_L1       0x%x\n", ((int) &pctx->l1) - (int) pctx);
+	fprintf(f,"#define OFFSET_L2       0x%x\n", ((int) &pctx->l2) - (int) pctx);
+	fprintf(f,"#define OFFSET_L3       0x%x\n", ((int) &pctx->l3) - (int) pctx);
+	fprintf(f,"#define OFFSET_L4       0x%x\n", ((int) &pctx->l4) - (int) pctx);
+	fprintf(f,"#define OFFSET_L5       0x%x\n", ((int) &pctx->l5) - (int) pctx);
+	fprintf(f,"#define OFFSET_L6       0x%x\n", ((int) &pctx->l6) - (int) pctx);
+	fprintf(f,"#define OFFSET_L7       0x%x\n", ((int) &pctx->l7) - (int) pctx);
+	fprintf(f,"#define OFFSET_CLEANWIN 0x%x\n", ((int) &pctx->cleanwin) - (int) pctx);
+
+	fclose(f);
+
+	return 0;
+}
