Added calls to read and write the MSR, the machine state register.

Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14537 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-10-26 23:39:38 +00:00
parent 8fcd6b8e61
commit 90ce9e8305
3 changed files with 67 additions and 44 deletions
+41 -35
View File
@@ -1,7 +1,10 @@
/* /*
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Copyright 2002-2005, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the NewOS License. * Distributed under the terms of the MIT License.
*/ *
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#ifndef _KERNEL_ARCH_x86_CPU_H #ifndef _KERNEL_ARCH_x86_CPU_H
#define _KERNEL_ARCH_x86_CPU_H #define _KERNEL_ARCH_x86_CPU_H
@@ -10,10 +13,8 @@
#include <arch/x86/descriptors.h> #include <arch/x86/descriptors.h>
#ifdef __cplusplus // MSR registers (possibly Intel specific)
extern "C" { #define IA32_MSR_APIC_BASE 0x1b
#endif
struct tss { struct tss {
uint16 prev_task; uint16 prev_task;
@@ -32,37 +33,40 @@ struct tss {
uint16 io_map_base; uint16 io_map_base;
}; };
/**************************************************************************/
struct iframe { struct iframe {
unsigned int gs; uint32 gs;
unsigned int fs; uint32 fs;
unsigned int es; uint32 es;
unsigned int ds; uint32 ds;
unsigned int edi; uint32 edi;
unsigned int esi; uint32 esi;
unsigned int ebp; uint32 ebp;
unsigned int esp; uint32 esp;
unsigned int ebx; uint32 ebx;
unsigned int edx; uint32 edx;
unsigned int ecx; uint32 ecx;
unsigned int eax; uint32 eax;
unsigned int orig_eax; uint32 orig_eax;
unsigned int orig_edx; uint32 orig_edx;
unsigned int vector; uint32 vector;
unsigned int error_code; uint32 error_code;
unsigned int eip; uint32 eip;
unsigned int cs; uint32 cs;
unsigned int flags; uint32 flags;
unsigned int user_esp; uint32 user_esp;
unsigned int user_ss; uint32 user_ss;
}; };
#ifdef __cplusplus
extern "C" {
#endif
#define nop() __asm__ ("nop"::) #define nop() __asm__ ("nop"::)
struct arch_thread; struct arch_thread;
void setup_system_time(unsigned int cv_factor); void setup_system_time(uint32 cv_factor);
void i386_context_switch(struct arch_thread *old_state, struct arch_thread *new_state, addr_t new_pgdir); void i386_context_switch(struct arch_thread *old_state, struct arch_thread *new_state, addr_t new_pgdir);
void i386_enter_uspace(addr_t entry, void *args1, void *args2, addr_t ustack_top); void i386_enter_uspace(addr_t entry, void *args1, void *args2, addr_t ustack_top);
void i386_set_tss_and_kstack(addr_t kstack); void i386_set_tss_and_kstack(addr_t kstack);
@@ -74,6 +78,8 @@ void i386_frstor(const void *fpu_state);
void i386_fxrstor(const void *fpu_state); void i386_fxrstor(const void *fpu_state);
void i386_fsave_swap(void *old_fpu_state, const void *new_fpu_state); void i386_fsave_swap(void *old_fpu_state, const void *new_fpu_state);
void i386_fxsave_swap(void *old_fpu_state, const void *new_fpu_state); void i386_fxsave_swap(void *old_fpu_state, const void *new_fpu_state);
uint64 x86_read_msr(uint32 register);
void x86_write_msr(uint32 register, uint64 value);
void x86_set_task_gate(int32 n, int32 segment); void x86_set_task_gate(int32 n, int32 segment);
struct tss *x86_get_main_tss(void); struct tss *x86_get_main_tss(void);
@@ -103,19 +109,19 @@ __asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port))
__asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port)) __asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port))
#define in8(port) ({ \ #define in8(port) ({ \
unsigned char _v; \ uint8 _v; \
__asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \ __asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
_v; \ _v; \
}) })
#define in16(port) ({ \ #define in16(port) ({ \
unsigned short _v; \ uint16 _v; \
__asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \ __asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \
_v; \ _v; \
}) })
#define in32(port) ({ \ #define in32(port) ({ \
unsigned int _v; \ uint32 _v; \
__asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \ __asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \
_v; \ _v; \
}) })
@@ -127,7 +133,7 @@ __asm__ ("outb %%al,%%dx\n" \
"1:" : : "a" (value), "d" (port)) "1:" : : "a" (value), "d" (port))
#define in8_p(port) ({ \ #define in8_p(port) ({ \
unsigned char _v; \ uint8 _v; \
__asm__ volatile ("inb %%dx,%%al\n" \ __asm__ volatile ("inb %%dx,%%al\n" \
"\tjmp 1f\n" \ "\tjmp 1f\n" \
"1:\tjmp 1f\n" \ "1:\tjmp 1f\n" \
+5 -5
View File
@@ -130,17 +130,17 @@ stack_trace(int argc, char **argv)
struct iframe *frame = (struct iframe *)(ebp + 8); struct iframe *frame = (struct iframe *)(ebp + 8);
kprintf("iframe at %p\n", frame); kprintf("iframe at %p\n", frame);
kprintf(" eax 0x%-9x ebx 0x%-9x ecx 0x%-9x edx 0x%x\n", kprintf(" eax 0x%-9lx ebx 0x%-9lx ecx 0x%-9lx edx 0x%lx\n",
frame->eax, frame->ebx, frame->ecx, frame->edx); frame->eax, frame->ebx, frame->ecx, frame->edx);
kprintf(" esi 0x%-9x edi 0x%-9x ebp 0x%-9x esp 0x%x\n", kprintf(" esi 0x%-9lx edi 0x%-9lx ebp 0x%-9lx esp 0x%lx\n",
frame->esi, frame->edi, frame->ebp, frame->esp); frame->esi, frame->edi, frame->ebp, frame->esp);
kprintf(" eip 0x%-9x eflags 0x%-9x", frame->eip, frame->flags); kprintf(" eip 0x%-9lx eflags 0x%-9lx", frame->eip, frame->flags);
if ((frame->error_code & 0x4) != 0) { if ((frame->error_code & 0x4) != 0) {
// from user space // from user space
kprintf("user esp 0x%x", frame->user_esp); kprintf("user esp 0x%lx", frame->user_esp);
} }
kprintf("\n"); kprintf("\n");
kprintf(" vector: 0x%x, error code: 0x%x\n", frame->vector, frame->error_code); kprintf(" vector: 0x%lx, error code: 0x%lx\n", frame->vector, frame->error_code);
ebp = frame->ebp; ebp = frame->ebp;
} else { } else {
addr_t eip, nextEbp, diff; addr_t eip, nextEbp, diff;
+21 -4
View File
@@ -1,8 +1,11 @@
/* /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved. * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
** Copyright 2002, Michael Noisternig. All rights reserved. * Distributed under the terms of the MIT License.
** Distributed under the terms of the NewOS License. *
*/ * Copyright 2001, Travis Geiselbrecht. All rights reserved.
* Copyright 2002, Michael Noisternig. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#include <arch/x86/descriptors.h> #include <arch/x86/descriptors.h>
@@ -58,6 +61,20 @@ FUNCTION(i386_fxsave_swap):
fxrstor (%eax) fxrstor (%eax)
ret ret
/* uint64 x86_read_msr(uint32 register); */
FUNCTION(x86_read_msr):
movl 4(%esp), %ecx
rdmsr
ret
/* void x86_write_msr(uint32 register, uint64 value); */
FUNCTION(x86_write_msr):
movl 4(%esp), %ecx
movl 8(%esp), %edx
movl 12(%esp), %eax
wrmsr
ret
/* void i386_context_switch(struct arch_thread *old_state, struct arch_thread *new_state, addr new_pgdir); */ /* void i386_context_switch(struct arch_thread *old_state, struct arch_thread *new_state, addr new_pgdir); */
FUNCTION(i386_context_switch): FUNCTION(i386_context_switch):
pusha /* pushes 8 words onto the stack */ pusha /* pushes 8 words onto the stack */