From: AceVest Date: Mon, 28 Apr 2014 15:01:53 +0000 (+0800) Subject: clean irq code X-Git-Tag: 0.3.0~78 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-revoke.html?a=commitdiff_plain;h=b087ddc5e1e7e54dcfba619a9dda90dc95be7745;p=kernel.git clean irq code --- diff --git a/include/io.h b/include/io.h index 75c3a06..351c46e 100644 --- a/include/io.h +++ b/include/io.h @@ -19,68 +19,68 @@ #include -#define outb_p(value,port)({ \ -__asm__("outb %%al,%%dx;nop;nop;nop;nop" \ -: \ -:"a" (value),"d" (port)); \ +#define outb_p(value,port)({ \ +__asm__("outb %%al,%%dx;nop;nop;nop;nop" \ +: \ +:"a" (value),"d" (port)); \ }) -#define inb_p(port)({ \ -u8 _bt; \ -__asm__("inb %%dx,%%al;nop;nop;nop;nop" \ -:"=a" (_bt) \ -:"d" (port)); \ -_bt; \ +#define inb_p(port)({ \ +u8 _bt; \ +__asm__("inb %%dx,%%al;nop;nop;nop;nop" \ +:"=a" (_bt) \ +:"d" (port)); \ +_bt; \ }) -#define outb(value,port)({ \ -__asm__("outb %%al,%%dx" \ -: \ -:"a" (value),"d" (port)); \ +#define outb(value,port)({ \ +__asm__("outb %%al,%%dx" \ +: \ +:"a" (value),"d" (port)); \ }) -#define outw(value,port)({ \ -__asm__("outw %%ax,%%dx" \ -: \ -:"a" (value),"d" (port)); \ +#define outw(value,port)({ \ +__asm__("outw %%ax,%%dx" \ +: \ +:"a" (value),"d" (port)); \ }) -#define outl(value,port)({ \ -__asm__("outl %%eax,%%dx" \ -: \ -:"a" (value),"d" (port)); \ +#define outl(value,port)({ \ +__asm__("outl %%eax,%%dx" \ +: \ +:"a" (value),"d" (port)); \ }) -#define inb(port)({ \ +#define inb(port)({ \ u8 _bt; \ -asm("inb %%dx,%%al" \ -:"=a" (_bt) \ -:"d" (port)); \ -_bt; \ +asm("inb %%dx,%%al" \ +:"=a" (_bt) \ +:"d" (port)); \ +_bt; \ }) -#define inw(port)({ \ -u16 _bt; \ -asm("inw %%dx,%%ax" \ -:"=a" (_bt) \ -:"d" (port)); \ -_bt; \ +#define inw(port)({ \ +u16 _bt; \ +asm("inw %%dx,%%ax" \ +:"=a" (_bt) \ +:"d" (port)); \ +_bt; \ }) -#define inl(port)({ \ -u16 _bt; \ -asm("inl %%dx,%%eax" \ -:"=a" (_bt) \ -:"d" (port)); \ -_bt; \ +#define inl(port)({ \ +u16 _bt; \ +asm("inl %%dx,%%eax" \ +:"=a" (_bt) \ +:"d" (port)); \ +_bt; \ }) -#define BUILDIO(bwl, type) \ -static inline void ins##bwl(int port, void *buf, unsigned long count) \ -{ \ - asm volatile( "cld;rep;ins" #bwl \ - : "+c"(count), "+D"(buf) : "d"(port)); \ +#define BUILDIO(bwl, type) \ +static inline void ins##bwl(int port, void *buf, unsigned long count) \ +{ \ + asm volatile( "cld;rep;ins" #bwl \ + : "+c"(count), "+D"(buf) : "d"(port)); \ } diff --git a/include/irq.h b/include/irq.h index 53b06c9..eaf90e4 100644 --- a/include/irq.h +++ b/include/irq.h @@ -14,21 +14,21 @@ *-------------------------------------------------------------------------- */ -#ifndef _IRQ_H +#ifndef _IRQ_H #define _IRQ_H #include "system.h" -#define NR_IRQS 224 #define FIRST_IRQ_VECT 0x20 +#define NR_IRQS (0xFF-FIRST_IRQ_VECT) -typedef struct +typedef struct irq_chip { const char *name; int (*enable)(unsigned int irq); int (*disable)(unsigned int irq); void (*ack)(unsigned int irq); -} IrqChip, *pIrqChip; +} irq_chip_t; typedef struct irqaction { @@ -37,19 +37,19 @@ typedef struct irqaction const char *dev_name; void *dev_id; struct irqaction *next; -} IrqAction, *pIrqAction; +} irq_action_t; -typedef struct +typedef struct irq_desc { - pIrqChip chip; - pIrqAction action; + irq_chip_t * chip; + irq_action_t * action; unsigned int status; unsigned int depth; -} IrqDesc, *pIrqDesc; +} irq_desc_t; -extern IrqChip i8259_chip; -extern IrqDesc irq_desc[]; -extern IrqDesc no_irq_desc; +extern irq_chip_t i8259_chip; +extern irq_desc_t irq_desc[]; +extern irq_desc_t no_irq_desc; int request_irq(unsigned int irq, //void (*handler)(pPtRegs, unsigned int), void (*handler)(unsigned int, pPtRegs, void *), diff --git a/kernel/clock.c b/kernel/clock.c index 84ac85e..44a314c 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -12,9 +12,13 @@ #include #include -//void clk_handler(pPtRegs regs, unsigned int irq) + +static unsigned int jiffies = 0; + void clk_handler(unsigned int irq, pPtRegs regs, void *dev_id) { - //printk("^"); + jiffies++; + + printk("^%d^ ", jiffies); //printk("%s ", dev_id); } diff --git a/kernel/i8259.c b/kernel/i8259.c index c9dcc6c..c80a45d 100644 --- a/kernel/i8259.c +++ b/kernel/i8259.c @@ -19,7 +19,7 @@ #include "i8259.h" #include "irq.h" -IrqChip i8259_chip = +irq_chip_t i8259_chip = { .name = "XT-PIC", .enable = enable_i8259_irq, diff --git a/kernel/irq.c b/kernel/irq.c index 8f6943f..ee4e25a 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -18,17 +18,17 @@ #include #include -IrqDesc 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;} -IrqChip no_irq_chip = +irq_chip_t no_irq_chip = { .name = "none", .enable = enable_no_irq_chip, .disable = disable_no_irq_chip }; -IrqDesc no_irq_desc = +irq_desc_t no_irq_desc = { .chip = &no_irq_chip, .action = NULL, @@ -39,8 +39,8 @@ __attribute__ ((regparm(1))) void irq_handler(pPtRegs regs) { unsigned int irq = regs->irq; - pIrqDesc p = irq_desc + irq; - pIrqAction action = p->action; + irq_desc_t * p = irq_desc + irq; + irq_action_t * action = p->action; p->chip->ack(irq); while(action) { @@ -52,18 +52,12 @@ __attribute__ ((regparm(1))) void irq_handler(pPtRegs regs) } -/* -int request_irq( unsigned int irq, - void (*handler)(pPtRegs, unsigned int), - const char *devname, - void *dev_id) -*/ int request_irq( unsigned int irq, void (*handler)(unsigned int, pPtRegs, void *), const char *devname, void *dev_id) { - pIrqAction p; + irq_action_t * p; if(irq >= NR_IRQS) return -EINVAL; @@ -79,7 +73,7 @@ int request_irq( unsigned int irq, p = p->next; } - p = kmalloc_old(sizeof(IrqAction)); + p = (irq_action_t *) kmalloc(sizeof(irq_action_t), 0); if(p == NULL) return -ENOMEM; diff --git a/kernel/syscall.c b/kernel/syscall.c index 6288742..4e80ffa 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -25,13 +25,11 @@ unsigned long sysc_handler_table[SYSC_NUM]; void setup_sysc() { - wrmsr(MSR_SYSENTER_CS, SELECTOR_KRNL_CS, 0); - wrmsr(MSR_SYSENTER_EIP, syscall_entry, 0); - wrmsr(MSR_SYSENTER_ESP, ¤t, 0); - + wrmsr(MSR_SYSENTER_CS, SELECTOR_KRNL_CS, 0); + wrmsr(MSR_SYSENTER_EIP, syscall_entry, 0); + wrmsr(MSR_SYSENTER_ESP, ¤t, 0); init_sysc_handler_table(); - } diff --git a/mm/slub.c b/mm/slub.c index ae2fd90..9d99bfa 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -290,6 +290,7 @@ void init_slub_system() printk("kmem objsize %d size %d \n", cache->objsize, cache->size); } +#if 0 list_head_t *p; list_for_each(p, &slub_caches) { @@ -319,4 +320,5 @@ void init_slub_system() printk("kmalloc addr %08x\n", (unsigned long) addr); addrs[i] = addr; } +#endif } diff --git a/setup/setup.c b/setup/setup.c index a1c0580..fff210a 100644 --- a/setup/setup.c +++ b/setup/setup.c @@ -25,7 +25,6 @@ extern void setup_sysc(); extern void setup_pci(); extern void set_tss(); extern void show_logo(); -//extern void setup_tTasks(); extern void setup_tasks(); extern void setup_root_dev(); extern void setup_hd(); @@ -46,7 +45,6 @@ void setup_kernel() init_mm(); - while(1); setup_gdt(); setup_idt(); @@ -54,13 +52,14 @@ void setup_kernel() detect_cpu(); - //setup_tTasks(); - setup_irqs(); set_tss(); + setup_sysc(); setup_pci(); + setup_irqs(); + while(1); // TODO MODIFY CODE BELOW diff --git a/setup/system.c b/setup/system.c index c5e6881..1724c7d 100644 --- a/setup/system.c +++ b/setup/system.c @@ -119,19 +119,18 @@ void setup_irqs() irq_desc[i].chip = &i8259_chip; } - //extern void kbd_handler(pPtRegs, unsigned int); - //extern void clk_handler(pPtRegs, unsigned int); + //extern void kbd_handler(pPtRegs, unsigned int); //extern void clk_handler(pPtRegs, unsigned int); //extern void hd_handler(pPtRegs, unsigned int); void kbd_handler(unsigned int irq, pPtRegs regs, void *dev_id); void clk_handler(unsigned int irq, pPtRegs regs, void *dev_id); void hd_handler(unsigned int irq, pPtRegs regs, void *dev_id); request_irq(0x00, clk_handler, "Intel 8254", "Clock Chip"); request_irq(0x01, kbd_handler, "Intel 8042", "PS/2 Keyboard"); - request_irq(0x0E, hd_handler, "IDE", "IDE"); + request_irq(0x0E, hd_handler, "IDE", "IDE"); enable_irq(0x00); enable_irq(0x01); enable_irq(0x0E); - + asm("sti"); /* pIRQAction pKbdAction, pClkAction;