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

📄 i386.c

📁 从网上下载的一个自己编写的简单的操作系统源代码,对底层了解很有好处的
💻 C
字号:
#include "i386/i386.h"



 //1  IDT opreation
 
extern  unsigned int *idt;   //entry.s 
   //bug if define as gate_t  *idt and access by idt[gate_num]
   // 不论定义成什么用
   //(gate_t*)&idt+gate 访问总是正确的

  
/*参数attr 取值如下: arch.h
 *  IGA_K   interupte gate kernel
 *  IGA_U   interupte gate user
 *  TGA_K   trap gate kernel
 *  TGA_U   trap gate user
 *  gate: idt 索引   
 *  offset: 异常/中断处理函数void foo(void) 的地址 
 */
void _gate_fill(short gate,unsigned int offset, unsigned char attr)
{
   //请确保 0<=gate<=255 
   gate_t  *pgate = (gate_t*)&idt+gate;
   
   pgate->attr = attr;
   pgate->Res = (unsigned char)0;
   pgate->sel = _KERNEL_CS;
   
   pgate->offh = (unsigned short)(offset>>16);
              //bug if (unsigned short)offset>>16;
              
   pgate->offl = (unsigned short)(offset);
}

/*
 * @ void _fill_int_gate
 *   把中断门 0x20---0x2F     
 *   设置为在archarch.s 中定义的
 *   中断处理函数
 */
extern unsigned int  _all_int_handler; //通过此表知道处理函数的地址
void _fill_int_gate()
{
   int gate;
   int *base = (unsigned int*)&_all_int_handler;
        	   
   for(gate=0x20; gate<=0x2F; gate++){
        _gate_fill( gate,*(base+gate-0x20), IGA_K);
   	}

}



/*
 * @ IRQ Table 
 *  arch.s
 *
 */
extern unsigned int _irq_table; //arch.s

/*
* 注册irq 处理函数 irqact 到系统irq表
*   void irqact (int irq_num)
*  
* 用_gate_fill 设置_hw_gatexx (archarch.s) 到idt, 注册irqact到_irq_table
*/
int  _irq_reg(short irq,  irq_act irqact)
{
   //请确保 0<=irq<=16 
   * ((irq_act *)&_irq_table+irq) = irqact;

   return 0;
}


/*
 * @ void delay()
 *
 */
void delay()
{
  int i;
  int j;
  for(i=0;i<1000;i++)
  {
    
    for(j=0;j<400;j++)
    {}
  }
}




⌨️ 快捷键说明

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