From 0a0793cc556da1782ec1fae680a4c9238609bf31 Mon Sep 17 00:00:00 2001 From: AceVest Date: Wed, 7 May 2014 21:53:30 +0800 Subject: [PATCH] support 8253 --- include/errno.h | 6 ++---- kernel/clock.c | 3 ++- kernel/fork.c | 3 +-- kernel/init.c | 6 ++---- kernel/irq.c | 36 +++++++++++++++++++++--------------- kernel/syscall.c | 7 ++++--- setup/setup.c | 18 ++++++++++++++---- 7 files changed, 46 insertions(+), 33 deletions(-) diff --git a/include/errno.h b/include/errno.h index bacc954..93f3f00 100644 --- a/include/errno.h +++ b/include/errno.h @@ -1,6 +1,4 @@ -/* - *-------------------------------------------------------------------------- - * File Name: errno.h +/* *-------------------------------------------------------------------------- * File Name: errno.h * * Author: Zhao Yanbai [zhaoyanbai@126.com] * Mon Feb 1 17:07:06 2010 @@ -10,7 +8,7 @@ *-------------------------------------------------------------------------- */ -#ifndef _ERRNO_H +#ifndef _ERRNO_H #define _ERRNO_H #define EPERM 1 /* Operation not permitted */ diff --git a/kernel/clock.c b/kernel/clock.c index a7d3e96..8bc7cd2 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -19,6 +19,7 @@ void clk_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { jiffies++; - printk("^%d^ ", jiffies); + printk("^"); + //printk("^%d^ ", jiffies); //printk("%s ", dev_id); } diff --git a/kernel/fork.c b/kernel/fork.c index 06f72f4..d044361 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -24,7 +24,7 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { task_union *tsk; tsk = alloc_task_union(); - printk("another task %08x flags %08x\n", tsk, flags); + printk("fork task %08x flags %08x\n", tsk, flags); if(tsk == NULL) panic("can not malloc PCB"); @@ -82,7 +82,6 @@ int do_fork(pt_regs_t *regs, unsigned long flags) if(flags & FORK_KRNL) { - printk("--dsfsdafdsaf----\n"); tsk->eip= (unsigned long) ret_from_fork_krnl; } diff --git a/kernel/init.c b/kernel/init.c index 2a8c294..a9dbbde 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -26,7 +26,7 @@ void init_task_entry() printk("hahahha %s\n", __func__); while(1) { - printk("i "); + printk("i"); asm("sti;hlt;"); } } @@ -42,14 +42,12 @@ void root_task_entry() pt_regs_t regs; memset((void*)®s, 0, sizeof(regs)); regs.edx = (unsigned long) init_task_entry; - cli(); int pid = do_fork(®s, FORK_KRNL); - sti(); printk("pid is %d\n", pid); while(1) { - printk("r "); + printk("r"); asm("sti;hlt;"); //sysc_test(); //syscall0(SYSC_TEST); diff --git a/kernel/irq.c b/kernel/irq.c index a37b205..5ce8c42 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -18,36 +18,42 @@ #include #include -irq_desc_t irq_desc[NR_IRQS]; +irq_desc_t irq_desc[NR_IRQS]; -int enable_no_irq_chip(unsigned int irq){return 0;} -int disable_no_irq_chip(unsigned int irq){return 0;} -irq_chip_t no_irq_chip = +int enable_no_irq_chip(unsigned int irq){return 0;} +int disable_no_irq_chip(unsigned int irq){return 0;} + +irq_chip_t no_irq_chip = { - .name = "none", - .enable = enable_no_irq_chip, - .disable = disable_no_irq_chip + .name = "none", + .enable = enable_no_irq_chip, + .disable= disable_no_irq_chip }; -irq_desc_t no_irq_desc = + +irq_desc_t no_irq_desc = { - .chip = &no_irq_chip, - .action = NULL, - .status = 0, - .depth = 0 + .chip = &no_irq_chip, + .action = NULL, + .status = 0, + .depth = 0 }; -__attribute__ ((regparm(1))) void irq_handler(pt_regs_t * regs) + +__attribute__ ((regparm(1))) void irq_handler(pt_regs_t *regs) { unsigned int irq = regs->irq; - irq_desc_t * p = irq_desc + irq; - irq_action_t * action = p->action; + irq_desc_t *p = irq_desc + irq; + irq_action_t *action = p->action; + p->chip->ack(irq); + sti(); while(action) { //action->handler(regs, irq); action->handler(irq, regs, action->dev_id); action = action->next; } + p->chip->enable(irq); } diff --git a/kernel/syscall.c b/kernel/syscall.c index 85d4657..eb4be16 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -62,18 +62,19 @@ void init_sysc_handler_table() }while(0); /* 有没有一种宏定义可以把大写直接转成小写? */ - _sysc_(SYSC_WRITE, sysc_write); + _sysc_(SYSC_WRITE, sysc_write); _sysc_(SYSC_READ_KBD, sysc_read_kbd); - _sysc_(SYSC_REBOOT, sysc_reboot); + _sysc_(SYSC_REBOOT, sysc_reboot); _sysc_(SYSC_FORK, sysc_fork); _sysc_(SYSC_EXEC, sysc_exec); _sysc_(SYSC_OPEN, sysc_open); _sysc_(SYSC_READ, sysc_read); _sysc_(SYSC_STAT, sysc_stat); _sysc_(SYSC_EXIT, sysc_exit); - _sysc_(SYSC_PAUSE, sysc_pause); + _sysc_(SYSC_PAUSE, sysc_pause); _sysc_(SYSC_TEST, sysc_test); } + int sysc_bad_syscnr() { int sysc_nr; diff --git a/setup/setup.c b/setup/setup.c index 6cfa18f..fe42875 100644 --- a/setup/setup.c +++ b/setup/setup.c @@ -16,6 +16,7 @@ #include #include #include +#include extern void setup_gdt(); extern void setup_idt(); @@ -31,11 +32,18 @@ extern void setup_hd(); extern void setup_fs(); extern void setup_ext2(); -extern unsigned long mb_mm_lower, mb_mm_upper; -extern unsigned long mb_mmap_addr, mb_mmap_size; - extern void reboot(); +#define HZ 100 +#define CLOCK_TICK_RATE 1193180 +#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) + +void setup_i8253() +{ + outb_p(0x34, 0x43); + outb_p(LATCH & 0xFF, 0x40); + outb(LATCH >> 8, 0x40); +} void setup_kernel() { @@ -49,12 +57,14 @@ void setup_kernel() setup_idt(); setup_gate(); + setup_i8253(); + detect_cpu(); set_tss(); setup_sysc(); - //setup_pci(); + setup_pci(); setup_irqs(); -- 2.44.0