2002-07-09 16:24:59 +04:00
|
|
|
/*
|
|
|
|
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
** Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
#ifndef _KERNEL_ARCH_x86_CPU_H
|
|
|
|
#define _KERNEL_ARCH_x86_CPU_H
|
|
|
|
|
2004-11-19 22:40:05 +03:00
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
2002-07-25 00:59:25 +04:00
|
|
|
#include <arch/x86/descriptors.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-19 22:40:05 +03:00
|
|
|
|
2005-03-02 02:52:09 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
struct tss {
|
|
|
|
uint16 prev_task;
|
|
|
|
uint16 unused0;
|
|
|
|
uint32 sp0;
|
|
|
|
uint32 ss0;
|
|
|
|
uint32 sp1;
|
|
|
|
uint32 ss1;
|
|
|
|
uint32 sp2;
|
|
|
|
uint32 ss2;
|
|
|
|
uint32 cr3;
|
|
|
|
uint32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
|
|
|
uint32 es, cs, ss, ds, fs, gs;
|
|
|
|
uint32 ldt_seg_selector;
|
|
|
|
uint16 unused1;
|
|
|
|
uint16 io_map_base;
|
|
|
|
};
|
|
|
|
|
2003-01-06 11:02:44 +03:00
|
|
|
/**************************************************************************/
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-14 01:42:53 +04:00
|
|
|
struct iframe {
|
|
|
|
unsigned int gs;
|
|
|
|
unsigned int fs;
|
|
|
|
unsigned int es;
|
|
|
|
unsigned int ds;
|
|
|
|
unsigned int edi;
|
|
|
|
unsigned int esi;
|
|
|
|
unsigned int ebp;
|
|
|
|
unsigned int esp;
|
|
|
|
unsigned int ebx;
|
|
|
|
unsigned int edx;
|
|
|
|
unsigned int ecx;
|
|
|
|
unsigned int eax;
|
2002-10-23 21:31:10 +04:00
|
|
|
unsigned int orig_eax;
|
|
|
|
unsigned int orig_edx;
|
2002-08-14 01:42:53 +04:00
|
|
|
unsigned int vector;
|
|
|
|
unsigned int error_code;
|
|
|
|
unsigned int eip;
|
|
|
|
unsigned int cs;
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int user_esp;
|
|
|
|
unsigned int user_ss;
|
|
|
|
};
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#define nop() __asm__ ("nop"::)
|
|
|
|
|
2004-10-12 07:54:03 +04:00
|
|
|
struct arch_thread;
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
void setup_system_time(unsigned int cv_factor);
|
2004-10-20 04:33:06 +04:00
|
|
|
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_set_tss_and_kstack(addr_t kstack);
|
|
|
|
void i386_switch_stack_and_call(addr_t stack, void (*func)(void *), void *arg);
|
|
|
|
void i386_swap_pgdir(addr_t new_pgdir);
|
2002-10-23 21:31:10 +04:00
|
|
|
void i386_fsave(void *fpu_state);
|
|
|
|
void i386_fxsave(void *fpu_state);
|
2005-03-02 02:52:09 +03:00
|
|
|
void i386_frstor(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_fxsave_swap(void *old_fpu_state, const void *new_fpu_state);
|
2004-12-14 04:46:46 +03:00
|
|
|
void x86_set_task_gate(int32 n, int32 segment);
|
2005-04-05 01:43:47 +04:00
|
|
|
struct tss *x86_get_main_tss(void);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-14 01:42:53 +04:00
|
|
|
#define read_ebp(value) \
|
|
|
|
__asm__("movl %%ebp,%0" : "=r" (value))
|
|
|
|
|
2004-12-14 04:46:46 +03:00
|
|
|
#define read_cr3(value) \
|
|
|
|
__asm__("movl %%cr3,%0" : "=r" (value))
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#define read_dr3(value) \
|
|
|
|
__asm__("movl %%dr3,%0" : "=r" (value))
|
|
|
|
|
|
|
|
#define write_dr3(value) \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__("movl %0,%%dr3" : : "r" (value))
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define invalidate_TLB(va) \
|
|
|
|
__asm__("invlpg (%0)" : : "r" (va))
|
|
|
|
|
|
|
|
#define out8(value,port) \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ ("outb %%al,%%dx" : : "a" (value), "d" (port))
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define out16(value,port) \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port))
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define out32(value,port) \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port))
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define in8(port) ({ \
|
|
|
|
unsigned char _v; \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
|
2002-07-09 16:24:59 +04:00
|
|
|
_v; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define in16(port) ({ \
|
|
|
|
unsigned short _v; \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \
|
2002-07-09 16:24:59 +04:00
|
|
|
_v; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define in32(port) ({ \
|
|
|
|
unsigned int _v; \
|
2003-05-20 07:02:19 +04:00
|
|
|
__asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \
|
2002-07-09 16:24:59 +04:00
|
|
|
_v; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define out8_p(value,port) \
|
|
|
|
__asm__ ("outb %%al,%%dx\n" \
|
|
|
|
"\tjmp 1f\n" \
|
|
|
|
"1:\tjmp 1f\n" \
|
2003-05-20 07:02:19 +04:00
|
|
|
"1:" : : "a" (value), "d" (port))
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define in8_p(port) ({ \
|
|
|
|
unsigned char _v; \
|
|
|
|
__asm__ volatile ("inb %%dx,%%al\n" \
|
|
|
|
"\tjmp 1f\n" \
|
|
|
|
"1:\tjmp 1f\n" \
|
2003-05-20 07:02:19 +04:00
|
|
|
"1:" : "=a" (_v) : "d" (port)); \
|
2002-07-09 16:24:59 +04:00
|
|
|
_v; \
|
|
|
|
})
|
|
|
|
|
2003-01-06 11:02:44 +03:00
|
|
|
extern segment_descriptor *gGDT;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-03-02 02:52:09 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-01-06 11:02:44 +03:00
|
|
|
#endif /* _KERNEL_ARCH_x86_CPU_H */
|