Defines new struct user_context (XCC)
[akaros.git] / kern / arch / i686 / ros / trapframe.h
1 /*  Mostly from JOS.   See COPYRIGHT for copyright information. */
2
3 #ifndef ROS_INC_ARCH_TRAPFRAME_H
4 #define ROS_INC_ARCH_TRAPFRAME_H
5
6 #ifndef ROS_INC_TRAPFRAME_H
7 #error "Do not include include ros/arch/trapframe.h directly"
8 #endif
9
10 #include <ros/common.h>
11
12 typedef struct pushregs {
13         /* registers as pushed by pusha */
14         uint32_t reg_edi;
15         uint32_t reg_esi;
16         uint32_t reg_ebp; uint32_t reg_oesp;            /* Useless */
17         uint32_t reg_ebx;
18         uint32_t reg_edx;
19         uint32_t reg_ecx;
20         uint32_t reg_eax;
21 } push_regs_t;
22
23 typedef struct trapframe {
24         push_regs_t tf_regs;
25         uint16_t tf_gs;
26         uint16_t tf_padding1;
27         uint16_t tf_fs;
28         uint16_t tf_padding2;
29         uint16_t tf_es;
30         uint16_t tf_padding3;
31         uint16_t tf_ds;
32         uint16_t tf_padding4;
33         uint32_t tf_trapno;
34         /* below here defined by x86 hardware */
35         uint32_t tf_err;
36         uintptr_t tf_eip;
37         uint16_t tf_cs;
38         uint16_t tf_padding5;
39         uint32_t tf_eflags;
40         /* below here only when crossing rings, such as from user to kernel */
41         uintptr_t tf_esp;
42         uint16_t tf_ss;
43         uint16_t tf_padding6;
44 } trapframe_t;
45
46 /* Temporary aliasing */
47 #define hw_trapframe trapframe
48
49 struct sw_trapframe {
50         /* TODO */
51 };
52
53 /* TODO: consider using a user-space specific trapframe, since they don't need
54  * all of this information.  Might do that eventually, but til then: */
55 #define user_trapframe trapframe
56
57 /* FP state and whatever else the kernel won't muck with automatically.  For
58  * now, it's the Non-64-bit-mode layout of FP and XMM registers, as used by
59  * FXSAVE and FXRSTOR.  Other modes will require a union on a couple entries.
60  * See SDM 2a 3-451. */
61 /* Header for the non-64-bit mode FXSAVE map */
62 struct fp_header_non_64bit {
63         uint16_t                fcw;
64         uint16_t                fsw;
65         uint8_t                 ftw;
66         uint8_t                 padding0;
67         uint16_t                fop;
68         uint32_t                fpu_ip;
69         uint16_t                cs;
70         uint16_t                padding1;
71         uint32_t                fpu_dp;
72         uint16_t                ds;
73         uint16_t                padding2;
74         uint32_t                mxcsr;
75         uint32_t                mxcsr_mask;
76 };
77
78 /* Header for the 64-bit mode FXSAVE map with promoted operand size */
79 struct fp_header_64bit_promoted {
80         uint16_t                fcw;
81         uint16_t                fsw;
82         uint8_t                 ftw;
83         uint8_t                 padding0;
84         uint16_t                fop;
85         uint64_t                fpu_ip;
86         uint64_t                fpu_dp;
87         uint32_t                mxcsr;
88         uint32_t                mxcsr_mask;
89 };
90
91 /* Header for the 64-bit mode FXSAVE map with default operand size */
92 struct fp_header_64bit_default {
93         uint16_t                fcw;
94         uint16_t                fsw;
95         uint8_t                 ftw;
96         uint8_t                 padding0;
97         uint16_t                fop;
98         uint32_t                fpu_ip;
99         uint16_t                cs;
100         uint16_t                padding1;
101         uint32_t                fpu_dp;
102         uint16_t                ds;
103         uint16_t                padding2;
104         uint32_t                mxcsr;
105         uint32_t                mxcsr_mask;
106 };
107
108 /* Just for storage space, not for real use     */
109 typedef struct {
110         unsigned int stor[4];
111 } __uint128_t;
112
113 typedef struct ancillary_state {
114         union { /* whichever header used depends on the mode */
115                 struct fp_header_non_64bit                      fp_head_n64;
116                 struct fp_header_64bit_promoted         fp_head_64p;
117                 struct fp_header_64bit_default          fp_head_64d;
118         };
119         __uint128_t             st0_mm0;        /* 128 bits: 80 for the st0, 48 rsv */
120         __uint128_t             st1_mm1;
121         __uint128_t             st2_mm2;
122         __uint128_t             st3_mm3;
123         __uint128_t             st4_mm4;
124         __uint128_t             st5_mm5;
125         __uint128_t             st6_mm6;
126         __uint128_t             st7_mm7;
127         __uint128_t             xmm0;
128         __uint128_t             xmm1;
129         __uint128_t             xmm2;
130         __uint128_t             xmm3;
131         __uint128_t             xmm4;
132         __uint128_t             xmm5;
133         __uint128_t             xmm6;
134         __uint128_t             xmm7;
135         __uint128_t             xmm8;           /* xmm8 and below only for 64-bit-mode */
136         __uint128_t             xmm9;
137         __uint128_t             xmm10;
138         __uint128_t             xmm11;
139         __uint128_t             xmm12;
140         __uint128_t             xmm13;
141         __uint128_t             xmm14;
142         __uint128_t             xmm15;
143         __uint128_t             reserv0;
144         __uint128_t             reserv1;
145         __uint128_t             reserv2;
146         __uint128_t             reserv3;
147         __uint128_t             reserv4;
148         __uint128_t             reserv5;
149 } __attribute__((aligned(16))) ancillary_state_t;
150
151 #endif /* ROS_INC_ARCH_TRAPFRAME_H */