kvm_sys/
x86_64.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12use libc::{c_void, calloc, free};
13use std::{mem, slice};
14use std::ops::{Deref, DerefMut};
15
16#[repr(C)]
17#[derive(Copy, Debug)]
18pub struct PicState {
19    pub last_irr: u8,
20    pub irr: u8,
21    pub imr: u8,
22    pub isr: u8,
23    pub priority_add: u8,
24    pub irq_base: u8,
25    pub read_reg_select: u8,
26    pub poll: u8,
27    pub special_mask: u8,
28    pub init_state: u8,
29    pub auto_eoi: u8,
30    pub rotate_on_auto_eoi: u8,
31    pub special_fully_nested_mode: u8,
32    pub init4: u8,
33    pub elcr: u8,
34    pub elcr_mask: u8,
35}
36impl ::std::clone::Clone for PicState {
37    fn clone(&self) -> Self {
38        *self
39    }
40}
41impl ::std::default::Default for PicState {
42    fn default() -> Self {
43        unsafe { ::std::mem::zeroed() }
44    }
45}
46#[repr(C)]
47#[derive(Copy)]
48pub struct IoapicState {
49    pub base_address: u64,
50    pub ioregsel: u32,
51    pub id: u32,
52    pub irr: u32,
53    pub pad: u32,
54    pub redirtbl: [Union_Unnamed3; 24usize],
55}
56impl ::std::clone::Clone for IoapicState {
57    fn clone(&self) -> Self {
58        *self
59    }
60}
61impl ::std::default::Default for IoapicState {
62    fn default() -> Self {
63        unsafe { ::std::mem::zeroed() }
64    }
65}
66#[repr(C)]
67#[derive(Copy)]
68pub struct Union_Unnamed3 {
69    pub _bindgen_data_: [u64; 1usize],
70}
71impl Union_Unnamed3 {
72    pub unsafe fn bits(&mut self) -> *mut u64 {
73        let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
74        ::std::mem::transmute(raw.offset(0))
75    }
76    pub unsafe fn fields(&mut self) -> *mut Struct_Unnamed4 {
77        let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
78        ::std::mem::transmute(raw.offset(0))
79    }
80}
81impl ::std::clone::Clone for Union_Unnamed3 {
82    fn clone(&self) -> Self {
83        *self
84    }
85}
86impl ::std::default::Default for Union_Unnamed3 {
87    fn default() -> Self {
88        unsafe { ::std::mem::zeroed() }
89    }
90}
91#[repr(C)]
92#[derive(Copy)]
93pub struct Struct_Unnamed4 {
94    pub vector: u8,
95    pub _bindgen_bitfield_1_: u8,
96    pub _bindgen_bitfield_2_: u8,
97    pub _bindgen_bitfield_3_: u8,
98    pub _bindgen_bitfield_4_: u8,
99    pub _bindgen_bitfield_5_: u8,
100    pub _bindgen_bitfield_6_: u8,
101    pub _bindgen_bitfield_7_: u8,
102    pub _bindgen_bitfield_8_: u8,
103    pub reserved: [u8; 4usize],
104    pub dest_id: u8,
105}
106impl ::std::clone::Clone for Struct_Unnamed4 {
107    fn clone(&self) -> Self {
108        *self
109    }
110}
111impl ::std::default::Default for Struct_Unnamed4 {
112    fn default() -> Self {
113        unsafe { ::std::mem::zeroed() }
114    }
115}
116#[repr(C)]
117#[derive(Copy)]
118pub struct Regs {
119    pub rax: u64,
120    pub rbx: u64,
121    pub rcx: u64,
122    pub rdx: u64,
123    pub rsi: u64,
124    pub rdi: u64,
125    pub rsp: u64,
126    pub rbp: u64,
127    pub r8: u64,
128    pub r9: u64,
129    pub r10: u64,
130    pub r11: u64,
131    pub r12: u64,
132    pub r13: u64,
133    pub r14: u64,
134    pub r15: u64,
135    pub rip: u64,
136    pub rflags: u64,
137}
138impl ::std::clone::Clone for Regs {
139    fn clone(&self) -> Self {
140        *self
141    }
142}
143impl ::std::default::Default for Regs {
144    fn default() -> Self {
145        unsafe { ::std::mem::zeroed() }
146    }
147}
148#[repr(C)]
149#[derive(Copy)]
150pub struct LapicState {
151    pub regs: [::libc::c_char; 1024usize],
152}
153impl ::std::clone::Clone for LapicState {
154    fn clone(&self) -> Self {
155        *self
156    }
157}
158impl ::std::default::Default for LapicState {
159    fn default() -> Self {
160        unsafe { ::std::mem::zeroed() }
161    }
162}
163#[repr(C)]
164#[derive(Copy, Debug)]
165pub struct Segment {
166    pub base: u64,
167    pub limit: u32,
168    pub selector: u16,
169    pub _type: u8,
170    pub present: u8,
171    pub dpl: u8,
172    pub db: u8,
173    pub s: u8,
174    pub l: u8,
175    pub g: u8,
176    pub avl: u8,
177    pub unusable: u8,
178    pub padding: u8,
179}
180impl ::std::clone::Clone for Segment {
181    fn clone(&self) -> Self {
182        *self
183    }
184}
185impl ::std::default::Default for Segment {
186    fn default() -> Self {
187        unsafe { ::std::mem::zeroed() }
188    }
189}
190#[repr(C)]
191#[derive(Copy, Debug)]
192pub struct Dtable {
193    pub base: u64,
194    pub limit: u16,
195    pub padding: [u16; 3usize],
196}
197impl ::std::clone::Clone for Dtable {
198    fn clone(&self) -> Self {
199        *self
200    }
201}
202impl ::std::default::Default for Dtable {
203    fn default() -> Self {
204        unsafe { ::std::mem::zeroed() }
205    }
206}
207#[repr(C)]
208#[derive(Copy, Debug)]
209pub struct Sregs {
210    pub cs: Segment,
211    pub ds: Segment,
212    pub es: Segment,
213    pub fs: Segment,
214    pub gs: Segment,
215    pub ss: Segment,
216    pub tr: Segment,
217    pub ldt: Segment,
218    pub gdt: Dtable,
219    pub idt: Dtable,
220    pub cr0: u64,
221    pub cr2: u64,
222    pub cr3: u64,
223    pub cr4: u64,
224    pub cr8: u64,
225    pub efer: u64,
226    pub apic_base: u64,
227    pub interrupt_bitmap: [u64; 4usize],
228}
229impl ::std::clone::Clone for Sregs {
230    fn clone(&self) -> Self {
231        *self
232    }
233}
234impl ::std::default::Default for Sregs {
235    fn default() -> Self {
236        unsafe { ::std::mem::zeroed() }
237    }
238}
239#[repr(C)]
240#[derive(Copy)]
241pub struct Fpu {
242    pub fpr: [[u8; 16usize]; 8usize],
243    pub fcw: u16,
244    pub fsw: u16,
245    pub ftwx: u8,
246    pub pad1: u8,
247    pub last_opcode: u16,
248    pub last_ip: u64,
249    pub last_dp: u64,
250    pub xmm: [[u8; 16usize]; 16usize],
251    pub mxcsr: u32,
252    pub pad2: u32,
253}
254impl ::std::clone::Clone for Fpu {
255    fn clone(&self) -> Self {
256        *self
257    }
258}
259impl ::std::default::Default for Fpu {
260    fn default() -> Self {
261        unsafe { ::std::mem::zeroed() }
262    }
263}
264#[repr(C)]
265#[derive(Copy)]
266pub struct MsrEntry {
267    pub index: u32,
268    pub reserved: u32,
269    pub data: u64,
270}
271impl ::std::clone::Clone for MsrEntry {
272    fn clone(&self) -> Self {
273        *self
274    }
275}
276impl ::std::default::Default for MsrEntry {
277    fn default() -> Self {
278        unsafe { ::std::mem::zeroed() }
279    }
280}
281#[repr(C)]
282#[derive(Copy)]
283pub struct Msrs {
284    pub nmsrs: u32,
285    pub pad: u32,
286    pub entries: [MsrEntry; 0usize],
287}
288impl ::std::clone::Clone for Msrs {
289    fn clone(&self) -> Self {
290        *self
291    }
292}
293impl ::std::default::Default for Msrs {
294    fn default() -> Self {
295        unsafe { ::std::mem::zeroed() }
296    }
297}
298#[repr(C)]
299#[derive(Copy)]
300pub struct MsrList {
301    pub nmsrs: u32,
302    pub indices: [u32; 0usize],
303}
304impl ::std::clone::Clone for MsrList {
305    fn clone(&self) -> Self {
306        *self
307    }
308}
309impl ::std::default::Default for MsrList {
310    fn default() -> Self {
311        unsafe { ::std::mem::zeroed() }
312    }
313}
314#[repr(C)]
315#[derive(Copy)]
316pub struct CpuidEntry {
317    pub function: u32,
318    pub eax: u32,
319    pub ebx: u32,
320    pub ecx: u32,
321    pub edx: u32,
322    pub padding: u32,
323}
324impl ::std::clone::Clone for CpuidEntry {
325    fn clone(&self) -> Self {
326        *self
327    }
328}
329impl ::std::default::Default for CpuidEntry {
330    fn default() -> Self {
331        unsafe { ::std::mem::zeroed() }
332    }
333}
334#[repr(C)]
335#[derive(Copy)]
336pub struct Cpuid {
337    pub nent: u32,
338    pub padding: u32,
339    pub entries: [CpuidEntry; 0usize],
340}
341impl ::std::clone::Clone for Cpuid {
342    fn clone(&self) -> Self {
343        *self
344    }
345}
346impl ::std::default::Default for Cpuid {
347    fn default() -> Self {
348        unsafe { ::std::mem::zeroed() }
349    }
350}
351#[repr(C)]
352#[derive(Copy)]
353pub struct CpuidEntry2 {
354    pub function: u32,
355    pub index: u32,
356    pub flags: u32,
357    pub eax: u32,
358    pub ebx: u32,
359    pub ecx: u32,
360    pub edx: u32,
361    pub padding: [u32; 3usize],
362}
363impl ::std::clone::Clone for CpuidEntry2 {
364    fn clone(&self) -> Self {
365        *self
366    }
367}
368impl ::std::default::Default for CpuidEntry2 {
369    fn default() -> Self {
370        unsafe { ::std::mem::zeroed() }
371    }
372}
373
374#[allow(missing_copy_implementations)]
375#[repr(C)]
376pub struct Cpuid2 {
377    pub nent: u32,
378    padding: u32,
379}
380
381pub struct CpuidHandle {
382    cpuid: *mut Cpuid2,
383}
384
385impl CpuidHandle {
386    pub fn new(nent: u32) -> CpuidHandle {
387        unsafe {
388            let sz = mem::size_of::<Cpuid2>() +
389                     nent as usize * mem::size_of::<CpuidEntry2>();
390            let ptr = calloc(1, sz) as *mut Cpuid2;
391            assert!(!ptr.is_null());
392            (*ptr).nent = nent;
393            CpuidHandle { cpuid: ptr }
394        }
395    }
396}
397
398impl Deref for CpuidHandle {
399    type Target = Cpuid2;
400
401    fn deref(&self) -> &Cpuid2 {
402        unsafe { &*self.cpuid }
403    }
404}
405
406impl DerefMut for CpuidHandle {
407    fn deref_mut(&mut self) -> &mut Cpuid2 {
408        unsafe { &mut *self.cpuid }
409    }
410}
411
412impl Drop for CpuidHandle {
413    fn drop(&mut self) {
414        unsafe {
415            free(self.cpuid as *mut c_void);
416        }
417    }
418}
419
420impl Cpuid2 {
421    pub fn entries(&self) -> &[CpuidEntry2] {
422        unsafe {
423            let begin: *const Cpuid2 = self;
424            let first_ent = (begin as *const u8)
425                                .offset(mem::size_of::<Cpuid2>() as isize);
426            slice::from_raw_parts(first_ent as *const _, self.nent as usize)
427        }
428    }
429    pub fn entries_mut(&mut self) -> &mut [CpuidEntry2] {
430        unsafe {
431            let begin: *mut Cpuid2 = self;
432            let first_ent = (begin as *mut u8)
433                                .offset(mem::size_of::<Cpuid2>() as isize);
434            slice::from_raw_parts_mut(first_ent as *mut _, self.nent as usize)
435        }
436    }
437}
438
439#[repr(C)]
440#[derive(Copy)]
441pub struct PitChannelState {
442    pub count: u32,
443    pub latched_count: u16,
444    pub count_latched: u8,
445    pub status_latched: u8,
446    pub status: u8,
447    pub read_state: u8,
448    pub write_state: u8,
449    pub write_latch: u8,
450    pub rw_mode: u8,
451    pub mode: u8,
452    pub bcd: u8,
453    pub gate: u8,
454    pub count_load_time: i64,
455}
456impl ::std::clone::Clone for PitChannelState {
457    fn clone(&self) -> Self {
458        *self
459    }
460}
461impl ::std::default::Default for PitChannelState {
462    fn default() -> Self {
463        unsafe { ::std::mem::zeroed() }
464    }
465}
466#[repr(C)]
467#[derive(Copy, Debug)]
468pub struct DebugExitArch {
469    pub exception: u32,
470    pub pad: u32,
471    pub pc: u64,
472    pub dr6: u64,
473    pub dr7: u64,
474}
475impl ::std::clone::Clone for DebugExitArch {
476    fn clone(&self) -> Self {
477        *self
478    }
479}
480impl ::std::default::Default for DebugExitArch {
481    fn default() -> Self {
482        unsafe { ::std::mem::zeroed() }
483    }
484}
485#[repr(C)]
486#[derive(Copy)]
487pub struct GuestDebugArch {
488    pub debugreg: [u64; 8usize],
489}
490impl ::std::clone::Clone for GuestDebugArch {
491    fn clone(&self) -> Self {
492        *self
493    }
494}
495impl ::std::default::Default for GuestDebugArch {
496    fn default() -> Self {
497        unsafe { ::std::mem::zeroed() }
498    }
499}
500#[repr(C)]
501#[derive(Copy)]
502pub struct PitState {
503    pub channels: [PitChannelState; 3usize],
504}
505impl ::std::clone::Clone for PitState {
506    fn clone(&self) -> Self {
507        *self
508    }
509}
510impl ::std::default::Default for PitState {
511    fn default() -> Self {
512        unsafe { ::std::mem::zeroed() }
513    }
514}
515#[repr(C)]
516#[derive(Copy)]
517pub struct PitState2 {
518    pub channels: [PitChannelState; 3usize],
519    pub flags: u32,
520    pub reserved: [u32; 9usize],
521}
522impl ::std::clone::Clone for PitState2 {
523    fn clone(&self) -> Self {
524        *self
525    }
526}
527impl ::std::default::Default for PitState2 {
528    fn default() -> Self {
529        unsafe { ::std::mem::zeroed() }
530    }
531}
532#[repr(C)]
533#[derive(Copy)]
534pub struct ReinjectControl {
535    pub pit_reinject: u8,
536    pub reserved: [u8; 31usize],
537}
538impl ::std::clone::Clone for ReinjectControl {
539    fn clone(&self) -> Self {
540        *self
541    }
542}
543impl ::std::default::Default for ReinjectControl {
544    fn default() -> Self {
545        unsafe { ::std::mem::zeroed() }
546    }
547}
548#[repr(C)]
549#[derive(Copy)]
550pub struct VcpuEvents {
551    pub exception: StructUnnamed5,
552    pub interrupt: StructUnnamed6,
553    pub nmi: StructUnnamed7,
554    pub sipi_vector: u32,
555    pub flags: u32,
556    pub reserved: [u32; 10usize],
557}
558impl ::std::clone::Clone for VcpuEvents {
559    fn clone(&self) -> Self {
560        *self
561    }
562}
563impl ::std::default::Default for VcpuEvents {
564    fn default() -> Self {
565        unsafe { ::std::mem::zeroed() }
566    }
567}
568#[repr(C)]
569#[derive(Copy)]
570pub struct StructUnnamed5 {
571    pub injected: u8,
572    pub nr: u8,
573    pub has_error_code: u8,
574    pub pad: u8,
575    pub error_code: u32,
576}
577impl ::std::clone::Clone for StructUnnamed5 {
578    fn clone(&self) -> Self {
579        *self
580    }
581}
582impl ::std::default::Default for StructUnnamed5 {
583    fn default() -> Self {
584        unsafe { ::std::mem::zeroed() }
585    }
586}
587#[repr(C)]
588#[derive(Copy)]
589pub struct StructUnnamed6 {
590    pub injected: u8,
591    pub nr: u8,
592    pub soft: u8,
593    pub shadow: u8,
594}
595impl ::std::clone::Clone for StructUnnamed6 {
596    fn clone(&self) -> Self {
597        *self
598    }
599}
600impl ::std::default::Default for StructUnnamed6 {
601    fn default() -> Self {
602        unsafe { ::std::mem::zeroed() }
603    }
604}
605#[repr(C)]
606#[derive(Copy)]
607pub struct StructUnnamed7 {
608    pub injected: u8,
609    pub pending: u8,
610    pub masked: u8,
611    pub pad: u8,
612}
613impl ::std::clone::Clone for StructUnnamed7 {
614    fn clone(&self) -> Self {
615        *self
616    }
617}
618impl ::std::default::Default for StructUnnamed7 {
619    fn default() -> Self {
620        unsafe { ::std::mem::zeroed() }
621    }
622}
623#[repr(C)]
624#[derive(Copy)]
625pub struct Debugregs {
626    pub db: [u64; 4usize],
627    pub dr6: u64,
628    pub dr7: u64,
629    pub flags: u64,
630    pub reserved: [u64; 9usize],
631}
632impl ::std::clone::Clone for Debugregs {
633    fn clone(&self) -> Self {
634        *self
635    }
636}
637impl ::std::default::Default for Debugregs {
638    fn default() -> Self {
639        unsafe { ::std::mem::zeroed() }
640    }
641}
642#[repr(C)]
643#[derive(Copy)]
644pub struct Xsave {
645    pub region: [u32; 1024usize],
646}
647impl ::std::clone::Clone for Xsave {
648    fn clone(&self) -> Self {
649        *self
650    }
651}
652impl ::std::default::Default for Xsave {
653    fn default() -> Self {
654        unsafe { ::std::mem::zeroed() }
655    }
656}
657#[repr(C)]
658#[derive(Copy)]
659pub struct Xcr {
660    pub xcr: u32,
661    pub reserved: u32,
662    pub value: u64,
663}
664impl ::std::clone::Clone for Xcr {
665    fn clone(&self) -> Self {
666        *self
667    }
668}
669impl ::std::default::Default for Xcr {
670    fn default() -> Self {
671        unsafe { ::std::mem::zeroed() }
672    }
673}
674#[repr(C)]
675#[derive(Copy)]
676pub struct Xcrs {
677    pub nr_xcrs: u32,
678    pub flags: u32,
679    pub xcrs: [Xcr; 16usize],
680    pub padding: [u64; 16usize],
681}
682impl ::std::clone::Clone for Xcrs {
683    fn clone(&self) -> Self {
684        *self
685    }
686}
687impl ::std::default::Default for Xcrs {
688    fn default() -> Self {
689        unsafe { ::std::mem::zeroed() }
690    }
691}
692#[repr(C)]
693#[derive(Copy)]
694pub struct SyncRegs;
695impl ::std::clone::Clone for SyncRegs {
696    fn clone(&self) -> Self {
697        *self
698    }
699}
700impl ::std::default::Default for SyncRegs {
701    fn default() -> Self {
702        unsafe { ::std::mem::zeroed() }
703    }
704}