⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i386.h

📁 Jazmyn is a 32-bit, protected mode, multitasking OS which runs on i386 & above CPU`s. Its complete
💻 H
字号:
#ifndef _I386_H
#define _I386_H

#define _AL  ({byte _v;__asm__ __volatile__("":"=a" (_v));_v;})
#define _AH  ({byte _v;__asm__ __volatile__("movb %%ah,%0":"=g" (_v));_v;})
#define _BL  ({byte _v;__asm__ __volatile__("":"=b" (_v));_v;})
#define _BH  ({byte _v;__asm__ __volatile__("movb %%bh,%0":"=g" (_v));_v;})
#define _CL  ({byte _v;__asm__ __volatile__("":"=c" (_v));_v;})
#define _CH  ({byte _v;__asm__ __volatile__("movb %%ch,%0":"=g" (_v));_v;})
#define _DL  ({byte _v;__asm__ __volatile__("":"=d" (_v));_v;})
#define _DH  ({byte _v;__asm__ __volatile__("movb %%dh,%0":"=g" (_v));_v;})
#define _AX  ({word _v;__asm__ __volatile__("":"=a" (_v));_v;})
#define _BX  ({word _v;__asm__ __volatile__("":"=b" (_v));_v;})
#define _CX  ({word _v;__asm__ __volatile__("":"=c" (_v));_v;})
#define _DX  ({word _v;__asm__ __volatile__("":"=d" (_v));_v;})
#define _EAX ({uint _v;__asm__ __volatile__("":"=a" (_v));_v;})
#define _EBX ({uint _v;__asm__ __volatile__("":"=b" (_v));_v;})
#define _ECX ({uint _v;__asm__ __volatile__("":"=c" (_v));_v;})
#define _EDX ({uint _v;__asm__ __volatile__("":"=d" (_v));_v;})
#define _ESI ({uint _v;__asm__ __volatile__("":"=S" (_v));_v;})
#define _EDI ({uint _v;__asm__ __volatile__("":"=D" (_v));_v;})
#define _ESP ({uint _v;__asm__ __volatile__("movl %%esp,%0":"=g" (_v));_v;})
#define _EBP ({uint _v;__asm__ __volatile__("movl %%ebp,%0":"=g" (_v));_v;})
#define _CS  ({word _v;__asm__ __volatile__("movw %%cs,%0":"=g" (_v));_v;})
#define _DS  ({word _v;__asm__ __volatile__("movw %%ds,%0":"=g" (_v));_v;})
#define _SS  ({word _v;__asm__ __volatile__("movw %%ss,%0":"=g" (_v));_v;})
#define _ES  ({word _v;__asm__ __volatile__("movw %%es,%0":"=g" (_v));_v;})
#define _FS  ({word _v;__asm__ __volatile__("movw %%fs,%0":"=g" (_v));_v;})
#define _GS  ({word _v;__asm__ __volatile__("movw %%gs,%0":"=g" (_v));_v;})
#define _CR0 ({uint _v;__asm__ __volatile__("movl %%cr0,%%eax":"=a"(_v));_v;})
#define _CR2 ({uint _v;__asm__ __volatile__("movl %%cr2,%%eax":"=a"(_v));_v;})
#define _CR3 ({uint _v;__asm__ __volatile__("movl %%cr3,%%eax":"=a"(_v));_v;})

#ifdef __cplusplus
extern "C" {
#endif

static inline void LLDT(ushort _s)
{
        __asm__ __volatile__("lldt %%ax"::"a" (_s));
}

static inline ushort SLDT()
{
        ushort _s;
        __asm__ __volatile__("sldt %%ax":"=a" (_s));
        return _s;
}

static inline void LGDT(uint _l,uint _b)
{
        uint _a[2];
        _a[0] = _l << 16;
        _a[1] = _b;
        __asm__ __volatile__("lgdt (%0)"::"p" (((char*)_a)+2));
}
                
static inline void SGDT(uint *_l,uint *_b)
{
        uint _a[2];
        __asm__ __volatile__("sgdt (%0)"::"p" (((char*)_a)+2));
        *_l = _a[0] >> 16;
        *_b = _a[1];
}

static inline void LIDT(uint _l,uint _b)
{
        uint _a[2];
        _a[0] = _l << 16;
        _a[1] = _b;
        __asm__ __volatile__("lidt (%0)"::"p" (((char*)_a)+2));
}

static inline void SIDT(uint *_l,uint *_b)
{
        uint _a[2];
        __asm__ __volatile__("sidt (%0)":: "p" (((char*)_a)+2));
        *_l = _a[0] >> 16;
        *_b = _a[1];
}

static inline void LTR(ushort _s)
{
        __asm__ __volatile__("ltr %%ax"::"a" (_s));
}

static inline ushort STR()
{
        ushort _s=0;
        __asm__ __volatile__("str %%ax":"=a" (_s));
        return _s;
}

static inline void enable_paging(uint page_dir)
{
        __asm__ __volatile__("movl %%eax,%%cr3 \n"
                             "movl %%cr0,%%eax \n"
                             "orl  $0x80000000,%%eax \n"
                             "movl %%eax,%%cr0"
                              ::"a" (page_dir));
}

static inline void disable_paging()
{
        __asm__ __volatile__("movl %cr0,%eax \n"
                             "andl $0x7fffffff,%eax \n"
                             "movl %eax,%cr0");
}

#ifdef __cplusplus
}
#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -