]> Zhao Yanbai Git Server - kernel.git/commitdiff
clean irq code
authorAceVest <zhaoyanbai@126.com>
Mon, 28 Apr 2014 15:01:53 +0000 (23:01 +0800)
committerAceVest <zhaoyanbai@126.com>
Mon, 28 Apr 2014 15:01:53 +0000 (23:01 +0800)
include/io.h
include/irq.h
kernel/clock.c
kernel/i8259.c
kernel/irq.c
kernel/syscall.c
mm/slub.c
setup/setup.c
setup/system.c

index 75c3a066825d53c0e3e886a566406ac74991bd1e..351c46e7b6d7c65dac83144e321c50f6d78193ad 100644 (file)
 
 #include <types.h>
 
-#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));                      \
 }
 
 
index 53b06c94a84f548e6b195392cc475be65cc6a7b6..eaf90e47ed81b29fe7e03fe14be53cc95db820db 100644 (file)
  *--------------------------------------------------------------------------
  */
 
-#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 *),
index 84ac85ea36c0c7f736de2086129aa560d5e0511d..44a314c34d8161e3adb39aaf7d8bf91963c41394 100644 (file)
 
 #include <printk.h>
 #include <system.h>
-//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);
 }
index c9dcc6c2f08f4c3dd0df5712c2127edd33116010..c80a45df1879841658fa73c24d066f7f24a2ed57 100644 (file)
@@ -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,
index 8f6943f7ab21c24f372c06e720481fe1fa844a2c..ee4e25abed700392b8dd543a2b1c1b7460225501 100644 (file)
 #include <errno.h>
 #include <assert.h>
 
-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;
 
index 6288742b819b93bc92b7ec8603b594eead0ddf5e..4e80ffa8d432b6312f3d0c36db7315288b8072b6 100644 (file)
@@ -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,    &current,        0);
-
+    wrmsr(MSR_SYSENTER_CS,  SELECTOR_KRNL_CS,   0);
+    wrmsr(MSR_SYSENTER_EIP, syscall_entry,      0);
+    wrmsr(MSR_SYSENTER_ESP, &current,           0);
 
     init_sysc_handler_table();
-
 }
 
 
index ae2fd90b055e202b49d831ea1199a82820dd5401..9d99bfa042bbc78227cd52883c256f86fc2e8b60 100644 (file)
--- 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
 }
index a1c058079234ff208c8a22732693e33b89aa0eb4..fff210aca5acdf9a2b78d0f4798179a6ac2de9e5 100644 (file)
@@ -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
 
index c5e6881cfa7216794b69949fae98cddc1265d5f3..1724c7df68600e4ddbc800c2fb010cbe522f184f 100644 (file)
@@ -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;