]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-amd64/utcb.h
912bfa2b4bd87bba534fa750a477ed05b60c4b72
[l4.git] / l4 / pkg / l4sys / include / ARCH-amd64 / utcb.h
1 /**
2  * \file
3  * \brief   UTCB definitions for amd64.
4  * \ingroup l4_utcb_api
5  */
6 /*
7  * (c) 2008-2009 Technische Universität Dresden
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  *
12  * As a special exception, you may use this file as part of a free software
13  * library without restriction.  Specifically, if other files instantiate
14  * templates or use macros or inline functions from this file, or you compile
15  * this file and link it with other files to produce an executable, this
16  * file does not by itself cause the resulting executable to be covered by
17  * the GNU General Public License.  This exception does not however
18  * invalidate any other reasons why the executable file might be covered by
19  * the GNU General Public License.
20  */
21 /*****************************************************************************/
22 #ifndef __L4_SYS__INCLUDE__ARCH_AMD64__UTCB_H__
23 #define __L4_SYS__INCLUDE__ARCH_AMD64__UTCB_H__
24
25 #include <l4/sys/types.h>
26
27 /**
28  * \defgroup l4_utcb_api_amd64 amd64 Virtual Registers (UTCB)
29  * \ingroup  l4_utcb_api
30  */
31
32 /**
33  * \brief UTCB constants for AMD64
34  * \ingroup l4_utcb_api_amd64
35  */
36 enum L4_utcb_consts_amd64
37 {
38   L4_UTCB_EXCEPTION_REGS_SIZE    = 23,
39   L4_UTCB_GENERIC_DATA_SIZE      = 63,
40   L4_UTCB_GENERIC_BUFFERS_SIZE   = 58,
41
42   L4_UTCB_MSG_REGS_OFFSET        = 0,
43   L4_UTCB_BUF_REGS_OFFSET        = 64 * sizeof(l4_umword_t),
44   L4_UTCB_THREAD_REGS_OFFSET     = 123 * sizeof(l4_umword_t),
45
46   L4_UTCB_INHERIT_FPU            = 1UL << 24,
47   L4_UTCB_OFFSET                 = 1024,
48 };
49
50 /**
51  * \brief UTCB structure for exceptions.
52  * \ingroup l4_utcb_api_amd64
53  */
54 typedef struct l4_exc_regs_t
55 {
56   l4_umword_t r15;        /**< r15 */
57   l4_umword_t r14;        /**< r14 */
58   l4_umword_t r13;        /**< r13 */
59   l4_umword_t r12;        /**< r12 */
60   l4_umword_t r11;        /**< r11 */
61   l4_umword_t r10;        /**< r10 */
62   l4_umword_t r9;         /**< r9 */
63   l4_umword_t r8;         /**< r8 */
64   l4_umword_t rdi;        /**< rdi */
65   l4_umword_t rsi;        /**< rsi */
66   l4_umword_t rbp;        /**< rbp */
67   l4_umword_t pfa;        /**< page fault address */
68   l4_umword_t rbx;        /**< rbx */
69   l4_umword_t rdx;        /**< rdx */
70   l4_umword_t rcx;        /**< rcx */
71   l4_umword_t rax;        /**< rax */
72
73   l4_umword_t trapno;     /**< trap number */
74   l4_umword_t err;        /**< error code */
75   l4_umword_t ip;         /**< instruction pointer */
76   l4_umword_t dummy1;
77   l4_umword_t flags;      /**< rflags */
78   l4_umword_t sp;         /**< stack pointer */
79   l4_umword_t ss;         /**< stack segment register */
80 } l4_exc_regs_t;
81
82
83 #include_next <l4/sys/utcb.h>
84
85 /*
86  * ==================================================================
87  * Implementations.
88  */
89
90 L4_INLINE l4_utcb_t *l4_utcb_direct(void) L4_NOTHROW
91 {
92   l4_utcb_t *res;
93   __asm__ __volatile__ ( "mov %%gs:0xffffffffeacfd000, %0 \n" : "=r"(res));
94   return res;
95 }
96
97 L4_INLINE l4_umword_t l4_utcb_exc_pc(l4_exc_regs_t *u) L4_NOTHROW
98 {
99   return u->ip;
100 }
101
102 L4_INLINE void l4_utcb_exc_pc_set(l4_exc_regs_t *u, l4_addr_t pc) L4_NOTHROW
103 {
104   u->ip = pc;
105 }
106
107 L4_INLINE l4_umword_t l4_utcb_exc_typeval(l4_exc_regs_t *u) L4_NOTHROW
108 {
109   return u->trapno;
110 }
111
112 L4_INLINE int l4_utcb_exc_is_pf(l4_exc_regs_t *u) L4_NOTHROW
113 {
114   return u->trapno == 14;
115 }
116
117 L4_INLINE l4_addr_t l4_utcb_exc_pfa(l4_exc_regs_t *u) L4_NOTHROW
118 {
119   return (u->pfa & ~3) | (u->err & 2);
120 }
121
122 #endif /* ! __L4_SYS__INCLUDE__ARCH_AMD64__UTCB_H__ */