x86 userspace uses software contexts (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 struct hw_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 };
45
46 struct sw_trapframe {
47         uint32_t tf_ebp;
48         uint32_t tf_ebx;
49         uint32_t tf_esi;
50         uint32_t tf_edi;
51         uint32_t tf_esp;
52         uint32_t tf_eip;
53         uint32_t tf_mxcsr;
54         uint16_t tf_fpucw;
55         uint16_t tf_gs;         /* something to track TLS is callee-saved (sort of) */
56 };
57
58 /* FP state and whatever else the kernel won't muck with automatically.  For
59  * now, it's the Non-64-bit-mode layout of FP and XMM registers, as used by
60  * FXSAVE and FXRSTOR.  Other modes will require a union on a couple entries.
61  * See SDM 2a 3-451. */
62 /* Header for the non-64-bit mode FXSAVE map */
63 struct fp_header_non_64bit {
64         uint16_t                fcw;
65         uint16_t                fsw;
66         uint8_t                 ftw;
67         uint8_t                 padding0;
68         uint16_t                fop;
69         uint32_t                fpu_ip;
70         uint16_t                cs;
71         uint16_t                padding1;
72         uint32_t                fpu_dp;
73         uint16_t                ds;
74         uint16_t                padding2;
75         uint32_t                mxcsr;
76         uint32_t                mxcsr_mask;
77 };
78
79 /* Header for the 64-bit mode FXSAVE map with promoted operand size */
80 struct fp_header_64bit_promoted {
81         uint16_t                fcw;
82         uint16_t                fsw;
83         uint8_t                 ftw;
84         uint8_t                 padding0;
85         uint16_t                fop;
86         uint64_t                fpu_ip;
87         uint64_t                fpu_dp;
88         uint32_t                mxcsr;
89         uint32_t                mxcsr_mask;
90 };
91
92 /* Header for the 64-bit mode FXSAVE map with default operand size */
93 struct fp_header_64bit_default {
94         uint16_t                fcw;
95         uint16_t                fsw;
96         uint8_t                 ftw;
97         uint8_t                 padding0;
98         uint16_t                fop;
99         uint32_t                fpu_ip;
100         uint16_t                cs;
101         uint16_t                padding1;
102         uint32_t                fpu_dp;
103         uint16_t                ds;
104         uint16_t                padding2;
105         uint32_t                mxcsr;
106         uint32_t                mxcsr_mask;
107 };
108
109 /* Just for storage space, not for real use     */
110 typedef struct {
111         unsigned int stor[4];
112 } __uint128_t;
113
114 typedef struct ancillary_state {
115         union { /* whichever header used depends on the mode */
116                 struct fp_header_non_64bit                      fp_head_n64;
117                 struct fp_header_64bit_promoted         fp_head_64p;
118                 struct fp_header_64bit_default          fp_head_64d;
119         };
120         __uint128_t             st0_mm0;        /* 128 bits: 80 for the st0, 48 rsv */
121         __uint128_t             st1_mm1;
122         __uint128_t             st2_mm2;
123         __uint128_t             st3_mm3;
124         __uint128_t             st4_mm4;
125         __uint128_t             st5_mm5;
126         __uint128_t             st6_mm6;
127         __uint128_t             st7_mm7;
128         __uint128_t             xmm0;
129         __uint128_t             xmm1;
130         __uint128_t             xmm2;
131         __uint128_t             xmm3;
132         __uint128_t             xmm4;
133         __uint128_t             xmm5;
134         __uint128_t             xmm6;
135         __uint128_t             xmm7;
136         __uint128_t             xmm8;           /* xmm8 and below only for 64-bit-mode */
137         __uint128_t             xmm9;
138         __uint128_t             xmm10;
139         __uint128_t             xmm11;
140         __uint128_t             xmm12;
141         __uint128_t             xmm13;
142         __uint128_t             xmm14;
143         __uint128_t             xmm15;
144         __uint128_t             reserv0;
145         __uint128_t             reserv1;
146         __uint128_t             reserv2;
147         __uint128_t             reserv3;
148         __uint128_t             reserv4;
149         __uint128_t             reserv5;
150 } __attribute__((aligned(16))) ancillary_state_t;
151
152 #endif /* ROS_INC_ARCH_TRAPFRAME_H */