Skip to content

Commit

Permalink
使用定时器
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed Apr 18, 2016
1 parent 71b32da commit 375f5de
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 12_day/Makefile
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
7 changes: 5 additions & 2 deletions 12_day/bootpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -169,4 +172,4 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
}
}
return;
}
}
5 changes: 5 additions & 0 deletions 12_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
1 change: 1 addition & 0 deletions 12_day/dsctbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 20 additions & 2 deletions 12_day/naskfunc.nas
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions 12_day/timer.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 375f5de

Please sign in to comment.