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