使用定时器

This commit is contained in:
Yourtion
2016-04-18 11:28:19 +08:00
parent 71b32daf8d
commit 375f5deda4
6 changed files with 52 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \
int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj
int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj
TOOLPATH = ../z_tools/
INCPATH = ../z_tools/haribote/

View File

@@ -3,6 +3,8 @@
#include "bootpack.h"
#include <stdio.h>
void make_window8(unsigned char *buf, int xsize, int ysize, char *title);
void HariMain(void)
{
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
@@ -21,7 +23,8 @@ void HariMain(void)
fifo8_init(&keyfifo, 32, keybuf);
fifo8_init(&mousefifo, 128, mousebuf);
io_out8(PIC0_IMR, 0xf9); /* 开放PIC1和键盘中断(11111001) */
init_pit();
io_out8(PIC0_IMR, 0xf8); /* PIT和PIC1和键盘设置为许可(11111000) */
io_out8(PIC1_IMR, 0xef); /* 开放鼠标中断(11101111) */
init_keyboard();
@@ -169,4 +172,4 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
}
}
return;
}
}

View File

@@ -22,6 +22,7 @@ void load_gdtr(int limit, int addr);
void load_idtr(int limit, int addr);
int load_cr0(void);
void store_cr0(int cr0);
void asm_inthandler20(void);
void asm_inthandler21(void);
void asm_inthandler27(void);
void asm_inthandler2c(void);
@@ -166,3 +167,7 @@ void sheet_updown(struct SHEET *sht, int height);
void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1);
void sheet_slide(struct SHEET *sht, int vx0, int vy0);
void sheet_free(struct SHEET *sht);
/* timer.c */
void init_pit(void);
void inthandler20(int *esp);

View File

@@ -23,6 +23,7 @@ void init_gdtidt(void)
load_idtr(LIMIT_IDT, ADR_IDT);
/* IDT设置*/
set_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);

View File

@@ -12,9 +12,11 @@
GLOBAL _io_load_eflags, _io_store_eflags
GLOBAL _load_gdtr, _load_idtr
GLOBAL _load_cr0, _store_cr0
GLOBAL _asm_inthandler21, _asm_inthandler27, _asm_inthandler2c
GLOBAL _asm_inthandler20, _asm_inthandler21
GLOBAL _asm_inthandler27, _asm_inthandler2c
GLOBAL _memtest_sub
EXTERN _inthandler21, _inthandler27, _inthandler2c
EXTERN _inthandler20, _inthandler21
EXTERN _inthandler27, _inthandler2c
[SECTION .text]
@@ -102,6 +104,22 @@ _store_cr0: ; void store_cr0(int cr0);
MOV CR0,EAX
RET
_asm_inthandler20:
PUSH ES
PUSH DS
PUSHAD
MOV EAX,ESP
PUSH EAX
MOV AX,SS
MOV DS,AX
MOV ES,AX
CALL _inthandler20
POP EAX
POPAD
POP DS
POP ES
IRETD
_asm_inthandler21:
PUSH ES
PUSH DS

20
12_day/timer.c Normal file
View File

@@ -0,0 +1,20 @@
/* 定时器 */
#include "bootpack.h"
#define PIT_CTRL 0x0043
#define PIT_CNT0 0x0040
void init_pit(void)
{
io_out8(PIT_CTRL, 0x43);
io_out8(PIT_CNT0, 0x9c);
io_out8(PIT_CNT0, 0x2e);
}
void inthandler20(int *esp)
{
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
/* 暂时什么也不做 */
return;
}