Skip to content

Commit 6949959

Browse files
mdouchapevik
authored andcommitted
KVM: Add helper function for reading x86 segment registers
Acked-by: Petr Vorel <[email protected]> Acked-by: Cyril Hrubis <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent 4fd496f commit 6949959

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

doc/kvm-test-api.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ struct kvm_cpuid {
329329
struct kvm_cregs {
330330
unsigned long cr0, cr2, cr3, cr4;
331331
};
332+
333+
struct kvm_sregs {
334+
uint16_t cs, ds, es, fs, gs, ss;
335+
};
332336
-------------------------------------------------------------------------------
333337

334338
`struct page_table_entry_pae` is the page table entry structure for PAE and
@@ -370,6 +374,9 @@ Developer's Manual, Volume 3, Chapter 4 for explanation of the fields.
370374
- `void kvm_read_cregs(struct kvm_cregs *buf)` – Copies the current values
371375
of control registers to `buf`.
372376

377+
- `void kvm_read_sregs(struct kvm_sregs *buf)` - Copies the current values
378+
of segment registers to `buf`.
379+
373380
- `uint64_t kvm_rdmsr(unsigned int msr)` – Returns the current value
374381
of model-specific register `msr`.
375382

testcases/kernel/kvm/bootstrap_x86.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ kvm_read_cregs:
197197
pop %edi
198198
ret
199199

200+
.global kvm_read_sregs
201+
kvm_read_sregs:
202+
push %edi
203+
mov 8(%esp), %edi
204+
mov %cs, %ax
205+
movw %ax, (%edi)
206+
mov %ds, %ax
207+
movw %ax, 2(%edi)
208+
mov %es, %ax
209+
movw %ax, 4(%edi)
210+
mov %fs, %ax
211+
movw %ax, 6(%edi)
212+
mov %gs, %ax
213+
movw %ax, 8(%edi)
214+
mov %ss, %ax
215+
movw %ax, 10(%edi)
216+
pop %edi
217+
ret
218+
200219
handle_interrupt:
201220
/* save CPU state */
202221
push %ebp

testcases/kernel/kvm/bootstrap_x86_64.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,22 @@ kvm_read_cregs:
303303
mov %rax, 24(%rdi)
304304
retq
305305

306+
.global kvm_read_sregs
307+
kvm_read_sregs:
308+
mov %cs, %ax
309+
movw %ax, (%rdi)
310+
mov %ds, %ax
311+
movw %ax, 2(%rdi)
312+
mov %es, %ax
313+
movw %ax, 4(%rdi)
314+
mov %fs, %ax
315+
movw %ax, 6(%rdi)
316+
mov %gs, %ax
317+
movw %ax, 8(%rdi)
318+
mov %ss, %ax
319+
movw %ax, 10(%rdi)
320+
retq
321+
306322
handle_interrupt:
307323
/* push CPU state */
308324
push %rbp

testcases/kernel/kvm/include/kvm_x86.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ struct kvm_cregs {
158158
unsigned long cr0, cr2, cr3, cr4;
159159
};
160160

161+
struct kvm_sregs {
162+
uint16_t cs, ds, es, fs, gs, ss;
163+
};
164+
161165
extern struct page_table_entry_pae kvm_pagetable[];
162166
extern struct intr_descriptor kvm_idt[X86_INTR_COUNT];
163167
extern struct segment_descriptor kvm_gdt[KVM_GDT_SIZE];
@@ -178,6 +182,7 @@ unsigned int kvm_create_stack_descriptor(struct segment_descriptor *table,
178182
/* Functions for querying CPU info and status */
179183
void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf);
180184
void kvm_read_cregs(struct kvm_cregs *buf);
185+
void kvm_read_sregs(struct kvm_sregs *buf);
181186
uint64_t kvm_rdmsr(unsigned int msr);
182187
void kvm_wrmsr(unsigned int msr, uint64_t value);
183188

0 commit comments

Comments
 (0)