72a4782084cf759a2ef3c75873926a526b4a2a74
[coreboot.git] / src / include / cpu / x86 / smm.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20
21 typedef uint64_t u64;
22
23 /* AMD64 SMM State-Save Area 
24  * starts @ 0x7e00
25  */
26 typedef struct {
27         u16     es_selector;
28         u16     es_attributes;
29         u32     es_limit;
30         u64     es_base;
31
32         u16     cs_selector;
33         u16     cs_attributcs;
34         u32     cs_limit;
35         u64     cs_base;
36
37         u16     ss_selector;
38         u16     ss_attributss;
39         u32     ss_limit;
40         u64     ss_base;
41
42         u16     ds_selector;
43         u16     ds_attributds;
44         u32     ds_limit;
45         u64     ds_base;
46
47         u16     fs_selector;
48         u16     fs_attributfs;
49         u32     fs_limit;
50         u64     fs_base;
51
52         u16     gs_selector;
53         u16     gs_attributgs;
54         u32     gs_limit;
55         u64     gs_base;
56
57         u8      reserved0[4];
58         u16     gdtr_limit;
59         u8      reserved1[2];
60         u64     gdtr_base;
61
62         u16     ldtr_selector;
63         u16     ldtr_attributes;
64         u32     ldtr_limit;
65         u64     ldtr_base;
66
67         u8      reserved2[4];
68         u16     idtr_limit;
69         u8      reserved3[2];
70         u64     idtr_base;
71
72         u16     tr_selector;
73         u16     tr_attributes;
74         u32     tr_limit;
75         u64     tr_base;
76
77         u8      reserved4[40];
78
79         u8      io_restart;
80         u8      autohalt_restart;
81
82         u8      reserved5[6];
83
84         u64     efer;
85
86         u8      reserved6[36];
87
88         u32     smm_revision;
89         u32     smbase;
90
91         u8      reserved7[68];
92
93         u64     cr4;
94         u64     cr3;
95         u64     cr0;
96         u64     dr7;
97         u64     dr6;
98
99         u64     rflags;
100         u64     rip;
101         u64     r15;
102         u64     r14;
103         u64     r13;
104         u64     r12;
105         u64     r11;
106         u64     r10;
107         u64     r9;
108         u64     r8;
109
110         u64     rdi;
111         u64     rsi;
112         u64     rpb;
113         u64     rsp;
114         u64     rbx;
115         u64     rdx;
116         u64     rcx;
117         u64     rax;
118 } __attribute__((packed)) amd64_smm_state_save_area_t;
119
120
121 /* Intel Core 2 (EM64T) SMM State-Save Area 
122  * starts @ 0x7d00
123  */
124 typedef struct {
125         u8      reserved0[208];
126
127         u32     gdtr_upper_base;
128         u32     ldtr_upper_base;
129         u32     idtr_upper_base;
130
131         u8      reserved1[4];
132
133         u64     io_rdi;
134         u64     io_rip;
135         u64     io_rcx;
136         u64     io_rsi;
137         u64     cr4;
138
139         u8      reserved2[68];
140
141         u64     gdtr_base;
142         u64     idtr_base;
143         u64     ldtr_base;
144
145         u8      reserved3[84];
146
147         u32     smm_revision;
148         u32     smbase;
149
150         u16     io_restart;
151         u16     autohalt_restart;
152
153         u8      reserved4[24];
154
155         u64     r15;
156         u64     r14;
157         u64     r13;
158         u64     r12;
159         u64     r11;
160         u64     r10;
161         u64     r9;
162         u64     r8;
163
164         u64     rax;
165         u64     rcx;
166         u64     rdx;
167         u64     rbx;
168
169         u64     rsp;
170         u64     rbp;
171         u64     rsi;
172         u64     rdi;
173
174
175         u64     io_mem_addr;
176         u32     io_misc_info;
177
178         u32     es_sel;
179         u32     cs_sel;
180         u32     ss_sel;
181         u32     ds_sel;
182         u32     fs_sel;
183         u32     gs_sel;
184
185         u32     ldtr_sel;
186         u32     tr_sel;
187
188         u64     dr7;
189         u64     dr6;
190         u64     rip;
191         u64     efer;
192         u64     rflags;
193
194         u64     cr3;
195         u64     cr0;
196 } __attribute__((packed)) em64t_smm_state_save_area_t;
197
198
199 /* Legacy x86 SMM State-Save Area 
200  * starts @ 0x7e00
201  */
202
203 typedef struct {
204         u8      reserved0[248];
205         u32     smbase;
206         u32     smm_revision;
207         u16     io_restart;
208         u16     autohalt_restart;
209         u8      reserved1[132];
210         u32     gdtbase;
211         u8      reserved2[8];
212         u32     idtbase;
213         u8      reserved3[16];
214         u32     es;
215         u32     cs;
216         u32     ss;
217         u32     ds;
218         u32     fs;
219         u32     gs;
220         u32     ldtbase;
221         u32     tr;
222         u32     dr7;
223         u32     dr6;
224         u32     eax;
225         u32     ecx;
226         u32     edx;
227         u32     ebx;
228         u32     esp;
229         u32     ebp;
230         u32     esi;
231         u32     edi;
232         u32     eip;
233         u32     eflags;
234         u32     cr3;
235         u32     cr0;
236 } __attribute__((packed)) legacy_smm_state_save_area_t;
237
238 typedef enum {
239         AMD64,
240         EM64T,
241         LEGACY
242 } save_state_type_t;
243
244
245 typedef struct {
246         save_state_type_t type;
247         union {
248         amd64_smm_state_save_area_t *amd64_state_save;
249         em64t_smm_state_save_area_t *em64t_state_save;
250         legacy_smm_state_save_area_t *legacy_state_save;
251         };
252 } smm_state_save_area_t;
253