]> Zhao Yanbai Git Server - kernel.git/commitdiff
replace '\t' with ' '
authorAceVest <zhaoyanbai@126.com>
Fri, 4 Apr 2014 10:52:01 +0000 (18:52 +0800)
committerAceVest <zhaoyanbai@126.com>
Fri, 4 Apr 2014 10:52:01 +0000 (18:52 +0800)
89 files changed:
bin/helloworld.S
bin/helloworld.c
bin/shell.S
bin/shell.c
boot/boot.c
boot/cmdline.c
boot/multiboot.S
boot/reboot.S
drivers/hd.c
drivers/hd.h
drivers/keyboard.c
drivers/vga.c
fs/ext2.c
fs/fs.c
fs/open.c
fs/read.c
fs/stat.c
fs/write.c
include/assert.h
include/bits.h
include/boot/multiboot.h
include/elf.h
include/errno.h
include/ext2.h
include/fcntl.h
include/fs.h
include/global.h
include/i8259.h
include/io.h
include/irq.h
include/linkage.h
include/list.h
include/msr.h
include/page.h
include/pci.h
include/printk.h
include/processor.h
include/sched.h
include/stat.h
include/stdio.h
include/stdlib.h
include/string.h
include/syscall.h
include/system.h
include/task.h
include/types.h
include/unistd.h
include/wait.h
kernel/clock.c
kernel/entry.S
kernel/exec.c
kernel/exit.c
kernel/fork.c
kernel/i8259.c
kernel/init.c
kernel/innerint.c
kernel/interrupts.S
kernel/irq.c
kernel/printk.c
kernel/processor.c
kernel/sched.c
kernel/syscall.S
kernel/syscall.c
kernel/system.c
kernel/test.c
kernel/test_task.c
kernel/wait.c
lib/assert.c
lib/errno.c
lib/exec.c
lib/exit.c
lib/fork.c
lib/keyboard.c
lib/lib.c
lib/open.c
lib/read.c
lib/stat.c
lib/string.c
lib/vsprintf.c
lib/write.c
mm/kmalloc.c
mm/mm.c
mm/page.c
pci/setuppci.c
setup/cpuid.c
setup/logo.c
setup/setup.c
setup/system.c
setup/version.c

index 1e469e8247c4bd8783f1f63533e23ef36c6e2a21..55c1ab87e6988274372c575af24b2647e61dbe23 100644 (file)
@@ -1,30 +1,30 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        helloworld.S
+ *   File Name: helloworld.S
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 20:15:27 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 20:15:27 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#define        ASM
-#include<syscall.h>
-.global        _start
+#define ASM
+#include <syscall.h>
+.global    _start
 _start:
-       nop
-       nop
-       nop
-       #xchg %bx, %bx
+    nop
+    nop
+    nop
+    #xchg %bx, %bx
 loop:
-       #jmp    loop
-       call    hw
-       
-       nop
-       nop
-       nop
-       nop
-       nop
+    #jmp    loop
+    call    hw
+    
+    nop
+    nop
+    nop
+    nop
+    nop
 die:
-       jmp     die
+    jmp    die
index a204a6532b282fcb7c36678c4597cefd38fadf58..8b4e9c85f036b0b0f57380db711a57e39e7a4512 100644 (file)
@@ -1,25 +1,25 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        helloworld.c
+ *   File Name: helloworld.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 22:44:40 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 22:44:40 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<unistd.h>
-#include<stdio.h>
+#include <unistd.h>
+#include <stdio.h>
 
 int hw()
 {
-       printf("hello world\n");
-       //syscall3(SYSC_WRITE, 0, "fuck", 5);
-       //write(0, "hello world", sizeof("hello world"));
-       //write(0, "hello world", 12);
-       
-       exit(0);
+    printf("hello world\n");
+    //syscall3(SYSC_WRITE, 0, "fuck", 5);
+    //write(0, "hello world", sizeof("hello world"));
+    //write(0, "hello world", 12);
+    
+    exit(0);
 
-       return 0;
+    return 0;
 }
index fe91cbeec14497b42ec1026a02d33e117772b874..93330fcaffadc74f9050e0bc87c2cc29620fa859 100644 (file)
@@ -1,29 +1,29 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        shell.S
+ *   File Name: shell.S
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Feb 24 17:47:27 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Feb 24 17:47:27 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-.global        _start
+.global    _start
 _start:
-       nop
-       nop
-       nop
+    nop
+    nop
+    nop
 loop:
-       #jmp    loop
-       call    shell
-       nop
-       nop
-       nop
-       nop
-       nop
-       nop
-       nop
-       nop
+    #jmp    loop
+    call    shell
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
 die:
-       jmp     die
+    jmp    die
index a14e736c0277f82278956089405a965417a7cec8..3883d962273dbf6d6b0c606194109b856d2d0d6f 100644 (file)
@@ -1,60 +1,60 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        shell.c
+ *   File Name: shell.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Feb 24 17:47:22 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Feb 24 17:47:22 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<stdio.h>
-#include<types.h>
-#include<string.h>
-#define        CMD_SIZE        256
+#include <stdio.h>
+#include <types.h>
+#include <string.h>
+#define CMD_SIZE    256
 char cmd[CMD_SIZE];
 
 void get_cmd()
 {
-       int i;
-
-       i=0;
-       printf("#");
-       while(1)
-       {
-               int k;
-               char ch;
-               extern char ParseKbdInput(int k);
-               extern unsigned char read_kbd();
+    int i;
+
+    i=0;
+    printf("#");
+    while(1)
+    {
+        int k;
+        char ch;
+        extern char ParseKbdInput(int k);
+        extern unsigned char read_kbd();
 reinput:
-               k = read_kbd();
-               ch = ParseKbdInput(k);
-               if(ch == -1)
-                       continue;
-               
-               if(ch == '\b')
-               {
+        k = read_kbd();
+        ch = ParseKbdInput(k);
+        if(ch == -1)
+            continue;
+        
+        if(ch == '\b')
+        {
             i = --i < 0 ? 0 : i;
-                       cmd[i] = 0;
-                       continue;
-               }
-
-               if(ch == '\n')
-               {
-                       cmd[i++] = 0;
-                       break;
-               }
-
-               cmd[i++] = ch;
-
-               if(i == CMD_SIZE - 1)
-               {
-                       printf("shell buffer is full..."
-                               "reset buffer...\n");
-                       i = 0;
-               }
-       }
+            cmd[i] = 0;
+            continue;
+        }
+
+        if(ch == '\n')
+        {
+            cmd[i++] = 0;
+            break;
+        }
+
+        cmd[i++] = ch;
+
+        if(i == CMD_SIZE - 1)
+        {
+            printf("shell buffer is full..."
+                "reset buffer...\n");
+            i = 0;
+        }
+    }
 
     int len = strlen(cmd);
     int j;
@@ -71,83 +71,83 @@ reinput:
         goto reinput;
     }
 
-       cmd[CMD_SIZE-1] = 0;
+    cmd[CMD_SIZE-1] = 0;
 }
 
 int shell()
 {
-       char buf[CMD_SIZE];
-
-       while(1)
-       {
-               get_cmd();
-
-               //printf("\nCMD: %s\n", cmd);
-
-               if(cmd[0] == 0) continue;
-               if(cmd[0] != '/')
-               {
-                       strcpy(buf, cmd);
-                       strcpy(cmd, "/bin/");
-                       strcat(cmd, buf);
-               }
-               
-               pid_t pid;
-               pid = fork();
-
-               if(pid<0)
-               {
-                       printf("shit happens in shell\n");
-                       while(1);
-               }
-               else if(pid == 0)
-               {
-                       execv(cmd, NULL);
-               }
-
-               int  i = 100000;
-               while(i--);
-       }
-
-
-
-       return 0;
+    char buf[CMD_SIZE];
+
+    while(1)
+    {
+        get_cmd();
+
+        //printf("\nCMD: %s\n", cmd);
+
+        if(cmd[0] == 0) continue;
+        if(cmd[0] != '/')
+        {
+            strcpy(buf, cmd);
+            strcpy(cmd, "/bin/");
+            strcat(cmd, buf);
+        }
+        
+        pid_t pid;
+        pid = fork();
+
+        if(pid<0)
+        {
+            printf("shit happens in shell\n");
+            while(1);
+        }
+        else if(pid == 0)
+        {
+            execv(cmd, NULL);
+        }
+
+        int  i = 100000;
+        while(i--);
+    }
+
+
+
+    return 0;
 }
 
 #if 0
 int shell()
 {
-       pid_t pid;
-
-       pid = fork();
-
-       if(pid<0)
-       {
-               printf("shit happens in shell\n");
-               while(1);
-       }
-       else if(pid == 0)
-       {
-               execv("/bin/hw", NULL);
-       }
-       else
-       {
-
-               while(1)
-               {
-                       int k;
-                       char ch;
-                       extern char ParseKbdInput(int k);
-                       extern unsigned char read_kbd();
-                       //asm("xchg %bx, %bx");
-                       k = read_kbd();
-                       ch = ParseKbdInput(k);
-                       if(ch != -1)
-                       printf("<%c>",ch);
-               }
-       }
-
-
-       return 0;
+    pid_t pid;
+
+    pid = fork();
+
+    if(pid<0)
+    {
+        printf("shit happens in shell\n");
+        while(1);
+    }
+    else if(pid == 0)
+    {
+        execv("/bin/hw", NULL);
+    }
+    else
+    {
+
+        while(1)
+        {
+            int k;
+            char ch;
+            extern char ParseKbdInput(int k);
+            extern unsigned char read_kbd();
+            //asm("xchg %bx, %bx");
+            k = read_kbd();
+            ch = ParseKbdInput(k);
+            if(ch != -1)
+            printf("<%c>",ch);
+        }
+    }
+
+
+    return 0;
 }
 #endif
index 69bff433c9d58e4a3d77df313f2b048bebf655b3..329d169752fca27c6a07ba5b7068720c52948f2e 100644 (file)
@@ -1,24 +1,24 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        boot.c
+ *   File Name: boot.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Dec 30 21:55:29 2009
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Dec 30 21:55:29 2009
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
 
-#include<system.h>
-#include<boot/boot.h>
-#include<page.h>
-#include<bits.h>
-#include<assert.h>
+#include <system.h>
+#include <boot/boot.h>
+#include <page.h>
+#include <bits.h>
+#include <assert.h>
 
-extern void    parse_cmdline(const char *cmdline);
-void   init_free_area(u32 base, u32 len);
+extern void    parse_cmdline(const char *cmdline);
+void    init_free_area(u32 base, u32 len);
 
 
 struct boot_params boot_params __attribute__((aligned(32)));
@@ -48,19 +48,19 @@ void init_boot_params(multiboot_info_t *p)
 
 void CheckKernel(unsigned long addr, unsigned long magic)
 {
-       if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
-       {
-               printk("Your boot loader does not support multiboot.\n");
-               while(1);
-       }
+    if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
+    {
+        printk("Your boot loader does not support multiboot.\n");
+        while(1);
+    }
 
     multiboot_info_t *mbi = (multiboot_info_t *) addr;
 
-       if( (mbi->flags & 0x47) != 0x47)
-       {
-               printk("Kernel Need More Information\n");
-               while(1);
-       }
+    if( (mbi->flags & 0x47) != 0x47)
+    {
+        printk("Kernel Need More Information\n");
+        while(1);
+    }
 
     init_boot_params(mbi);
 
@@ -68,206 +68,206 @@ void CheckKernel(unsigned long addr, unsigned long magic)
 
 #if 0
 {
-       int i, mmapCount;
-       pmmapItem pMPI;
+    int i, mmapCount;
+    pmmapItem pMPI;
 
-       pMultiBootInfo pMBI = (pMultiBootInfo) addr;
+    pMultiBootInfo pMBI = (pMultiBootInfo) addr;
 
 
     
     {
         printk("mmap_addr %x mmap_length %x\n", pMBI->mmap_addr, pMBI->mmap_length);
-               while(1);
+        while(1);
 
     }
 
 
-       system.boot_device      = pMBI->boot_device;
-
-       /* 分析命令行参数 */
-       parse_cmdline((const char *)pMBI->cmdline);
-
-       system.mmap_addr= pMBI->mmap_addr;
-       system.mmap_size= pMBI->mmap_length;
-       system.mm_lower = pMBI->mem_lower;
-       system.mm_upper = pMBI->mem_upper;
-       system.mm_size          = 0x100000 + (system.mm_upper<<10);
-       // 最大只管理1G的内存
-       if(system.mm_size > MAX_SUPT_PHYMM_SIZE)
-               system.mm_size = MAX_SUPT_PHYMM_SIZE;
-
-       // 重新进行页映射
-       system.page_count       = (system.mm_size >> PAGE_SHIFT);
-       system.pgd              = (unsigned long *) &krnl_end;
-       system.pte_start        = system.pgd + PAGE_ITEMS;
-
-       unsigned long *pde = system.pgd;
-       unsigned long *pte = system.pte_start;
-       unsigned long pde_count = system.page_count/PAGE_ITEMS + 
-                                 (system.page_count%PAGE_ITEMS != 0);
-
-       unsigned long pde_base = KRNLADDR>>22;
-       pde[pde_base] = 7 + va2pa(pte);
-       for(i=pde_base+1; i<(pde_base+pde_count); i++)
-               pde[i] = pde[i-1] + 0x1000;
-       pte[0] = 7;
-       for(i=1; i<system.page_count; i++)
-               pte[i] = pte[i-1] + 0x1000;
-
-       //asm("xchg %bx,%bx");
-       asm("movl %%edx, %%cr3"::"d"(va2pa(pde)));
-
-       system.pte_end          = pte+i;
-       system.pte_end          = (u32*) PAGE_UP(system.pte_end);
-
-       system.page_map         = (pPage)system.pte_end;
-       system.page_bitmap      = PAGE_UP((system.page_map +
-                                       system.page_count));
-       memset((u32)system.page_map, 0,
-               system.page_bitmap-(u32)system.page_map);
-
-       // 初始化伙伴系统的位图
-       unsigned int    bmSize = system.page_count>>1;//bitmap size
-       u32             bmaddr = system.page_bitmap;
-       for(i=0; i<MAX_ORDER; i++)
-       {
-               freeArea[i].map = (unsigned char *)bmaddr;
-               bmSize = (bmSize>>1) + (bmSize%8 != 0);
-               bmaddr += bmSize;
-               bmaddr = ALIGN(bmaddr, sizeof(long));
-       }
-       memset(system.page_bitmap, 0x00, bmaddr - system.page_bitmap);
-
-       system.kernel_end       = PAGE_UP(bmaddr);
-       
-
-
-       mmapCount = system.mmap_size/sizeof(mmapItem);
-       pMPI    = (pmmapItem) system.mmap_addr;
+    system.boot_device    = pMBI->boot_device;
+
+    /* 分析命令行参数 */
+    parse_cmdline((const char *)pMBI->cmdline);
+
+    system.mmap_addr= pMBI->mmap_addr;
+    system.mmap_size= pMBI->mmap_length;
+    system.mm_lower    = pMBI->mem_lower;
+    system.mm_upper    = pMBI->mem_upper;
+    system.mm_size        = 0x100000 + (system.mm_upper<<10);
+    // 最大只管理1G的内存
+    if(system.mm_size > MAX_SUPT_PHYMM_SIZE)
+        system.mm_size = MAX_SUPT_PHYMM_SIZE;
+
+    // 重新进行页映射
+    system.page_count    = (system.mm_size >> PAGE_SHIFT);
+    system.pgd        = (unsigned long *) &krnl_end;
+    system.pte_start    = system.pgd + PAGE_ITEMS;
+
+    unsigned long *pde = system.pgd;
+    unsigned long *pte = system.pte_start;
+    unsigned long pde_count = system.page_count/PAGE_ITEMS + 
+                  (system.page_count%PAGE_ITEMS != 0);
+
+    unsigned long pde_base = KRNLADDR>>22;
+    pde[pde_base] = 7 + va2pa(pte);
+    for(i=pde_base+1; i<(pde_base+pde_count); i++)
+        pde[i] = pde[i-1] + 0x1000;
+    pte[0] = 7;
+    for(i=1; i<system.page_count; i++)
+        pte[i] = pte[i-1] + 0x1000;
+
+    //asm("xchg %bx,%bx");
+    asm("movl %%edx, %%cr3"::"d"(va2pa(pde)));
+
+    system.pte_end        = pte+i;
+    system.pte_end        = (u32*) PAGE_UP(system.pte_end);
+
+    system.page_map        = (pPage)system.pte_end;
+    system.page_bitmap    = PAGE_UP((system.page_map +
+                    system.page_count));
+    memset((u32)system.page_map, 0,
+        system.page_bitmap-(u32)system.page_map);
+
+    // 初始化伙伴系统的位图
+    unsigned int    bmSize = system.page_count>>1;//bitmap size
+    u32        bmaddr = system.page_bitmap;
+    for(i=0; i<MAX_ORDER; i++)
+    {
+        freeArea[i].map = (unsigned char *)bmaddr;
+        bmSize = (bmSize>>1) + (bmSize%8 != 0);
+        bmaddr += bmSize;
+        bmaddr = ALIGN(bmaddr, sizeof(long));
+    }
+    memset(system.page_bitmap, 0x00, bmaddr - system.page_bitmap);
+
+    system.kernel_end    = PAGE_UP(bmaddr);
+    
+
+
+    mmapCount = system.mmap_size/sizeof(mmapItem);
+    pMPI    = (pmmapItem) system.mmap_addr;
 
 #if 1
-       printk("mm_size: %d MB\n", system.mm_size>>20);
-       printk("page_count:%d page_map:%08x page_bitmap:%08x\n",
-               system.page_count, system.page_map, system.page_bitmap);
-       printk("boot device: %x\n", (unsigned int)system.boot_device);
-       printk("CmdLine: %s\n", system.cmdline);
-       printk("mmap count: %d\n", mmapCount);
+    printk("mm_size: %d MB\n", system.mm_size>>20);
+    printk("page_count:%d page_map:%08x page_bitmap:%08x\n",
+        system.page_count, system.page_map, system.page_bitmap);
+    printk("boot device: %x\n", (unsigned int)system.boot_device);
+    printk("CmdLine: %s\n", system.cmdline);
+    printk("mmap count: %d\n", mmapCount);
 #endif
 
 
-       // 初始化空闲页链表头
-       for(i=0; i<MAX_ORDER; i++)
-               INIT_LIST_HEAD(&freeArea[i].freeList);
-
-       // 初始化描述每个页的结构体
-       for(i=0; i<system.page_count; i++)
-       {
-               INIT_LIST_HEAD(&pgmap[i].list);
-               pgmap[i].mapNR = i;
-               pgmap[i].count = 0;
-       }
-
-       for(i=0; i<mmapCount; i++, pMPI++)
-       {
-               // unsupport high part
-               u32 base        = pMPI->base_addr_low;
-               u32 length      = pMPI->length_low;
-               u32 type        = pMPI->type;
-
-
-               printk("--%08x %08x %02x\n", base, length, type);
-
-
-               if(type == E820_RAM)
-               {
-                       if((base+length)>MAX_SUPT_PHYMM_SIZE)
-                       {
-                               length = MAX_SUPT_PHYMM_SIZE - base;
-                       }
-
-                       if(base < va2pa(system.kernel_end)
-                       && va2pa(system.kernel_end) < base+length)
-                       {
-                               unsigned int offset;
-                               offset = va2pa(PAGE_UP(system.kernel_end)) - base;
-                               base += offset;
-                               length -= offset;
-                       }
-                       if(base == 0)
-                       {
-                               if(length < 0x1000)
-                                       continue;
-                               base += 0x1000;
-                               length -= 0x1000;
-                       }
-                       printk("base:%08x length:%08x addr:%08x\n",
-                       base, length, base+length);
-
-                       init_free_area(base, length);
-               }
-       }
+    // 初始化空闲页链表头
+    for(i=0; i<MAX_ORDER; i++)
+        INIT_LIST_HEAD(&freeArea[i].freeList);
+
+    // 初始化描述每个页的结构体
+    for(i=0; i<system.page_count; i++)
+    {
+        INIT_LIST_HEAD(&pgmap[i].list);
+        pgmap[i].mapNR = i;
+        pgmap[i].count = 0;
+    }
+
+    for(i=0; i<mmapCount; i++, pMPI++)
+    {
+        // unsupport high part
+        u32 base    = pMPI->base_addr_low;
+        u32 length    = pMPI->length_low;
+        u32 type    = pMPI->type;
+
+
+        printk("--%08x %08x %02x\n", base, length, type);
+
+
+        if(type == E820_RAM)
+        {
+            if((base+length)>MAX_SUPT_PHYMM_SIZE)
+            {
+                length = MAX_SUPT_PHYMM_SIZE - base;
+            }
+
+            if(base < va2pa(system.kernel_end)
+            && va2pa(system.kernel_end) < base+length)
+            {
+                unsigned int offset;
+                offset = va2pa(PAGE_UP(system.kernel_end)) - base;
+                base += offset;
+                length -= offset;
+            }
+            if(base == 0)
+            {
+                if(length < 0x1000)
+                    continue;
+                base += 0x1000;
+                length -= 0x1000;
+            }
+            printk("base:%08x length:%08x addr:%08x\n",
+            base, length, base+length);
+
+            init_free_area(base, length);
+        }
+    }
 }
 
 int get_order(unsigned int min_pfn, unsigned int max_pfn)
 {
-       int i, order, size;
+    int i, order, size;
 
-       assert(min_pfn<=max_pfn);
-       for(i=order=0; i<MAX_ORDER; i++)
-       {
-               if(min_pfn % (1UL<<i) == 0)
-                       order = i;
-       }
+    assert(min_pfn<=max_pfn);
+    for(i=order=0; i<MAX_ORDER; i++)
+    {
+        if(min_pfn % (1UL<<i) == 0)
+            order = i;
+    }
 
-       size = 1UL<<order;
+    size = 1UL<<order;
 
-       while(min_pfn+size>max_pfn)
-       {
-               order--;
-               size >>= 1;
-       }
+    while(min_pfn+size>max_pfn)
+    {
+        order--;
+        size >>= 1;
+    }
 
-       return order;
+    return order;
 }
 
-void   init_free_area(u32 base, u32 len)
+void    init_free_area(u32 base, u32 len)
 {
-       unsigned int max_pfn, min_pfn;
-       unsigned int i,order,size;
+    unsigned int max_pfn, min_pfn;
+    unsigned int i,order,size;
 
-       min_pfn = get_pfn(base);
-       max_pfn = get_pfn(base+len);
+    min_pfn = get_pfn(base);
+    max_pfn = get_pfn(base+len);
 /*
-       printk("%08x\t%08x\t%x\t%x\t%x\t%d\n",base, base+len, 
-                                       min_pfn, max_pfn,
-                                       max_pfn-min_pfn,
-                                       max_pfn-min_pfn);
+    printk("%08x\t%08x\t%x\t%x\t%x\t%d\n",base, base+len, 
+                    min_pfn, max_pfn,
+                    max_pfn-min_pfn,
+                    max_pfn-min_pfn);
 */
-       assert(min_pfn<=system.page_count);
-       assert(max_pfn<=system.page_count);
+    assert(min_pfn<=system.page_count);
+    assert(max_pfn<=system.page_count);
 
-       while(min_pfn != max_pfn)
-       {
-               order = get_order(min_pfn, max_pfn);
-               //printk("min:%05d end:%05d max:%05d order:%02d\n",
-               //      min_pfn, min_pfn+(1<<order), max_pfn, order);
+    while(min_pfn != max_pfn)
+    {
+        order = get_order(min_pfn, max_pfn);
+        //printk("min:%05d end:%05d max:%05d order:%02d\n",
+        //    min_pfn, min_pfn+(1<<order), max_pfn, order);
 
-               //order = (order>=MAX_ORDER)? MAX_ORDER-1: order;
-               assert(0<=order && order<MAX_ORDER);
+        //order = (order>=MAX_ORDER)? MAX_ORDER-1: order;
+        assert(0<=order && order<MAX_ORDER);
 
-               size = 1<<order;
+        size = 1<<order;
 
-               pgmap[min_pfn].order = order;
-               list_add(&pgmap[min_pfn].list, &freeArea[order].freeList);
+        pgmap[min_pfn].order = order;
+        list_add(&pgmap[min_pfn].list, &freeArea[order].freeList);
 
-               change_bit(pgmap[min_pfn].mapNR>>(order+1),
-                               (unsigned long *)freeArea[order].map);
+        change_bit(pgmap[min_pfn].mapNR>>(order+1),
+                (unsigned long *)freeArea[order].map);
 
-               //printk("%d\t%08x %d\t",pgmap[min_pfn].mapNR>>(order+1),
-               //                      freeArea[order].map, min_pfn);
-               min_pfn += size;
-               //printk("%d\t%d\t%d\t%d\n",min_pfn, max_pfn, order, size);
-               //int j=3000000;while(j--);
-       }
+        //printk("%d\t%08x %d\t",pgmap[min_pfn].mapNR>>(order+1),
+        //            freeArea[order].map, min_pfn);
+        min_pfn += size;
+        //printk("%d\t%d\t%d\t%d\n",min_pfn, max_pfn, order, size);
+        //int j=3000000;while(j--);
+    }
 }
 #endif
index 39d9c12716c0b1125364c368cea47d422ac86beb..2937e01c76182d1a5b8eeecb77b222e94e3afafb 100644 (file)
@@ -1,36 +1,36 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        cmdline.c
+ *   File Name: cmdline.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Feb 17 17:11:37 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Feb 17 17:11:37 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<fs.h>
-#include<printk.h>
-#include<system.h>
-#include<string.h>
-#include<stdlib.h>
+#include <fs.h>
+#include <printk.h>
+#include <system.h>
+#include <string.h>
+#include <stdlib.h>
 
 void get_variable_value(const char *name, char *value);
 
 void parse_root_dev()
 {
-       char    value[128];
-       int     n;
-       get_variable_value("root", value);
+    char    value[128];
+    int    n;
+    get_variable_value("root", value);
 
-       /* 目前只支持通道一的一个硬盘 */
+    /* 目前只支持通道一的一个硬盘 */
     /*
     printk("D:%s\n", value);
-       assert( value[0] == '(' &&
-               value[1] == 'h' &&
-               value[2] == 'd' &&
-               value[3] == '0' &&
-               value[4] == ',');
+    assert(    value[0] == '(' &&
+        value[1] == 'h' &&
+        value[2] == 'd' &&
+        value[3] == '0' &&
+        value[4] == ',');
     */
     value[0] = '(';
     value[1] = 'h';
@@ -40,74 +40,74 @@ void parse_root_dev()
     value[5] = ',';
     value[6] = '0';
     value[7] = '\0';
-       n = atoi(value+5);
+    n = atoi(value+5);
 
-       system.root_dev = MAKE_DEV(DEV_MAJOR_HD, n+1);
+    system.root_dev = MAKE_DEV(DEV_MAJOR_HD, n+1);
 }
 void parse_debug()
 {
-       char value[128];
-       int n;
-       get_variable_value("debug", value);
-       n = atoi(value);
+    char value[128];
+    int n;
+    get_variable_value("debug", value);
+    n = atoi(value);
 
-       system.debug = (n != 0);
+    system.debug = (n != 0);
 }
 
 
 void parse_cmdline(char *cmdline)
 {
-       system.cmdline = cmdline;
-       printk("cmdline: %s\n", system.cmdline);
-       parse_root_dev();
-       parse_debug();
+    system.cmdline = cmdline;
+    printk("cmdline: %s\n", system.cmdline);
+    parse_root_dev();
+    parse_debug();
 #if 0
-       get_variable_value("root", value);
-       printk("root : %s\n", value, n);
-       get_variable_value("debug", value);
-       n = atoi(value);
-       printk("debug : %s %d\n", value, n);
-       while(1);
+    get_variable_value("root", value);
+    printk("root : %s\n", value, n);
+    get_variable_value("debug", value);
+    n = atoi(value);
+    printk("debug : %s %d\n", value, n);
+    while(1);
 #endif
 }
 
 
 void get_variable_value(const char *name, char *value)
 {
-       char *p = system.cmdline;
-       char buf[256];
-       int  i;
-       *value = 0;
+    char *p = system.cmdline;
+    char buf[256];
+    int  i;
+    *value = 0;
 
-       while(*p)
-       {
-               while(*p != ' ')
-               {
-                       if(*p++ == 0)
-                               return;
-               }
-               p++;
-               i = 0;
-               while(*p != '=' && *p != 0)
-                       buf[i++] = *p++;
-               if(*p++ == 0)
-                       return;
-               buf[i] = 0;
-               //printk("%s %s %d\n",buf, name, strcmp(buf, name));
+    while(*p)
+    {
+        while(*p != ' ')
+        {
+            if(*p++ == 0)
+                return;
+        }
+        p++;
+        i = 0;
+        while(*p != '=' && *p != 0)
+            buf[i++] = *p++;
+        if(*p++ == 0)
+            return;
+        buf[i] = 0;
+        //printk("%s %s %d\n",buf, name, strcmp(buf, name));
 
-               if(strcmp(buf, name) != 0)
-               {
-                       while(*p != ' ' && *p != 0)
-                               p++;
-                       continue;
-               }
+        if(strcmp(buf, name) != 0)
+        {
+            while(*p != ' ' && *p != 0)
+                p++;
+            continue;
+        }
 
-               i = 0;
-               while(*p != ' ' && *p != 0)
-                       value[i++] = *p++;
-               value[i] = 0;
-               //printk("DD %s", value);
-               return ;
-       }
+        i = 0;
+        while(*p != ' ' && *p != 0)
+            value[i++] = *p++;
+        value[i] = 0;
+        //printk("DD %s", value);
+        return ;
+    }
 
 }
index f8ad7e76e8f887130f1102fafbbc733f94ec6a7c..2c98aa9be7e84e5f1ea688430002ecb8ff39bfff 100644 (file)
@@ -14,8 +14,8 @@
  *--------------------------------------------------------------------------
  */
 #define ASM
-#include"boot/boot.h"
-#include"system.h"
+#include "boot/boot.h"
+#include "system.h"
 .global _start
 .extern CheckKernel
 .extern SetupKernel
index 72a30cca65af00c3e66e9f564d321f18fbddb14e..6dcd94d8e1d365e16e988e96b57cfc6d81475504 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        reboot.S
+ *   File Name: reboot.S
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sat Jul 11 19:16:42 2009
  * Last Update: Sat Jul 11 19:16:42 2009
  * 
  *--------------------------------------------------------------------------
  */
-#define        ASM
-#include<system.h>
+#define ASM
+#include <system.h>
 .global do_restart
-.global        do_reboot
-.global        do_poweroff
-.extern        printk
+.global    do_reboot
+.global    do_poweroff
+.extern    printk
 .text
 .code32
 .align 32
 do_restart:
 do_reboot:
-       movl    $REBOOT_RESTART,RebootFlag
-       pushl   $msgReboot
-       call    printk
-       addl    $4,%esp
-       jmp     _do_reboot
-msgReboot:     .asciz  "Rebooting ..........."
+    movl    $REBOOT_RESTART,RebootFlag
+    pushl    $msgReboot
+    call    printk
+    addl    $4,%esp
+    jmp    _do_reboot
+msgReboot:    .asciz    "Rebooting ..........."
 do_poweroff:
-       movl    $REBOOT_POWEROFF,RebootFlag
-       pushl   $msgPowerOff
-       call    printk
-       addl    $4,%esp
-       jmp     _do_reboot
-msgPowerOff:   .asciz  "Shutdown System......"
+    movl    $REBOOT_POWEROFF,RebootFlag
+    pushl    $msgPowerOff
+    call    printk
+    addl    $4,%esp
+    jmp    _do_reboot
+msgPowerOff:    .asciz    "Shutdown System......"
 
 _do_reboot:
-       # Disable All Interrupts
-       cli
+    # Disable All Interrupts
+    cli
 
-       # Write to CMOS
-       movb    $0x8F,%al
-       movw    $0x70,%dx
-       outb    %al,%dx
-       movb    $0x00,%al
-       movw    $0x71,%dx
-       outb    %al,%dx
+    # Write to CMOS
+    movb    $0x8F,%al
+    movw    $0x70,%dx
+    outb    %al,%dx
+    movb    $0x00,%al
+    movw    $0x71,%dx
+    outb    %al,%dx
 
 
-       # Prepare Paging For Reboot 
-       movl    $256,%ecx
-       movl    $0x100C00,%esi
-       movl    $0x100000,%edi
-       rep
-       movsl
+    # Prepare Paging For Reboot 
+    movl    $256,%ecx
+    movl    $0x100C00,%esi
+    movl    $0x100000,%edi
+    rep
+    movsl
 
 
-       # Modify 'jmp' Instruction In Real Mode Code
-       cmpl    $REBOOT_POWEROFF,RebootFlag
-       je      1f
-       cmpl    $REBOOT_RESTART,RebootFlag
-       je      2f
+    # Modify 'jmp' Instruction In Real Mode Code
+    cmpl    $REBOOT_POWEROFF,RebootFlag
+    je    1f
+    cmpl    $REBOOT_RESTART,RebootFlag
+    je    2f
 1:
-       movl    $JUMPEND,%ecx
-       subl    $JUMPBEGIN,%ecx
-       movl    $JUMPBEGIN,%edi
-       movb    $0x90,%al
-       rep
-       stosb
+    movl    $JUMPEND,%ecx
+    subl    $JUMPBEGIN,%ecx
+    movl    $JUMPBEGIN,%edi
+    movb    $0x90,%al
+    rep
+    stosb
 
 2:
-       # Copy The Real Mode Code to Low Memory
-       movl    $Code16End,%ecx
-       subl    $Code16,%ecx
-       movl    $Code16,%esi
-       movl    $0x1000,%edi
-       rep
-       movsb
+    # Copy The Real Mode Code to Low Memory
+    movl    $Code16End,%ecx
+    subl    $Code16,%ecx
+    movl    $Code16,%esi
+    movl    $0x1000,%edi
+    rep
+    movsb
 
-       # Reload CR3
-       #movl   $0x100000,%eax
-       #movl   %eax,%cr3
+    # Reload CR3
+    #movl    $0x100000,%eax
+    #movl    %eax,%cr3
 
-       # Set Reboot Mode
-       # 0x1234 For Warm Reboot
-       # 0x0000 For Cold Reboot
-       movw    $0x1234,(0x472)
+    # Set Reboot Mode
+    # 0x1234 For Warm Reboot
+    # 0x0000 For Cold Reboot
+    movw    $0x1234,(0x472)
 
-       lidt    IDTR
-       lgdt    GDTR
+    lidt    IDTR
+    lgdt    GDTR
 
-       movl    $0x10,%eax
-       movw    %ax,%ds
-       movw    %ax,%es
-       movw    %ax,%fs
-       movw    %ax,%gs
-       movw    %ax,%ss
+    movl    $0x10,%eax
+    movw    %ax,%ds
+    movw    %ax,%es
+    movw    %ax,%fs
+    movw    %ax,%gs
+    movw    %ax,%ss
 
-       # Jump to Real Mode Code
-       ljmp    $0x0008,$0x1000
+    # Jump to Real Mode Code
+    ljmp    $0x0008,$0x1000
 
 RebootGDT:
-EMPT:  .long   0x00000000,0x00000000
-Code:  .long   0x0000FFFF,0x00009A00
-Data:  .long   0x0000FFFF,0x00009200
+EMPT:    .long    0x00000000,0x00000000
+Code:    .long    0x0000FFFF,0x00009A00
+Data:    .long    0x0000FFFF,0x00009200
 RebootGDTEnd:
 GDTR:
-       GDTRLimit:      .word   RebootGDTEnd-RebootGDT
-       GDTRBase:       .long   RebootGDT
+    GDTRLimit:    .word    RebootGDTEnd-RebootGDT
+    GDTRBase:    .long    RebootGDT
 IDTR:
-       IDTRLimit:      .word   0x3FF
-       IDTRBase:       .long   0x0
-RebootFlag:    .long   REBOOT_RESTART
-.align 16
+    IDTRLimit:    .word    0x3FF
+    IDTRBase:    .long    0x0
+RebootFlag:    .long    REBOOT_RESTART
+.align    16
 .code16
 Code16:
-       movl    %cr0,%eax
-       andl    $0x00000011,%eax
-       orl     $0x60000000,%eax
-       movl    %eax,%cr0
-       movl    %eax,%cr3
-       movl    %cr0,%ebx
-       andl    $0x60000000,%ebx
-       jz      1f
-       invd
+    movl    %cr0,%eax
+    andl    $0x00000011,%eax
+    orl    $0x60000000,%eax
+    movl    %eax,%cr0
+    movl    %eax,%cr3
+    movl    %cr0,%ebx
+    andl    $0x60000000,%ebx
+    jz    1f
+    invd
 1:
-       andb    $0x10,%al
-       movl    %eax,%cr0
+    andb    $0x10,%al
+    movl    %eax,%cr0
 
-       # The Jump Instruction Will be Set 'nop' If Need Reboot.
+    # The Jump Instruction Will be Set 'nop' If Need Reboot.
 JUMPBEGIN:
-       jmp     REBOOT
+    jmp    REBOOT
 JUMPEND:
 
 SHUTDOWN:
-       movw    $0x1000,%ax
-       movw    %ax,%ss
-       movw    $0xF000,%sp
-       movw    $0x5307,%ax
-       movw    $0x0001,%bx
-       movw    $0x0003,%cx
-       int     $0x15
+    movw    $0x1000,%ax
+    movw    %ax,%ss
+    movw    $0xF000,%sp
+    movw    $0x5307,%ax
+    movw    $0x0001,%bx
+    movw    $0x0003,%cx
+    int    $0x15
 REBOOT:
-       ljmp    $0xFFFF,$0x0000
+    ljmp    $0xFFFF,$0x0000
 Code16End:
index 0e47b48c3220758a9782a166179b813bf10508b9..41b12f88bd4ba60034b314b19cfb2ddb271fd1cd 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        hd.c
+ *   File Name: hd.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Mon Feb  1 15:26:55 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Mon Feb  1 15:26:55 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<io.h>
-#include<hd.h>
-#include<irq.h>
-#include<system.h>
-//void hd_handler(pPtRegs regs, unsigned int irq)
-void   hd_handler(unsigned int irq, pPtRegs regs, void *dev_id)
+#include <io.h>
+#include <hd.h>
+#include <irq.h>
+#include <system.h>
+//void    hd_handler(pPtRegs regs, unsigned int irq)
+void    hd_handler(unsigned int irq, pPtRegs regs, void *dev_id)
 {
-       printk("hd_handler:%d ", irq);
+    printk("hd_handler:%d ", irq);
 }
 
-int    hd_controller_ready(Dev dev)
+int    hd_controller_ready(Dev dev)
 {
-       int retries = 0x1000;
+    int retries = 0x1000;
 
-       do
-       {
-               if(hd_rdy(dev))
-                       return 1;
-       }while(--retries);
+    do
+    {
+        if(hd_rdy(dev))
+            return 1;
+    }while(--retries);
 
-       return 0;
+    return 0;
 }
 
-void   hd_controller_reset(unsigned int dev)
+void    hd_controller_reset(unsigned int dev)
 {
-       outb(HD_CTL_RESET,      REG_CTL(dev));
+    outb(HD_CTL_RESET,    REG_CTL(dev));
 /*
-       //outb(HD_CTL_RESET,    REG_CTL(dev));
-       while(1)
-       {
-               printk("%02x ", inb(REG_STATUS(dev)));
-       }
-       while(hd_bsy(dev))
-       {
-               printk("bsy");
-       }
+    //outb(HD_CTL_RESET,    REG_CTL(dev));
+    while(1)
+    {
+        printk("%02x ", inb(REG_STATUS(dev)));
+    }
+    while(hd_bsy(dev))
+    {
+        printk("bsy");
+    }
 */
 }
 
-void   hd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
+void    hd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
 {
-       assert(nsect > 0);
-       assert(HD_GET_DEV(dev) < 2);    // 0: ata-master 1:ata-slave
+    assert(nsect > 0);
+    assert(HD_GET_DEV(dev) < 2);    // 0: ata-master 1:ata-slave
 
-       unsigned char device = 0xE0;
-       device |= ((HD_GET_DEV(dev)) << 4);
+    unsigned char device = 0xE0;
+    device |= ((HD_GET_DEV(dev)) << 4);
 
-       if(!hd_controller_ready(dev))
-       {
-               return ;
-       }
+    if(!hd_controller_ready(dev))
+    {
+        return ;
+    }
 
-       if(system.debug)
-       {
-               hd_controller_reset(dev);
-       }
+    if(system.debug)
+    {
+        hd_controller_reset(dev);
+    }
 
-       outb(0x00,                              REG_CTL(dev));
-       outb(0x00,                              REG_FEATURES(dev));
-       outb((u8)nsect,                         REG_NSECTOR(dev));
+    outb(0x00,                REG_CTL(dev));
+    outb(0x00,                REG_FEATURES(dev));
+    outb((u8)nsect,                REG_NSECTOR(dev));
 #ifdef USE_LBA_48
-       /* 
-        * LBA-48 bit
-        * 先写高位.再写低位.
-        */
-       outb((u8)((sect_nr>>0x18)&0xFF),        REG_LBAL(dev));
-       outb((u8)((sect_nr>>0x20)&0xFF),        REG_LBAM(dev));
-       outb((u8)((sect_nr>>0x28)&0xFF),        REG_LBAH(dev));
-
-       outb((u8)((sect_nr>>0x00)&0xFF),        REG_LBAL(dev));
-       outb((u8)((sect_nr>>0x08)&0xFF),        REG_LBAM(dev));
-       outb((u8)((sect_nr>>0x10)&0xFF),        REG_LBAH(dev));
+    /* 
+     * LBA-48 bit
+     * 先写高位.再写低位.
+     */
+    outb((u8)((sect_nr>>0x18)&0xFF),    REG_LBAL(dev));
+    outb((u8)((sect_nr>>0x20)&0xFF),    REG_LBAM(dev));
+    outb((u8)((sect_nr>>0x28)&0xFF),    REG_LBAH(dev));
+
+    outb((u8)((sect_nr>>0x00)&0xFF),    REG_LBAL(dev));
+    outb((u8)((sect_nr>>0x08)&0xFF),    REG_LBAM(dev));
+    outb((u8)((sect_nr>>0x10)&0xFF),    REG_LBAH(dev));
 #else
-       outb((u8)((sect_nr>>0x00)&0xFF),        REG_LBAL(dev));
-       outb((u8)((sect_nr>>0x08)&0xFF),        REG_LBAM(dev));
-       outb((u8)((sect_nr>>0x10)&0xFF),        REG_LBAH(dev));
-#endif 
-       outb((u8)device,                        REG_DEVICE(dev));
-       outb((u8)cmd,                           REG_CMD(dev));
+    outb((u8)((sect_nr>>0x00)&0xFF),    REG_LBAL(dev));
+    outb((u8)((sect_nr>>0x08)&0xFF),    REG_LBAM(dev));
+    outb((u8)((sect_nr>>0x10)&0xFF),    REG_LBAH(dev));
+#endif    
+    outb((u8)device,            REG_DEVICE(dev));
+    outb((u8)cmd,                REG_CMD(dev));
 }
 
-void   _hd_read(Dev dev, u64 sect_nr, void *buf, u32 count, u32 cmd)
+void    _hd_read(Dev dev, u64 sect_nr, void *buf, u32 count, u32 cmd)
 {
-       u32     device;
-       u32     nsect;
-       u32     retires = 100;
+    u32    device;
+    u32    nsect;
+    u32    retires = 100;
 
-       nsect   = (count + SECT_SIZE -1)/SECT_SIZE;
+    nsect    = (count + SECT_SIZE -1)/SECT_SIZE;
 
-       do
-       {
-               hd_out(dev, nsect,  sect_nr, cmd);
+    do
+    {
+        hd_out(dev, nsect,  sect_nr, cmd);
 
-               int drq_retires = 100000;
-               while(!hd_drq(dev) && --drq_retires)
-                       /* do nothing */;
+        int drq_retires = 100000;
+        while(!hd_drq(dev) && --drq_retires)
+            /* do nothing */;
 
-               if(drq_retires != 0)
-                       break;
-       }while(--retires);
+        if(drq_retires != 0)
+            break;
+    }while(--retires);
 
-       if(retires == 0)
-               panic("hard disk is not ready");
+    if(retires == 0)
+        panic("hard disk is not ready");
 
-       hd_rd_data(dev, buf, count);
+    hd_rd_data(dev, buf, count);
 }
 
 
-void   hd_read(Dev dev, u64 sect_nr, void *buf, u32 count)
+void    hd_read(Dev dev, u64 sect_nr, void *buf, u32 count)
 {
-       _hd_read(dev, sect_nr, buf, count, HD_CMD_READ_EXT);
+    _hd_read(dev, sect_nr, buf, count, HD_CMD_READ_EXT);
 }
 
-void   hd_read_identify(Dev dev, void *buf)
+void    hd_read_identify(Dev dev, void *buf)
 {
-       _hd_read(dev, 0, buf, SECT_SIZE, HD_CMD_IDENTIFY);
+    _hd_read(dev, 0, buf, SECT_SIZE, HD_CMD_IDENTIFY);
 }
 
-void   hd_print_identify(const char *buf)
+void    hd_print_identify(const char *buf)
 {
-       char    *p;
-       short   *ident;
-       int     i;
-
-       ident = (short *) buf;
-
-       char    hd_sn[32];      /* 20 bytes */
-       char    hd_model[64];   /* 40 bytes */
-       short   hd_capabilites = ident[49];
-       short   hd_supt_inst_set = ident[83];
-
-       p = (char *) (ident+10);
-       for(i=0; i<20; i++)
-       {
-               hd_sn[i] = p[i];
-       }
-       hd_sn[i] = 0;
-
-       p = (char *) (ident+27);
-       for(i=0; i<40; i++)
-       {
-               hd_model[i] = p[i];
-       }
-       hd_model[i] = 0;
-
-
-       printk("Hard Disk Vendor: %s\n", hd_sn);
-       printk("Hard Disk Model: %s\n", hd_model);
-       printk("Hard Disk Support LBA: %s\n",
-               (hd_capabilites & 0x0200) ? "Yes" : "No");
-       printk("Hard Disk Support LBA-48bit: %s\n",
-               (hd_supt_inst_set & 0x0400) ? "Yes" : "No");
-
-       if(!(hd_supt_inst_set & 0x0400))
-               panic("Your hard disk ");
+    char    *p;
+    short    *ident;
+    int    i;
+
+    ident = (short *) buf;
+
+    char    hd_sn[32];    /* 20 bytes */
+    char    hd_model[64];    /* 40 bytes */
+    short    hd_capabilites = ident[49];
+    short     hd_supt_inst_set = ident[83];
+
+    p = (char *) (ident+10);
+    for(i=0; i<20; i++)
+    {
+        hd_sn[i] = p[i];
+    }
+    hd_sn[i] = 0;
+
+    p = (char *) (ident+27);
+    for(i=0; i<40; i++)
+    {
+        hd_model[i] = p[i];
+    }
+    hd_model[i] = 0;
+
+
+    printk("Hard Disk Vendor: %s\n", hd_sn);
+    printk("Hard Disk Model: %s\n", hd_model);
+    printk("Hard Disk Support LBA: %s\n",
+        (hd_capabilites & 0x0200) ? "Yes" : "No");
+    printk("Hard Disk Support LBA-48bit: %s\n",
+        (hd_supt_inst_set & 0x0400) ? "Yes" : "No");
+
+    if(!(hd_supt_inst_set & 0x0400))
+        panic("Your hard disk ");
 }
 
-void   setup_hd()
+void    setup_hd()
 {
-       if(!system.debug)
-               hd_controller_reset(ROOT_DEV);
-       //hd_controller_reset(1);
-       //return ;
+    if(!system.debug)
+        hd_controller_reset(ROOT_DEV);
+    //hd_controller_reset(1);
+    //return ;
 
-       char *buf;
-       buf = (unsigned char *) get_virt_pages(1);
-       assert(buf != NULL);
+    char *buf;
+    buf = (unsigned char *) get_virt_pages(1);
+    assert(buf != NULL);
 
 #if 1
-       hd_read_identify(ROOT_DEV, buf);
+    hd_read_identify(ROOT_DEV, buf);
 #else
-       outb(0x00, 0x1F1);
-       outb(0x01, 0x1F2);
-       outb(0x00, 0x1F3);
-       outb(0x00, 0x1F4);
-       outb(0x00, 0x1F5);
-       outb(0xE0, 0x1F6);
-       outb(0xEC, 0x1F7);
-       while(!(inb(0x1F7) & 0x08)){}
-       asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
+    outb(0x00, 0x1F1);
+    outb(0x01, 0x1F2);
+    outb(0x00, 0x1F3);
+    outb(0x00, 0x1F4);
+    outb(0x00, 0x1F5);
+    outb(0xE0, 0x1F6);
+    outb(0xEC, 0x1F7);
+    while(!(inb(0x1F7) & 0x08)){}
+    asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
 #endif
-       hd_print_identify(buf);
+    hd_print_identify(buf);
 
-       free_virt_pages(buf);
+    free_virt_pages(buf);
 }
 
 
 
 
 #if 0
-int    hd_controller_ready(unsigned int channel)
+int    hd_controller_ready(unsigned int channel)
 {
-       int retries = 0x1000;
+    int retries = 0x1000;
 
-       do
-       {
-               if(hd_rdy(channel))
-                       return 1;
-       }while(--retries);
+    do
+    {
+        if(hd_rdy(channel))
+            return 1;
+    }while(--retries);
 
-       return 0;
+    return 0;
 }
 
-void   hd_controller_reset(unsigned int channel)
+void    hd_controller_reset(unsigned int channel)
 {
-       outb(HD_CTL_RESET,      REG_CTL(channel));
+    outb(HD_CTL_RESET,    REG_CTL(channel));
 }
 
-void   hd_out(u32 channel, u32 device, u32 nsect, u64 sect_nr, u32 cmd)
+void    hd_out(u32 channel, u32 device, u32 nsect, u64 sect_nr, u32 cmd)
 {
-       assert(device < 2);     // 0: ata-master 1: ata-slave
-       assert(channel < 2);    // PC only support 2 IDE channels
-       assert(nsect > 0);
+    assert(device < 2);    // 0: ata-master 1: ata-slave
+    assert(channel < 2);    // PC only support 2 IDE channels
+    assert(nsect > 0);
 
-       unsigned char dev = (device)?0x10 : 0x00;
-       dev |= 0xE0;
+    unsigned char dev = (device)?0x10 : 0x00;
+    dev |= 0xE0;
 
-       if(!hd_controller_ready(channel))
-               return ;
+    if(!hd_controller_ready(channel))
+        return ;
 
-       outb(0x00,                              REG_CTL(channel));
-       outb(0x00,                              REG_FEATURES(channel));
-       outb((u8)nsect,                         REG_NSECTOR(channel));
+    outb(0x00,                REG_CTL(channel));
+    outb(0x00,                REG_FEATURES(channel));
+    outb((u8)nsect,                REG_NSECTOR(channel));
 #ifdef USE_LBA_48
-       /* 
-        * LBA-48 bit
-        * 先写高位.再写低位.
-        */
-       outb((u8)((sect_nr>>0x18)&0xFF),        REG_LBAL(channel));
-       outb((u8)((sect_nr>>0x20)&0xFF),        REG_LBAM(channel));
-       outb((u8)((sect_nr>>0x28)&0xFF),        REG_LBAH(channel));
-
-       outb((u8)((sect_nr>>0x00)&0xFF),        REG_LBAL(channel));
-       outb((u8)((sect_nr>>0x08)&0xFF),        REG_LBAM(channel));
-       outb((u8)((sect_nr>>0x10)&0xFF),        REG_LBAH(channel));
+    /* 
+     * LBA-48 bit
+     * 先写高位.再写低位.
+     */
+    outb((u8)((sect_nr>>0x18)&0xFF),    REG_LBAL(channel));
+    outb((u8)((sect_nr>>0x20)&0xFF),    REG_LBAM(channel));
+    outb((u8)((sect_nr>>0x28)&0xFF),    REG_LBAH(channel));
+
+    outb((u8)((sect_nr>>0x00)&0xFF),    REG_LBAL(channel));
+    outb((u8)((sect_nr>>0x08)&0xFF),    REG_LBAM(channel));
+    outb((u8)((sect_nr>>0x10)&0xFF),    REG_LBAH(channel));
 #else
-       outb((u8)((sect_nr>>0x00)&0xFF),        REG_LBAL(channel));
-       outb((u8)((sect_nr>>0x08)&0xFF),        REG_LBAM(channel));
-       outb((u8)((sect_nr>>0x10)&0xFF),        REG_LBAH(channel));
-#endif 
-       outb((u8)dev,                           REG_DEVICE(channel));
-       outb((u8)cmd,                           REG_CMD(channel));
+    outb((u8)((sect_nr>>0x00)&0xFF),    REG_LBAL(channel));
+    outb((u8)((sect_nr>>0x08)&0xFF),    REG_LBAM(channel));
+    outb((u8)((sect_nr>>0x10)&0xFF),    REG_LBAH(channel));
+#endif    
+    outb((u8)dev,                REG_DEVICE(channel));
+    outb((u8)cmd,                REG_CMD(channel));
 }
 
-void   _hd_read(u32 dev, u64 sect_nr, void *buf, u32 count, u32 cmd)
+void    _hd_read(u32 dev, u64 sect_nr, void *buf, u32 count, u32 cmd)
 {
-       u32     channel, device;
-       u32     nsect;
-       u32     retires = 100;
+    u32    channel, device;
+    u32    nsect;
+    u32    retires = 100;
 
-       channel = device = 0;   //
+    channel = device = 0;    //
 
-       nsect   = (count + SECT_SIZE -1)/SECT_SIZE;
+    nsect    = (count + SECT_SIZE -1)/SECT_SIZE;
 
-       do
-       {
-               hd_out(channel, device, nsect,  sect_nr, cmd);
+    do
+    {
+        hd_out(channel, device,    nsect,  sect_nr, cmd);
 
-               int drq_retires = 100000;
-               while(!hd_drq(channel) && --drq_retires)
-                       /* do nothing */;
+        int drq_retires = 100000;
+        while(!hd_drq(channel) && --drq_retires)
+            /* do nothing */;
 
-               if(drq_retires != 0)
-                       break;
-       }while(--retires);
+        if(drq_retires != 0)
+            break;
+    }while(--retires);
 
-       if(retires == 0)
-               panic("hard disk is not ready");
+    if(retires == 0)
+        panic("hard disk is not ready");
 
-       hd_rd_data(channel, buf, count);
+    hd_rd_data(channel, buf, count);
 }
 
 
-void   hd_read(u32 dev, u64 sect_nr, void *buf, u32 count)
+void    hd_read(u32 dev, u64 sect_nr, void *buf, u32 count)
 {
-       _hd_read(dev, sect_nr, buf, count, HD_CMD_READ_EXT);
+    _hd_read(dev, sect_nr, buf, count, HD_CMD_READ_EXT);
 }
 
-void   hd_read_identify(u32 dev, void *buf)
+void    hd_read_identify(u32 dev, void *buf)
 {
-       _hd_read(dev, 0, buf, SECT_SIZE, HD_CMD_IDENTIFY);
+    _hd_read(dev, 0, buf, SECT_SIZE, HD_CMD_IDENTIFY);
 }
 
-void   hd_print_identify(const char *buf)
+void    hd_print_identify(const char *buf)
 {
-       char    *p;
-       short   *ident;
-       int     i;
-
-       ident = (short *) buf;
-
-       char    hd_sn[32];      /* 20 bytes */
-       char    hd_model[64];   /* 40 bytes */
-       short   hd_capabilites = ident[49];
-       short   hd_supt_inst_set = ident[83];
-
-       p = (char *) (ident+10);
-       for(i=0; i<20; i++)
-       {
-               hd_sn[i] = p[i];
-       }
-       hd_sn[i] = 0;
-
-       p = (char *) (ident+27);
-       for(i=0; i<40; i++)
-       {
-               hd_model[i] = p[i];
-       }
-       hd_model[i] = 0;
-
-
-       printk("Hard Disk SN: %s\n", hd_sn);
-       printk("Hard Disk Model: %s\n", hd_model);
-       printk("Hard Disk Support LBA: %s\n",
-               (hd_capabilites & 0x0200) ? "Yes" : "No");
-       printk("Hard Disk Support LBA-48bit: %s\n",
-               (hd_supt_inst_set & 0x0400) ? "Yes" : "No");
-
-       if(!(hd_supt_inst_set & 0x0400))
-               panic("Your hard disk ");
+    char    *p;
+    short    *ident;
+    int    i;
+
+    ident = (short *) buf;
+
+    char    hd_sn[32];    /* 20 bytes */
+    char    hd_model[64];    /* 40 bytes */
+    short    hd_capabilites = ident[49];
+    short     hd_supt_inst_set = ident[83];
+
+    p = (char *) (ident+10);
+    for(i=0; i<20; i++)
+    {
+        hd_sn[i] = p[i];
+    }
+    hd_sn[i] = 0;
+
+    p = (char *) (ident+27);
+    for(i=0; i<40; i++)
+    {
+        hd_model[i] = p[i];
+    }
+    hd_model[i] = 0;
+
+
+    printk("Hard Disk SN: %s\n", hd_sn);
+    printk("Hard Disk Model: %s\n", hd_model);
+    printk("Hard Disk Support LBA: %s\n",
+        (hd_capabilites & 0x0200) ? "Yes" : "No");
+    printk("Hard Disk Support LBA-48bit: %s\n",
+        (hd_supt_inst_set & 0x0400) ? "Yes" : "No");
+
+    if(!(hd_supt_inst_set & 0x0400))
+        panic("Your hard disk ");
 }
 
-void   setup_hd()
+void    setup_hd()
 {
-       //hd_controller_reset(0);
-       //hd_controller_reset(1);
-       //return ;
+    //hd_controller_reset(0);
+    //hd_controller_reset(1);
+    //return ;
 
-       char *buf;
-       buf = (unsigned char *) get_virt_pages(1);
-       assert(buf != NULL);
+    char *buf;
+    buf = (unsigned char *) get_virt_pages(1);
+    assert(buf != NULL);
 
 #if 1
-       hd_read_identify(ROOT_DEV, buf);
+    hd_read_identify(ROOT_DEV, buf);
 #else
-       outb(0x00, 0x1F1);
-       outb(0x01, 0x1F2);
-       outb(0x00, 0x1F3);
-       outb(0x00, 0x1F4);
-       outb(0x00, 0x1F5);
-       outb(0xE0, 0x1F6);
-       outb(0xEC, 0x1F7);
-       while(!(inb(0x1F7) & 0x08)){}
-       asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
+    outb(0x00, 0x1F1);
+    outb(0x01, 0x1F2);
+    outb(0x00, 0x1F3);
+    outb(0x00, 0x1F4);
+    outb(0x00, 0x1F5);
+    outb(0xE0, 0x1F6);
+    outb(0xEC, 0x1F7);
+    while(!(inb(0x1F7) & 0x08)){}
+    asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
 #endif
-       hd_print_identify(buf);
+    hd_print_identify(buf);
 
-       free_virt_pages(buf);
+    free_virt_pages(buf);
 }
 #endif
 
 
 #if 0
-void   hd_rd_sect(u64 sn, char *buf)
+void    hd_rd_sect(u64 sn, char *buf)
 {
-       int chl = 0;
-       unsigned char dev = 0xE0;
+    int chl = 0;
+    unsigned char dev = 0xE0;
 
-       outb(HD_CTL_RESET,      REG_CTL(chl));
-       outb(HD_CTL_DISABLE_INT,REG_CTL(chl));
-       outb(0x00,              REG_FEATURES(chl));
-       outb(0x01,              REG_NSECTOR(chl));
+    outb(HD_CTL_RESET,    REG_CTL(chl));
+    outb(HD_CTL_DISABLE_INT,REG_CTL(chl));
+    outb(0x00,         REG_FEATURES(chl));
+    outb(0x01,        REG_NSECTOR(chl));
 #if 0
-       outb((sn>>0x00)&0xFF,   REG_LBAL(chl));
-       outb((sn>>0x08)&0xFF,   REG_LBAM(chl));
-       outb((sn>>0x10)&0xFF,   REG_LBAH(chl));
+    outb((sn>>0x00)&0xFF,    REG_LBAL(chl));
+    outb((sn>>0x08)&0xFF,    REG_LBAM(chl));
+    outb((sn>>0x10)&0xFF,    REG_LBAH(chl));
 #endif
 #if 0
-       outb(0x00,      REG_LBAL(chl));
-       outb(0x00,      REG_LBAL(chl));
-       outb(0x00,      REG_LBAM(chl));
-       outb(0x00,      REG_LBAM(chl));
-       outb(0x00,      REG_LBAH(chl));
-       outb(0x00,      REG_LBAH(chl));
+    outb(0x00,    REG_LBAL(chl));
+    outb(0x00,    REG_LBAL(chl));
+    outb(0x00,    REG_LBAM(chl));
+    outb(0x00,    REG_LBAM(chl));
+    outb(0x00,    REG_LBAH(chl));
+    outb(0x00,    REG_LBAH(chl));
 #endif
 #if 1
-       /* 
-        * LBA-48 bit
-        * 先写高位.再写低位.
-        */
-       outb(0x00,                      REG_LBAL(chl));
-       outb(0x00,                      REG_LBAM(chl));
-       outb(0x00,                      REG_LBAH(chl));
-
-       outb(0x00,                      REG_LBAL(chl)); outb(0x00,                      REG_LBAM(chl));
-       outb(0x00,                      REG_LBAH(chl));
+    /* 
+     * LBA-48 bit
+     * 先写高位.再写低位.
+     */
+    outb(0x00,            REG_LBAL(chl));
+    outb(0x00,            REG_LBAM(chl));
+    outb(0x00,            REG_LBAH(chl));
+
+    outb(0x00,            REG_LBAL(chl)); outb(0x00,            REG_LBAM(chl));
+    outb(0x00,            REG_LBAH(chl));
 #endif
 
-       outb(dev,                       REG_DEVICE(chl));
-       outb(HD_CMD_READ_EXT,           REG_CMD(chl));
+    outb(dev,            REG_DEVICE(chl));
+    outb(HD_CMD_READ_EXT,        REG_CMD(chl));
 
-       while(!hd_drq(chl));
+    while(!hd_drq(chl));
 
-       hd_rd_data(chl, buf, SECT_SIZE);
+    hd_rd_data(chl, buf, SECT_SIZE);
 }
 #endif
index 4da59c2053515a03d9e7d90e97b5fa7a42a7890b..e41cb84e1fbe212f03d9a2051673996720e36596 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        hd.h
+ *   File Name: hd.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Tue Feb 10 15:17:57 2009
  * Last Update: Mon Feb 01 21:07:31 2010
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _HD_H
-#define        _HD_H
+#ifndef    _HD_H
+#define _HD_H
 
-#include<types.h>
-#include<printk.h>
-#include<assert.h>
+#include <types.h>
+#include <printk.h>
+#include <assert.h>
 
 #if 0
-#define        HD_CHL0_DATA            0x1F0
-#define        HD_CHL0_ERR             0x1F1
-#define        HD_CHL0_NSECTOR 0x1F2
-#define        HD_CHL0_SECTOR  0x1F3
-#define        HD_CHL0_CYLL            0x1F4
-#define        HD_CHL0_CYLH            0x1F5
-#define        HD_CHL0_CURRENT 0x1F6   /*101nhhhh
-                                n:0--First Hardisk, 1--Second Hardisk.
-                                hhhh: head*/
-#define        HD_STATUS       0x1F7
-#define        HD_CMD          HD_STATUS
+#define HD_CHL0_DATA        0x1F0
+#define HD_CHL0_ERR        0x1F1
+#define HD_CHL0_NSECTOR    0x1F2
+#define HD_CHL0_SECTOR    0x1F3
+#define HD_CHL0_CYLL        0x1F4
+#define HD_CHL0_CYLH        0x1F5
+#define HD_CHL0_CURRENT    0x1F6    /*101nhhhh
+                 n:0--First Hardisk, 1--Second Hardisk.
+                 hhhh: head*/
+#define HD_STATUS    0x1F7
+#define HD_CMD        HD_STATUS
 #endif
 
 
 /* 命令寄存器的起始值 */
-#define        HD_CHL0_CMD_BASE        0x1F0
-#define        HD_CHL1_CMD_BASE        0x170
-
-#define        HD_DATA                 0
-#define        HD_ERR                  1
-#define                HD_ERR_BB               0x80
-#define                HD_ERR_ECC              0x40
-#define                HD_ERR_ID               0x10
-#define                HD_ERR_AC               0x04
-#define                HD_ERR_TK               0x02
-#define                HD_ERR_DM               0x01
-#define        HD_NSECTOR              2
-#define        HD_LBAL                 3
-#define        HD_LBAM                 4
-#define        HD_LBAH                 5
-#define        HD_DEVICE               6
-#define        HD_STATUS               7               /* controller status */
-#define                HD_STATUS_BSY           0x80    /* controller busy */
-#define                HD_STATUS_RDY           0x40    /* drive ready */
-#define                HD_STATUS_WF            0x20    /* write fault */
-#define                HD_STATUS_SC            0x10    /* seek complete */
-#define                HD_STATUS_DRQ           0x08    /* data transfer request */
-#define                HD_STATUS_CRD           0x04    /* correct data */
-#define                HD_STATUS_IDX           0x02    /* index pulse */
-#define                HD_STATUS_ERR           0x01    /* error */
-#define        HD_FEATURES             HD_ERR
-#define        HD_CMD                  HD_STATUS
-#define                HD_CMD_IDLE             0x00
-#define                HD_CMD_RECALIBRATE      0x10
-#define                HD_CMD_READ             0x20    /* read data */
-#define                HD_CMD_READ_EXT         0x24    /* read data (LBA-48 bit)*/
-#define                HD_CMD_WRITE            0x30
-#define                HD_CMD_WRITE_EXT        0x34
-#define                HD_CMD_READ_VERIFY      0x40
-#define                HD_CMD_FORMAT           0x50
-#define                HD_CMD_SEEK             0x70
-#define                HD_CMD_DIAG             0x90
-#define                HD_CMD_SPECIFY          0x91
-#define                HD_CMD_IDENTIFY         0xEC
+#define HD_CHL0_CMD_BASE    0x1F0
+#define HD_CHL1_CMD_BASE    0x170
+
+#define HD_DATA            0
+#define HD_ERR            1
+#define     HD_ERR_BB        0x80
+#define     HD_ERR_ECC        0x40
+#define     HD_ERR_ID        0x10
+#define     HD_ERR_AC        0x04
+#define     HD_ERR_TK        0x02
+#define     HD_ERR_DM        0x01
+#define HD_NSECTOR        2
+#define HD_LBAL            3
+#define HD_LBAM            4
+#define HD_LBAH            5
+#define HD_DEVICE        6
+#define HD_STATUS        7        /* controller status */
+#define     HD_STATUS_BSY        0x80    /* controller busy */
+#define     HD_STATUS_RDY        0x40    /* drive ready */
+#define     HD_STATUS_WF        0x20    /* write fault */
+#define     HD_STATUS_SC        0x10    /* seek complete */
+#define     HD_STATUS_DRQ        0x08    /* data transfer request */
+#define     HD_STATUS_CRD        0x04    /* correct data */
+#define     HD_STATUS_IDX        0x02    /* index pulse */
+#define     HD_STATUS_ERR        0x01    /* error */
+#define HD_FEATURES        HD_ERR
+#define HD_CMD            HD_STATUS
+#define     HD_CMD_IDLE        0x00
+#define     HD_CMD_RECALIBRATE    0x10
+#define     HD_CMD_READ        0x20    /* read data */
+#define     HD_CMD_READ_EXT        0x24    /* read data (LBA-48 bit)*/
+#define     HD_CMD_WRITE        0x30
+#define     HD_CMD_WRITE_EXT    0x34
+#define     HD_CMD_READ_VERIFY    0x40
+#define     HD_CMD_FORMAT        0x50
+#define     HD_CMD_SEEK        0x70
+#define     HD_CMD_DIAG        0x90
+#define     HD_CMD_SPECIFY        0x91
+#define     HD_CMD_IDENTIFY        0xEC
 
 /* 硬盘控制寄存器 */
-#define        HD_CHL0_CTL_BASE        0x3F6
-#define        HD_CHL1_CTL_BASE        0x376
+#define HD_CHL0_CTL_BASE    0x3F6
+#define HD_CHL1_CTL_BASE    0x376
 
-#define        HD_CTL                  0
-#define                HD_CTL_NORETRY          0x80    /* disable access retry */
-#define                HD_CTL_NOECC            0x40    /* disable ecc retry */
-#define                HD_CTL_EIGHTHEADS       0x08    /* more than 8 heads */
-#define                HD_CTL_RESET            0x04    /* reset controller */
-#define                HD_CTL_DISABLE_INT      0x02    /* disable interrupts */
+#define HD_CTL            0
+#define     HD_CTL_NORETRY        0x80    /* disable access retry */
+#define     HD_CTL_NOECC        0x40    /* disable ecc retry */
+#define     HD_CTL_EIGHTHEADS    0x08    /* more than 8 heads */
+#define     HD_CTL_RESET        0x04    /* reset controller */
+#define     HD_CTL_DISABLE_INT    0x02    /* disable interrupts */
 
-#define                HD_GET_CHL(dev)         (0)     /* 暂时还是只支持通道0 */
-#define                HD_GET_DEV(dev)         (0)     /* 暂时还是只支持一个硬盘 */
+#define     HD_GET_CHL(dev)        (0)    /* 暂时还是只支持通道0 */
+#define     HD_GET_DEV(dev)        (0)    /* 暂时还是只支持一个硬盘 */
 
-#define        REG_CMD_BASE(dev, offset)                       \
-       (HD_GET_CHL(dev)?(HD_CHL1_CMD_BASE+offset)      \
-       :                                               \
-       (HD_CHL0_CMD_BASE+offset))
+#define REG_CMD_BASE(dev, offset)            \
+    (HD_GET_CHL(dev)?(HD_CHL1_CMD_BASE+offset)    \
+    :                        \
+    (HD_CHL0_CMD_BASE+offset))
 
-#define        REG_CTL_BASE(dev, offset)                       \
-       (HD_GET_CHL(dev)?(HD_CHL1_CTL_BASE+offset)      \
-       :                                               \
-       (HD_CHL0_CTL_BASE+offset))
+#define REG_CTL_BASE(dev, offset)            \
+    (HD_GET_CHL(dev)?(HD_CHL1_CTL_BASE+offset)    \
+    :                        \
+    (HD_CHL0_CTL_BASE+offset))
 
 #if 1
-#define        REG_DATA(dev)           REG_CMD_BASE(dev, HD_DATA)
-#define        REG_ERR(dev)            REG_CMD_BASE(dev, HD_ERR)
-#define        REG_NSECTOR(dev)        REG_CMD_BASE(dev, HD_NSECTOR)
-#define        REG_LBAL(dev)           REG_CMD_BASE(dev, HD_LBAL)
-#define        REG_LBAM(dev)           REG_CMD_BASE(dev, HD_LBAM)
-#define        REG_LBAH(dev)           REG_CMD_BASE(dev, HD_LBAH)
-#define        REG_DEVICE(dev)         REG_CMD_BASE(dev, HD_DEVICE)
-#define        REG_STATUS(dev)         REG_CMD_BASE(dev, HD_STATUS)
-#define        REG_FEATURES(dev)       REG_CMD_BASE(dev, HD_FEATURES)
-#define        REG_CMD(dev)            REG_CMD_BASE(dev, HD_CMD)
-
-#define        REG_CTL(dev)            REG_CTL_BASE(dev, HD_CTL)
-#else  
-#define        REG_DATA        REG_CMD_BASE(0, HD_DATA)
-#define        REG_ERR         REG_CMD_BASE(0, HD_ERR)
-#define        REG_NSECTOR     REG_CMD_BASE(0, HD_NSECTOR)
-#define        REG_LBAL        REG_CMD_BASE(0, HD_LBAL)
-#define        REG_LBAM        REG_CMD_BASE(0, HD_LBAM)
-#define        REG_LBAH        REG_CMD_BASE(0, HD_LBAH)
-#define        REG_DEVICE      REG_CMD_BASE(0, HD_DEVICE)
-#define        REG_STATUS      REG_CMD_BASE(0, HD_STATUS)
-#define        REG_FEATURES    REG_CMD_BASE(0, HD_FEATURES)
-#define        REG_CMD         REG_CMD_BASE(0, HD_CMD)
-
-#define        REG_CTL         REG_CTL_BASE(0, HD_CTL)
+#define REG_DATA(dev)        REG_CMD_BASE(dev, HD_DATA)
+#define REG_ERR(dev)        REG_CMD_BASE(dev, HD_ERR)
+#define REG_NSECTOR(dev)    REG_CMD_BASE(dev, HD_NSECTOR)
+#define REG_LBAL(dev)        REG_CMD_BASE(dev, HD_LBAL)
+#define REG_LBAM(dev)        REG_CMD_BASE(dev, HD_LBAM)
+#define REG_LBAH(dev)        REG_CMD_BASE(dev, HD_LBAH)
+#define REG_DEVICE(dev)        REG_CMD_BASE(dev, HD_DEVICE)
+#define REG_STATUS(dev)        REG_CMD_BASE(dev, HD_STATUS)
+#define REG_FEATURES(dev)    REG_CMD_BASE(dev, HD_FEATURES)
+#define REG_CMD(dev)        REG_CMD_BASE(dev, HD_CMD)
+
+#define REG_CTL(dev)        REG_CTL_BASE(dev, HD_CTL)
+#else    
+#define REG_DATA    REG_CMD_BASE(0, HD_DATA)
+#define REG_ERR        REG_CMD_BASE(0, HD_ERR)
+#define REG_NSECTOR    REG_CMD_BASE(0, HD_NSECTOR)
+#define REG_LBAL    REG_CMD_BASE(0, HD_LBAL)
+#define REG_LBAM    REG_CMD_BASE(0, HD_LBAM)
+#define REG_LBAH    REG_CMD_BASE(0, HD_LBAH)
+#define REG_DEVICE    REG_CMD_BASE(0, HD_DEVICE)
+#define REG_STATUS    REG_CMD_BASE(0, HD_STATUS)
+#define REG_FEATURES    REG_CMD_BASE(0, HD_FEATURES)
+#define REG_CMD        REG_CMD_BASE(0, HD_CMD)
+
+#define REG_CTL        REG_CTL_BASE(0, HD_CTL)
 #endif
 
 /* 一个扇区包含的字节数 */
-#define        SECT_SIZE       512
+#define SECT_SIZE    512
 
 
 static inline void hd_rd_port(int port, void *buf, unsigned long count)
 {
-       unsigned char *p =(unsigned char *)buf;
-       unsigned char value[4];
-       int i, n;
-       n = (count & 3UL);
-       if(n == 0)
-       {
-               insl(port, p, count>>2);
-       }
-       else
-       {
-               insl(port, p, (count>>2));
-               insl(port, value, 1);
-
-               count -= n;
-               for(i=0; i<n; i++)
-                       p[count+i] = value[i];
-       }
-
-#if 0  
-       unsigned char *p =(unsigned char *)buf;
-       int l, w, b;
-       l = count & (~3UL);
-       w = count - l;
-       b = w & 0x01;
-       w = w - b;
-       printk("l:%d w:%d b:%d\n", l, w, b);
-       if(l)
-       {
-               insl(port, p, l);
-               p += l;
-       }
-       if(w)
-       {
-               insw(port, p+l, w);
-               p += w;
-       }
-       if(b)
-       {
-               insb(port, p+l+w, b);
-       }
+    unsigned char *p =(unsigned char *)buf;
+    unsigned char value[4];
+    int i, n;
+    n = (count & 3UL);
+    if(n == 0)
+    {
+        insl(port, p, count>>2);
+    }
+    else
+    {
+        insl(port, p, (count>>2));
+        insl(port, value, 1);
+
+        count -= n;
+        for(i=0; i<n; i++)
+            p[count+i] = value[i];
+    }
+
+#if 0    
+    unsigned char *p =(unsigned char *)buf;
+    int l, w, b;
+    l = count & (~3UL);
+    w = count - l;
+    b = w & 0x01;
+    w = w - b;
+    printk("l:%d w:%d b:%d\n", l, w, b);
+    if(l)
+    {
+        insl(port, p, l);
+        p += l;
+    }
+    if(w)
+    {
+        insw(port, p+l, w);
+        p += w;
+    }
+    if(b)
+    {
+        insb(port, p+l+w, b);
+    }
 #endif
 #if 0
-       int i, rest;
-       unsigned char *p =(unsigned char *)buf;
+    int i, rest;
+    unsigned char *p =(unsigned char *)buf;
 
-       rest = count & 3UL;
-       count-= rest;
+    rest = count & 3UL;
+    count-= rest;
 
-       printk("count:%d rest:%d\n", count, rest);
+    printk("count:%d rest:%d\n", count, rest);
 
-       insl(port, p, count>>2);
+    insl(port, p, count>>2);
 
-       for(i=0; i<rest; i++)
-               insb(port, p+count+i, 1);
+    for(i=0; i<rest; i++)
+        insb(port, p+count+i, 1);
 #endif
 #if 0
-       if(!(count & 0x3UL))
-       {
-               count >>= 2;
-               insl(port, buf, count-2);
-       }
-       else if(!(count & 0x1UL))
-       {
-               count >>= 1;
-               insw(port, buf, count);
-       }
+    if(!(count & 0x3UL))
+    {
+        count >>= 2;
+        insl(port, buf, count-2);
+    }
+    else if(!(count & 0x1UL))
+    {
+        count >>= 1;
+        insw(port, buf, count);
+    }
 #endif
 }
 
 /* 从硬盘数据端口读取数据 */
-#define        hd_rd_data(dev, buf, count) hd_rd_port(REG_DATA(dev), buf, count)
+#define hd_rd_data(dev, buf, count) hd_rd_port(REG_DATA(dev), buf, count)
 
-#define        hd_bsy(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_BSY))
-#define        hd_rdy(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_RDY))
-#define        hd_drq(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_DRQ))
-#define        hd_err(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_ERR))
+#define hd_bsy(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_BSY))
+#define hd_rdy(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_RDY))
+#define hd_drq(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_DRQ))
+#define hd_err(dev) ((inb(REG_STATUS(dev)) & HD_STATUS_ERR))
 
 
-#define        USE_LBA_48      /* 使用LBA-48bit 模式操作硬盘 */
+#define USE_LBA_48    /* 使用LBA-48bit 模式操作硬盘 */
 
 #endif //_HD_H
index 09fcee451b06a1d6ee0b742ca444c5ce32d9c20e..1d85d88eb15077a0e0984896ecee2dc99b61c46b 100644 (file)
@@ -1,70 +1,70 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        keyboard.h
+ *   File Name: keyboard.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Thu Jul 16 18:39:57 2009
  * Last Update: Thu Jul 16 18:39:57 2009
  * 
  *--------------------------------------------------------------------------
  */
-#include<printk.h>
-#include<system.h>
-#include<syscall.h>
-#include<stdio.h>
-#include<io.h>
+#include <printk.h>
+#include <system.h>
+#include <syscall.h>
+#include <stdio.h>
+#include <io.h>
 
-#define        KBD_BUF_SIZE    256
+#define KBD_BUF_SIZE    256
 static struct
 {
-       unsigned int count;
-       unsigned int head,tail;
-       unsigned char buf[KBD_BUF_SIZE];
+    unsigned int count;
+    unsigned int head,tail;
+    unsigned char buf[KBD_BUF_SIZE];
 } kbd_buf;
-#define        count   kbd_buf.count
-#define        head    kbd_buf.head
-#define        tail    kbd_buf.tail
-#define        buf     kbd_buf.buf
+#define count    kbd_buf.count
+#define head    kbd_buf.head
+#define tail    kbd_buf.tail
+#define buf    kbd_buf.buf
 
 
 
 extern void reboot();
 extern void poweroff();
-void   kbd_handler(unsigned int irq, pPtRegs regs, void *dev_id)
+void    kbd_handler(unsigned int irq, pPtRegs regs, void *dev_id)
 {
-       unsigned char ScanCode;
-       //printk("%s\n", dev_id);
-       ScanCode = inb(0x60);
-       //printk("%02x", ScanCode);
-       if(count < KBD_BUF_SIZE)
-       {
-               count++;
-               buf[tail++] = ScanCode;
-               tail %= KBD_BUF_SIZE;
-       }
+    unsigned char ScanCode;
+    //printk("%s\n", dev_id);
+    ScanCode = inb(0x60);
+    //printk("%02x", ScanCode);
+    if(count < KBD_BUF_SIZE)
+    {
+        count++;
+        buf[tail++] = ScanCode;
+        tail %= KBD_BUF_SIZE;
+    }
 }
 
 inline int getScanCode()
 {
-       unsigned int ScanCode;
-       
-       //while(count <= 0);
-       if(count <= 0) return -1;
+    unsigned int ScanCode;
+    
+    //while(count <= 0);
+    if(count <= 0) return -1;
 
-       ScanCode = buf[head++];
-       head %= KBD_BUF_SIZE;
-       count--;        //很明显这是临界资源但现在只能这样了
+    ScanCode = buf[head++];
+    head %= KBD_BUF_SIZE;
+    count--;    //很明显这是临界资源但现在只能这样了
 
-       return (0xFF & ScanCode);
+    return (0xFF & ScanCode);
 }
 
 
-int    sysc_read_kbd()
+int    sysc_read_kbd()
 {
-       return getScanCode();
+    return getScanCode();
 }
index c27d8204274788c452e3494812368e48366bc323..fcc50e9085c94a52585077c0cd207f0eb825c9ba 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        vga.c
+ *   File Name: vga.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jul 18 23:01:18 2009
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jul 18 23:01:18 2009
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<io.h>
+#include <io.h>
 
-#define        VGA_CRTC_ADDR   0x3D4
-#define        VGA_CRTC_DATA   0x3D5
-#define        VGA_CRTC_START_ADDR_H   0xC
-#define        VGA_CRTC_START_ADDR_L   0xD
-#define        VGA_CRTC_CURSOR_H       0xE
-#define        VGA_CRTC_CURSOR_L       0xF
+#define VGA_CRTC_ADDR    0x3D4
+#define VGA_CRTC_DATA    0x3D5
+#define VGA_CRTC_START_ADDR_H    0xC
+#define VGA_CRTC_START_ADDR_L    0xD
+#define VGA_CRTC_CURSOR_H    0xE
+#define VGA_CRTC_CURSOR_L    0xF
 
 
-#define        LINES_PER_SCREEN        24      //25
-#define        CHARS_PER_LINE          80
-#define        BYTES_PER_LINE          (CHARS_PER_LINE<<1)
-#define        MAX_LINES               (LINES_PER_SCREEN<<1)
-#define        VIDEO_ADDR              0xC00B8000
+#define LINES_PER_SCREEN    24    //25
+#define CHARS_PER_LINE        80
+#define BYTES_PER_LINE        (CHARS_PER_LINE<<1)
+#define MAX_LINES        (LINES_PER_SCREEN<<1)
+#define VIDEO_ADDR        0xC00B8000
 
 static unsigned int xpos, ypos;
 
-void   setCursorPos(unsigned int x, unsigned int y);
-void   printString(const char *buf, unsigned char color);
-void   printChar(const unsigned char c, const unsigned char color);
-void   ScrollUp();
+void    setCursorPos(unsigned int x, unsigned int y);
+void     printString(const char *buf, unsigned char color);
+void    printChar(const unsigned char c, const unsigned char color);
+void    ScrollUp();
 
-void   setCursorPos(unsigned int x, unsigned int y)
+void    setCursorPos(unsigned int x, unsigned int y)
 {
-       unsigned short  offset = x +  y * CHARS_PER_LINE;
-       outb(VGA_CRTC_CURSOR_H, VGA_CRTC_ADDR);
-       outb((offset>>8) & 0xFF,VGA_CRTC_DATA);
-       outb(VGA_CRTC_CURSOR_L, VGA_CRTC_ADDR);
-       outb(offset & 0xFF,     VGA_CRTC_DATA);
+    unsigned short    offset = x +  y * CHARS_PER_LINE;
+    outb(VGA_CRTC_CURSOR_H,    VGA_CRTC_ADDR);
+    outb((offset>>8) & 0xFF,VGA_CRTC_DATA);
+    outb(VGA_CRTC_CURSOR_L,    VGA_CRTC_ADDR);
+    outb(offset & 0xFF,    VGA_CRTC_DATA);
 }
 
-void   printChar(const unsigned char c, const unsigned char color)
+void    printChar(const unsigned char c, const unsigned char color)
 {
-       unsigned short * const pv = (unsigned short * const) VIDEO_ADDR;
-
-       switch(c)
-       {
-       case '\r':
-               xpos = 0;
-               break;
-       case '\n':
-               xpos = 0; ypos++;
-               break;
-       case '\t':
-               xpos &= (~0x07);
-               xpos += 8;
-               if(xpos >= CHARS_PER_LINE)
-               {
-                       xpos = 0;
-                       ypos ++;
-               }
-               break;
-       case '\b':
-               if(xpos > 0)
-                       xpos--;
-               else if(ypos > 0)
-               {
-                       xpos = CHARS_PER_LINE - 1;
-                       ypos --;
-               }
-               *(pv + xpos + ypos*CHARS_PER_LINE) = ' ' | (color << 8);
-               break;
-       default:
-               *(pv + xpos + ypos*CHARS_PER_LINE) = c | (color << 8);
-               xpos ++;
-               if(xpos == CHARS_PER_LINE)
-               {
-                       xpos = 0;
-                       ypos ++;
-               }
-               break;
-       }
-
-       ScrollUp();
-
-       setCursorPos(xpos, ypos);
+    unsigned short * const pv = (unsigned short * const) VIDEO_ADDR;
+
+    switch(c)
+    {
+    case '\r':
+        xpos = 0;
+        break;
+    case '\n':
+        xpos = 0; ypos++;
+        break;
+    case '\t':
+        xpos &= (~0x07);
+        xpos += 8;
+        if(xpos >= CHARS_PER_LINE)
+        {
+            xpos = 0;
+            ypos ++;
+        }
+        break;
+    case '\b':
+        if(xpos > 0)
+            xpos--;
+        else if(ypos > 0)
+        {
+            xpos = CHARS_PER_LINE - 1;
+            ypos --;
+        }
+        *(pv + xpos + ypos*CHARS_PER_LINE) = ' ' | (color << 8);
+        break;
+    default:
+        *(pv + xpos + ypos*CHARS_PER_LINE) = c | (color << 8);
+        xpos ++;
+        if(xpos == CHARS_PER_LINE)
+        {
+            xpos = 0;
+            ypos ++;
+        }
+        break;
+    }
+
+    ScrollUp();
+
+    setCursorPos(xpos, ypos);
 }
 
-void   ScrollUp()
+void    ScrollUp()
 {
-       static unsigned int last_ypos;
-       unsigned short topline;
-       if((ypos >= LINES_PER_SCREEN) && (ypos > last_ypos))
-       {
-               topline = ypos - LINES_PER_SCREEN;
-
-               if(topline == MAX_LINES)
-               {
-
-                       memcpy( VIDEO_ADDR,
-                               VIDEO_ADDR+MAX_LINES*BYTES_PER_LINE,
-                               LINES_PER_SCREEN*BYTES_PER_LINE);
-
-                       unsigned char *p;
-                       const unsigned char *pend;
-                       p=(unsigned char *)
-                       VIDEO_ADDR+LINES_PER_SCREEN*BYTES_PER_LINE;
-                       while(p <=(unsigned char *) VIDEO_ADDR 
-                       + (LINES_PER_SCREEN+MAX_LINES)*BYTES_PER_LINE)
-                       {
-                               *p++ = ' ';
-                               *p++ = 0x0F;
-                       }
-                       ypos -= topline;
-                       topline = 0;
-               }
-               outb(VGA_CRTC_START_ADDR_H,VGA_CRTC_ADDR);
-               outb(((topline*CHARS_PER_LINE)>>8)&0xFF,VGA_CRTC_DATA);
-               outb(VGA_CRTC_START_ADDR_L,VGA_CRTC_ADDR);
-               outb((topline*CHARS_PER_LINE)&0xFF,VGA_CRTC_DATA);
-       }
-       last_ypos = ypos;
+    static unsigned int last_ypos;
+    unsigned short topline;
+    if((ypos >= LINES_PER_SCREEN) && (ypos > last_ypos))
+    {
+        topline = ypos - LINES_PER_SCREEN;
+
+        if(topline == MAX_LINES)
+        {
+
+            memcpy(    VIDEO_ADDR,
+                VIDEO_ADDR+MAX_LINES*BYTES_PER_LINE,
+                LINES_PER_SCREEN*BYTES_PER_LINE);
+
+            unsigned char *p;
+            const unsigned char *pend;
+            p=(unsigned char *)
+            VIDEO_ADDR+LINES_PER_SCREEN*BYTES_PER_LINE;
+            while(p <=(unsigned char *) VIDEO_ADDR 
+            + (LINES_PER_SCREEN+MAX_LINES)*BYTES_PER_LINE)
+            {
+                *p++ = ' ';
+                *p++ = 0x0F;
+            }
+            ypos -= topline;
+            topline = 0;
+        }
+        outb(VGA_CRTC_START_ADDR_H,VGA_CRTC_ADDR);
+        outb(((topline*CHARS_PER_LINE)>>8)&0xFF,VGA_CRTC_DATA);
+        outb(VGA_CRTC_START_ADDR_L,VGA_CRTC_ADDR);
+        outb((topline*CHARS_PER_LINE)&0xFF,VGA_CRTC_DATA);
+    }
+    last_ypos = ypos;
 }
 
-void   printString(const char *buf, unsigned char color)
+void     printString(const char *buf, unsigned char color)
 {
-       char *p = (char *) buf;
+    char *p = (char *) buf;
 
-       while(*p)
-       {
-               printChar(*p, color);
-               p++;
-       }
+    while(*p)
+    {
+        printChar(*p, color);
+        p++;
+    }
 }
index a9f96f24c4a54ac88de1c470124d9a358ab30561..da1ca6d6e08f4aa3dfa08a2523bd056ce0d5c9de 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -1,25 +1,25 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        ext2.c
+ *   File Name: ext2.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Feb 14 15:52:01 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Feb 14 15:52:01 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<fs.h>
-#include<system.h>
-#include<string.h>
-#include<stat.h>
+#include <fs.h>
+#include <system.h>
+#include <string.h>
+#include <stat.h>
 
 unsigned int ext2_start_sect;
-Inode  ext2_root_inode;
+Inode    ext2_root_inode;
 
 extern void hd_read(Dev dev, u64 sect_nr, void *buf, u32 count);
-void   ext2_read_block(int block_id, char *buf);
+void    ext2_read_block(int block_id, char *buf);
 static void ext2_print_group_descriptor(pGroupDesc p);
 static void ext2_print_inode(pInode p);
 int ext2_search_file(const char *file, const pInode in, pInode out);
@@ -27,88 +27,88 @@ int ext2_search_file(const char *file, const pInode in, pInode out);
 
 /* ext2 super block */
 SuperBlock ext2_sb
-       __attribute__((__aligned__(PAGE_SIZE)));
-Inode  inode_table[NR_INODES]
-       __attribute__((__aligned__(PAGE_SIZE))) = {{0,},};
+    __attribute__((__aligned__(PAGE_SIZE)));
+Inode    inode_table[NR_INODES]
+    __attribute__((__aligned__(PAGE_SIZE))) = {{0,},};
 /* 
  * ext2 group descriptor table
  * 其大小为一个EXT2_BLOCK_SIZE
  */
 static pGroupDesc gdesc;
 
-void   setup_ext2()
+void    setup_ext2()
 {
-       int i;
-
-       hd_read(ROOT_DEV, ext2_start_sect+2, EXT2_SB, sizeof(SuperBlock));
-       printk("EXT2 SB:%x\n", sizeof(SuperBlock));
-       printk("inodes count: %d\n", EXT2_SB->s_inodes_count);
-       printk("blocks count: %d\n", EXT2_SB->s_blocks_count);
-       printk("s_magic: %x\n", EXT2_SB->s_magic);
-       printk("LOG BLOCK SIZE:%x\n", EXT2_SB->s_log_block_size);
-       printk("Block Size:%d %x\n", EXT2_BLOCK_SIZE, EXT2_BLOCK_SIZE);
-
-
-       if(EXT2_SB->s_magic != 0xEF53)
-               panic("Only Support Ext2 File System...");
-
-       /* 分配group descriptor table 的内存 */
-       gdesc = (pGroupDesc) kmalloc(EXT2_BLOCK_SIZE);
-       if(gdesc == NULL)
-               panic("out of memory for ext2 group descritpor table");
-       /* 初始化ext2 group descriptor table */
-       ext2_read_block(EXT2_FIRST_BLOCK_ID+1, (char *)gdesc);
+    int i;
+
+    hd_read(ROOT_DEV, ext2_start_sect+2, EXT2_SB, sizeof(SuperBlock));
+    printk("EXT2 SB:%x\n", sizeof(SuperBlock));
+    printk("inodes count: %d\n", EXT2_SB->s_inodes_count);
+    printk("blocks count: %d\n", EXT2_SB->s_blocks_count);
+    printk("s_magic: %x\n", EXT2_SB->s_magic);
+    printk("LOG BLOCK SIZE:%x\n", EXT2_SB->s_log_block_size);
+    printk("Block Size:%d %x\n", EXT2_BLOCK_SIZE, EXT2_BLOCK_SIZE);
+
+
+    if(EXT2_SB->s_magic != 0xEF53)
+        panic("Only Support Ext2 File System...");
+
+    /* 分配group descriptor table 的内存 */
+    gdesc = (pGroupDesc) kmalloc(EXT2_BLOCK_SIZE);
+    if(gdesc == NULL)
+        panic("out of memory for ext2 group descritpor table");
+    /* 初始化ext2 group descriptor table */
+    ext2_read_block(EXT2_FIRST_BLOCK_ID+1, (char *)gdesc);
 #if 0
-       printk("-------%d %d %d",
-               EXT2_BLOCK_SIZE, EXT2_INODE_SIZE, EXT2_INODES_PER_BLOCK);
-       for(i=0; i<12; i++)
-               ext2_print_group_descriptor(gdesc+i);
+    printk("-------%d %d %d",
+        EXT2_BLOCK_SIZE, EXT2_INODE_SIZE, EXT2_INODES_PER_BLOCK);
+    for(i=0; i<12; i++)
+        ext2_print_group_descriptor(gdesc+i);
 #endif
 
-       ext2_read_inode(2, &ext2_root_inode);
+    ext2_read_inode(2, &ext2_root_inode);
 #if 1
-       ext2_print_inode(&ext2_root_inode);
+    ext2_print_inode(&ext2_root_inode);
 #endif
 
 #if 0
-       Inode   boot_ino, grub_ino, grubconf_ino;
-       int     boot_n, grub_n, grubconf_n;
-       boot_n = ext2_search_file("boot", &ext2_root_inode, &boot_ino);
-       printk("boot_n:%d size:%d\n", boot_n, boot_ino.i_size);
-       grub_n = ext2_search_file("grub", &boot_ino, &grub_ino);
-       printk("grub_n:%d size:%d\n", grub_n, grub_ino.i_size);
-       grubconf_n = ext2_search_file("grub.conf",
-                                       &grub_ino, &grubconf_ino);
-       printk("grubconf_n:%d size:%d\n", grubconf_n, grubconf_ino.i_size);
+    Inode    boot_ino, grub_ino, grubconf_ino;
+    int    boot_n, grub_n, grubconf_n;
+    boot_n = ext2_search_file("boot", &ext2_root_inode, &boot_ino);
+    printk("boot_n:%d size:%d\n", boot_n, boot_ino.i_size);
+    grub_n = ext2_search_file("grub", &boot_ino, &grub_ino);
+    printk("grub_n:%d size:%d\n", grub_n, grub_ino.i_size);
+    grubconf_n = ext2_search_file("grub.conf",
+                    &grub_ino, &grubconf_ino);
+    printk("grubconf_n:%d size:%d\n", grubconf_n, grubconf_ino.i_size);
 #endif
 #if 0
-       size_t filesz;
-       char *buf=ext2_loadfile("/boot/grub/grub.conf", &filesz);
+    size_t filesz;
+    char *buf=ext2_loadfile("/boot/grub/grub.conf", &filesz);
 
-       for(i=0; i<filesz; i++)
-               printk("%c", buf[i]);
+    for(i=0; i<filesz; i++)
+        printk("%c", buf[i]);
 #endif
 #if 0
-       unsigned char *p = (char *)kmalloc(EXT2_BLOCK_SIZE);
-       ext2_read_block(0, p);
+    unsigned char *p = (char *)kmalloc(EXT2_BLOCK_SIZE);
+    ext2_read_block(0, p);
 
-       for(i=0; i<512; i++)
-               printk("%02x ", p[i]);
+    for(i=0; i<512; i++)
+        printk("%02x ", p[i]);
 #endif
 #if 0
-       int dly = 0xF000000;
-       while(dly--);
+    int dly = 0xF000000;
+    while(dly--);
 #endif
 }
 
-void   ext2_read_block(int block_id, char *buf)
+void    ext2_read_block(int block_id, char *buf)
 {
-       u64 sect = EXT2_SECT;
-       sect += block_id*EXT2_SECT_PER_BLOCK;
+    u64 sect = EXT2_SECT;
+    sect += block_id*EXT2_SECT_PER_BLOCK;
 
-       //printk("block id: %d sect:%d\n", block_id, sect);
+    //printk("block id: %d sect:%d\n", block_id, sect);
 
-       hd_read(ROOT_DEV, sect, buf, EXT2_BLOCK_SIZE);
+    hd_read(ROOT_DEV, sect, buf, EXT2_BLOCK_SIZE);
 }
 
 
@@ -118,86 +118,86 @@ void      ext2_read_block(int block_id, char *buf)
  * 之前的那个版本写得那是相当的滑稽幼稚.甚至还有大大的BUG.
  * 但是正是这些点滴见证着我的内核的成长.
  */
-int    ext2_read_inode(unsigned int n, pInode ino)
+int    ext2_read_inode(unsigned int n, pInode ino)
 {
-       assert(1<=n && n <= EXT2_INODES_COUNT);
-       if(n == EXT2_BAD_INO) return 0;
+    assert(1<=n && n <= EXT2_INODES_COUNT);
+    if(n == EXT2_BAD_INO) return 0;
 
-       unsigned int    gnr;    /* inode 所在的group的号 */
-       unsigned int    gidx;   /* inode 所在的group的偏移 */
-       unsigned int    inotbl; /* inode table 的 block id */
+    unsigned int    gnr;    /* inode 所在的group的号 */
+    unsigned int    gidx;    /* inode 所在的group的偏移 */
+    unsigned int    inotbl;    /* inode table 的 block id */
 
 
-       gnr     = (n-1) / EXT2_INODES_PER_GROUP;
-       gidx    = (n-1) % EXT2_INODES_PER_GROUP;
+    gnr    = (n-1) / EXT2_INODES_PER_GROUP;
+    gidx    = (n-1) % EXT2_INODES_PER_GROUP;
 
-       inotbl  = (gdesc+gnr)->bg_inode_table;
+    inotbl    = (gdesc+gnr)->bg_inode_table;
 
-       // 跳过完整的BLOCK
-       inotbl += (gidx/EXT2_INODES_PER_BLOCK);
-       gidx   %= EXT2_INODES_PER_BLOCK;
+    // 跳过完整的BLOCK
+    inotbl += (gidx/EXT2_INODES_PER_BLOCK);
+    gidx   %= EXT2_INODES_PER_BLOCK;
 
 
-       char *buf = kmalloc(EXT2_BLOCK_SIZE);
-       if(buf == NULL)
-               panic("faild read inode. out of memory");
-       ext2_read_block(inotbl, buf);
+    char *buf = kmalloc(EXT2_BLOCK_SIZE);
+    if(buf == NULL)
+        panic("faild read inode. out of memory");
+    ext2_read_block(inotbl, buf);
 
-       memcpy((void *)ino,(void*)(((pInode)buf)+gidx), EXT2_INODE_SIZE);
+    memcpy((void *)ino,(void*)(((pInode)buf)+gidx), EXT2_INODE_SIZE);
 
-       kfree(buf);
+    kfree(buf);
 
-       return n;
+    return n;
 }
 int ext2_read_file(const pInode ino, void *buf, size_t count)
 {
-       int i, blks;
-       void *p;
+    int i, blks;
+    void *p;
 
-       blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
-       assert(blks>0);
+    blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
+    assert(blks>0);
 
-       if(blks > EXT2_NDIR_BLOCKS)
-               panic("file too large to read");
+    if(blks > EXT2_NDIR_BLOCKS)
+        panic("file too large to read");
 
-       p = kmalloc(blks*EXT2_BLOCK_SIZE);
+    p = kmalloc(blks*EXT2_BLOCK_SIZE);
 
-       if(p == NULL)
-               panic("out of memory when search inode in directory");
+    if(p == NULL)
+        panic("out of memory when search inode in directory");
 
-       for(i=0; i<blks; i++)
-       {
-               ext2_read_block(ino->i_block[i],
-                       (char *)(i*EXT2_BLOCK_SIZE + (unsigned long)p));
-       }
+    for(i=0; i<blks; i++)
+    {
+        ext2_read_block(ino->i_block[i],
+            (char *)(i*EXT2_BLOCK_SIZE + (unsigned long)p));
+    }
 
-       memcpy(buf, p, count);
+    memcpy(buf, p, count);
 
-       kfree(p);
+    kfree(p);
 
-       return count;
+    return count;
 }
 #if 0
 char *load_inode_content(const pInode ino)
 {
-       int i, blks;
-       char *buf;
+    int i, blks;
+    char *buf;
 
-       blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
-       assert(blks>0);
-       if(blks > EXT2_NDIR_BLOCKS)
-               panic("unsupport file large than 12KB");
+    blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
+    assert(blks>0);
+    if(blks > EXT2_NDIR_BLOCKS)
+        panic("unsupport file large than 12KB");
 
 
-       buf = kmalloc(blks*EXT2_BLOCK_SIZE);
-       if(buf == NULL)
-               panic("out of memory when search inode in directory");
-       for(i=0; i<blks; i++)
-       {
-               ext2_read_block(ino->i_block[i], buf + i*EXT2_BLOCK_SIZE);
-       }
+    buf = kmalloc(blks*EXT2_BLOCK_SIZE);
+    if(buf == NULL)
+        panic("out of memory when search inode in directory");
+    for(i=0; i<blks; i++)
+    {
+        ext2_read_block(ino->i_block[i], buf + i*EXT2_BLOCK_SIZE);
+    }
 
-       return buf;
+    return buf;
 }
 #endif
 
@@ -208,84 +208,84 @@ char *load_inode_content(const pInode ino)
  */
 int ext2_search_file(const char *file, const pInode in, pInode out)
 {
-       assert(file != NULL);
-       assert(in != NULL);
-       assert(S_ISDIR(in->i_mode));
+    assert(file != NULL);
+    assert(in != NULL);
+    assert(S_ISDIR(in->i_mode));
 
-       char *buf;
+    char *buf;
 #if 0
-       buf = load_inode_content(in);
+    buf = load_inode_content(in);
 #else
-       buf = kmalloc(in->i_size);
-       ext2_read_file(in, buf, in->i_size);
+    buf = kmalloc(in->i_size);
+    ext2_read_file(in, buf, in->i_size);
 #endif
 
-       pDirEnt ent = (pDirEnt)buf;
-       int len = strlen(file);
-       int inode_n = EXT2_BAD_INO;
-       while(ent < (pDirEnt)(buf + in->i_size))
-       {
-               if(ent->name_len == len)
-               {
-                       if(strncmp(file, ent->name, ent->name_len) == 0)
-                       {
-                               inode_n = ent->inode;
+    pDirEnt    ent = (pDirEnt)buf;
+    int len = strlen(file);
+    int inode_n = EXT2_BAD_INO;
+    while(ent < (pDirEnt)(buf + in->i_size))
+    {
+        if(ent->name_len == len)
+        {
+            if(strncmp(file, ent->name, ent->name_len) == 0)
+            {
+                inode_n = ent->inode;
 #if 0
-                               printk("file: %s\n", ent->name);
+                printk("file: %s\n", ent->name);
 #endif
-                               break;
-                       }
-               }
+                break;
+            }
+        }
 
 
-               ent = (pDirEnt)(ent->rec_len + (unsigned long)ent);
-       }
-       kfree(buf);
+        ent = (pDirEnt)(ent->rec_len + (unsigned long)ent);
+    }
+    kfree(buf);
 
-       ext2_read_inode(inode_n, out);
+    ext2_read_inode(inode_n, out);
 
-       return inode_n;
+    return inode_n;
 }
 
 
 static int get_filename_from_path(const char *path, char *filename)
 {
-       int i = 0;
+    int i = 0;
 
-       while(*path != '/' && *path != '\0')
-       {
-               filename[i++] = *path++;
-       }
-       filename[i] = 0;
+    while(*path != '/' && *path != '\0')
+    {
+        filename[i++] = *path++;
+    }
+    filename[i] = 0;
 
 
-       return i; // file name len
+    return i; // file name len
 }
 
 
 int ext2_get_file_inode_nr(const char *path)
 {
-       assert(*path++ == '/'); /* 目前只支持从根目录开始的路径 */
-       Inode   ino = ext2_root_inode;
-       int     ino_nr, len;
-       char file[EXT2_NAME_LEN];
+    assert(*path++ == '/');    /* 目前只支持从根目录开始的路径 */
+    Inode    ino = ext2_root_inode;
+    int    ino_nr, len;
+    char file[EXT2_NAME_LEN];
 
-       while((len=get_filename_from_path(path, file)) != 0)
-       {
+    while((len=get_filename_from_path(path, file)) != 0)
+    {
 #if 0
-               printk("file: %s ", file);
+        printk("file: %s ", file);
 #endif
-               ino_nr = ext2_search_file(file, &ino, &ino);
+        ino_nr = ext2_search_file(file, &ino, &ino);
 
-               path += len;
+        path += len;
 
-               if(*path != 0)
-                       path++;
-       }
+        if(*path != 0)
+            path++;
+    }
 #if 0
-       printk("ino_nr:%d\n", ino_nr);
+    printk("ino_nr:%d\n", ino_nr);
 #endif
-       return ino_nr;
+    return ino_nr;
 }
 
 #if 0
@@ -294,24 +294,24 @@ int ext2_get_file_inode_nr(const char *path)
  */
 char *ext2_loadfile(const char *path, size_t *file_size)
 {
-       char *buf;
-       buf = load_inode_content(&inode);
-       *file_size = inode.i_size;
+    char *buf;
+    buf = load_inode_content(&inode);
+    *file_size = inode.i_size;
 
-       return buf;
+    return buf;
 }
 #endif
 
 static void ext2_print_group_descriptor(pGroupDesc p)
 {
-       printk("block bitmap:%d inode bitmap:%d inode table:%d\n",
-               p->bg_block_bitmap,
-               p->bg_inode_bitmap,
-               p->bg_inode_table);
+    printk("block bitmap:%d inode bitmap:%d inode table:%d\n",
+        p->bg_block_bitmap,
+        p->bg_inode_bitmap,
+        p->bg_inode_table);
 }
 
 static void ext2_print_inode(pInode p)
 {
-       printk("i_mode:%04x i_size:%d i_blocks:%d\n",
-               p->i_mode, p->i_size, p->i_blocks);
+    printk("i_mode:%04x i_size:%d i_blocks:%d\n",
+        p->i_mode, p->i_size, p->i_blocks);
 }
diff --git a/fs/fs.c b/fs/fs.c
index 334858635ded7d4972defa1ba636791019ca4ec3..d3d568f5ed60e760e064d45a9c4f6ac360b5b10a 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
 /*
  *--------------------------------------------------------------------------
- *   File Name:        fs.c
+ *   File Name: fs.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Fri Feb 12 20:48:50 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Fri Feb 12 20:48:50 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<fs.h>
-#include<io.h>
-#include<printk.h>
-#include<system.h>
-#define        SECT_SIZE       512
-
-File   file_table[NR_FILES]
-       __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
+#include <fs.h>
+#include <io.h>
+#include <printk.h>
+#include <system.h>
+#define SECT_SIZE    512
+
+File    file_table[NR_FILES]
+    __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
 extern unsigned int ext2_start_sect;
-void   hd_read(Dev dev, u64 sect_nr, void *buf, u32 count);
-void   init_file_table();
-void   save_boot_part(int n, pPartition p, u32 base_sect);
-void   read_ext_part(u32 base, u32 offset);
+void    hd_read(Dev dev, u64 sect_nr, void *buf, u32 count);
+void    init_file_table();
+void    save_boot_part(int n, pPartition p, u32 base_sect);
+void    read_ext_part(u32 base, u32 offset);
 
-void   setup_fs()
+void    setup_fs()
 {
-       int i, minor;
-       pPartition p;
-       unsigned char *buf;
+    int i, minor;
+    pPartition p;
+    unsigned char *buf;
 
 
-       init_file_table();
+    init_file_table();
 
 
-       minor = DEV_MINOR(ROOT_DEV);
-       buf = (unsigned char *) get_virt_pages(1);
-       hd_read(ROOT_DEV, 0, buf, SECT_SIZE);
+    minor = DEV_MINOR(ROOT_DEV);
+    buf = (unsigned char *) get_virt_pages(1);
+    hd_read(ROOT_DEV, 0, buf, SECT_SIZE);
 
 
-       for(i=0; i<4; i++)
-       {
-               p = (pPartition)(buf+PARTS_POS) + i;
-               if(p->Type == 0)
-                       continue;
+    for(i=0; i<4; i++)
+    {
+        p = (pPartition)(buf+PARTS_POS) + i;
+        if(p->Type == 0)
+            continue;
 
-               //save_boot_part(i+1, p, p->AbsoluteSectNo);
-               save_boot_part(i, p, p->AbsoluteSectNo);
+        //save_boot_part(i+1, p, p->AbsoluteSectNo);
+        save_boot_part(i, p, p->AbsoluteSectNo);
 
-               printk("hd%d\tbase: %08x size: %08x type:%02x",
-                       i, p->AbsoluteSectNo, p->PartitionSize, p->Type);
-               if(p->Type == 0x05)
-               {
-                       printk("\tExtend\n");
-                       //read_ext_part(p->AbsoluteSectNo, 0);
-               }
-               else
-                       printk("\n");
-       }
+        printk("hd%d\tbase: %08x size: %08x type:%02x",
+            i, p->AbsoluteSectNo, p->PartitionSize, p->Type);
+        if(p->Type == 0x05)
+        {
+            printk("\tExtend\n");
+            //read_ext_part(p->AbsoluteSectNo, 0);
+        }
+        else
+            printk("\n");
+    }
 
 
-       printk("ext2_start_sect: %x\n", ext2_start_sect);
+    printk("ext2_start_sect: %x\n", ext2_start_sect);
 
 
-       return ;
-       //int j = 0xF0000000;
-       //while(j--);
-       
+    return ;
+    //int j = 0xF0000000;
+    //while(j--);
+    
 
 /*
-       minor = 5;      
-       if(minor >= 5)
-       {
-               for(i=0; i<4; i++)
-               {
-                       p = (pPartition)(buf+PARTS_POS) + i;
-                       if(p->Type == 0x05)
-                               break;
-               }
-               assert(i<4);
-               //read_ext_part(0, p->AbsoluteSectNo);
-               read_ext_part(p->AbsoluteSectNo, 0);
-       }
+    minor = 5;    
+    if(minor >= 5)
+    {
+        for(i=0; i<4; i++)
+        {
+            p = (pPartition)(buf+PARTS_POS) + i;
+            if(p->Type == 0x05)
+                break;
+        }
+        assert(i<4);
+        //read_ext_part(0, p->AbsoluteSectNo);
+        read_ext_part(p->AbsoluteSectNo, 0);
+    }
 */
 #if 0
-       outb(0x00, 0x1F1);
-       outb(1, 0x1F2);
-       outb(0x00, 0x1F3);
-       outb(0x00, 0x1F4);
-       outb(0x00, 0x1F5);
-       outb(0xE0, 0x1F6);
-       outb(0xEC, 0x1F7);
-       while(!(inb(0x1F7) & 0x08)){}
-       /*
-       while(1)
-       {
-               printk("%02x ", inb(0x1F7));
-       }*/
-       asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
-
-       for(i=0; i<512; i++)
-               printk("%02x ", buf[i]);
+    outb(0x00, 0x1F1);
+    outb(1, 0x1F2);
+    outb(0x00, 0x1F3);
+    outb(0x00, 0x1F4);
+    outb(0x00, 0x1F5);
+    outb(0xE0, 0x1F6);
+    outb(0xEC, 0x1F7);
+    while(!(inb(0x1F7) & 0x08)){}
+    /*
+    while(1)
+    {
+        printk("%02x ", inb(0x1F7));
+    }*/
+    asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf));
+
+    for(i=0; i<512; i++)
+        printk("%02x ", buf[i]);
 #endif
 
 #if 0
-#define        SZ      512
-       hd_read(ROOT_DEV, 0, buf, SZ);
-       //hd_read(0, 1, buf+512, 512);
-       //hd_read(0,0,buf, 1023);
-       pPartition p;
+#define SZ    512
+    hd_read(ROOT_DEV, 0, buf, SZ);
+    //hd_read(0, 1, buf+512, 512);
+    //hd_read(0,0,buf, 1023);
+    pPartition p;
 #if 0
-       for(i=0; i<SZ; i++)
-               printk("%02x ", buf[i]);
-       while(1);
+    for(i=0; i<SZ; i++)
+        printk("%02x ", buf[i]);
+    while(1);
 #endif
 #endif
 #if 0
-       for(i=0; i<4; i++)
-       {
-               p = (pPartition)(buf+PARTS_POS)+i;
-               printk( "State:%02x Head:%d StartSC:%d Type:%02x "
-                       "EndHead:%d EndSC:%d AboluteSectNo:%d "
-                       "PartitionSize:%d\n",
-               p->State, p->Head, p->StartSC, p->Type,
-               p->EndHead, p->EndSC, p->AbsoluteSectNo, p->PartitionSize);
-       }
+    for(i=0; i<4; i++)
+    {
+        p = (pPartition)(buf+PARTS_POS)+i;
+        printk(    "State:%02x Head:%d StartSC:%d Type:%02x "
+            "EndHead:%d EndSC:%d AboluteSectNo:%d "
+            "PartitionSize:%d\n",
+        p->State, p->Head, p->StartSC, p->Type,
+        p->EndHead, p->EndSC, p->AbsoluteSectNo, p->PartitionSize);
+    }
 #endif
 
 #if 0
-       int j, k;
-       j = 0x10000;
-       while(j--)
-       {
-               k = 0x10000;
-               while(k--);
-       }
+    int j, k;
+    j = 0x10000;
+    while(j--)
+    {
+        k = 0x10000;
+        while(k--);
+    }
 #endif
 }
 
-void   init_file_table()
+void    init_file_table()
 {
-       int i;
-
-       for(i=0; i<NR_FILES; i++)
-       {
-               file_table[i].count     = 0;
-               file_table[i].ino_nr    = 0;
-               file_table[i].inode     = NULL;
-       }
+    int i;
+
+    for(i=0; i<NR_FILES; i++)
+    {
+        file_table[i].count    = 0;
+        file_table[i].ino_nr    = 0;
+        file_table[i].inode    = NULL;
+    }
 }
 
-void   save_boot_part(int n, pPartition p, u32 base_sect)
+void    save_boot_part(int n, pPartition p, u32 base_sect)
 {
-       if(p->Type == 0x05)
-               panic("partition should not be extended");
+    if(p->Type == 0x05)
+        panic("partition should not be extended");
 
-       int minor = DEV_MINOR(ROOT_DEV);
+    int minor = DEV_MINOR(ROOT_DEV);
 
-       if(minor-1 == n)
-               ext2_start_sect = base_sect;
+    if(minor-1 == n)
+        ext2_start_sect = base_sect;
 }
 
 static unsigned int ext_part = 5;
-void   read_ext_part(u32 base, u32 offset)
+void    read_ext_part(u32 base, u32 offset)
 {
-       unsigned char *buf;
-       pPartition p;
-       buf = get_virt_pages(1);
-
-       //printk("^^^^^^^^^:%08x\n", base+offset);
-       hd_read(ROOT_DEV, base+offset, buf, SECT_SIZE);
-       int i;
-
-       for(i=0; i<4; i++)
-       {
-               p = (pPartition)(buf+PARTS_POS) + i;
-               if(p->Type == 0x00)
-                       continue;
-
-               if(p->Type != 0x05)
-               {
-
-                       //save_boot_part(ext_part, p, 0);
-                       printk("  hd%d\tbase: %08x size: %08x type:%02x\n",
-                               ext_part++, base+p->AbsoluteSectNo,
-                               p->PartitionSize, p->Type);
-               }
-               else
-               {
-                       read_ext_part(base, p->AbsoluteSectNo);
-               }
-       }
-
-       printk("\n");
-
-       free_virt_pages(buf);
+    unsigned char *buf;
+    pPartition p;
+    buf = get_virt_pages(1);
+
+    //printk("^^^^^^^^^:%08x\n", base+offset);
+    hd_read(ROOT_DEV, base+offset, buf, SECT_SIZE);
+    int i;
+
+    for(i=0; i<4; i++)
+    {
+        p = (pPartition)(buf+PARTS_POS) + i;
+        if(p->Type == 0x00)
+            continue;
+
+        if(p->Type != 0x05)
+        {
+
+            //save_boot_part(ext_part, p, 0);
+            printk("  hd%d\tbase: %08x size: %08x type:%02x\n",
+                ext_part++, base+p->AbsoluteSectNo,
+                p->PartitionSize, p->Type);
+        }
+        else
+        {
+            read_ext_part(base, p->AbsoluteSectNo);
+        }
+    }
+
+    printk("\n");
+
+    free_virt_pages(buf);
 }
 
index 564c7ea50a86cdc24240db3b2e1b0b4a1f8845f4..fb2c192aa955dfd62fb8841b34c7a76c8eaf999c 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -1,93 +1,93 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        open.c
+ *   File Name: open.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Feb 20 18:53:47 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Feb 20 18:53:47 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<fs.h>
-#include<errno.h>
-#include<types.h>
-#include<sched.h>
-#include<fcntl.h>
-#include<assert.h>
-#include<syscall.h>
+#include <fs.h>
+#include <errno.h>
+#include <types.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <syscall.h>
 
 int sysc_open(const char *path, int flags, mode_t mode)
 {
-       assert(mode == 0); // unsupport now...
-       assert(flags == O_RDONLY);      // support only...
+    assert(mode == 0); // unsupport now...
+    assert(flags == O_RDONLY);    // support only...
 
-       int ino_nr, i, fd;
-       pInode inode;
+    int ino_nr, i, fd;
+    pInode inode;
 
-       /* 先获取文件的i节点号 */
-       ino_nr = get_inode_nr(path);
-       if(ino_nr == EXT2_BAD_INO)
-               return -ENOENT;
+    /* 先获取文件的i节点号 */
+    ino_nr = get_inode_nr(path);
+    if(ino_nr == EXT2_BAD_INO)
+        return -ENOENT;
 
-       /* 找到空的文件描述符句柄 */
-       for(i=0; i<NR_OPENS; i++)
-               if(current->fps[i] == NULL)
-                       break;
-       if(i == NR_OPENS)
-               return -EMFILE;
-       fd = i;
+    /* 找到空的文件描述符句柄 */
+    for(i=0; i<NR_OPENS; i++)
+        if(current->fps[i] == NULL)
+            break;
+    if(i == NR_OPENS)
+        return -EMFILE;
+    fd = i;
 
 
-       /* 找到空的描述符或已经打开的描述符 */
-       int empt_nr, fdt_nr;
-       pFile pf;
-       empt_nr = fdt_nr = -1;
-       for(i=0, pf=file_table; i<NR_FILES; i++, pf++)
-       {
-               if(pf->ino_nr == ino_nr)
-               {
-                       fdt_nr = i;
-                       break;
-               }
-               else if(pf->ino_nr == 0)
-               {
-                       empt_nr = i;
-               }
-       }
+    /* 找到空的描述符或已经打开的描述符 */
+    int empt_nr, fdt_nr;
+    pFile pf;
+    empt_nr = fdt_nr = -1;
+    for(i=0, pf=file_table; i<NR_FILES; i++, pf++)
+    {
+        if(pf->ino_nr == ino_nr)
+        {
+            fdt_nr = i;
+            break;
+        }
+        else if(pf->ino_nr == 0)
+        {
+            empt_nr = i;
+        }
+    }
 
-       if(fdt_nr != -1)
-       {
-               pf = file_table+fdt_nr;
-       }
-       else if(empt_nr != -1)
-       {
-               pf = file_table+empt_nr;
-       }
-       else
-       {
-               return -EMFILE;
-       }
+    if(fdt_nr != -1)
+    {
+        pf = file_table+fdt_nr;
+    }
+    else if(empt_nr != -1)
+    {
+        pf = file_table+empt_nr;
+    }
+    else
+    {
+        return -EMFILE;
+    }
 
 
-       if(pf->ino_nr == ino_nr)
-       {
-               pf->count++;
-               current->fps[fd] = pf;
-               return fd;
-       }
+    if(pf->ino_nr == ino_nr)
+    {
+        pf->count++;
+        current->fps[fd] = pf;
+        return fd;
+    }
 
-       inode = find_empty_inode();
-       if(inode == NULL)
-               return -ENOMEM;
+    inode = find_empty_inode();
+    if(inode == NULL)
+        return -ENOMEM;
 
-       get_inode(ino_nr, inode);
-       
-       pf->count = 1;
-       pf->ino_nr = ino_nr;
-       pf->inode = inode;
-       current->fps[fd] = pf;
+    get_inode(ino_nr, inode);
+    
+    pf->count = 1;
+    pf->ino_nr = ino_nr;
+    pf->inode = inode;
+    current->fps[fd] = pf;
 
-       return fd;
+    return fd;
 }
index 873d3b84c2d2e92cad4d286bfc35048a5c82aaed..3e2fc060054fb3e266a9832228c81cd5b884b730 100644 (file)
--- a/fs/read.c
+++ b/fs/read.c
@@ -1,33 +1,33 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        read.c
+ *   File Name: read.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 18:53:47 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 18:53:47 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<types.h>
-#include<assert.h>
-#include<fs.h>
-#include<errno.h>
-#include<sched.h>
+#include <types.h>
+#include <assert.h>
+#include <fs.h>
+#include <errno.h>
+#include <sched.h>
 
 int sysc_read(int fd, void *buf, size_t count)
 {
-       if(fd<0 || fd>=NR_OPENS)
-               return -EBADF;
+    if(fd<0 || fd>=NR_OPENS)
+        return -EBADF;
 
-       pFile fp = current->fps[fd];
-       assert(fp != NULL);
+    pFile fp = current->fps[fd];
+    assert(fp != NULL);
 
-       pInode  inode = fp->inode;
-       assert(inode->i_size > 0);      // 目前只能这样支持
-       if(inode->i_size > MAX_SUPT_FILE_SIZE)
-               return -EFAULT;
+    pInode    inode = fp->inode;
+    assert(inode->i_size > 0);    // 目前只能这样支持
+    if(inode->i_size > MAX_SUPT_FILE_SIZE)
+        return -EFAULT;
 
 
-       return read_file(inode, buf, count);
+    return read_file(inode, buf, count);
 }
index 537394972b6e050644102f09c7e19e9367795a6f..be4af9739f6322b57eebd73c01ce469b7a5c2e4b 100644 (file)
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -1,44 +1,44 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        stat.c
+ *   File Name: stat.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 19:56:08 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 19:56:08 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<types.h>
-#include<stat.h>
-#include<errno.h>
-#include<fs.h>
-#include<sched.h>
-#include<memory.h>
+#include <types.h>
+#include <stat.h>
+#include <errno.h>
+#include <fs.h>
+#include <sched.h>
+#include <memory.h>
 int sysc_stat(int fd, struct stat *stat)
 {
-       if(fd<0 || fd>=NR_OPENS)
-               return -EBADF;
+    if(fd<0 || fd>=NR_OPENS)
+        return -EBADF;
 
-       pFile fp = current->fps[fd];
-       assert(fp != NULL);
+    pFile fp = current->fps[fd];
+    assert(fp != NULL);
 
-       pInode  inode = fp->inode;
-       assert(inode->i_size > 0);      // 目前只能这样支持
-       if(inode->i_size > MAX_SUPT_FILE_SIZE)
-               return -EFAULT;
+    pInode    inode = fp->inode;
+    assert(inode->i_size > 0);    // 目前只能这样支持
+    if(inode->i_size > MAX_SUPT_FILE_SIZE)
+        return -EFAULT;
 
-       memset((void*)stat, 0, sizeof(struct stat));
+    memset((void*)stat, 0, sizeof(struct stat));
 
-       stat->st_ino    = fp->ino_nr;
-       stat->st_mode   = inode->i_mode;
-       stat->st_uid    = inode->i_uid;
-       stat->st_gid    = inode->i_gid;
-       stat->st_size   = inode->i_size;
-       stat->st_blocks = inode->i_blocks;
-       stat->st_atime  = inode->i_atime;
-       stat->st_mtime  = inode->i_mtime;
-       stat->st_ctime  = inode->i_ctime;
+    stat->st_ino    = fp->ino_nr;
+    stat->st_mode    = inode->i_mode;
+    stat->st_uid    = inode->i_uid;
+    stat->st_gid    = inode->i_gid;
+    stat->st_size    = inode->i_size;
+    stat->st_blocks    = inode->i_blocks;
+    stat->st_atime    = inode->i_atime;
+    stat->st_mtime    = inode->i_mtime;
+    stat->st_ctime    = inode->i_ctime;
 
-       return 0;
+    return 0;
 }
index 89e7c154c4dda61ee07d57a1b4aa5b0280862b1b..9dbe44b8b455af77340a859a119c0e49ba540384 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        write.c
+ *   File Name: write.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Mar  8 11:05:12 2009
  * Last Update: Sun Mar  8 11:05:12 2009
  * 
  */
 
 
-extern void    printString(const char *buf, unsigned char color);
+extern void     printString(const char *buf, unsigned char color);
 int sysc_write(int fd, const char *buf, unsigned long size)
 {
-       if(size < 0) return -1;
+    if(size < 0) return -1;
 
-       switch(fd)
-       {
-       case 0:
-               printString(buf, 0xF);
-               break;
-       default:
-               return -1;
-       }
+    switch(fd)
+    {
+    case 0:
+        printString(buf, 0xF);
+        break;
+    default:
+        return -1;
+    }
 
-       return size;
+    return size;
 }
index e157a7ecdb7a4de88a4048c6d9b5b228dc0d3899..791a6b0aabbf57c0a6fd295e3aed2427b3a1dfd6 100644 (file)
@@ -1,23 +1,23 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        assert.h
+ *   File Name: assert.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jan 23 14:02:00 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jan 23 14:02:00 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _ASSERT_H
-#define        _ASSERT_H
+#ifndef    _ASSERT_H
+#define _ASSERT_H
 
-#include<global.h>
+#include <global.h>
 
-#define        assert(exp)                                                     \
-( (exp)                                                                        \
-? (void) (0)                                                           \
+#define assert(exp)                            \
+( (exp)                                    \
+? (void) (0)                                \
 : assert_fail(__STRING(exp), __FILE__, __LINE__, __PRETTY_FUNCTION__))
 
 #endif //_ASSERT_H
index b73d895b2a66dc37834a704b2eb15bfbedbe9b06..82c0582bab0b05b0bf990db4347371024c7abc86 100644 (file)
@@ -1,36 +1,36 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        bits.h
+ *   File Name: bits.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Mar  4 20:56:29 2009
  * Last Update: Wed Mar  4 20:56:29 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _BITS_H
-#define        _BITS_H
+#ifndef    _BITS_H
+#define _BITS_H
 
-//#define      SET_BIT(bit) (1UL<<bit)
-//#define      CLR_BIT(bit) (~(1UL<<bit))
-//#define      ISSET_BIT(val,bit) ((val) & SET_BIT(bit))
-#define        SET_BIT(val, bit)       (val |= (1UL<<bit))
-#define        CLR_BIT(val, bit)       (val &= (~(1UL<<bit)))
-#define        XOR_BIT(val, bit)       (btc((unsigned int *)&val, bit), val)
-#define        ISSET_BIT(val, bit)     (val & (1UL<<bit))
-#define        ISCLR_BIT(val, bit)     (!ISSET_BIT(val, bit))
+//#define    SET_BIT(bit) (1UL<<bit)
+//#define    CLR_BIT(bit) (~(1UL<<bit))
+//#define    ISSET_BIT(val,bit) ((val) & SET_BIT(bit))
+#define SET_BIT(val, bit)    (val |= (1UL<<bit))
+#define CLR_BIT(val, bit)    (val &= (~(1UL<<bit)))
+#define XOR_BIT(val, bit)    (btc((unsigned int *)&val, bit), val)
+#define ISSET_BIT(val, bit)    (val & (1UL<<bit))
+#define ISCLR_BIT(val, bit)    (!ISSET_BIT(val, bit))
 
 #define BITS_PER_LONG (sizeof(unsigned long)*8)
 
 static inline void btc(unsigned int *v, unsigned int b)
 {
-       asm ("btc %1,%0":"=m"(*v): "Ir"(b));
+    asm ("btc %1,%0":"=m"(*v): "Ir"(b));
 }
 
 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
@@ -46,14 +46,14 @@ static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
 
 static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
 {
-       int oldbit;
+    int oldbit;
 
-       asm volatile("btr %2,%1\n\t"
-                    "sbb %0,%0"
-                    : "=r" (oldbit), "+m" (*(volatile long *) (addr)) 
-                    : "Ir" (nr) : "memory");
+    asm volatile("btr %2,%1\n\t"
+             "sbb %0,%0"
+             : "=r" (oldbit), "+m" (*(volatile long *) (addr)) 
+             : "Ir" (nr) : "memory");
 
-       return oldbit;
+    return oldbit;
 }
 /**
  * test_and_change_bit - Change a bit and return its old value
@@ -65,14 +65,14 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
  */
 static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
 {
-       int oldbit;
+    int oldbit;
 
-       asm volatile("btc %2,%1\n\t"
-                    "sbb %0,%0"
-                    : "=r" (oldbit), "+m" (*(volatile long *) (addr)) 
-                    : "Ir" (nr) : "memory");
+    asm volatile("btc %2,%1\n\t"
+             "sbb %0,%0"
+             : "=r" (oldbit), "+m" (*(volatile long *) (addr)) 
+             : "Ir" (nr) : "memory");
 
-       return oldbit;
+    return oldbit;
 }
 
 /**
@@ -86,8 +86,8 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
  */
 static inline void change_bit(int nr, volatile unsigned long *addr)
 {
-       asm volatile("btc %1,%0": "+m" (*(volatile long *) (addr)) 
-                               : "Ir" (nr));
+    asm volatile("btc %1,%0": "+m" (*(volatile long *) (addr)) 
+                : "Ir" (nr));
 }
 
 static inline int constant_test_bit(unsigned int nr, const volatile unsigned long *addr)
@@ -106,22 +106,22 @@ static inline int constant_test_bit(unsigned int nr, const volatile unsigned lon
  */
 static inline int find_first_bit(const unsigned long *addr, unsigned size)
 {
-       int d0, d1;
-       int res;
-
-       /* This looks at memory. Mark it volatile to tell gcc not to move it around */
-       __asm__ __volatile__(
-               "xorl %%eax,%%eax\n\t"
-               "repe; scasl\n\t"
-               "jz 1f\n\t"
-               "leal -4(%%edi),%%edi\n\t"
-               "bsfl (%%edi),%%eax\n"
-               "1:\tsubl %%ebx,%%edi\n\t"
-               "shll $3,%%edi\n\t"
-               "addl %%edi,%%eax"
-               :"=a" (res), "=&c" (d0), "=&D" (d1)
-               :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory");
-       return res;
+    int d0, d1;
+    int res;
+
+    /* This looks at memory. Mark it volatile to tell gcc not to move it around */
+    __asm__ __volatile__(
+        "xorl %%eax,%%eax\n\t"
+        "repe; scasl\n\t"
+        "jz 1f\n\t"
+        "leal -4(%%edi),%%edi\n\t"
+        "bsfl (%%edi),%%eax\n"
+        "1:\tsubl %%ebx,%%edi\n\t"
+        "shll $3,%%edi\n\t"
+        "addl %%edi,%%eax"
+        :"=a" (res), "=&c" (d0), "=&D" (d1)
+        :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory");
+    return res;
 }
 
 /**
@@ -134,26 +134,26 @@ static inline int find_first_bit(const unsigned long *addr, unsigned size)
  */
 static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
 {
-       int d0, d1, d2;
-       int res;
-
-       if (!size)
-               return 0;
-       /* This looks at memory. Mark it volatile to tell gcc not to move it around */
-       __asm__ __volatile__(
-               "movl $-1,%%eax\n\t"
-               "xorl %%edx,%%edx\n\t"
-               "repe; scasl\n\t"
-               "je 1f\n\t"
-               "xorl -4(%%edi),%%eax\n\t"
-               "subl $4,%%edi\n\t"
-               "bsfl %%eax,%%edx\n"
-               "1:\tsubl %%ebx,%%edi\n\t"
-               "shll $3,%%edi\n\t"
-               "addl %%edi,%%edx"
-               :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
-               :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory");
-       return res;
+    int d0, d1, d2;
+    int res;
+
+    if (!size)
+        return 0;
+    /* This looks at memory. Mark it volatile to tell gcc not to move it around */
+    __asm__ __volatile__(
+        "movl $-1,%%eax\n\t"
+        "xorl %%edx,%%edx\n\t"
+        "repe; scasl\n\t"
+        "je 1f\n\t"
+        "xorl -4(%%edi),%%eax\n\t"
+        "subl $4,%%edi\n\t"
+        "bsfl %%eax,%%edx\n"
+        "1:\tsubl %%ebx,%%edi\n\t"
+        "shll $3,%%edi\n\t"
+        "addl %%edi,%%edx"
+        :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
+        :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory");
+    return res;
 }
 
 /**
@@ -164,40 +164,40 @@ static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
  */
 static inline int find_next_zero_bit(const unsigned long *addr, int size, int offset)
 {
-       unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
-       int set = 0, bit = offset & 31, res;
-
-       if (bit) {
-               /*
-                * Look for zero in the first 32 bits.
-                */
-               __asm__("bsfl %1,%0\n\t"
-                       "jne 1f\n\t"
-                       "movl $32, %0\n"
-                       "1:"
-                       : "=r" (set)
-                       : "r" (~(*p >> bit)));
-               if (set < (32 - bit))
-                       return set + offset;
-               set = 32 - bit;
-               p++;
-       }
-       /*
-        * No zero yet, search remaining full bytes for a zero
-        */
-       res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
-       return (offset + set + res);
+    unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
+    int set = 0, bit = offset & 31, res;
+
+    if (bit) {
+        /*
+         * Look for zero in the first 32 bits.
+         */
+        __asm__("bsfl %1,%0\n\t"
+            "jne 1f\n\t"
+            "movl $32, %0\n"
+            "1:"
+            : "=r" (set)
+            : "r" (~(*p >> bit)));
+        if (set < (32 - bit))
+            return set + offset;
+        set = 32 - bit;
+        p++;
+    }
+    /*
+     * No zero yet, search remaining full bytes for a zero
+     */
+    res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
+    return (offset + set + res);
 }
 
 static inline int variable_test_bit(int nr, volatile const unsigned long *addr)
 {
-       int oldbit;
+    int oldbit;
 
-       asm volatile("bt %2,%1\n\t"
-                    "sbb %0,%0"
-                    : "=r" (oldbit)
-                    : "m" (*(unsigned long *)addr), "Ir" (nr));
+    asm volatile("bt %2,%1\n\t"
+             "sbb %0,%0"
+             : "=r" (oldbit)
+             : "m" (*(unsigned long *)addr), "Ir" (nr));
 
-       return oldbit;
+    return oldbit;
 }
 #endif //_BITS_H
index 2b751d11ae3b2cdaaf9799120f7a1ac28fdb9cd8..e333adc10c19e34d229a32138d49276c860e32c3 100644 (file)
 #pragma once
 
 /* The magic number for the Multiboot header.  */
-#define MULTIBOOT_HEADER_MAGIC         0x1BADB002
+#define MULTIBOOT_HEADER_MAGIC        0x1BADB002
 
 /* The flags for the Multiboot header.  */
 #ifdef __ELF__
-# define MULTIBOOT_HEADER_FLAGS                0x00000003
+# define MULTIBOOT_HEADER_FLAGS        0x00000003
 #else
-# define MULTIBOOT_HEADER_FLAGS                0x00010003
+# define MULTIBOOT_HEADER_FLAGS        0x00010003
 #endif
 
 /* The magic number passed by a Multiboot-compliant boot loader.  */
-#define MULTIBOOT_BOOTLOADER_MAGIC     0x2BADB002
+#define MULTIBOOT_BOOTLOADER_MAGIC    0x2BADB002
 
 /* The size of our stack (16KB).  */
-#define MULTIBOOT_STACK_SIZE           0x4000
+#define MULTIBOOT_STACK_SIZE        0x4000
 
 /* C symbol format. HAVE_ASM_USCORE is defined by configure.  */
 #ifdef HAVE_ASM_USCORE
-# define EXT_C(sym)                    _ ## sym
+# define EXT_C(sym)            _ ## sym
 #else
-# define EXT_C(sym)                    sym
+# define EXT_C(sym)            sym
 #endif
 
 #ifndef ASM
index ea6eb2fc553cd55d33bf77b2d1bd444e1141bdc6..0181615edd81f82c9de53049b42f74ca4f317afe 100644 (file)
@@ -1,27 +1,27 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        elf.h
+ *   File Name: elf.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jan 30 19:36:15 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jan 30 19:36:15 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _ELF_H
-#define        _ELF_H
+#ifndef    _ELF_H
+#define _ELF_H
 
-typedef        u16     Elf32_Half;
-typedef        u32     Elf32_Word;
-typedef        s32     Elf32_Sword;
-typedef        u64     Elf32_Xword;
-typedef        s64     Elf32_Sxword;
-typedef        u32     Elf32_Addr;
-typedef        u32     Elf32_Off;
-typedef        u16     Elf32_Section;
-typedef        Elf32_Half      Elf32_Versym;
+typedef    u16    Elf32_Half;
+typedef    u32    Elf32_Word;
+typedef    s32    Elf32_Sword;
+typedef    u64    Elf32_Xword;
+typedef    s64    Elf32_Sxword;
+typedef    u32    Elf32_Addr;
+typedef    u32    Elf32_Off;
+typedef    u16    Elf32_Section;
+typedef    Elf32_Half    Elf32_Versym;
 
 /*
  *--------------------------------------------------------------------------
@@ -30,117 +30,117 @@ typedef   Elf32_Half      Elf32_Versym;
  *--------------------------------------------------------------------------
  */
 
-#define        EI_NIDENT       (16)
-typedef        struct
+#define EI_NIDENT    (16)
+typedef    struct
 {
-       unsigned char   e_ident[EI_NIDENT];
-       Elf32_Half      e_type;
-       Elf32_Half      e_machine;
-       Elf32_Word      e_version;
-       Elf32_Addr      e_entry;
-       Elf32_Off       e_phoff;
-       Elf32_Off       e_shoff;
-       Elf32_Word      e_flags;
-       Elf32_Half      e_ehsize;       // ELF Header Size in bytes 
-       Elf32_Half      e_phentsize;    // Program header table entry size
-       Elf32_Half      e_phnum;
-       Elf32_Half      e_shentsize;
-       Elf32_Half      e_shnum;
-       Elf32_Half      e_shstrndx;     //Section Header String Table Index
+    unsigned char    e_ident[EI_NIDENT];
+    Elf32_Half    e_type;
+    Elf32_Half    e_machine;
+    Elf32_Word    e_version;
+    Elf32_Addr    e_entry;
+    Elf32_Off    e_phoff;
+    Elf32_Off    e_shoff;
+    Elf32_Word    e_flags;
+    Elf32_Half    e_ehsize;    // ELF Header Size in bytes 
+    Elf32_Half    e_phentsize;    // Program header table entry size
+    Elf32_Half    e_phnum;
+    Elf32_Half    e_shentsize;
+    Elf32_Half    e_shnum;
+    Elf32_Half    e_shstrndx;    //Section Header String Table Index
 }Elf32_Ehdr, *pElf32_Ehdr;
 
-#define        ELFMAG                  "\177ELF"
-#define        SELFMAG                 4
+#define ELFMAG            "\177ELF"
+#define SELFMAG            4
 
-#define        EI_MAG0                 0
-#define                ELFMAG0         0x7F
+#define EI_MAG0            0
+#define     ELFMAG0        0x7F
 
-#define        EI_MAG1                 1
-#define                ELFMAG1         'E'
+#define EI_MAG1            1
+#define     ELFMAG1        'E'
 
-#define        EI_MAG2                 2
-#define                ELFMAG2         'L'
+#define EI_MAG2            2
+#define     ELFMAG2        'L'
 
-#define        EI_MAG3                 3
-#define                ELFMAG3         'F'
+#define EI_MAG3            3
+#define     ELFMAG3        'F'
 
-#define        EI_CLASS                4
-#define                ELFCLASSNONE    0
-#define                ELFCLASS32      1
-#define                ELFCLASS64      2
-#define                ELFCLASSNUM     3
+#define EI_CLASS        4
+#define     ELFCLASSNONE    0
+#define     ELFCLASS32    1
+#define     ELFCLASS64    2
+#define     ELFCLASSNUM    3
 
-#define        EI_DATA                 5
-#define                ELFDATANONE     0
-#define                ELFDATA2LSB     1       /* 2's complement, little endian */
-#define                ELFDATA2MSB     2       /* 2's complement, big endian */
-#define                ELFDATANUM      3
+#define EI_DATA            5
+#define     ELFDATANONE    0
+#define     ELFDATA2LSB    1    /* 2's complement, little endian */
+#define     ELFDATA2MSB    2    /* 2's complement, big endian */
+#define     ELFDATANUM    3
 
-#define        EI_VERSION              6       /* value must be EV_CURRENT */
+#define EI_VERSION        6    /* value must be EV_CURRENT */
 
-#define        EI_OSABI                7       
-#define        ELFOSABI_NONE           0       /* UNIX System V ABI */
-#define        ELFOSABI_SYSV           0       /* Alias.  */
-#define        ELFOSABI_HPUX           1       /* HP-UX */
-#define        ELFOSABI_NETBSD         2       /* NetBSD.  */
-#define        ELFOSABI_LINUX          3       /* Linux.  */
-#define        ELFOSABI_SOLARIS        6       /* Sun Solaris.  */
-#define        ELFOSABI_AIX            7       /* IBM AIX.  */
-#define        ELFOSABI_IRIX           8       /* SGI Irix.  */
-#define        ELFOSABI_FREEBSD        9       /* FreeBSD.  */
-#define        ELFOSABI_TRU64          10      /* Compaq TRU64 UNIX.  */
-#define        ELFOSABI_MODESTO        11      /* Novell Modesto.  */
-#define        ELFOSABI_OPENBSD        12      /* OpenBSD.  */
-#define        ELFOSABI_ARM            97      /* ARM */
-#define        ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
+#define EI_OSABI        7    
+#define  ELFOSABI_NONE        0    /* UNIX System V ABI */
+#define  ELFOSABI_SYSV        0    /* Alias.  */
+#define  ELFOSABI_HPUX        1    /* HP-UX */
+#define  ELFOSABI_NETBSD        2    /* NetBSD.  */
+#define  ELFOSABI_LINUX        3    /* Linux.  */
+#define  ELFOSABI_SOLARIS    6    /* Sun Solaris.  */
+#define  ELFOSABI_AIX        7    /* IBM AIX.  */
+#define  ELFOSABI_IRIX        8    /* SGI Irix.  */
+#define  ELFOSABI_FREEBSD    9    /* FreeBSD.  */
+#define  ELFOSABI_TRU64        10    /* Compaq TRU64 UNIX.  */
+#define  ELFOSABI_MODESTO    11    /* Novell Modesto.  */
+#define  ELFOSABI_OPENBSD    12    /* OpenBSD.  */
+#define  ELFOSABI_ARM        97    /* ARM */
+#define  ELFOSABI_STANDALONE    255    /* Standalone (embedded) application */
 
-#define        EI_ABIVERSION           8
+#define EI_ABIVERSION        8
 
-#define        EI_PAD                  9
+#define EI_PAD            9
 
 
 /* values for e_type (object file type). */
-#define        ET_NONE         0       /* No file type */
-#define        ET_REL          1       /* Relocatable file */
-#define        ET_EXEC         2       /* Executable file */
-#define        ET_DYN          3       /* Shared object file */
-#define        ET_CORE         4       /* Core file */
-#define        ET_NUM          5       /* Number of defined types */
-#define        ET_LOOS         0xFE00  /* OS-Specific range start */
-#define        ET_HIOS         0xFEFF  /* OS-Specific range end */
-#define        ET_LOPROC       0xFF00  /* Processor-Specific range start */
-#define        ET_HIPROC       0xFFFF  /* Processor-Specific range end */
-
-#define        EM_NONE         0       /* No Machine */
-#define        EM_386          3       /* Intel 80386 */
-#define        EM_MIPS         8       /* MIPS R3000 big endian*/
-#define        EM_MIPS_RS3_LE  8       /* MIPS R3000 little endian*/
-#define        EM_PPC          20      /* Power PC */
-#define        EM_ARM          40      /* ARM */
-#define        EM_NUM          95
+#define ET_NONE        0    /* No file type */
+#define ET_REL        1    /* Relocatable file */
+#define ET_EXEC        2    /* Executable file */
+#define ET_DYN        3    /* Shared object file */
+#define ET_CORE        4    /* Core file */
+#define ET_NUM        5    /* Number of defined types */
+#define ET_LOOS        0xFE00    /* OS-Specific range start */
+#define ET_HIOS        0xFEFF    /* OS-Specific range end */
+#define ET_LOPROC    0xFF00    /* Processor-Specific range start */
+#define ET_HIPROC    0xFFFF    /* Processor-Specific range end */
+
+#define EM_NONE        0    /* No Machine */
+#define EM_386        3    /* Intel 80386 */
+#define EM_MIPS        8    /* MIPS R3000 big endian*/
+#define EM_MIPS_RS3_LE    8    /* MIPS R3000 little endian*/
+#define EM_PPC        20    /* Power PC */
+#define EM_ARM        40    /* ARM */
+#define EM_NUM        95
 
 
 /* values for e_version */
-#define        EV_NONE         0
-#define        EV_CURRENT      1
-#define        EV_NUM          2
+#define EV_NONE        0
+#define EV_CURRENT    1
+#define EV_NUM        2
 /*
  *--------------------------------------------------------------------------
  * Section header
  *--------------------------------------------------------------------------
  */
-typedef        struct
+typedef    struct
 {
-       Elf32_Word      sh_name;        /* Section name(string tbl index) */
-       Elf32_Word      sh_type;        /* Section type */
-       Elf32_Word      sh_flags;       /* Section flags */
-       Elf32_Addr      sh_addr;        /* virtual addr at execution */
-       Elf32_Off       sh_offset;      /* Section file offset */
-       Elf32_Word      sh_size;        /* Section size in bytes */
-       Elf32_Word      sh_link;        /* Link to another section */
-       Elf32_Word      sh_info;        /* Additional section infomation */
-       Elf32_Word      sh_addralign;   /* Section alignment */
-       Elf32_Word      sh_entsize;     /* Entry size if section holds tbl*/
+    Elf32_Word    sh_name;    /* Section name(string tbl index) */
+    Elf32_Word    sh_type;    /* Section type */
+    Elf32_Word    sh_flags;    /* Section flags */
+    Elf32_Addr    sh_addr;    /* virtual addr at execution */
+    Elf32_Off    sh_offset;    /* Section file offset */
+    Elf32_Word    sh_size;    /* Section size in bytes */
+    Elf32_Word    sh_link;    /* Link to another section */
+    Elf32_Word    sh_info;    /* Additional section infomation */
+    Elf32_Word    sh_addralign;    /* Section alignment */
+    Elf32_Word    sh_entsize;    /* Entry size if section holds tbl*/
 } Elf32_Shdr, *pElf32_Shdr;
 
 
@@ -152,36 +152,36 @@ typedef   struct
 
 typedef struct
 {
-       Elf32_Word      p_type;
-       Elf32_Off       p_offset;
-       Elf32_Addr      p_vaddr;
-       Elf32_Addr      p_paddr;
-       Elf32_Word      p_filesz;
-       Elf32_Word      p_memsz;
-       Elf32_Word      p_flags;
-       Elf32_Word      p_align;
+    Elf32_Word    p_type;
+    Elf32_Off    p_offset;
+    Elf32_Addr    p_vaddr;
+    Elf32_Addr    p_paddr;
+    Elf32_Word    p_filesz;
+    Elf32_Word    p_memsz;
+    Elf32_Word    p_flags;
+    Elf32_Word    p_align;
 } Elf32_Phdr,*pElf32_Phdr;
 
 /* p_type */
-#define        PT_NULL         0       /* Program header table entry unused */
-#define        PT_LOAD         1       /* Loadable program segment */
-#define        PT_DYNAMIC      2       /* Dynamic linking information */
-#define        PT_INTERP       3       /* Program interpreter */
-#define        PT_NOTE         4       /* Auxiliary information */
-#define        PT_SHLIB        5       /* Reserved */
-#define        PT_PHDR         6       /* Entry for header table itself */
-#define        PT_TLS          7       /* Thread-local storage segment */
-#define        PT_NUM          8       /* Number of defined types */
-#define        PT_LOOS         0x60000000      /* Start of OS-Specific */
-#define        PT_GNU_EH_FRAME 0x6474E550      /* GCC .eh_frame_hdr segment */
-#define        PT_GNU_STACK    0x6474E551      /* Indicates stack executability */
-#define        PT_GNU_RELRO    0x6474E552      /* Read-only after relocation */
-#define        PT_LOSUNW       0x6FFFFFFA
-#define        PT_SHNWBSS      0x6FFFFFFA      /* Sun Specific Segment */
-#define        PT_SUNWSTACK    0x6FFFFFFB      /* Stack segment */
-#define        PT_HISUNW       0x6FFFFFFF
-#define        PT_HIOS         0x6FFFFFFF      /* End of OS-Specific */
-#define        PT_LOPROC       0x70000000      /* Start of processor-specific */
-#define        PT_HIPROC       0x7FFFFFFF      /* End of processor-specific */
+#define PT_NULL        0    /* Program header table entry unused */
+#define PT_LOAD        1    /* Loadable program segment */
+#define PT_DYNAMIC    2    /* Dynamic linking information */
+#define PT_INTERP    3    /* Program interpreter */
+#define PT_NOTE        4    /* Auxiliary information */
+#define PT_SHLIB    5    /* Reserved */
+#define PT_PHDR        6    /* Entry for header table itself */
+#define PT_TLS        7    /* Thread-local storage segment */
+#define PT_NUM        8    /* Number of defined types */
+#define PT_LOOS        0x60000000    /* Start of OS-Specific */
+#define PT_GNU_EH_FRAME    0x6474E550    /* GCC .eh_frame_hdr segment */
+#define PT_GNU_STACK    0x6474E551    /* Indicates stack executability */
+#define PT_GNU_RELRO    0x6474E552    /* Read-only after relocation */
+#define PT_LOSUNW    0x6FFFFFFA
+#define PT_SHNWBSS    0x6FFFFFFA    /* Sun Specific Segment */
+#define PT_SUNWSTACK    0x6FFFFFFB    /* Stack segment */
+#define PT_HISUNW    0x6FFFFFFF
+#define PT_HIOS        0x6FFFFFFF    /* End of OS-Specific */
+#define PT_LOPROC    0x70000000    /* Start of processor-specific */
+#define PT_HIPROC    0x7FFFFFFF    /* End of processor-specific */
 
 #endif //_ELF_H
index 03e0371206752ed188aa2ea4f0828c9b67a41494..bacc95466d2c0cb132bff90020bce7f0b16685a6 100644 (file)
@@ -1,53 +1,53 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        errno.h
+ *   File Name: errno.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Mon Feb  1 17:07:06 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Mon Feb  1 17:07:06 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _ERRNO_H
-#define        _ERRNO_H
+#ifndef    _ERRNO_H
+#define _ERRNO_H
 
-#define        EPERM            1      /* Operation not permitted */
-#define        ENOENT           2      /* No such file or directory */
-#define        ESRCH            3      /* No such process */
-#define        EINTR            4      /* Interrupted system call */
-#define        EIO              5      /* I/O error */
-#define        ENXIO            6      /* No such device or address */
-#define        E2BIG            7      /* Argument list too long */
-#define        ENOEXEC          8      /* Exec format error */
-#define        EBADF            9      /* Bad file number */
-#define        ECHILD          10      /* No child processes */
-#define        EAGAIN          11      /* Try again */
-#define        ENOMEM          12      /* Out of memory */
-#define        EACCES          13      /* Permission denied */
-#define        EFAULT          14      /* Bad address */
-#define        ENOTBLK         15      /* Block device required */
-#define        EBUSY           16      /* Device or resource busy */
-#define        EEXIST          17      /* File exists */
-#define        EXDEV           18      /* Cross-device link */
-#define        ENODEV          19      /* No such device */
-#define        ENOTDIR         20      /* Not a directory */
-#define        EISDIR          21      /* Is a directory */
-#define        EINVAL          22      /* Invalid argument */
-#define        ENFILE          23      /* File table overflow */
-#define        EMFILE          24      /* Too many open files */
-#define        ENOTTY          25      /* Not a typewriter */
-#define        ETXTBSY         26      /* Text file busy */
-#define        EFBIG           27      /* File too large */
-#define        ENOSPC          28      /* No space left on device */
-#define        ESPIPE          29      /* Illegal seek */
-#define        EROFS           30      /* Read-only file system */
-#define        EMLINK          31      /* Too many links */
-#define        EPIPE           32      /* Broken pipe */
-#define        EDOM            33      /* Math argument out of domain of func */
-#define        ERANGE          34      /* Math result not representable */
+#define EPERM         1    /* Operation not permitted */
+#define ENOENT         2    /* No such file or directory */
+#define ESRCH         3    /* No such process */
+#define EINTR         4    /* Interrupted system call */
+#define EIO         5    /* I/O error */
+#define ENXIO         6    /* No such device or address */
+#define E2BIG         7    /* Argument list too long */
+#define ENOEXEC         8    /* Exec format error */
+#define EBADF         9    /* Bad file number */
+#define ECHILD        10    /* No child processes */
+#define EAGAIN        11    /* Try again */
+#define ENOMEM        12    /* Out of memory */
+#define EACCES        13    /* Permission denied */
+#define EFAULT        14    /* Bad address */
+#define ENOTBLK        15    /* Block device required */
+#define EBUSY        16    /* Device or resource busy */
+#define EEXIST        17    /* File exists */
+#define EXDEV        18    /* Cross-device link */
+#define ENODEV        19    /* No such device */
+#define ENOTDIR        20    /* Not a directory */
+#define EISDIR        21    /* Is a directory */
+#define EINVAL        22    /* Invalid argument */
+#define ENFILE        23    /* File table overflow */
+#define EMFILE        24    /* Too many open files */
+#define ENOTTY        25    /* Not a typewriter */
+#define ETXTBSY        26    /* Text file busy */
+#define EFBIG        27    /* File too large */
+#define ENOSPC        28    /* No space left on device */
+#define ESPIPE        29    /* Illegal seek */
+#define EROFS        30    /* Read-only file system */
+#define EMLINK        31    /* Too many links */
+#define EPIPE        32    /* Broken pipe */
+#define EDOM        33    /* Math argument out of domain of func */
+#define ERANGE        34    /* Math result not representable */
 
-extern int errno;
+extern    int errno;
 
 #endif //_ERRNO_H
index 26e86e130afe3735b18b1aada033f6e9d429b7eb..f105ed81d5fe5efef5e27936ec2ed70cd8d9a333 100644 (file)
@@ -1,60 +1,60 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        ext2.h
+ *   File Name: ext2.h
  * 
- * Description:        当然.几乎来自Linux 内核.
+ * Description: 当然.几乎来自Linux 内核.
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Dec 26 22:43:43 2008
  * Last Update: Fri Dec 26 22:43:43 2008
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _EXT2_H
-#define        _EXT2_H
+#ifndef    _EXT2_H
+#define _EXT2_H
 
-#include<types.h>
+#include <types.h>
 
-#define        EXT2_BAD_INO            1
-#define        EXT2_ROOT_INO           2
-#define        EXT2_BOOT_LOADER_INO    5
-#define        EXT2_UNDEL_DIR_INO      6
+#define EXT2_BAD_INO        1
+#define EXT2_ROOT_INO        2
+#define EXT2_BOOT_LOADER_INO    5
+#define EXT2_UNDEL_DIR_INO    6
 
-#define        EXT2_MIN_BLOCK_SIZE     1024
-#define        EXT2_MAX_BLOCK_SIZE     4096
-#define        EXT2_MIN_BLOCK_LOG_SIZE 10
+#define EXT2_MIN_BLOCK_SIZE    1024
+#define EXT2_MAX_BLOCK_SIZE    4096
+#define EXT2_MIN_BLOCK_LOG_SIZE    10
 
-#define        EXT2_SB                 (&ext2_sb)
-#define        EXT2_SECT               (ext2_start_sect)
+#define EXT2_SB            (&ext2_sb)
+#define EXT2_SECT        (ext2_start_sect)
 
-#ifndef        EXT2_SB
+#ifndef    EXT2_SB
 #error "Please define EXT2_SB"
 #endif
 
-#define        EXT2_BLOCK_SIZE         (EXT2_MIN_BLOCK_SIZE <<         \
-                               (EXT2_SB)->s_log_block_size)
+#define EXT2_BLOCK_SIZE        (EXT2_MIN_BLOCK_SIZE <<     \
+                (EXT2_SB)->s_log_block_size)
 
-#define        EXT2_SECT_PER_BLOCK     (EXT2_BLOCK_SIZE/512)
+#define EXT2_SECT_PER_BLOCK    (EXT2_BLOCK_SIZE/512)
 
-#define        EXT2_BLOCK_SIZE_BITS    ((EXT2_SB)->s_log_block_size + 10)
-#define        EXT2_INODE_SIZE         ((EXT2_SB)->s_inode_size)
-#define        EXT2_INODES_PER_BLOCK   (EXT2_BLOCK_SIZE/EXT2_INODE_SIZE)
-#define        EXT2_FIRST_INO          ((EXT2_SB)->s_first_ino)
+#define EXT2_BLOCK_SIZE_BITS    ((EXT2_SB)->s_log_block_size + 10)
+#define EXT2_INODE_SIZE        ((EXT2_SB)->s_inode_size)
+#define EXT2_INODES_PER_BLOCK    (EXT2_BLOCK_SIZE/EXT2_INODE_SIZE)
+#define EXT2_FIRST_INO        ((EXT2_SB)->s_first_ino)
 /* 
  * 表示第一个块号. 因为SuperBlock总是从第三个扇区开始的所以如果块的大小
  * 是1024的话SuperBlock的块号是1.而如果块的大小是2048或4096则SuperBlock
  * 的块号是0
  */
-#define        EXT2_FIRST_BLOCK_ID     (EXT2_BLOCK_SIZE == 1024)
+#define EXT2_FIRST_BLOCK_ID    (EXT2_BLOCK_SIZE == 1024)
 
-#define        EXT2_BLOCKS_PER_GROUP   ((EXT2_SB)->s_blocks_per_group)
-#define        EXT2_DESC_PER_BLOCK     ((EXT2_SB)->s_desc_per_block)
-#define        EXT2_INODES_PER_GROUP   ((EXT2_SB)->s_inodes_per_group)
-#define        EXT2_INODES_COUNT       ((EXT2_SB)->s_inodes_count)
+#define EXT2_BLOCKS_PER_GROUP    ((EXT2_SB)->s_blocks_per_group)
+#define EXT2_DESC_PER_BLOCK    ((EXT2_SB)->s_desc_per_block)
+#define EXT2_INODES_PER_GROUP    ((EXT2_SB)->s_inodes_per_group)
+#define EXT2_INODES_COUNT    ((EXT2_SB)->s_inodes_count)
 
 /*
  * ------------------------------------------------------------------------
 typedef struct ext2_superblock
 {
 /*
-       u32     s_inodes_count;
-       u32     s_blocks_count;
-       u32     s_r_blocks_count;
-       u32     s_free_blocks_count;
-       u32     s_free_inodes_count;
-       u32     s_first_data_block;
-       u32     s_log_block_size;
-       u32     s_log_frag_size;
-       u32     s_blocks_per_group;
-       u32     s_frags_per_group;
-       u32     s_inodes_per_group;
-
-       // So Much Items
-       // I do not want to write down ...
+    u32    s_inodes_count;
+    u32    s_blocks_count;
+    u32    s_r_blocks_count;
+    u32    s_free_blocks_count;
+    u32    s_free_inodes_count;
+    u32    s_first_data_block;
+    u32    s_log_block_size;
+    u32    s_log_frag_size;
+    u32    s_blocks_per_group;
+    u32    s_frags_per_group;
+    u32    s_inodes_per_group;
+
+    // So Much Items
+    // I do not want to write down ...
 */
-       u32     s_inodes_count;         /* Inodes count */
-       u32     s_blocks_count;         /* Blocks count */
-       u32     s_r_blocks_count;       /* Reserved blocks count */
-       u32     s_free_blocks_count;    /* Free blocks count */
-       u32     s_free_inodes_count;    /* Free inodes count */
-       u32     s_first_data_block;     /* First Data Block */
-       u32     s_log_block_size;       /* Block size */
-       u32     s_log_frag_size;        /* Fragment size */
-       u32     s_blocks_per_group;     /* # Blocks per group */
-       u32     s_frags_per_group;      /* # Fragments per group */
-       u32     s_inodes_per_group;     /* # Inodes per group */
-       u32     s_mtime;                /* Mount time */
-       u32     s_wtime;                /* Write time */
-       u16     s_mnt_count;            /* Mount count */
-       u16     s_max_mnt_count;        /* Maximal mount count */
-       u16     s_magic;                /* Magic signature */
-       u16     s_state;                /* File system state */
-       u16     s_errors;       /* Behaviour when detecting errors */
-       u16     s_minor_rev_level;      /* minor revision level */
-       u32     s_lastcheck;            /* time of last check */
-       u32     s_checkinterval;        /* max. time between checks */
-       u32     s_creator_os;           /* OS */
-       u32     s_rev_level;            /* Revision level */
-       u16     s_def_resuid;   /* Default uid for reserved blocks */
-       u16     s_def_resgid;   /* Default gid for reserved blocks */
-       /*
-        * These fields are for EXT2_DYNAMIC_REV superblocks only.
-        *
-        * Note: the difference between the compatible feature set and
-        * the incompatible feature set is that if there is a bit set
-        * in the incompatible feature set that the kernel doesn't
-        * know about, it should refuse to mount the filesystem.
-        
-        * e2fsck's requirements are more strict; if it doesn't know
-        * about a feature in either the compatible or incompatible
-        * feature set, it must abort and not try to meddle with
-        * things it doesn't understand...
-        */
-       u32     s_first_ino;            /* First non-reserved inode */
-       u16     s_inode_size;           /* size of inode structure */
-       u16     s_block_group_nr; /* block group # of this superblock */
-       u32     s_feature_compat;       /* compatible feature set */
-       u32     s_feature_incompat;     /* incompatible feature set */
-       u32     s_feature_ro_compat; /* readonly-compatible feature set */
-       u8      s_uuid[16];             /* 128-bit uuid for volume */
-       char    s_volume_name[16];      /* volume name */
-       char    s_last_mounted[64];     /* directory where last mounted */
-       u32     s_algorithm_usage_bitmap; /* For compression */
-       /*
-        * Performance hints.  Directory preallocation should only
-        * happen if the EXT2_COMPAT_PREALLOC flag is on.
-        */
-       u8      s_prealloc_blocks;/* Nr of blocks to try to preallocate*/
-       u8      s_prealloc_dir_blocks;/* Nr to preallocate for dirs */
-       u16     s_padding1;
-       /*
-        * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
-        */
-       u8      s_journal_uuid[16];     /* uuid of journal superblock */
-       u32     s_journal_inum;         /* inode number of journal file */
-       u32     s_journal_dev;          /* device number of journal file */
-       u32     s_last_orphan;  /* start of list of inodes to delete */
-       u32     s_hash_seed[4];         /* HTREE hash seed */
-       u8      s_def_hash_version;     /* Default hash version to use */
-       u8      s_reserved_char_pad;
-       u16     s_reserved_word_pad;
-       u32     s_default_mount_opts;
-       u32     s_first_meta_bg;        /* First metablock block group */
-       u32     s_reserved[190];/* Padding to the end of the block */
+    u32    s_inodes_count;        /* Inodes count */
+    u32    s_blocks_count;        /* Blocks count */
+    u32    s_r_blocks_count;    /* Reserved blocks count */
+    u32    s_free_blocks_count;    /* Free blocks count */
+    u32    s_free_inodes_count;    /* Free inodes count */
+    u32    s_first_data_block;    /* First Data Block */
+    u32    s_log_block_size;    /* Block size */
+    u32    s_log_frag_size;    /* Fragment size */
+    u32    s_blocks_per_group;    /* # Blocks per group */
+    u32    s_frags_per_group;    /* # Fragments per group */
+    u32    s_inodes_per_group;    /* # Inodes per group */
+    u32    s_mtime;        /* Mount time */
+    u32    s_wtime;        /* Write time */
+    u16    s_mnt_count;        /* Mount count */
+    u16    s_max_mnt_count;    /* Maximal mount count */
+    u16    s_magic;        /* Magic signature */
+    u16    s_state;        /* File system state */
+    u16    s_errors;    /* Behaviour when detecting errors */
+    u16    s_minor_rev_level;     /* minor revision level */
+    u32    s_lastcheck;        /* time of last check */
+    u32    s_checkinterval;    /* max. time between checks */
+    u32    s_creator_os;        /* OS */
+    u32    s_rev_level;        /* Revision level */
+    u16    s_def_resuid;    /* Default uid for reserved blocks */
+    u16    s_def_resgid;    /* Default gid for reserved blocks */
+    /*
+     * These fields are for EXT2_DYNAMIC_REV superblocks only.
+     *
+     * Note: the difference between the compatible feature set and
+     * the incompatible feature set is that if there is a bit set
+     * in the incompatible feature set that the kernel doesn't
+     * know about, it should refuse to mount the filesystem.
+     * 
+     * e2fsck's requirements are more strict; if it doesn't know
+     * about a feature in either the compatible or incompatible
+     * feature set, it must abort and not try to meddle with
+     * things it doesn't understand...
+     */
+    u32    s_first_ino;         /* First non-reserved inode */
+    u16    s_inode_size;         /* size of inode structure */
+    u16    s_block_group_nr; /* block group # of this superblock */
+    u32    s_feature_compat;     /* compatible feature set */
+    u32    s_feature_incompat;     /* incompatible feature set */
+    u32    s_feature_ro_compat; /* readonly-compatible feature set */
+    u8    s_uuid[16];        /* 128-bit uuid for volume */
+    char    s_volume_name[16];     /* volume name */
+    char    s_last_mounted[64];     /* directory where last mounted */
+    u32    s_algorithm_usage_bitmap; /* For compression */
+    /*
+     * Performance hints.  Directory preallocation should only
+     * happen if the EXT2_COMPAT_PREALLOC flag is on.
+     */
+    u8    s_prealloc_blocks;/* Nr of blocks to try to preallocate*/
+    u8    s_prealloc_dir_blocks;/* Nr to preallocate for dirs */
+    u16    s_padding1;
+    /*
+     * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
+     */
+    u8    s_journal_uuid[16];    /* uuid of journal superblock */
+    u32    s_journal_inum;        /* inode number of journal file */
+    u32    s_journal_dev;        /* device number of journal file */
+    u32    s_last_orphan;    /* start of list of inodes to delete */
+    u32    s_hash_seed[4];        /* HTREE hash seed */
+    u8    s_def_hash_version;    /* Default hash version to use */
+    u8    s_reserved_char_pad;
+    u16    s_reserved_word_pad;
+    u32    s_default_mount_opts;
+     u32    s_first_meta_bg;     /* First metablock block group */
+    u32    s_reserved[190];/* Padding to the end of the block */
 } SuperBlock,*pSuperBlock;
 
 extern SuperBlock ext2_sb;
@@ -155,54 +155,54 @@ extern SuperBlock ext2_sb;
 
 typedef struct ext2_group_descriptor
 {
-       u32     bg_block_bitmap;
-       u32     bg_inode_bitmap;
-       u32     bg_inode_table;
-       u16     bg_free_blocks_count;
-       u16     bg_free_inodes_count;
-       u16     bg_used_dirs_count;
-       u16     bg_pad;
-       u32     bg_reserved[3];
+    u32    bg_block_bitmap;
+    u32    bg_inode_bitmap;
+    u32    bg_inode_table;
+    u16    bg_free_blocks_count;
+    u16    bg_free_inodes_count;
+    u16    bg_used_dirs_count;
+    u16    bg_pad;
+    u32    bg_reserved[3];
 } GroupDesc,*pGroupDesc;
 
-#define        EXT2_NDIR_BLOCKS        (12)
-#define        EXT2_IND_BLOCK          (EXT2_NDIR_BLOCKS)
-#define        EXT2_DIND_BLOCK         (EXT2_IND_BLOCK + 1)
-#define        EXT2_TIND_BLOCK         (EXT2_DIND_BLOCK + 1)
-#define        EXT2_N_BLOCKS           (EXT2_TIND_BLOCK + 1)
+#define EXT2_NDIR_BLOCKS    (12)
+#define EXT2_IND_BLOCK        (EXT2_NDIR_BLOCKS)
+#define EXT2_DIND_BLOCK        (EXT2_IND_BLOCK + 1)
+#define EXT2_TIND_BLOCK        (EXT2_DIND_BLOCK + 1)
+#define EXT2_N_BLOCKS        (EXT2_TIND_BLOCK + 1)
 
 
 typedef struct ext2_inode
 {
-       u16     i_mode;
-       u16     i_uid;
-       u32     i_size;
-       u32     i_atime;
-       u32     i_ctime;
-       u32     i_mtime;
-       u32     i_dtime;
-       u16     i_gid;
-       u16     i_links_count;
-       u32     i_blocks;
-       u32     i_flags;
-       u32     i_osd1;
-       u32     i_block[EXT2_N_BLOCKS];
-       u32     i_generation;
-       u32     i_file_acl;
-       u32     i_dir_acl;
-       u32     i_faddr;
-       u8      i_osd2[12];
+    u16    i_mode;
+    u16    i_uid;
+    u32    i_size;
+    u32    i_atime;
+    u32    i_ctime;
+    u32    i_mtime;
+    u32    i_dtime;
+    u16    i_gid;
+    u16    i_links_count;
+    u32    i_blocks;
+    u32    i_flags;
+    u32    i_osd1;
+    u32    i_block[EXT2_N_BLOCKS];
+    u32    i_generation;
+    u32    i_file_acl;
+    u32    i_dir_acl;
+    u32    i_faddr;
+    u8    i_osd2[12];
 } Inode,*pInode;
 
 
-#define        EXT2_NAME_LEN   255
+#define EXT2_NAME_LEN    255
 typedef struct ext2_dir_ent
 {
-       u32     inode;
-       u16     rec_len;
-       u8      name_len;
-       u8      file_type;              /* 目录类型 */
-       char    name[EXT2_NAME_LEN];
+    u32    inode;
+    u16    rec_len;
+    u8    name_len;
+    u8    file_type;        /* 目录类型 */
+    char    name[EXT2_NAME_LEN];
 } DirEnt, *pDirEnt;
 
 /*
@@ -211,28 +211,28 @@ typedef struct ext2_dir_ent
  */
 enum
 {
-       EXT2_FT_UNKNOWN,
-       EXT2_FT_REG_FILE,
-       EXT2_FT_DIR,
-       EXT2_FT_CHRDEV,
-       EXT2_FT_BLKDEV,
-       EXT2_FT_FIFO,
-       EXT2_FT_SOCK,
-       EXT2_FT_SYMLINK,
-       EXT2_FT_MAX
+    EXT2_FT_UNKNOWN,
+    EXT2_FT_REG_FILE,
+    EXT2_FT_DIR,
+    EXT2_FT_CHRDEV,
+    EXT2_FT_BLKDEV,
+    EXT2_FT_FIFO,
+    EXT2_FT_SOCK,
+    EXT2_FT_SYMLINK,
+    EXT2_FT_MAX
 };
 
 
-#define        EXT2_DIR_PAD                    4
-#define        EXT2_DIR_ROUND                  (EXT2_DIR_PAD-1)
-#define        EXT2_DIR_REC_LEN(name_len)      (((name_len)+8+EXT2_DIR_ROUND) & \
-                                               ~EXT2_DIR_ROUND)
-#define        EXT2_MAX_REC_LEN                ((1<<16)-1)
+#define EXT2_DIR_PAD            4
+#define EXT2_DIR_ROUND            (EXT2_DIR_PAD-1)
+#define EXT2_DIR_REC_LEN(name_len)    (((name_len)+8+EXT2_DIR_ROUND) & \
+                        ~EXT2_DIR_ROUND)
+#define EXT2_MAX_REC_LEN        ((1<<16)-1)
 
 
-extern int ext2_read_inode(unsigned int n, pInode inode);
-extern int ext2_get_file_inode(const char *path, pInode inode);
-extern int ext2_read_file(const pInode ino, void *buf, size_t count);
+extern    int ext2_read_inode(unsigned int n, pInode inode);
+extern    int ext2_get_file_inode(const char *path, pInode inode);
+extern    int ext2_read_file(const pInode ino, void *buf, size_t count);
 
 
 #endif //_EXT2_H
index fb871c7a19894c7e6091219406da70c9908e2383..5a0e72f880eaeb83ac51e3a118d0f7eb0617b7d6 100644 (file)
@@ -1,32 +1,32 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        fcntl.h
+ *   File Name: fcntl.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 16:24:15 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 16:24:15 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _FCNTL_H
-#define        _FCNTL_H
+#ifndef    _FCNTL_H
+#define _FCNTL_H
 
-#define O_ACCMODE         0003
-#define O_RDONLY            00
-#define O_WRONLY            01
-#define O_RDWR              02
-#define O_CREAT                   0100 /* not fcntl */
-#define O_EXCL            0200 /* not fcntl */
-#define O_NOCTTY          0400 /* not fcntl */
-#define O_TRUNC                  01000 /* not fcntl */
-#define O_APPEND         02000
-#define O_NONBLOCK       04000
-#define O_NDELAY       O_NONBLOCK
-#define O_SYNC          010000
-#define O_FSYNC                 O_SYNC
-#define O_ASYNC                 020000
+#define O_ACCMODE       0003
+#define O_RDONLY         00
+#define O_WRONLY         01
+#define O_RDWR             02
+#define O_CREAT           0100    /* not fcntl */
+#define O_EXCL           0200    /* not fcntl */
+#define O_NOCTTY       0400    /* not fcntl */
+#define O_TRUNC          01000    /* not fcntl */
+#define O_APPEND      02000
+#define O_NONBLOCK      04000
+#define O_NDELAY    O_NONBLOCK
+#define O_SYNC         010000
+#define O_FSYNC         O_SYNC
+#define O_ASYNC         020000
 
 
 #endif //_FCNTL_H
index 0240f86336d6f2dfff4bbe939be6890ed538f7f7..e81046930103b44910c82b48de4a1739d39a1c30 100644 (file)
@@ -1,69 +1,69 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        fs.h
+ *   File Name: fs.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Fri Feb 12 22:29:59 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Fri Feb 12 22:29:59 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _FS_H
-#define        _FS_H
+#ifndef    _FS_H
+#define _FS_H
 
-#include<types.h>
-#include<page.h>
-#include<ext2.h>
+#include <types.h>
+#include <page.h>
+#include <ext2.h>
 
 typedef struct partition
 {
-       u8      State;
-       u8      Head;
-       u16     StartSC;
-       u8      Type;
-       u8      EndHead;
-       u16     EndSC;
-       u32     AbsoluteSectNo;
-       u32     PartitionSize;
+    u8    State;
+    u8    Head;
+    u16    StartSC;
+    u8    Type;
+    u8    EndHead;
+    u16    EndSC;
+    u32    AbsoluteSectNo;
+    u32    PartitionSize;
 } Partition, *pPartition;
 
 
 /* 分区表开始的位置 */
-#define        PARTS_POS       0x1BE
+#define PARTS_POS    0x1BE
 
 /* 设备的主设备号. 占用两个字节. */
-#define        DEV_MAJOR_UNUSED        0x0000
-#define        DEV_MAJOR_MEM           0x0001
-#define        DEV_MAJOR_TTY           0x0002
-#define        DEV_MAJOR_IDE0          0x0003
-#define        DEV_MAJOR_HD            DEV_MAJOR_IDE0
-#define        DEV_MAJOR_IDE1          0x0004
-#define        DEV_MAJOR_SCSI0         0x0005
-#define        DEV_MAJOR_SCSI2         0x0006
+#define DEV_MAJOR_UNUSED    0x0000
+#define DEV_MAJOR_MEM        0x0001
+#define DEV_MAJOR_TTY        0x0002
+#define DEV_MAJOR_IDE0        0x0003
+#define DEV_MAJOR_HD        DEV_MAJOR_IDE0
+#define DEV_MAJOR_IDE1        0x0004
+#define DEV_MAJOR_SCSI0        0x0005
+#define DEV_MAJOR_SCSI2        0x0006
 
-#define        DEV_MAJOR_BITS          (16)
-#define        DEV_MINOR_MASK          ((1UL << DEV_MAJOR_BITS) - 1)
+#define DEV_MAJOR_BITS        (16)
+#define DEV_MINOR_MASK        ((1UL << DEV_MAJOR_BITS) - 1)
 
-#define        MAKE_DEV(major, minor)  ((major) << DEV_MAJOR_BITS | minor)
+#define MAKE_DEV(major, minor)    ((major) << DEV_MAJOR_BITS | minor)
 
-#define        DEV_MAJOR(dev)          ((unsigned int)((dev) >> DEV_MAJOR_BITS))
-#define        DEV_MINOR(dev)          ((unsigned int)((dev) &  DEV_MINOR_MASK))
+#define DEV_MAJOR(dev)        ((unsigned int)((dev) >> DEV_MAJOR_BITS))
+#define DEV_MINOR(dev)        ((unsigned int)((dev) &  DEV_MINOR_MASK))
 
 
 
 typedef struct
 {
-       int     count;
-       int     ino_nr;
-       pInode  inode;
+    int    count;
+    int    ino_nr;
+    pInode    inode;
 } File, *pFile;
 
-#define        MAX_SUPT_FILE_SIZE      (EXT2_IND_BLOCK*EXT2_BLOCK_SIZE)
-#define        NR_FILES        (PAGE_SIZE/sizeof(File))
-#define        NR_INODES       (2*NR_FILES)
-#define        NR_OPENS        (2)     /* 一个进程同时打开文件的限制数 */
+#define MAX_SUPT_FILE_SIZE    (EXT2_IND_BLOCK*EXT2_BLOCK_SIZE)
+#define NR_FILES    (PAGE_SIZE/sizeof(File))
+#define NR_INODES    (2*NR_FILES)
+#define NR_OPENS    (2)    /* 一个进程同时打开文件的限制数 */
 extern File file_table[NR_FILES];
 extern Inode inode_table[NR_INODES];
 
@@ -72,17 +72,17 @@ extern Inode inode_table[NR_INODES];
 
 static inline int get_inode_nr(const char *path)
 {
-       return ext2_get_file_inode_nr(path);
+    return ext2_get_file_inode_nr(path);
 }
 
 static inline int get_inode(unsigned int n, pInode inode)
 {
-       return ext2_read_inode(n, inode);
+    return ext2_read_inode(n, inode);
 }
 
 static inline int read_file(const pInode inode, void *buf, size_t count)
 {
-       return ext2_read_file(inode, buf, count);
+    return ext2_read_file(inode, buf, count);
 }
 
 /* 在多进程下这样肯定不行 
@@ -90,18 +90,18 @@ static inline int read_file(const pInode inode, void *buf, size_t count)
  */
 static inline pInode find_empty_inode()
 {
-       int i;
-       pInode p = inode_table;
-       for(i=0; i<NR_FILES; i++, p++)
-       {
-               if(p->i_size == 0)
-               {
-                       p->i_size = 1;
-                       return p;
-               }
-       }
-
-       return NULL;
+    int i;
+    pInode p = inode_table;
+    for(i=0; i<NR_FILES; i++, p++)
+    {
+        if(p->i_size == 0)
+        {
+            p->i_size = 1;
+            return p;
+        }
+    }
+
+    return NULL;
 }
 
 #endif //_FS_H
index e2d02f227754529052397986d452603e6d485017..00c63745fb77cc44d30ae26733f8a75a94c5faf0 100644 (file)
@@ -1,21 +1,21 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        global.h
+ *   File Name: global.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jan 23 14:12:40 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jan 23 14:12:40 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _GLOBAL_H
-#define        _GLOBAL_H
+#ifndef    _GLOBAL_H
+#define _GLOBAL_H
 
 
-#ifndef        __STRING
-#define        __STRING(x)     #x
+#ifndef    __STRING
+#define __STRING(x)    #x
 #endif
 
 #endif //_GLOBAL_H
index 009906d6ce9b394cdcd59d700f02a64dedf36bcc..aee8b5c7a0415dad0612075b14bfb647d6b26202 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        i8259.h
+ *   File Name: i8259.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Nov  9 11:37:09 2008
  *     Version: 1.1
  * Last Update: Tue Feb 10 20:28:47 2009
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _I8259_H
-#define        _I8259_H
+#ifndef    _I8259_H
+#define _I8259_H
 
 #include "irq.h"
 #include "io.h"
 
-#define        PIC_MASTER_CMD  0x20
-#define        PIC_MASTER_IMR  0x21
-#define        PIC_SLAVER_CMD  0xA0
-#define        PIC_SLAVER_IMR  0xA1
+#define PIC_MASTER_CMD    0x20
+#define PIC_MASTER_IMR    0x21
+#define PIC_SLAVER_CMD    0xA0
+#define PIC_SLAVER_IMR    0xA1
 
-#define        PIC_MASTER_ISR  PIC_MASTER_CMD
-#define        PIC_SLAVER_ISR  PIC_SLAVER_CMD
+#define PIC_MASTER_ISR    PIC_MASTER_CMD
+#define PIC_SLAVER_ISR    PIC_SLAVER_CMD
 
-#define        PIC_CASCADE_IR  0x2     //The IR2 on Master Connect to Slaver.
+#define PIC_CASCADE_IR    0x2    //The IR2 on Master Connect to Slaver.
 
 extern void init_i8259();
 extern void mask_i8259();
 
 static inline int enable_i8259_irq(unsigned int irq)
 {
-       unsigned char mask = ~(1 << irq);
-       if(irq & 8)
-       {
-               mask &= inb(PIC_SLAVER_IMR);
-               outb( mask, PIC_SLAVER_IMR);
-       }
-       else
-       {
-               mask &= inb(PIC_MASTER_IMR);
-               outb_p( mask, PIC_MASTER_IMR);
-       }
+    unsigned char mask = ~(1 << irq);
+    if(irq & 8)
+    {
+        mask &= inb(PIC_SLAVER_IMR);
+        outb( mask, PIC_SLAVER_IMR);
+    }
+    else
+    {
+        mask &= inb(PIC_MASTER_IMR);
+        outb_p( mask, PIC_MASTER_IMR);
+    }
 }
 static inline int disable_i8259_irq(unsigned int irq)
 {
-       unsigned char mask = 1 << irq;
-       if(irq & 8)
-       {
-               mask |= inb(PIC_SLAVER_IMR);
-               outb( mask, PIC_SLAVER_IMR);
-       }
-       else
-       {
-               mask |= inb(PIC_MASTER_IMR);
-               outb( mask, PIC_MASTER_IMR);
-       }
+    unsigned char mask = 1 << irq;
+    if(irq & 8)
+    {
+        mask |= inb(PIC_SLAVER_IMR);
+        outb( mask, PIC_SLAVER_IMR);
+    }
+    else
+    {
+        mask |= inb(PIC_MASTER_IMR);
+        outb( mask, PIC_MASTER_IMR);
+    }
 }
 
 static inline void mask_ack_i8259_irq(unsigned int irq)
 {
-       unsigned int mask = 1 << irq;
+    unsigned int mask = 1 << irq;
 
-       if(irq & 8)
-       {
-               mask |= inb(PIC_SLAVER_IMR);
-               // Mask
-               outb(mask, PIC_SLAVER_IMR);
-               // Specific EOI to slave
-               outb(0x60 + (irq & 0x07), PIC_SLAVER_CMD);
-               // Specific EOI to master
-               outb(0x60 + (PIC_CASCADE_IR & 0x07), PIC_MASTER_CMD);
-       }
-       else
-       {
-               mask |= inb(PIC_MASTER_IMR);
-               // Mask
-               outb(mask, PIC_MASTER_IMR);
-               // Specific EOI to master
-               outb(0x60 + irq, PIC_MASTER_CMD);
-       }
+    if(irq & 8)
+    {
+        mask |= inb(PIC_SLAVER_IMR);
+        // Mask
+        outb(mask, PIC_SLAVER_IMR);
+        // Specific EOI to slave
+        outb(0x60 + (irq & 0x07), PIC_SLAVER_CMD);
+        // Specific EOI to master
+        outb(0x60 + (PIC_CASCADE_IR & 0x07), PIC_MASTER_CMD);
+    }
+    else
+    {
+        mask |= inb(PIC_MASTER_IMR);
+        // Mask
+        outb(mask, PIC_MASTER_IMR);
+        // Specific EOI to master
+        outb(0x60 + irq, PIC_MASTER_CMD);
+    }
 
 /*
-       // None Specific EOI
-       outb(0x20, PIC_MASTER_CMDA);
-       outb(0x20, PIC_SLAVER_CMDA);
+    // None Specific EOI
+    outb(0x20, PIC_MASTER_CMDA);
+    outb(0x20, PIC_SLAVER_CMDA);
 */
 }
 
index ea21313f01591c392f07122b56296e26e803f989..75c3a066825d53c0e3e886a566406ac74991bd1e 100644 (file)
@@ -1,86 +1,86 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        io.h
+ *   File Name: io.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Mon Jun 18 23:25:23 2007
  * Last Update: Mon Jun 18 23:25:23 2007
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _IO_H
-#define        _IO_H
+#ifndef    _IO_H
+#define _IO_H
 
-#include<types.h>
+#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)({                                    \
-u8 _bt;                                                \
-asm("inb       %%dx,%%al"                              \
-:"=a" (_bt)                                            \
-:"d" (port));                                          \
-_bt;                                                   \
+#define inb(port)({                     \
+u8 _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 585d65cf576d35d3e14cdf074409a189b799204c..53b06c94a84f548e6b195392cc475be65cc6a7b6 100644 (file)
@@ -1,67 +1,67 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        irq.h
+ *   File Name: irq.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Nov 28 16:38:25 2008
  * Last Update: Fri Nov 28 16:38:25 2008
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _IRQ_H
-#define        _IRQ_H
+#ifndef    _IRQ_H
+#define _IRQ_H
 
-#include"system.h"
+#include "system.h"
 
-#define        NR_IRQS         224
-#define        FIRST_IRQ_VECT  0x20
+#define NR_IRQS        224
+#define FIRST_IRQ_VECT    0x20
 
-typedef        struct
+typedef    struct
 {
-       const char *name;
-       int     (*enable)(unsigned int irq);
-       int     (*disable)(unsigned int irq);
-       void    (*ack)(unsigned int irq);
+    const char *name;
+    int     (*enable)(unsigned int irq);
+    int     (*disable)(unsigned int irq);
+    void    (*ack)(unsigned int irq);
 } IrqChip, *pIrqChip;
 
 typedef struct irqaction
 {
-       //void (*handler)(pPtRegs regs, unsigned int irq);
-       void    (*handler)(unsigned int irq, pPtRegs regs, void *dev_id);
-       const char *dev_name;
-       void *dev_id;
-       struct irqaction *next; 
+    //void (*handler)(pPtRegs regs, unsigned int irq);
+    void    (*handler)(unsigned int irq, pPtRegs regs, void *dev_id);
+    const char *dev_name;
+    void *dev_id;
+    struct irqaction *next;    
 } IrqAction, *pIrqAction;
 
-typedef        struct
+typedef    struct
 {
-       pIrqChip        chip;
-       pIrqAction      action;
-       unsigned int    status;
-       unsigned int    depth;
+    pIrqChip    chip;
+    pIrqAction    action;
+    unsigned int    status;
+    unsigned int    depth;
 } IrqDesc, *pIrqDesc;
 
-extern IrqChip i8259_chip;
-extern IrqDesc irq_desc[];
-extern IrqDesc no_irq_desc;
-int    request_irq(unsigned int irq,
-       //void (*handler)(pPtRegs, unsigned int),
-       void    (*handler)(unsigned int, pPtRegs, void *),
-       const char *devname,
-       void    *dev_id);
+extern    IrqChip    i8259_chip;
+extern    IrqDesc    irq_desc[];
+extern    IrqDesc    no_irq_desc;
+int    request_irq(unsigned int irq,
+    //void (*handler)(pPtRegs, unsigned int),
+    void    (*handler)(unsigned int, pPtRegs, void *),
+    const char *devname,
+    void    *dev_id);
 
 static inline int enable_irq(unsigned int irq)
 {
-       return irq_desc[irq].chip->enable(irq);
+    return irq_desc[irq].chip->enable(irq);
 }
 static inline int disable_irq(unsigned int irq)
 {
-       return irq_desc[irq].chip->disable(irq);
+    return irq_desc[irq].chip->disable(irq);
 }
 #endif //_IRQ_H
index b40d5f0b970fb1d704f7529ce88c6fb907c638b6..ccbe68d97546cb7c55e35e40503dc82025a81cf2 100644 (file)
@@ -1,27 +1,27 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        linkage.h
+ *   File Name: linkage.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Jul  10 11:19:26 2009
  * Last Update: Fri Jul  10 11:19:26 2009
  * 
  *--------------------------------------------------------------------------
  */
-#ifndef        __LINKAGE_H
-#define        __LINKAGE_H
+#ifndef    __LINKAGE_H
+#define __LINKAGE_H
 
-#define        ALIGN           .align  0x04,0x90
-#define        ALIGN_STR       ".align 0x04,0x90"
-#define        ENTRY(symbol)   \
-       .global symbol; \
-       ALIGN;          \
-       symbol:
+#define ALIGN        .align    0x04,0x90
+#define ALIGN_STR    ".align    0x04,0x90"
+#define ENTRY(symbol)    \
+    .global    symbol;    \
+    ALIGN;        \
+    symbol:
 
 
 
index b25fdea24e7e8ede3331fae4244fd08d864735b4..4b087ff40a3180e56049b04a586fb2e399d06462 100644 (file)
@@ -1,87 +1,87 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        list.h
+ *   File Name: list.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Mon Apr 20 20:52:05 2009
  * Last Update: Mon Apr 20 20:52:05 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _LIST_H
-#define        _LIST_H
+#ifndef    _LIST_H
+#define _LIST_H
 
 /* Allmost Copy From Linux */
 typedef struct list_head
 {
-       struct list_head *prev, *next;
+    struct list_head *prev, *next;
 } ListHead, *pListHead;
 
-#define        LIST_HEAD_INIT(name) {&(name), &(name) }
-#define        LIST_HEAD(name) ListHead name = LIST_HEAD_INIT(name)
-#define        INIT_LIST_HEAD(ptr)             \
-do{                                    \
-       (ptr)->next = (ptr);            \
-       (ptr)->prev = (ptr);            \
+#define LIST_HEAD_INIT(name) {&(name), &(name) }
+#define LIST_HEAD(name) ListHead name = LIST_HEAD_INIT(name)
+#define INIT_LIST_HEAD(ptr)         \
+do{                    \
+    (ptr)->next = (ptr);        \
+    (ptr)->prev = (ptr);        \
 }while(0)
 
-#define        list_entry(ptr, type, member)   \
-       ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+#define list_entry(ptr, type, member)    \
+    ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
 
-#define        list_for_each(pos, head)        \
-       for(pos = (head)->next; pos != (head); pos = pos->next)
-#define        list_for_each_safe(pos, tmp, head)              \
-       for(pos = (head)->next, tmp = pos->next;        \
-               pos != (head);                          \
-               pos = tmp, tmp = pos->next)
+#define list_for_each(pos, head)    \
+    for(pos = (head)->next; pos != (head); pos = pos->next)
+#define list_for_each_safe(pos, tmp, head)        \
+    for(pos = (head)->next, tmp = pos->next;    \
+        pos != (head);                \
+        pos = tmp, tmp = pos->next)
 
-static inline void _list_add(  pListHead newItem,
-                               pListHead prev,
-                               pListHead next)
+static inline void _list_add(    pListHead newItem,
+                pListHead prev,
+                pListHead next)
 {
-       next->prev      = newItem;
-       newItem->next   = next;
-       newItem->prev   = prev;
-       prev->next      = newItem;
+    next->prev    = newItem;
+    newItem->next    = next;
+    newItem->prev    = prev;
+    prev->next    = newItem;
 }
 
 static inline void list_add(pListHead newItem, pListHead head)
 {
-       _list_add(newItem, head, head->next);
+    _list_add(newItem, head, head->next);
 }
 
 static inline void list_add_tail(pListHead newItem, pListHead head)
 {
-       _list_add(newItem, head->prev, head);
+    _list_add(newItem, head->prev, head);
 }
 
 
 static inline void _list_del(pListHead prev, pListHead next)
 {
-       next->prev = prev;
-       prev->next = next;
+    next->prev = prev;
+    prev->next = next;
 }
 
 static inline void list_del(pListHead entry)
 {
-       _list_del(entry->prev, entry->next);
+    _list_del(entry->prev, entry->next);
 }
 
 static inline void list_del_init(pListHead entry)
 {
-       _list_del(entry->prev, entry->next);
-       INIT_LIST_HEAD(entry);
+    _list_del(entry->prev, entry->next);
+    INIT_LIST_HEAD(entry);
 }
 
 static inline int list_is_empty(pListHead head)
 {
-       return head->next == head;
+    return head->next == head;
 }
 
 
index 319d8f50eb4222718ef727d21782eb28040d4604..725caf27f29f288d9654e575211779b223584c90 100644 (file)
@@ -1,28 +1,28 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        msr.h
+ *   File Name: msr.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Jan  2 19:54:18 2009
  * Last Update: Fri Jan  2 19:54:18 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _MSR_H
-#define        _MSR_H
+#ifndef    _MSR_H
+#define _MSR_H
 
-#define        MSR_SYSENTER_CS         0x174
-#define        MSR_SYSENTER_ESP        0x175
-#define        MSR_SYSENTER_EIP        0x176
+#define MSR_SYSENTER_CS        0x174
+#define MSR_SYSENTER_ESP    0x175
+#define MSR_SYSENTER_EIP    0x176
 
-#define        wrmsr(msr, lowval, highval) do{\
-       asm("wrmsr;"::"c"(msr),"a"(lowval),"d"(highval));\
+#define wrmsr(msr, lowval, highval) do{\
+    asm("wrmsr;"::"c"(msr),"a"(lowval),"d"(highval));\
 }while(0);
 
 
index 3fa10386bba4e6405fb29db33eeee249285c9eb4..0eb6492ea48edc3d7a2f12af08d16f6cc479173f 100644 (file)
@@ -1,56 +1,56 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        page.h
+ *   File Name: page.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sat Feb  7 21:47:42 2009
  * Last Update: Sat Feb  7 21:47:42 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _PAGE_H
-#define        _PAGE_H
+#ifndef    _PAGE_H
+#define _PAGE_H
 
 
 
-#define        PAGE_P          0x0
-#define        PAGE_WR         0x1
-#define        PAGE_US         0x2
+#define PAGE_P        0x0
+#define PAGE_WR        0x1
+#define PAGE_US        0x2
 
-#define        PAGE_SHIFT      (12)
-#define        PAGE_SIZE       (1UL << PAGE_SHIFT)
-#define        PAGE_MASK       (~((1UL << PAGE_SHIFT)-1))
-#define        PAGE_OFFSET     (0xC0000000)
+#define PAGE_SHIFT    (12)
+#define PAGE_SIZE    (1UL << PAGE_SHIFT)
+#define PAGE_MASK    (~((1UL << PAGE_SHIFT)-1))
+#define PAGE_OFFSET    (0xC0000000)
 
-#ifndef        ASM
-#include<types.h>
-#define        get_npd(vaddr)  (((u32)(vaddr))>>22)
-#define        get_npt(vaddr)  ((((u32)(vaddr))>>12) & 0x3FF)
+#ifndef    ASM
+#include <types.h>
+#define get_npd(vaddr)    (((u32)(vaddr))>>22)
+#define get_npt(vaddr)    ((((u32)(vaddr))>>12) & 0x3FF)
 
-#include<list.h>
+#include <list.h>
 
 typedef unsigned long pde_t;
 typedef unsigned long pte_t;
 
-#define        PDECNT_PER_PAGE (PAGE_SIZE/sizeof(pde_t))
+#define PDECNT_PER_PAGE (PAGE_SIZE/sizeof(pde_t))
 #define PTECNT_PER_PAGE (PAGE_SIZE/sizeof(pte_t))
 
-#define        PAGE_ITEMS (PAGE_SIZE/sizeof(unsigned long))
-#define        PAGE_ALIGN(page)        (page & PAGE_MASK)
-#define        PAGE_UP(page)   (((unsigned long)page + PAGE_SIZE -1) & PAGE_MASK)
-#define        PAGE_DOWN       PAGE_ALIGN
+#define PAGE_ITEMS (PAGE_SIZE/sizeof(unsigned long))
+#define PAGE_ALIGN(page)    (page & PAGE_MASK)
+#define PAGE_UP(page)     (((unsigned long)page + PAGE_SIZE -1) & PAGE_MASK)
+#define PAGE_DOWN    PAGE_ALIGN
 
 #define va2pa(x) (((unsigned long)(x)) - PAGE_OFFSET)
 #define pa2va(x) ((void *) (((unsigned long)(x)) + PAGE_OFFSET))
 
 // pfn: page frame number
-#define        pa2pfn(addr)    ((addr)>>PAGE_SHIFT)
+#define pa2pfn(addr)    ((addr)>>PAGE_SHIFT)
 #define pfn2pa(pfn)     ((pfn)<<PAGE_SHIFT)
 
 #define va2pfn(addr)    pa2pfn(va2pa(addr))
@@ -63,35 +63,35 @@ typedef unsigned long pte_t;
 
 #define LOAD_CR3(pde) asm("movl %%edx, %%cr3"::"d"(va2pa(pde)))
 
-#define        MAX_ORDER       (11)
+#define MAX_ORDER    (11)
 
 typedef struct page
 {
-       //struct page *prev, *next;
-       ListHead list;
-       unsigned int order;
-       unsigned int mapNR;
-       unsigned int count;
+    //struct page *prev, *next;
+    ListHead list;
+    unsigned int order;
+    unsigned int mapNR;
+    unsigned int count;
 } Page, *pPage;
 
 typedef struct free_area
 {
-       //struct page *prev, *next;
-       ListHead freeList;
-       unsigned char *map;
-       unsigned int mapSize;
-       unsigned int count;
+    //struct page *prev, *next;
+    ListHead freeList;
+    unsigned char *map;
+    unsigned int mapSize;
+    unsigned int count;
 } FreeArea, *pFreeArea;
 
 
 extern FreeArea freeArea[MAX_ORDER];
 
-pPage  alloc_pages(unsigned int order);
-void   free_pages(pPage page);
-//void free_pages(pPage page, unsigned int order);
-void   disp_free_area();
+pPage    alloc_pages(unsigned int order);
+void    free_pages(pPage page);
+//void    free_pages(pPage page, unsigned int order);
+void    disp_free_area();
 
 
-#endif // ASM
+#endif    // ASM
 
 #endif //_PAGE_H
index 582cb38df71971302139f9612fafd77e582e5666..7a1c1219cacf20628c98c18f7fb0cb92ede8be97 100644 (file)
@@ -1,24 +1,24 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        pci.h
+ *   File Name: pci.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Mar  8 21:32:16 2009
  * Last Update: Sun Mar  8 21:32:16 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _PCI_H
-#define        _PCI_H
+#ifndef    _PCI_H
+#define _PCI_H
 
-#define        PCI_ADDR        0xCF8   // CONFIG_ADDRESS
-#define        PCI_DATA        0xCFC   // CONFIG_DATA
+#define PCI_ADDR    0xCF8   // CONFIG_ADDRESS
+#define PCI_DATA    0xCFC   // CONFIG_DATA
 
 // PCI Device
 /*
  */
 
 
-#define        PCI_VENDORID            0x00
-#define        PCI_DEVICEID            0x02
-#define        PCI_COMMAND             0x04
-#define        PCI_STATUS              0x06
-#define        PCI_REVISION            0x08
-#define        PCI_CLASSPROG           0x09
-#define        PCI_CLASSDEVICE         0x10
-#define        PCI_HDRTYPE             0x0E
-       #define PCI_HDRTYPE_MASK        0x7F
-       #define PCI_HDRTYPE_NORMAL      0x00
-       #define PCI_HDRTYPE_BRIDGE      0x01
-       #define PCI_HDRTYPE_CARDBUS     0x02
-#define        PCI_INTRLINE            0x3C
-#define        PCI_INTRPIN             0x3D
-#define        PCI_MINGNT              0x3E
-#define        PCI_MAXLAT              0x3F
-
-
-#define        PCI_CMD(bus, dev, devfn, reg) \
+#define PCI_VENDORID        0x00
+#define PCI_DEVICEID        0x02
+#define PCI_COMMAND        0x04
+#define PCI_STATUS        0x06
+#define PCI_REVISION        0x08
+#define PCI_CLASSPROG        0x09
+#define PCI_CLASSDEVICE        0x10
+#define PCI_HDRTYPE        0x0E
+    #define    PCI_HDRTYPE_MASK    0x7F
+    #define    PCI_HDRTYPE_NORMAL    0x00
+    #define    PCI_HDRTYPE_BRIDGE    0x01
+    #define    PCI_HDRTYPE_CARDBUS    0x02
+#define PCI_INTRLINE        0x3C
+#define PCI_INTRPIN        0x3D
+#define PCI_MINGNT        0x3E
+#define PCI_MAXLAT        0x3F
+
+
+#define PCI_CMD(bus, dev, devfn, reg) \
 (0x80000000 | (dev << 11) | (devfn << 8) | (reg & 0xFC))
 
-#define        PCI_CONFIG_CMD(cmd) (cmd & ~3)
-#define        PCI_GET_CMD_REG(cmd) (cmd & 0xFF)
+#define PCI_CONFIG_CMD(cmd) (cmd & ~3)
+#define PCI_GET_CMD_REG(cmd) (cmd & 0xFF)
 
 
 /*   PCI IDS   */
 // Display
-#define        PCI_BASE_CLASS_DISPLAY          0x03
-#define        PCI_CLASS_DISPLAY_VGA           0x0300
+#define PCI_BASE_CLASS_DISPLAY        0x03
+#define PCI_CLASS_DISPLAY_VGA        0x0300
 // Bridge
-#define        PCI_BASE_CLASS_BRIDGE           0x06
-#define        PCI_CLASS_BRIDGE_HOST           0x0600
-#define        PCI_CLASS_BRIDGE_ISA            0x0601
-#define        PCI_CLASS_BRIDGE_PCI            0x0604
-#define        PCI_CLASS_BRIDGE_CARDBUS        0x0607
+#define PCI_BASE_CLASS_BRIDGE        0x06
+#define PCI_CLASS_BRIDGE_HOST        0x0600
+#define PCI_CLASS_BRIDGE_ISA        0x0601
+#define PCI_CLASS_BRIDGE_PCI        0x0604
+#define PCI_CLASS_BRIDGE_CARDBUS    0x0607
 
 /* Vendors*/
-#define        PCI_VENDORID_COMPAQ     0x0E11
-#define        PCI_VENDORID_INTEL      0x8086
-#define        PCI_VENDORID_ATI        0x1002
-#define        PCI_VENDORID_IBM        0x1014
-#define        PCI_VENDORID_AMD        0x1022
-#define        PCI_VENDORID_HP         0x103C
-#define        PCI_VENDORID_SONY       0x104D
-#define        PCI_VENDORID_MOTOROLA   0x1057
-#define        PCI_VENDORID_APPLE      0x106B
-#define        PCI_VENDORID_SUN        0x108E
-#define        PCI_VENDORID_NVIDIA     0x10DE
-#define        PCI_VENDORID_REALTEK    0x10EC
+#define PCI_VENDORID_COMPAQ    0x0E11
+#define PCI_VENDORID_INTEL    0x8086
+#define PCI_VENDORID_ATI    0x1002
+#define PCI_VENDORID_IBM    0x1014
+#define PCI_VENDORID_AMD    0x1022
+#define PCI_VENDORID_HP        0x103C
+#define PCI_VENDORID_SONY    0x104D
+#define PCI_VENDORID_MOTOROLA    0x1057
+#define PCI_VENDORID_APPLE    0x106B
+#define PCI_VENDORID_SUN    0x108E
+#define PCI_VENDORID_NVIDIA    0x10DE
+#define PCI_VENDORID_REALTEK    0x10EC
 
 
 // PCI Bridge
index 461cc66a0faab96829fa468e6c3b5d1615c23c75..68ffed9f96c76251de4c9f8c29a336ddad5d4148 100644 (file)
@@ -1,22 +1,22 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        printk.h
+ *   File Name: printk.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Mar  4 21:49:19 2009
  * Last Update: Wed Mar  4 21:49:19 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _PRINTK_H
-#define        _PRINTK_H
+#ifndef    _PRINTK_H
+#define _PRINTK_H
 
-int    printk(char *fmtstr, ...);
+int    printk(char *fmtstr, ...);
 
 #endif //_PRINTK_H
index 389f611fbe4ba492a7ce75cbbb9681f904f2dcf8..3626e406ebca8914a6df94de7181d10061cee029 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        processor.h
+ *   File Name: processor.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Aug 03 21:37:34 2008
  * Last Update: Sun Aug 03 21:37:34 2008
  * 
 
 
 
-#ifndef        _DESCRIPTOR_H
+#ifndef    _DESCRIPTOR_H
 #define _DESCRIPTOR_H 
 
-#include"types.h"
-#include"system.h"
-#include"string.h"
+#include "types.h"
+#include "system.h"
+#include "string.h"
 
 //Descriptor Attrib.
-#define        DA_E    0x8     //Executable
-#define        DA_ED   0x4     //For Data SEG
-#define        DA_C    0x4     //For Code SEG
-#define        DA_W    0x2     //For Data SEG
-#define        DA_A    0x1     //Access. 1-Accessed.
+#define DA_E    0x8    //Executable
+#define DA_ED    0x4    //For Data SEG
+#define DA_C    0x4    //For Code SEG
+#define DA_W    0x2    //For Data SEG
+#define DA_A    0x1    //Access. 1-Accessed.
 //we just need Accessed.
 //For Data Segment.
-#define        DSA_R   (DA_A)
-#define DSA_RW (DA_A | DA_W)
-#define        DSA_RD  (DA_A | DA_ED)          //down to ...
-#define        DSA_RWD (DA_A | DA_W | DA_ED)
+#define DSA_R    (DA_A)
+#define DSA_RW    (DA_A | DA_W)
+#define DSA_RD    (DA_A | DA_ED)        //down to ...
+#define DSA_RWD    (DA_A | DA_W | DA_ED)
 //For Code Segment.
-#define        CSA_E   (DA_E | DA_A)
-#define        CSA_ER  (DA_E | DA_A | DA_R)
-#define        CSA_EC  (DA_E | DA_A | DA_C)
-#define        CSA_ERC (DA_E | DA_A | DA_R | DA_C)
+#define CSA_E    (DA_E | DA_A)
+#define CSA_ER    (DA_E | DA_A | DA_R)
+#define CSA_EC    (DA_E | DA_A | DA_C)
+#define CSA_ERC    (DA_E | DA_A | DA_R | DA_C)
 
 
 //-------------------------------------------------------------------------
 // Code And Data Descriptor.
 // Program Segment Descriptor.
 //-------------------------------------------------------------------------
-typedef        struct
+typedef    struct
 {
-       unsigned short limitL;
-
-       unsigned short baseL;
-
-       unsigned char baseM;
-       unsigned char type:4;
-       unsigned char S:1;      //allways set to 0. NOT SYS SEG DESC
-       unsigned char DPL:2;
-       unsigned char P:1;      //allways set to 1.
-
-       unsigned char limitH:4;
-       unsigned char AVL:1;
-       unsigned char zero:1;   //should be set to 0
-       unsigned char DB:1;     //0--16bits,1--32bits
-       unsigned char G:1;      //set to 1. We just need 4K size.
-       unsigned char baseH;
+    unsigned short limitL;
+
+    unsigned short baseL;
+
+    unsigned char baseM;
+    unsigned char type:4;
+    unsigned char S:1;    //allways set to 0. NOT SYS SEG DESC
+    unsigned char DPL:2;
+    unsigned char P:1;    //allways set to 1.
+
+    unsigned char limitH:4;
+    unsigned char AVL:1;
+    unsigned char zero:1;    //should be set to 0
+    unsigned char DB:1;    //0--16bits,1--32bits
+    unsigned char G:1;    //set to 1. We just need 4K size.
+    unsigned char baseH;
 } Seg,*pSeg;
 
 
@@ -73,67 +73,67 @@ typedef     struct
 //-------------------------------------------------------------------------
 typedef struct
 {
-       unsigned short  eaddrL;
+    unsigned short    eaddrL;
 
-       unsigned short  selector;
+    unsigned short    selector;
 
-       unsigned char   parmeter:5;     //for call gate
-                                       //reserved by other gates.
-       unsigned char   zero:3;
-       unsigned char   type:4;
-       unsigned char   S:1;
-       unsigned char   DPL:2;
-       unsigned char   P:1;
+    unsigned char    parmeter:5;    //for call gate
+                    //reserved by other gates.
+    unsigned char    zero:3;
+    unsigned char    type:4;
+    unsigned char    S:1;
+    unsigned char    DPL:2;
+    unsigned char    P:1;
 
-       unsigned short eaddrH;
+    unsigned short eaddrH;
 
 } Gate, *pGate;
 
 //just used for type...
 typedef union
 {
-       Seg     seg;
-       Gate    gate;
+    Seg    seg;
+    Gate    gate;
 } Desc, *pDesc;
 
 
-#define        NGDT    256
-#define        NIDT    256
-#define        NLDT    5
-extern Desc    idt[NIDT];
-extern Desc    gdt[NGDT];
+#define NGDT    256
+#define NIDT    256
+#define NLDT    5
+extern Desc    idt[NIDT];
+extern Desc    gdt[NGDT];
 
 //-------------------------------------------------------------------------
 //Define Gate Types...
 //-------------------------------------------------------------------------
-#define        INTR_GATE       0x0E    //Clear 'IF' bit.---->Close Interrupt
-#define        TRAP_GATE       0x0F    //Keep  'IF' bit.
-#define        TSS_DESC        0x09
+#define INTR_GATE    0x0E    //Clear 'IF' bit.---->Close Interrupt
+#define TRAP_GATE    0x0F    //Keep  'IF' bit.
+#define TSS_DESC    0x09
 
 static inline void _init_desc(pDesc desc)
 {
-       if(0xc010a1c8 == (unsigned long)desc)
-               asm("xchg %bx,%bx");
-       memset((char *)desc, 0, sizeof(Desc));
+    if(0xc010a1c8 == (unsigned long)desc)
+        asm("xchg %bx,%bx");
+    memset((char *)desc, 0, sizeof(Desc));
 }
 
 
 static inline Desc _create_seg(u8 type, u8 DPL)
 {
-       Desc    d;
-       pSeg    p=&d.seg;
-
-       _init_desc(&d);
-       p->limitL       = 0xFFFF;
-       p->limitH       = 0x0F; 
-       p->type         = type;
-       p->S            = 0x1;
-       p->DPL          = DPL;
-       p->P            = 0x1;
-       p->G            = 0x1;
-       p->DB           = 0x1;
-
-       return d;
+    Desc    d;
+    pSeg    p=&d.seg;
+
+    _init_desc(&d);
+    p->limitL    = 0xFFFF;
+    p->limitH    = 0x0F; 
+    p->type        = type;
+    p->S        = 0x1;
+    p->DPL        = DPL;
+    p->P        = 0x1;
+    p->G        = 0x1;
+    p->DB        = 0x1;
+
+    return d;
 }
 
 
@@ -142,75 +142,75 @@ static inline Desc _create_seg(u8 type, u8 DPL)
 
 static inline Desc _create_gate(u32 handler, u8 type, u8 DPL)
 {
-       Desc    d;
-       pGate   p = &d.gate;
+    Desc    d;
+    pGate    p = &d.gate;
 
-       _init_desc(&d);
+    _init_desc(&d);
 
-       p->eaddrL       = 0xFFFF & handler;
-       p->eaddrH       = 0xFFFF & (handler >> 16);
-       p->selector     = SELECTOR_KRNL_CS;
-       p->type         = type;
-       p->P            = 0x1;
-       p->DPL          = DPL;
+    p->eaddrL    = 0xFFFF & handler;
+    p->eaddrH    = 0xFFFF & (handler >> 16);
+    p->selector    = SELECTOR_KRNL_CS;
+    p->type        = type;
+    p->P        = 0x1;
+    p->DPL        = DPL;
 
-       return d;
+    return d;
 }
 static inline void set_idt_gate(u32 vec, u32 handler,u8 type, u8 DPL)
 {
-       idt[vec] = _create_gate(handler, type, DPL);
+    idt[vec] = _create_gate(handler, type, DPL);
 }
 
-typedef        struct
+typedef    struct
 {
-       u16     backlink, _backlink;
-       u32     esp0;
-       u16     ss0, _ss0;
-       u32     esp1;
-       u16     ss1, _ss1;
-       u32     esp2;
-       u16     ss2, _ss2;
-       u32     cr3;
-       u32     eip;
-       u32     eflags;
-       u32     eax;
-       u32     ecx;
-       u32     edx;
-       u32     ebx;
-       u32     esp;
-       u32     ebp;
-       u32     esi;
-       u32     edi;
-       u16     es, _es;
-       u16     cs, _cs;
-       u16     ss, _ss;
-       u16     ds, _ds;
-       u16     fs, _fs;
-       u16     gs, _gs;
-       u16     ldt, _ldt;
-       u16     T:1, _T:15, iomap_base;
+    u16    backlink, _backlink;
+    u32    esp0;
+    u16    ss0, _ss0;
+    u32    esp1;
+    u16    ss1, _ss1;
+    u32    esp2;
+    u16    ss2, _ss2;
+    u32    cr3;
+    u32    eip;
+    u32    eflags;
+    u32    eax;
+    u32    ecx;
+    u32    edx;
+    u32    ebx;
+    u32    esp;
+    u32    ebp;
+    u32    esi;
+    u32    edi;
+    u16    es, _es;
+    u16    cs, _cs;
+    u16    ss, _ss;
+    u16    ds, _ds;
+    u16    fs, _fs;
+    u16    gs, _gs;
+    u16    ldt, _ldt;
+    u16    T:1, _T:15, iomap_base;
 } TSS, *pTSS;
 static inline void set_tss_gate(u32 vec, u32 addr)
 {
 #if 1
-       pSeg    p = (pSeg) (gdt+vec);
-       _init_desc((pDesc)p);
-       p->limitL = 0xFFFF & sizeof(TSS);
-       p->limitH = 0x0F   & (sizeof(TSS) >> 16);
-       p->baseL = 0xFFFF & addr;
-       p->baseM = 0xFF   & (addr>>16);
-       p->baseH = 0xFF   & (addr>>24);
-
-       p->P = 1;
-       p->DPL = PRIVILEGE_USER;
-       p->S = 0;
-
-       p->type = TSS_DESC;
+    pSeg    p = (pSeg) (gdt+vec);
+    _init_desc((pDesc)p);
+    p->limitL = 0xFFFF & sizeof(TSS);
+    p->limitH = 0x0F   & (sizeof(TSS) >> 16);
+    p->baseL = 0xFFFF & addr;
+    p->baseM = 0xFF   & (addr>>16);
+    p->baseH = 0xFF   & (addr>>24);
+
+    p->P = 1;
+    p->DPL = PRIVILEGE_USER;
+    p->S = 0;
+
+    p->type = TSS_DESC;
 #endif
 }
 
 
-extern TSS     tss;
+extern    TSS    tss;
 
 
 #endif//_DESCRIPTOR_H
index 89917b3d0a3cb8c9f679071af948e6787a367c45..eb5ac77101b895fbf2eead544ccaeabf8730f436 100644 (file)
@@ -1,34 +1,34 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        sched.h
+ *   File Name: sched.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sat Feb  7 21:43:49 2009
  * Last Update: Sat Feb  7 21:43:49 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _SCHED_H
-#define        _SCHED_H
+#ifndef    _SCHED_H
+#define _SCHED_H
 
-#include<task.h>
-#define        NR_TASKS        3
-//pTask        tTasks[NR_TASKS];
-//void add_task();
-void   SetupTasks();
-//void test_taskA();
-//void test_taskB();
-//unsigned long schedule(pPtRegs       regs);
+#include <task.h>
+#define NR_TASKS    3
+//pTask    tTasks[NR_TASKS];
+//void    add_task();
+void    SetupTasks();
+//void    test_taskA();
+//void    test_taskB();
+//unsigned long schedule(pPtRegs    regs);
 unsigned long schedule();
 
-pid_t  get_next_pid();
-void   init_tsk_cr3(pTask);
+pid_t    get_next_pid();
+void    init_tsk_cr3(pTask);
 
 
 inline void wake_up(pWaitQueue wq);
index 7cb614734939f4fdb54a94900c052c0e22ace1b3..53a38238010105fa542ff6614ab69c7493571ce8 100644 (file)
@@ -1,42 +1,42 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        stat.h
+ *   File Name: stat.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Fri Feb 12 18:01:27 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Fri Feb 12 18:01:27 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _STAT_H
-#define        _STAT_H
+#ifndef    _STAT_H
+#define _STAT_H
 
 typedef struct stat {
-       unsigned long  st_dev;
-       unsigned long  st_ino;
-       unsigned short st_mode;
-       unsigned short st_nlink;
-       unsigned short st_uid;
-       unsigned short st_gid;
-       unsigned long  st_rdev;
-       unsigned long  st_size;
-       unsigned long  st_blksize;
-       unsigned long  st_blocks;
-       unsigned long  st_atime;
-       unsigned long  st_atime_nsec;
-       unsigned long  st_mtime;
-       unsigned long  st_mtime_nsec;
-       unsigned long  st_ctime;
-       unsigned long  st_ctime_nsec;
-       unsigned long  __unused4;
-       unsigned long  __unused5;
+    unsigned long  st_dev;
+    unsigned long  st_ino;
+    unsigned short st_mode;
+    unsigned short st_nlink;
+    unsigned short st_uid;
+    unsigned short st_gid;
+    unsigned long  st_rdev;
+    unsigned long  st_size;
+    unsigned long  st_blksize;
+    unsigned long  st_blocks;
+    unsigned long  st_atime;
+    unsigned long  st_atime_nsec;
+    unsigned long  st_mtime;
+    unsigned long  st_mtime_nsec;
+    unsigned long  st_ctime;
+    unsigned long  st_ctime_nsec;
+    unsigned long  __unused4;
+    unsigned long  __unused5;
 } Stat, *pStat;
 
 #define S_IFMT  00170000
 #define S_IFSOCK 0140000
-#define S_IFLNK         0120000
+#define S_IFLNK     0120000
 #define S_IFREG  0100000
 #define S_IFBLK  0060000
 #define S_IFDIR  0040000
@@ -46,13 +46,13 @@ typedef struct stat {
 #define S_ISGID  0002000
 #define S_ISVTX  0001000
 
-#define S_ISLNK(m)     (((m) & S_IFMT) == S_IFLNK)
-#define S_ISREG(m)     (((m) & S_IFMT) == S_IFREG)
-#define S_ISDIR(m)     (((m) & S_IFMT) == S_IFDIR)
-#define S_ISCHR(m)     (((m) & S_IFMT) == S_IFCHR)
-#define S_ISBLK(m)     (((m) & S_IFMT) == S_IFBLK)
-#define S_ISFIFO(m)    (((m) & S_IFMT) == S_IFIFO)
-#define S_ISSOCK(m)    (((m) & S_IFMT) == S_IFSOCK)
+#define S_ISLNK(m)    (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m)    (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m)    (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m)    (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m)    (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m)    (((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m)    (((m) & S_IFMT) == S_IFSOCK)
 
 
 #endif //_STAT_H
index 05a2f15402aedcf09f43774e6984fa3ec3583b86..5f803c6c0d57c73aa293753507f37300e6c09f7c 100644 (file)
@@ -1,33 +1,33 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        stdio.h
+ *   File Name: stdio.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Mon Mar  9 01:59:06 2009
  * Last Update: Mon Mar  9 01:59:06 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _STDIO_H
-#define        _STDIO_H
-#include<string.h>
-#include<syscall.h>
+#ifndef    _STDIO_H
+#define _STDIO_H
+#include <string.h>
+#include <syscall.h>
 extern int write(int fd, const char *buf, unsigned long size);
 char ptfbuf[1024];
 static inline int printf(const char *fmt, ...)
 {
-       char *args = (char*)(((char*)&fmt)+4);
-       vsprintf(ptfbuf, fmt, args);
+    char *args = (char*)(((char*)&fmt)+4);
+    vsprintf(ptfbuf, fmt, args);
 
-       //asm("xchg %bx,%bx;");
-       
-       return write(0, ptfbuf, strlen(ptfbuf));
+    //asm("xchg %bx,%bx;");
+    
+    return write(0, ptfbuf, strlen(ptfbuf));
 }
 
 #endif //_STDIO_H
index 04afdd5fcca12710af58844049ab1131d68a7208..b405cf7d0ca79cf1ba7a8c02366686af2795be81 100644 (file)
@@ -1,18 +1,18 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        stdlib.h
+ *   File Name: stdlib.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Feb 17 19:01:02 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Feb 17 19:01:02 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _STDLIB_H
-#define        _STDLIB_H
+#ifndef    _STDLIB_H
+#define _STDLIB_H
 
-extern int atoi(const char *s);
+extern    int atoi(const char *s);
 
 #endif //_STDLIB_H
index 420db804674f46a72c978ef320b1641839f20c03..33c80c47c3efa4d3358d98ec1679157b5b3191d8 100644 (file)
@@ -1,31 +1,31 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        string.h
+ *   File Name: string.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Jul 30 16:03:27 2008
  * Last Update: Wed Jul 30 16:03:27 2008
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _STRING_H
-#define        _STRING_H
+#ifndef    _STRING_H
+#define _STRING_H
 
-#include"types.h"
-char   *strcpy(char *dest, const char *src);
-size_t strlen(const char *str);
-int    strcmp(const char *a, const char *b);
-int    strncmp(const char *a, const char *b, size_t count);
-char   *strcat(char *dest, const char *src);
+#include "types.h"
+char    *strcpy(char *dest, const char *src);
+size_t    strlen(const char *str);
+int    strcmp(const char *a, const char *b);
+int    strncmp(const char *a, const char *b, size_t count);
+char    *strcat(char *dest, const char *src);
 
 
-void   *memcpy(void *dest, const void *src, size_t size);
-void   memset(char *dest, char ch, size_t size);
+void    *memcpy(void *dest, const void *src, size_t size);
+void    memset(char *dest, char ch, size_t size);
 
 #endif //_STRING_H
index df5ffab417d0a8136924b6e69e0e17d0cf4ffa4f..857e78ac5d134745ce83dc08f9e6abceefe9a1a0 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        syscall.h
+ *   File Name: syscall.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Jan  2 19:52:28 2009
  * Last Update: Tue Feb 23 02:32:35 2010
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _SYSCALL_H
-#define        _SYSCALL_H
+#ifndef    _SYSCALL_H
+#define _SYSCALL_H
 
-#define        SYSC_NUM        256
+#define SYSC_NUM    256
 
-#ifndef        ASM
+#ifndef    ASM
 
 #include "page.h"
 #include "errno.h"
-typedef        int     SyscReturn;
+typedef    int    SyscReturn;
 typedef SyscReturn  (*pfSysc)();
 
 
-#define        SYSENTER                \
-       asm(                    \
-       "pushl  %ecx;"          \
-       "pushl  %edx;"          \
-       "pushl  %ebp;"          \
-       "pushl  $1f;"           \
-       "movl   %esp,%ebp;"     \
-       "sysenter;"             \
-       "1:"                    \
-       "addl   $4,%esp;"       \
-       "popl   %ebp;"          \
-       "popl   %edx;"          \
-       "popl   %ecx;");        \
+#define SYSENTER        \
+    asm(            \
+    "pushl    %ecx;"        \
+    "pushl    %edx;"        \
+    "pushl    %ebp;"        \
+    "pushl    $1f;"        \
+    "movl    %esp,%ebp;"    \
+    "sysenter;"        \
+    "1:"            \
+    "addl    $4,%esp;"    \
+    "popl    %ebp;"        \
+    "popl    %edx;"        \
+    "popl    %ecx;");    \
 
 
 
-#define        sysenter(vect)({        \
-       asm(""::"a"(vect));     \
-       SYSENTER                \
+#define sysenter(vect)({     \
+    asm(""::"a"(vect));    \
+    SYSENTER        \
 })
 #if 0
-#define        syscall0(vect)(({       \
-       sysenter(vect);         \
+#define syscall0(vect)(({    \
+    sysenter(vect);        \
 }), ({int i;asm("":"=a"(i));i;}))
 #endif
-#define        _syscall0(vect)({       \
-       sysenter(vect);         \
+#define _syscall0(vect)({    \
+    sysenter(vect);        \
 })
 
-#define        _syscall1(vect, a)({    \
-       asm(""::"b"(a));        \
-       sysenter(vect);         \
+#define _syscall1(vect, a)({    \
+    asm(""::"b"(a));    \
+    sysenter(vect);        \
 })
 
-#define        _syscall2(vect, a, b)({ \
-       asm(""::"b"(a), "d"(b));\
-       sysenter(vect);         \
+#define _syscall2(vect, a, b)({    \
+    asm(""::"b"(a), "d"(b));\
+    sysenter(vect);        \
 })
 
-#define        _syscall3(vect, a, b, c)({      \
-       asm(""::"b"(a), "d"(b), "c"(c));\
-       sysenter(vect);                 \
+#define _syscall3(vect, a, b, c)({    \
+    asm(""::"b"(a), "d"(b), "c"(c));\
+    sysenter(vect);            \
 })
 
-#define        _syscall_ret()({        \
-       int ret;                \
-       asm("":"=a"(ret));      \
-       if(ret < 0)             \
-       {                       \
-               errno = -ret;   \
-               ret = -1;       \
-       }                       \
-       ret;})
-
-#define        syscall0(vect)          \
-       (({_syscall0(vect);}),          ({_syscall_ret();}))
-#define        syscall1(vect, a)       \
-       (({_syscall1(vect, a);}),       ({_syscall_ret();}))
-#define        syscall2(vect, a, b)    \
-       (({_syscall2(vect, a, b);}),    ({_syscall_ret();}))
-#define        syscall3(vect, a, b, c) \
-       (({_syscall3(vect, a, b, c);}), ({_syscall_ret();}))
+#define _syscall_ret()({    \
+    int ret;        \
+    asm("":"=a"(ret));    \
+    if(ret < 0)        \
+    {            \
+        errno = -ret;    \
+        ret = -1;    \
+    }            \
+    ret;})
+
+#define syscall0(vect)        \
+    (({_syscall0(vect);}),        ({_syscall_ret();}))
+#define syscall1(vect, a)    \
+    (({_syscall1(vect, a);}),    ({_syscall_ret();}))
+#define syscall2(vect, a, b)    \
+    (({_syscall2(vect, a, b);}),    ({_syscall_ret();}))
+#define syscall3(vect, a, b, c)    \
+    (({_syscall3(vect, a, b, c);}),    ({_syscall_ret();}))
 #if 1
 enum
 {
-       SYSC_WRITE,
-       SYSC_READ_KBD,
-       SYSC_REBOOT,
-       SYSC_FORK,
-       SYSC_EXEC,
-       SYSC_OPEN,
-       SYSC_READ,
-       SYSC_STAT,
-       SYSC_EXIT,
+    SYSC_WRITE,
+    SYSC_READ_KBD,
+    SYSC_REBOOT,
+    SYSC_FORK,
+    SYSC_EXEC,
+    SYSC_OPEN,
+    SYSC_READ,
+    SYSC_STAT,
+    SYSC_EXIT,
     SYSC_PAUSE,
-       SYSC_TEST
+    SYSC_TEST
 };
 #endif
 
-#endif // ASM
+#endif    // ASM
 
 #endif //_SYSCALL_H
index abd135583ccea96f44e1da011a06cef61c052fd5..dd1301abe5798034c676a041bfe4fa90133cceca 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:    system.h
+ *   File Name: system.h
  * 
- * Description:    none
+ * Description: none
  * 
  * 
- *      Author:    Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
  *     Version:    1.0
  * Create Date: Sat Feb  7 18:57:58 2009
  */
 
 #ifndef    _SYSTEM_H
-#define    _SYSTEM_H
+#define _SYSTEM_H
 
-#include<page.h>
-#include<assert.h>
-#define    KRNLADDR    PAGE_OFFSET
+#include <page.h>
+#include <assert.h>
+#define KRNLADDR    PAGE_OFFSET
 
 #ifndef    ASM
 #include "types.h"
@@ -59,22 +59,22 @@ extern char etext, edata, end;
 
 char gdtr[6],idtr[6];
 #define lgdt()    __asm__    __volatile__("lgdt gdtr")
-#define    sgdt()    __asm__    __volatile__("sgdt gdtr")
-#define    lidt()    __asm__    __volatile__("lidt idtr")
-#define    sidt()    __asm__    __volatile__("sidt idtr")
+#define sgdt()    __asm__    __volatile__("sgdt gdtr")
+#define lidt()    __asm__    __volatile__("lidt idtr")
+#define sidt()    __asm__    __volatile__("sidt idtr")
 
-#define    cli()    __asm__    __volatile__("cli")
-#define    sti()    __asm__    __volatile__("sti")
-#define    disableIRQ()    cli()
-#define    enableIRQ()    sti()
+#define cli()    __asm__    __volatile__("cli")
+#define sti()    __asm__    __volatile__("sti")
+#define disableIRQ()    cli()
+#define enableIRQ()    sti()
 
-#define    ALIGN(x, a)    (((x)+(a)-1) & ~((a)-1))
+#define ALIGN(x, a)    (((x)+(a)-1) & ~((a)-1))
 
 
 // 1 GB
-#define    MAX_SUPT_PHYMM_SIZE    (1UL<<30)
+#define MAX_SUPT_PHYMM_SIZE    (1UL<<30)
 
-#define    INT_STACK_SIZE    PAGE_SIZE
+#define INT_STACK_SIZE    PAGE_SIZE
 
 
 enum GDTSelectorIndex
@@ -152,7 +152,7 @@ typedef struct system
     u32    boot_device;
 
     Dev    root_dev;
-#define    CMD_LINE_SIZE    128
+#define CMD_LINE_SIZE    128
     char    *cmdline;
 
     u32    debug;
@@ -160,12 +160,12 @@ typedef struct system
 
 extern    System system;
 
-#define    pgmap system.page_map
+#define pgmap system.page_map
 
 #endif
 
 
-#define    SAVE_REGS   \
+#define SAVE_REGS   \
     cld;            \
     pushl    %gs;    \
     pushl    %fs;    \
@@ -179,7 +179,7 @@ extern    System system;
     pushl    %edx;    \
     pushl    %ebx;
 
-#define    RESTORE_REGS    \
+#define RESTORE_REGS    \
     popl    %ebx;    \
     popl    %edx;    \
     popl    %ecx;    \
@@ -193,45 +193,45 @@ extern    System system;
     popl    %gs;
 
 
-#define    PRIVILEGE_KRNL    0x0
-#define    PRIVILEGE_USER    0x3
+#define PRIVILEGE_KRNL    0x0
+#define PRIVILEGE_USER    0x3
 
-#define    INDEX_UCODE    3
-#define    INDEX_UDATA    4
+#define INDEX_UCODE    3
+#define INDEX_UDATA    4
 /* *8 == <<3 .但要用于汇编文件 <<3 不行. */
-#define    SELECTOR_KRNL_CS    (INDEX_KCODE*8)
-#define    SELECTOR_KRNL_DS    (INDEX_KDATA*8)
-#define    SELECTOR_KRNL_SS    SELECTOR_KRNL_DS
-#define    SELECTOR_USER_CS    ((INDEX_UCODE*8)|PRIVILEGE_USER)
-#define    SELECTOR_USER_DS    ((INDEX_UDATA*8)|PRIVILEGE_USER)
-#define    SELECTOR_USER_SS    SELECTOR_USER_DS
+#define SELECTOR_KRNL_CS    (INDEX_KCODE*8)
+#define SELECTOR_KRNL_DS    (INDEX_KDATA*8)
+#define SELECTOR_KRNL_SS    SELECTOR_KRNL_DS
+#define SELECTOR_USER_CS    ((INDEX_UCODE*8)|PRIVILEGE_USER)
+#define SELECTOR_USER_DS    ((INDEX_UDATA*8)|PRIVILEGE_USER)
+#define SELECTOR_USER_SS    SELECTOR_USER_DS
 
 
 #if 0
-#define    INT_VECT_DIVIDE          0x0
-#define    INT_VECT_DEBUG           0x1
-#define    INT_VECT_NMI             0x2
-#define    INT_VECT_BREAKPOINT      0x3    /* Break Point */
-#define    INT_VECT_OVERFLOW        0x4
-#define    INT_VECT_BOUNDS          0x5
-#define    INT_VECT_INVALOP         0x6
-#define    INT_VECT_COPROCNOT       0x7
-#define    INT_VECT_DOUBLEFAULT     0x8    /* Double Fault */
-#define    INT_VECT_COPROCSEG       0x9
-#define    INT_VECT_INVALTSS        0xA
-#define    INT_VECT_SEGNOT          0xB
-#define    INT_VECT_STACKFAULT      0xC    /* Stack Fault */
-#define    INT_VECT_PROTECTION      0xD
-#define    INT_VECT_PAGEFAULT       0xE
-#define    INT_VECT_COPROCERR       0x10
+#define INT_VECT_DIVIDE          0x0
+#define INT_VECT_DEBUG           0x1
+#define INT_VECT_NMI             0x2
+#define INT_VECT_BREAKPOINT      0x3    /* Break Point */
+#define INT_VECT_OVERFLOW        0x4
+#define INT_VECT_BOUNDS          0x5
+#define INT_VECT_INVALOP         0x6
+#define INT_VECT_COPROCNOT       0x7
+#define INT_VECT_DOUBLEFAULT     0x8    /* Double Fault */
+#define INT_VECT_COPROCSEG       0x9
+#define INT_VECT_INVALTSS        0xA
+#define INT_VECT_SEGNOT          0xB
+#define INT_VECT_STACKFAULT      0xC    /* Stack Fault */
+#define INT_VECT_PROTECTION      0xD
+#define INT_VECT_PAGEFAULT       0xE
+#define INT_VECT_COPROCERR       0x10
 #endif
-#define    INT_VECT_IRQ0    0x20
-#define    INT_VECT_IRQ8    0x28
+#define INT_VECT_IRQ0    0x20
+#define INT_VECT_IRQ8    0x28
 
-#define    REBOOT_RESTART   0x00
-#define    REBOOT_POWEROFF  0x01
+#define REBOOT_RESTART   0x00
+#define REBOOT_POWEROFF  0x01
 
 
-#define    ROOT_DEV    system.root_dev
+#define ROOT_DEV    system.root_dev
 
 #endif //_SYSTEM_H
index 3df9102e15fc75a94a98e00805513aaa52e254c6..7724ab197d0dcfa85af9c111b44fbeda3543e383 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        task.h
+ *   File Name: task.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Thu Dec 31 16:54:48 2009
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Thu Dec 31 16:54:48 2009
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _TASK_H
-#define        _TASK_H
+#ifndef    _TASK_H
+#define _TASK_H
 
 #include <page.h>
 #include <list.h>
 #include <system.h>
 #include <wait.h>
 #include <fs.h>
-#define        TASK_PAGES      (2)
-#define        TASK_SIZE       (TASK_PAGES<<PAGE_SHIFT)
+#define TASK_PAGES    (2)
+#define TASK_SIZE    (TASK_PAGES<<PAGE_SHIFT)
 
 enum
 {
     TASK_UNUSED,
-       TASK_RUNNING,
-       TASK_UNINTERRUPTIBLE,
-       TASK_INTERRUPTIBLE,
-       TASK_EXITING
+    TASK_RUNNING,
+    TASK_UNINTERRUPTIBLE,
+    TASK_INTERRUPTIBLE,
+    TASK_EXITING
 };
 
-typedef        union
+typedef    union
 {
-       struct
-       {
-               PtRegs          regs;
+    struct
+    {
+        PtRegs        regs;
 
-               unsigned long   esp0;   /* 指示发生在用户态的中断在进入
-                                          内核态后的栈位置 */
+        unsigned long    esp0;    /* 指示发生在用户态的中断在进入
+                       内核态后的栈位置 */
 
-               /* 进程切换时用 */
-               unsigned long   esp;
-               unsigned long   eip;
+        /* 进程切换时用 */
+        unsigned long    esp;
+        unsigned long    eip;
 
-               pid_t           pid;
-               pid_t           ppid;
-               unsigned int state;
-               long            exit_code;
-               void            *cr3;
+        pid_t        pid;
+        pid_t        ppid;
+        unsigned int state;
+        long        exit_code;
+        void        *cr3;
 
-               long            tty;
+        long        tty;
 
-               ListHead        list;
+        ListHead     list;
 
-               WaitQueue       wait;
+        WaitQueue    wait;
 
-               pFile           fps[NR_OPENS];
+        pFile        fps[NR_OPENS];
 
-       };
+    };
 
-       unsigned char stack[TASK_SIZE];
+    unsigned char stack[TASK_SIZE];
 } Task, *pTask;
 
 typedef Task task_struct;
 
-#define        ROOT_TSK_PID    (1)
+#define ROOT_TSK_PID    (1)
 
-extern pTask           current;
-extern Task            RootTsk;
-extern ListHead        tsk_list;
+extern    pTask        current;
+extern    Task        RootTsk;
+extern    ListHead    tsk_list;
 
-#define        add_tsk2list(tsk)       list_add_tail((&(tsk)->list), &tsk_list)
-#define        get_tsk_from_list(p)    list_entry((p), Task, list)
-#define        del_tsk_from_list(tsk)  list_del((&tsk->list))
+#define add_tsk2list(tsk)    list_add_tail((&(tsk)->list), &tsk_list)
+#define get_tsk_from_list(p)    list_entry((p), Task, list)
+#define del_tsk_from_list(tsk)    list_del((&tsk->list))
 
 #endif //_TASK_H
index f1251894117297109f9496b36f97f19bea9e2a1f..5aff1f349dd19c964edcf33c226c672681ae0cdf 100644 (file)
@@ -1,45 +1,45 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        types.h
+ *   File Name: types.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Aug 13 23:06:22 2008
  * Last Update: Wed Aug 13 23:06:22 2008
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _TYPES_H
-#define        _TYPES_H
+#ifndef    _TYPES_H
+#define _TYPES_H
 
-typedef                unsigned int            size_t;
-typedef                int                     ssize_t;
+typedef        unsigned int         size_t;
+typedef        int             ssize_t;
 
-typedef                signed char             s8;
-typedef                signed short            s16;
-typedef                signed long             s32;
-typedef                signed long long        s64;
+typedef        signed char        s8;
+typedef        signed short        s16;
+typedef        signed long        s32;
+typedef        signed long long    s64;
 
-typedef                unsigned char           u8;
-typedef        unsigned short          u16;
-typedef                unsigned long           u32;
-typedef                unsigned long long      u64;
+typedef        unsigned char        u8;
+typedef     unsigned short        u16;
+typedef        unsigned long        u32;
+typedef        unsigned long long    u64;
 
-typedef                unsigned long           pid_t;
-typedef                unsigned long           mode_t;
+typedef        unsigned long        pid_t;
+typedef        unsigned long        mode_t;
 
 
-#define        NULL ((void*)0)
+#define NULL ((void*)0)
 
 
 //=========================================================================
 //Define kinds of function's type ...
 //=========================================================================
-typedef        void    (*pf_intr)();
+typedef    void    (*pf_intr)();
 
 #endif //_TYPES_H
index cf7ee375c5da23a7567a4242ba2d0a4970a9fa91..692326c243761485e6945724bf48a50a9efe00d3 100644 (file)
@@ -1,21 +1,21 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        unistd.h
+ *   File Name: unistd.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Feb  7 13:24:11 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Feb  7 13:24:11 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _UNISTD_H
-#define        _UNISTD_H
+#ifndef    _UNISTD_H
+#define _UNISTD_H
 
-#include<types.h>
+#include <types.h>
 
-extern pid_t   fork();
-extern int     exit(int status);
+extern    pid_t    fork();
+extern    int    exit(int status);
 
 #endif //_UNISTD_H
index b3f40feaa6772d0ec29ecdfe3caf715d0fa899c1..a23111c5d649ec9e35e2ad24797d5a9bb0d5f6af 100644 (file)
@@ -1,26 +1,26 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        wait.h
+ *   File Name: wait.h
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Mon Feb 22 20:50:56 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Mon Feb 22 20:50:56 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#ifndef        _WAIT_H
-#define        _WAIT_H
+#ifndef    _WAIT_H
+#define _WAIT_H
 
-#include<list.h>
+#include <list.h>
 
-typedef        struct
+typedef    struct
 {
-       ListHead wait;
+    ListHead wait;
 } WaitQueueHead, *pWaitQueueHead;
 
-typedef        ListHead WaitQueue, *pWaitQueue;
+typedef    ListHead WaitQueue, *pWaitQueue;
 
 void init_wait_queue(pWaitQueueHead wqh);
 
index 1d6dc4ae4e4963613a126cbb4644a06003da66f7..84ac85ea36c0c7f736de2086129aa560d5e0511d 100644 (file)
@@ -1,20 +1,20 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        clock.c
+ *   File Name: clock.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Jan  5 09:51:54 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Jan  5 09:51:54 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<printk.h>
-#include<system.h>
-//void clk_handler(pPtRegs regs, unsigned int irq)
-void   clk_handler(unsigned int irq, pPtRegs regs, void *dev_id)
+#include <printk.h>
+#include <system.h>
+//void    clk_handler(pPtRegs regs, unsigned int irq)
+void    clk_handler(unsigned int irq, pPtRegs regs, void *dev_id)
 {
-       //printk("^");
-       //printk("%s ", dev_id);
+    //printk("^");
+    //printk("%s ", dev_id);
 }
index da8d993b74c851ec0cc6d867667fec9b831c7ae8..1efa193646257fa3e68177410321de1d78e89ea2 100644 (file)
@@ -1,37 +1,37 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        entry.S
+ *   File Name: entry.S
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Thu Jul 09 19:56:40 2009
  * Last Update: Thu Jul 09 19:56:40 2009
  * 
  *--------------------------------------------------------------------------
  */
-#define        ASM
-#include<system.h>
-#include<linkage.h>
+#define ASM
+#include <system.h>
+#include <linkage.h>
 
 /*
  * 陷阱门不会自动清除IF位.所以必需先关中断.
  * 这个bug我调了很久很久......
  */
-#define        EC_ENTRY(name)      \
-       .extern do##name;       \
-       ENTRY(name)             \
-       cli; /* 非常重要 */
+#define EC_ENTRY(name)      \
+    .extern    do##name;       \
+    ENTRY(name)             \
+    cli; /* 非常重要 */
 
-#define        EC_CALLDO(name)     \
-       SAVE_REGS                           \
-       call    do##name;               \
-       RESTORE_REGS;                   \
-       addl    $4,%esp;                \
-       iret;
+#define EC_CALLDO(name)     \
+    SAVE_REGS                \
+    call    do##name;        \
+    RESTORE_REGS;            \
+    addl    $4,%esp;        \
+    iret;
 
 
 /*
  * 零来占据错误码的位置.以保持代码风格的
  * 一致性.
  */
-#define        NOERRCODE(name)     \
-       EC_ENTRY(name)          \
-       pushl   $0;             \
-       EC_CALLDO(name)
+#define NOERRCODE(name)     \
+    EC_ENTRY(name)          \
+    pushl    $0;             \
+    EC_CALLDO(name)
 
-#define        ERRORCODE(name)     \
-       EC_ENTRY(name)          \
-       EC_CALLDO(name)
+#define ERRORCODE(name)     \
+    EC_ENTRY(name)          \
+    EC_CALLDO(name)
 
 
-NOERRCODE      (DivideError)
-NOERRCODE      (Debug)
-NOERRCODE      (NMI)
-NOERRCODE      (BreakPoint)
-NOERRCODE      (OverFlow)
-NOERRCODE      (BoundsCheck)
-NOERRCODE      (InvalidOpcode)
-NOERRCODE      (DeviceNotAvailable)
-NOERRCODE      (DoubleFault)
-NOERRCODE      (CoprocSegOverRun)
-ERRORCODE      (InvalidTss)
-ERRORCODE      (SegNotPresent)
-ERRORCODE      (StackFault)
-ERRORCODE      (GeneralProtection)
-ERRORCODE      (PageFault)
-NOERRCODE      (CoprocError)
+NOERRCODE    (DivideError)
+NOERRCODE    (Debug)
+NOERRCODE    (NMI)
+NOERRCODE    (BreakPoint)
+NOERRCODE    (OverFlow)
+NOERRCODE    (BoundsCheck)
+NOERRCODE    (InvalidOpcode)
+NOERRCODE    (DeviceNotAvailable)
+NOERRCODE    (DoubleFault)
+NOERRCODE    (CoprocSegOverRun)
+ERRORCODE    (InvalidTss)
+ERRORCODE    (SegNotPresent)
+ERRORCODE    (StackFault)
+ERRORCODE    (GeneralProtection)
+ERRORCODE    (PageFault)
+NOERRCODE    (CoprocError)
 
index 06ff350e8bee1326bf47ab37804937d5c7bdc53f..f8d3557f0a5d3bc41facd86da7983b596af1d277 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        exec.c
+ *   File Name: exec.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Feb 20 21:12:30 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Feb 20 21:12:30 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<syscall.h>
-#include<types.h>
-#include<fcntl.h>
-#include<assert.h>
-#include<stat.h>
-#include<sched.h>
-#include<memory.h>
-#include<elf.h>
+#include <syscall.h>
+#include <types.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <stat.h>
+#include <sched.h>
+#include <memory.h>
+#include <elf.h>
 
 int sysc_exec(const char *path, char *const argv[])
 {
-       assert(argv == NULL);   // unsupport now
-
-       int fd;
-       int i;
-
-       fd = sysc_open(path, O_RDONLY, 0);
-       if(fd == -1)
-       {
-               panic("can not find file");
-       }
-
-       int     filesz;
-       Stat    stat;
-       char    *buf;
-
-       sysc_stat(fd, &stat);
-       filesz  = stat.st_size;
-       if(stat.st_size <=0 || stat.st_size>MAX_SUPT_FILE_SIZE)
-       {
-               printk("file %s is not exist\n", path);
-               return -ENOENT;
-       }
-       buf = (void*)kmalloc(filesz);
-       sysc_read(fd, buf, filesz);
-
-#if 0  
-       for(i=0; i<filesz; i++)
-               printk("%02x ", (unsigned char)buf[i]);
+    assert(argv == NULL);    // unsupport now
+
+    int fd;
+    int i;
+
+    fd = sysc_open(path, O_RDONLY, 0);
+    if(fd == -1)
+    {
+        panic("can not find file");
+    }
+
+    int    filesz;
+    Stat    stat;
+    char    *buf;
+
+    sysc_stat(fd, &stat);
+    filesz    = stat.st_size;
+    if(stat.st_size <=0 || stat.st_size>MAX_SUPT_FILE_SIZE)
+    {
+        printk("file %s is not exist\n", path);
+        return -ENOENT;
+    }
+    buf = (void*)kmalloc(filesz);
+    sysc_read(fd, buf, filesz);
+
+#if 0    
+    for(i=0; i<filesz; i++)
+        printk("%02x ", (unsigned char)buf[i]);
 #endif
 
-       pElf32_Ehdr ehdr = (pElf32_Ehdr) buf;
-       //assert(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG)-1) == 0);
-       if(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG)-1) != 0)
-       {
-               printk("file %s can not execute\n", path);
-               kfree(buf);
-               return -ENOEXEC;
-       }
-       //printk("Entry: %08x phnum:%d\n", ehdr->e_entry, ehdr->e_phnum);
-       
-       int size = 0;
-       char *pv = NULL;        // phdr 中第一个的VirtAddr
-       for(i=0; i<ehdr->e_phnum; i++)
-       {
-               pElf32_Phdr phdr;
-               phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
-               //printk(" %d %08x\n", i, phdr->p_type);
-               if(phdr->p_type == PT_LOAD)
-               {
-                       size += phdr->p_memsz;
-                       if(i==0)
-                               pv = (char *)phdr->p_vaddr;
-               }
-       }
-
-       char *exe = (char *) kmalloc(size);
-       for(i=0; i<ehdr->e_phnum; i++)
-       {
-               pElf32_Phdr phdr;
-               phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
-               if(phdr->p_type != PT_LOAD)
-                       continue;
+    pElf32_Ehdr ehdr = (pElf32_Ehdr) buf;
+    //assert(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG)-1) == 0);
+    if(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG)-1) != 0)
+    {
+        printk("file %s can not execute\n", path);
+        kfree(buf);
+        return -ENOEXEC;
+    }
+    //printk("Entry: %08x phnum:%d\n", ehdr->e_entry, ehdr->e_phnum);
+    
+    int size = 0;
+    char *pv = NULL;    // phdr 中第一个的VirtAddr
+    for(i=0; i<ehdr->e_phnum; i++)
+    {
+        pElf32_Phdr phdr;
+        phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
+        //printk(" %d %08x\n", i, phdr->p_type);
+        if(phdr->p_type == PT_LOAD)
+        {
+            size += phdr->p_memsz;
+            if(i==0)
+                pv = (char *)phdr->p_vaddr;
+        }
+    }
+
+    char *exe = (char *) kmalloc(size);
+    for(i=0; i<ehdr->e_phnum; i++)
+    {
+        pElf32_Phdr phdr;
+        phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
+        if(phdr->p_type != PT_LOAD)
+            continue;
 #if 0
-               printk("%08x ", exe+phdr->p_vaddr-pv);
-               printk("p_offset:%d\n", phdr->p_offset);
+        printk("%08x ", exe+phdr->p_vaddr-pv);
+        printk("p_offset:%d\n", phdr->p_offset);
 
-               int j;
-               for(j=0; j<100;/*phdr->p_filesz*/ j++)
-                       printk("%02x ", *((char *)(buf+phdr->p_offset)+j));
+        int j;
+        for(j=0; j<100;/*phdr->p_filesz*/ j++)
+            printk("%02x ", *((char *)(buf+phdr->p_offset)+j));
 #endif
-               if(phdr->p_filesz != 0)
-               {
-                       memcpy((void*)(exe+phdr->p_vaddr-pv),
-                               (void*)(buf+phdr->p_offset),
-                               phdr->p_filesz);
-               }
+        if(phdr->p_filesz != 0)
+        {
+            memcpy((void*)(exe+phdr->p_vaddr-pv),
+                (void*)(buf+phdr->p_offset),
+                phdr->p_filesz);
+        }
 
 
 #if 0
-               u32     *pd =(u32*)pa2va(current->cr3);
-               u32     *pt;
-               u32     npd_min, npd_max, npt;
-               u32     pde, pte;
-               u32     vaddr = phdr->p_vaddr;
-               npd_min = get_npd(vaddr);
-               npd_max = get_npd(vaddr+phdr->p_memsz);
-               u32     npd;
-
-               for(npd=npd_min; npd<=npd_max; npd++)
-               {
-                       void *tmp = get_phys_pages(1);
-                       pd[npd] = tmp | 7;
-               }
+        u32    *pd =(u32*)pa2va(current->cr3);
+        u32    *pt;
+        u32    npd_min, npd_max, npt;
+        u32    pde, pte;
+        u32    vaddr = phdr->p_vaddr;
+        npd_min = get_npd(vaddr);
+        npd_max = get_npd(vaddr+phdr->p_memsz);
+        u32    npd;
+
+        for(npd=npd_min; npd<=npd_max; npd++)
+        {
+            void *tmp = get_phys_pages(1);
+            pd[npd] = tmp | 7;
+        }
 #endif
-       }
-
-
-       /*
-        *  因为目前文件支持最大为12*EXT2_BLOCK_SIZE
-        *  即12K~48K之间
-        *  所以就以一个页目录项来简化处理
-        */
-       u32     *pd = (u32*) pa2va(current->cr3);
-       u32     *pt;
-       u32     pa_exe;
-       u32     npd, npt;
-       
-       pa_exe  = va2pa(exe);
-       npd     = get_npd(ehdr->e_entry);
-       pt      = get_phys_pages(1);
-       if(pt == NULL)
-               panic("out of memory");
-       //printk("npd: %d pt:%08x\n", npd, pt);
-       memset(pa2va(pt), 0, PAGE_SIZE);
-       pd[npd] = (u32) pt | 7;
-       pt = pa2va(pt);
-       for(i=0; i<ehdr->e_phnum; i++)
-       {
-               pElf32_Phdr phdr;
-               phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
-               if(phdr->p_type != PT_LOAD)
-                       continue;
-
-               u32     npt_min, npt_max;
-
-               npt_min = get_npt(phdr->p_vaddr);
-               npt_max = get_npt(phdr->p_vaddr+phdr->p_memsz);
-               //printk("npt_min:%d npt_max:%d\n", npt_min, npt_max);
-               int j;
-               for(j=npt_min; j<=npt_max; j++)
-               {
-                       pt[j] = (u32)(pa_exe | 7);      // 对于.text不能这样
-                       //printk("pt[j] :%08x\n", pt[j]);
-                       pa_exe = PAGE_SIZE+pa_exe;
-               }
-       }
-       
-       //printk("exe : %08x cr3:%08x\n", exe, pd);
-
-
-       /* 准备内核栈的数据并从ret_from_fork返回 */
-       pPtRegs regs    = ((pPtRegs)(TASK_SIZE+(unsigned long)current)) - 1;
-       extern void ret_from_fork();
-       memset((void*)regs, 0, sizeof(PtRegs));
-       regs->ss        = SELECTOR_USER_DS;
-       regs->ds        = SELECTOR_USER_DS;
-       regs->es        = SELECTOR_USER_DS;
-       regs->fs        = SELECTOR_USER_DS;
-       regs->gs        = SELECTOR_USER_DS;
-       regs->esp       = (KRNLADDR-4*sizeof(unsigned long));
-       regs->eflags    = 0x200;
-       regs->cs        = SELECTOR_USER_CS;
-       regs->eip       = (unsigned long)ehdr->e_entry;
-       current->esp    = (unsigned long) regs;
-       current->eip    = (unsigned long)ret_from_fork;
-
-#if 0  /* 写完之后发现貌似不用 */
-       /* 准备用户栈数据 */
-       /* 先找到用户栈的位置 */
-       u32 pde = pd[get_npd(KRNLADDR)-1] & PAGE_MASK;
-       pt = pa2va(pde);
-       u32 *stack = (u32*)pa2va(pt[1023]);
-       stack[1023] = 0x00;
-       stack[1022] = 0x00;     /* ebp */
-       stack[1021] = 0x00;     /* edx */
-       stack[1020] = 0x00;     /* ecx */
-       printk("stack pt: %08x pde:%08x %08x %08x\n",
-               pt, pde, pd[get_npd(KRNLADDR)-1]);
+    }
+
+
+    /*
+     *  因为目前文件支持最大为12*EXT2_BLOCK_SIZE
+     *  即12K~48K之间
+     *  所以就以一个页目录项来简化处理
+     */
+    u32    *pd = (u32*) pa2va(current->cr3);
+    u32    *pt;
+    u32    pa_exe;
+    u32    npd, npt;
+    
+    pa_exe    = va2pa(exe);
+    npd    = get_npd(ehdr->e_entry);
+    pt    = get_phys_pages(1);
+    if(pt == NULL)
+        panic("out of memory");
+    //printk("npd: %d pt:%08x\n", npd, pt);
+    memset(pa2va(pt), 0, PAGE_SIZE);
+    pd[npd]    = (u32) pt | 7;
+    pt = pa2va(pt);
+    for(i=0; i<ehdr->e_phnum; i++)
+    {
+        pElf32_Phdr phdr;
+        phdr = (pElf32_Phdr)(buf+ehdr->e_phoff+(i*ehdr->e_phentsize));
+        if(phdr->p_type != PT_LOAD)
+            continue;
+
+        u32    npt_min, npt_max;
+
+        npt_min = get_npt(phdr->p_vaddr);
+        npt_max = get_npt(phdr->p_vaddr+phdr->p_memsz);
+        //printk("npt_min:%d npt_max:%d\n", npt_min, npt_max);
+        int j;
+        for(j=npt_min; j<=npt_max; j++)
+        {
+            pt[j] = (u32)(pa_exe | 7);    // 对于.text不能这样
+            //printk("pt[j] :%08x\n", pt[j]);
+            pa_exe = PAGE_SIZE+pa_exe;
+        }
+    }
+    
+    //printk("exe : %08x cr3:%08x\n", exe, pd);
+
+
+    /* 准备内核栈的数据并从ret_from_fork返回 */
+    pPtRegs    regs    = ((pPtRegs)(TASK_SIZE+(unsigned long)current)) - 1;
+    extern void ret_from_fork();
+    memset((void*)regs, 0, sizeof(PtRegs));
+    regs->ss    = SELECTOR_USER_DS;
+    regs->ds    = SELECTOR_USER_DS;
+    regs->es    = SELECTOR_USER_DS;
+    regs->fs    = SELECTOR_USER_DS;
+    regs->gs    = SELECTOR_USER_DS;
+    regs->esp    = (KRNLADDR-4*sizeof(unsigned long));
+    regs->eflags    = 0x200;
+    regs->cs    = SELECTOR_USER_CS;
+    regs->eip    = (unsigned long)ehdr->e_entry;
+    current->esp    = (unsigned long) regs;
+    current->eip    = (unsigned long)ret_from_fork;
+
+#if 0    /* 写完之后发现貌似不用 */
+    /* 准备用户栈数据 */
+    /* 先找到用户栈的位置 */
+    u32 pde = pd[get_npd(KRNLADDR)-1] & PAGE_MASK;
+    pt = pa2va(pde);
+    u32 *stack = (u32*)pa2va(pt[1023]);
+    stack[1023] = 0x00;
+    stack[1022] = 0x00;    /* ebp */
+    stack[1021] = 0x00;    /* edx */
+    stack[1020] = 0x00;    /* ecx */
+    printk("stack pt: %08x pde:%08x %08x %08x\n",
+        pt, pde, pd[get_npd(KRNLADDR)-1]);
 #endif
-       kfree(buf);
+    kfree(buf);
 
 
-       //printk("eip: %08x \n", regs->eip);
+    //printk("eip: %08x \n", regs->eip);
 
-       load_cr3(current);
+    load_cr3(current);
 
-       return 0;
+    return 0;
 }
index 812e63b6f897f2f23d2b66b87dcde5382f697fbf..05835bde91f02a2dc495f3b1256139a36be6ea9d 100644 (file)
@@ -1,29 +1,29 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        exit.c
+ *   File Name: exit.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Thu Mar  4 10:03:57 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Thu Mar  4 10:03:57 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<sched.h>
-#include<system.h>
+#include <sched.h>
+#include <system.h>
 
 int sysc_exit(int status)
 {
 
-       if(current == &RootTsk)
-               panic("Root Task is Exiting...");
+    if(current == &RootTsk)
+        panic("Root Task is Exiting...");
 
-       /* 先简要实现 */
-       current->state = TASK_EXITING;
+    /* 先简要实现 */
+    current->state = TASK_EXITING;
 
-       
-       schedule();
+    
+    schedule();
 
-       return 0;
+    return 0;
 }
index 6a2975be2650b980e0284f0d1bc2814b1b6d8fc7..89c7a330df06bb9ca85212689a7c0e20e7a120db 100644 (file)
@@ -1,93 +1,93 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        fork.c
+ *   File Name: fork.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Feb  7 13:25:28 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Feb  7 13:25:28 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<sched.h>
+#include <sched.h>
 #if 1
 int sysc_fork()
 {
-       // 先分配一个进程控制结构
-       task_struct *tsk;
-       // TODO tsk = get_unused_task_pcb();
-       if(tsk == NULL)
-               panic("can not malloc PCB");
+    // 先分配一个进程控制结构
+    task_struct *tsk;
+    // TODO tsk = get_unused_task_pcb();
+    if(tsk == NULL)
+        panic("can not malloc PCB");
 
-       //printk("CHILD:%08x\n", tsk);
+    //printk("CHILD:%08x\n", tsk);
 
-       memcpy(tsk, current, sizeof(task_struct));
+    memcpy(tsk, current, sizeof(task_struct));
 
-       tsk->pid        = get_next_pid();
-       tsk->ppid       = current->pid;
+    tsk->pid    = get_next_pid();
+    tsk->ppid    = current->pid;
 
-       init_tsk_cr3(tsk);
+    init_tsk_cr3(tsk);
 
-       int i, j;
-       u32 *p_pd  = (u32 *) current->cr3; // parent's page dir
-       u32 p_pde; // parent's page dir entry
-       u32 *p_pt  = NULL;
-       u32 *c_pd  = (u32 *) tsk->cr3;
-       u32 c_pde;
-       u32 *c_pt  = NULL;
+    int i, j;
+    u32 *p_pd  = (u32 *) current->cr3; // parent's page dir
+    u32 p_pde; // parent's page dir entry
+    u32 *p_pt  = NULL;
+    u32 *c_pd  = (u32 *) tsk->cr3;
+    u32 c_pde;
+    u32 *c_pt  = NULL;
 
-       p_pd = pa2va(p_pd);
-       c_pd = pa2va(c_pd);
+    p_pd = pa2va(p_pd);
+    c_pd = pa2va(c_pd);
 
-       for(i = (KRNLADDR>>22); i>=0; i--)
-       {
-               p_pde = p_pd[i] & 0xFFFFF000;
-               if(p_pde == 0)
-                       continue;
+    for(i = (KRNLADDR>>22); i>=0; i--)
+    {
+        p_pde = p_pd[i] & 0xFFFFF000;
+        if(p_pde == 0)
+            continue;
 
-               //printk("i:%d p_pde:%08x ", i, p_pde);
+        //printk("i:%d p_pde:%08x ", i, p_pde);
 
-               // 分配页表
-               c_pde = (u32) get_phys_pages(1);
+        // 分配页表
+        c_pde = (u32) get_phys_pages(1);
 
-               //printk("c_pde:%08x ", c_pde);
+        //printk("c_pde:%08x ", c_pde);
 
-               c_pt  = pa2va(c_pde);
-               p_pt  = pa2va(p_pde);
+        c_pt  = pa2va(c_pde);
+        p_pt  = pa2va(p_pde);
 
-               //printk("c_pt:%08x p_pt:%08x\n", c_pt, p_pt);
+        //printk("c_pt:%08x p_pt:%08x\n", c_pt, p_pt);
 
-               for(j=0; j<PAGE_ITEMS; j++)
-               {
-                       p_pt[j] &= (~2UL);
-                       c_pt[j] = p_pt[j];
-                       /* 增加此页的共享计数 */
-                       pgmap[p_pt[j]>>PAGE_SHIFT].count++;
-               }
+        for(j=0; j<PAGE_ITEMS; j++)
+        {
+            p_pt[j] &= (~2UL);
+            c_pt[j] = p_pt[j];
+            /* 增加此页的共享计数 */
+            pgmap[p_pt[j]>>PAGE_SHIFT].count++;
+        }
 
-               c_pd[i] = c_pde | 7;
-       }
+        c_pd[i] = c_pde | 7;
+    }
 
 
-       load_cr3(current);
+    load_cr3(current);
 
-       //pPtRegs       regs    = ((pPtRegs)(TASK_SIZE+(unsigned long) current))-1;
-       //tsk->regs     = *regs;
-       //tsk->regs.eax = 0x00;
-       //tsk->regs.eflags |= 0x200; //enable IF
-       pPtRegs regs    = ((pPtRegs)(TASK_SIZE+(unsigned long) tsk))-1;
-       extern  void ret_from_fork();
-       regs->eax       = 0x00;
-       tsk->esp0       = TASK_SIZE + (unsigned long) tsk;
-       tsk->esp        = (unsigned long) regs;
-       tsk->eip        = (unsigned long) ret_from_fork;
+    //pPtRegs    regs    = ((pPtRegs)(TASK_SIZE+(unsigned long) current))-1;
+    //tsk->regs    = *regs;
+    //tsk->regs.eax    = 0x00;
+    //tsk->regs.eflags |= 0x200; //enable IF
+    pPtRegs    regs    = ((pPtRegs)(TASK_SIZE+(unsigned long) tsk))-1;
+    extern    void ret_from_fork();
+    regs->eax    = 0x00;
+    tsk->esp0    = TASK_SIZE + (unsigned long) tsk;
+    tsk->esp    = (unsigned long) regs;
+    tsk->eip    = (unsigned long) ret_from_fork;
 
 
-       //printk("FORK:%08x\n", tsk);
+    //printk("FORK:%08x\n", tsk);
 
     tsk->state = TASK_RUNNING;
 
-       return (int)tsk->pid;
+    return (int)tsk->pid;
 }
 #endif
index eb469525fdc3f84aecc7fb1e0772097036833226..c9dcc6c2f08f4c3dd0df5712c2127edd33116010 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        i8259.c
+ *   File Name: i8259.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Nov  9 11:35:22 2008
  * Last Update: Tue Feb 10 22:37:15 2009
  * 
 #include "i8259.h"
 #include "irq.h"
 
-IrqChip        i8259_chip =
+IrqChip    i8259_chip =
 {
-       .name           = "XT-PIC",
-       .enable         = enable_i8259_irq,
-       .disable        = disable_i8259_irq,
-       .ack            = mask_ack_i8259_irq,
+    .name        = "XT-PIC",
+    .enable        = enable_i8259_irq,
+    .disable    = disable_i8259_irq,
+    .ack        = mask_ack_i8259_irq,
 };
 #if 0
 void enable_i8259_irq(unsigned int irq)
 {
-       unsigned int mask = ~(1 << irq);
-       cached_irq_mask &= mask;
-       if(irq & 8)
-               outb_p(cached_slaver_mask, PIC_SLAVER_IMR);
-       else
-               outb_p(cached_master_mask, PIC_MASTER_IMR);
+    unsigned int mask = ~(1 << irq);
+    cached_irq_mask &= mask;
+    if(irq & 8)
+        outb_p(cached_slaver_mask, PIC_SLAVER_IMR);
+    else
+        outb_p(cached_master_mask, PIC_MASTER_IMR);
 }
 
 void disable_i8259_irq(unsigned int irq)
 {
-       unsigned int mask = 1 << irq;
-       cached_irq_mask |= mask;
-       if(irq & 8)
-               outb_p(cached_slaver_mask, PIC_SLAVER_IMR);
-       else
-               outb_p(cached_master_mask, PIC_MASTER_IMR);
+    unsigned int mask = 1 << irq;
+    cached_irq_mask |= mask;
+    if(irq & 8)
+        outb_p(cached_slaver_mask, PIC_SLAVER_IMR);
+    else
+        outb_p(cached_master_mask, PIC_MASTER_IMR);
 }
 #endif
 void mask_i8259()
 {
-       //mask all of 8259
-       outb_p(0xFF, PIC_MASTER_IMR);
-       outb_p(0xFF, PIC_SLAVER_IMR);
+    //mask all of 8259
+    outb_p(0xFF, PIC_MASTER_IMR);
+    outb_p(0xFF, PIC_SLAVER_IMR);
 }
 void init_i8259()
 {
 #if 0
-       outb_p(0x11,0x20);
-       outb_p(0x11,0xA0);
+    outb_p(0x11,0x20);
+    outb_p(0x11,0xA0);
 
-       outb_p(0x20,0x21);
-       outb_p(0x28,0xA1);
+    outb_p(0x20,0x21);
+    outb_p(0x28,0xA1);
 
-       outb_p(0x04,0x21);
-       outb_p(0x02,0xA1);
+    outb_p(0x04,0x21);
+    outb_p(0x02,0xA1);
 
-       outb_p(0x01,0x21);
-       outb_p(0x01,0xA1);
+    outb_p(0x01,0x21);
+    outb_p(0x01,0xA1);
 
-       outb_p(0xFF,0x21);
-       outb_p(0xFF,0xA1);
+    outb_p(0xFF,0x21);
+    outb_p(0xFF,0xA1);
 #else
-       //Master...
-       outb_p(0x11, PIC_MASTER_CMD); // ICW1
-       outb_p(0x20, PIC_MASTER_IMR); // ICW2: IR0-7 mapped to 0x20-0x27
-       outb_p(1U<<PIC_CASCADE_IR, PIC_MASTER_IMR); //IR2 Connect Slaver.
-       outb_p(0x01, PIC_MASTER_IMR);   // Normal EOI
-       //Auto EOI:outb_p(0x03, PIC_MASTER_CMDB);
-       
-       //Slaver...
-       outb_p(0x11, PIC_SLAVER_CMD);
-       outb_p(0x28, PIC_SLAVER_IMR); // IR0-7 mapped to 0x28-0x2F
-       outb_p(PIC_CASCADE_IR, PIC_SLAVER_IMR);
-       outb_p(0x01, PIC_SLAVER_IMR);
-       //Auto EOI:outb_p(0x01, PIC_SLAVER_CMDB);
-       mask_i8259();
+    //Master...
+    outb_p(0x11, PIC_MASTER_CMD); // ICW1
+    outb_p(0x20, PIC_MASTER_IMR); // ICW2: IR0-7 mapped to 0x20-0x27
+    outb_p(1U<<PIC_CASCADE_IR, PIC_MASTER_IMR); //IR2 Connect Slaver.
+    outb_p(0x01, PIC_MASTER_IMR);    // Normal EOI
+    //Auto EOI:outb_p(0x03, PIC_MASTER_CMDB);
+    
+    //Slaver...
+    outb_p(0x11, PIC_SLAVER_CMD);
+    outb_p(0x28, PIC_SLAVER_IMR); // IR0-7 mapped to 0x28-0x2F
+    outb_p(PIC_CASCADE_IR, PIC_SLAVER_IMR);
+    outb_p(0x01, PIC_SLAVER_IMR);
+    //Auto EOI:outb_p(0x01, PIC_SLAVER_CMDB);
+    mask_i8259();
 #endif
 }
index e60c3c3b22ea99d126c4e6756086ff991a0528e9..375287296caeaf40969861ec128203be46977267 100644 (file)
-#include<io.h>
-#include<sched.h>
-#include<types.h>
-#include<page.h>
-#include<stdio.h>
-#include<system.h>
-#include<syscall.h>
-#include<processor.h>
-#include<irq.h>
-#include<fcntl.h>
-#include<stat.h>
+#include <io.h>
+#include <sched.h>
+#include <types.h>
+#include <page.h>
+#include <stdio.h>
+#include <system.h>
+#include <syscall.h>
+#include <processor.h>
+#include <irq.h>
+#include <fcntl.h>
+#include <stat.h>
 
-#define        KRNL_STACK_SIZE 4096
+#define KRNL_STACK_SIZE    4096
 
-extern void    root_task();
-extern void    setup_kernel();
+extern void    root_task();
+extern void    setup_kernel();
 
-TSS    tss;
-System system;
+TSS    tss;
+System    system;
 
-static char    kernel_stack[KRNL_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE)));
+static char    kernel_stack[KRNL_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE)));
 
 int KernelEntry()
 {
-       asm(    "movl $kernel_stack,%%esp;"
-               "addl %%eax,%%esp;"
-               ::"a"(KRNL_STACK_SIZE));
+    asm(    "movl $kernel_stack,%%esp;"
+        "addl %%eax,%%esp;"
+        ::"a"(KRNL_STACK_SIZE));
 
-       setup_kernel();
+    setup_kernel();
 
-       asm("   movl    $0x23,%%eax;            \
-               movw    %%ax,%%ds;              \
-               movw    %%ax,%%es;              \
-               movw    %%ax,%%fs;              \
-               movw    %%ax,%%gs;              \
-               pushl   $0x23;                  \
-               pushl   %%ebx;                  \
-               pushl   $0x282;                 \
-               pushl   $0x1B;                  \
-               leal    root_task,%%eax;        \
-               pushl   %%eax;                  \
-               iret;"::"b"(KRNLADDR));
-       return 0;
+    asm("    movl    $0x23,%%eax;        \
+        movw    %%ax,%%ds;        \
+        movw    %%ax,%%es;        \
+        movw    %%ax,%%fs;        \
+        movw    %%ax,%%gs;        \
+        pushl    $0x23;            \
+        pushl    %%ebx;            \
+        pushl    $0x282;            \
+        pushl    $0x1B;            \
+        leal    root_task,%%eax;    \
+        pushl    %%eax;            \
+        iret;"::"b"(KRNLADDR));
+    return 0;
 }
 
 #if 0
 void root_task()
 {
-       pid_t pid;
-       pid = fork();
-       if(pid < 0)
-       {
-               printf("failed create child\n");
-               while(1);
-       }
-       else if(pid == 0)
-       {
-               execv("/bin/sh", NULL);
-               while(1);
-       }
-       else
-       {
-               while(1)
-               {
+    pid_t pid;
+    pid = fork();
+    if(pid < 0)
+    {
+        printf("failed create child\n");
+        while(1);
+    }
+    else if(pid == 0)
+    {
+        execv("/bin/sh", NULL);
+        while(1);
+    }
+    else
+    {
+        while(1)
+        {
 
-               }
-       }
+        }
+    }
 }
 #else
 void root_task()
 {
-       pid_t pid;
+    pid_t pid;
 /*
-       int fd = open("/boot/grub/grub.conf", O_RDONLY);
-       //int fd = open("/bin/hw", O_RDONLY);
-       printf("FD: %d\n", fd);
-       char    buf[1024];
-       int     filesz, i;
-       Stat    stat;
-       fstat(fd, &stat);
-       filesz = stat.st_size;
-       printf("file size: %d bytes\n", filesz);
-       read(fd, buf, filesz);
-       for(i=0; i<filesz; i++)
-               printf("%c", buf[i]);
-       execv("/bin/hw", NULL);
-       while(0)
-       {
-               printf("r");
-               int d=100000; while(d--);
-       }
+    int fd = open("/boot/grub/grub.conf", O_RDONLY);
+    //int fd = open("/bin/hw", O_RDONLY);
+    printf("FD: %d\n", fd);
+    char    buf[1024];
+    int    filesz, i;
+    Stat    stat;
+    fstat(fd, &stat);
+    filesz = stat.st_size;
+    printf("file size: %d bytes\n", filesz);
+    read(fd, buf, filesz);
+    for(i=0; i<filesz; i++)
+        printf("%c", buf[i]);
+    execv("/bin/hw", NULL);
+    while(0)
+    {
+        printf("r");
+        int d=100000; while(d--);
+    }
 */
 
 
-//#define      SHOW    
+//#define    SHOW    
 
-       pid = fork();
-#ifdef SHOW
-       printf("PID: %d\n", pid);
+    pid = fork();
+#ifdef    SHOW
+    printf("PID: %d\n", pid);
 #endif
-       if(pid < 0)
-       {
-               printf("failed create child\n");
-               while(1);
-       }
-       else if(pid == 0)
-       {
-               pid_t ccid;
-               ccid = fork();
+    if(pid < 0)
+    {
+        printf("failed create child\n");
+        while(1);
+    }
+    else if(pid == 0)
+    {
+        pid_t ccid;
+        ccid = fork();
 
-#ifdef SHOW
-               printf("CCID: %d\n", ccid);
+#ifdef    SHOW
+        printf("CCID: %d\n", ccid);
 #endif
 
-               if(ccid < 0)
-               {
-                       printf("child faild to create child\n");
-                       while(1);
-               }
-               else if(ccid == 0)
-               {
-                       execv("/bin/sh", NULL);
-                       while(1)
-                       {
-#ifdef SHOW
-                               printf("a");
+        if(ccid < 0)
+        {
+            printf("child faild to create child\n");
+            while(1);
+        }
+        else if(ccid == 0)
+        {
+            execv("/bin/sh", NULL);
+            while(1)
+            {
+#ifdef    SHOW
+                printf("a");
 #endif
-                               delay(100);
-                       }
-               }
-               else
-               {
-                       while(1)
-                       {
-#ifdef SHOW
-                               printf("b");
+                delay(100);
+            }
+        }
+        else
+        {
+            while(1)
+            {
+#ifdef    SHOW
+                printf("b");
 #endif
-                               delay(200);
-                       }
-               }
-       }
-       else
-       {
-               pid_t pcid;
-               pcid = fork();
-       
-#ifdef SHOW
-               printf("PCID: %d\n", pcid);
+                delay(200);
+            }
+        }
+    }
+    else
+    {
+        pid_t pcid;
+        pcid = fork();
+    
+#ifdef    SHOW
+        printf("PCID: %d\n", pcid);
 #endif
-               if(pcid < 0)
-               {
-                       printf("parent faild to create child\n");
-                       while(1);
-               }
-               else if(pcid == 0)
-               {
-                       while(1)
-                       {
-#ifdef SHOW
-                               printf("c");
+        if(pcid < 0)
+        {
+            printf("parent faild to create child\n");
+            while(1);
+        }
+        else if(pcid == 0)
+        {
+            while(1)
+            {
+#ifdef    SHOW
+                printf("c");
 #endif
-                               delay(300);
-                       }
-               }
-               else
-               {
-                       while(1)
-                       {
+                delay(300);
+            }
+        }
+        else
+        {
+            while(1)
+            {
 #if 0
-                               int k;
-                               extern  void    ParseKbdInput(int k);
-                               k = read_kbd();
-                               ParseKbdInput(k);
+                int k;
+                extern    void    ParseKbdInput(int k);
+                k = read_kbd();
+                ParseKbdInput(k);
 #else
-#ifdef SHOW
-                               printf("d");
+#ifdef    SHOW
+                printf("d");
 #endif
-                               delay(400);
+                delay(400);
 #endif
-                       }
-               }
-       }
+            }
+        }
+    }
 }
 #endif
index 1463029e14803e1eb89aca01cabebbad54dee86a..58fcd91b022838aa29b4fbff33def706335761b2 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        innerint.c
+ *   File Name: innerint.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Mon Nov 10 15:58:46 2008
  * Last Update: Tue Feb 10 22:39:24 2009
- *     Version:        2.0
+ *     Version:    2.0
  * Last Update: Fri Jul 10 11:55:39 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<system.h>
-#include<sched.h>
+#include <system.h>
+#include <sched.h>
 
-#define        DIE_MSG() do{\
-       printk("Unsupport Now...[%s]\n", __FUNCTION__);         \
-       printk("EFLAGS:%08x CS:%02x EIP:%08x ERRCODE:%x",       \
-       regs.eflags, regs.cs, regs.eip, regs.errcode);          \
-       while(1);                                               \
+#define DIE_MSG() do{\
+    printk("Unsupport Now...[%s]\n", __FUNCTION__);        \
+    printk("EFLAGS:%08x CS:%02x EIP:%08x ERRCODE:%x",     \
+    regs.eflags, regs.cs, regs.eip, regs.errcode);        \
+    while(1);                        \
 }while(0);
 
 void doDivideError(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doDebug(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doNMI(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doBreakPoint(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doOverFlow(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doBoundsCheck(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doInvalidOpcode(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doDeviceNotAvailable(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doDoubleFault(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doCoprocSegOverRun(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doInvalidTss(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doSegNotPresent(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doStackFault(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doGeneralProtection(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
 void doPageFault(PtRegs regs)
 {
-       //DIE_MSG();
-       void    *addr;
-       u32     errcode = regs.errcode;
+    //DIE_MSG();
+    void    *addr;
+    u32    errcode = regs.errcode;
 
-       asm("movl %%cr2,%%eax":"=a"(addr));
+    asm("movl %%cr2,%%eax":"=a"(addr));
 
 /*
-       unsigned long cr3;
-       asm("movl %%cr3,%%eax":"=a"(cr3));
-       printk("%08x errcode: %08x cr2: %08x cr3: %08x\n",
-               current, errcode, addr, cr3);
+    unsigned long cr3;
+    asm("movl %%cr3,%%eax":"=a"(cr3));
+    printk("%08x errcode: %08x cr2: %08x cr3: %08x\n",
+        current, errcode, addr, cr3);
 */
 
-       if((errcode & (1UL<<PAGE_P)) == 0)
-       {
-               extern  void    do_no_page(void *);
-               do_no_page(addr);
-       }
-       else
-       {
-               extern  void    do_wp_page(void *);
-               do_wp_page(addr);
-       }
+    if((errcode & (1UL<<PAGE_P)) == 0)
+    {
+        extern    void    do_no_page(void *);
+        do_no_page(addr);
+    }
+    else
+    {
+        extern    void    do_wp_page(void *);
+        do_wp_page(addr);
+    }
 }
 void doCoprocError(PtRegs regs)
 {
-       DIE_MSG();
+    DIE_MSG();
 }
index 679117cd6bd96257d9e0bc3e5e33fdc228baf9e0..bf3d0a761e7d651e39ac29c55a496ab190dcf145 100644 (file)
@@ -1,47 +1,47 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        interrupts.S
+ *   File Name: interrupts.S
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Thu Jul 16 18:54:08 2009
  * Last Update: Wed Feb 10 23:10:56 2010
  * 
  *--------------------------------------------------------------------------
  */
-#define        ASM
-#include<linkage.h>
-#include<system.h>
-
-#define        IRQ_SYMBL(a,b)  irq_0x##a##b_handler
-#define        IRQ_LIST(x)     \
-IRQ_SYMBL(x,0),                \
-IRQ_SYMBL(x,1),                \
-IRQ_SYMBL(x,2),                \
-IRQ_SYMBL(x,3),                \
-IRQ_SYMBL(x,4),                \
-IRQ_SYMBL(x,5),                \
-IRQ_SYMBL(x,6),                \
-IRQ_SYMBL(x,7),                \
-IRQ_SYMBL(x,8),                \
-IRQ_SYMBL(x,9),                \
-IRQ_SYMBL(x,A),                \
-IRQ_SYMBL(x,B),                \
-IRQ_SYMBL(x,C),                \
-IRQ_SYMBL(x,D),                \
-IRQ_SYMBL(x,E),                \
+#define ASM
+#include <linkage.h>
+#include <system.h>
+
+#define IRQ_SYMBL(a,b)    irq_0x##a##b_handler
+#define IRQ_LIST(x)    \
+IRQ_SYMBL(x,0),        \
+IRQ_SYMBL(x,1),        \
+IRQ_SYMBL(x,2),        \
+IRQ_SYMBL(x,3),        \
+IRQ_SYMBL(x,4),        \
+IRQ_SYMBL(x,5),        \
+IRQ_SYMBL(x,6),        \
+IRQ_SYMBL(x,7),        \
+IRQ_SYMBL(x,8),        \
+IRQ_SYMBL(x,9),        \
+IRQ_SYMBL(x,A),        \
+IRQ_SYMBL(x,B),        \
+IRQ_SYMBL(x,C),        \
+IRQ_SYMBL(x,D),        \
+IRQ_SYMBL(x,E),        \
 IRQ_SYMBL(x,F)
 
-#define        DEF_IRQ(a,b)            \
-.align 0x04,0x90;              \
-.global        irq_0x##a##b##_handler; \
-irq_0x##a##b##_handler:                \
-pushl  $0x##a##b;              \
-jmp    _irq_handler;
+#define DEF_IRQ(a,b)        \
+.align    0x04,0x90;        \
+.global    irq_0x##a##b##_handler;    \
+irq_0x##a##b##_handler:        \
+pushl    $0x##a##b;        \
+jmp    _irq_handler;
 
 
 DEF_IRQ(0,0)
@@ -64,65 +64,65 @@ DEF_IRQ(0,F)
 
 .global _irq_handler
 .extern irq_handler
-.extern        schedule
+.extern    schedule
 _irq_handler:
 #if 1
-       /*
-        * 这些寄存器以及上面的中断号和中断自动压栈的寄存器
-        * 都存在中断栈中.
-        */
-       SAVE_REGS
-
-       movw    %ss,%ax
-       movw    %ax, %ds
-       movw    %ax, %es
-       movw    %ax, %fs
-       movw    %ax, %gs
-
-       movl    %esp, %eax
-       call    irq_handler
-
-       call    schedule
-
-       # movl  current, %esp
-               
-       RESTORE_REGS
-       
-       addl    $4,%esp /* 跳过中断号. */
-
-       iret
+    /*
+     * 这些寄存器以及上面的中断号和中断自动压栈的寄存器
+     * 都存在中断栈中.
+     */
+    SAVE_REGS
+
+    movw    %ss,%ax
+    movw    %ax, %ds
+    movw    %ax, %es
+    movw    %ax, %fs
+    movw    %ax, %gs
+
+    movl    %esp, %eax
+    call    irq_handler
+
+    call    schedule
+
+    # movl    current, %esp
+        
+    RESTORE_REGS
+    
+    addl    $4,%esp    /* 跳过中断号. */
+
+    iret
 #endif
 
-#if 0  /* 2010.02.22 */
-       /*
-        * 这些寄存器以及上面的中断号和中断自动压栈的寄存器
-        * 都存在中断栈中.
-        */
-       SAVE_REGS
-
-       movw    %ss,%ax
-       movw    %ax, %ds
-       movw    %ax, %es
-       movw    %ax, %fs
-       movw    %ax, %gs
-
-       movl    %esp, %eax
-       call    irq_handler
-
-
-       /* 向调度器传递栈帧的位置以便其保存现场. */
-       pushl   %esp
-       call    schedule
-
-       /*
-        * 利用task_struct 里的内容作为新进程的现场来恢复
-        * 所以用不着针对pushl %esp 写 addl $4,%esp了.
-        */
-       movl    current, %esp
-               
-       RESTORE_REGS
-       
-       addl    $4,%esp /* 跳过中断号. */
-
-       iret
+#if 0    /* 2010.02.22 */
+    /*
+     * 这些寄存器以及上面的中断号和中断自动压栈的寄存器
+     * 都存在中断栈中.
+     */
+    SAVE_REGS
+
+    movw    %ss,%ax
+    movw    %ax, %ds
+    movw    %ax, %es
+    movw    %ax, %fs
+    movw    %ax, %gs
+
+    movl    %esp, %eax
+    call    irq_handler
+
+
+    /* 向调度器传递栈帧的位置以便其保存现场. */
+    pushl    %esp
+    call    schedule
+
+    /*
+     * 利用task_struct 里的内容作为新进程的现场来恢复
+     * 所以用不着针对pushl %esp 写 addl $4,%esp了.
+     */
+    movl    current, %esp
+        
+    RESTORE_REGS
+    
+    addl    $4,%esp    /* 跳过中断号. */
+
+    iret
 #endif
index cbc162ba058c91e868e7a55c1da1b0b6a6aa0f67..8d5891d95002296df419caed4801c6cddd7847b8 100644 (file)
@@ -1,99 +1,99 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        irq.c
+ *   File Name: irq.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Thu Jul 16 18:06:22 2009
  * Last Update: Thu Jul 16 18:06:22 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<irq.h>
-#include<errno.h>
-#include<assert.h>
+#include <irq.h>
+#include <errno.h>
+#include <assert.h>
 
-IrqDesc        irq_desc[NR_IRQS];
+IrqDesc    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 =
+int    enable_no_irq_chip(unsigned int irq){return 0;}
+int    disable_no_irq_chip(unsigned int irq){return 0;}
+IrqChip    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
 };
-IrqDesc        no_irq_desc =
+IrqDesc    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(pPtRegs regs)
+__attribute__ ((regparm(1))) void    irq_handler(pPtRegs regs)
 {
 
-       unsigned int irq = regs->irq;
-       pIrqDesc        p = irq_desc + irq;
-       pIrqAction      action = p->action;
-       p->chip->ack(irq);
-       while(action)
-       {
-               //action->handler(regs, irq);
-               action->handler(irq, regs, action->dev_id);
-               action = action->next;
-       }
-       p->chip->enable(irq);
+    unsigned int irq = regs->irq;
+    pIrqDesc    p = irq_desc + irq;
+    pIrqAction    action = p->action;
+    p->chip->ack(irq);
+    while(action)
+    {
+        //action->handler(regs, irq);
+        action->handler(irq, regs, action->dev_id);
+        action = action->next;
+    }
+    p->chip->enable(irq);
 }
 
 
 /*
-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)(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)
+int    request_irq(    unsigned int irq,
+            void    (*handler)(unsigned int, pPtRegs, void *),
+            const char *devname,
+            void    *dev_id)
 {
-       pIrqAction      p;
+    pIrqAction    p;
 
-       if(irq >= NR_IRQS)
-               return -EINVAL;
-       if(handler == NULL)
-               return -EINVAL;
+    if(irq >= NR_IRQS)
+        return -EINVAL;
+    if(handler == NULL)
+        return -EINVAL;
 
-       // 检查是否已经注册过处理函数了
-       p = irq_desc[irq].action;
-       while(p != NULL)
-       {
-               if(p->handler == handler)
-                       return 0;
-               p = p->next;
-       }
+    // 检查是否已经注册过处理函数了
+    p = irq_desc[irq].action;
+    while(p != NULL)
+    {
+        if(p->handler == handler)
+            return 0;
+        p = p->next;
+    }
 
-       p = kmalloc(sizeof(IrqAction));
-       if(p == NULL)
-               return -ENOMEM;
+    p = kmalloc(sizeof(IrqAction));
+    if(p == NULL)
+        return -ENOMEM;
 
 
-       p->dev_name             = devname;
-       p->dev_id               = dev_id;
-       p->handler              = handler;
-       p->next                 = NULL;
-       if(irq_desc[irq].action != NULL)
-       {
-               p->next = irq_desc[irq].action;
-               //printk("p->next:%x\n", p->next);
-       }
-       irq_desc[irq].action = p;
-       //printk("irq: %d action:%x\n", irq, p);
-       return 0;
+    p->dev_name        = devname;
+    p->dev_id        = dev_id;
+    p->handler        = handler;
+    p->next            = NULL;
+    if(irq_desc[irq].action != NULL)
+    {
+        p->next    = irq_desc[irq].action;
+        //printk("p->next:%x\n", p->next);
+    }
+    irq_desc[irq].action = p;
+    //printk("irq: %d action:%x\n", irq, p);
+    return 0;
 }
index aa4345436b9e48996c9a87baa807ce1b3f9a5b62..9ab61384fee3885fdd718a71c750d34749c45c60 100644 (file)
@@ -1,27 +1,27 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        printk.c
+ *   File Name: printk.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0 Wed Jul 30 14:25:23 2008
+ *     Version:    1.0 Wed Jul 30 14:25:23 2008
  *     Version: 1.1 Tue Feb 10 22:40:25 2009
- *     Version:        2.0 Sun Mar 08 10:52:51 2009
- *     Version:        3.0 Sat Jul 18 23:06:27 2009
+ *     Version:    2.0 Sun Mar 08 10:52:51 2009
+ *     Version:    3.0 Sat Jul 18 23:06:27 2009
  * 
  *--------------------------------------------------------------------------
  */
 
 char pkbuf[1024];
-extern void    printString(const char *buf, unsigned char color);
+extern void     printString(const char *buf, unsigned char color);
 int printk(const char *fmtstr, ...)
 {
-       char *args = (char*)(((char*)&fmtstr)+4);
-       vsprintf(pkbuf, fmtstr, args);
-       printString(pkbuf,0x2);
-       return 0;
+    char *args = (char*)(((char*)&fmtstr)+4);
+    vsprintf(pkbuf, fmtstr, args);
+    printString(pkbuf,0x2);
+    return 0;
 }
 
index 78ccf8c54b4bb9f5763e0b45c38def2a8517b42c..e3b0738af80d8d39f1237a1cd41da122e67fc757 100644 (file)
@@ -8,5 +8,5 @@
  */
 #include "processor.h"
 
-Desc   idt[NIDT];
-Desc   gdt[NGDT];
+Desc    idt[NIDT];
+Desc    gdt[NGDT];
index 4d1c230eb12971231b19393ffa0bf304ae9b9e2a..4172ecc4813191a6eee597b3970b8df04d9d10f4 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        sched.c
+ *   File Name: sched.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Tue Feb 10 11:53:21 2009
  * Last Update: Tue Feb 10 11:53:21 2009
  * 
 
 
 
-pTask          current;
-Task           RootTsk __attribute__((__aligned__(PAGE_SIZE)));
+pTask        current;
+Task        RootTsk __attribute__((__aligned__(PAGE_SIZE)));
 
 task_struct* task[TASK_CNT];
 
 #define root_task task[0]
 #define first_task task[0]
 
-pid_t  get_next_pid()
+pid_t    get_next_pid()
 {
-       static pid_t    g_pid = ROOT_TSK_PID;
+    static pid_t    g_pid = ROOT_TSK_PID;
 
-       return g_pid++;
+    return g_pid++;
 }
 
-inline void    load_cr3(pTask  tsk)
+inline    void    load_cr3(pTask    tsk)
 {
-       //printk("tsk %08x cr3: %08x\n",tsk, tsk->cr3);
-       asm("movl %%eax,%%cr3;"::"a"(tsk->cr3));
-       //int j=10000; while(j--);
+    //printk("tsk %08x cr3: %08x\n",tsk, tsk->cr3);
+    asm("movl %%eax,%%cr3;"::"a"(tsk->cr3));
+    //int j=10000; while(j--);
 }
 
-void   init_tsk_cr3(pTask tsk)
+void    init_tsk_cr3(pTask tsk)
 {
-       tsk->cr3 = pa2va(get_phys_pages(1));
+    tsk->cr3 = pa2va(get_phys_pages(1));
 
-       if(tsk->cr3 == NULL)
-               panic("failed init tsk cr3");
+    if(tsk->cr3 == NULL)
+        panic("failed init tsk cr3");
 
-       memset(tsk->cr3, 0, PAGE_SIZE);
-       memcpy((void *)tsk->cr3, (void*)system.page_dir, PAGE_SIZE);
-       tsk->cr3 = (void *)va2pa(tsk->cr3);
+    memset(tsk->cr3, 0, PAGE_SIZE);
+    memcpy((void *)tsk->cr3, (void*)system.page_dir, PAGE_SIZE);
+    tsk->cr3 = (void *)va2pa(tsk->cr3);
 }
 
-void   init_root_tsk()
+void    init_root_tsk()
 {
-       int i;
+    int i;
 
-       root_task->pid  = get_next_pid();
-       root_task->ppid = 0;
+    root_task->pid    = get_next_pid();
+    root_task->ppid    = 0;
 
-       for(i=0; i<NR_OPENS; i++)
-               root_task->fps[i] = 0;
+    for(i=0; i<NR_OPENS; i++)
+        root_task->fps[i] = 0;
 
-       /* 这个时候还没有进程开始 */
-       root_task->esp0 = tss.esp0;
+    /* 这个时候还没有进程开始 */
+    root_task->esp0    = tss.esp0;
 
-       init_tsk_cr3(root_task);
-       load_cr3(root_task);
+    init_tsk_cr3(root_task);
+    load_cr3(root_task);
 
-       current = root_task;
+    current = root_task;
 /*
-       // 栈
-       void *stack = kmalloc(PAGE_SIZE);
-       if(stack == NULL)
-               panic("stack");
-       stack = va2pa(stack);
+    // 栈
+    void *stack = kmalloc(PAGE_SIZE);
+    if(stack == NULL)
+        panic("stack");
+    stack = va2pa(stack);
 
-       printk("Stack : %08x\n", stack);
+    printk("Stack : %08x\n", stack);
 
-       u32 *pde = pa2va(current->cr3);
-       u32 *pte = (u32 *)kmalloc(PAGE_SIZE);
-       if(pte == NULL)
-               panic("root task stack pte");
-       pte[1023] = stack + 7;
-       printk("pte: %08x\n", pte);
-       pde[(KRNLADDR>>22)-1] = va2pa(pte) + 7;
+    u32 *pde = pa2va(current->cr3);
+    u32 *pte = (u32 *)kmalloc(PAGE_SIZE);
+    if(pte == NULL)
+        panic("root task stack pte");
+    pte[1023] = stack + 7;
+    printk("pte: %08x\n", pte);
+    pde[(KRNLADDR>>22)-1] = va2pa(pte) + 7;
 
 
-       printk("CR3:%08x\n", current->cr3);
-       asm("movl %%eax,%%cr3;"::"a"(current->cr3));
+    printk("CR3:%08x\n", current->cr3);
+    asm("movl %%eax,%%cr3;"::"a"(current->cr3));
 */
 }
 
-void   setup_tasks()
+void    setup_tasks()
 {
 
-       /* 初始化第一个特殊的进程 */
-       init_root_tsk();
+    /* 初始化第一个特殊的进程 */
+    init_root_tsk();
 #if 0
-       add_task(test_taskB);
-       add_task(test_taskA);
+    add_task(test_taskB);
+    add_task(test_taskA);
 #endif
 }
 
@@ -114,7 +114,7 @@ task_struct *get_unused_task_pcb()
     }
 }
 
-inline pTask get_next_tsk()
+inline    pTask get_next_tsk()
 {
     static unsigned int inx = 0;
     unsigned int i = 0;
@@ -137,74 +137,74 @@ inline    pTask get_next_tsk()
 }
 
 #if 1
-inline void set_esp0(pTask tsk)
+inline    void set_esp0(pTask tsk)
 {
-       tss.esp0 = tsk->esp0;
+    tss.esp0 = tsk->esp0;
 }
-inline void    switch_to()
+inline void    switch_to()
 {
 
-       //printk("current:%08x esp0:%08x\n", current, current->esp0);
-       load_cr3(current);
-       set_esp0(current);
+    //printk("current:%08x esp0:%08x\n", current, current->esp0);
+    load_cr3(current);
+    set_esp0(current);
 }
 inline void context_switch(pTask prev, pTask next)
 {
 #if 1
-       //pTask last;
-       unsigned long eax, ebx, ecx, edx, esi, edi;
-       //asm("xchg %bx, %bx");
-       asm volatile(
-       "pushfl;"
-       "pushl  %%ebp;"
-       "movl   %%esp,%[prev_esp];"
-       "movl   %[next_esp],%%esp;"
-       "movl   $1f,%[prev_eip];"
-       "pushl  %[next_eip];"
-       "jmp    switch_to;"
-       "1:"
-       "popl   %%ebp;"
-       "popfl;"
-       :       [prev_esp] "=m" (prev->esp),
-               [prev_eip] "=m" (prev->eip),
-               "=a" (prev),    "=b" (ebx),     "=c" (ecx),
-               "=d" (edx),     "=S" (esi),     "=D" (edi)
-       :       [next_esp] "m"  (next->esp),
-               [next_eip] "m"  (next->eip),
-               [prev]  "a" (prev),
-               [next]  "d" (next)
-       :       "memory"
-       );
+    //pTask    last;
+    unsigned long eax, ebx, ecx, edx, esi, edi;
+    //asm("xchg %bx, %bx");
+    asm volatile(
+    "pushfl;"
+    "pushl    %%ebp;"
+    "movl    %%esp,%[prev_esp];"
+    "movl    %[next_esp],%%esp;"
+    "movl    $1f,%[prev_eip];"
+    "pushl    %[next_eip];"
+    "jmp    switch_to;"
+    "1:"
+    "popl    %%ebp;"
+    "popfl;"
+    :    [prev_esp] "=m"    (prev->esp),
+        [prev_eip] "=m"    (prev->eip),
+        "=a" (prev),    "=b" (ebx),    "=c" (ecx),
+        "=d" (edx),    "=S" (esi),    "=D" (edi)
+    :    [next_esp] "m"    (next->esp),
+        [next_eip] "m"    (next->eip),
+        [prev]    "a" (prev),
+        [next]    "d" (next)
+    :    "memory"
+    );
 #endif
 }
 
-unsigned long  schedule()
+unsigned long    schedule()
 {
-       pTask   tsk, prev, next;
-
-       cli();  // For Safe.
-       tsk = current;
-       do
-       {
-               tsk = get_next_tsk(tsk);
-       }while(tsk->state == TASK_EXITING); /* 简单实现 */
-
-       if(current == tsk)
-               return;
-
-       //tsk = current;
-       //printk("tsk:%08x\t", tsk);
-       //current = tsk;
-       prev = current;
-       current = next = tsk;
-       context_switch(prev, next);
+    pTask    tsk, prev, next;
+
+    cli();    // For Safe.
+    tsk = current;
+    do
+    {
+        tsk = get_next_tsk(tsk);
+    }while(tsk->state == TASK_EXITING); /* 简单实现 */
+
+    if(current == tsk)
+        return;
+
+    //tsk = current;
+    //printk("tsk:%08x\t", tsk);
+    //current = tsk;
+    prev = current;
+    current = next = tsk;
+    context_switch(prev, next);
 }
 #endif
 
 
 inline void wake_up(pWaitQueue wq)
 {
-       
+    
 }
 
 inline void sleep_on(pWaitQueue wq)
index 25988f98d4a180f8e61d80cd891de3b47ac30d80..62bced03bd8a2378872408c68d10b4a89ca44026 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        syscall.S
+ *   File Name: syscall.S
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Tue Feb 10 13:20:33 2009
  *     Version: 2.0
  * Last Update: Wed Feb 10 23:36:34 2010
  *--------------------------------------------------------------------------
  */
 
-#define        ASM
-#include<system.h>
-#include<syscall.h>
+#define ASM
+#include <system.h>
+#include <syscall.h>
 
-#define        TASK_SIZE 4096*2
+#define TASK_SIZE 4096*2
 .code32
 #if 0
 .extern sysc_handler_table
 #endif
 .text
-.global        syscall_entry
-.global        ret_from_fork
+.global    syscall_entry
+.global    ret_from_fork
 
 /*
- *     0x40 -- %ss
- *     0x3C -- %esp
- *     0x38 -- %eflags
- *     0x34 -- %cs
- *     0x30 -- %eip
- *     0x2C -- sysc_nr
- *     0x28 -- %gs
- *     0x24 -- %fs
- *     0x20 -- %es
- *     0x1C -- %ds
- *     0x18 -- %eax
- *     0x14 -- %ebp
- *     0x10 -- %esi
- *     0x0C -- %edi
- *     0x08 -- %ecx
- *     0x04 -- %edx
- *     0x00 -- %ebx
+ *    0x40 -- %ss
+ *    0x3C -- %esp
+ *    0x38 -- %eflags
+ *    0x34 -- %cs
+ *    0x30 -- %eip
+ *    0x2C -- sysc_nr
+ *    0x28 -- %gs
+ *    0x24 -- %fs
+ *    0x20 -- %es
+ *    0x1C -- %ds
+ *    0x18 -- %eax
+ *    0x14 -- %ebp
+ *    0x10 -- %esi
+ *    0x0C -- %edi
+ *    0x08 -- %ecx
+ *    0x04 -- %edx
+ *    0x00 -- %ebx
  */
 #if 1
 syscall_entry:
-       /* 此时%esp存的是current的地址(&current) */
-       movl    (%esp),%esp             /* 获得current的值 */
-       addl    $TASK_SIZE, %esp        /* 指向PCB的顶部 */
-
-       pushl   %ds                     /* %ss */
-       pushl   %ebp                    /* %esp */
-       pushfl                          /* %eflags */
-       pushl   $SELECTOR_USER_CS       /* %cs */
-       pushl   %gs:(,%ebp)             /* %eip */
-       pushl   %eax                    /* sysc_nr */
-       SAVE_REGS
-
-       pushl   %eax
-       movw    %ss,%ax
-       movw    %ax, %ds
-       movw    %ax, %es
-       movw    %ax, %gs
-       movw    %ax, %fs
-       popl    %eax
-
-       cmpl    $SYSC_NUM, %eax
-       jae     bad_syscnr
-
-       call    *sysc_handler_table(,%eax,4)
+    /* 此时%esp存的是current的地址(&current) */
+    movl    (%esp),%esp        /* 获得current的值 */
+    addl    $TASK_SIZE, %esp    /* 指向PCB的顶部 */
+
+    pushl    %ds            /* %ss */
+    pushl    %ebp            /* %esp */
+    pushfl                /* %eflags */
+    pushl    $SELECTOR_USER_CS    /* %cs */
+    pushl    %gs:(,%ebp)        /* %eip */
+    pushl    %eax            /* sysc_nr */
+    SAVE_REGS
+
+    pushl    %eax
+    movw    %ss,%ax
+    movw    %ax, %ds
+    movw    %ax, %es
+    movw    %ax, %gs
+    movw    %ax, %fs
+    popl    %eax
+
+    cmpl    $SYSC_NUM, %eax
+    jae    bad_syscnr
+
+    call    *sysc_handler_table(,%eax,4)
 
 ret_from_bad_syscnr:
 
 
-       movl    %eax, 0x18(%esp)        /* return value */
+    movl    %eax, 0x18(%esp)    /* return value */
 
-       /*
-        * fork 后的新进程的返回值已经在栈上被设定为0了.
-        * ret_from_fork 就是新进程被换入执行的入口地址.
-        */
+    /*
+     * fork 后的新进程的返回值已经在栈上被设定为0了.
+     * ret_from_fork 就是新进程被换入执行的入口地址.
+     */
 ret_from_fork:
 
-       RESTORE_REGS
-       
-       movl    0x04(%esp), %edx        /* sysexit 参数 %eip */
-       movl    0x10(%esp), %ecx        /* sysexit 参数 %esp */
+    RESTORE_REGS
+    
+    movl    0x04(%esp), %edx    /* sysexit 参数 %eip */
+    movl    0x10(%esp), %ecx    /* sysexit 参数 %esp */
 
-       #xchg   %bx, %bx
-       sti             /* sysenter会自动清除IF.貌似sysexit不会自动置位 */
-       sysexit
+    #xchg    %bx, %bx
+    sti        /* sysenter会自动清除IF.貌似sysexit不会自动置位 */
+    sysexit
 
 bad_syscnr:
-       call    sysc_bad_syscnr
-       jmp     ret_from_bad_syscnr
+    call    sysc_bad_syscnr
+    jmp    ret_from_bad_syscnr
 #endif
 
 #if 0
 syscall_entry:
-       /* 此时%esp存的是current的地址(&current) */
-       movl    (%esp),%esp             /* 获得current的值 */
-       addl    $TASK_SIZE, %esp        /* 指向PCB的顶部 */
-
-       pushl   %ds                     /* %ss */
-       pushl   %ebp                    /* %esp */
-       pushfl                          /* %eflags */
-       pushl   $SELECTOR_USER_CS       /* %cs */
-       pushl   %gs:(,%ebp)             /* %eip */
-       pushl   %eax                    /* sysc_nr */
-       SAVE_REGS
-
-       pushl   %eax
-       movw    %ss,%ax
-       movw    %ax, %ds
-       movw    %ax, %es
-       movw    %ax, %gs
-       movw    %ax, %fs
-       popl    %eax
-
-       call    *sysc_handler_table(,%eax,4)
-
-       movl    %eax, 0x18(%esp)        /* return value */
-
-       RESTORE_REGS
-       
-       movl    0x04(%esp), %edx        /* sysexit 参数 %eip */
-       movl    0x10(%esp), %ecx        /* sysexit 参数 %esp */
-
-       sti             /* sysenter会自动清除IF.貌似sysexit不会自动置位 */
-       sysexit
+    /* 此时%esp存的是current的地址(&current) */
+    movl    (%esp),%esp        /* 获得current的值 */
+    addl    $TASK_SIZE, %esp    /* 指向PCB的顶部 */
+
+    pushl    %ds            /* %ss */
+    pushl    %ebp            /* %esp */
+    pushfl                /* %eflags */
+    pushl    $SELECTOR_USER_CS    /* %cs */
+    pushl    %gs:(,%ebp)        /* %eip */
+    pushl    %eax            /* sysc_nr */
+    SAVE_REGS
+
+    pushl    %eax
+    movw    %ss,%ax
+    movw    %ax, %ds
+    movw    %ax, %es
+    movw    %ax, %gs
+    movw    %ax, %fs
+    popl    %eax
+
+    call    *sysc_handler_table(,%eax,4)
+
+    movl    %eax, 0x18(%esp)    /* return value */
+
+    RESTORE_REGS
+    
+    movl    0x04(%esp), %edx    /* sysexit 参数 %eip */
+    movl    0x10(%esp), %ecx    /* sysexit 参数 %esp */
+
+    sti        /* sysenter会自动清除IF.貌似sysexit不会自动置位 */
+    sysexit
 #endif
 
 #if 0
 .global sysc_handler_table
 .extern sysc_write
-.extern        sysc_read_kbd
-.extern        sysc_reboot
-.extern        sysc_fork
+.extern    sysc_read_kbd
+.extern    sysc_reboot
+.extern    sysc_fork
 sysc_handler_table:
-.long  sysc_write
-.long  sysc_read_kbd
-.long  sysc_reboot
-.long  sysc_fork
+.long    sysc_write
+.long    sysc_read_kbd
+.long    sysc_reboot
+.long    sysc_fork
 #endif
index f6585979fe6e78739c40d953775ec9824a4804c1..6288742b819b93bc92b7ec8603b594eead0ddf5e 100644 (file)
@@ -1,13 +1,13 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        syscall.c
+ *   File Name: syscall.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Fri Jan  2 19:49:20 2009
  * Last Update: Fri Jan  2 19:49:20 2009
  * 
@@ -23,25 +23,25 @@ extern void init_sysc_handler_table();
 
 unsigned long sysc_handler_table[SYSC_NUM];
 
-void   setup_sysc()
+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();
+    init_sysc_handler_table();
 
 }
 
 
-int    sysc_none()
+int    sysc_none()
 {
-       int sysc_nr;
-       asm("":"=a"(sysc_nr));
-       printk("unsupport syscall:%d\n", sysc_nr);
+    int sysc_nr;
+    asm("":"=a"(sysc_nr));
+    printk("unsupport syscall:%d\n", sysc_nr);
 
-       return 0;
+    return 0;
 }
 
 int sysc_pause()
@@ -50,38 +50,38 @@ int sysc_pause()
     return 0;
 }
 
-void   init_sysc_handler_table()
+void    init_sysc_handler_table()
 {
-       int i;
-
-       for(i=0; i<SYSC_NUM; i++)
-               sysc_handler_table[i] = (unsigned long) sysc_none;
-
-#define        _sysc_(nr, sym)                                                     \
-       do                                                                              \
-       {                                                                               \
-               extern int sym ();                                              \
-               sysc_handler_table[nr] = (unsigned long) sym;   \
-       }while(0);
-
-       /* 有没有一种宏定义可以把大写直接转成小写? */
-       _sysc_(SYSC_WRITE,          sysc_write);
-       _sysc_(SYSC_READ_KBD,   sysc_read_kbd);
-       _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_TEST,           sysc_test);
+    int i;
+
+    for(i=0; i<SYSC_NUM; i++)
+        sysc_handler_table[i] = (unsigned long) sysc_none;
+
+#define _sysc_(nr, sym)                                    \
+    do                                                    \
+    {                                                    \
+        extern int sym ();                                \
+        sysc_handler_table[nr] = (unsigned long) sym;    \
+    }while(0);
+
+    /* 有没有一种宏定义可以把大写直接转成小写? */
+    _sysc_(SYSC_WRITE,        sysc_write);
+    _sysc_(SYSC_READ_KBD,    sysc_read_kbd);
+    _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_TEST,        sysc_test);
 }
-int    sysc_bad_syscnr()
+int    sysc_bad_syscnr()
 {
-       int sysc_nr;
-       asm("":"=a"(sysc_nr));
-       printk("bad syscall nr:%d\n", sysc_nr);
+    int sysc_nr;
+    asm("":"=a"(sysc_nr));
+    printk("bad syscall nr:%d\n", sysc_nr);
 
-       return 0;
+    return 0;
 }
index 5de7d2a45515b159900ad90d03f1d2be9add41d8..726230cab96952620541d2568e4fd6d797ce05ba 100644 (file)
@@ -1,41 +1,41 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        system.c
+ *   File Name: system.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Jan 24 13:57:46 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Jan 24 13:57:46 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
 
-#include<syscall.h>
+#include <syscall.h>
 
-int    sysc_reboot(int mode)
+int    sysc_reboot(int mode)
 {
 
-       void do_reboot();
-       void do_poweroff();
+    void do_reboot();
+    void do_poweroff();
 
-       switch(mode)
-       {
-       case 0:
-               do_reboot();
-               break;
-       case 1:
-               do_poweroff();
-               break;
-       }
+    switch(mode)
+    {
+    case 0:
+        do_reboot();
+        break;
+    case 1:
+        do_poweroff();
+        break;
+    }
 
-       return 0;
+    return 0;
 }
 
 
 inline void panic(char *msg)
 {
-       printk("PANIC:\"%s\" file:%s function:%s line:%d\n",
-               msg, __FILE__, __FUNCTION__, __LINE__);
-       while(1);
+    printk("PANIC:\"%s\" file:%s function:%s line:%d\n",
+        msg, __FILE__, __FUNCTION__, __LINE__);
+    while(1);
 }
index 2512968877e67fcf688611c1ecc193659a142093..060389978a2ffde20e1a7ecb14e53e1406f09e09 100644 (file)
@@ -1,39 +1,39 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        test.c
+ *   File Name: test.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 17:47:43 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 17:47:43 2010
  * 
- * Description:        sysc_test
+ * Description: sysc_test
  * 
  *--------------------------------------------------------------------------
  */
-#include<syscall.h>
-#include<printk.h>
-#include<sched.h>
+#include <syscall.h>
+#include <printk.h>
+#include <sched.h>
 
 void dump_fd()
 {
-       int i;
-       for(i=0; i<NR_OPENS; i++)
-       {
-               pFile pf = current->fps[i];
-               if(pf == NULL) continue;
-               printk("fd[%d]: %08x\n", i, pf);
+    int i;
+    for(i=0; i<NR_OPENS; i++)
+    {
+        pFile pf = current->fps[i];
+        if(pf == NULL) continue;
+        printk("fd[%d]: %08x\n", i, pf);
 
 
-               pInode inode = pf->inode;
-               printk("file_desc ino_nr: %04d inode:%08x\n",
-                       pf->ino_nr, inode);
+        pInode inode = pf->inode;
+        printk("file_desc ino_nr: %04d inode:%08x\n",
+            pf->ino_nr, inode);
 
-               printk("inode: size: %d\n", inode->i_size);
-       }
+        printk("inode: size: %d\n", inode->i_size);
+    }
 }
 
 int sysc_test()
 {
-       dump_fd();
+    dump_fd();
 
-       return 0;
+    return 0;
 }
index f24cf5df8070482a62f566e87b93ab5ce7a19353..4aab2aab8be90e650196419c910231864c900d45 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        test_task.c
+ *   File Name: test_task.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb  2 20:18:05 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb  2 20:18:05 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
 
-#include<stdio.h>
-#include<sched.h>
-#include<assert.h>
-#include<system.h>
-pTask  tTasks[NR_TASKS];
+#include <stdio.h>
+#include <sched.h>
+#include <assert.h>
+#include <system.h>
+pTask    tTasks[NR_TASKS];
 
 #if 0
-void   SetuptTasks()
+void    SetuptTasks()
 {
-       int i;
+    int i;
 
 
-       for(i=0; i<NR_TASKS; i++)
-       {
-               tTasks[i] = NULL;
-       }
+    for(i=0; i<NR_TASKS; i++)
+    {
+        tTasks[i] = NULL;
+    }
 
-       tTasks[0] = &RootTsk;
-       current = tTasks[0];
+    tTasks[0] = &RootTsk;
+    current    = tTasks[0];
 }
 #endif
-void   add_task(void *fun)
+void    add_task(void *fun)
 {
 #if 0
-       assert(fun != NULL);
-       pTask   tsk = NULL;
-       tsk = kmalloc(sizeof(Task));
-       if(tsk == NULL)
-               panic("shit happens");
-
-       printk("tsk:%08x\n", tsk);
-
-       tsk->pid        = get_next_pid();
-       tsk->ppid       = 0;
-       init_tsk_cr3(tsk);
-
-       pPtRegs r;
-       r = &tsk->regs;
-       memset((void *)r, 0, sizeof(PtRegs));
-       r->ds = r->es = r->fs = r->gs = SELECTOR_USER_DS;
-       r->eip          = (unsigned long)fun;
-       r->cs           = SELECTOR_USER_CS;
-       r->eflags       = 0x282;
-       r->esp          = (unsigned long)tsk;
-       r->ss           = SELECTOR_USER_SS;
-
-       add_tsk2list(tsk);
+    assert(fun != NULL);
+    pTask    tsk = NULL;
+    tsk = kmalloc(sizeof(Task));
+    if(tsk == NULL)
+        panic("shit happens");
+
+    printk("tsk:%08x\n", tsk);
+
+    tsk->pid    = get_next_pid();
+    tsk->ppid    = 0;
+    init_tsk_cr3(tsk);
+
+    pPtRegs    r;
+    r = &tsk->regs;
+    memset((void *)r, 0, sizeof(PtRegs));
+    r->ds = r->es = r->fs = r->gs = SELECTOR_USER_DS;
+    r->eip        = (unsigned long)fun;
+    r->cs        = SELECTOR_USER_CS;
+    r->eflags    = 0x282;
+    r->esp        = (unsigned long)tsk;
+    r->ss        = SELECTOR_USER_SS;
+
+    add_tsk2list(tsk);
 #endif
 }
 
 #if 0
-void   add_task(void *fun)
+void    add_task(void *fun)
 {
-       assert(fun != NULL);
-       pTask   tsk = NULL;
-       int i=0;
-       for(i=0; i<NR_TASKS; i++)
-       {
-               if(tTasks[i] == NULL)
-               {
-                       tsk = kmalloc(sizeof(Task));
-                       if(tsk == NULL)
-                               panic("shit happens");
-                       //tTasks[i] = tsk;
-                       break;
-               }
-       }
-
-       if(i == NR_TASKS)
-               panic("tasks full");
-
-       pPtRegs r;
-       r = &tsk->regs;//(pPtRegs)(TASK_SIZE + (unsigned long)tsk);
-       //printk("Add Tsk: tsk:%08x r:%08x ", tsk, r);
-       //r--;
-       //printk("r:%08x sizeof regs:%x ", r, sizeof(PtRegs));
-
-       memset((void *)r, 0, sizeof(PtRegs));
-       //printk("USER CS: %x\n", SELECTOR_USER_CS);
-       //printk("USER DS: %x\n", SELECTOR_USER_DS);
-       r->ds = r->es = r->fs = r->gs = SELECTOR_USER_DS;
-       r->eip          = (unsigned long)fun;
-       r->cs           = SELECTOR_USER_CS;
-       r->eflags       = 0x282;
-       r->esp          = (unsigned long)tsk;
-       r->ss           = SELECTOR_USER_SS;
-
-
-       tTasks[i] = tsk;
+    assert(fun != NULL);
+    pTask    tsk = NULL;
+    int i=0;
+    for(i=0; i<NR_TASKS; i++)
+    {
+        if(tTasks[i] == NULL)
+        {
+            tsk = kmalloc(sizeof(Task));
+            if(tsk == NULL)
+                panic("shit happens");
+            //tTasks[i] = tsk;
+            break;
+        }
+    }
+
+    if(i == NR_TASKS)
+        panic("tasks full");
+
+    pPtRegs    r;
+    r = &tsk->regs;//(pPtRegs)(TASK_SIZE + (unsigned long)tsk);
+    //printk("Add Tsk: tsk:%08x r:%08x ", tsk, r);
+    //r--;
+    //printk("r:%08x sizeof regs:%x ", r, sizeof(PtRegs));
+
+    memset((void *)r, 0, sizeof(PtRegs));
+    //printk("USER CS: %x\n", SELECTOR_USER_CS);
+    //printk("USER DS: %x\n", SELECTOR_USER_DS);
+    r->ds = r->es = r->fs = r->gs = SELECTOR_USER_DS;
+    r->eip        = (unsigned long)fun;
+    r->cs        = SELECTOR_USER_CS;
+    r->eflags    = 0x282;
+    r->esp        = (unsigned long)tsk;
+    r->ss        = SELECTOR_USER_SS;
+
+
+    tTasks[i] = tsk;
 }
 #endif
 
-void   delay(unsigned int d)
+void    delay(unsigned int d)
 {
-       unsigned int i;
-       int n = 10000;
-       for(i=0; i<d*n; i++)
-                       ;
+    unsigned int i;
+    int n = 10000;
+    for(i=0; i<d*n; i++)
+            ;
 }
 
 #if 0
-void   test_taskA()
+void    test_taskA()
 {
-       while(1)
-       {
-               printf("A");
-               delay(400);
-       }
+    while(1)
+    {
+        printf("A");
+        delay(400);
+    }
 }
 
-void   test_taskB()
+void    test_taskB()
 {
-       while(1)
-       {
-               printf("B");
-               delay(500);
-       }
+    while(1)
+    {
+        printf("B");
+        delay(500);
+    }
 }
 #endif
index e9bda8418f6d11f56e3a3568c661d406cd2fe59e..5ad1fb2f173850f0f6be8b2fa2c8c17b494b8f2b 100644 (file)
@@ -1,27 +1,27 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        wait.c
+ *   File Name: wait.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Mon Feb 22 20:45:22 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Mon Feb 22 20:45:22 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<wait.h>
+#include <wait.h>
 
 void init_wait_queue(pWaitQueueHead wqh)
 {
-       INIT_LIST_HEAD(&wqh->wait);
+    INIT_LIST_HEAD(&wqh->wait);
 }
 
 void add_wait_queue(pWaitQueueHead wqh, pWaitQueue wq)
 {
-       list_add_tail(wq, &wqh->wait);
+    list_add_tail(wq, &wqh->wait);
 }
 
 void del_wait_queue(pWaitQueueHead wqh, pWaitQueue old)
 {
-       //list_del_init();
+    //list_del_init();
 }
index ec3309a0d7c19a39b09262e5c66b4f4af2ec965c..f44057f9ba5fd3824b43d1a625e4535886253c80 100644 (file)
@@ -1,19 +1,19 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        assert.c
+ *   File Name: assert.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jan 23 15:25:29 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jan 23 15:25:29 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
 void assert_fail(char *exp, char *file, unsigned int line, char *func)
 {
-       printk("%s:%d: %s: Assertion \'%s\' failed.\n",
-               file, line, func, exp);
+    printk("%s:%d: %s: Assertion \'%s\' failed.\n",
+        file, line, func, exp);
 
-       while(1);
+    while(1);
 }
index 9d0a4e41951db6cbaec108b41e6f3a0f385c1eaf..01b46b419231e995b2723a0b47a090255eaa2e97 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        errno.c
+ *   File Name: errno.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 01:49:49 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 01:49:49 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
index b912564624f04a502817c729bff4d6bef655a43e..208352c59054f72d8c2f207c446acb42800e293b 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        exec.c
+ *   File Name: exec.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 20:47:11 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 20:47:11 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<syscall.h>
+#include <syscall.h>
 
 int execv(const char *path, char *const argv[])
 {
-       return syscall2(SYSC_EXEC, path, argv);
+    return syscall2(SYSC_EXEC, path, argv);
 }
index 8749935c94a92b79e2fa6699c7255d7a5df81bb2..6931fa231734132481d41cd5ae864a43de177125 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        exit.c
+ *   File Name: exit.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Thu Mar  4 10:11:57 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Thu Mar  4 10:11:57 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<syscall.h>
-int    exit(int status)
+#include <syscall.h>
+int    exit(int status)
 {
-       syscall1(SYSC_EXIT, status);
+    syscall1(SYSC_EXIT, status);
 }
index 36d9cd06f6bb5e827b36c256d8d1ea752fcd6959..6b2696fb579aeb619c8a21acb3872004b55a59db 100644 (file)
@@ -1,30 +1,30 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        fork.c
+ *   File Name: fork.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Feb  7 13:30:24 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Feb  7 13:30:24 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<types.h>
-#include<syscall.h>
-#include<stdio.h>
-pid_t  fork()
+#include <types.h>
+#include <syscall.h>
+#include <stdio.h>
+pid_t    fork()
 {
 #if 0
-       pid_t pid;
-       //asm("xchg %bx, %bx;");
-       //syscall0(SYSC_FORK);
-       //while(1);
-       //asm("xchg %bx, %bx;");
-       //asm("":"=a"(pid));
-       //printf("pid:%x\n", pid);
-       pid = syscall0(SYSC_FORK);
-       return pid;
+    pid_t pid;
+    //asm("xchg %bx, %bx;");
+    //syscall0(SYSC_FORK);
+    //while(1);
+    //asm("xchg %bx, %bx;");
+    //asm("":"=a"(pid));
+    //printf("pid:%x\n", pid);
+    pid = syscall0(SYSC_FORK);
+    return pid;
 #endif
-       return (pid_t) syscall0(SYSC_FORK);
+    return (pid_t) syscall0(SYSC_FORK);
 }
index 9364447693377f1ad8a038e0f95dc7d4dca7d489..0a3a896d5458850aa4396c7d53eb045439b69864 100644 (file)
@@ -1,53 +1,53 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        keyboard.h
+ *   File Name: keyboard.h
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Thu Jul 16 18:39:57 2009
  * Last Update: Thu Jul 16 18:39:57 2009
  * 
  *--------------------------------------------------------------------------
  */
-#include<system.h>
-#include<syscall.h>
-#include<stdio.h>
-#include<io.h>
-#define        EXT_KEY         0x80000000      /* None Print Key */
-#define        L_SHIFT_DOWN    0x00000100
-#define        R_SHIFT_DOWN    0x00000200
-#define        L_CTRL_DOWN     0x00000400
-#define        R_CTRL_DOWN     0x00000800
-#define        L_ALT_DOWN      0x00001000
-#define        R_ALT_DOWN      0x00002000
-#define        L_SHIFT_UP      (~L_SHIFT_DOWN)
-#define        R_SHIFT_UP      (~R_SHIFT_DOWN)
-#define        L_CTRL_UP       (~L_CTRL_DOWN)
-#define        R_CTRL_UP       (~R_CTRL_DOWN)
-#define        L_ALT_UP        (~L_ALT_DOWN)
-#define        R_ALT_UP        (~R_ALT_DOWN)
-#define        SET_L_SHIFT_DOWN(key)   (key |= L_SHIFT_DOWN)
-#define        SET_R_SHIFT_DOWN(key)   (key |= R_SHIFT_DOWN)
-#define        SET_L_CTRL_DOWN(key)    (key |= L_CTRL_DOWN)
-#define        SET_R_CTRL_DOWN(key)    (key |= R_CTRL_DOWN)
-#define        SET_L_ALT_DOWN(key)     (key |= L_ALT_DOWN)
-#define        SET_R_ALT_DOWN(key)     (key |= R_ALT_DOWN)
-#define        SET_L_SHIFT_UP(key)     (key &= L_SHIFT_UP)
-#define        SET_R_SHIFT_UP(key)     (key &= R_SHIFT_UP)
-#define        SET_L_CTRL_UP(key)      (key &= L_CTRL_UP)
-#define        SET_R_CTRL_UP(key)      (key &= R_CTRL_UP)
-#define        SET_L_ALT_UP(key)       (key &= L_ALT_UP)
-#define        SET_R_ALT_UP(key)       (key &= R_ALT_UP)
-#define        IS_L_SHIFT_DOWN(key)    (key & L_SHIFT_DOWN)
-#define        IS_R_SHIFT_DOWN(key)    (key & R_SHIFT_DOWN)
-#define        IS_L_CTRL_DOWN(key)     (key & L_CTRL_DOWN)
-#define        IS_R_CTRL_DOWN(key)     (key & R_CTRL_DOWN)
-#define        IS_L_ALT_DOWN(key)      (key & L_ALT_DOWN)
-#define        IS_R_ALT_DOWN(key)      (key & R_ALT_DOWN)
+#include <system.h>
+#include <syscall.h>
+#include <stdio.h>
+#include <io.h>
+#define EXT_KEY        0x80000000    /* None Print Key */
+#define L_SHIFT_DOWN    0x00000100
+#define R_SHIFT_DOWN    0x00000200
+#define L_CTRL_DOWN    0x00000400
+#define R_CTRL_DOWN    0x00000800
+#define L_ALT_DOWN    0x00001000
+#define R_ALT_DOWN    0x00002000
+#define L_SHIFT_UP    (~L_SHIFT_DOWN)
+#define R_SHIFT_UP    (~R_SHIFT_DOWN)
+#define L_CTRL_UP    (~L_CTRL_DOWN)
+#define R_CTRL_UP    (~R_CTRL_DOWN)
+#define L_ALT_UP    (~L_ALT_DOWN)
+#define R_ALT_UP    (~R_ALT_DOWN)
+#define SET_L_SHIFT_DOWN(key)    (key |= L_SHIFT_DOWN)
+#define SET_R_SHIFT_DOWN(key)    (key |= R_SHIFT_DOWN)
+#define SET_L_CTRL_DOWN(key)    (key |= L_CTRL_DOWN)
+#define SET_R_CTRL_DOWN(key)    (key |= R_CTRL_DOWN)
+#define SET_L_ALT_DOWN(key)    (key |= L_ALT_DOWN)
+#define SET_R_ALT_DOWN(key)    (key |= R_ALT_DOWN)
+#define SET_L_SHIFT_UP(key)    (key &= L_SHIFT_UP)
+#define SET_R_SHIFT_UP(key)    (key &= R_SHIFT_UP)
+#define SET_L_CTRL_UP(key)    (key &= L_CTRL_UP)
+#define SET_R_CTRL_UP(key)    (key &= R_CTRL_UP)
+#define SET_L_ALT_UP(key)    (key &= L_ALT_UP)
+#define SET_R_ALT_UP(key)    (key &= R_ALT_UP)
+#define IS_L_SHIFT_DOWN(key)    (key & L_SHIFT_DOWN)
+#define IS_R_SHIFT_DOWN(key)    (key & R_SHIFT_DOWN)
+#define IS_L_CTRL_DOWN(key)    (key & L_CTRL_DOWN)
+#define IS_R_CTRL_DOWN(key)    (key & R_CTRL_DOWN)
+#define IS_L_ALT_DOWN(key)    (key & L_ALT_DOWN)
+#define IS_R_ALT_DOWN(key)    (key & R_ALT_DOWN)
 
 const unsigned char kbdCharTable[]={0,0,
 '1','2','3','4','5','6','7','8','9','0','-','=','\b',0,
@@ -65,116 +65,116 @@ const unsigned char kbdShiftCharTable[]={0,0,
 };
 
 /* Make Code */
-#define        MC_BACKSPACE    0x0E
-#define        MC_CTRL         0x1D
-#define        MC_L_SHIFT      0x2A
-#define        MC_R_SHIFT      0x36
-#define        MC_ALT          0x38
-#define        MC_CAPSLOCK     0x3A
-#define        MC_DELETE       0x53
-#define        BC_BACKSPACE    (0x80 | MC_BACKSPACE)
-#define        BC_CTRL         (0x80 | MC_CTRL)
-#define        BC_L_SHIFT      (0x80 | MC_L_SHIFT)
-#define        BC_R_SHIFT      (0x80 | MC_R_SHIFT)
-#define        BC_ALT          (0x80 | MC_ALT)
-#define        BC_DELETE       (0x80 | MC_DELETE)
-#define        BC_CAPSLOCK     (0x80 | MC_CAPSLOCK)
+#define MC_BACKSPACE    0x0E
+#define MC_CTRL        0x1D
+#define MC_L_SHIFT    0x2A
+#define MC_R_SHIFT    0x36
+#define MC_ALT        0x38
+#define MC_CAPSLOCK    0x3A
+#define MC_DELETE    0x53
+#define BC_BACKSPACE    (0x80 | MC_BACKSPACE)
+#define BC_CTRL        (0x80 | MC_CTRL)
+#define BC_L_SHIFT    (0x80 | MC_L_SHIFT)
+#define BC_R_SHIFT    (0x80 | MC_R_SHIFT)
+#define BC_ALT        (0x80 | MC_ALT)
+#define BC_DELETE    (0x80 | MC_DELETE)
+#define BC_CAPSLOCK    (0x80 | MC_CAPSLOCK)
 
 static unsigned char E0Flag = 0;
 
 unsigned char read_kbd()
 {
-       char    k;
-       int ret = -1;
+    char    k;
+    int ret = -1;
 
-       while(ret == -1)
-       {
-               syscall0(SYSC_READ_KBD);
-               asm("":"=a"(ret));
-       }
+    while(ret == -1)
+    {
+        syscall0(SYSC_READ_KBD);
+        asm("":"=a"(ret));
+    }
 
-       k = (unsigned char) ret;
+    k = (unsigned char) ret;
 
 
-       return k;
+    return k;
 }
 /*
  * 貌似现在CapsLock不工作了
  */
 unsigned int _parse_kbd(int ScanCode)
 {
-       //int ScanCode;
-       static unsigned int key;
-       //ScanCode = read_kbd();
-
-       if(ScanCode == 0xE0)
-       {
-               E0Flag = 1;
-               return -1;
-       }
-
-       if(ScanCode & 0x80)     // Make Or Break Code ?
-               goto    BreakCode;
-#if 0  
-       // Ctrl + Alt + Del
-       if( IS_L_CTRL_DOWN(key) && IS_L_ALT_DOWN(key))
-       {
-               if(E0Flag == 1 && ScanCode == MC_DELETE)
-               {
-                       extern  void reboot();
-                       printf("Reboot System Now ...\n");
-                       int i = 100000;
-                       while(i--);
-                       reboot();
-               }
-               if(ScanCode ==  MC_BACKSPACE)
-               {
-                       extern  void poweroff();
-                       printf("Shutdown System Now ...\n");
-                       int i = 100000;
-                       while(i--);
-                       poweroff();
-               }
-       }
+    //int ScanCode;
+    static unsigned int key;
+    //ScanCode = read_kbd();
+
+    if(ScanCode == 0xE0)
+    {
+        E0Flag = 1;
+        return -1;
+    }
+
+    if(ScanCode & 0x80)    // Make Or Break Code ?
+        goto    BreakCode;
+#if 0    
+    // Ctrl    + Alt + Del
+    if( IS_L_CTRL_DOWN(key) && IS_L_ALT_DOWN(key))
+    {
+        if(E0Flag == 1 && ScanCode == MC_DELETE)
+        {
+            extern    void reboot();
+            printf("Reboot System Now ...\n");
+            int i = 100000;
+            while(i--);
+            reboot();
+        }
+        if(ScanCode ==  MC_BACKSPACE)
+        {
+            extern    void poweroff();
+            printf("Shutdown System Now ...\n");
+            int i = 100000;
+            while(i--);
+            poweroff();
+        }
+    }
 #endif
 
-       switch(ScanCode)
-       {
-       case    MC_L_SHIFT:     SET_L_SHIFT_DOWN(key);  goto End;
-       case    MC_R_SHIFT:     SET_R_SHIFT_DOWN(key);  goto End;
+    switch(ScanCode)
+    {
+    case    MC_L_SHIFT:    SET_L_SHIFT_DOWN(key);    goto End;
+    case    MC_R_SHIFT:    SET_R_SHIFT_DOWN(key);    goto End;
 
-       case    MC_CTRL:
-               E0Flag?SET_R_CTRL_DOWN(key):SET_L_CTRL_DOWN(key);
-               goto End;
-       case    MC_ALT:
+    case    MC_CTRL:
+        E0Flag?SET_R_CTRL_DOWN(key):SET_L_CTRL_DOWN(key);
+        goto End;
+    case    MC_ALT:
 
-               E0Flag?SET_R_ALT_DOWN(key):SET_L_ALT_DOWN(key);
-               goto End;
-       }
-               
-       goto    End;
+        E0Flag?SET_R_ALT_DOWN(key):SET_L_ALT_DOWN(key);
+        goto End;
+    }
+        
+    goto    End;
 
 BreakCode:
-       switch(ScanCode)
-       {
-       case    BC_L_SHIFT:     SET_L_SHIFT_UP(key);    goto End;
-       case    BC_R_SHIFT:     SET_R_SHIFT_UP(key);    goto End;
-       case    BC_CTRL:
-               E0Flag?SET_R_CTRL_UP(key):SET_L_CTRL_UP(key);
-               goto End;
-       case    BC_ALT:
-               E0Flag?SET_R_ALT_UP(key):SET_L_ALT_UP(key);
-               goto End;
-       }
+    switch(ScanCode)
+    {
+    case    BC_L_SHIFT:    SET_L_SHIFT_UP(key);    goto End;
+    case    BC_R_SHIFT:    SET_R_SHIFT_UP(key);    goto End;
+    case    BC_CTRL:
+        E0Flag?SET_R_CTRL_UP(key):SET_L_CTRL_UP(key);
+        goto End;
+    case    BC_ALT:
+        E0Flag?SET_R_ALT_UP(key):SET_L_ALT_UP(key);
+        goto End;
+    }
 
 End:
 
-       key &= 0xFFFFFF00;
-       key |= (((E0Flag)?0x00:ScanCode) & 0xFF);
+    key &= 0xFFFFFF00;
+    key |= (((E0Flag)?0x00:ScanCode) & 0xFF);
 
-       E0Flag = 0;
+    E0Flag = 0;
 
-       return key;
+    return key;
 
 }
 
@@ -182,48 +182,48 @@ End:
 
 char ParseKbdInput(int k)
 {
-       //unsigned int k;
-       unsigned int inx;
-       unsigned char chr;
-       static unsigned char CapsLock;
+    //unsigned int k;
+    unsigned int inx;
+    unsigned char chr;
+    static unsigned char CapsLock;
 
-       k = _parse_kbd(k);
+    k = _parse_kbd(k);
 
-       k = k & 0xFF;
+    k = k & 0xFF;
 
-       if(k == -1) return ;
+    if(k == -1) return ;
 
-       inx = k & 0xFF;
-       chr = 0;
+    inx = k & 0xFF;
+    chr = 0;
 
-       if(inx >= sizeof(kbdCharTable)) goto End;
+    if(inx >= sizeof(kbdCharTable)) goto End;
 
-       // CapsLock ON OR OFF
-       if(inx == MC_CAPSLOCK)
-               CapsLock = (CapsLock)?0:1;
+    // CapsLock ON OR OFF
+    if(inx == MC_CAPSLOCK)
+        CapsLock = (CapsLock)?0:1;
 
 
-       //if((!IS_L_SHIFT_DOWN(k) && !IS_R_SHIFT_DOWN(k) && CapsLock == 0)
-       //|| ((IS_L_SHIFT_DOWN(k) || IS_R_SHIFT_DOWN(k)) && CapsLock ==1))
-       if(!IS_L_SHIFT_DOWN(k) && !IS_R_SHIFT_DOWN(k))
-       {
-               chr = kbdCharTable[inx];
-               if(CapsLock ==1 && chr >= 'a' && chr <= 'z')
-                       chr -= 32;
-       }
-       else
-       {
-               chr = kbdShiftCharTable[inx];
-               if(CapsLock ==1 && chr >= 'A' && chr <= 'Z')
-                       chr += 32;
-       }
+    //if((!IS_L_SHIFT_DOWN(k) && !IS_R_SHIFT_DOWN(k) && CapsLock == 0)
+    //|| ((IS_L_SHIFT_DOWN(k) || IS_R_SHIFT_DOWN(k)) && CapsLock ==1))
+    if(!IS_L_SHIFT_DOWN(k) && !IS_R_SHIFT_DOWN(k))
+    {
+        chr = kbdCharTable[inx];
+        if(CapsLock ==1 && chr >= 'a' && chr <= 'z')
+            chr -= 32;
+    }
+    else
+    {
+        chr = kbdShiftCharTable[inx];
+        if(CapsLock ==1 && chr >= 'A' && chr <= 'Z')
+            chr += 32;
+    }
 
 End:
-       if(chr != 0)
-       {
-               printf("%c", chr);
-               return (char)chr;
-       }
+    if(chr != 0)
+    {
+        printf("%c", chr);
+        return (char)chr;
+    }
 
-       return -1;
+    return -1;
 }
index 5e865e7a8d6eac6c9e74a643cdef918de788a216..7709d20580ab22855918dea2058af7e764f78649 100644 (file)
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1,40 +1,40 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        lib.c
+ *   File Name: lib.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Wed Feb 17 18:58:13 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Wed Feb 17 18:58:13 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<syscall.h>
-#include<system.h>
+#include <syscall.h>
+#include <system.h>
 
 int isdigit(char c)
 {
-       return ('0'<=c && c<='9');
+    return ('0'<=c && c<='9');
 }
 
 int atoi(const char *s)
 {
-       int i=0;
-       while(isdigit(*s))
-       {
-               i *= 10;
-               i += (*s++ - '0');
-       }
+    int i=0;
+    while(isdigit(*s))
+    {
+        i *= 10;
+        i += (*s++ - '0');
+    }
 
-       return i;
+    return i;
 }
 
 void reboot()
 {
-       syscall1(SYSC_REBOOT,0);
+    syscall1(SYSC_REBOOT,0);
 }
 
 void poweroff()
 {
-       syscall1(SYSC_REBOOT,1);
+    syscall1(SYSC_REBOOT,1);
 }
index 1b39d14d43ee9fb7b5710811a01d8e32aa200071..9b5f3a3fc6f0c5e658d1e448890042b879266e17 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        open.c
+ *   File Name: open.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 01:15:29 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 01:15:29 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<syscall.h>
+#include <syscall.h>
 int open(const char *path, int flags, ...)
 {
-       // 不支持第三个参数
-       return syscall3(SYSC_OPEN, path, flags, 0);
+    // 不支持第三个参数
+    return syscall3(SYSC_OPEN, path, flags, 0);
 }
index 09a9aeff40ecd20b8a81392f1e38bb839a35a6f3..419db62c7dc8c9de6d597349b008bd227e45db9c 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        read.c
+ *   File Name: read.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 18:54:48 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 18:54:48 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<types.h>
-#include<syscall.h>
+#include <types.h>
+#include <syscall.h>
 ssize_t read(int fd, void *buf, size_t count)
 {
-       return (ssize_t) syscall3(SYSC_READ, fd, buf, count);
+    return (ssize_t) syscall3(SYSC_READ, fd, buf, count);
 }
index 938b2004e584e539690c3a8947b1de2745904f89..9ad26ecb1aa25d4fc49ccc31da5a7a0f71a27eef 100644 (file)
@@ -1,23 +1,23 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        stat.c
+ *   File Name: stat.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Tue Feb 23 19:27:15 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Tue Feb 23 19:27:15 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
-#include<types.h>
-#include<syscall.h>
-#include<stat.h>
+#include <types.h>
+#include <syscall.h>
+#include <stat.h>
 
 inline int _stat(int fd, struct stat *stat)
 {
-       return syscall2(SYSC_STAT, fd, stat);
+    return syscall2(SYSC_STAT, fd, stat);
 }
 int fstat(int fd, struct stat *buf)
 {
-       return _stat(fd, buf);
+    return _stat(fd, buf);
 }
index 2e76bbfcc1e8ce0108d886f103cc486bbfb9f172..c8bae0f47c8e8b956e581a49f40788ac1ad5091b 100644 (file)
@@ -1,73 +1,73 @@
 //=========================================================================
 // lib/string.c (C) Zhao Yanbai
-//     wed, 30 Jul 2008 15:22 +0800
+//     wed, 30 Jul 2008 15:22 +0800
 //=========================================================================
 
-#include"string.h"
+#include "string.h"
 
 char *strcpy(char *dest, const char *src)
 {
-       char *p = dest;
-       while((*dest++ = *src++));
-       return p;
+    char *p = dest;
+    while((*dest++ = *src++));
+    return p;
 }
 
 size_t strlen(const char *str)
 {
-       int i=0;
-       while(*str++) i++;
-       return i;
+    int i=0;
+    while(*str++) i++;
+    return i;
 }
-int    strcmp(const char *a, const char *b)
+int    strcmp(const char *a, const char *b)
 {
-       int delta;
-       while (*a || *b)
-       {
-               delta = *a++ - *b++;
-               if(delta != 0)
-                       return delta;
-       }
-       return 0;
+    int delta;
+    while (*a || *b)
+    {
+        delta = *a++ - *b++;
+        if(delta != 0)
+            return delta;
+    }
+    return 0;
 }
 
-int    strncmp(const char *a, const char *b, size_t count)
+int    strncmp(const char *a, const char *b, size_t count)
 {
-       unsigned char c1, c2;
-       int delta;
-       while(count)
-       {
-               c1 = *a++;
-               c2 = *b++;
+    unsigned char c1, c2;
+    int delta;
+    while(count)
+    {
+        c1 = *a++;
+        c2 = *b++;
 
-               delta = c1-c2;
-               if(delta != 0)
-                       return delta;
+        delta = c1-c2;
+        if(delta != 0)
+            return delta;
 
-               if(c1 == 0)
-                       break;
-               
-               count--;
-       }
+        if(c1 == 0)
+            break;
+        
+        count--;
+    }
 
-       return 0;
+    return 0;
 }
 
-char   *strcat(char *dest, const char *src)
+char    *strcat(char *dest, const char *src)
 {
-       char *tmp = dest;
-       while(*dest) dest++;
-       while((*dest++ = *src++) != '\0');
-       return tmp;
+    char *tmp = dest;
+    while(*dest) dest++;
+    while((*dest++ = *src++) != '\0');
+    return tmp;
 }
 void *memcpy(void *dest, const void *src, size_t size)
 {
-       char *d = (char *) dest;
-       char *s = (char *) src;
-       while(size-->0) {*d = *s;d++;s++;}
-       return dest;
+    char *d = (char *) dest;
+    char *s = (char *) src;
+    while(size-->0) {*d = *s;d++;s++;}
+    return dest;
 }
 
-void   memset(char *dest, char ch, size_t size)
+void    memset(char *dest, char ch, size_t size)
 {
-       while(size--) *dest++ = ch;
+    while(size--) *dest++ = ch;
 }
index 1f0004aa69847dba6756a44f2192c812cce90e31..9abcd4e75affeb6fecc8ebd9eaf8ad3494469cfb 100644 (file)
@@ -1,12 +1,12 @@
 //=========================================================================
 // vsprintf.c (C) Zhao Yanbai
-//     wed, 30 Jul 2008 14:47 +0800
-//     Add %012d %012x %12d %12x Support  Mon, 20 Jul 2009 19:30:34
+//     wed, 30 Jul 2008 14:47 +0800
+//     Add %012d %012x %12d %12x Support  Mon, 20 Jul 2009 19:30:34
 // ========================================================================
-#include"string.h"
+#include "string.h"
 
-char   *itoa(char *s, int n);
-char   *itox(char *s, unsigned int n);
+char    *itoa(char *s, int n);
+char    *itox(char *s, unsigned int n);
 
 enum {
     ALIGN_RIGHT,
@@ -40,19 +40,19 @@ int write_buf(char *buf, const char *str, char fillch, int charcnt, int align)
 
 int vsprintf(char *buf, const char *fmt, char *args)
 {
-       char *p = buf;
-       int char_cnt;
-       char tmp[64];
+    char *p = buf;
+    int char_cnt;
+    char tmp[64];
 
-       while(*fmt)
-       {
-               if( *fmt != '%' )
-               {
-                       *p++ = *fmt++;
-                       continue;
-               }
+    while(*fmt)
+    {
+        if( *fmt != '%' )
+        {
+            *p++ = *fmt++;
+            continue;
+        }
 
-               fmt++;
+        fmt++;
 
         int align = ALIGN_RIGHT;
         if(*(fmt) == '-')
@@ -63,108 +63,108 @@ int vsprintf(char *buf, const char *fmt, char *args)
         
 
         char char_fill = ' ';
-               if(*(fmt) == '0' || *(fmt) == ' ')
+        if(*(fmt) == '0' || *(fmt) == ' ')
         {
             char_fill = *(fmt);
             ++fmt;
         }
 
-               char_cnt = 0;
-               while(*(fmt) >= '0' && *(fmt) <= '9')
-               {
-                       char_cnt += *(fmt) - '0';
-                       char_cnt *= 10;
-                       ++fmt;
-               }
+        char_cnt = 0;
+        while(*(fmt) >= '0' && *(fmt) <= '9')
+        {
+            char_cnt += *(fmt) - '0';
+            char_cnt *= 10;
+            ++fmt;
+        }
 
         char_cnt /= 10;
 
-               switch(*fmt)
-               {
-               case 'c':
-                       *p++ = *args;
-                       break;
-               case 'd':
-                       itoa(tmp, *((int*)args));
+        switch(*fmt)
+        {
+        case 'c':
+            *p++ = *args;
+            break;
+        case 'd':
+            itoa(tmp, *((int*)args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);           
 #if 0
-                       char_cnt -= strlen(tmp);
-                       if(char_cnt > 0)
-                       {
-                               while(char_cnt--)
-                               *p++ = char_fill;
-                       }
-                       strcpy(p, tmp);
-                       p += strlen(tmp);
+            char_cnt -= strlen(tmp);
+            if(char_cnt > 0)
+            {
+                while(char_cnt--)
+                *p++ = char_fill;
+            }
+            strcpy(p, tmp);
+            p += strlen(tmp);
 #endif
-                       break;
-               case 's':
+            break;
+        case 's':
             p += write_buf(p, (const char *)*((unsigned int *) args), char_fill, char_cnt, align);           
 #if 0
-                       strcpy(p, (const char *)*((unsigned int *) args));
-                       p += strlen((const char *)*((unsigned int *) args));
+            strcpy(p, (const char *)*((unsigned int *) args));
+            p += strlen((const char *)*((unsigned int *) args));
 #endif
-                       break;
-               case 'x':
-                       itox(tmp, *((unsigned int *) args));
+            break;
+        case 'x':
+            itox(tmp, *((unsigned int *) args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);           
 #if 0
-                       char_cnt -= strlen(tmp);
-                       if(char_cnt > 0)
-                       {
-                               while(char_cnt--)
-                                *p++ = char_fill;
-                       }
-                       strcpy(p, tmp);
-                       p += strlen(tmp);
+            char_cnt -= strlen(tmp);
+            if(char_cnt > 0)
+            {
+                while(char_cnt--)
+                 *p++ = char_fill;
+            }
+            strcpy(p, tmp);
+            p += strlen(tmp);
 #endif
-                       break;
-               default:
-                       break;
-               }
-               args += 4;
-               fmt++;
-       }
-       *p = 0;
+            break;
+        default:
+            break;
+        }
+        args += 4;
+        fmt++;
+    }
+    *p = 0;
 }
 
-char   *itoa(char *s, int n)
+char    *itoa(char *s, int n)
 {
-       int i;
-       char tmp[64];
-       if( n & 0x80000000 )
-       {
-               n       = ~n + 1;
-               *s++    = '-';
-       }
-       i=0;
-       do
-       {
-               tmp[i++]        = (n % 10) + '0';
-               n               /= 10;
-       }while(n);
-       while(i) *s++=tmp[--i];
-       *s = 0;
-       
+    int i;
+    char tmp[64];
+    if( n & 0x80000000 )
+    {
+        n    = ~n + 1;
+        *s++    = '-';
+    }
+    i=0;
+    do
+    {
+        tmp[i++]    = (n % 10) + '0';
+        n        /= 10;
+    }while(n);
+    while(i) *s++=tmp[--i];
+    *s = 0;
+    
 }
 
-char   *itox(char *s, unsigned int n)
+char    *itox(char *s, unsigned int n)
 {
-       char *p = s;
-       char ch,i,flag = 0;
-       
-       //*p++  = '0';  *p++    = 'x';
-
-       if(n==0){*p++='0';*p=0;return s;}
-       for(i=28; i>=0; i-=4)
-       {
-               ch      = (n>>i) & 0x0F;
-               if(ch >= 0)     ch += '0';
-               if(ch > '9')    ch += 7;
-               if(ch != '0')   flag = 1;
-               if(ch != '0' || flag == 1)
-                       *p++ = ch;
-       }
-       *p = 0;
-       return s;
+    char *p = s;
+    char ch,i,flag = 0;
+    
+    //*p++    = '0';    *p++    = 'x';
+
+    if(n==0){*p++='0';*p=0;return s;}
+    for(i=28; i>=0; i-=4)
+    {
+        ch    = (n>>i) & 0x0F;
+        if(ch >= 0)    ch += '0';
+        if(ch > '9')    ch += 7;
+        if(ch != '0')    flag = 1;
+        if(ch != '0' || flag == 1)
+            *p++ = ch;
+    }
+    *p = 0;
+    return s;
 }
index 89859d4502439018e86a60c1d5bd6162715e76d7..09d2b2766d7c0fa2118d8766c82b6dd02e3ce429 100644 (file)
@@ -1,29 +1,29 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        write.c
+ *   File Name: write.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Mon Mar  9 02:00:09 2009
  * Last Update: Mon Mar  9 02:00:09 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<syscall.h>
+#include <syscall.h>
 
 int write(int fd, const char *buf, unsigned long size)
 {
-       //asm(""::"c"(size),"d"(buf),"b"(fd));
-       //sysenter(0);
-       //syscall3(0, fd, buf, size);
-       //asm("nop;nop;nop;");
+    //asm(""::"c"(size),"d"(buf),"b"(fd));
+    //sysenter(0);
+    //syscall3(0, fd, buf, size);
+    //asm("nop;nop;nop;");
 
-       syscall3(SYSC_WRITE, fd, buf, size);
+    syscall3(SYSC_WRITE, fd, buf, size);
 
-       return size;
+    return size;
 }
index 7e1f9ac23b93847e71700f7c6acf0bffc5b635c3..bd5d996b379713615aaa40c570b747acfa2e9c97 100644 (file)
@@ -1,62 +1,62 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        kmalloc.c
+ *   File Name: kmalloc.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sat Jan 30 12:15:51 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sat Jan 30 12:15:51 2010
  * 
- * Description:        现在的版本实现得非常简单,简陋。不能分配大于32*4K的内存
- *             另外小于32*4K的都按32*4K分配
- *             以后再来重写这里吧
+ * Description: 现在的版本实现得非常简单,简陋。不能分配大于32*4K的内存
+ *         另外小于32*4K的都按32*4K分配
+ *         以后再来重写这里吧
  *--------------------------------------------------------------------------
  */
-#include<page.h>
-#include<types.h>
-#include<assert.h>
-#include<system.h>
+#include <page.h>
+#include <types.h>
+#include <assert.h>
+#include <system.h>
 
-static get_order(size_t size)
+static    get_order(size_t size)
 {
-       //printk("size:%08x ", size);
-       size = ALIGN(size, PAGE_SIZE);
-       //printk(" %08x\n", size);
-       int i;
-       int n = size>>PAGE_SHIFT;
-       for(i=0; i<MAX_ORDER; i++)
-       {
-               if(n<=(1UL<<i))
-                       break;
-       }
-
-       //printk("i:%d\n", i);
-       return i;
+    //printk("size:%08x ", size);
+    size = ALIGN(size, PAGE_SIZE);
+    //printk(" %08x\n", size);
+    int i;
+    int n = size>>PAGE_SHIFT;
+    for(i=0; i<MAX_ORDER; i++)
+    {
+        if(n<=(1UL<<i))
+            break;
+    }
+
+    //printk("i:%d\n", i);
+    return i;
 }
-void   *kmalloc(size_t size)
+void    *kmalloc(size_t size)
 {
-       assert(0<size && size<=32*PAGE_SIZE);
-       int     order = get_order(size);
-       void    *p;
-       pPage page = alloc_pages(order);
+    assert(0<size && size<=32*PAGE_SIZE);
+    int    order = get_order(size);
+    void    *p;
+    pPage page = alloc_pages(order);
 
-       if(page == NULL)
-               return NULL;
+    if(page == NULL)
+        return NULL;
 
-       //printk("kmalloc:%08x %08x ", page->mapNR, page->mapNR<<PAGE_SHIFT);
-       p = (void*)pa2va(page->mapNR<<PAGE_SHIFT);
-       
-       //printk("kmalloc: %08x\n", p);
+    //printk("kmalloc:%08x %08x ", page->mapNR, page->mapNR<<PAGE_SHIFT);
+    p = (void*)pa2va(page->mapNR<<PAGE_SHIFT);
+    
+    //printk("kmalloc: %08x\n", p);
 
-       return p;
+    return p;
 }
 
 
-void   kfree(void *p)
+void    kfree(void *p)
 {
-       assert(p != NULL);
+    assert(p != NULL);
 
-       pPage page = system.page_map;
-       //printk("kfree:%08x %08x %08x ", p, va2pa(p));
-       page += ((unsigned long)va2pa(p)>>PAGE_SHIFT);
-       //printk("%08x\n", page->mapNR);
-       free_pages(page);
+    pPage page = system.page_map;
+    //printk("kfree:%08x %08x %08x ", p, va2pa(p));
+    page += ((unsigned long)va2pa(p)>>PAGE_SHIFT);
+    //printk("%08x\n", page->mapNR);
+    free_pages(page);
 }
diff --git a/mm/mm.c b/mm/mm.c
index 7e11b7de27ff88631b3b1a364dec82b90fdfb789..d51e90e33292a26847f38fecba60be0f06831f21 100644 (file)
--- a/mm/mm.c
+++ b/mm/mm.c
@@ -1,26 +1,26 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        mm.c
+ *   File Name: mm.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Mar  4 21:08:47 2009
  * Last Update: Wed Mar  4 21:08:47 2009
  * 
  *--------------------------------------------------------------------------
  */
-#include<printk.h>
-#include<system.h>
-#include<page.h>
-#include<types.h>
-#include<bits.h>
-#include<mm.h>
-#include<init.h>
-#include<boot/boot.h>
+#include <printk.h>
+#include <system.h>
+#include <page.h>
+#include <types.h>
+#include <bits.h>
+#include <mm.h>
+#include <init.h>
+#include <boot/boot.h>
 
 
 extern char kernel_begin, kernel_end;
@@ -59,11 +59,11 @@ void e820_print_map()
     {
         struct e820_entry *p = boot_params.e820map.map + i;
 
-               printk("[%02d] 0x%08x - 0x%08x size %- 10d %8dKB %5dMB ", i, p->addr, p->addr + p->size, p->size, p->size>>10, p->size>>20);
+        printk("[%02d] 0x%08x - 0x%08x size %- 10d %8dKB %5dMB ", i, p->addr, p->addr + p->size, p->size, p->size>>10, p->size>>20);
 
         e820_print_type(p->type);
 
-               printk("\n");
+        printk("\n");
     }
 }
 
@@ -384,102 +384,102 @@ FreeArea freeArea[MAX_ORDER];
 
 void printBitMap(FreeArea fa)
 {
-       int i;
-       printk("# ");
-       for(i=0; i<fa.mapSize; i++)
-               printk("%x ", fa.map[i]);
-       printk("++++ %d ++++", freeArea[i].count);
-       printk(" #\n");
+    int i;
+    printk("# ");
+    for(i=0; i<fa.mapSize; i++)
+        printk("%x ", fa.map[i]);
+    printk("++++ %d ++++", freeArea[i].count);
+    printk(" #\n");
 }
 void setup_mm()
 {
-       u32 mm_size = system.mm_size;
-       if(mm_size > 1UL<<30)
-               mm_size = 1UL<<30;
+    u32 mm_size = system.mm_size;
+    if(mm_size > 1UL<<30)
+        mm_size = 1UL<<30;
 
-       printk("mm_size: %x\n", mm_size);
+    printk("mm_size: %x\n", mm_size);
 
 /*
-       pmmapItem mmap;
-       unsigned long maxAddr;
-
-       mmStart = (va2pa(&end) + (PAGE_SIZE-1)) & PAGE_MASK;
-       //mmEnd = (mb_mm_upper) & PAGE_MASK;
-
-       mmap = (pmmapItem)mb_mmap_addr;
-       maxAddr = 0;
-       int n = 1;
-       printk("Boot Loader Provided Physical RAM Map:\n");
-       while((unsigned long)mmap < (mb_mmap_addr + mb_mmap_size))
-       {
-               printk("[%02d] 0x%08x%08x - 0x%08x%08x ",
-               n++,//mmap->size,
-
-               mmap->base_addr_high,
-               mmap->base_addr_low,
-               mmap->length_high,
-               mmap->length_low);
-
-               switch(mmap->type)
-               {
-               case E820_RAM:
-                       printk("RAM");
-                       if(maxAddr<(mmap->base_addr_low+mmap->length_low))
-                       {
-                               maxAddr = 
-                               mmap->base_addr_low + mmap->length_low;
-                       }
-                       break;
-               case E820_RESERVED:
-                       printk("Reserved");
-                       break;
-               case E820_ACPI:
-                       printk("ACPI Data");
-                       break;
-               case E820_NVS:
-                       printk("ACPI NVS");
-                       break;
-               default:
-                       printk("Unknown %x\n", mmap->type);
-                       break;
-               }
-               printk("\n");
-
-               mmap = (pmmapItem) ((unsigned long) mmap
-                       + mmap->size + sizeof(mmap->size));
-       }
-
-       
-       //if(maxAddr < mmEnd)   
-       mmEnd = maxAddr & PAGE_MASK;
-       if(mmEnd > MAX_SUPT_PHY_MEM_SIZE)
-               mmEnd = MAX_SUPT_PHY_MEM_SIZE;
-       totalPages = mmEnd >> PAGE_SHIFT;
-
-
-       // bit map
-       int i;
-       static char *bitmap_start,*bitmap_end;
-       bitmap_start = (char *)mmStart;
-
-
-
-       // 
-       unsigned long bitmap_size = (mmEnd + 7) / 8;
-       bitmap_size =  (bitmap_size + (sizeof(long) - 1UL))
-                   &~ (sizeof(long) - 1UL);
-       //while(1);
-       //memset(bitmap_start, 0xFF, bitmap_size);
+    pmmapItem mmap;
+    unsigned long maxAddr;
+
+    mmStart = (va2pa(&end) + (PAGE_SIZE-1)) & PAGE_MASK;
+    //mmEnd = (mb_mm_upper) & PAGE_MASK;
+
+    mmap = (pmmapItem)mb_mmap_addr;
+    maxAddr = 0;
+    int n = 1;
+    printk("Boot Loader Provided Physical RAM Map:\n");
+    while((unsigned long)mmap < (mb_mmap_addr + mb_mmap_size))
+    {
+        printk("[%02d] 0x%08x%08x - 0x%08x%08x ",
+        n++,//mmap->size,
+
+        mmap->base_addr_high,
+        mmap->base_addr_low,
+        mmap->length_high,
+        mmap->length_low);
+
+        switch(mmap->type)
+        {
+        case E820_RAM:
+            printk("RAM");
+            if(maxAddr<(mmap->base_addr_low+mmap->length_low))
+            {
+                maxAddr = 
+                mmap->base_addr_low + mmap->length_low;
+            }
+            break;
+        case E820_RESERVED:
+            printk("Reserved");
+            break;
+        case E820_ACPI:
+            printk("ACPI Data");
+            break;
+        case E820_NVS:
+            printk("ACPI NVS");
+            break;
+        default:
+            printk("Unknown %x\n", mmap->type);
+            break;
+        }
+        printk("\n");
+
+        mmap = (pmmapItem) ((unsigned long) mmap
+            + mmap->size + sizeof(mmap->size));
+    }
+
+    
+    //if(maxAddr < mmEnd)    
+    mmEnd = maxAddr & PAGE_MASK;
+    if(mmEnd > MAX_SUPT_PHY_MEM_SIZE)
+        mmEnd = MAX_SUPT_PHY_MEM_SIZE;
+    totalPages = mmEnd >> PAGE_SHIFT;
+
+
+    // bit map
+    int i;
+    static char *bitmap_start,*bitmap_end;
+    bitmap_start = (char *)mmStart;
+
+
+
+    // 
+    unsigned long bitmap_size = (mmEnd + 7) / 8;
+    bitmap_size =  (bitmap_size + (sizeof(long) - 1UL))
+            &~ (sizeof(long) - 1UL);
+    //while(1);
+    //memset(bitmap_start, 0xFF, bitmap_size);
 
 #if 0
-       printk( "bitmap_start: %x "
-               "mmStart: %x "
-               "mmEnd: %x "
-               "bitmap_size: %x\n",
-               bitmap_start,
-               mmStart,
-               mmEnd,
-               bitmap_size);
+    printk(    "bitmap_start: %x "
+        "mmStart: %x "
+        "mmEnd: %x "
+        "bitmap_size: %x\n",
+        bitmap_start,
+        mmStart,
+        mmEnd,
+        bitmap_size);
 #endif
 */
 }
index d8af96ad5674b68c5e8c136b80d55c912e84a3d8..64632b68b54e26ba19f5052b5bd619208b0e54b1 100644 (file)
--- a/mm/page.c
+++ b/mm/page.c
 /*
  *--------------------------------------------------------------------------
- *   File Name:        page.c
+ *   File Name: page.c
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
- *                     Sun Jan 24 15:14:24 2010
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
+ *              Sun Jan 24 15:14:24 2010
  * 
- * Description:        none
+ * Description: none
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<page.h>
-#include<bits.h>
-#include<types.h>
-#include<sched.h>
-#include<assert.h>
-#include<printk.h>
-#include<init.h>
-#include<mm.h>
+#include <page.h>
+#include <bits.h>
+#include <types.h>
+#include <sched.h>
+#include <assert.h>
+#include <printk.h>
+#include <init.h>
+#include <mm.h>
 
 
-#define        get_page_from_list(pList) list_entry(pList, Page, list)
-#define        add_page2list(page, order) \
-               list_add(&page->list, &freeArea[order].freeList)
+#define get_page_from_list(pList) list_entry(pList, Page, list)
+#define add_page2list(page, order) \
+        list_add(&page->list, &freeArea[order].freeList)
 
 #if 1
-void   do_no_page(void *addr)
+void    do_no_page(void *addr)
 {
-       //printk("%s ", __FUNCTION__);
-       u32     *pde = (u32*)pa2va(current->cr3);
-       u32     *pte;
-       void    *page = get_phys_pages(1);
-       if(page == NULL)
-               panic("failed alloc page");
-
-       int npde = ((u32)addr)>>22;
-       int npte = (((u32)addr)>>12) & 0x3FF;
-
-       if((pde[npde] & 0xFFFFF000)== 0)
-       {
-               //printk("*a*\n");
-               pte = (u32 *) pa2va(get_phys_pages(1));
-               memset((void*)pte, 0, PAGE_SIZE);
-               if(pte == NULL)
-                       panic("failed alloc pte");
-
-               pte[npte] = (u32) page | 7;
-               pde[npde] = va2pa(pte) | 7;
-       }
-       else
-       {
-               //printk("*b* : %08x\n", page);
-               //printk("*b* : %08x %08x\n", pde[npde], page);
-               pte = (u32*)(pde[npde] & 0xFFFFF000);
-               pte = pa2va(pte);
-               pte[npte] = (u32) page | 7;
-       }
-       load_cr3(current);
+    //printk("%s ", __FUNCTION__);
+    u32    *pde = (u32*)pa2va(current->cr3);
+    u32    *pte;
+    void    *page = get_phys_pages(1);
+    if(page == NULL)
+        panic("failed alloc page");
+
+    int npde = ((u32)addr)>>22;
+    int npte = (((u32)addr)>>12) & 0x3FF;
+
+    if((pde[npde] & 0xFFFFF000)== 0)
+    {
+        //printk("*a*\n");
+        pte = (u32 *) pa2va(get_phys_pages(1));
+        memset((void*)pte, 0, PAGE_SIZE);
+        if(pte == NULL)
+            panic("failed alloc pte");
+
+        pte[npte] = (u32) page | 7;
+        pde[npde] = va2pa(pte) | 7;
+    }
+    else
+    {
+        //printk("*b* : %08x\n", page);
+        //printk("*b* : %08x %08x\n", pde[npde], page);
+        pte = (u32*)(pde[npde] & 0xFFFFF000);
+        pte = pa2va(pte);
+        pte[npte] = (u32) page | 7;
+    }
+    load_cr3(current);
 #if 0
-       u32     *pde = (u32*)pa2va(current->cr3);
-       u32     *pte;
-       void    *page = (void*)va2pa(kmalloc(PAGE_SIZE));
-       if(page == NULL)
-               panic("failed alloc page");
-
-       int npde = ((u32)addr)>>22;
-       int npte = (((u32)addr)>>12) & 0x3FF;
-
-       if(pde[npde] == 0)
-       {
-               printk("*a*");
-               pte = (u32 *) kmalloc(PAGE_SIZE);
-               memset((void*)pte, 0, PAGE_SIZE);
-               if(pte == NULL)
-                       panic("failed alloc pte");
-
-               pte[npte] = (u32) page | 7;
-               pde[npde] = va2pa(pte) | 7;
-       }
-       else
-       {
-               printk("*b*");
-               pte = pde[npde] & 0xFFFFF000;
-               pte = pa2va(pte);
-               pte[npte] = (u32) page | 7;
-       }
+    u32    *pde = (u32*)pa2va(current->cr3);
+    u32    *pte;
+    void    *page = (void*)va2pa(kmalloc(PAGE_SIZE));
+    if(page == NULL)
+        panic("failed alloc page");
+
+    int npde = ((u32)addr)>>22;
+    int npte = (((u32)addr)>>12) & 0x3FF;
+
+    if(pde[npde] == 0)
+    {
+        printk("*a*");
+        pte = (u32 *) kmalloc(PAGE_SIZE);
+        memset((void*)pte, 0, PAGE_SIZE);
+        if(pte == NULL)
+            panic("failed alloc pte");
+
+        pte[npte] = (u32) page | 7;
+        pde[npde] = va2pa(pte) | 7;
+    }
+    else
+    {
+        printk("*b*");
+        pte = pde[npde] & 0xFFFFF000;
+        pte = pa2va(pte);
+        pte[npte] = (u32) page | 7;
+    }
 #endif
 }
 
 
 void do_wp_page(void *addr)
 {
-       int npde = ((u32)addr)>>22;
-       int npte = (((u32)addr)>>12) & 0x3FF;
+    int npde = ((u32)addr)>>22;
+    int npte = (((u32)addr)>>12) & 0x3FF;
 
 
-       u32 *pd = (u32 *)pa2va(current->cr3);
-       u32 *pt = NULL;
+    u32 *pd = (u32 *)pa2va(current->cr3);
+    u32 *pt = NULL;
 
 
-       pt = pa2va(pd[npde] & 0xFFFFF000);
+    pt = pa2va(pd[npde] & 0xFFFFF000);
 
-       void *dst, *src;
+    void *dst, *src;
 
-       src = (void*)pt[npte];
+    src = (void*)pt[npte];
 
-       if(pgmap[((u32)src)>>PAGE_SHIFT].count > 0)
-       {
-               pgmap[((u32)src)>>PAGE_SHIFT].count--;
+    if(pgmap[((u32)src)>>PAGE_SHIFT].count > 0)
+    {
+        pgmap[((u32)src)>>PAGE_SHIFT].count--;
 
-               src = (void *)pa2va(((u32)src) & 0xFFFFF000);
+        src = (void *)pa2va(((u32)src) & 0xFFFFF000);
 
-               dst = get_phys_pages(1);
-               if(dst == NULL)
-                       panic("out of memory");
-               dst = pa2va(dst);
+        dst = get_phys_pages(1);
+        if(dst == NULL)
+            panic("out of memory");
+        dst = pa2va(dst);
 
-               memcpy(dst, src, PAGE_SIZE);    
+        memcpy(dst, src, PAGE_SIZE);    
 
-               dst = (void *)va2pa(dst);
-               pt[npte] = (u32)dst | 7;
-       }
-       else
-       {
-               pt[npte] |= 7;
-       }
+        dst = (void *)va2pa(dst);
+        pt[npte] = (u32)dst | 7;
+    }
+    else
+    {
+        pt[npte] |= 7;
+    }
 
-       load_cr3(current);
+    load_cr3(current);
 }
 
 inline pPage __alloc_pages(unsigned int order, unsigned int alloc_order)
 {
-       assert(0 <= order && order<MAX_ORDER);
-       assert(!list_is_empty(&freeArea[order].freeList));
-       assert(alloc_order <= order);
-
-       pListHead pl = freeArea[order].freeList.next;
-       list_del_init(pl);
-       pPage   page = get_page_from_list(pl);
-
-       if(order == alloc_order)
-       {
-               page->order = alloc_order;
-               page->count = 0;
-               assert((page->mapNR%(1UL<<(order))) == 0);
-               return page;
-       }
-
-       assert(order >= 1);
-
-       // 把这个页分成两半挂到小一级的队列上
-       add_page2list(page, order-1);
+    assert(0 <= order && order<MAX_ORDER);
+    assert(!list_is_empty(&freeArea[order].freeList));
+    assert(alloc_order <= order);
+
+    pListHead pl = freeArea[order].freeList.next;
+    list_del_init(pl);
+    pPage    page = get_page_from_list(pl);
+
+    if(order == alloc_order)
+    {
+        page->order = alloc_order;
+        page->count = 0;
+        assert((page->mapNR%(1UL<<(order))) == 0);
+        return page;
+    }
+
+    assert(order >= 1);
+
+    // 把这个页分成两半挂到小一级的队列上
+    add_page2list(page, order-1);
 #if 0
-       if(page->mapNR == 0)
-       {
-               printk("[>1<%08x %d %d]\n", page, order, alloc_order);
-               while(1);
-       }
+    if(page->mapNR == 0)
+    {
+        printk("[>1<%08x %d %d]\n", page, order, alloc_order);
+        while(1);
+    }
 #endif
-       assert((page->mapNR%(1UL<<(order-1))) == 0);
-       page += (1 << (order-1));
-       assert((page->mapNR%(1UL<<(order-1))) == 0);
+    assert((page->mapNR%(1UL<<(order-1))) == 0);
+    page += (1 << (order-1));
+    assert((page->mapNR%(1UL<<(order-1))) == 0);
 #if 0
-       if(page->mapNR == 0)
-       {
-               printk("[>2<%08x %d %d]\n", page, order, alloc_order);
-               while(1);
-       }
+    if(page->mapNR == 0)
+    {
+        printk("[>2<%08x %d %d]\n", page, order, alloc_order);
+        while(1);
+    }
 #endif
-       add_page2list(page, order-1);
+    add_page2list(page, order-1);
 
-       //int j=2000000;while(j--);
-       return __alloc_pages(order-1, alloc_order);
+    //int j=2000000;while(j--);
+    return __alloc_pages(order-1, alloc_order);
 }
 
-pPage  alloc_pages(unsigned int order)
+pPage    alloc_pages(unsigned int order)
 {
-       if(order<0 || order>=MAX_ORDER)
-               return NULL;
-
-       int i;
-       for(i=order; i<MAX_ORDER; i++)
-       {
-               if(list_is_empty(&freeArea[i].freeList))
-                       continue;
-
-               return  __alloc_pages(i, order);
-       }
-       return NULL;
+    if(order<0 || order>=MAX_ORDER)
+        return NULL;
+
+    int i;
+    for(i=order; i<MAX_ORDER; i++)
+    {
+        if(list_is_empty(&freeArea[i].freeList))
+            continue;
+
+        return    __alloc_pages(i, order);
+    }
+    return NULL;
 }
 
 
-pPage  get_buddy_page(pPage page, unsigned int order)
+pPage    get_buddy_page(pPage page, unsigned int order)
 {
-       assert(0<=order && order<MAX_ORDER);
-       assert(page != NULL);
+    assert(0<=order && order<MAX_ORDER);
+    assert(page != NULL);
 
-       //printk("mapnr: %d order:%d %d\n", page->mapNR, order, 1UL<<order);
-       assert((page->mapNR%(1UL<<order)) == 0);
+    //printk("mapnr: %d order:%d %d\n", page->mapNR, order, 1UL<<order);
+    assert((page->mapNR%(1UL<<order)) == 0);
 
-       int off = 1<<(order+0);
-       int div = 1<<(order+1);
-       int nr = page->mapNR;
+    int off = 1<<(order+0);
+    int div = 1<<(order+1);
+    int nr = page->mapNR;
 
-       pListHead pos, tmp;
-       pPage p;
+    pListHead pos, tmp;
+    pPage p;
 
-       nr += ((nr+off)/div == nr/div) ? off : -off;
+    nr += ((nr+off)/div == nr/div) ? off : -off;
 
-       list_for_each_safe(pos, tmp, &freeArea[order].freeList)
-       {
-               p = get_page_from_list(pos);
-               if(p->mapNR == nr)
-               {
-                       list_del_init(&p->list);
-                       p->order = order;
-                       return p;
-               }
-       }
+    list_for_each_safe(pos, tmp, &freeArea[order].freeList)
+    {
+        p = get_page_from_list(pos);
+        if(p->mapNR == nr)
+        {
+            list_del_init(&p->list);
+            p->order = order;
+            return p;
+        }
+    }
 
 
-       return NULL;
+    return NULL;
 }
 
-void   free_pages(pPage page)
+void    free_pages(pPage page)
 {
-       assert(page != NULL);
-       unsigned int order = page->order;
-       assert(0<=order && order<MAX_ORDER);
-
-
-       // buddy page
-       //printk("[%d %d]", page->mapNR, page->order);
-       assert((page->mapNR % (1UL<<order)) == 0);
-       pPage bpage = get_buddy_page(page, order);
-       //printk("<%d %d>", bpage->mapNR, bpage->order);
-       
-
-       if(bpage == NULL || order == MAX_ORDER-1)
-       {
-               add_page2list(page, order);
-       }
-       else
-       {
-               //list_del_init(&bpage->list);
-               page = (page->mapNR > bpage->mapNR) ? bpage : page;
-               page->order += 1;
-               assert((page->mapNR%(1UL<<page->order)) == 0);
+    assert(page != NULL);
+    unsigned int order = page->order;
+    assert(0<=order && order<MAX_ORDER);
+
+
+    // buddy page
+    //printk("[%d %d]", page->mapNR, page->order);
+    assert((page->mapNR % (1UL<<order)) == 0);
+    pPage bpage = get_buddy_page(page, order);
+    //printk("<%d %d>", bpage->mapNR, bpage->order);
+    
+
+    if(bpage == NULL || order == MAX_ORDER-1)
+    {
+        add_page2list(page, order);
+    }
+    else
+    {
+        //list_del_init(&bpage->list);
+        page = (page->mapNR > bpage->mapNR) ? bpage : page;
+        page->order += 1;
+        assert((page->mapNR%(1UL<<page->order)) == 0);
 #if 0
-               if((page->mapNR%(1UL<<page->order)) != 0)
-               {
-                       printk("*%d %d*", page->mapNR, 1UL<<page->order);
-                       panic("bug");
-               }
+        if((page->mapNR%(1UL<<page->order)) != 0)
+        {
+            printk("*%d %d*", page->mapNR, 1UL<<page->order);
+            panic("bug");
+        }
 #endif
-               free_pages(page);
-       }
+        free_pages(page);
+    }
 }
 
 #else
 
 inline pPage __alloc_pages(unsigned int order, unsigned int alloc_order)
 {
-       assert(0 <= order && order<MAX_ORDER);
-       assert(!list_is_empty(&freeArea[order].freeList));
-       assert(alloc_order <= order);
-
-       pListHead pl = freeArea[order].freeList.next;
-       list_del_init(pl);
-       pPage   pg = list_entry(pl, Page, list);
-       change_bit(pg->mapNR>>(order+1), (unsigned long *)freeArea[order].map);
-
-       if(order == alloc_order)
-       {
-               return pg;
-       }
-
-       // 把这个页分成两半挂到小一级的队列上
-       assert(order >= 1);
-       list_add(&pg->list, &freeArea[order-1].freeList);
-       pg += (1 << (order-1));
-       list_add(&pg->list, &freeArea[order-1].freeList);
-
-       return __alloc_pages(order-1, alloc_order);
+    assert(0 <= order && order<MAX_ORDER);
+    assert(!list_is_empty(&freeArea[order].freeList));
+    assert(alloc_order <= order);
+
+    pListHead pl = freeArea[order].freeList.next;
+    list_del_init(pl);
+    pPage    pg = list_entry(pl, Page, list);
+    change_bit(pg->mapNR>>(order+1), (unsigned long *)freeArea[order].map);
+
+    if(order == alloc_order)
+    {
+        return pg;
+    }
+
+    // 把这个页分成两半挂到小一级的队列上
+    assert(order >= 1);
+    list_add(&pg->list, &freeArea[order-1].freeList);
+    pg += (1 << (order-1));
+    list_add(&pg->list, &freeArea[order-1].freeList);
+
+    return __alloc_pages(order-1, alloc_order);
 }
 
 pPage alloc_pages(unsigned int order)
 {
-       if(order >= MAX_ORDER)
-               return NULL;
+    if(order >= MAX_ORDER)
+        return NULL;
 
-       int i;
-       for(i=order; i<MAX_ORDER; i++)
-       {
-               if(list_is_empty(&freeArea[i].freeList))
-                       continue;
+    int i;
+    for(i=order; i<MAX_ORDER; i++)
+    {
+        if(list_is_empty(&freeArea[i].freeList))
+            continue;
 
-               return __alloc_pages(i, order);
-       }
+        return __alloc_pages(i, order);
+    }
 
-       return NULL;
+    return NULL;
 }
 
 
 void free_pages(pPage page, unsigned int order)
 {
-       assert(0<=order &&  order<MAX_ORDER);
-       assert(page != NULL);
-
-
-       
-       int nr = page->mapNR>>(order+1);
-       //printk("#########%d %d\n",page->mapNR, variable_test_bit( nr, (unsigned long *)freeArea[order].map));
-       if(order == MAX_ORDER -1
-       || !variable_test_bit( nr, (unsigned long *)freeArea[order].map))
-       {
-               change_bit( nr, (unsigned long *)freeArea[order].map);
-               list_add(&page->list, &freeArea[order].freeList);
-       }
-       else
-       {
-               
-               pListHead pos, tmp;
-
-               int offset = 1<<order;
-               nr = page->mapNR;
-               printk("------------%d %d ", offset, nr);
-               nr += (((nr+offset)>>(order)) == (nr>>(order)))
-                        ? offset : -offset;
-               printk("%d\n", nr);
-               list_for_each_safe(pos, tmp, &freeArea[order].freeList)
-               {
-                       printk("[%d] ",list_entry(pos, Page, list)->mapNR);
-                       if(list_entry(pos, Page, list)->mapNR == nr)
-                               break;
-               }
-
-               assert(pos != &freeArea[order].freeList);
-               list_del_init(pos);
-
-               nr = page->mapNR>>(order+2);
-               change_bit( nr, (unsigned long *)freeArea[order+1].map);
-               pPage bpage = get_page_from_list(pos);
-               page = (page->mapNR > bpage->mapNR)? bpage: page;
-               list_add(&page->list, &freeArea[order+1].freeList);
-       }
+    assert(0<=order &&  order<MAX_ORDER);
+    assert(page != NULL);
+
+
+    
+    int nr = page->mapNR>>(order+1);
+    //printk("#########%d %d\n",page->mapNR, variable_test_bit( nr, (unsigned long *)freeArea[order].map));
+    if(order == MAX_ORDER -1
+    || !variable_test_bit( nr, (unsigned long *)freeArea[order].map))
+    {
+        change_bit( nr, (unsigned long *)freeArea[order].map);
+        list_add(&page->list, &freeArea[order].freeList);
+    }
+    else
+    {
+        
+        pListHead pos, tmp;
+
+        int offset = 1<<order;
+        nr = page->mapNR;
+        printk("------------%d %d ", offset, nr);
+        nr += (((nr+offset)>>(order)) == (nr>>(order)))
+             ? offset : -offset;
+        printk("%d\n", nr);
+        list_for_each_safe(pos, tmp, &freeArea[order].freeList)
+        {
+            printk("[%d] ",list_entry(pos, Page, list)->mapNR);
+            if(list_entry(pos, Page, list)->mapNR == nr)
+                break;
+        }
+
+        assert(pos != &freeArea[order].freeList);
+        list_del_init(pos);
+
+        nr = page->mapNR>>(order+2);
+        change_bit( nr, (unsigned long *)freeArea[order+1].map);
+        pPage bpage = get_page_from_list(pos);
+        page = (page->mapNR > bpage->mapNR)? bpage: page;
+        list_add(&page->list, &freeArea[order+1].freeList);
+    }
 }
 #endif
 
 void disp_free_area()
 {
-       int i;
-       for(i=0; i<MAX_ORDER; i++)
-       {
-               pListHead pos,tmp;
-               int count = 0;
-
-               list_for_each_safe(pos, tmp, &freeArea[i].freeList)
-               {
-                       count++;
-                       //printk("%d ", list_entry(pos, Page, list)->mapNR);
-                       //printk("%08x %08x %08x %08x\n",pos, pos->prev, tmp,
-                       //              &(freeArea[i].freeList));
-               }
-               printk("[%d %d]",i, count);
-       }
-       printk("\n");
-       int j=100000;
-       //while(j--);
+    int i;
+    for(i=0; i<MAX_ORDER; i++)
+    {
+        pListHead pos,tmp;
+        int count = 0;
+
+        list_for_each_safe(pos, tmp, &freeArea[i].freeList)
+        {
+            count++;
+            //printk("%d ", list_entry(pos, Page, list)->mapNR);
+            //printk("%08x %08x %08x %08x\n",pos, pos->prev, tmp,
+            //        &(freeArea[i].freeList));
+        }
+        printk("[%d %d]",i, count);
+    }
+    printk("\n");
+    int j=100000;
+    //while(j--);
 }
index 5a5ade3336047e71df783f7a751b3a9b770f4edd..ec5dee7fa53e487b1668df6ed3b9c75c8cd2de14 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        setuppci.c
+ *   File Name: setuppci.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sun Mar  8 21:33:13 2009
  * Last Update: Sun Mar  8 21:33:13 2009
  * 
  *--------------------------------------------------------------------------
  */
-#include<io.h>
-#include<pci.h>
-#include<types.h>
-#include<system.h>
-#include<printk.h>
+#include <io.h>
+#include <pci.h>
+#include <types.h>
+#include <system.h>
+#include <printk.h>
 
 void ScanPCIBus(int bus);
 int ProbePCIBus();
 
 static int pci_read_config_byte(int cmd)
 {
-       outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
-       return inb(PCI_DATA + (PCI_GET_CMD_REG(cmd) & 3));
+    outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
+    return inb(PCI_DATA + (PCI_GET_CMD_REG(cmd) & 3));
 }
 
 static int pci_read_config_word(int cmd)
 {
-       outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
-       return inw(PCI_DATA + (PCI_GET_CMD_REG(cmd) & 2));
+    outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
+    return inw(PCI_DATA + (PCI_GET_CMD_REG(cmd) & 2));
 }
 
 static int pci_read_config_long(int cmd)
 {
-       outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
-       return inl(PCI_DATA);
+    outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
+    return inl(PCI_DATA);
 }
 
 
-void   setup_pci()
+void    setup_pci()
 {
-       if(!ProbePCIBus())
-               return ;
+    if(!ProbePCIBus())
+        return ;
 
-       ScanPCIBus(0);
+    ScanPCIBus(0);
 }
 
 void ScanPCIBus(int bus)
 {
-       u8 dev, devfn;
-       u32 cmd;
-       u32 retval;
-       printk("Scanning PCI Bus.\n");
-       
-       for(dev=0; dev<32; dev++)
-               for(devfn =0; devfn<8; devfn++)
-               {
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_VENDORID);
-                       retval = pci_read_config_word(cmd);
-                       if(retval == 0xFFFF)
-                               continue;
-                       //Vendor
-                       printk("%x ", retval);
-
-                       //Device
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_DEVICEID);
-                       retval = pci_read_config_word(cmd);
-                       printk("%x ", retval);
-               
-                       // Class Device
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_CLASSPROG);
-                       retval = pci_read_config_byte(cmd);
-                       printk("%x ", retval);
-
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_CLASSDEVICE);
-                       retval = pci_read_config_word(cmd);
-                       printk("%x ", retval);
-                       
-
-                       //Interrupt Line
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_INTRLINE);
-                       retval = pci_read_config_byte(cmd);
-                       printk("%x ", retval);
-
-                       //Interrupt Pin
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_INTRPIN);
-                       retval = pci_read_config_byte(cmd);
-                       printk("%x ", retval);
-
-                       cmd = PCI_CMD(bus, dev, devfn, PCI_HDRTYPE);
-                       retval = pci_read_config_byte(cmd);
-                       printk("%x ", retval);
-                       retval &= PCI_HDRTYPE_MASK;
-                       printk("%x", retval);
-                       
-                       switch(retval)
-                       {
-                       case PCI_HDRTYPE_NORMAL:
-                               printk("Normal Device\n");
-                               break;
-                       case PCI_HDRTYPE_BRIDGE:
-                               printk("Aha PCI-PCI Bridge\n");
-                               break;
-                       case PCI_HDRTYPE_CARDBUS:
-                               printk("Wow PCI-CardBus\n");
-                               break;
-                       default:
-                               printk("Not Support!\n");
-                               break;
-                       }
-               }
+    u8 dev, devfn;
+    u32 cmd;
+    u32 retval;
+    printk("Scanning PCI Bus.\n");
+    
+    for(dev=0; dev<32; dev++)
+        for(devfn =0; devfn<8; devfn++)
+        {
+            cmd = PCI_CMD(bus, dev, devfn, PCI_VENDORID);
+            retval = pci_read_config_word(cmd);
+            if(retval == 0xFFFF)
+                continue;
+            //Vendor
+            printk("%x ", retval);
+
+            //Device
+            cmd = PCI_CMD(bus, dev, devfn, PCI_DEVICEID);
+            retval = pci_read_config_word(cmd);
+            printk("%x ", retval);
+        
+            // Class Device
+            cmd = PCI_CMD(bus, dev, devfn, PCI_CLASSPROG);
+            retval = pci_read_config_byte(cmd);
+            printk("%x ", retval);
+
+            cmd = PCI_CMD(bus, dev, devfn, PCI_CLASSDEVICE);
+            retval = pci_read_config_word(cmd);
+            printk("%x ", retval);
+            
+
+            //Interrupt Line
+            cmd = PCI_CMD(bus, dev, devfn, PCI_INTRLINE);
+            retval = pci_read_config_byte(cmd);
+            printk("%x ", retval);
+
+            //Interrupt Pin
+            cmd = PCI_CMD(bus, dev, devfn, PCI_INTRPIN);
+            retval = pci_read_config_byte(cmd);
+            printk("%x ", retval);
+
+            cmd = PCI_CMD(bus, dev, devfn, PCI_HDRTYPE);
+            retval = pci_read_config_byte(cmd);
+            printk("%x ", retval);
+            retval &= PCI_HDRTYPE_MASK;
+            printk("%x", retval);
+            
+            switch(retval)
+            {
+            case PCI_HDRTYPE_NORMAL:
+                printk("Normal Device\n");
+                break;
+            case PCI_HDRTYPE_BRIDGE:
+                printk("Aha PCI-PCI Bridge\n");
+                break;
+            case PCI_HDRTYPE_CARDBUS:
+                printk("Wow PCI-CardBus\n");
+                break;
+            default:
+                printk("Not Support!\n");
+                break;
+            }
+        }
 }
 
 int ProbePCIBus()
 {
-       int retval;
-       int cmd;
-       int dev,devfn;
-       char errmsg[]="Can not find PCI bus on your computer";
-
-       // Check if The IO Address was Used...
-       cmd = PCI_CMD(0,0,0,0);
-       retval = pci_read_config_long(cmd);
-       if( retval == 0xFFFFFFFF || retval == 0x00000000
-       ||  retval == 0x0000FFFF || retval == 0xFFFF0000)
-       {
-               printk("%s\n",errmsg);
-               return 0;
-       }
-
-       // Maybe it's just an ISA Device
-       // So We Must Check if It is PCI...
-       for(dev=0; dev<32; dev++)
-               for(devfn=0; devfn<8; devfn++)
-               {
-                       cmd = PCI_CMD(0, dev, devfn, PCI_CLASSDEVICE);
-                       retval = pci_read_config_word(cmd);
-                       if(retval == PCI_CLASS_BRIDGE_HOST
-                       || retval == PCI_CLASS_DISPLAY_VGA)
-                               return 1;
-                       cmd = PCI_CMD(0, dev, devfn, PCI_VENDORID);
-                       retval = pci_read_config_word(cmd);
-                       if(retval == PCI_VENDORID_INTEL
-                       || retval == PCI_VENDORID_COMPAQ)
-                               return 1;
-               }
-
-
-       printk("%s\n",errmsg);
-       return 0;
+    int retval;
+    int cmd;
+    int dev,devfn;
+    char errmsg[]="Can not find PCI bus on your computer";
+
+    // Check if The IO Address was Used...
+    cmd = PCI_CMD(0,0,0,0);
+    retval = pci_read_config_long(cmd);
+    if( retval == 0xFFFFFFFF || retval == 0x00000000
+    ||  retval == 0x0000FFFF || retval == 0xFFFF0000)
+    {
+        printk("%s\n",errmsg);
+        return 0;
+    }
+
+    // Maybe it's just an ISA Device
+    // So We Must Check if It is PCI...
+    for(dev=0; dev<32; dev++)
+        for(devfn=0; devfn<8; devfn++)
+        {
+            cmd = PCI_CMD(0, dev, devfn, PCI_CLASSDEVICE);
+            retval = pci_read_config_word(cmd);
+            if(retval == PCI_CLASS_BRIDGE_HOST
+            || retval == PCI_CLASS_DISPLAY_VGA)
+                return 1;
+            cmd = PCI_CMD(0, dev, devfn, PCI_VENDORID);
+            retval = pci_read_config_word(cmd);
+            if(retval == PCI_VENDORID_INTEL
+            || retval == PCI_VENDORID_COMPAQ)
+                return 1;
+        }
+
+
+    printk("%s\n",errmsg);
+    return 0;
 }
index ede5e898459943de108b55b0b0a86d930136d410..4972dc57bc6ad311c26e8e2ff4b583731bf9efee 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        cpuid.c
+ *   File Name: cpuid.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sat Feb 28 14:43:35 2009
  * Last Update: Sat Feb 28 14:43:35 2009
  * 
  *--------------------------------------------------------------------------
  */
-#include<bits.h>
+#include <bits.h>
 
-#define        TEST_FEATURE(val,bit,fea)\
+#define TEST_FEATURE(val,bit,fea)\
 do{\
-       if( ISSET_BIT(val,bit) )\
-               /*printk(" %s",fea)*/;\
+    if( ISSET_BIT(val,bit) )\
+        /*printk(" %s",fea)*/;\
 }while(0);
 
 typedef struct reg{ unsigned long eax,ebx,ecx,edx; }Reg,*pReg;
-Reg    cpuid(unsigned long op)
+Reg    cpuid(unsigned long op)
 {
-       Reg     r;
-       asm("cpuid;"
-       :"=a"(r.eax),
-        "=b"(r.ebx),
-        "=c"(r.ecx),
-        "=d"(r.edx)
-       :"a"(op)
-       );
+    Reg    r;
+    asm("cpuid;"
+    :"=a"(r.eax),
+     "=b"(r.ebx),
+     "=c"(r.ecx),
+     "=d"(r.edx)
+    :"a"(op)
+    );
 
-       return  r;
+    return     r;
 }
 
-void   detect_cpu()
+void    detect_cpu()
 {
 
-       Reg     r;
-       unsigned short int cpu_sn[6];   //serial number
-       int     i;
+    Reg    r;
+    unsigned short int cpu_sn[6];    //serial number
+    int    i;
 
-       /**********************Get CPU Name********************************/
-       char    cpu_name[13];
+    /**********************Get CPU Name********************************/
+    char    cpu_name[13];
 
-       //printk("Detecting CPU...   ");
+    //printk("Detecting CPU...   ");
 
-       r=cpuid(0);
-       memcpy(cpu_name + 0, &r.ebx, 4);
-       memcpy(cpu_name + 4, &r.edx, 4);
-       memcpy(cpu_name + 8, &r.ecx, 4);
-       cpu_name[12] = 0;
-       printk("%s ",cpu_name);
+    r=cpuid(0);
+    memcpy(cpu_name + 0, &r.ebx, 4);
+    memcpy(cpu_name + 4, &r.edx, 4);
+    memcpy(cpu_name + 8, &r.ecx, 4);
+    cpu_name[12] = 0;
+    printk("%s ",cpu_name);
 
-       /**********************Get Processor Brand String******************/
-       char    pbs[50];                //processor brand string
-       r = cpuid(0x80000002);
-       memcpy(pbs + 0 , &r.eax, 4);
-       memcpy(pbs + 4 , &r.ebx, 4);
-       memcpy(pbs + 8 , &r.ecx, 4);
-       memcpy(pbs + 12, &r.edx, 4);
-       r=cpuid(0x80000003);
-       memcpy(pbs + 16 , &r.eax, 4);
-       memcpy(pbs + 20 , &r.ebx, 4);
-       memcpy(pbs + 24 , &r.ecx, 4);
-       memcpy(pbs + 28 , &r.edx, 4);
-       r=cpuid(0x80000004);
-       memcpy(pbs + 32 , &r.eax, 4);
-       memcpy(pbs + 36 , &r.ebx, 4);
-       memcpy(pbs + 40 , &r.ecx, 4);
-       memcpy(pbs + 44 , &r.edx, 4);
-       //printk("Model Name: %s\n",pbs);
-       printk("%s", pbs);
+     /**********************Get Processor Brand String******************/
+    char    pbs[50];        //processor brand string
+    r = cpuid(0x80000002);
+    memcpy(pbs + 0 , &r.eax, 4);
+    memcpy(pbs + 4 , &r.ebx, 4);
+    memcpy(pbs + 8 , &r.ecx, 4);
+    memcpy(pbs + 12, &r.edx, 4);
+    r=cpuid(0x80000003);
+    memcpy(pbs + 16 , &r.eax, 4);
+    memcpy(pbs + 20 , &r.ebx, 4);
+    memcpy(pbs + 24 , &r.ecx, 4);
+    memcpy(pbs + 28 , &r.edx, 4);
+    r=cpuid(0x80000004);
+    memcpy(pbs + 32 , &r.eax, 4);
+    memcpy(pbs + 36 , &r.ebx, 4);
+    memcpy(pbs + 40 , &r.ecx, 4);
+    memcpy(pbs + 44 , &r.edx, 4);
+    //printk("Model Name: %s\n",pbs);
+    printk("%s", pbs);
 
-       /**********************Get Number of Processors********************/
-       int     pn;//number of logical processors in one physical processor
-       r=cpuid(1);
-       pn      = ((r.ebx & 0x00FF0000) >> 16);
+     /**********************Get Number of Processors********************/
+    int    pn;//number of logical processors in one physical processor
+    r=cpuid(1);
+    pn    = ((r.ebx & 0x00FF0000) >> 16);
 
-       /**********************Get the CPU's Feature***********************/
-       int     fv = r.edx;
-       TEST_FEATURE(fv, 1, "fpu")
-       TEST_FEATURE(fv, 2, "vme")
-       TEST_FEATURE(fv, 3, "de")
-       TEST_FEATURE(fv, 4, "pse")
-       TEST_FEATURE(fv, 5, "msr")
-       TEST_FEATURE(fv, 6, "pae")
-       TEST_FEATURE(fv, 7, "mce")
-       TEST_FEATURE(fv, 8, "cxs")
-       TEST_FEATURE(fv, 9, "apic")
-       //TEST_FEATURE(fv, 10, "Reserved")
-       //TEST_FEATURE(fv, 11, "SYSENTER/SYSEXIT")
-       TEST_FEATURE(fv, 12, "mttr")
-       TEST_FEATURE(fv, 13, "pge")     
-       TEST_FEATURE(fv, 14, "mca")
-       TEST_FEATURE(fv, 15, "cmov")
-       TEST_FEATURE(fv, 16, "pat")
-       TEST_FEATURE(fv, 17, "pse-36")
-       TEST_FEATURE(fv, 18, "psn")
-       TEST_FEATURE(fv, 19, "clflush")
-       //TEST_FEATURE(fv, 20, "Reserved")
-       TEST_FEATURE(fv, 21, "dts")
-       TEST_FEATURE(fv, 22, "acpi")
-       TEST_FEATURE(fv, 23, "mmx")
-       TEST_FEATURE(fv, 24, "fxsr")
-       TEST_FEATURE(fv, 25, "sse")
-       TEST_FEATURE(fv, 26, "sse2")
-       //TEST_FEATURE(fv, 27, "Reserved")
-       TEST_FEATURE(fv, 28, "ht")
-       TEST_FEATURE(fv, 29, "tm")
-       //TEST_FEATURE(fv, 30, "Reserved")
-       TEST_FEATURE(fv, 31, "pbe")
+     /**********************Get the CPU's Feature***********************/
+    int    fv = r.edx;
+    TEST_FEATURE(fv, 1, "fpu")
+    TEST_FEATURE(fv, 2, "vme")
+    TEST_FEATURE(fv, 3, "de")
+    TEST_FEATURE(fv, 4, "pse")
+    TEST_FEATURE(fv, 5, "msr")
+    TEST_FEATURE(fv, 6, "pae")
+    TEST_FEATURE(fv, 7, "mce")
+    TEST_FEATURE(fv, 8, "cxs")
+    TEST_FEATURE(fv, 9, "apic")
+    //TEST_FEATURE(fv, 10, "Reserved")
+    //TEST_FEATURE(fv, 11, "SYSENTER/SYSEXIT")
+    TEST_FEATURE(fv, 12, "mttr")
+    TEST_FEATURE(fv, 13, "pge")    
+    TEST_FEATURE(fv, 14, "mca")
+    TEST_FEATURE(fv, 15, "cmov")
+    TEST_FEATURE(fv, 16, "pat")
+    TEST_FEATURE(fv, 17, "pse-36")
+    TEST_FEATURE(fv, 18, "psn")
+    TEST_FEATURE(fv, 19, "clflush")
+    //TEST_FEATURE(fv, 20, "Reserved")
+    TEST_FEATURE(fv, 21, "dts")
+    TEST_FEATURE(fv, 22, "acpi")
+    TEST_FEATURE(fv, 23, "mmx")
+    TEST_FEATURE(fv, 24, "fxsr")
+    TEST_FEATURE(fv, 25, "sse")
+    TEST_FEATURE(fv, 26, "sse2")
+    //TEST_FEATURE(fv, 27, "Reserved")
+    TEST_FEATURE(fv, 28, "ht")
+    TEST_FEATURE(fv, 29, "tm")
+    //TEST_FEATURE(fv, 30, "Reserved")
+    TEST_FEATURE(fv, 31, "pbe")
 
-       printk(" x %d Cores\n",pn);
+    printk(" x %d Cores\n",pn);
 
-       if(!((1UL<<11) & fv))
-       {
-               printk("Your CPU Do Not Support SYSENTER/SYSEXIT\n");
-               while(1);
-       }
-       
+    if(!((1UL<<11) & fv))
+    {
+        printk("Your CPU Do Not Support SYSENTER/SYSEXIT\n");
+        while(1);
+    }
+    
 }
index b9a2e79e72eb4f6e3af08d4622f51dcce989100a..5a70a32418893a7cc895ecacbf4b6d5615c673a9 100644 (file)
@@ -1,11 +1,11 @@
-#include<string.h>
+#include <string.h>
 extern const char *version;
 extern void printString(const char *s, unsigned char color);
 void show_logo()
 {
 #if 1
 int i;
-#define        VER_SIZE        81
+#define VER_SIZE    81
 char ver[VER_SIZE];
 memset(ver, ' ', VER_SIZE);
 ver[VER_SIZE-1] = 0;
@@ -26,20 +26,20 @@ printString(
 memset(ver, ' ', VER_SIZE);
 strcpy(ver, version);
 for(i=0; i<VER_SIZE; i++)
-       if(ver[i] == '\0')
-       {
-               ver[i] = ' ';
-               break;
-       }
+    if(ver[i] == '\0')
+    {
+        ver[i] = ' ';
+        break;
+    }
 ver[VER_SIZE-1] = 0;
 printString(ver, 0x70);
 #endif
 #if 0
 for(i=1; i<80*1*2; i+=2)
-       *((unsigned char *)(0xB8000+i)) = 0x00;
+    *((unsigned char *)(0xB8000+i)) = 0x00;
 for(i=1+80*1*2; i<80*9*2; i+=2)
-       *((unsigned char *)(0xB8000+i)) = 0x1F;
+    *((unsigned char *)(0xB8000+i)) = 0x1F;
 for(i=1+80*9*2; i<80*10*2; i+=2)
-       *((unsigned char *)(0xB8000+i)) = 0x7F;
+    *((unsigned char *)(0xB8000+i)) = 0x7F;
 #endif
 }
index d7d5d638fbbf5e04ab58e1122bf6b3e038286a7c..72011a6a08d61f0839c1e8ceb4529776069b9925 100644 (file)
@@ -13,9 +13,9 @@
  * 
  *--------------------------------------------------------------------------
  */
-#include<bits.h>
-#include<printk.h>
-#include<system.h>
+#include <bits.h>
+#include <printk.h>
+#include <system.h>
 
 extern void setup_gdt();
 extern void setup_idt();
index e9a3f2e04a073985427670defaf0660e8d6e802e..b79581131cecf4d72dce7084d02da1984dfc14fb 100644 (file)
 /*
  *--------------------------------------------------------------------------
- *   File Name:        system.c
+ *   File Name: system.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Wed Mar  4 21:34:47 2009
  * Last Update: Wed Mar  4 21:34:47 2009
  * 
  *--------------------------------------------------------------------------
  */
 
-#include<system.h>
-#include<string.h>
-#include<processor.h>
-#include<page.h>
-#include<irq.h>
-#include<sched.h>
-#include<assert.h>
-#include<i8259.h>
-#include<fs.h>
-
-void   setup_gdt()
+#include <system.h>
+#include <string.h>
+#include <processor.h>
+#include <page.h>
+#include <irq.h>
+#include <sched.h>
+#include <assert.h>
+#include <i8259.h>
+#include <fs.h>
+
+void    setup_gdt()
 {
-       pDesc   pdesc;
-       //change to new gdt.
-       sgdt();
-       memcpy(gdt, (void *)*((unsigned long*)(gdtr+2)),
-                               *((unsigned short *)gdtr));
-       *((unsigned short *)gdtr)       = NGDT*sizeof(Desc);
-       *((unsigned long  *)(gdtr+2))   = (unsigned long)gdt;
-       lgdt();
-       memcpy(gdt+INDEX_UCODE, gdt+INDEX_KCODE, sizeof(Desc));
-       memcpy(gdt+INDEX_UDATA, gdt+INDEX_KDATA, sizeof(Desc));
-       pdesc = gdt+INDEX_UCODE;
-       pdesc->seg.DPL = 3;
-       pdesc = gdt+INDEX_UDATA;
-       pdesc->seg.DPL = 3;
+    pDesc    pdesc;
+    //change to new gdt.
+    sgdt();
+    memcpy(gdt, (void *)*((unsigned long*)(gdtr+2)),
+                *((unsigned short *)gdtr));
+    *((unsigned short *)gdtr)    = NGDT*sizeof(Desc);
+    *((unsigned long  *)(gdtr+2))    = (unsigned long)gdt;
+    lgdt();
+    memcpy(gdt+INDEX_UCODE, gdt+INDEX_KCODE, sizeof(Desc));
+    memcpy(gdt+INDEX_UDATA, gdt+INDEX_KDATA, sizeof(Desc));
+    pdesc = gdt+INDEX_UCODE;
+    pdesc->seg.DPL = 3;
+    pdesc = gdt+INDEX_UDATA;
+    pdesc->seg.DPL = 3;
 }
 
-void   setup_idt()
+void    setup_idt()
 {
-       //init idt.
-       *((unsigned short *)idtr)       = NIDT*sizeof(Gate);
-       *((unsigned long  *)(idtr+2))   = (unsigned long)idt;
-       lidt();
+    //init idt.
+    *((unsigned short *)idtr)    = NIDT*sizeof(Gate);
+    *((unsigned long  *)(idtr+2))    = (unsigned long)idt;
+    lidt();
 }
 void no_irq_handler()
 {
-       printk("no_irq_handler");
-       while(1);
+    printk("no_irq_handler");
+    while(1);
 }
 
-void   setup_gate()
-{      int i;
-#define        set_sys_int(vect, type, DPL, handler)           \
-do{                                                    \
-       extern  void    handler ();                     \
-       set_idt_gate(vect, (u32)handler, type, DPL);    \
+void    setup_gate()
+{    int i;
+#define set_sys_int(vect, type, DPL, handler)        \
+do{                            \
+    extern    void    handler ();            \
+    set_idt_gate(vect, (u32)handler, type, DPL);    \
 }while(0)
 
-#define        PL_KRNL PRIVILEGE_KRNL
-#define        PL_USER PRIVILEGE_USER
+#define PL_KRNL    PRIVILEGE_KRNL
+#define PL_USER    PRIVILEGE_USER
 #if 1
-       set_sys_int(0x00, TRAP_GATE, PL_KRNL, DivideError);
-       set_sys_int(0x01, TRAP_GATE, PL_KRNL, Debug);
-       set_sys_int(0x02, INTR_GATE, PL_KRNL, NMI);     
-       set_sys_int(0x03, TRAP_GATE, PL_USER, BreakPoint);      
-       set_sys_int(0x04, TRAP_GATE, PL_USER, OverFlow);        
-       set_sys_int(0x05, TRAP_GATE, PL_USER, BoundsCheck);     
-       set_sys_int(0x06, TRAP_GATE, PL_KRNL, InvalidOpcode);   
-       set_sys_int(0x07, TRAP_GATE, PL_KRNL, DeviceNotAvailable);      
-       set_sys_int(0x08, TRAP_GATE, PL_KRNL, DoubleFault);     
-       set_sys_int(0x09, TRAP_GATE, PL_KRNL, CoprocSegOverRun);        
-       set_sys_int(0x0A, TRAP_GATE, PL_KRNL, InvalidTss);      
-       set_sys_int(0x0B, TRAP_GATE, PL_KRNL, SegNotPresent);   
-       set_sys_int(0x0C, TRAP_GATE, PL_KRNL, StackFault);      
-       set_sys_int(0x0D, TRAP_GATE, PL_KRNL, GeneralProtection);       
-       set_sys_int(0x0E, TRAP_GATE, PL_KRNL, PageFault);       
-       set_sys_int(0x10, TRAP_GATE, PL_KRNL, CoprocError);
-
-       for(i=0x20; i<256; i++)
-               set_sys_int(i, INTR_GATE, PL_KRNL, no_irq_handler);
-
-       set_sys_int(0x20, INTR_GATE, PL_KRNL, irq_0x00_handler);
-       set_sys_int(0x21, INTR_GATE, PL_KRNL, irq_0x01_handler);        
-       set_sys_int(0x22, INTR_GATE, PL_KRNL, irq_0x02_handler);        
-       set_sys_int(0x23, INTR_GATE, PL_KRNL, irq_0x03_handler);        
-       set_sys_int(0x24, INTR_GATE, PL_KRNL, irq_0x04_handler);        
-       set_sys_int(0x25, INTR_GATE, PL_KRNL, irq_0x05_handler);        
-       set_sys_int(0x26, INTR_GATE, PL_KRNL, irq_0x06_handler);        
-       set_sys_int(0x27, INTR_GATE, PL_KRNL, irq_0x07_handler);        
-       set_sys_int(0x28, INTR_GATE, PL_KRNL, irq_0x08_handler);        
-       set_sys_int(0x29, INTR_GATE, PL_KRNL, irq_0x09_handler);        
-       set_sys_int(0x2A, INTR_GATE, PL_KRNL, irq_0x0A_handler);        
-       set_sys_int(0x2B, INTR_GATE, PL_KRNL, irq_0x0B_handler);        
-       set_sys_int(0x2C, INTR_GATE, PL_KRNL, irq_0x0C_handler);        
-       set_sys_int(0x2D, INTR_GATE, PL_KRNL, irq_0x0D_handler);        
-       set_sys_int(0x2E, INTR_GATE, PL_KRNL, irq_0x0E_handler);        
-       set_sys_int(0x2F, INTR_GATE, PL_KRNL, irq_0x0F_handler);        
+    set_sys_int(0x00, TRAP_GATE, PL_KRNL, DivideError);
+    set_sys_int(0x01, TRAP_GATE, PL_KRNL, Debug);
+    set_sys_int(0x02, INTR_GATE, PL_KRNL, NMI);    
+    set_sys_int(0x03, TRAP_GATE, PL_USER, BreakPoint);    
+    set_sys_int(0x04, TRAP_GATE, PL_USER, OverFlow);    
+    set_sys_int(0x05, TRAP_GATE, PL_USER, BoundsCheck);    
+    set_sys_int(0x06, TRAP_GATE, PL_KRNL, InvalidOpcode);    
+    set_sys_int(0x07, TRAP_GATE, PL_KRNL, DeviceNotAvailable);    
+    set_sys_int(0x08, TRAP_GATE, PL_KRNL, DoubleFault);    
+    set_sys_int(0x09, TRAP_GATE, PL_KRNL, CoprocSegOverRun);    
+    set_sys_int(0x0A, TRAP_GATE, PL_KRNL, InvalidTss);    
+    set_sys_int(0x0B, TRAP_GATE, PL_KRNL, SegNotPresent);    
+    set_sys_int(0x0C, TRAP_GATE, PL_KRNL, StackFault);    
+    set_sys_int(0x0D, TRAP_GATE, PL_KRNL, GeneralProtection);    
+    set_sys_int(0x0E, TRAP_GATE, PL_KRNL, PageFault);    
+    set_sys_int(0x10, TRAP_GATE, PL_KRNL, CoprocError);
+
+    for(i=0x20; i<256; i++)
+        set_sys_int(i, INTR_GATE, PL_KRNL, no_irq_handler);
+
+    set_sys_int(0x20, INTR_GATE, PL_KRNL, irq_0x00_handler);
+    set_sys_int(0x21, INTR_GATE, PL_KRNL, irq_0x01_handler);    
+    set_sys_int(0x22, INTR_GATE, PL_KRNL, irq_0x02_handler);    
+    set_sys_int(0x23, INTR_GATE, PL_KRNL, irq_0x03_handler);    
+    set_sys_int(0x24, INTR_GATE, PL_KRNL, irq_0x04_handler);    
+    set_sys_int(0x25, INTR_GATE, PL_KRNL, irq_0x05_handler);    
+    set_sys_int(0x26, INTR_GATE, PL_KRNL, irq_0x06_handler);    
+    set_sys_int(0x27, INTR_GATE, PL_KRNL, irq_0x07_handler);    
+    set_sys_int(0x28, INTR_GATE, PL_KRNL, irq_0x08_handler);    
+    set_sys_int(0x29, INTR_GATE, PL_KRNL, irq_0x09_handler);    
+    set_sys_int(0x2A, INTR_GATE, PL_KRNL, irq_0x0A_handler);    
+    set_sys_int(0x2B, INTR_GATE, PL_KRNL, irq_0x0B_handler);    
+    set_sys_int(0x2C, INTR_GATE, PL_KRNL, irq_0x0C_handler);    
+    set_sys_int(0x2D, INTR_GATE, PL_KRNL, irq_0x0D_handler);    
+    set_sys_int(0x2E, INTR_GATE, PL_KRNL, irq_0x0E_handler);    
+    set_sys_int(0x2F, INTR_GATE, PL_KRNL, irq_0x0F_handler);    
 #endif
 }
 
-void   setup_irqs()
+void    setup_irqs()
 {
-       extern  void init_i8259();
-       init_i8259();
-
-       int i;
-       for(i=0; i<NR_IRQS; i++)
-       {
-               irq_desc[i] = no_irq_desc;
-
-               if(i<16)
-                       irq_desc[i].chip = &i8259_chip;
-       }
-
-       //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");
-       enable_irq(0x00);
-       enable_irq(0x01);
-       enable_irq(0x0E);
-       
+    extern    void init_i8259();
+    init_i8259();
+
+    int i;
+    for(i=0; i<NR_IRQS; i++)
+    {
+        irq_desc[i] = no_irq_desc;
+
+        if(i<16)
+            irq_desc[i].chip = &i8259_chip;
+    }
+
+    //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");
+    enable_irq(0x00);
+    enable_irq(0x01);
+    enable_irq(0x0E);
+    
 
 /*
-       pIRQAction      pKbdAction, pClkAction;
+    pIRQAction    pKbdAction, pClkAction;
 
 
-       pKbdAction      = (pIRQAction) kmalloc(sizeof(IRQAction));
-       pClkAction      = (pIRQAction) kmalloc(sizeof(IRQAction));
+    pKbdAction    = (pIRQAction) kmalloc(sizeof(IRQAction));
+    pClkAction    = (pIRQAction) kmalloc(sizeof(IRQAction));
 
 
-       assert(pKbdAction != NULL);
-       assert(pClkAction != NULL);
+    assert(pKbdAction != NULL);
+    assert(pClkAction != NULL);
 
-       pClkAction->handler     = clk_handler;
-       pClkAction->next        = NULL;
-       pKbdAction->handler     = kbd_handler;
-       pKbdAction->next        = NULL;
+    pClkAction->handler    = clk_handler;
+    pClkAction->next    = NULL;
+    pKbdAction->handler    = kbd_handler;
+    pKbdAction->next    = NULL;
 
-       printk("**********%08x %08x", pKbdAction, pClkAction);
+    printk("**********%08x %08x", pKbdAction, pClkAction);
 
-       irq_desc[0x0].chip = &i8259_chip;
-       irq_desc[0x0].chip->enable(0x0);
-       irq_desc[0x0].action = pClkAction;
+    irq_desc[0x0].chip = &i8259_chip;
+    irq_desc[0x0].chip->enable(0x0);
+    irq_desc[0x0].action = pClkAction;
 
-       irq_desc[0x1].chip = &i8259_chip;
-       irq_desc[0x1].chip->enable(0x1);
-       irq_desc[0x1].action = pKbdAction;
+    irq_desc[0x1].chip = &i8259_chip;
+    irq_desc[0x1].chip->enable(0x1);
+    irq_desc[0x1].action = pKbdAction;
 */
 
 }
 
 
-void   set_tss()
+void    set_tss()
 {
-       pTSS p = &tss;
-       memset((void *)p, sizeof(TSS), 0);
-       p->esp0         = TASK_SIZE + (unsigned long)&RootTsk;
-       p->ss0          = SELECTOR_KRNL_DS;
-       p->ss           = SELECTOR_KRNL_DS;
-       p->gs           = SELECTOR_KRNL_DS;
-       p->fs           = SELECTOR_KRNL_DS;
-       p->es           = SELECTOR_KRNL_DS;
-       p->ds           = SELECTOR_KRNL_DS;
-       p->cs           = SELECTOR_KRNL_CS;
-       p->eflags       = 0x1200;
-       p->iomap_base   = sizeof(TSS);
-       set_tss_gate(INDEX_TSS, (u32)p);
-       //printk("TSS:%08x\n", p);
-       asm("ltr %%ax"::"a"((INDEX_TSS<<3)+3));
+    pTSS p = &tss;
+    memset((void *)p, sizeof(TSS), 0);
+    p->esp0        = TASK_SIZE + (unsigned long)&RootTsk;
+    p->ss0        = SELECTOR_KRNL_DS;
+    p->ss        = SELECTOR_KRNL_DS;
+    p->gs        = SELECTOR_KRNL_DS;
+    p->fs        = SELECTOR_KRNL_DS;
+    p->es        = SELECTOR_KRNL_DS;
+    p->ds        = SELECTOR_KRNL_DS;
+    p->cs        = SELECTOR_KRNL_CS;
+    p->eflags    = 0x1200;
+    p->iomap_base    = sizeof(TSS);
+    set_tss_gate(INDEX_TSS, (u32)p);
+    //printk("TSS:%08x\n", p);
+    asm("ltr %%ax"::"a"((INDEX_TSS<<3)+3));
 }
 
 void setup_root_dev()
 {
-       unsigned char dev;
-       dev = (unsigned char)(system.boot_device >> 24);
-       //if(dev != 0x80)
-       //      panic("OS must boot from the first hard disk");
+    unsigned char dev;
+    dev = (unsigned char)(system.boot_device >> 24);
+    //if(dev != 0x80)
+    //    panic("OS must boot from the first hard disk");
 
-       printk("root device: %08x\n", system.root_dev);
+    printk("root device: %08x\n", system.root_dev);
 #if 0
 
-       /* 
-        * 硬盘的次设备号
-        * 0: 整个硬盘
-        * 1-4: 主分区
-        * 5~N: 逻辑分区(N<2^16-5)
-        * 目录只支持从第一个硬盘引导.
-        */
-       int     minor = ((system.boot_device>>16) & 0xFF) + 1;
-       system.root_dev = MAKE_DEV(DEV_MAJOR_HD, minor);
+    /* 
+     * 硬盘的次设备号
+     * 0: 整个硬盘
+     * 1-4: 主分区
+     * 5~N: 逻辑分区(N<2^16-5)
+     * 目录只支持从第一个硬盘引导.
+     */
+    int    minor = ((system.boot_device>>16) & 0xFF) + 1;
+    system.root_dev = MAKE_DEV(DEV_MAJOR_HD, minor);
 #endif
 }
index 01292605df9eb5711707619c1ec1b84dfb6d9a5b..24173c1b202ed3b5dcadb6001f9fc069916272be 100644 (file)
@@ -1,23 +1,23 @@
 /*
  *--------------------------------------------------------------------------
- *   File Name:        version.c
+ *   File Name: version.c
  * 
- * Description:        none
+ * Description: none
  * 
  * 
- *      Author:        Zhao Yanbai [zhaoyanbai@126.com]
+ *      Author: Zhao Yanbai [zhaoyanbai@126.com]
  * 
- *     Version:        1.0
+ *     Version:    1.0
  * Create Date: Sat Mar  7 10:47:41 2009
  * Last Update: Sat Mar  7 10:47:41 2009
  * 
  *--------------------------------------------------------------------------
  */
-#define        VERSION "0.2.5 Final"
-#define        BUIDER  "Zhao Yanbai"
+#define VERSION    "0.2.5 Final"
+#define BUIDER    "Zhao Yanbai"
 const char *version = 
-       "Kernel "
-       VERSION
-       " Build on "__DATE__ " " __TIME__
-       " by "
-       BUIDER;
+    "Kernel "
+    VERSION
+    " Build on "__DATE__ " " __TIME__
+    " by "
+    BUIDER;