summaryrefslogtreecommitdiff
path: root/src/sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/sh')
-rw-r--r--src/sh/Gcreate_addr_space.c59
-rw-r--r--src/sh/Gget_proc_info.c39
-rw-r--r--src/sh/Gget_save_loc.c83
-rw-r--r--src/sh/Gglobal.c56
-rw-r--r--src/sh/Ginit.c186
-rw-r--r--src/sh/Ginit_local.c55
-rw-r--r--src/sh/Ginit_remote.c45
-rw-r--r--src/sh/Gis_signal_frame.c119
-rw-r--r--src/sh/Gregs.c79
-rw-r--r--src/sh/Gresume.c165
-rw-r--r--src/sh/Gstep.c117
-rw-r--r--src/sh/Lcreate_addr_space.c5
-rw-r--r--src/sh/Lget_proc_info.c5
-rw-r--r--src/sh/Lget_save_loc.c5
-rw-r--r--src/sh/Lglobal.c5
-rw-r--r--src/sh/Linit.c5
-rw-r--r--src/sh/Linit_local.c5
-rw-r--r--src/sh/Linit_remote.c5
-rw-r--r--src/sh/Lis_signal_frame.c5
-rw-r--r--src/sh/Lregs.c5
-rw-r--r--src/sh/Lresume.c5
-rw-r--r--src/sh/Lstep.c5
-rw-r--r--src/sh/gen-offsets.c51
-rw-r--r--src/sh/init.h74
-rw-r--r--src/sh/is_fpreg.c32
-rw-r--r--src/sh/offsets.h32
-rw-r--r--src/sh/regname.c56
-rw-r--r--src/sh/siglongjmp.S8
-rw-r--r--src/sh/unwind_i.h40
29 files changed, 1351 insertions, 0 deletions
diff --git a/src/sh/Gcreate_addr_space.c b/src/sh/Gcreate_addr_space.c
new file mode 100644
index 00000000..1907d046
--- /dev/null
+++ b/src/sh/Gcreate_addr_space.c
@@ -0,0 +1,59 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "unwind_i.h"
+
+PROTECTED unw_addr_space_t
+unw_create_addr_space (unw_accessors_t *a, int byte_order)
+{
+#ifdef UNW_LOCAL_ONLY
+ return NULL;
+#else
+ unw_addr_space_t as;
+
+ /* SH supports little-endian and big-endian. */
+ if (byte_order != 0 && byte_order != __LITTLE_ENDIAN
+ && byte_order != __BIG_ENDIAN)
+ return NULL;
+
+ as = malloc (sizeof (*as));
+ if (!as)
+ return NULL;
+
+ memset (as, 0, sizeof (*as));
+
+ as->acc = *a;
+
+ /* Default to little-endian for SH. */
+ if (byte_order == 0 || byte_order == __LITTLE_ENDIAN)
+ as->big_endian = 0;
+ else
+ as->big_endian = 1;
+
+ return as;
+#endif
+}
diff --git a/src/sh/Gget_proc_info.c b/src/sh/Gget_proc_info.c
new file mode 100644
index 00000000..de9199f9
--- /dev/null
+++ b/src/sh/Gget_proc_info.c
@@ -0,0 +1,39 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+PROTECTED int
+unw_get_proc_info (unw_cursor_t *cursor, unw_proc_info_t *pi)
+{
+ struct cursor *c = (struct cursor *) cursor;
+ int ret;
+
+ ret = dwarf_make_proc_info (&c->dwarf);
+ if (ret < 0)
+ return ret;
+
+ *pi = c->dwarf.pi;
+ return 0;
+}
diff --git a/src/sh/Gget_save_loc.c b/src/sh/Gget_save_loc.c
new file mode 100644
index 00000000..8b83c6f6
--- /dev/null
+++ b/src/sh/Gget_save_loc.c
@@ -0,0 +1,83 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+PROTECTED int
+unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc)
+{
+ struct cursor *c = (struct cursor *) cursor;
+ dwarf_loc_t loc;
+
+ switch (reg)
+ {
+ case UNW_SH_R0:
+ case UNW_SH_R1:
+ case UNW_SH_R2:
+ case UNW_SH_R3:
+ case UNW_SH_R4:
+ case UNW_SH_R5:
+ case UNW_SH_R6:
+ case UNW_SH_R7:
+ case UNW_SH_R8:
+ case UNW_SH_R9:
+ case UNW_SH_R10:
+ case UNW_SH_R11:
+ case UNW_SH_R12:
+ case UNW_SH_R13:
+ case UNW_SH_R14:
+ case UNW_SH_R15:
+ case UNW_SH_PC:
+ case UNW_SH_PR:
+ loc = c->dwarf.loc[reg];
+ break;
+
+ default:
+ loc = DWARF_NULL_LOC; /* default to "not saved" */
+ break;
+ }
+
+ memset (sloc, 0, sizeof (*sloc));
+
+ if (DWARF_IS_NULL_LOC (loc))
+ {
+ sloc->type = UNW_SLT_NONE;
+ return 0;
+ }
+
+#if !defined(UNW_LOCAL_ONLY)
+ if (DWARF_IS_REG_LOC (loc))
+ {
+ sloc->type = UNW_SLT_REG;
+ sloc->u.regnum = DWARF_GET_LOC (loc);
+ }
+ else
+#endif
+ {
+ sloc->type = UNW_SLT_MEMORY;
+ sloc->u.addr = DWARF_GET_LOC (loc);
+ }
+ return 0;
+}
diff --git a/src/sh/Gglobal.c b/src/sh/Gglobal.c
new file mode 100644
index 00000000..4776d22a
--- /dev/null
+++ b/src/sh/Gglobal.c
@@ -0,0 +1,56 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+#include "dwarf_i.h"
+
+HIDDEN define_lock (sh_lock);
+HIDDEN int tdep_init_done;
+
+HIDDEN void
+tdep_init (void)
+{
+ intrmask_t saved_mask;
+
+ sigfillset (&unwi_full_mask);
+
+ lock_acquire (&sh_lock, saved_mask);
+ {
+ if (tdep_init_done)
+ /* another thread else beat us to it... */
+ goto out;
+
+ mi_init ();
+
+ dwarf_init ();
+
+#ifndef UNW_REMOTE_ONLY
+ sh_local_addr_space_init ();
+#endif
+ tdep_init_done = 1; /* signal that we're initialized... */
+ }
+ out:
+ lock_release (&sh_lock, saved_mask);
+}
diff --git a/src/sh/Ginit.c b/src/sh/Ginit.c
new file mode 100644
index 00000000..d65bff6b
--- /dev/null
+++ b/src/sh/Ginit.c
@@ -0,0 +1,186 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "unwind_i.h"
+
+#ifdef UNW_REMOTE_ONLY
+
+/* unw_local_addr_space is a NULL pointer in this case. */
+PROTECTED unw_addr_space_t unw_local_addr_space;
+
+#else /* !UNW_REMOTE_ONLY */
+
+static struct unw_addr_space local_addr_space;
+
+PROTECTED unw_addr_space_t unw_local_addr_space = &local_addr_space;
+
+static inline void *
+uc_addr (ucontext_t *uc, int reg)
+{
+ if (reg >= UNW_SH_R0 && reg <= UNW_SH_PR)
+ return &uc->uc_mcontext.gregs[reg];
+ else
+ return NULL;
+}
+
+# ifdef UNW_LOCAL_ONLY
+
+HIDDEN void *
+tdep_uc_addr (ucontext_t *uc, int reg)
+{
+ return uc_addr (uc, reg);
+}
+
+# endif /* UNW_LOCAL_ONLY */
+
+HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
+
+/* XXX fix me: there is currently no way to locate the dyn-info list
+ by a remote unwinder. On ia64, this is done via a special
+ unwind-table entry. Perhaps something similar can be done with
+ DWARF2 unwind info. */
+
+static void
+put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
+{
+ /* it's a no-op */
+}
+
+static int
+get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
+ void *arg)
+{
+ *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
+ return 0;
+}
+
+static int
+access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write,
+ void *arg)
+{
+ if (write)
+ {
+ Debug (16, "mem[%x] <- %x\n", addr, *val);
+ *(unw_word_t *) addr = *val;
+ }
+ else
+ {
+ *val = *(unw_word_t *) addr;
+ Debug (16, "mem[%x] -> %x\n", addr, *val);
+ }
+ return 0;
+}
+
+static int
+access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, int write,
+ void *arg)
+{
+ unw_word_t *addr;
+ ucontext_t *uc = arg;
+
+ if (unw_is_fpreg (reg))
+ goto badreg;
+
+ if (!(addr = uc_addr (uc, reg)))
+ goto badreg;
+
+ if (write)
+ {
+ *(unw_word_t *) addr = *val;
+ Debug (12, "%s <- %x\n", unw_regname (reg), *val);
+ }
+ else
+ {
+ *val = *(unw_word_t *) addr;
+ Debug (12, "%s -> %x\n", unw_regname (reg), *val);
+ }
+ return 0;
+
+ badreg:
+ Debug (1, "bad register number %u\n", reg);
+ return -UNW_EBADREG;
+}
+
+static int
+access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
+ int write, void *arg)
+{
+ ucontext_t *uc = arg;
+ unw_fpreg_t *addr;
+
+ if (!unw_is_fpreg (reg))
+ goto badreg;
+
+ if (!(addr = uc_addr (uc, reg)))
+ goto badreg;
+
+ if (write)
+ {
+ Debug (12, "%s <- %08lx.%08lx.%08lx\n", unw_regname (reg),
+ ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
+ *(unw_fpreg_t *) addr = *val;
+ }
+ else
+ {
+ *val = *(unw_fpreg_t *) addr;
+ Debug (12, "%s -> %08lx.%08lx.%08lx\n", unw_regname (reg),
+ ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
+ }
+ return 0;
+
+ badreg:
+ Debug (1, "bad register number %u\n", reg);
+ /* attempt to access a non-preserved register */
+ return -UNW_EBADREG;
+}
+
+static int
+get_static_proc_name (unw_addr_space_t as, unw_word_t ip,
+ char *buf, size_t buf_len, unw_word_t *offp,
+ void *arg)
+{
+ return _Uelf32_get_proc_name (as, getpid (), ip, buf, buf_len, offp);
+}
+
+HIDDEN void
+sh_local_addr_space_init (void)
+{
+ memset (&local_addr_space, 0, sizeof (local_addr_space));
+ local_addr_space.caching_policy = UNW_CACHE_GLOBAL;
+ local_addr_space.acc.find_proc_info = dwarf_find_proc_info;
+ local_addr_space.acc.put_unwind_info = put_unwind_info;
+ local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
+ local_addr_space.acc.access_mem = access_mem;
+ local_addr_space.acc.access_reg = access_reg;
+ local_addr_space.acc.access_fpreg = access_fpreg;
+ local_addr_space.acc.resume = sh_local_resume;
+ local_addr_space.acc.get_proc_name = get_static_proc_name;
+ unw_flush_cache (&local_addr_space, 0, 0);
+}
+
+#endif /* !UNW_REMOTE_ONLY */
diff --git a/src/sh/Ginit_local.c b/src/sh/Ginit_local.c
new file mode 100644
index 00000000..e1cc30c6
--- /dev/null
+++ b/src/sh/Ginit_local.c
@@ -0,0 +1,55 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright 2011 Linaro Limited
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+#include "init.h"
+
+#ifdef UNW_REMOTE_ONLY
+
+PROTECTED int
+unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
+{
+ return -UNW_EINVAL;
+}
+
+#else /* !UNW_REMOTE_ONLY */
+
+PROTECTED int
+unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
+{
+ struct cursor *c = (struct cursor *) cursor;
+
+ if (!tdep_init_done)
+ tdep_init ();
+
+ Debug (1, "(cursor=%p)\n", c);
+
+ c->dwarf.as = unw_local_addr_space;
+ c->dwarf.as_arg = uc;
+
+ return common_init (c, 1);
+}
+
+#endif /* !UNW_REMOTE_ONLY */
diff --git a/src/sh/Ginit_remote.c b/src/sh/Ginit_remote.c
new file mode 100644
index 00000000..f284e994
--- /dev/null
+++ b/src/sh/Ginit_remote.c
@@ -0,0 +1,45 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "init.h"
+#include "unwind_i.h"
+
+PROTECTED int
+unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
+{
+#ifdef UNW_LOCAL_ONLY
+ return -UNW_EINVAL;
+#else /* !UNW_LOCAL_ONLY */
+ struct cursor *c = (struct cursor *) cursor;
+
+ if (!tdep_init_done)
+ tdep_init ();
+
+ Debug (1, "(cursor=%p)\n", c);
+
+ c->dwarf.as = as;
+ c->dwarf.as_arg = as_arg;
+ return common_init (c, 0);
+#endif /* !UNW_LOCAL_ONLY */
+}
diff --git a/src/sh/Gis_signal_frame.c b/src/sh/Gis_signal_frame.c
new file mode 100644
index 00000000..9719f8e0
--- /dev/null
+++ b/src/sh/Gis_signal_frame.c
@@ -0,0 +1,119 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+/* Disassembly of the Linux VDSO sigreturn functions:
+
+00000000 <__kernel_sigreturn>:
+ 0: 05 93 mov.w e <__kernel_sigreturn+0xe>,r3 ! 77
+ 2: 10 c3 trapa #16
+ 4: 0b 20 or r0,r0
+ 6: 0b 20 or r0,r0
+ 8: 0b 20 or r0,r0
+ a: 0b 20 or r0,r0
+ c: 0b 20 or r0,r0
+ e: 77 00 .word 0x0077
+ 10: 09 00 nop
+ 12: 09 00 nop
+ 14: 09 00 nop
+ 16: 09 00 nop
+ 18: 09 00 nop
+ 1a: 09 00 nop
+ 1c: 09 00 nop
+ 1e: 09 00 nop
+
+00000020 <__kernel_rt_sigreturn>:
+ 20: 05 93 mov.w 2e <__kernel_rt_sigreturn+0xe>,r3 ! ad
+ 22: 10 c3 trapa #16
+ 24: 0b 20 or r0,r0
+ 26: 0b 20 or r0,r0
+ 28: 0b 20 or r0,r0
+ 2a: 0b 20 or r0,r0
+ 2c: 0b 20 or r0,r0
+ 2e: ad 00 mov.w @(r0,r10),r0
+ 30: 09 00 nop
+ 32: 09 00 nop
+ 34: 09 00 nop
+ 36: 09 00 nop
+ 38: 09 00 nop
+ 3a: 09 00 nop
+ 3c: 09 00 nop
+ 3e: 09 00 nop
+*/
+
+PROTECTED int
+unw_is_signal_frame (unw_cursor_t *cursor)
+{
+#ifdef __linux__
+ struct cursor *c = (struct cursor *) cursor;
+ unw_word_t w0, ip;
+ unw_addr_space_t as;
+ unw_accessors_t *a;
+ void *arg;
+ int ret;
+
+ as = c->dwarf.as;
+ a = unw_get_accessors (as);
+ arg = c->dwarf.as_arg;
+
+ ip = c->dwarf.ip;
+
+ ret = (*a->access_mem) (as, ip, &w0, 0, arg);
+ if (ret < 0)
+ return ret;
+
+ if (w0 != 0xc3109305)
+ return 0;
+
+ ret = (*a->access_mem) (as, ip+4, &w0, 0, arg);
+ if (ret < 0)
+ return ret;
+
+ if (w0 != 0x200b200b)
+ return 0;
+
+ ret = (*a->access_mem) (as, ip+8, &w0, 0, arg);
+ if (ret < 0)
+ return ret;
+
+ if (w0 != 0x200b200b)
+ return 0;
+
+ ret = (*a->access_mem) (as, ip+12, &w0, 0, arg);
+ if (ret < 0)
+ return ret;
+
+ if (w0 == 0x0077200b)
+ return 1; /* non-RT */
+ else if (w0 == 0x00ad200b)
+ return 2; /* RT */
+
+ /* does not look like a signal frame */
+ return 0;
+
+#else
+ return -UNW_ENOINFO;
+#endif
+}
diff --git a/src/sh/Gregs.c b/src/sh/Gregs.c
new file mode 100644
index 00000000..cd86a2da
--- /dev/null
+++ b/src/sh/Gregs.c
@@ -0,0 +1,79 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+HIDDEN int
+tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
+ int write)
+{
+ dwarf_loc_t loc = DWARF_NULL_LOC;
+
+ switch (reg)
+ {
+ case UNW_SH_R0:
+ case UNW_SH_R1:
+ case UNW_SH_R2:
+ case UNW_SH_R3:
+ case UNW_SH_R4:
+ case UNW_SH_R5:
+ case UNW_SH_R6:
+ case UNW_SH_R7:
+ case UNW_SH_R8:
+ case UNW_SH_R9:
+ case UNW_SH_R10:
+ case UNW_SH_R11:
+ case UNW_SH_R12:
+ case UNW_SH_R13:
+ case UNW_SH_R14:
+ case UNW_SH_PC:
+ case UNW_SH_PR:
+ loc = c->dwarf.loc[reg];
+ break;
+
+ case UNW_SH_R15:
+ if (write)
+ return -UNW_EREADONLYREG;
+ *valp = c->dwarf.cfa;
+ return 0;
+
+ default:
+ Debug (1, "bad register number %u\n", reg);
+ return -UNW_EBADREG;
+ }
+
+ if (write)
+ return dwarf_put (&c->dwarf, loc, *valp);
+ else
+ return dwarf_get (&c->dwarf, loc, valp);
+}
+
+HIDDEN int
+tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
+ int write)
+{
+ Debug (1, "bad register number %u\n", reg);
+ return -UNW_EBADREG;
+}
diff --git a/src/sh/Gresume.c b/src/sh/Gresume.c
new file mode 100644
index 00000000..6a76fe12
--- /dev/null
+++ b/src/sh/Gresume.c
@@ -0,0 +1,165 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright 2011 Linaro Limited
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+#include "offsets.h"
+
+#ifndef UNW_REMOTE_ONLY
+
+HIDDEN inline int
+sh_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
+{
+#ifdef __linux__
+ struct cursor *c = (struct cursor *) cursor;
+ unw_tdep_context_t *uc = c->dwarf.as_arg;
+
+ if (c->sigcontext_format == SH_SCF_NONE)
+ {
+ /* Since there are no signals involved here we restore the non scratch
+ registers only. */
+ unsigned long regs[8];
+ regs[0] = uc->uc_mcontext.gregs[8];
+ regs[1] = uc->uc_mcontext.gregs[9];
+ regs[2] = uc->uc_mcontext.gregs[10];
+ regs[3] = uc->uc_mcontext.gregs[11];
+ regs[4] = uc->uc_mcontext.gregs[12];
+ regs[5] = uc->uc_mcontext.gregs[13];
+ regs[6] = uc->uc_mcontext.gregs[14];
+ regs[7] = uc->uc_mcontext.gregs[15];
+ unsigned long pc = uc->uc_mcontext.pr;
+
+ struct regs_overlay {
+ char x[sizeof(regs)];
+ };
+
+ asm volatile (
+ "mov.l @%0+, r8\n"
+ "mov.l @%0+, r9\n"
+ "mov.l @%0+, r10\n"
+ "mov.l @%0+, r11\n"
+ "mov.l @%0+, r12\n"
+ "mov.l @%0+, r13\n"
+ "mov.l @%0+, r14\n"
+ "mov.l @%0, r15\n"
+ "lds %1, pr\n"
+ "rts\n"
+ "nop\n"
+ :
+ : "r" (regs),
+ "r" (pc),
+ "m" (*(struct regs_overlay *)regs)
+ );
+ }
+ else
+ {
+ /* In case a signal frame is involved, we're using its trampoline which
+ calls sigreturn. */
+ struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
+ sc->sc_regs[0] = uc->uc_mcontext.gregs[0];
+ sc->sc_regs[1] = uc->uc_mcontext.gregs[1];
+ sc->sc_regs[2] = uc->uc_mcontext.gregs[2];
+ sc->sc_regs[3] = uc->uc_mcontext.gregs[3];
+ sc->sc_regs[4] = uc->uc_mcontext.gregs[4];
+ sc->sc_regs[5] = uc->uc_mcontext.gregs[5];
+ sc->sc_regs[6] = uc->uc_mcontext.gregs[6];
+ sc->sc_regs[7] = uc->uc_mcontext.gregs[7];
+ sc->sc_regs[8] = uc->uc_mcontext.gregs[8];
+ sc->sc_regs[9] = uc->uc_mcontext.gregs[9];
+ sc->sc_regs[10] = uc->uc_mcontext.gregs[10];
+ sc->sc_regs[11] = uc->uc_mcontext.gregs[11];
+ sc->sc_regs[12] = uc->uc_mcontext.gregs[12];
+ sc->sc_regs[13] = uc->uc_mcontext.gregs[13];
+ sc->sc_regs[14] = uc->uc_mcontext.gregs[14];
+ sc->sc_regs[15] = uc->uc_mcontext.gregs[15];
+ sc->sc_pc = uc->uc_mcontext.pc;
+ sc->sc_pr = uc->uc_mcontext.pr;
+
+ /* Set the SP and the PC in order to continue execution at the modified
+ trampoline which restores the signal mask and the registers. */
+ asm __volatile__ (
+ "mov %0, r15\n"
+ "lds %1, pr\n"
+ "rts\n"
+ "nop\n"
+ :
+ : "r" (c->sigcontext_sp),
+ "r" (c->sigcontext_pc)
+ );
+ }
+ __builtin_unreachable();
+#endif
+ return -UNW_EINVAL;
+}
+
+#endif /* !UNW_REMOTE_ONLY */
+
+static inline void
+establish_machine_state (struct cursor *c)
+{
+ unw_addr_space_t as = c->dwarf.as;
+ void *arg = c->dwarf.as_arg;
+ unw_fpreg_t fpval;
+ unw_word_t val;
+ int reg;
+
+ Debug (8, "copying out cursor state\n");
+
+ for (reg = 0; reg <= UNW_REG_LAST; ++reg)
+ {
+ Debug (16, "copying %s %d\n", unw_regname (reg), reg);
+ if (unw_is_fpreg (reg))
+ {
+ if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
+ as->acc.access_fpreg (as, reg, &fpval, 1, arg);
+ }
+ else
+ {
+ if (tdep_access_reg (c, reg, &val, 0) >= 0)
+ as->acc.access_reg (as, reg, &val, 1, arg);
+ }
+ }
+}
+
+PROTECTED int
+unw_resume (unw_cursor_t *cursor)
+{
+ struct cursor *c = (struct cursor *) cursor;
+
+ Debug (1, "(cursor=%p)\n", c);
+
+ if (!c->dwarf.ip)
+ {
+ /* This can happen easily when the frame-chain gets truncated
+ due to bad or missing unwind-info. */
+ Debug (1, "refusing to resume execution at address 0\n");
+ return -UNW_EINVAL;
+ }
+
+ establish_machine_state (c);
+
+ return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
+ c->dwarf.as_arg);
+}
diff --git a/src/sh/Gstep.c b/src/sh/Gstep.c
new file mode 100644
index 00000000..9bbb5ff9
--- /dev/null
+++ b/src/sh/Gstep.c
@@ -0,0 +1,117 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+ Copyright 2011 Linaro Limited
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+#include "offsets.h"
+
+PROTECTED int
+unw_handle_signal_frame (unw_cursor_t *cursor)
+{
+ struct cursor *c = (struct cursor *) cursor;
+ int ret;
+ unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
+ struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
+
+ if ((ret = dwarf_get (&c->dwarf, sp_loc, &sp)) < 0)
+ return -UNW_EUNSPEC;
+
+ ret = unw_is_signal_frame (cursor);
+ Debug(1, "unw_is_signal_frame()=%d\n", ret);
+
+ /* Save the SP and PC to be able to return execution at this point
+ later in time (unw_resume). */
+ c->sigcontext_sp = c->dwarf.cfa;
+ c->sigcontext_pc = c->dwarf.ip;
+
+ if (ret == 1)
+ {
+ /* Handle non-RT signal frame. */
+ c->sigcontext_format = SH_SCF_LINUX_SIGFRAME;
+ sc_addr = sp_addr;
+ }
+ else if (ret == 2)
+ {
+ /* Handle RT signal frame. */
+ c->sigcontext_format = SH_SCF_LINUX_RT_SIGFRAME;
+ sc_addr = sp_addr + sizeof (siginfo_t) + LINUX_UC_MCONTEXT_OFF;
+ }
+ else
+ return -UNW_EUNSPEC;
+
+ c->sigcontext_addr = sc_addr;
+
+ /* Update the dwarf cursor.
+ Set the location of the registers to the corresponding addresses of the
+ uc_mcontext / sigcontext structure contents. */
+ c->dwarf.loc[UNW_SH_R0] = DWARF_LOC (sc_addr + LINUX_SC_R0_OFF, 0);
+ c->dwarf.loc[UNW_SH_R1] = DWARF_LOC (sc_addr + LINUX_SC_R1_OFF, 0);
+ c->dwarf.loc[UNW_SH_R2] = DWARF_LOC (sc_addr + LINUX_SC_R2_OFF, 0);
+ c->dwarf.loc[UNW_SH_R3] = DWARF_LOC (sc_addr + LINUX_SC_R3_OFF, 0);
+ c->dwarf.loc[UNW_SH_R4] = DWARF_LOC (sc_addr + LINUX_SC_R4_OFF, 0);
+ c->dwarf.loc[UNW_SH_R5] = DWARF_LOC (sc_addr + LINUX_SC_R5_OFF, 0);
+ c->dwarf.loc[UNW_SH_R6] = DWARF_LOC (sc_addr + LINUX_SC_R6_OFF, 0);
+ c->dwarf.loc[UNW_SH_R7] = DWARF_LOC (sc_addr + LINUX_SC_R7_OFF, 0);
+ c->dwarf.loc[UNW_SH_R8] = DWARF_LOC (sc_addr + LINUX_SC_R8_OFF, 0);
+ c->dwarf.loc[UNW_SH_R9] = DWARF_LOC (sc_addr + LINUX_SC_R9_OFF, 0);
+ c->dwarf.loc[UNW_SH_R10] = DWARF_LOC (sc_addr + LINUX_SC_R10_OFF, 0);
+ c->dwarf.loc[UNW_SH_R11] = DWARF_LOC (sc_addr + LINUX_SC_R11_OFF, 0);
+ c->dwarf.loc[UNW_SH_R12] = DWARF_LOC (sc_addr + LINUX_SC_R12_OFF, 0);
+ c->dwarf.loc[UNW_SH_R13] = DWARF_LOC (sc_addr + LINUX_SC_R13_OFF, 0);
+ c->dwarf.loc[UNW_SH_R14] = DWARF_LOC (sc_addr + LINUX_SC_R14_OFF, 0);
+ c->dwarf.loc[UNW_SH_R15] = DWARF_LOC (sc_addr + LINUX_SC_R15_OFF, 0);
+ c->dwarf.loc[UNW_SH_PR] = DWARF_LOC (sc_addr + LINUX_SC_PR_OFF, 0);
+ c->dwarf.loc[UNW_SH_PC] = DWARF_LOC (sc_addr + LINUX_SC_PC_OFF, 0);
+
+ /* Set SP/CFA and PC/IP. */
+ dwarf_get (&c->dwarf, c->dwarf.loc[UNW_SH_R15], &c->dwarf.cfa);
+ dwarf_get (&c->dwarf, c->dwarf.loc[UNW_SH_PC], &c->dwarf.ip);
+
+ c->dwarf.pi_valid = 0;
+
+ return 1;
+}
+
+PROTECTED int
+unw_step (unw_cursor_t *cursor)
+{
+ struct cursor *c = (struct cursor *) cursor;
+ int ret;
+
+ Debug (1, "(cursor=%p)\n", c);
+
+ if (unw_is_signal_frame (cursor))
+ return unw_handle_signal_frame (cursor);
+
+ ret = dwarf_step (&c->dwarf);
+
+ if (unlikely (ret == -UNW_ESTOPUNWIND))
+ return ret;
+
+ if (unlikely (ret < 0))
+ return 0;
+
+ return (c->dwarf.ip == 0) ? 0 : 1;
+}
diff --git a/src/sh/Lcreate_addr_space.c b/src/sh/Lcreate_addr_space.c
new file mode 100644
index 00000000..0f2dc6be
--- /dev/null
+++ b/src/sh/Lcreate_addr_space.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gcreate_addr_space.c"
+#endif
diff --git a/src/sh/Lget_proc_info.c b/src/sh/Lget_proc_info.c
new file mode 100644
index 00000000..69028b01
--- /dev/null
+++ b/src/sh/Lget_proc_info.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gget_proc_info.c"
+#endif
diff --git a/src/sh/Lget_save_loc.c b/src/sh/Lget_save_loc.c
new file mode 100644
index 00000000..9ea048a9
--- /dev/null
+++ b/src/sh/Lget_save_loc.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gget_save_loc.c"
+#endif
diff --git a/src/sh/Lglobal.c b/src/sh/Lglobal.c
new file mode 100644
index 00000000..6d7b489e
--- /dev/null
+++ b/src/sh/Lglobal.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gglobal.c"
+#endif
diff --git a/src/sh/Linit.c b/src/sh/Linit.c
new file mode 100644
index 00000000..e9abfdd4
--- /dev/null
+++ b/src/sh/Linit.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Ginit.c"
+#endif
diff --git a/src/sh/Linit_local.c b/src/sh/Linit_local.c
new file mode 100644
index 00000000..68a1687e
--- /dev/null
+++ b/src/sh/Linit_local.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Ginit_local.c"
+#endif
diff --git a/src/sh/Linit_remote.c b/src/sh/Linit_remote.c
new file mode 100644
index 00000000..58cb04ab
--- /dev/null
+++ b/src/sh/Linit_remote.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Ginit_remote.c"
+#endif
diff --git a/src/sh/Lis_signal_frame.c b/src/sh/Lis_signal_frame.c
new file mode 100644
index 00000000..b9a7c4f5
--- /dev/null
+++ b/src/sh/Lis_signal_frame.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gis_signal_frame.c"
+#endif
diff --git a/src/sh/Lregs.c b/src/sh/Lregs.c
new file mode 100644
index 00000000..2c9c75cd
--- /dev/null
+++ b/src/sh/Lregs.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gregs.c"
+#endif
diff --git a/src/sh/Lresume.c b/src/sh/Lresume.c
new file mode 100644
index 00000000..41a8cf00
--- /dev/null
+++ b/src/sh/Lresume.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gresume.c"
+#endif
diff --git a/src/sh/Lstep.c b/src/sh/Lstep.c
new file mode 100644
index 00000000..c1ac3c75
--- /dev/null
+++ b/src/sh/Lstep.c
@@ -0,0 +1,5 @@
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
+#include "Gstep.c"
+#endif
diff --git a/src/sh/gen-offsets.c b/src/sh/gen-offsets.c
new file mode 100644
index 00000000..16695a64
--- /dev/null
+++ b/src/sh/gen-offsets.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stddef.h>
+#include <ucontext.h>
+#include <asm/sigcontext.h>
+
+#define UC(N,X) \
+ printf ("#define LINUX_UC_" N "_OFF\t0x%X\n", offsetof (ucontext_t, X))
+
+#define SC(N,X) \
+ printf ("#define LINUX_SC_" N "_OFF\t0x%X\n", offsetof (struct sigcontext, X))
+
+int
+main (void)
+{
+ printf (
+"/* Linux-specific definitions: */\n\n"
+
+"/* Define various structure offsets to simplify cross-compilation. */\n\n"
+
+"/* Offsets for SH Linux \"ucontext_t\": */\n\n");
+
+ UC ("FLAGS", uc_flags);
+ UC ("LINK", uc_link);
+ UC ("STACK", uc_stack);
+ UC ("MCONTEXT", uc_mcontext);
+ UC ("SIGMASK", uc_sigmask);
+
+ printf ("\n/* Offsets for SH Linux \"struct sigcontext\": */\n\n");
+
+ SC ("R0", sc_regs[0]);
+ SC ("R1", sc_regs[1]);
+ SC ("R2", sc_regs[2]);
+ SC ("R3", sc_regs[3]);
+ SC ("R4", sc_regs[4]);
+ SC ("R5", sc_regs[5]);
+ SC ("R6", sc_regs[6]);
+ SC ("R7", sc_regs[7]);
+ SC ("R8", sc_regs[8]);
+ SC ("R9", sc_regs[9]);
+ SC ("R10", sc_regs[10]);
+ SC ("R11", sc_regs[11]);
+ SC ("R12", sc_regs[12]);
+ SC ("R13", sc_regs[13]);
+ SC ("R14", sc_regs[14]);
+ SC ("R15", sc_regs[15]);
+
+ SC ("PC", sc_pc);
+ SC ("PR", sc_pr);
+
+ return 0;
+}
diff --git a/src/sh/init.h b/src/sh/init.h
new file mode 100644
index 00000000..a180258e
--- /dev/null
+++ b/src/sh/init.h
@@ -0,0 +1,74 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+static inline int
+common_init (struct cursor *c, unsigned use_prev_instr)
+{
+ int ret;
+
+ c->dwarf.loc[UNW_SH_R0] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R0);
+ c->dwarf.loc[UNW_SH_R1] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R1);
+ c->dwarf.loc[UNW_SH_R2] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R2);
+ c->dwarf.loc[UNW_SH_R3] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R3);
+ c->dwarf.loc[UNW_SH_R4] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R4);
+ c->dwarf.loc[UNW_SH_R5] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R5);
+ c->dwarf.loc[UNW_SH_R6] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R6);
+ c->dwarf.loc[UNW_SH_R7] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R7);
+ c->dwarf.loc[UNW_SH_R8] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R8);
+ c->dwarf.loc[UNW_SH_R9] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R9);
+ c->dwarf.loc[UNW_SH_R10] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R10);
+ c->dwarf.loc[UNW_SH_R11] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R11);
+ c->dwarf.loc[UNW_SH_R12] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R12);
+ c->dwarf.loc[UNW_SH_R13] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R13);
+ c->dwarf.loc[UNW_SH_R14] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R14);
+ c->dwarf.loc[UNW_SH_R15] = DWARF_REG_LOC (&c->dwarf, UNW_SH_R15);
+ c->dwarf.loc[UNW_SH_PC] = DWARF_REG_LOC (&c->dwarf, UNW_SH_PC);
+ c->dwarf.loc[UNW_SH_PR] = DWARF_REG_LOC (&c->dwarf, UNW_SH_PR);
+
+ ret = dwarf_get (&c->dwarf, c->dwarf.loc[UNW_SH_PC], &c->dwarf.ip);
+ if (ret < 0)
+ return ret;
+
+ ret = dwarf_get (&c->dwarf, c->dwarf.loc[UNW_TDEP_SP], &c->dwarf.cfa);
+ if (ret < 0)
+ return ret;
+
+ c->sigcontext_format = SH_SCF_NONE;
+ c->sigcontext_addr = 0;
+ c->sigcontext_sp = 0;
+ c->sigcontext_pc = 0;
+
+ c->dwarf.args_size = 0;
+ c->dwarf.ret_addr_column = 0;
+ c->dwarf.stash_frames = 0;
+ c->dwarf.use_prev_instr = use_prev_instr;
+ c->dwarf.pi_valid = 0;
+ c->dwarf.pi_is_dynamic = 0;
+ c->dwarf.hint = 0;
+ c->dwarf.prev_rs = 0;
+
+ return 0;
+}
diff --git a/src/sh/is_fpreg.c b/src/sh/is_fpreg.c
new file mode 100644
index 00000000..c351f81c
--- /dev/null
+++ b/src/sh/is_fpreg.c
@@ -0,0 +1,32 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2008 CodeSourcery
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "libunwind_i.h"
+
+PROTECTED int
+unw_is_fpreg (int regnum)
+{
+ /* FIXME: Support FP. */
+ return 0;
+}
diff --git a/src/sh/offsets.h b/src/sh/offsets.h
new file mode 100644
index 00000000..75c86ca2
--- /dev/null
+++ b/src/sh/offsets.h
@@ -0,0 +1,32 @@
+/* Linux-specific definitions: */
+
+/* Define various structure offsets to simplify cross-compilation. */
+
+/* Offsets for SH Linux "ucontext_t": */
+
+#define LINUX_UC_FLAGS_OFF 0x0
+#define LINUX_UC_LINK_OFF 0x4
+#define LINUX_UC_STACK_OFF 0x8
+#define LINUX_UC_MCONTEXT_OFF 0x14
+#define LINUX_UC_SIGMASK_OFF 0xFC
+
+/* Offsets for SH Linux "struct sigcontext": */
+
+#define LINUX_SC_R0_OFF 0x4
+#define LINUX_SC_R1_OFF 0x8
+#define LINUX_SC_R2_OFF 0xC
+#define LINUX_SC_R3_OFF 0x10
+#define LINUX_SC_R4_OFF 0x14
+#define LINUX_SC_R5_OFF 0x18
+#define LINUX_SC_R6_OFF 0x1C
+#define LINUX_SC_R7_OFF 0x20
+#define LINUX_SC_R8_OFF 0x24
+#define LINUX_SC_R9_OFF 0x28
+#define LINUX_SC_R10_OFF 0x2C
+#define LINUX_SC_R11_OFF 0x30
+#define LINUX_SC_R12_OFF 0x34
+#define LINUX_SC_R13_OFF 0x38
+#define LINUX_SC_R14_OFF 0x3C
+#define LINUX_SC_R15_OFF 0x40
+#define LINUX_SC_PC_OFF 0x44
+#define LINUX_SC_PR_OFF 0x48
diff --git a/src/sh/regname.c b/src/sh/regname.c
new file mode 100644
index 00000000..dcab2405
--- /dev/null
+++ b/src/sh/regname.c
@@ -0,0 +1,56 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "unwind_i.h"
+
+static const char *const regname[] =
+ {
+ [UNW_SH_R0] = "r0",
+ [UNW_SH_R1] = "r1",
+ [UNW_SH_R2] = "r2",
+ [UNW_SH_R3] = "r3",
+ [UNW_SH_R4] = "r4",
+ [UNW_SH_R5] = "r5",
+ [UNW_SH_R6] = "r6",
+ [UNW_SH_R7] = "r7",
+ [UNW_SH_R8] = "r8",
+ [UNW_SH_R9] = "r9",
+ [UNW_SH_R10] = "r10",
+ [UNW_SH_R11] = "r11",
+ [UNW_SH_R12] = "r12",
+ [UNW_SH_R13] = "r13",
+ [UNW_SH_R14] = "r14",
+ [UNW_SH_R15] = "r15",
+ [UNW_SH_PC] = "pc",
+ [UNW_SH_PR] = "pr",
+ };
+
+PROTECTED const char *
+unw_regname (unw_regnum_t reg)
+{
+ if (reg < (unw_regnum_t) ARRAY_SIZE (regname) && regname[reg] != NULL)
+ return regname[reg];
+ else
+ return "???";
+}
diff --git a/src/sh/siglongjmp.S b/src/sh/siglongjmp.S
new file mode 100644
index 00000000..9ca53d12
--- /dev/null
+++ b/src/sh/siglongjmp.S
@@ -0,0 +1,8 @@
+ /* Dummy implementation for now. */
+
+ .globl _UI_siglongjmp_cont
+ .globl _UI_longjmp_cont
+
+_UI_siglongjmp_cont:
+_UI_longjmp_cont:
+ rts
diff --git a/src/sh/unwind_i.h b/src/sh/unwind_i.h
new file mode 100644
index 00000000..5de0bea7
--- /dev/null
+++ b/src/sh/unwind_i.h
@@ -0,0 +1,40 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
+
+This file is part of libunwind.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#ifndef unwind_i_h
+#define unwind_i_h
+
+#include <libunwind-sh.h>
+
+#include "libunwind_i.h"
+
+#define sh_lock UNW_OBJ(lock)
+#define sh_local_resume UNW_OBJ(local_resume)
+#define sh_local_addr_space_init UNW_OBJ(local_addr_space_init)
+
+extern void sh_local_addr_space_init (void);
+extern int sh_local_resume (unw_addr_space_t as, unw_cursor_t *cursor,
+ void *arg);
+
+#endif /* unwind_i_h */