]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libc_backends/lib/sig/lib/ARCH-amd64/arch.h
update
[l4.git] / l4 / pkg / libc_backends / lib / sig / lib / ARCH-amd64 / arch.h
1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  * This file is part of TUD:OS and distributed under the terms of the
5  * GNU Lesser General Public License 2.1.
6  * Please see the COPYING-LGPL-2.1 file for details.
7  */
8 #pragma once
9
10 #include <ucontext.h>
11 #include <sys/ucontext.h>
12 #include <stdio.h>
13
14 static inline
15 void fill_ucontext_frame(ucontext_t *ucf, l4_exc_regs_t *ue)
16 {
17   ucf->uc_mcontext.gregs[REG_R15]    = ue->r15;
18   ucf->uc_mcontext.gregs[REG_R14]    = ue->r14;
19   ucf->uc_mcontext.gregs[REG_R13]    = ue->r13;
20   ucf->uc_mcontext.gregs[REG_R12]    = ue->r12;
21   ucf->uc_mcontext.gregs[REG_R11]    = ue->r11;
22   ucf->uc_mcontext.gregs[REG_R10]    = ue->r10;
23   ucf->uc_mcontext.gregs[REG_R9]     = ue->r9;
24   ucf->uc_mcontext.gregs[REG_R8]     = ue->r8;
25   ucf->uc_mcontext.gregs[REG_RDI]    = ue->rdi;
26   ucf->uc_mcontext.gregs[REG_RSI]    = ue->rsi;
27   ucf->uc_mcontext.gregs[REG_RBP]    = ue->rbp;
28   ucf->uc_mcontext.gregs[REG_RBX]    = ue->rbx;
29   ucf->uc_mcontext.gregs[REG_RDX]    = ue->rdx;
30   ucf->uc_mcontext.gregs[REG_RCX]    = ue->rcx;
31   ucf->uc_mcontext.gregs[REG_RAX]    = ue->rax;
32
33   ucf->uc_mcontext.gregs[REG_TRAPNO] = ue->trapno;
34   ucf->uc_mcontext.gregs[REG_ERR]    = ue->err;
35   ucf->uc_mcontext.gregs[REG_CR2]    = ue->pfa;
36
37   ucf->uc_mcontext.gregs[REG_RIP]    = ue->ip;
38   ucf->uc_mcontext.gregs[REG_EFL]    = ue->flags;
39   ucf->uc_mcontext.gregs[REG_RSP]    = ue->sp;
40 }
41
42 static inline
43 void fill_utcb_exc(l4_exc_regs_t *ue, ucontext_t *ucf)
44 {
45   ue->r15    = ucf->uc_mcontext.gregs[REG_R15];
46   ue->r14    = ucf->uc_mcontext.gregs[REG_R14];
47   ue->r13    = ucf->uc_mcontext.gregs[REG_R13];
48   ue->r12    = ucf->uc_mcontext.gregs[REG_R12];
49   ue->r11    = ucf->uc_mcontext.gregs[REG_R11];
50   ue->r10    = ucf->uc_mcontext.gregs[REG_R10];
51   ue->r9     = ucf->uc_mcontext.gregs[REG_R9];
52   ue->r8     = ucf->uc_mcontext.gregs[REG_R8];
53   ue->rdi    = ucf->uc_mcontext.gregs[REG_RDI];
54   ue->rsi    = ucf->uc_mcontext.gregs[REG_RSI];
55   ue->rbp    = ucf->uc_mcontext.gregs[REG_RBP];
56   ue->rbx    = ucf->uc_mcontext.gregs[REG_RBX];
57   ue->rdx    = ucf->uc_mcontext.gregs[REG_RDX];
58   ue->rcx    = ucf->uc_mcontext.gregs[REG_RCX];
59   ue->rax    = ucf->uc_mcontext.gregs[REG_RAX];
60
61   ue->trapno = ucf->uc_mcontext.gregs[REG_TRAPNO];
62   ue->err    = ucf->uc_mcontext.gregs[REG_ERR];
63
64   ue->sp     = ucf->uc_mcontext.gregs[REG_RSP];
65   ue->ip     = ucf->uc_mcontext.gregs[REG_RIP];
66   ue->flags  = ucf->uc_mcontext.gregs[REG_EFL];
67 }
68
69 static inline
70 void show_regs(l4_exc_regs_t *u)
71 {
72   printf("Exception: State:  Trap=%ld\n", u->trapno);
73   printf("Want more? Code it...\n");
74 }