1 /**
2  * \file
3  * \brief   UTCB definitions for PPC32.
4  * \ingroup l4_utcb_api
5  */
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
8  *     economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction.  Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License.  This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #ifndef __L4_SYS__INCLUDE__ARCH_PPC32__UTCB_H__
24 #define __L4_SYS__INCLUDE__ARCH_PPC32__UTCB_H__
25 
26 #include <l4/sys/types.h>
27 
28 /**
29  * \defgroup l4_utcb_api_arm PPC32 Virtual Registers (UTCB)
30  * \ingroup  l4_utcb_api
31  */
32 
33 /**
34  * \brief UTCB constants for PPC32
35  * \ingroup l4_utcb_api_arm
36  * \hideinitializer
37  */
38 enum L4_utcb_consts_ppc32
39 {
40   L4_UTCB_EXCEPTION_REGS_SIZE    = 39,
41   L4_UTCB_GENERIC_DATA_SIZE      = 63,
42   L4_UTCB_GENERIC_BUFFERS_SIZE   = 58,
43 
44   L4_UTCB_MSG_REGS_OFFSET        = 0,
45   L4_UTCB_BUF_REGS_OFFSET        = 64 * sizeof(l4_umword_t),
46   L4_UTCB_THREAD_REGS_OFFSET     = 123 * sizeof(l4_umword_t),
47 
48   L4_UTCB_INHERIT_FPU            = 1UL << 24,
49 
50   L4_UTCB_OFFSET                 = 512,
51 };
52 
53 /**
54  * \brief UTCB structure for exceptions.
55  * \ingroup l4_utcb_api_arm
56  */
57 typedef struct l4_exc_regs_t
58 {
59   l4_umword_t pfa;     /**< page fault address */
60   l4_umword_t err;     /**< error code */
61 
62   l4_umword_t r[28];   /** GPR 0,3 .. 10, 13 .. 31 */
63   l4_umword_t xer;     /**< fixed point exception register */
64   l4_umword_t ctr;     /**< count register */
65   l4_umword_t cr;      /**< condition register */
66   l4_umword_t dummy;   /**< dummy */
67   l4_umword_t srr0;    /**< IP */
68   l4_umword_t lr;      /**< ulr */
69   l4_umword_t sp;      /**< stack pointer */
70   l4_umword_t r12;     /**< GPR 12 */
71   l4_umword_t r11;     /**< GPR 11 */
72 } l4_exc_regs_t;
73 
74 #include_next <l4/sys/utcb.h>
75 
76 /*
77  * ==================================================================
78  * Implementations.
79  */
80 
81 #ifdef __GNUC__
l4_utcb_direct(void)82 L4_INLINE l4_utcb_t *l4_utcb_direct(void) L4_NOTHROW
83 {
84   l4_utcb_t *utcb;
85 
86   __asm__
87   ("mr %[utcb], %%r2\n"
88    : [utcb] "=r" (utcb)
89    : );
90 
91   return utcb;
92 }
93 #endif
94 
l4_utcb_exc_pc(l4_exc_regs_t const * u)95 L4_INLINE l4_umword_t l4_utcb_exc_pc(l4_exc_regs_t const *u) L4_NOTHROW
96 {
97   return u->srr0;
98 }
99 
l4_utcb_exc_pc_set(l4_exc_regs_t * u,l4_addr_t pc)100 L4_INLINE void l4_utcb_exc_pc_set(l4_exc_regs_t *u, l4_addr_t pc) L4_NOTHROW
101 {
102   u->srr0 = pc;
103 }
104 
l4_utcb_exc_typeval(l4_exc_regs_t const * u)105 L4_INLINE l4_umword_t l4_utcb_exc_typeval(l4_exc_regs_t const *u) L4_NOTHROW
106 {
107   return u->err;
108 }
109 
110 //TODO: cbass check pfa values
l4_utcb_exc_is_pf(l4_exc_regs_t const * u)111 L4_INLINE int l4_utcb_exc_is_pf(l4_exc_regs_t const *u) L4_NOTHROW
112 {
113   return u->err & 0x00010000;
114 }
115 
l4_utcb_exc_pfa(l4_exc_regs_t const * u)116 L4_INLINE l4_addr_t l4_utcb_exc_pfa(l4_exc_regs_t const *u) L4_NOTHROW
117 {
118   return (u->pfa & ~7UL) | (!(u->err & 0x00020000) << 1);
119 }
120 
l4_utcb_exc_is_ex_regs_exception(l4_exc_regs_t const * u)121 L4_INLINE int l4_utcb_exc_is_ex_regs_exception(l4_exc_regs_t const *u) L4_NOTHROW
122 {
123   // ex_regs trigger exception not implemented.
124   (void)u;
125   return 0;
126 }
127 
128 #endif /* ! __L4_SYS__INCLUDE__ARCH_PPC32__UTCB_H__ */
129