From 375f5deda458307614cd3e289650522406028163 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Mon, 18 Apr 2016 11:28:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 12_day/Makefile | 2 +- 12_day/bootpack.c | 7 +++++-- 12_day/bootpack.h | 5 +++++ 12_day/dsctbl.c | 1 + 12_day/naskfunc.nas | 22 ++++++++++++++++++++-- 12_day/timer.c | 20 ++++++++++++++++++++ 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 12_day/timer.c diff --git a/12_day/Makefile b/12_day/Makefile index 71add12..174bccd 100644 --- a/12_day/Makefile +++ b/12_day/Makefile @@ -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/ diff --git a/12_day/bootpack.c b/12_day/bootpack.c index b52dca8..a2468c9 100644 --- a/12_day/bootpack.c +++ b/12_day/bootpack.c @@ -3,6 +3,8 @@ #include "bootpack.h" #include +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; -} \ No newline at end of file +} diff --git a/12_day/bootpack.h b/12_day/bootpack.h index 4f154c9..dd81c9b 100644 --- a/12_day/bootpack.h +++ b/12_day/bootpack.h @@ -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); diff --git a/12_day/dsctbl.c b/12_day/dsctbl.c index 6735c6d..ae81655 100644 --- a/12_day/dsctbl.c +++ b/12_day/dsctbl.c @@ -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); diff --git a/12_day/naskfunc.nas b/12_day/naskfunc.nas index 9de8522..995d540 100644 --- a/12_day/naskfunc.nas +++ b/12_day/naskfunc.nas @@ -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 diff --git a/12_day/timer.c b/12_day/timer.c new file mode 100644 index 0000000..1020139 --- /dev/null +++ b/12_day/timer.c @@ -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; +}