2 -- Copyright (C) 2013-2016 Reto Buerki <reet@codelabs.ch>
3 -- Copyright (C) 2013-2016 Adrian-Ken Rueegsegger <ken@codelabs.ch>
5 -- This program is free software: you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation, either version 3 of the License, or
8 -- (at your option) any later version.
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.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
22 --D Package providing access to low-level CPU instructions.
26 -- Clear Interrupt Flag.
29 Global => (In_Out => X86_64.State),
30 Depends => (X86_64.State =>+ null),
33 -- Execute CPUID instruction.
35 (EAX : in out SK.Word32;
37 ECX : in out SK.Word32;
40 Global => (Input => X86_64.State),
41 Depends => ((EAX, EBX, ECX, EDX) => (EAX, ECX, X86_64.State)),
47 Global => (In_Out => X86_64.State),
48 Depends => (X86_64.State =>+ null),
51 -- Set Interrupt Flag.
54 Global => (In_Out => X86_64.State),
55 Depends => (X86_64.State =>+ null),
58 -- Load Global Descriptor Table (GDT) register.
59 procedure Lgdt (Descriptor : Pseudo_Descriptor_Type)
61 Global => (In_Out => X86_64.State),
62 Depends => (X86_64.State =>+ Descriptor),
65 -- Load Interrupt Descriptor Table (IDT) register.
66 procedure Lidt (Descriptor : Pseudo_Descriptor_Type)
68 Global => (In_Out => X86_64.State),
69 Depends => (X86_64.State =>+ Descriptor),
72 -- Load Task Register (TR).
73 procedure Ltr (Address : SK.Word16)
75 Global => (In_Out => X86_64.State),
76 Depends => (X86_64.State =>+ Address),
85 -- RDTSC (Read Time-Stamp Counter).
86 function RDTSC return SK.Word64
88 Global => (Input => X86_64.State),
91 pragma Annotate (GNATprove, Terminating, RDTSC);
96 Global => (In_Out => X86_64.State),
97 Depends => (X86_64.State =>+ null),
101 -- Return current value of CR0 register.
102 function Get_CR0 return SK.Word64
104 Global => (Input => X86_64.State),
107 pragma Annotate (GNATprove, Terminating, Get_CR0);
109 -- Return current value of CR2 register.
110 function Get_CR2 return SK.Word64
112 Global => (Input => X86_64.State),
115 pragma Annotate (GNATprove, Terminating, Get_CR2);
117 -- Return current value of CR3 register.
118 function Get_CR3 return SK.Word64
120 Global => (Input => X86_64.State),
123 pragma Annotate (GNATprove, Terminating, Get_CR3);
125 -- Return current value of CR4 register.
126 function Get_CR4 return SK.Word64
128 Global => (Input => X86_64.State),
131 pragma Annotate (GNATprove, Terminating, Get_CR4);
134 procedure Set_CR2 (Value : SK.Word64)
136 Global => (In_Out => X86_64.State),
137 Depends => (X86_64.State =>+ Value),
141 procedure Set_CR4 (Value : SK.Word64)
143 Global => (In_Out => X86_64.State),
144 Depends => (X86_64.State =>+ Value),
147 -- Return current value of given model specific register.
148 function Get_MSR64 (Register : SK.Word32) return SK.Word64
150 Global => (Input => X86_64.State),
153 pragma Annotate (GNATprove, Terminating, Get_MSR64);
155 -- Return value of given MSR as low/high doublewords.
157 (Register : SK.Word32;
159 High : out SK.Word32)
161 Global => (Input => X86_64.State),
162 Depends => ((Low, High) => (X86_64.State, Register)),
165 -- Write specified quadword to given MSR.
166 procedure Write_MSR64
167 (Register : SK.Word32;
170 Global => (In_Out => X86_64.State),
171 Depends => (X86_64.State =>+ (Register, Value)),
174 -- Write specified low/high doublewords to given MSR.
176 (Register : SK.Word32;
180 Global => (In_Out => X86_64.State),
181 Depends => (X86_64.State =>+ (Register, Low, High)),
184 -- Return current RFLAGS.
185 function Get_RFLAGS return SK.Word64
187 Global => (Input => X86_64.State),
190 pragma Annotate (GNATprove, Terminating, Get_RFLAGS);
192 -- Restore specified Processor Extended States from given XSAVE area.
194 (Source : XSAVE_Area_Type;
197 Global => (In_Out => X86_64.State),
198 Depends => (X86_64.State =>+ (Source, State)),
201 -- Save specified Processor Extended States to given XSAVE area.
203 (Target : out XSAVE_Area_Type;
206 Global => (Input => X86_64.State),
207 Depends => (Target => (X86_64.State, State)),
210 -- Get current value of specified Extended Control Register (XCR).
212 (Register : SK.Word32;
213 Value : out SK.Word64)
215 Global => (Input => X86_64.State),
216 Depends => (Value => (X86_64.State, Register)),
219 -- Set specified Extended Control Register (XCR) to given value.
221 (Register : SK.Word32;
224 Global => (In_Out => X86_64.State),
225 Depends => (X86_64.State =>+ (Register, Value)),