]> Zhao Yanbai Git Server - kernel.git/commitdiff
将已有的代码按统一的风格格式化
authoracevest <zhaoyanbai@126.com>
Wed, 31 Dec 2025 14:44:42 +0000 (22:44 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 31 Dec 2025 14:44:42 +0000 (22:44 +0800)
118 files changed:
.clang-format
bin/hello.c
bin/init.S
bin/shell.c
boot/acpi.c
boot/boot.c
boot/boot.h
boot/cmdline.c
boot/multiboot2_header.c
boot/reboot.S
boot/unpaged_boot.c
boot/vbe.c
doc/dev.md [deleted file]
drivers/ata.c
drivers/blk_rw.c
drivers/block.c
drivers/console.c
drivers/ide.c
drivers/ide.h
drivers/keyboard.c
drivers/pci.c
drivers/pci_members.c
drivers/sata.c
drivers/serial.c
fs/buffer.c
fs/dentry.c
fs/ext2.c
fs/ext2.h
fs/file.c
fs/fs.c
fs/fssysc.c
fs/inode.c
fs/mount.c
fs/mount.h
fs/open.c
fs/path.c
fs/ramfs.c
fs/read.c
fs/stat.c
fs/super.c
fs/vfs.c
fs/vfs.h
fs/write.c
include/assert.h
include/atomic.h
include/bits.h
include/buffer.h
include/bug.h
include/completion.h
include/cpuid.h
include/disk.h
include/fs.h
include/io.h
include/irq.h
include/list.h
include/mm.h
include/msr.h
include/page.h
include/pci.h
include/printk.h
include/processor.h
include/sched.h
include/semaphore.h
include/stdio.h
include/stdlib.h
include/string.h
include/system.h
include/task.h
include/tty.h
include/types.h
include/wait.h
kernel/apic.c
kernel/assert.c
kernel/clock.c
kernel/completion.c
kernel/cpuid.c
kernel/exec.c
kernel/exit.c
kernel/fork.c
kernel/i8259.c
kernel/innerint.c
kernel/irq.c
kernel/printk.c
kernel/sched.c
kernel/semaphore.c
kernel/setup.c
kernel/syscall.c
kernel/system.c
kernel/task_disk.c
kernel/task_init.c
kernel/task_root.c
kernel/task_user.c
kernel/time.c
kernel/tty.c
kernel/wait.c
lib/exec.c
lib/exit.c
lib/keyboard.c
lib/lib.c
lib/libc.S
lib/open.c
lib/read.c
lib/stat.c
lib/string.c
lib/syscall.c
lib/vsprintf.c
lib/wait.c
lib/write.c
mm/bootmem.c
mm/buddy.c
mm/kmem.c
mm/mm.c
mm/page.c
mm/slub.c
mm/slub.h
scripts/PCIMemberCompanies.py
scripts/archived/README.md [deleted file]
test_list.c

index 3db5ed9c18157f6f76ad16c150232d8f19d31efb..58d7356b470d2ef0824beada9d969f49e616d8cc 100644 (file)
@@ -1,10 +1,51 @@
----
+# 指定格式化语言为C
+Language: C
+
+# 基于Google的代码风格规范
 BasedOnStyle: Google
+
+# 每行最大字符数为120,超过会自动换行
 ColumnLimit: 120
+
+# 缩进宽度为4个空格
 IndentWidth: 4
+
+# Tab键宽度为4个空格
 TabWidth: 4
 
+# 不使用Tab键,全部用空格
+UseTab: Never
+
+# 左大括号不换行,保持与上一行在同一行
+BreakBeforeBraces: Attach
+
+# 预处理指令整体与代码块一起缩进
+# IndentPPDirectives: BeforeHash
+IndentPPDirectives: None
+
+# 不自动排序头文件,保持原有顺序
+SortIncludes: false
+
+# case标签不额外缩进(相对于switch语句)
 IndentCaseLabels: false
 
-# 行注释 "//" 前增加两个空格
+# 行尾注释前添加2个空格
 SpacesBeforeTrailingComments: 2
+
+# 不自动断行
+AllowAllParametersOfDeclarationOnNextLine: false
+
+# 禁止短代码块放在一行
+AllowShortBlocksOnASingleLine: false
+
+# 禁止短case标签放在一行
+AllowShortCaseLabelsOnASingleLine: false
+
+# 禁止短函数放在一行
+AllowShortFunctionsOnASingleLine: false
+
+# 禁止短if语句放在一行
+AllowShortIfStatementsOnASingleLine: false
+
+# 禁止短循环放在一行
+AllowShortLoopsOnASingleLine: false
index a2d5f823d8375e132264dc225e3d4639db14af27..fec6725eb65c08c0842c6415d3d199e6533a2fe3 100644 (file)
 #include <unistd.h>
 
 int main() {
-    while(1) {
+    while (1) {
         asm("nop;");
     }
-    //printf("hello world\n");
+    // printf("hello world\n");
 
     return 0;
 }
index e06a06b4a2266adfe5f70bf21c174c17b529a708..f3f13ec39ab884e2de8a4097d763ec9ff92795fd 100644 (file)
@@ -16,7 +16,7 @@ _start:
     nop;
     movl %esp,%ebp;
     nop;
-    movl $123,%ebx 
+    movl $123,%ebx
     movl $5,%eax # SYSC_WAIT
     sysenter;
 1:
index 8f68621f41a0bbab800fd1be8e0d1e943bd2d974..201d89d9b52e027be8f52237295ecacf3c720109 100644 (file)
@@ -25,7 +25,9 @@ int main() {
         read(0, cmd, 256);
 
         int len = strlen(cmd);
-        if (len > 0) cmd[len - 1] = 0;
+        if (len > 0) {
+            cmd[len - 1] = 0;
+        }
 
         int pid = fork();
         if (pid > 0) {
index 55c7db713c7b9d61f7d19ae3885bc189861cd783..7957c0a40c174cc59c72251eca098d01616152e2 100644 (file)
 #include <page.h>
 
 typedef struct {
-    char signature[8];        // "RSD PTR "
-    uint8_t checksum;         // 校验和
-    char oemid[6];            // OEM厂商ID
-    uint8_t revision;         // ACPI版本(0=1.0,2=2.0)
-    uint32_t rsdt_addr;       // 指向RSDT的物理地址
+    char signature[8];   // "RSD PTR "
+    uint8_t checksum;    // 校验和
+    char oemid[6];       // OEM厂商ID
+    uint8_t revision;    // ACPI版本(0=1.0,2=2.0)
+    uint32_t rsdt_addr;  // 指向RSDT的物理地址
 } __attribute__((packed)) rsdp_v1_t;
 
 // ACPI标准表头(所有表都有)
@@ -36,106 +36,99 @@ typedef struct {
 // RSDT(Root System Description Table)结构
 typedef struct {
     acpi_sdt_header_t header;
-    uint32_t table_ptrs[];     // 指向其他ACPI表的物理地址数组
+    uint32_t table_ptrs[];  // 指向其他ACPI表的物理地址数组
 } __attribute__((packed)) rsdt_t;
 
-
 typedef struct {
     acpi_sdt_header_t header;
-    uint32_t lapic_addr; // 本地APIC地址
+    uint32_t lapic_addr;  // 本地APIC地址
     uint32_t flags;
     // 后面跟着可变长度的结构
 } __attribute__((packed)) madt_t;
 
-
 void parse_madt(paddr_t addr) {
-    if(0 == addr) {
+    if (0 == addr) {
         printk("MADT addr is null\n");
         return;
     }
 
     page_map(addr, addr, PAGE_P | PAGE_WR);
 
-    madt_t *madt = (madt_t *)addr;
+    madt_t* madt = (madt_t*)addr;
     printk("MADT LAPIC addr %08x flags %08x\n", madt->lapic_addr, madt->flags);
 
-    uint8_t *ptr = (uint8_t *)(madt + 1); // 跳过表头
-    uint8_t *end = (uint8_t *)madt + madt->header.length;
+    uint8_t* ptr = (uint8_t*)(madt + 1);  // 跳过表头
+    uint8_t* end = (uint8_t*)madt + madt->header.length;
 
     uint32_t ioapic_cnt = 0;
     uint32_t lapic_cnt = 0;
 
-    while(ptr < end) {
-        uint8_t type = ptr[0]; // 条目类型
-        uint8_t length = ptr[1]; // 条目长度
+    while (ptr < end) {
+        uint8_t type = ptr[0];    // 条目类型
+        uint8_t length = ptr[1];  // 条目长度
 
-        if(0 == length) {
+        if (0 == length) {
             printk("invalid madt entry\n");
             break;
         }
 
-        switch(type) {
-            case 0: { // 本地APIC
-                uint8_t cpu_id = ptr[2];
-                uint8_t apic_id = ptr[3];
-                uint32_t flags = *(uint32_t *)(ptr+4);
-                if(1 == flags) {
-                    lapic_cnt++;
-                    printk("LAPIC cpu %u apic %u flags %08x\n", cpu_id, apic_id, flags);
-                } else {
-                    printk("LAPIC cpu %u apic %u flags %08x [disabled]\n", cpu_id, apic_id, flags);
-                }
-            }
-            break;
-            case 1: { // IO APIC
-                uint8_t ioapic_id = ptr[2];
-                uint8_t reserved = ptr[3];
-                uint32_t ioapic_addr = *(uint32_t *)(ptr+4);
-                uint32_t global_irq_base = *(uint32_t *)(ptr+8);
-                ioapic_cnt++;
-                printk("IOAPIC id %u addr %08x global_irq_base %u\n", ioapic_id, ioapic_addr, global_irq_base);
-            }
-            break;
-            case 2: { // IO APIC 中断源重映射
-                uint8_t bus = ptr[2];
-                uint8_t irq = ptr[3];
-                uint32_t global_irq = *(uint32_t *)(ptr+4);
-                uint16_t flags = *(uint16_t *)(ptr+8);
-                printk("IOAPIC irq %u global_irq %u flags %04x bus %u\n", irq, global_irq, flags, bus);
+        switch (type) {
+        case 0: {  // 本地APIC
+            uint8_t cpu_id = ptr[2];
+            uint8_t apic_id = ptr[3];
+            uint32_t flags = *(uint32_t*)(ptr + 4);
+            if (1 == flags) {
+                lapic_cnt++;
+                printk("LAPIC cpu %u apic %u flags %08x\n", cpu_id, apic_id, flags);
+            } else {
+                printk("LAPIC cpu %u apic %u flags %08x [disabled]\n", cpu_id, apic_id, flags);
             }
+        } break;
+        case 1: {  // IO APIC
+            uint8_t ioapic_id = ptr[2];
+            uint8_t reserved = ptr[3];
+            uint32_t ioapic_addr = *(uint32_t*)(ptr + 4);
+            uint32_t global_irq_base = *(uint32_t*)(ptr + 8);
+            ioapic_cnt++;
+            printk("IOAPIC id %u addr %08x global_irq_base %u\n", ioapic_id, ioapic_addr, global_irq_base);
+        } break;
+        case 2: {  // IO APIC 中断源重映射
+            uint8_t bus = ptr[2];
+            uint8_t irq = ptr[3];
+            uint32_t global_irq = *(uint32_t*)(ptr + 4);
+            uint16_t flags = *(uint16_t*)(ptr + 8);
+            printk("IOAPIC irq %u global_irq %u flags %04x bus %u\n", irq, global_irq, flags, bus);
+        } break;
+        case 3: {  // 本地APIC非统一中断
+            uint8_t cpu_id = ptr[2];
+            uint8_t apic_id = ptr[3];
+            uint8_t flags = ptr[4];
+            printk("LAPIC non-uniform cpu %u apic %u flags %02x\n", cpu_id, apic_id, flags);
+        } break;
+        case 4: {  // 虚拟化APIC
+            uint16_t reserved = *(uint16_t*)(ptr + 2);
+            uint32_t apic_addr = *(uint32_t*)(ptr + 4);
+            printk("Virtual APIC addr %08x\n", apic_addr);
+        } break;
+        default:
+            printk("unknown madt entry type %u\n", type);
             break;
-            case 3: { // 本地APIC非统一中断
-                uint8_t cpu_id = ptr[2];
-                uint8_t apic_id = ptr[3];
-                uint8_t flags = ptr[4];
-                printk("LAPIC non-uniform cpu %u apic %u flags %02x\n", cpu_id, apic_id, flags);
-            }
-            break;
-            case 4: { // 虚拟化APIC
-                uint16_t reserved = *(uint16_t *)(ptr+2);
-                uint32_t apic_addr = *(uint32_t *)(ptr+4);
-                printk("Virtual APIC addr %08x\n", apic_addr);
-            }
-            break;
-            default:
-                printk("unknown madt entry type %u\n", type);
-                break;
         }
         ptr += length;
     }
 }
 
 void parse_rsdt(paddr_t addr) {
-    if(0 == addr) {
+    if (0 == addr) {
         printk("RSDT addr is null\n");
         return;
     }
 
     page_map(addr, addr, PAGE_P | PAGE_WR);
 
-    rsdt_t *rsdt = (rsdt_t *)addr;
+    rsdt_t* rsdt = (rsdt_t*)addr;
     // 验证签名
-    if(memcmp(rsdt->header.signature, "RSDT", 4) != 0) {
+    if (memcmp(rsdt->header.signature, "RSDT", 4) != 0) {
         panic("ACPI RSDT invalid\n");
     }
 
@@ -147,47 +140,45 @@ void parse_rsdt(paddr_t addr) {
 
     printk("RSDT have %u ACPI tables\n", table_count);
 
-    for(int i=0; i<table_count; i++) {
+    for (int i = 0; i < table_count; i++) {
         uint32_t table_phys_addr = rsdt->table_ptrs[i];
         page_map((vaddr_t)table_phys_addr, (paddr_t)table_phys_addr, PAGE_P | PAGE_WR);
 
-        acpi_sdt_header_t *table = (acpi_sdt_header_t *)table_phys_addr;
-        if(table == 0) {
+        acpi_sdt_header_t* table = (acpi_sdt_header_t*)table_phys_addr;
+        if (table == 0) {
             printk("ACPI table %u:%x is null\n", i, table_phys_addr);
             continue;
         }
 
         char sig[5] = {0};
         memcpy(sig, table->signature, 4);
-        if(sig[0] == 0) {
+        if (sig[0] == 0) {
             continue;
         }
         printk("ACPI table %u signature %s addr %08x len %u\n", i, sig, table_phys_addr, table->length);
-        if(memcmp(sig, "APIC", 4) == 0) {
+        if (memcmp(sig, "APIC", 4) == 0) {
             parse_madt((paddr_t)table);
         }
     }
-
 }
 
-
-void parse_acpi(void *tag) {
+void parse_acpi(void* tag) {
     printk("ACPI[old].RSDP ");
-    struct multiboot_tag_old_acpi *acpi_tag = (struct multiboot_tag_old_acpi *)tag;
-    uint8_t *rsdp = (uint8_t *)acpi_tag->rsdp;
-    for(int i =0; i<acpi_tag->size; i++){
+    struct multiboot_tag_old_acpi* acpi_tag = (struct multiboot_tag_old_acpi*)tag;
+    uint8_t* rsdp = (uint8_t*)acpi_tag->rsdp;
+    for (int i = 0; i < acpi_tag->size; i++) {
         printk("%02x ", rsdp[i]);
     }
     printk("\n");
 
-    if(memcmp(rsdp, "RSD PTR ", 8) != 0) {
+    if (memcmp(rsdp, "RSD PTR ", 8) != 0) {
         panic("ACPI[old] RSDP invalid\n");
     }
-    rsdp_v1_t *rsdp_v1 = (rsdp_v1_t *)rsdp;
+    rsdp_v1_t* rsdp_v1 = (rsdp_v1_t*)rsdp;
     printk("ACPI[old] RSDP checksum %02x\n", rsdp_v1->checksum);
     printk("ACPI[old] RSDP OEM ID %6s\n", rsdp_v1->oemid);
     printk("ACPI[old] RSDP revision %u\n", rsdp_v1->revision);
     printk("ACPI[old] RSDP RSDT addr %08x\n", rsdp_v1->rsdt_addr);
 
-    system.rsdt_addr = (void *)rsdp_v1->rsdt_addr;
+    system.rsdt_addr = (void*)rsdp_v1->rsdt_addr;
 }
index 5f3fa451811702bf7f0cbac9c40982ecd7729f12..d30b077f38b22ba0871acf1e994f7c9e2d652c68 100644 (file)
@@ -20,8 +20,8 @@
 
 struct boot_params boot_params __attribute__((aligned(32)));
 
-void parse_cmdline(const char *cmdline);
-void init_vbe(void *, void *);
+void parse_cmdline(const charcmdline);
+void init_vbe(void*, void*);
 
 // ticks < 0 代表永远等待
 void boot_delay(int ticks) {
@@ -57,9 +57,9 @@ void set_tss();
 void setup_i8254(uint16_t);
 void setup_boot_irqs();
 
-void parse_framebuffer(void *addr) {
-    struct multiboot_tag_framebuffer *fb = (struct multiboot_tag_framebuffer *)addr;
-    if(0 == fb) {
+void parse_framebuffer(voidaddr) {
+    struct multiboot_tag_framebuffer* fb = (struct multiboot_tag_framebuffer*)addr;
+    if (0 == fb) {
         printk("no framebuffer info\n");
     }
 
@@ -94,19 +94,17 @@ void parse_framebuffer(void *addr) {
     uint8_t fb_bpp = fb->common.framebuffer_bpp;
     uint8_t fb_type = fb->common.framebuffer_type;
 
-
     system.vbe_phys_addr = fb_addr;
     system.x_resolution = fb_width;
     system.y_resolution = fb_height;
 
-    printk("type %u size %u addr %lx pitch %u width %u height %u bpp %u type %u\n",
-            type, size, fb_addr, fb_pitch, fb_width, fb_height, fb_bpp, fb_type);
+    printk("type %u size %u addr %lx pitch %u width %u height %u bpp %u type %u\n", type, size, fb_addr, fb_pitch,
+           fb_width, fb_height, fb_bpp, fb_type);
 
     // 直接就不打算支持32位以外的色深
     // assert(fb_bpp == 32);
 }
 
-
 void check_kernel(unsigned long addr, unsigned long magic) {
     init_serial();
 
@@ -137,17 +135,17 @@ void check_kernel(unsigned long addr, unsigned long magic) {
         printk("Your boot loader does not support multiboot.\n");
         boot_delay(-1);
     }
-    unsigned long total_size = *((unsigned long *)addr);
-    struct multiboot_tag *tag = (struct multiboot_tag *)(addr + 8);  // 跳过中间的 reserved 字段
+    unsigned long total_size = *((unsigned long*)addr);
+    struct multiboot_tag* tag = (struct multiboot_tag*)(addr + 8);  // 跳过中间的 reserved 字段
 
     printk("total size: %d tags: %x\n", total_size, tag);
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
-    struct multiboot_tag_basic_meminfo *mminfo = 0;
-    struct multiboot_tag_bootdev *bootdev = 0;
-    struct multiboot_tag_mmap *mmap_tag = 0;
-    struct multiboot_tag_vbe *vbe = 0;
-    struct multiboot_tag_framebuffer *fb = 0;
-    struct multiboot_tag_elf_sections *elf = 0;
+    struct multiboot_tag_basic_meminfomminfo = 0;
+    struct multiboot_tag_bootdevbootdev = 0;
+    struct multiboot_tag_mmapmmap_tag = 0;
+    struct multiboot_tag_vbevbe = 0;
+    struct multiboot_tag_framebufferfb = 0;
+    struct multiboot_tag_elf_sectionself = 0;
 
     boot_params.e820map.map_cnt = 0;
 
@@ -155,25 +153,25 @@ void check_kernel(unsigned long addr, unsigned long magic) {
         bool support = true;
         switch (tag->type) {
         case MULTIBOOT_TAG_TYPE_CMDLINE:
-            strlcpy(boot_params.cmdline, ((struct multiboot_tag_string *)tag)->string, sizeof(boot_params.cmdline));
+            strlcpy(boot_params.cmdline, ((struct multiboot_tag_string*)tag)->string, sizeof(boot_params.cmdline));
             parse_cmdline(boot_params.cmdline);
             break;
         case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
-            strlcpy(boot_params.bootloader, ((struct multiboot_tag_string *)tag)->string,
+            strlcpy(boot_params.bootloader, ((struct multiboot_tag_string*)tag)->string,
                     sizeof(boot_params.bootloader));
             break;
         case MULTIBOOT_TAG_TYPE_MODULE:
-            struct multiboot_tag_module *m = (struct multiboot_tag_module *)tag;
-            void *mod_start = (void *)m->mod_start;
+            struct multiboot_tag_module* m = (struct multiboot_tag_module*)tag;
+            void* mod_start = (void*)m->mod_start;
             printk("module 0x%08x - 0x%08x size %u cmdline %s\n", m->mod_start, m->mod_end, m->size, m->cmdline);
-            boot_params.boot_module_begin = (void *)m->mod_start;
-            boot_params.boot_module_end = (void *)m->mod_end;
+            boot_params.boot_module_begin = (void*)m->mod_start;
+            boot_params.boot_module_end = (void*)m->mod_end;
 #if 1
-            const uint32_t mod_magic = *(uint32_t *)(mod_start + 0);
-            const uint32_t mod_head_size = *(uint32_t *)(mod_start + 4);
-            const uint32_t mod_timestamp = *(uint32_t *)(mod_start + 8);
-            const uint32_t mod_file_entry_cnt = *(uint32_t *)(mod_start + 12);
-            const char *mod_name = (const char *)mod_start + 16;
+            const uint32_t mod_magic = *(uint32_t*)(mod_start + 0);
+            const uint32_t mod_head_size = *(uint32_t*)(mod_start + 4);
+            const uint32_t mod_timestamp = *(uint32_t*)(mod_start + 8);
+            const uint32_t mod_file_entry_cnt = *(uint32_t*)(mod_start + 12);
+            const char* mod_name = (const char*)mod_start + 16;
             printk("module magic %08x header size %u timestamp %u file entry cnt %u name %s \n", mod_magic,
                    mod_head_size, mod_timestamp, mod_file_entry_cnt, mod_name);
             void timestamp_to_date(uint32_t ts);
@@ -181,22 +179,22 @@ void check_kernel(unsigned long addr, unsigned long magic) {
 
             int file_entry_offset = mod_head_size;
             for (int i = 0; i < mod_file_entry_cnt; i++) {
-                void *fe = mod_start + file_entry_offset;
+                voidfe = mod_start + file_entry_offset;
 
-                const uint32_t fe_size = *(uint32_t *)(fe + 0);
-                const uint32_t fe_type = *(uint32_t *)(fe + 4);
-                const uint32_t fe_filesz = *(uint32_t *)(fe + 8);
-                const uint32_t fe_offset = *(uint32_t *)(fe + 12);
-                const char *fe_name = (const char *)(fe + 16);
+                const uint32_t fe_size = *(uint32_t*)(fe + 0);
+                const uint32_t fe_type = *(uint32_t*)(fe + 4);
+                const uint32_t fe_filesz = *(uint32_t*)(fe + 8);
+                const uint32_t fe_offset = *(uint32_t*)(fe + 12);
+                const char* fe_name = (const char*)(fe + 16);
 
                 file_entry_offset += fe_size;
 
-                void *fc = mod_start + fe_offset;
+                voidfc = mod_start + fe_offset;
 
                 printk("[fe:%u:%u] file size %u type %u name %s\n", i, fe_size, fe_filesz, fe_type, fe_name);
 
                 for (int k = 0; k < 16; k++) {
-                    uint8_t c = *(uint8_t *)(fc + k);
+                    uint8_t c = *(uint8_t*)(fc + k);
                     printk("%02X ", c);
                 }
                 printk("\n");
@@ -204,33 +202,33 @@ void check_kernel(unsigned long addr, unsigned long magic) {
 #endif
             break;
         case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
-            mminfo = (struct multiboot_tag_basic_meminfo *)tag;
+            mminfo = (struct multiboot_tag_basic_meminfo*)tag;
             // KB to Bytes
             // no need to concern about 64bit
             boot_params.mem_lower = mminfo->mem_lower << 10;
             boot_params.mem_upper = mminfo->mem_upper << 10;
             break;
         case MULTIBOOT_TAG_TYPE_BOOTDEV:
-            bootdev = (struct multiboot_tag_bootdev *)tag;
+            bootdev = (struct multiboot_tag_bootdev*)tag;
             boot_params.biosdev = bootdev->biosdev;
             boot_params.partition = bootdev->slice;
             boot_params.sub_partition = bootdev->part;
             break;
         case MULTIBOOT_TAG_TYPE_MMAP:
-            mmap_tag = (struct multiboot_tag_mmap *)tag;
-            multiboot_memory_map_t *mmap = mmap_tag->entries;
+            mmap_tag = (struct multiboot_tag_mmap*)tag;
+            multiboot_memory_map_tmmap = mmap_tag->entries;
             while (((multiboot_uint32_t)mmap) < (((multiboot_uint32_t)mmap_tag) + mmap_tag->size)) {
                 boot_params.e820map.map[boot_params.e820map.map_cnt].addr = mmap->addr;
                 boot_params.e820map.map[boot_params.e820map.map_cnt].size = mmap->len;
                 boot_params.e820map.map[boot_params.e820map.map_cnt].type = mmap->type;
                 boot_params.e820map.map_cnt++;
-                mmap = (multiboot_memory_map_t *)(((unsigned long)mmap) + mmap_tag->entry_size);
+                mmap = (multiboot_memory_map_t*)(((unsigned long)mmap) + mmap_tag->entry_size);
             }
             break;
         case MULTIBOOT_TAG_TYPE_VBE:
-            vbe = (struct multiboot_tag_vbe *)tag;
-            void *vci = (void *)vbe->vbe_control_info.external_specification;
-            void *vmi = (void *)vbe->vbe_mode_info.external_specification;
+            vbe = (struct multiboot_tag_vbe*)tag;
+            void* vci = (void*)vbe->vbe_control_info.external_specification;
+            void* vmi = (void*)vbe->vbe_mode_info.external_specification;
             printk("VBE[deprecated] mode %04x\n", vbe->vbe_mode);
             init_vbe(vci, vmi);
             break;
@@ -238,47 +236,46 @@ void check_kernel(unsigned long addr, unsigned long magic) {
             printk("frame buffer\n");
             parse_framebuffer(tag);
             break;
-        case MULTIBOOT_TAG_TYPE_ELF_SECTIONS:
-            {
-                elf = (struct multiboot_tag_elf_sections *)tag;
-                Elf32_Shdr *sections = (Elf32_Shdr *)elf->sections;
-                int sections_cnt = elf->num;
-
-                const char *strtab = 0;
-                Elf32_Shdr *strtab_section = 0;
-
-                for(int i=0; i<sections_cnt; i++) {
-                    Elf32_Shdr *section = sections + i;
-                    if (section->sh_type == 3/*SHT_STRTAB*/) {
-                        if (i == elf->shndx) {
-                            strtab_section = section;
-                            strtab = (const char *)pa2va(section->sh_addr);
-                            break;
-                        }
+        case MULTIBOOT_TAG_TYPE_ELF_SECTIONS: {
+            elf = (struct multiboot_tag_elf_sections*)tag;
+            Elf32_Shdr* sections = (Elf32_Shdr*)elf->sections;
+            int sections_cnt = elf->num;
+
+            const char* strtab = 0;
+            Elf32_Shdr* strtab_section = 0;
+
+            for (int i = 0; i < sections_cnt; i++) {
+                Elf32_Shdr* section = sections + i;
+                if (section->sh_type == 3 /*SHT_STRTAB*/) {
+                    if (i == elf->shndx) {
+                        strtab_section = section;
+                        strtab = (const char*)pa2va(section->sh_addr);
+                        break;
                     }
                 }
+            }
 
-                for (int i=0; i<sections_cnt; i++) {
-                    Elf32_Shdr *section = sections + i;
+            for (int i = 0; i < sections_cnt; i++) {
+                Elf32_Shdr* section = sections + i;
 
-                    const char *name = 0;
-                    if(strtab && section->sh_name < strtab_section->sh_size) {
-                        name = strtab + section->sh_name;
-                    }
-
-                    uint32_t addr = section->sh_addr;
-                    uint32_t size = section->sh_size;
-                    uint32_t type = section->sh_type;
-                    uint32_t flags = section->sh_flags;
-                    printk("%20s addr %08x size %08x type %08x flags %08x\n", name ? name : "(unnamed)", addr, size, type, flags);
+                const char* name = 0;
+                if (strtab && section->sh_name < strtab_section->sh_size) {
+                    name = strtab + section->sh_name;
                 }
+
+                uint32_t addr = section->sh_addr;
+                uint32_t size = section->sh_size;
+                uint32_t type = section->sh_type;
+                uint32_t flags = section->sh_flags;
+                printk("%20s addr %08x size %08x type %08x flags %08x\n", name ? name : "(unnamed)", addr, size, type,
+                       flags);
             }
-            break;
+        } break;
         case MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR:
-            printk("load base addr %08x\n", ((struct multiboot_tag_load_base_addr *)tag)->load_base_addr);
+            printk("load base addr %08x\n", ((struct multiboot_tag_load_base_addr*)tag)->load_base_addr);
             break;
         case MULTIBOOT_TAG_TYPE_ACPI_OLD:
-            extern void parse_acpi(void *);
+            extern void parse_acpi(void*);
             parse_acpi(tag);
             break;
         case MULTIBOOT_TAG_TYPE_ACPI_NEW:
@@ -291,7 +288,7 @@ void check_kernel(unsigned long addr, unsigned long magic) {
         printk("tag %x size %x\t[%ssupport]\n", tag->type, tag->size, support ? "" : "un");
         // next tag
         unsigned long size = (tag->size + 7) & (~7UL);
-        tag = (struct multiboot_tag *)(((unsigned long)tag) + size);
+        tag = (struct multiboot_tag*)(((unsigned long)tag) + size);
     }
 
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
@@ -334,9 +331,9 @@ void check_kernel(unsigned long addr, unsigned long magic) {
 #endif
 }
 
-extern void *kernel_begin;
-extern void *kernel_end;
-extern void *bootmem_bitmap_begin;
+extern voidkernel_begin;
+extern voidkernel_end;
+extern voidbootmem_bitmap_begin;
 
 void init_system_info() {
     system.kernel_begin = &kernel_begin;
index d236c8df70327235c42883f3077acca76e13ef6f..e58f7d9b313ab5f24fbee71653e62035444254f4 100644 (file)
@@ -44,8 +44,8 @@ struct boot_params {
     unsigned long mem_lower;  // in bytes
     unsigned long mem_upper;
 
-    void *boot_module_begin;
-    void *boot_module_end;
+    voidboot_module_begin;
+    voidboot_module_end;
 
     unsigned long biosdev;
     unsigned long partition;
@@ -61,7 +61,7 @@ typedef struct bootmem_data {
     // 准备分配的超始pfn
     unsigned long prepare_alloc_pfn;
 
-    void *bitmap;
+    voidbitmap;
     unsigned long mapsize;
 } bootmem_data_t;
 
index dfb8c8bca6728ed70f67831feaf99bc691e6b85e..3133e7d5045ba56c1d292cb930a99a077a9da3ea 100644 (file)
 #include <string.h>
 #include <system.h>
 
-static void get_value(const char *name, char *value) {
-    const char *p;
+static void get_value(const char* name, char* value) {
+    const charp;
     if (0 != (p = strstr(system.cmdline, name))) {
         if (0 != (p = strstr(p, "="))) {
             p++;
-            while (*p != ' ' && *p != 0) *value++ = *p++;
+            while (*p != ' ' && *p != 0) {
+                *value++ = *p++;
+            }
         }
     }
 
     *value = 0;
 }
 
-void parse_cmdline(const char *cmdline) {
+void parse_cmdline(const charcmdline) {
     char value[128];
     system.cmdline = cmdline;
     printk("cmdline: %s\n", system.cmdline);
index 18b6639a384bb909ce9cbf49509f9a41b456145d..cce1bff7adf587333ce723fff2642fe6a5d80c4b 100644 (file)
@@ -7,11 +7,8 @@
  * ------------------------------------------------------------------------
  */
 
-
-
 #include <multiboot2.h>
 
-
 // 启用FB这个功能,需要修改grub.cfg,添加如下内容
 // load_video
 // set gfxmode=auto
@@ -29,32 +26,32 @@ typedef struct ALIGN8 multiboot2_elf_header {
     ALIGN8 struct multiboot_header_tag end;
 } multiboot2_bin_header_t;
 
-
-
-__attribute__((section(".multiboot2_header"), used))
-const multiboot2_bin_header_t multiboot2_elf_header = {
-    .header = {
-        .magic = MULTIBOOT2_HEADER_MAGIC,
-        .architecture = MULTIBOOT_ARCHITECTURE_I386,
-        .header_length = sizeof(multiboot2_bin_header_t),
-        .checksum = -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + sizeof(multiboot2_bin_header_t)),
-    },
+__attribute__((section(".multiboot2_header"), used)) const multiboot2_bin_header_t multiboot2_elf_header = {
+    .header =
+        {
+            .magic = MULTIBOOT2_HEADER_MAGIC,
+            .architecture = MULTIBOOT_ARCHITECTURE_I386,
+            .header_length = sizeof(multiboot2_bin_header_t),
+            .checksum = -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + sizeof(multiboot2_bin_header_t)),
+        },
 #if ENABLE_FB
-    .fb = {
-        .type = MULTIBOOT_HEADER_TAG_FRAMEBUFFER,
-        .flags = MULTIBOOT_HEADER_TAG_OPTIONAL,
-        .size = sizeof(struct multiboot_header_tag_framebuffer),
-        .width = 1024,
-        .height = 768,
-        .depth = 32,
-    },
+    .fb =
+        {
+            .type = MULTIBOOT_HEADER_TAG_FRAMEBUFFER,
+            .flags = MULTIBOOT_HEADER_TAG_OPTIONAL,
+            .size = sizeof(struct multiboot_header_tag_framebuffer),
+            .width = 1024,
+            .height = 768,
+            .depth = 32,
+        },
 #endif
-    .end = {
-        // tags are terminated by a tag of type ‘0’ and size ‘8’.
-        // MULTIBOOT_HEADER_TAG_END == 0
-        // sizeof(struct multiboot_header_tag) == 8
-        .type = MULTIBOOT_HEADER_TAG_END,
-        .flags = 0,
-        .size = sizeof(struct multiboot_header_tag),
-    },
+    .end =
+        {
+            // tags are terminated by a tag of type ‘0’ and size ‘8’.
+            // MULTIBOOT_HEADER_TAG_END == 0
+            // sizeof(struct multiboot_header_tag) == 8
+            .type = MULTIBOOT_HEADER_TAG_END,
+            .flags = 0,
+            .size = sizeof(struct multiboot_header_tag),
+        },
 };
index aabea799fd4b0e8e69f6da5d10689025c642015d..ef206fc992f1aa67ec4ef47411e0d951ac195354 100644 (file)
@@ -1,16 +1,16 @@
 /*
  *--------------------------------------------------------------------------
  *   File Name: reboot.S
- * 
+ *
  * Description: none
- * 
- * 
+ *
+ *
  *      Author: Zhao Yanbai [zhaoyanbai@126.com]
- * 
+ *
  *     Version:    1.0
  * Create Date: Sat Jul 11 19:16:42 2009
  * Last Update: Sat Jul 11 19:16:42 2009
- * 
+ *
  *--------------------------------------------------------------------------
  */
 #define ASM
@@ -60,7 +60,7 @@ _do_reboot:
     outb    %al,%dx
 
 
-    # Prepare Paging For Reboot 
+    # Prepare Paging For Reboot
     movl    $256,%ecx
     movl    $0x100C00,%esi
     movl    $0x100000,%edi
index 175ec2e2bc29f6640bcf1367baca4299b2ca3f9e..53d67ef9d3b0bc18be09998227a7f2a44e698596 100644 (file)
@@ -7,13 +7,11 @@
  * ------------------------------------------------------------------------
  */
 
-#include <types.h>
+#include <boot.h>
+#include <linkage.h>
 #include <msr.h>
 #include <page.h>
-#include <linkage.h>
-#include <boot.h>
-
-
+#include <types.h>
 
 extern unsigned long kernel_virtual_addr_start;
 extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
@@ -29,28 +27,27 @@ void boot_paging() {
     unsigned long init_pgt_paddr = va2pa(init_pgt);
 
     // 清空页目录
-    pde_t *dir =(pde_t *)init_pgd_paddr;
-    for(int i=0; i<PDECNT_PER_PAGE; i++) {
+    pde_t* dir = (pde_t*)init_pgd_paddr;
+    for (int i = 0; i < PDECNT_PER_PAGE; i++) {
         dir[i] = 0;
     }
 
     // 初始化页目录
     unsigned long kpde_base = get_npde((unsigned long)(&kernel_virtual_addr_start));
     pde_t pd_entry = init_pgt_paddr | PAGE_WR | PAGE_P;
-    for(int i=0; i<BOOT_INIT_PAGETBL_CNT; i++) {
-        dir[i] = pd_entry; // 设置低端线性地址空间的页表项
-        dir[kpde_base+i] = pd_entry; // 设置内核线性地址空间的页表项
+    for (int i = 0; i < BOOT_INIT_PAGETBL_CNT; i++) {
+        dir[i] = pd_entry;              // 设置低端线性地址空间的页表项
+        dir[kpde_base + i] = pd_entry;  // 设置内核线性地址空间的页表项
         pd_entry += PAGE_SIZE;
     }
 
-
-    pte_t *table = (pte_t *)init_pgt_paddr;
+    pte_t* table = (pte_t*)init_pgt_paddr;
     pte_t pt_entry = PAGE_WR | PAGE_P;
-    for(int i=0; i<BOOT_INIT_PAGETBL_CNT*PTECNT_PER_PAGE; i++) {
+    for (int i = 0; i < BOOT_INIT_PAGETBL_CNT * PTECNT_PER_PAGE; i++) {
         table[i] = pt_entry;
         pt_entry += PAGE_SIZE;
     }
 
     // 设置页目录
-    asm volatile("mov %0, %%cr3"::"r"(init_pgd_paddr));
+    asm volatile("mov %0, %%cr3" ::"r"(init_pgd_paddr));
 }
index 57913b21cc2e3b0e1ac7223e772aff1935962dec..140b994cc8377b05e9d1dc79090aab92f2ef6790 100644 (file)
@@ -114,21 +114,23 @@ typedef struct vbe_mode_info {
 
 // pte_t vbe_pte[PTECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
 
-uint32_t segoff_to_addr(segoff_t sg) { return 0xC0000000 + (sg.segment << 4) + sg.offset; }
+uint32_t segoff_to_addr(segoff_t sg) {
+    return 0xC0000000 + (sg.segment << 4) + sg.offset;
+}
 
-vbe_mode_info_t *get_vbe_mode_info(uint16_t) {
+vbe_mode_info_tget_vbe_mode_info(uint16_t) {
     // 设置并执行实模式代码以调用 VBE 函数 0x4F01
     // 返回指向 VBE 模式信息的指针
     return NULL;
 }
 // extern pde_t init_pgd[];
-void init_vbe(void *vciptr, void *vmiptr) {
+void init_vbe(void* vciptr, void* vmiptr) {
     // VBE是传统BIOS接口,在现代系统上可能没有被正确初始化
     // 也无法在保护模式下调用VBE BIOS功能
     // 因此这里只是打印VBE信息
     // 更可靠的数据是 MULTIBOOT_TAG_TYPE_FRAMEBUFFER 的数据
-    vbe_controller_info_t *vci = vciptr;
-    vbe_mode_info_t *vmi = (vbe_mode_info_t *)vmiptr;
+    vbe_controller_info_tvci = vciptr;
+    vbe_mode_info_t* vmi = (vbe_mode_info_t*)vmiptr;
 
     printk("VBE[deprecated]:\n");
     printk("Signature %c%c%c%c\n", vci->signature[0], vci->signature[1], vci->signature[2], vci->signature[3]);
@@ -140,11 +142,11 @@ void init_vbe(void *vciptr, void *vmiptr) {
     printk("OEM product rev: %s\n", segoff_to_addr(vci->oem_product_rev_ptr));
 
     printk("SEG %04X OFFSET %04X\n", vci->video_mode_ptr.segment, vci->video_mode_ptr.offset);
-    uint16_t *modes = (uint16_t *)segoff_to_addr(vci->video_mode_ptr);
+    uint16_t* modes = (uint16_t*)segoff_to_addr(vci->video_mode_ptr);
     printk("vbe modes:");
     while (*modes != VBE_MODE_END) {
         printk(" %04x", *modes);
-        vbe_mode_info_t *mi = get_vbe_mode_info(*modes);
+        vbe_mode_info_tmi = get_vbe_mode_info(*modes);
 
         // 目前以下判断不会生效
         if ((mi != 0) && (mi->mode_attributes & 0x01)) {
@@ -155,7 +157,8 @@ void init_vbe(void *vciptr, void *vmiptr) {
     }
     printk("\n");
 
-    printk("vbe[deprecated] phys addr %08x resolution %u x %u\n", vmi->phys_base_ptr, vmi->x_resolution, vmi->y_resolution);
+    printk("vbe[deprecated] phys addr %08x resolution %u x %u\n", vmi->phys_base_ptr, vmi->x_resolution,
+           vmi->y_resolution);
 #if 0
     system.vbe_phys_addr = vmi->phys_base_ptr;
     system.x_resolution = vmi->x_resolution;
diff --git a/doc/dev.md b/doc/dev.md
deleted file mode 100644 (file)
index 057a568..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-# 开发日志
-
-这个文件主要用来记录特定版本的代码存在的主要问题,及修改方向。
-
-## 18cf417585b83e74d413f247fd578f2654e8c177 版本问题
-
-目前中断下半部处理有一个问题:就是第一个中断正在进行下半部分开中断处理的情况下,被第二个中断处理中断后,如果第二个中断处理有下半部处理需求,是无法得到调用的。因为第二个中断处理会直接返回不会调用下半部处理逻辑。
-
-## 92ca4828ee74f800ba3bdd132f162a739075d9f2 版本问题
-
-这个版本的问题表现是运行一段时间后,会在`clock_bh_handler`的`assert(p->state == TASK_WAIT);`处断言失败。经分析问题出在`sysc_wait`处。
-
-需要指明的前提是,目前版本代码在系统调用中上下文中还没有添加抢占相关的逻辑。
-
-
-```c
-128 int sysc_wait(unsigned long cnt) {
-129     unsigned long flags;
-130     irq_save(flags);
-131     current->state = TASK_WAIT;
-132     current->delay_jiffies = jiffies + cnt;
-133     list_add(&current->pend, &delay_tasks);
-134     irq_restore(flags);
-135 
-136     schedule();
-137 }
-```
-
-```c
-182 void schedule() {
-        ......
-193     unsigned long iflags;
-194     irq_save(iflags);
-195 
-196     if (0 == current->ticks) {
-197         current->turn++;
-198         current->ticks = current->priority;
-199         current->state = TASK_READY;
-200     }
-```
-
-这段代码在第`sysc_wait:134`行开中断,在`schedule:193`处再关中断。那么中断程序完全可能在这两个点之间中断这个逻辑,再叠加上ticks被减到`0`需要重新调度的条件就会出现该问题。
-
-问题路径:
-
-1. `current->ticks == 1`
-2. 程序执行到`sysc_wait:134`和`schedule:193`之间
-3. 时钟中断到达且时钟中断没有嵌套在其它中断的下半部分逻辑中
-4. 时钟中断将`current-ticks`减`1`至`0`
-5. 在时钟中断退出前调用`schedule`,
-6. `schedule`在判断到`current->ticks == 0`时无视其`TASK_WAIT`的状态,将其设置为`TASK_READY`
-7. 再次时钟中断到达,判断到睡眠队列里出现了`TASK_READY`状态的任务。
-
-### 修改方案1
-
-修改逻辑为在`schedule`完成前,不允许中断。
-
-```c
-int sysc_wait(unsigned long cnt) {
-    unsigned long flags;
-    irq_save(flags);
-    current->state = TASK_WAIT;
-    current->delay_jiffies = jiffies + cnt;
-    list_add(&current->pend, &delay_tasks);
-
-    schedule();
-
-    irq_restore(flags);
-}
-```
-
-### 修改方案2
-
-在`schedule`的逻辑加入只对`TASK_RUNNING`改成`TASK_READY`。
-
-```c
-    if (0 == current->ticks) {
-        current->turn++;
-        current->ticks = current->priority;
-    }
-
-    if (current->state == TASK_RUNNING) {
-        current->state = TASK_READY;
-    }
-```
-
-目前准备采用方案2修复。
-
-## 001073af2176de114d8588124d665aad2b4f2995 版本问题
-
-### 问题表现
-
-虽然在`kernel/sched.c:schedule`里如果`0 == current->ticks`则会将其重置的逻辑,但在`clock_handler`里的`current->ticks-`代码任有可能将其值减到0后继续再减进而溢出。就算是`schedule`代码里的处理逻辑已经是在关中断的情况下进行的也无济于事。
-
-将`qemu`的速度调至10%比较容易复现这个问题。
-
-### 问题原因
-
-在这个版本中,由于在`clock_handler`里塞了过多的调试代码,导致其耗时很长。这就可能会出现如下处理序列:
-
-1. 处理器进入硬盘`14`号中断的处理逻辑
-2. 如果硬盘中断逻辑已经到达开中断的部分
-3. 这时时钟中断到达,则会中断当前硬盘中断转而执行时钟中断。
-4. 时钟中断执行`current->ticks--`,其值有可能从`1`变为`0`
-5. 时钟中断占用相当长时间,甚至超过两次时钟中断间隔
-6. 时钟中断返回前判断到当前中断处于嵌套状态,不执行重新调度,此时`current->ticks == 0`。
-7. 时钟中断返回
-8. 由于上一个时钟中断耗时过长,因此当其刚返回后,14号中断还没来得及继续执行,或者刚执行了有限的几条指令,又被下一个时钟中断打断。
-9. 重复以上逻辑,这个时钟中断逻辑就继续对`current->ticks`减`1`,使其值为`0xFFFFFFFF`。
-
-### 问题修复计划
-
-### 优化中断处理服务程序
-
-只写少量必要代码,尽快返回,不再加入大量调试程序。
-
-#### 不再支持中断嵌套
-
-不支持中断嵌套仅指不嵌套执行中断服务器程序,而其它需要在中断环境执行的逻辑是可以开中断执行的,也就是有再次被新中断打断的可能。
-
-不再支持中断嵌套后,每次中断处理过程大致如下
-
-1. 硬件触发中断,自动关中断
-2. 保存上下文
-3. 执行中断服务例程
-3. 开中断
-4. 执行其它逻辑
-5. 关中断
-6. 恢复上下文返回
-
-可以到第4步是在开中断的状态下执行的。而执行它的时候是可能被新到的中断程序再次打断的,也就是第4步是可能嵌套执行的。
-
-为了避免这种情况,将上述程序引入一个`int`型的全局变更`reenter`,并将其初始化为`-1`后再做修改
-
-1. 硬件触发中断,自动关中断
-2. 保存上下文
-3. `reenter++`
-4. 执行中断服务例程
-5. 判断`reenter != 0`则跳转到第`9`步
-6. 开中断
-7. 执行其它逻辑
-8. 关中断
-9. `reenter--`
-10. 恢复上下文返回
-
-如果在执行第`7`步后被新到中断打断,那新逻辑就会执行如下序列
-
-
-1. 硬件触发中断,自动关中断
-2. 保存上下文
-3. `reenter++`
-4. 执行中断服务例程
-5. 判断`reenter != 0`则跳转到第`9`步
-6. ~~开中断~~
-7. ~~执行其它逻辑~~
-8. ~~关中断~~
-9. `reenter--`
-10. 恢复上下文返回
-
-这样就算第`7`步很耗时,在中断打断这个步骤的情况下,它也只会被执行一次,而不会嵌套执行。这是优点,也是缺点,目前逻辑简单还能应付。后续也还是要继续优化。
-
-
-但这也改变不了时钟中断可能将`current->ticks`改成负数的情况(因为可能在`current->ticks == 0`的情况下,第`7`步是有可能再撑到下一个时钟中断将之再减1的)。因此需要在`task_union`中引入一个`need_resched`字段,当`current->ticks == 0`时不再减,而是直接将`need_resched`设置为`1`。
-
-
-1. 硬件触发中断,自动关中断
-2. 保存上下文
-3. `reenter++`
-4. 执行中断服务例程
-5. 判断`reenter != 0`则跳转到第`11`步
-6. 开中断
-7. 执行其它逻辑
-8. 关中断
-9. assert(reenter == 0);
-10. 如果`current->need_resched == 0`则继续,否则跳`20`
-11. `reenter--`
-12. 恢复上下文返回
-
-
-以下为需要进程抢占步骤,目前不分内核还是用户进程。
-
-20. `reenter--`、`current->need_resched = 0`、`current->ticks = current->priority`
-21. schedule
-22. 跳`12`
-
-相似的逻辑也可以加到系统调用返回处。这样就可以在中断返回和系统调用返回处抢占任务。
\ No newline at end of file
index 1904a6e3bf3bcbab9c653982aee64b2056987995..686ac0ac39fec632294013731bc487a4facdb54b 100644 (file)
@@ -19,10 +19,10 @@ ide_drive_t ide_drives[MAX_IDE_DRIVE_CNT];
 
 #define ATA_TIMEOUT 10  // 10次时钟中断
 
-void ata_dma_read_ext(int drv, uint64_t pos, uint16_t count, void *dest);
-int ata_pio_read_ext(int drv, uint64_t pos, uint16_t count, int timeout, void *dest);
+void ata_dma_read_ext(int drv, uint64_t pos, uint16_t count, voiddest);
+int ata_pio_read_ext(int drv, uint64_t pos, uint16_t count, int timeout, voiddest);
 
-void *mbr_buf;
+voidmbr_buf;
 void ata_test(uint64_t nr) {
     memset(mbr_buf, 0xAA, SECT_SIZE);
     ata_dma_read_ext(0, nr, 1, mbr_buf);
@@ -43,9 +43,10 @@ void ata_test(uint64_t nr) {
 //  2. 等到status的BSY位清除
 //  3. 等到status的DRQ位或ERR位设置
 u16 identify[256];
-void ata_send_read_identify_cmd(int drv) {}
+void ata_send_read_identify_cmd(int drv) {
+}
 
-void ata_pio_read_data(int drv, int sect_cnt, void *dst) {
+void ata_pio_read_data(int drv, int sect_cnt, voiddst) {
     insl(REG_DATA(drv), dst, (512 * sect_cnt) / sizeof(uint32_t));
 }
 
@@ -56,7 +57,7 @@ void ata_io_wait() {
 }
 
 // 这里所用的drv是逻辑编号 ATA0、ATA1下的Master、Salve的drv分别为0,1,2,3
-bool ata_read_identify(int drv, int disable_intr, uint8_t *status, u16 *identify) {
+bool ata_read_identify(int drv, int disable_intr, uint8_t* status, u16* identify) {
     memset(identify, 0, SECT_SIZE);
 
     uint8_t ctlv = 0x00;
@@ -95,7 +96,7 @@ bool ata_read_identify(int drv, int disable_intr, uint8_t *status, u16 *identify
     return true;
 }
 
-bool ata_read_identify_packet(int drv, int disable_intr, uint8_t *status, u16 *identify) {
+bool ata_read_identify_packet(int drv, int disable_intr, uint8_t* status, u16* identify) {
     memset(identify, 0, SECT_SIZE);
 
     uint8_t ctlv = 0x00;
@@ -134,8 +135,8 @@ bool ata_read_identify_packet(int drv, int disable_intr, uint8_t *status, u16 *i
     return true;
 }
 
-void ata_read_identity_string(const uint16_t *identify, int bgn, int end, char *buf) {
-    const char *p = (const char *)(identify + bgn);
+void ata_read_identity_string(const uint16_t* identify, int bgn, int end, char* buf) {
+    const char* p = (const char*)(identify + bgn);
     int i = 0;
     for (; i <= (end - bgn); i++) {
         buf[2 * i + 1] = p[0];
@@ -159,7 +160,7 @@ void ide_ata_init() {
         int channel = drvid >> 1;
         memset(ide_drives + i, 0, sizeof(ide_drive_t));
 
-        ide_drive_t *drv = ide_drives + drvid;
+        ide_drive_tdrv = ide_drives + drvid;
         drv->drvid = drvid;
         drv->channel = channel;
         drv->ide_pci_controller = ide_pci_controller + channel;
@@ -196,7 +197,7 @@ void ide_ata_init() {
         //  2. 等到status的BSY位清除
         //  3. 等到status的DRQ位或ERR位设置
         uint8_t status = 0;
-        const char *ide_drive_type = "NONE";
+        const charide_drive_type = "NONE";
         if (ata_read_identify(drvid, 1, &status, identify)) {
             drv->present = 1;
             drv->type = IDE_DRIVE_TYPE_ATA;
@@ -256,7 +257,7 @@ void ide_ata_init() {
 
         if ((identify[83] & (1 << 10)) != 0) {
             drv->lba48 = 1;
-            max_lba = *(uint64_t *)(identify + 100);
+            max_lba = *(uint64_t*)(identify + 100);
         } else {
             // panic("your ide disk drive do not support LBA48");
             max_lba = (identify[61] << 16) | identify[60];
@@ -326,7 +327,7 @@ void ide_ata_init() {
 
     for (int i = 0; i < MAX_IDE_DRIVE_CNT; i++) {
         int drvid = i;
-        ide_drive_t *drv = ide_drives + drvid;
+        ide_drive_tdrv = ide_drives + drvid;
         if (drv->present) {
             assert(drv->dma == 1);
             // assert(drv->lba48 == 1);
@@ -335,7 +336,7 @@ void ide_ata_init() {
     }
 }
 
-void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t *b) {
+void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_tb) {
     disk_request_t r;
     r.dev = dev;
     r.command = DISK_REQ_READ;
@@ -346,7 +347,7 @@ void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t *b) {
     send_disk_request(&r);
 }
 
-void tmp_ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char *buf) {
+void tmp_ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, charbuf) {
     int ret = 0;
     int retry = 3;
     while (retry--) {
@@ -370,9 +371,9 @@ void tmp_ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char *buf) {
 
 // mbr_ext_offset: 在MBR中的扩展分区记录里的偏移地址
 // lba_partition_table: 扩展分区的真实偏移地址
-void read_partition_table(ide_drive_t *drv, uint32_t mbr_ext_offset, uint64_t lba_partition_table, int depth) {
+void read_partition_table(ide_drive_tdrv, uint32_t mbr_ext_offset, uint64_t lba_partition_table, int depth) {
     // disk_request_t r;
-    char *sect = kmalloc(SECT_SIZE, 0);
+    charsect = kmalloc(SECT_SIZE, 0);
     memset(sect, 0xAA, SECT_SIZE);
 #if 1
     // partid == 0 代表整块硬盘
@@ -388,12 +389,12 @@ void read_partition_table(ide_drive_t *drv, uint32_t mbr_ext_offset, uint64_t lb
     send_disk_request(&r);
 #endif
 
-    ide_part_t *part = 0;
+    ide_part_tpart = 0;
     uint32_t part_id = 0;
 
     // 用来计算保存下一个扩展分区的起始位置
     uint64_t lba_extended_partition = 0;
-    const char *pe = sect + PARTITION_TABLE_OFFSET;
+    const charpe = sect + PARTITION_TABLE_OFFSET;
     for (int i = 0; i < 4; i++) {
         if (part_id >= MAX_DISK_PARTIONS) {
             break;
@@ -410,8 +411,8 @@ void read_partition_table(ide_drive_t *drv, uint32_t mbr_ext_offset, uint64_t lb
         ide_part_t pt;
         pt.flags = (uint8_t)pe[0];
         pt.type = (uint8_t)pe[4];
-        pt.lba_start = *((uint32_t *)(pe + 8));
-        pt.lba_end = *((uint32_t *)(pe + 12));
+        pt.lba_start = *((uint32_t*)(pe + 8));
+        pt.lba_end = *((uint32_t*)(pe + 12));
 
         if (0x00 == pt.type) {
             continue;
@@ -452,7 +453,7 @@ void read_partition_table(ide_drive_t *drv, uint32_t mbr_ext_offset, uint64_t lb
 
 void ide_read_partions() {
     for (int i = 0; i < MAX_IDE_DRIVE_CNT; i++) {
-        ide_drive_t *drv = ide_drives + i;
+        ide_drive_tdrv = ide_drives + i;
         int channel = i >> 1;
 
         if (0 == drv->present) {
@@ -466,7 +467,7 @@ void ide_read_partions() {
 }
 
 // ATA_CMD_READ_DMA_EXT
-void ata_dma_read_ext(int drvid, uint64_t pos, uint16_t count, void *dest) {
+void ata_dma_read_ext(int drvid, uint64_t pos, uint16_t count, voiddest) {
     // Intel®
     //  82801CA (ICH3), 82801BA
     // (ICH2), 82801AA (ICH), and 82801AB
@@ -487,8 +488,8 @@ void ata_dma_read_ext(int drvid, uint64_t pos, uint16_t count, void *dest) {
 
     int channel = (drvid >> 1) & 0x01;
     assert(channel == 0 || channel == 1);
-    ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
-    ide_drive_t *drv = ide_drives + drvid;
+    ide_pci_controller_tide_ctrl = ide_pci_controller + channel;
+    ide_drive_tdrv = ide_drives + drvid;
 
     // 停止DMA
     outb(PCI_IDE_CMD_STOP, ide_ctrl->bus_cmd);
@@ -578,7 +579,7 @@ void ata_dma_read_ext(int drvid, uint64_t pos, uint16_t count, void *dest) {
 
 // TODO
 int ata_dma_stop(int channel) {
-    ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
+    ide_pci_controller_tide_ctrl = ide_pci_controller + channel;
 
     uint8_t x = inb(ide_ctrl->bus_cmd);
     x &= ~PCI_IDE_CMD_START;
@@ -596,8 +597,8 @@ int ata_dma_stop(int channel) {
 }
 
 // ATA_CMD_READ_PIO_EXT
-int ata_pio_read_ext(int drvid, uint64_t pos, uint16_t count, int timeout, void *dest) {
-    ide_drive_t *drv = ide_drives + drvid;
+int ata_pio_read_ext(int drvid, uint64_t pos, uint16_t count, int timeout, voiddest) {
+    ide_drive_tdrv = ide_drives + drvid;
 
     // PIO读,禁用中断
     outb(ATA_CTL_NIEN, REG_CTL(drvid));
index 0e74909a7b65372ae224e82d307213e2008a6436..9b98667fe12370abc4eec6f08a3d507943dd0108 100644 (file)
@@ -12,7 +12,7 @@
 #include <system.h>
 
 // only support read
-void blk_rw(dev_t dev, u64_t offset, u32_t size, char *buf) {
+void blk_rw(dev_t dev, u64_t offset, u32_t size, charbuf) {
     // assert(DEV_MAJOR(dev) == DEV_MAJOR_HDA);
     // assert(offset % SECT_SIZE == 0);
     // assert(size % SECT_SIZE == 0);
index 1b7b8bb8e96c61cc07afa3a86fc80e8df6e54928..39246c908168b74d03fc2f2e91a054fe86cd3f2c 100644 (file)
@@ -12,8 +12,8 @@
 #include <fs.h>
 #include <ide.h>
 
-void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t *b);
-void block_read(bbuffer_t *b) {
+void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_tb);
+void block_read(bbuffer_tb) {
     assert(b != NULL);
     assert(b->data != NULL);
     assert(b->page != NULL);
@@ -33,9 +33,9 @@ void ata_read_ext2_sb() {
     const int block = 0;
     const int offset = 1024;
     const int size = 4096;
-    bbuffer_t *bb = bread(system.root_dev, block, size);
+    bbuffer_tbb = bread(system.root_dev, block, size);
 
-    ext2_sb_t *p = (ext2_sb_t *)(bb->data + offset);
+    ext2_sb_t* p = (ext2_sb_t*)(bb->data + offset);
     printk("inodes count %u inodes per group %u free %u\n", p->s_inodes_count, p->s_inodes_per_group,
            p->s_free_inodes_count);
     printk("blocks count %u blocks per group %u free %u magic %04x\n", p->s_blocks_count, p->s_blocks_per_group,
index 85dcfe884e0ef6230736dcf8ff07d16c0fee1d38..f6dd56d1123b13980bd125d29e831e0fb2e1c669 100644 (file)
@@ -18,18 +18,22 @@ void vga_putc(unsigned int nr, unsigned char c, const unsigned char color);
 
 cnsl_t cnsl;
 
-static bool empty(const cnsl_queue_t *q) { return q->head == q->tail; }
+static bool empty(const cnsl_queue_t* q) {
+    return q->head == q->tail;
+}
 
-static bool full(const cnsl_queue_t *q) { return (q->head + 1) % CNSL_QUEUE_SIZE == q->tail; }
+static bool full(const cnsl_queue_t* q) {
+    return (q->head + 1) % CNSL_QUEUE_SIZE == q->tail;
+}
 
-static void put(cnsl_queue_t *q, char c) {
+static void put(cnsl_queue_tq, char c) {
     if (!full(q)) {
         q->data[q->head] = c;
         q->head = (q->head + 1) % CNSL_QUEUE_SIZE;
     }
 }
 
-static bool get(cnsl_queue_t *q, char *c) {
+static bool get(cnsl_queue_t* q, char* c) {
     if (!empty(q)) {
         *c = q->data[q->tail];
         q->tail = (q->tail + 1) % CNSL_QUEUE_SIZE;
@@ -39,10 +43,13 @@ static bool get(cnsl_queue_t *q, char *c) {
     return false;
 }
 
-static void clear(cnsl_queue_t *q) { q->head = q->tail = 0; }
+static void clear(cnsl_queue_t* q) {
+    q->head = q->tail = 0;
+}
 
-static void erase(cnsl_queue_t *q) {
-    if (empty(q)) return;
+static void erase(cnsl_queue_t* q) {
+    if (empty(q))
+        return;
 
     if (q->head == 0)
         q->head = CNSL_QUEUE_SIZE - 1;
@@ -50,8 +57,8 @@ static void erase(cnsl_queue_t *q) {
         q->head--;
 }
 
-static void cnsl_queue_init(cnsl_queue_t *cq) {
-    memset((void *)cq, 0, sizeof(*cq));
+static void cnsl_queue_init(cnsl_queue_tcq) {
+    memset((void*)cq, 0, sizeof(*cq));
     cq->head = 0;
     cq->tail = 0;
     init_wait_queue_head(&cq->wait);
@@ -71,7 +78,7 @@ int cnsl_kbd_write(char ch) {
     if (ch == 0) {
         return 0;
     }
-    extern tty_t *const default_tty;
+    extern tty_tconst default_tty;
     if (ch == '\b') {
         if (!empty(&cnsl.wr_q)) {
             tty_color_putc(default_tty, '\b', TTY_FG_HIGHLIGHT | TTY_WHITE, TTY_BLACK);
@@ -88,13 +95,14 @@ int cnsl_kbd_write(char ch) {
     if (ch == '\n') {
         clear(&cnsl.wr_q);
         return 0;  // TODO FIX
-        while (get(&cnsl.sc_q, &ch)) put(&cnsl.rd_q, ch);
+        while (get(&cnsl.sc_q, &ch))
+            put(&cnsl.rd_q, ch);
         // wake_up(&rdwq);
         up(&sem);
     }
 }
 
-int cnsl_read(char *buf, size_t count) {
+int cnsl_read(charbuf, size_t count) {
     unsigned long flags;
 
     assert(count > 0);
@@ -116,7 +124,7 @@ int cnsl_read(char *buf, size_t count) {
             }
         }
 #else
-        task_union *task = current;
+        task_uniontask = current;
         DECLARE_WAIT_QUEUE(wait, task);
         add_wait_queue(&rdwq, &wait);
 
@@ -132,7 +140,8 @@ int cnsl_read(char *buf, size_t count) {
                 task->state = TASK_READY;
                 del_wait_queue(&rdwq, &wait);
 
-                if (ch == '\n') goto end;
+                if (ch == '\n')
+                    goto end;
 
                 break;
             }
index 2ab964f4b375c37c5c52f2d1ead72d7ebb67f739..190801fc21bcb6071fa670704e5dd8ebb2e291ae 100644 (file)
@@ -107,7 +107,7 @@ ide_pci_controller_t ide_pci_controller[NR_IDE_CONTROLLER];
 
 void ata_dma_stop(int channel);
 
-void ide_stat_print(ide_pci_controller_t *ide_ctrl) {
+void ide_stat_print(ide_pci_controller_tide_ctrl) {
     int r = atomic_read(&(ide_ctrl->request_cnt));
     int i = atomic_read(&(ide_ctrl->irq_cnt));
     int c = atomic_read(&(ide_ctrl->consumed_cnt));
@@ -115,13 +115,13 @@ void ide_stat_print(ide_pci_controller_t *ide_ctrl) {
     printlxy(MPL_IDE0 + channel, MPO_IDE, "IDE%d req %u irq %u consumed %u", channel, r, i, c);
 }
 
-void ide_irq_bh_handler(void *arg) {
+void ide_irq_bh_handler(voidarg) {
     int channel = (int)arg;
 
     assert(channel <= 1);
     assert(channel >= 0);
 
-    ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
+    ide_pci_controller_tide_ctrl = ide_pci_controller + channel;
 
     // 读相关status寄存器
     const int drvid = (channel << 1);  // 虚拟一个drvid
@@ -142,13 +142,13 @@ void ide_irq_bh_handler(void *arg) {
     complete(&ide_ctrl->intr_complete);
 }
 
-void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) {
+void ide_irq_handler(unsigned int irq, pt_regs_t* regs, void* devid) {
     // printk("ide irq %d handler pci status: 0x%02x\n", irq, ata_pci_bus_status());
     int channel = irq == ide_pci_controller[0].irq_line ? 0 : 1;
 
     ata_dma_stop(channel);
 
-    add_irq_bh_handler(ide_irq_bh_handler, (void *)channel);
+    add_irq_bh_handler(ide_irq_bh_handler, (void*)channel);
 }
 
 unsigned int IDE_CHL0_CMD_BASE = 0x1F0;
@@ -159,7 +159,7 @@ unsigned int IDE_CHL1_CTL_BASE = 0x376;
 
 // 《PCI IDE Controller Specification》
 // 《Programming Interface for Bus Master IDE Controller》
-void ide_pci_init(pci_device_t *pci) {
+void ide_pci_init(pci_device_tpci) {
 #if 0
     uint32_t v;
     uint32_t cmd;
@@ -207,7 +207,7 @@ void ide_pci_init(pci_device_t *pci) {
         ide_pci_controller[i].bus_cmd = iobase + PCI_IDE_CMD;
         ide_pci_controller[i].bus_status = iobase + PCI_IDE_STATUS;
         ide_pci_controller[i].bus_prdt = iobase + PCI_IDE_PRDT;
-        ide_pci_controller[i].prdt = (prdte_t *)page2va(alloc_one_page(0));
+        ide_pci_controller[i].prdt = (prdte_t*)page2va(alloc_one_page(0));
 
         ide_pci_controller[i].status = 0;
         ide_pci_controller[i].pci_status = 0;
@@ -259,9 +259,9 @@ void ide_pci_init(pci_device_t *pci) {
 
 //     kfree(buf);
 // }
-const char *pci_get_info(unsigned int classcode, unsigned int progif);
+const charpci_get_info(unsigned int classcode, unsigned int progif);
 void init_pci_controller(unsigned int classcode) {
-    pci_device_t *pci = pci_find_device_by_classcode(classcode);
+    pci_device_tpci = pci_find_device_by_classcode(classcode);
     if (pci == NULL) {
         printk("can not find pci classcode: %08x", classcode);
         panic("can not find ide controller");
@@ -280,7 +280,7 @@ void init_pci_controller(unsigned int classcode) {
     }
 }
 
-extern void *mbr_buf;
+extern voidmbr_buf;
 
 uint8_t ata_pci_bus_status();
 
@@ -295,7 +295,7 @@ void ide_init() {
     ide_ata_init();
 }
 
-ide_drive_t *ide_get_drive(dev_t dev) {
+ide_drive_tide_get_drive(dev_t dev) {
     int major = DEV_MAJOR(dev);
     int minor = DEV_MINOR(dev);
 
@@ -305,7 +305,7 @@ ide_drive_t *ide_get_drive(dev_t dev) {
     assert(minor >= 0);
     assert(drvid < MAX_IDE_DRIVE_CNT);
 
-    ide_drive_t *drv = ide_drives + drvid;
+    ide_drive_tdrv = ide_drives + drvid;
 
     return drv;
 }
index 2b8c4c611b3aa3bf0c127a2bfdd5022f7eea57b9..96e19740f75a26b12da9727183aaf0e5fb344c0f 100644 (file)
@@ -171,14 +171,14 @@ typedef struct prdte {
     uint32_t eot : 1;
 } prdte_t;
 typedef struct _ide_pci_controller {
-    pci_device_t *pci;
+    pci_device_tpci;
 
     unsigned int bus_iobase;
     unsigned int bus_cmd;
     unsigned int bus_status;
     unsigned int bus_prdt;
 
-    prdte_t *prdt;
+    prdte_tprdt;
 
     //
     uint8_t status;
@@ -219,7 +219,7 @@ typedef struct _ide_drive {
     int lba48;  // 是否支持LBA48
     uint64_t max_lba;
 
-    ide_pci_controller_t *ide_pci_controller;
+    ide_pci_controller_tide_pci_controller;
 
     ide_part_t partions[MAX_DISK_PARTIONS];
 } ide_drive_t;
@@ -227,5 +227,5 @@ typedef struct _ide_drive {
 #define MAX_IDE_DRIVE_CNT 4
 extern ide_drive_t ide_drives[MAX_IDE_DRIVE_CNT];
 
-ide_drive_t *ide_get_drive(dev_t dev);
-void ide_stat_print(ide_pci_controller_t *ide_ctrl);
+ide_drive_tide_get_drive(dev_t dev);
+void ide_stat_print(ide_pci_controller_tide_ctrl);
index ff6aa8d7bdedfa7df2c001b908bc81111d9398bc..48690fc3d9c517bf3e056607fb8007edab1045bf 100644 (file)
@@ -52,7 +52,7 @@ char kbd_char_tbl[] = {
 
 // TODO 改造成环形缓冲区
 uint8_t scan_code;
-void kbd_bh_handler(void *arg) {
+void kbd_bh_handler(voidarg) {
     kbd_debug(scan_code);
     if (0x80 & scan_code) {  // break code
         return;
@@ -62,14 +62,14 @@ void kbd_bh_handler(void *arg) {
     cnsl_kbd_write(ch);
 }
 
-void kbd_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) {
+void kbd_handler(unsigned int irq, pt_regs_t* regs, void* dev_id) {
     scan_code = inb(0x60);
     add_irq_bh_handler(kbd_bh_handler, NULL);
 }
 
-extern tty_t *const default_tty;
-extern tty_t *const monitor_tty;
-extern tty_t *const debug_tty;
+extern tty_tconst default_tty;
+extern tty_tconst monitor_tty;
+extern tty_tconst debug_tty;
 extern void tty_switch_to_next();
 
 void kbd_debug(uint8_t scan_code) {
index 1a5c10e05e097f627fdc13da1caa3da9623379f1..ad13bf6661fb0ad2312c68656805b26520452985 100644 (file)
@@ -21,7 +21,7 @@
 
 LIST_HEAD(pci_devs);
 
-const char *pci_get_info(unsigned int classcode, unsigned int progif);
+const charpci_get_info(unsigned int classcode, unsigned int progif);
 
 int pci_read_config_byte(int cmd) {
     outl(PCI_CONFIG_CMD(cmd), PCI_ADDR);
@@ -68,7 +68,7 @@ void scan_pci_bus(int bus) {
                 continue;
             }
 
-            pci_device_t *pci = kmalloc(sizeof(pci_device_t), 0);
+            pci_device_tpci = kmalloc(sizeof(pci_device_t), 0);
             if (0 == pci) {
                 printk("no space to alloc for pci_device_t\n");
                 continue;
@@ -115,10 +115,10 @@ void scan_pci_bus(int bus) {
     }
 }
 
-pci_device_t *pci_find_device(unsigned int vendor, unsigned int device) {
+pci_device_tpci_find_device(unsigned int vendor, unsigned int device) {
     int i;
-    list_head_t *p;
-    pci_device_t *pci = 0;
+    list_head_tp;
+    pci_device_tpci = 0;
 
     list_for_each(p, &pci_devs) {
         pci = list_entry(p, pci_device_t, list);
@@ -131,21 +131,22 @@ pci_device_t *pci_find_device(unsigned int vendor, unsigned int device) {
     return 0;
 }
 
-pci_device_t *pci_find_device_by_classcode(unsigned int classcode) {
+pci_device_tpci_find_device_by_classcode(unsigned int classcode) {
     int i;
-    list_head_t *p;
-    pci_device_t *pci = 0;
+    list_head_tp;
+    pci_device_tpci = 0;
 
     list_for_each(p, &pci_devs) {
         pci = list_entry(p, pci_device_t, list);
 
-        if (pci->classcode == classcode) return pci;
+        if (pci->classcode == classcode)
+            return pci;
     }
 
     return 0;
 }
 
-const char *pci_intr_pin(int pin) {
+const charpci_intr_pin(int pin) {
     switch (pin) {
     case 0:
         return "NONE#";
@@ -163,11 +164,11 @@ const char *pci_intr_pin(int pin) {
 }
 
 void dump_pci_dev() {
-    list_head_t *p;
+    list_head_tp;
     int i;
 
     list_for_each(p, &pci_devs) {
-        pci_device_t *pci = list_entry(p, pci_device_t, list);
+        pci_device_tpci = list_entry(p, pci_device_t, list);
         // printk("vendor %04x device %04x class %04x:%02x bus %d intr %3d ", pci->vendor, pci->device, pci->classcode,
         //        pci->progif, pci->bus, pci->intr_line);
         // printk("%s\n", pci_get_info(pci->classcode, pci->progif));
@@ -256,8 +257,8 @@ void setup_pci() {
 typedef struct pci_info {
     unsigned long code;
     unsigned int flag;
-    const char *info;
-    const char *detail;
+    const charinfo;
+    const chardetail;
 } pci_info_t;
 
 pci_info_t pci_info[] = {
@@ -420,9 +421,9 @@ pci_info_t pci_info[] = {
     {0x118000, 0, "Acquisition/Signal Processing Controller", "Other Data Acquisition/Signal Processing Controller"},
     {0x000000, 0, 0}};
 
-const char *pci_get_info(unsigned int classcode, unsigned int progif) {
-    pci_info_t *p = pci_info;
-    const char *s = 0;
+const charpci_get_info(unsigned int classcode, unsigned int progif) {
+    pci_info_tp = pci_info;
+    const chars = 0;
 
     while (p->code != 0 || p->flag != 0 || p->info != 0) {
         unsigned long code = classcode;
index 1b82334af23434886ab6d11239379064c261e257..03f8861f777fb8c4002bb98f9c97d3c2b0c45dde 100644 (file)
@@ -15,7 +15,7 @@
 
 typedef struct pci_member {
     uint16_t vendor_id;
-    char *name;
+    charname;
 } pci_member_t;
 
 pci_member_t pci_members[] = {
@@ -909,4 +909,4 @@ pci_member_t pci_members[] = {
     {0xF5F5, "F5 Networks, Inc."},
     {0xFDEF, "Fermionic Design Private Limited"},
     {0xFE19, "TenaFe Inc."},
-};
\ No newline at end of file
+};
index f3d6d3f5c993d9e33c0be95da037d73d45d54f0b..767b46dab8df6e29c0a1f2acaddd7c6396854208 100644 (file)
 #include <pci.h>
 #include <system.h>
 
-
 void init_sata() {
-    pci_device_t *pci = pci_find_device_by_classcode(0x0106);
+    pci_device_tpci = pci_find_device_by_classcode(0x0106);
     if (pci == NULL) {
         printk("can not find pci classcode: %08x", 0x0106);
         panic("can not find sata controller");
     }
+
     // progif
     // 0x01 AHCI
     //
@@ -28,12 +28,12 @@ void init_sata() {
         printk("AHCI mode not supported\n");
     }
 
-    printk("found sata pci progif %02x %03d:%02d.%d #%02d %04X:%04X\n", pci->progif, pci->bus, pci->dev, pci->devfn, pci->intr_line, pci->vendor, pci->device);
+    printk("found sata pci progif %02x %03d:%02d.%d #%02d %04X:%04X\n", pci->progif, pci->bus, pci->dev, pci->devfn,
+           pci->intr_line, pci->vendor, pci->device);
     for (int i = 0; i < 6; i++) {
         printk("  sata pci BAR%u value 0x%08X\n", i, pci->bars[i]);
         // if (pci->bars[i] != 0) {
         //     assert((pci->bars[i] & 0x1) == 0x1);
         // }
     }
-
 }
index b848681e132740c067be94f44bc026cf1ab1ee0c..1059bc2fc4cf00d9bd5408dd48437e4a964825e9 100644 (file)
@@ -37,7 +37,7 @@ void serial_putc(char c) {
     outb(c, SERIAL_PORT);
 }
 
-void serial_write(const char *buf, size_t size) {
+void serial_write(const charbuf, size_t size) {
     // return 0;
     for (size_t i = 0; i < size; i++) {
         serial_putc(buf[i]);
index 244543b8a60549b97fc6d4ca24f74b09ebb011f3..1dca92510f21c98935db1f7b282793e1e235abd7 100644 (file)
@@ -18,7 +18,9 @@ list_head_t block_buffer_hash_table[BLOCK_BUFFER_HASH_TABLE_SIZE] = {
     0,
 };
 
-int hashfn(dev_t dev, uint32_t block) { return ((dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE; }
+int hashfn(dev_t dev, uint32_t block) {
+    return ((dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE;
+}
 
 typedef struct bbuffer_store {
     int blocksize;
@@ -30,12 +32,12 @@ typedef struct bbuffer_store {
 // 1024, 2048, 4096
 bbuffer_store_t store[3] = {0};
 
-kmem_cache_t *bbufer_kmem_cache = 0;
+kmem_cache_tbbufer_kmem_cache = 0;
 
-bbuffer_store_t *getstore(uint32_t size) {
+bbuffer_store_tgetstore(uint32_t size) {
     assert(size == 1024 || size == 2048 || size == 4096);
 
-    bbuffer_store_t *s = 0;
+    bbuffer_store_ts = 0;
 
     if (1024 == size) {
         s = store + 0;
@@ -50,14 +52,14 @@ bbuffer_store_t *getstore(uint32_t size) {
     return s;
 }
 
-bbuffer_t *get_from_hash_table(dev_t dev, uint64_t block, uint32_t size) {
-    list_head_t *p = 0;
-    bbuffer_t *b = 0;
+bbuffer_tget_from_hash_table(dev_t dev, uint64_t block, uint32_t size) {
+    list_head_tp = 0;
+    bbuffer_tb = 0;
 
     uint32_t hash = hashfn(dev, block);
     assert(hash < BLOCK_BUFFER_HASH_TABLE_SIZE);
     list_for_each(p, block_buffer_hash_table + hash) {
-        bbuffer_t *t = list_entry(p, bbuffer_t, node);
+        bbuffer_tt = list_entry(p, bbuffer_t, node);
         if (t->dev != dev) {
             continue;
         }
@@ -87,7 +89,7 @@ bbuffer_t *get_from_hash_table(dev_t dev, uint64_t block, uint32_t size) {
     return NULL;
 }
 
-bbuffer_t *getblk(dev_t dev, uint64_t block, uint32_t size) {
+bbuffer_tgetblk(dev_t dev, uint64_t block, uint32_t size) {
     assert(size == 1024 || size == 2048 || size == 4096);
 
     // 暂时先只支持hard disk
@@ -99,16 +101,16 @@ again:
     irq_save(iflags);
 
     // 先尝试从hash里分配
-    bbuffer_t *b = get_from_hash_table(dev, block, size);
+    bbuffer_tb = get_from_hash_table(dev, block, size);
     if (NULL != b) {
         return b;
     }
 
     // 如果没找到,则从store的free_list里尝试找到第一个ref_count == 0 且未上锁的
-    bbuffer_store_t *s = getstore(size);
-    list_head_t *p = 0;
+    bbuffer_store_ts = getstore(size);
+    list_head_tp = 0;
     list_for_each(p, &s->free_list) {
-        bbuffer_t *t = list_entry(p, bbuffer_t, node);
+        bbuffer_tt = list_entry(p, bbuffer_t, node);
         assert(NULL != t);
         assert(t->block_size == size);
 
@@ -136,7 +138,6 @@ again:
     // FIXME
     irq_restore(iflags);
 
-
     // 虽然此时该bbuffer_t上的ref_count为0但其可能还有I/O操作没有完成
     // 因为可能有的进程调用了write、read后再直接调用brelse
     // 所以需要在此等待其结束
@@ -149,17 +150,16 @@ again:
     atomic_set(&(b->ref_count), 1);
     b->uptodate = 0;
 
-
     return b;
 }
 
-void brelse(bbuffer_t *b) {
+void brelse(bbuffer_tb) {
     assert(b != NULL);
     assert(atomic_read(&(b->ref_count)) > 0);
 
     wait_completion(&b->io_done);
 
-    bbuffer_store_t *s = getstore(b->block_size);
+    bbuffer_store_ts = getstore(b->block_size);
     assert(s != NULL);
     assert(s - store < 3);
 
@@ -168,8 +168,8 @@ void brelse(bbuffer_t *b) {
     // wake_up(&s->waitq);
 }
 
-bbuffer_t *bread(dev_t dev, uint64_t block, uint32_t size) {
-    bbuffer_t *b = getblk(dev, block, size);
+bbuffer_tbread(dev_t dev, uint64_t block, uint32_t size) {
+    bbuffer_tb = getblk(dev, block, size);
 
     assert(b != NULL);
 
@@ -214,15 +214,15 @@ void init_buffer() {
         init_wait_queue_head(&store[i].waitq);
 
         int page_left_space = 0;
-        void *data = NULL;
-        page_t *page = NULL;
+        voiddata = NULL;
+        page_tpage = NULL;
         for (int j = 0; j < MAX_BBUFFER_CNT; j++) {
             if (page_left_space < blocksize) {
-                data = (void *)page2va(alloc_one_page(0));
+                data = (void*)page2va(alloc_one_page(0));
                 page = va2page(data);
             }
 
-            bbuffer_t *b = kmem_cache_alloc(bbufer_kmem_cache, 0);
+            bbuffer_tb = kmem_cache_alloc(bbufer_kmem_cache, 0);
             assert(NULL != b);
 
             b->block = 0;
index 04081a2b5f0951a6210d7605247e06033286ad3b..6194613f1b058ddf08170615e83ce64f1f91c0f8 100644 (file)
@@ -15,7 +15,7 @@
 #include <vfs.h>
 #define DENTRY_HASH_TABLE_SIZE 233
 
-static kmem_cache_t *g_dentry_kmem_cache = NULL;
+static kmem_cache_tg_dentry_kmem_cache = NULL;
 typedef struct {
     list_head_t list;
     mutex_t mutex;
@@ -45,8 +45,8 @@ uint32_t mod64(uint64_t x, uint32_t y) {
 #endif
 }
 
-dentry_t *dentry_alloc(dentry_t *parent, const qstr_t *s) {
-    dentry_t *dentry = NULL;
+dentry_t* dentry_alloc(dentry_t* parent, const qstr_t* s) {
+    dentry_tdentry = NULL;
 
     assert(s != NULL);
     assert(s->len > 0);
@@ -87,8 +87,8 @@ dentry_t *dentry_alloc(dentry_t *parent, const qstr_t *s) {
     return dentry;
 }
 
-dentry_t *dentry_alloc_root(inode_t *root_inode) {
-    dentry_t *dentry;
+dentry_t* dentry_alloc_root(inode_t* root_inode) {
+    dentry_tdentry;
 
     assert(root_inode != NULL);
 
@@ -105,11 +105,11 @@ dentry_t *dentry_alloc_root(inode_t *root_inode) {
     return dentry;
 }
 
-dentry_hash_entry_t *dentry_hash(dentry_t *parent, uint64_t hash) {
+dentry_hash_entry_t* dentry_hash(dentry_t* parent, uint64_t hash) {
     int index = mod64(hash, DENTRY_HASH_TABLE_SIZE);
     assert(index < DENTRY_HASH_TABLE_SIZE);
 
-    dentry_hash_entry_t *dhe = dentry_hash_table + index;
+    dentry_hash_entry_tdhe = dentry_hash_table + index;
 
     assert(dhe != NULL);
     assert(dhe >= dentry_hash_table);
@@ -118,15 +118,15 @@ dentry_hash_entry_t *dentry_hash(dentry_t *parent, uint64_t hash) {
     return dhe;
 }
 
-void dentry_attach_inode(dentry_t *dentry, inode_t *inode) {
+void dentry_attach_inode(dentry_t* dentry, inode_t* inode) {
     assert(dentry != NULL);
     // assert(inode != NULL);
 
     dentry->d_inode = inode;
 }
 
-void dentry_rehash(dentry_t *dentry) {
-    dentry_hash_entry_t *dhe = dentry_hash(dentry->d_parent, dentry->d_name.hash);
+void dentry_rehash(dentry_tdentry) {
+    dentry_hash_entry_tdhe = dentry_hash(dentry->d_parent, dentry->d_name.hash);
 
     mutex_lock(&dhe->mutex);
 
@@ -135,19 +135,19 @@ void dentry_rehash(dentry_t *dentry) {
     mutex_unlock(&dhe->mutex);
 }
 
-void dentry_add(dentry_t *dentry, inode_t *inode) {
+void dentry_add(dentry_t* dentry, inode_t* inode) {
     dentry_attach_inode(dentry, inode);
     dentry_rehash(dentry);
 }
 
-int dentry_cached_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
-    dentry_hash_entry_t *dhe = dentry_hash(parent, s->hash);
+int dentry_cached_lookup(dentry_t* parent, qstr_t* s, dentry_t** dentry) {
+    dentry_hash_entry_tdhe = dentry_hash(parent, s->hash);
 
     *dentry = NULL;
 
     mutex_lock(&dhe->mutex);
 
-    list_head_t *p;
+    list_head_tp;
     list_for_each(p, &dhe->list) {
         *dentry = list_entry(p, dentry_t, d_hash);
         assert(*dentry != NULL);
@@ -179,12 +179,12 @@ int dentry_cached_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
     return 0;
 }
 
-int dentry_real_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
+int dentry_real_lookup(dentry_t* parent, qstr_t* s, dentry_t** dentry) {
     *dentry = NULL;
     int ret = 0;
 
     assert(parent->d_inode != NULL);
-    inode_t *dir = parent->d_inode;
+    inode_tdir = parent->d_inode;
 
     down(&dir->i_sem);
 
@@ -198,7 +198,7 @@ int dentry_real_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
         return ret;
     }
 
-    dentry_t *new_dentry = dentry_alloc(parent, s);
+    dentry_tnew_dentry = dentry_alloc(parent, s);
     if (new_dentry == NULL) {
         ret = -ENOMEM;
     } else {
@@ -232,23 +232,23 @@ void dentry_cache_init() {
     }
 
     for (int i = 0; i < DENTRY_HASH_TABLE_SIZE; i++) {
-        dentry_hash_entry_t *dhe = dentry_hash_table + i;
+        dentry_hash_entry_tdhe = dentry_hash_table + i;
         list_init(&dhe->list);
         mutex_init(&dhe->mutex);
     }
 }
 
-dentry_t *dentry_get(dentry_t *dentry) {
+dentry_t* dentry_get(dentry_t* dentry) {
     assert(dentry != NULL);
     atomic_inc(&dentry->d_count);
     return dentry;
 }
 
-void dentry_get_locked(dentry_t *dentry) {
+void dentry_get_locked(dentry_tdentry) {
     //
 }
 
-void dentry_put(dentry_t *dentry) {
+void dentry_put(dentry_tdentry) {
     //
 }
 
index 58f1f6fa48689be9b13cc606db638e10858cf51e..c399c8dd0419a2459e8a4117ecbe2ed46ef03ae6 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -22,41 +22,51 @@ fs_type_t ext2_fs_type = {
     .next = 0,
 };
 
-void ext2_setup() { vfs_register_filesystem(&ext2_fs_type); }
+void ext2_setup() {
+    vfs_register_filesystem(&ext2_fs_type);
+}
 
 //--------------------------------------------------------------------------
 struct {
     ext2_sb_t ext2_sb;
-    ext2_gd_t *ext2_gd;
+    ext2_gd_text2_gd;
 } ext2_fs;
 
-extern void blk_rw(dev_t dev, u64_t offset, u32_t scnt, char *buf);
-extern void kmem_cache_free(kmem_cache_t *cache, void *addr);
+extern void blk_rw(dev_t dev, u64_t offset, u32_t scnt, charbuf);
+extern void kmem_cache_free(kmem_cache_t* cache, void* addr);
 
 #define BLKRW(blkid, blkcnt, buf)                                                                   \
     do {                                                                                            \
         blk_rw(system.root_dev, 1ULL * (blkid) * EXT2_BLOCK_SIZE, (blkcnt) * EXT2_BLOCK_SIZE, buf); \
     } while (0)
 
-kmem_cache_t *ext2_block_cache;
-kmem_cache_t *ext2_inode_cache;
+kmem_cache_text2_block_cache;
+kmem_cache_text2_inode_cache;
 
 ext2_inode_t ext2_root_inode;
 
 static ext2_inode_t boot_inode;
 static ext2_inode_t krnl_inode;
 
-unsigned long ext2_block_size() { return (EXT2_MIN_BLOCK_SIZE << (EXT2_SB)->s_log_block_size); }
+unsigned long ext2_block_size() {
+    return (EXT2_MIN_BLOCK_SIZE << (EXT2_SB)->s_log_block_size);
+}
 
-void *ext2_alloc_block() { return (void *)kmem_cache_alloc(ext2_block_cache, 0); }
+void* ext2_alloc_block() {
+    return (void*)kmem_cache_alloc(ext2_block_cache, 0);
+}
 
-void *ext2_free_block(void *blk) { kmem_cache_free(ext2_block_cache, blk); }
+void* ext2_free_block(void* blk) {
+    kmem_cache_free(ext2_block_cache, blk);
+}
 
-void *ext2_alloc_inode() { return (void *)kmem_cache_alloc(ext2_inode_cache, 0); }
+void* ext2_alloc_inode() {
+    return (void*)kmem_cache_alloc(ext2_inode_cache, 0);
+}
 
-#define ext2_gd(n) ((ext2_gd_t *)(EXT2_GD) + (n))
-void ext2_read_inode(unsigned int ino, ext2_inode_t *inode) {
-    void *blk = ext2_alloc_block();
+#define ext2_gd(n) ((ext2_gd_t*)(EXT2_GD) + (n))
+void ext2_read_inode(unsigned int ino, ext2_inode_tinode) {
+    voidblk = ext2_alloc_block();
     assert(blk != 0);
 
     printd("read_inode %u\n", ino);
@@ -85,7 +95,7 @@ void ext2_read_inode(unsigned int ino, ext2_inode_t *inode) {
     ext2_free_block(blk);
 }
 
-void ext2_read_file(const ext2_inode_t *inode, char *buf) {
+void ext2_read_file(const ext2_inode_t* inode, char* buf) {
     assert(inode != 0);
     assert(buf != 0);
     assert(inode->i_size > 0 && inode->i_size <= MAX_SUPT_FILE_SIZE);
@@ -101,7 +111,7 @@ void ext2_read_file(const ext2_inode_t *inode, char *buf) {
     if (left) {
         printd("read left %u bytes\n", left);
 
-        void *blk = ext2_alloc_block();
+        voidblk = ext2_alloc_block();
 
         memcpy(buf + i * EXT2_BLOCK_SIZE, blk, left);
 
@@ -110,7 +120,7 @@ void ext2_read_file(const ext2_inode_t *inode, char *buf) {
     printd("read file done\n");
 }
 
-void ext2_read_data(const ext2_inode_t *inode, unsigned int offset, size_t size, char *buf) {
+void ext2_read_data(const ext2_inode_t* inode, unsigned int offset, size_t size, char* buf) {
     assert(inode != 0);
     assert(buf != 0);
     assert(inode->i_size > 0 && inode->i_size <= MAX_SUPT_FILE_SIZE);
@@ -125,16 +135,16 @@ void ext2_read_data(const ext2_inode_t *inode, unsigned int offset, size_t size,
     BLKRW(inode->i_block[blkid], blkcnt, buf);
 }
 
-unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode, unsigned int *file_type) {
+unsigned int ext2_search_indir(const char* name, const ext2_inode_t* inode, unsigned int* file_type) {
     unsigned int ino = 0;
     *file_type = EXT2_FT_UNKNOWN;
 
-    void *blk = ext2_alloc_block();
+    voidblk = ext2_alloc_block();
     assert(blk != 0);
 
     BLKRW(inode->i_block[0], 1, blk);  // only support the first direct blocks
 
-    ext2_dirent_t *dirent = (ext2_dirent_t *)blk;
+    ext2_dirent_t* dirent = (ext2_dirent_t*)blk;
     char tmp[64];
     while (dirent->name_len != 0) {
         memcpy(tmp, dirent->name, dirent->name_len);
@@ -148,7 +158,7 @@ unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode, unsi
             break;
         }
 
-        dirent = (ext2_dirent_t *)(((unsigned int)dirent) + dirent->rec_len);
+        dirent = (ext2_dirent_t*)(((unsigned int)dirent) + dirent->rec_len);
 
         if (((unsigned long)dirent - (unsigned long)blk) >= EXT2_BLOCK_SIZE) {
             ino = 0;
@@ -161,26 +171,29 @@ unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode, unsi
     return ino;
 }
 
-static int get_filename_from_path(const char *path, char *file) {
+static int get_filename_from_path(const char* path, char* file) {
     int i = 0;
 
-    while (*path == '/' && *path != '\0') path++;
+    while (*path == '/' && *path != '\0')
+        path++;
 
-    while (*path != '/' && *path != '\0') file[i++] = *path++;
+    while (*path != '/' && *path != '\0')
+        file[i++] = *path++;
 
     file[i] = 0;
 
     return i;
 }
 
-unsigned int ext2_search_inpath(const char *path) {
-    if (path == 0 || strlen(path) == 0 || path[0] != '/') return 0;
+unsigned int ext2_search_inpath(const char* path) {
+    if (path == 0 || strlen(path) == 0 || path[0] != '/')
+        return 0;
 
     assert(path != 0);
     assert(strlen(path) > 0);
     assert(path[0] == '/');
 
-    ext2_inode_t *inode = kmalloc(sizeof(ext2_inode_t), 0);
+    ext2_inode_tinode = kmalloc(sizeof(ext2_inode_t), 0);
     assert(inode != 0);
     memcpy(inode, &ext2_root_inode, sizeof(ext2_inode_t));
 
@@ -193,7 +206,8 @@ unsigned int ext2_search_inpath(const char *path) {
     unsigned int file_type = EXT2_FT_UNKNOWN;
     while ((len = get_filename_from_path(path, file)) != 0) {
         ino = ext2_search_indir(file, inode, &file_type);
-        if (ino == 0) return 0;
+        if (ino == 0)
+            return 0;
         // assert(ino != 0);
 
         path += len;
@@ -207,7 +221,8 @@ unsigned int ext2_search_inpath(const char *path) {
         }
     }
 
-    if (file_type != EXT2_FT_REG_FILE) return 0;
+    if (file_type != EXT2_FT_REG_FILE)
+        return 0;
 
     return ino;
 }
@@ -215,7 +230,7 @@ unsigned int ext2_search_inpath(const char *path) {
 void ext2_setup_fs() {
     memset(&ext2_fs, 0, sizeof(ext2_fs));
 
-    char *buf = kmalloc(EXT2_BLOCK_SIZE, 0);
+    charbuf = kmalloc(EXT2_BLOCK_SIZE, 0);
     if (buf == 0) {
         panic("out of memory");
     }
@@ -237,15 +252,17 @@ void ext2_setup_fs() {
     printk(" blocks per group %u inodes per group %u\n", EXT2_SB->s_blocks_per_group, EXT2_SB->s_inodes_per_group);
 
     ext2_block_cache = kmem_cache_create("ext2_block_cache", EXT2_BLOCK_SIZE, EXT2_BLOCK_SIZE);
-    if (0 == ext2_block_cache) panic("setup ext2 block cache failed. out of memory");
+    if (0 == ext2_block_cache)
+        panic("setup ext2 block cache failed. out of memory");
 
     ext2_inode_cache = kmem_cache_create("ext2_inode_cache", EXT2_INODE_SIZE, EXT2_INODE_SIZE);
-    if (0 == ext2_inode_cache) panic("setup ext2 inode cache failed. out of memory");
+    if (0 == ext2_inode_cache)
+        panic("setup ext2 inode cache failed. out of memory");
 
     ext2_fs.ext2_gd = ext2_alloc_block();
     assert(ext2_fs.ext2_gd != 0);
 
-    BLKRW(EXT2_SB->s_first_data_block + 1, 1, (char *)ext2_fs.ext2_gd);
+    BLKRW(EXT2_SB->s_first_data_block + 1, 1, (char*)ext2_fs.ext2_gd);
 
     unsigned int gps = EXT2_SB->s_blocks_count / EXT2_SB->s_blocks_per_group;
     gps += (EXT2_SB->s_blocks_count % EXT2_SB->s_blocks_per_group) ? 1 : 0;
index b76eb2168da21956b3d98f57bc8d9bc4dbc832b4..adbc8e5fe5416441877b7a8aaf12f635b630e5fc 100644 (file)
--- a/fs/ext2.h
+++ b/fs/ext2.h
@@ -208,8 +208,8 @@ typedef struct ext2_dir_ent {
 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & ~EXT2_DIR_ROUND)
 #define EXT2_MAX_REC_LEN ((1 << 16) - 1)
 
-void ext2_read_inode(unsigned int ino, ext2_inode_t *inode);
-void ext2_read_file(const ext2_inode_t *inode, char *buf);
-void ext2_read_data(const ext2_inode_t *inode, unsigned int offset, size_t size, char *buf);
+void ext2_read_inode(unsigned int ino, ext2_inode_tinode);
+void ext2_read_file(const ext2_inode_t* inode, char* buf);
+void ext2_read_data(const ext2_inode_t* inode, unsigned int offset, size_t size, char* buf);
 
 #endif  //_EXT2_H
index e315c7868d1e7cd727934b63e7b3a89612dc0748..2f1dc0adca36d6b56d81347fe9b0ba37f1191cd9 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
 #include <irq.h>
 #include <task.h>
 
-file_t *get_file(int fd) {
+file_tget_file(int fd) {
     assert(fd >= 0);
     assert(fd < NR_TASK_OPEN_CNT);
 
-    file_t *fp = current->files.fds[fd];
+    file_tfp = current->files.fds[fd];
 
     // TOOD 添加对fp的引用记数
 
@@ -25,31 +25,31 @@ file_t *get_file(int fd) {
 //////////
 const uint32_t PAGE_HASH_BITS = 10;
 const uint32_t PAGE_HASH_SIZE = 1 << PAGE_HASH_BITS;
-page_t **page_hash_table = NULL;
+page_t** page_hash_table = NULL;
 
-static uint32_t page_hash_func(address_space_t *mapping, uint32_t index) {
+static uint32_t page_hash_func(address_space_tmapping, uint32_t index) {
     uint32_t i = (((uint32_t)mapping) / (sizeof(inode_t) & ~(sizeof(inode_t) - 1)));
 #define s(x) ((x) + (x) >> PAGE_HASH_BITS)
     return s(i + index) & (PAGE_HASH_SIZE - 1);
 #undef s
 }
 
-page_t *page_hash(address_space_t *mapping, uint32_t index) {
+page_t* page_hash(address_space_t* mapping, uint32_t index) {
     uint32_t hash = page_hash_func(mapping, index);
     assert(hash < PAGE_HASH_SIZE);
 
     return page_hash_table[hash];
 }
 
-page_t *find_hash_page(address_space_t *mapping, uint32_t index) {
-    page_t *page = NULL;
+page_t* find_hash_page(address_space_t* mapping, uint32_t index) {
+    page_tpage = NULL;
 
     uint32_t hash = page_hash_func(mapping, index);
     assert(hash < PAGE_HASH_SIZE);
 
     ENTER_CRITICAL_ZONE(EFLAGS);
 
-    page_t *p = page_hash_table[hash];
+    page_tp = page_hash_table[hash];
 
     while (p != NULL) {
         if (p->mapping == mapping) {
@@ -67,21 +67,21 @@ page_t *find_hash_page(address_space_t *mapping, uint32_t index) {
     return page;
 }
 
-void add_page_to_hash(page_t *page, address_space_t *mapping, uint32_t index) {
+void add_page_to_hash(page_t* page, address_space_t* mapping, uint32_t index) {
     uint32_t hash = page_hash_func(mapping, index);
     assert(hash < PAGE_HASH_SIZE);
 
     assert(page->mapping == mapping);
 
     ENTER_CRITICAL_ZONE(EFLAGS);
-    page_t *p = 0;
+    page_tp = 0;
     p = page_hash_table[hash];
     page->hash_next = p;
     page_hash_table[hash] = page;
     EXIT_CRITICAL_ZONE(EFLAGS);
 }
 
-void add_page_to_inode(address_space_t *mapping, page_t *page) {
+void add_page_to_inode(address_space_t* mapping, page_t* page) {
     assert(mapping != NULL);
     assert(page != NULL);
     assert(page->mapping == mapping);
@@ -91,8 +91,8 @@ void add_page_to_inode(address_space_t *mapping, page_t *page) {
     EXIT_CRITICAL_ZONE(EFLAGS);
 }
 
-page_t *get_cached_page(address_space_t *mapping, uint32_t index) {
-    page_t *page = NULL;
+page_t* get_cached_page(address_space_t* mapping, uint32_t index) {
+    page_tpage = NULL;
     page = find_hash_page(mapping, index);
     if (NULL == page) {
         page = alloc_one_page(0);
@@ -113,7 +113,7 @@ page_t *get_cached_page(address_space_t *mapping, uint32_t index) {
 }
 
 void vfs_page_cache_init() {
-    page_hash_table = (page_t **)page2va(alloc_one_page(0));
+    page_hash_table = (page_t**)page2va(alloc_one_page(0));
     assert(page_hash_table != NULL);
     memset(page_hash_table, 0, PAGE_SIZE);
 }
@@ -122,7 +122,7 @@ void vfs_page_cache_init() {
 #define MAX_FILES 1024
 file_t g_files[MAX_FILES];
 
-void init_file(file_t *fp) {
+void init_file(file_tfp) {
     fp->f_dentry = NULL;
     fp->f_flags = 0;
     fp->f_ops = NULL;
@@ -137,11 +137,11 @@ void init_files() {
     }
 }
 
-file_t *get_empty_filp() {
-    file_t *fp = NULL;
+file_tget_empty_filp() {
+    file_tfp = NULL;
 
     for (int i = 0; i < MAX_FILES; i++) {
-        file_t *p = g_files + i;
+        file_tp = g_files + i;
         if (p->f_state == 0) {
             ENTER_CRITICAL_ZONE(EFLAGS);
 
diff --git a/fs/fs.c b/fs/fs.c
index b9bbe974d9901209a4bbbb37fac18d6e80e8de9a..d14ac936d4fbec37a619ddb35cbd39de80a04444 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
 
 extern chrdev_t cnsl_chrdev;
 
-chrdev_t *chrdev[CHRDEV_SIZE] = {&cnsl_chrdev};
+chrdev_tchrdev[CHRDEV_SIZE] = {&cnsl_chrdev};
 
 // void ext2_setup_fs();
-unsigned int ext2_search_inpath(const char *path);
+unsigned int ext2_search_inpath(const charpath);
 
-unsigned int namei(const char *path) { return ext2_search_inpath(path); }
+unsigned int namei(const char* path) {
+    return ext2_search_inpath(path);
+}
 
 vfsmount_t rootfs_vfsmount;
 
index aac8de042055791265cdb248497e3c2712dc5b49..cc8b46cb538cd2106512a415e8f3e583ae8cd4aa 100644 (file)
@@ -13,7 +13,7 @@
 
 //////
 
-__attribute__((regparm(0))) long sysc_mkdir(const char *path, int mode) {
+__attribute__((regparm(0))) long sysc_mkdir(const charpath, int mode) {
     int ret = 0;
 
     // TODO 检查参数
@@ -26,7 +26,7 @@ __attribute__((regparm(0))) long sysc_mkdir(const char *path, int mode) {
         }
     }
 
-    dentry_t *dentry = NULL;
+    dentry_tdentry = NULL;
     ret = path_lookup_create(&ni, &dentry);
     if (0 == ret && dentry != NULL) {
         assert(dentry != NULL);
index 00b83044d532e658337e4f9f4be15da498a0b1a4..1b903dcd023b43ef8cdbbbdfc73bfc9257c70eb9 100644 (file)
 #include "printk.h"
 #include "system.h"
 
-static kmem_cache_t *g_inode_kmem_cache = NULL;
+static kmem_cache_tg_inode_kmem_cache = NULL;
 
-inode_t *alloc_inode(superblock_t *sb) {
-    inode_t *inode = 0;
+inode_t* alloc_inode(superblock_t* sb) {
+    inode_tinode = 0;
 
     assert(NULL != sb->sb_ops);
     // assert(NULL != sb->sb_ops->alloc_inode);
@@ -46,7 +46,7 @@ inode_t *alloc_inode(superblock_t *sb) {
     return inode;
 }
 
-void init_special_inode(inode_t *inode, umode_t mode, dev_t rdev) {
+void init_special_inode(inode_tinode, umode_t mode, dev_t rdev) {
     inode->i_mode = mode;
     if (S_ISCHR(mode)) {
         panic("todo");
index 2e4626161b90cd998bf8a29f5bab20bf062ce8f6..0a747966aab9565ab8e2fe9d7b20fb94d8c783fb 100644 (file)
 #include "system.h"
 #include "task.h"
 
-kmem_cache_t *vfsmount_kmem_cache = 0;
+kmem_cache_tvfsmount_kmem_cache = 0;
 
 // 通过挂载点目录的 path_t 也就是 {mount, dentry}计算hash
 // 就可以得到所有挂载在该目录上的挂载描述符 vfsmount
-vfsmount_t **vfsmount_hash_table = 0;
+vfsmount_t** vfsmount_hash_table = 0;
 int vfsmount_hash_table_size = 0;
 
-vfsmount_t *alloc_vfsmount(const char *name) {
-    vfsmount_t *mnt = 0;
+vfsmount_t* alloc_vfsmount(const char* name) {
+    vfsmount_tmnt = 0;
 
-    mnt = (vfsmount_t *)kmem_cache_zalloc(vfsmount_kmem_cache, 0);
+    mnt = (vfsmount_t*)kmem_cache_zalloc(vfsmount_kmem_cache, 0);
 
     if (0 == mnt) {
         panic("no mem alloc for vfsmount: %s", name);
@@ -40,9 +40,9 @@ vfsmount_t *alloc_vfsmount(const char *name) {
     return mnt;
 }
 
-vfsmount_t *vfs_kernel_mount(fs_type_t *type, int flags, const char *name, void *data) {
+vfsmount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data) {
     int ret = 0;
-    vfsmount_t *mnt = 0;
+    vfsmount_tmnt = 0;
 
     assert(0 != type);
 
@@ -62,7 +62,7 @@ vfsmount_t *vfs_kernel_mount(fs_type_t *type, int flags, const char *name, void
     return mnt;
 }
 
-unsigned long vfsmount_table_hash(vfsmount_t *mnt, dentry_t *dentry) {
+unsigned long vfsmount_table_hash(vfsmount_t* mnt, dentry_t* dentry) {
     unsigned long h = (unsigned long)mnt / 5;
     h += 1;
     h += (unsigned long)dentry / 5;
@@ -70,13 +70,13 @@ unsigned long vfsmount_table_hash(vfsmount_t *mnt, dentry_t *dentry) {
     return h & (vfsmount_hash_table_size - 1);
 }
 
-void add_vfsmount_to_hash_table(vfsmount_t *mnt) {
+void add_vfsmount_to_hash_table(vfsmount_tmnt) {
     unsigned long hash = vfsmount_table_hash(mnt->mnt_parent, mnt->mnt_point);
 
     uint32_t eflags;
     irq_save(eflags);
 
-    vfsmount_t **p = vfsmount_hash_table + hash;
+    vfsmount_t** p = vfsmount_hash_table + hash;
 
     mnt->hash_next = *p;
 
@@ -91,10 +91,10 @@ void init_mount() {
         panic("create vfsmount kmem cache failed");
     }
 
-    vfsmount_hash_table = (vfsmount_t **)page2va(alloc_one_page(0));
+    vfsmount_hash_table = (vfsmount_t**)page2va(alloc_one_page(0));
     memset(vfsmount_hash_table, 0, PAGE_SIZE);
 
-    vfsmount_hash_table_size = PAGE_SIZE / sizeof(vfsmount_t *);
+    vfsmount_hash_table_size = PAGE_SIZE / sizeof(vfsmount_t*);
 
     assert(vfsmount_hash_table_size != 0);
 
@@ -109,10 +109,10 @@ void init_mount() {
 }
 
 void mount_root() {
-    fs_type_t *type = vfs_find_filesystem("ramfs");
+    fs_type_ttype = vfs_find_filesystem("ramfs");
     assert(type != NULL);
 
-    vfsmount_t *mnt = vfs_kernel_mount(type, 0, "ramfs", NULL);
+    vfsmount_tmnt = vfs_kernel_mount(type, 0, "ramfs", NULL);
     assert(mnt != NULL);
 
     assert(mnt->mnt_root != NULL);
index e0ed4de94e8c4c36062f9909d3118ee482f0417a..375c6e19fa889359b8802b36f1ebc726708baf4f 100644 (file)
@@ -11,4 +11,4 @@
 
 #include "vfs.h"
 
-vfsmount_t *vfs_kernel_mount(fs_type_t *type, int flags, const char *name, void *data);
+vfsmount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data);
index bf92c7334e57690ff93bf0e96e087a99b484a757..141d4e57372742e00d91dc8ec8a4551339bfa3f8 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -20,7 +20,7 @@
 
 int get_unused_fd() {
     int fd;
-    task_files_t *files = &(current->files);
+    task_files_tfiles = &(current->files);
 
     for (int i = 0; i < NR_TASK_OPEN_CNT; i++) {
         if (files->fds[i] == 0) {
@@ -32,7 +32,7 @@ int get_unused_fd() {
     return -EMFILE;
 }
 
-int filp_open(const char *path, int flags, int mode, file_t **fp) {
+int filp_open(const char* path, int flags, int mode, file_t** fp) {
     int ret = 0;
 
     assert(path != NULL);
@@ -58,7 +58,7 @@ int filp_open(const char *path, int flags, int mode, file_t **fp) {
     return ret;
 }
 
-int sysc_open(const char *path, int flags, int mode) {
+int sysc_open(const charpath, int flags, int mode) {
     int fd = 0;
 
     fd = get_unused_fd();
@@ -67,7 +67,7 @@ int sysc_open(const char *path, int flags, int mode) {
         return fd;
     }
 
-    file_t *fp;
+    file_tfp;
 
     int ret = filp_open(path, flags, mode, &fp);
     if (ret != 0) {
index f47d10cf3eadab3399306c6e20489cd5507746ea..dbad1df3fa1cd63f0473f6a20ea27e579a4c7ea9 100644 (file)
--- a/fs/path.c
+++ b/fs/path.c
@@ -15,7 +15,7 @@
 #include <types.h>
 #include <vfs.h>
 
-bool path_init(const char *path, unsigned int flags, namei_t *ni) {
+bool path_init(const char* path, unsigned int flags, namei_t* ni) {
     ni->flags = flags;
     ni->last_type = LAST_ROOT;
 
@@ -37,13 +37,13 @@ bool path_init(const char *path, unsigned int flags, namei_t *ni) {
     return true;
 }
 
-void follow_dotdot(namei_t *ni) {
+void follow_dotdot(namei_tni) {
 #if 1
     panic("not supported");
 #else
     while (1) {
-        dentry_t *dentry = NULL;
-        vfsmount_t *parent = NULL;
+        dentry_tdentry = NULL;
+        vfsmount_tparent = NULL;
 
         // 如果当前目录已经是根目录
         if (ni->dentry == current->dentry_root) {
@@ -103,7 +103,7 @@ void follow_dotdot(namei_t *ni) {
 #endif
 }
 
-uint64_t compute_qstr_hash(qstr_t *q) {
+uint64_t compute_qstr_hash(qstr_tq) {
     q->hash = 0;
     for (int i = 0; i < q->len; i++) {
         uint64_t c = (uint64_t)(q->name[i]);
@@ -117,7 +117,7 @@ uint64_t compute_qstr_hash(qstr_t *q) {
     return q->hash;
 }
 
-int follow_down(dentry_t **dentry, vfsmount_t **vfsmnt) {
+int follow_down(dentry_t** dentry, vfsmount_t** vfsmnt) {
     // assert(*dentry != NULL);
     // assert(*vfsmnt != NULL);
 
@@ -134,8 +134,8 @@ int follow_down(dentry_t **dentry, vfsmount_t **vfsmnt) {
     // }
 }
 
-int path_walk(const char *path, namei_t *ni) {
-    dentry_t *dentry = NULL;
+int path_walk(const char* path, namei_t* ni) {
+    dentry_tdentry = NULL;
     int ret = 0;
     if (path == NULL) {
         return -EINVAL;
@@ -152,7 +152,7 @@ int path_walk(const char *path, namei_t *ni) {
     }
 
     // 拿到当前目录的 inode
-    inode_t *inode = ni->path.dentry->d_inode;
+    inode_tinode = ni->path.dentry->d_inode;
 
     uint32_t path_lookup_flags = ni->flags;
 
@@ -330,9 +330,9 @@ end:
     return ret;
 }
 
-int path_lookup_hash(dentry_t *base, qstr_t *name, dentry_t **dentry) {
+int path_lookup_hash(dentry_t* base, qstr_t* name, dentry_t** dentry) {
     int ret = 0;
-    inode_t *inode = base->d_inode;
+    inode_tinode = base->d_inode;
 
     ret = dentry_cached_lookup(base, name, dentry);
     assert(0 == ret);
@@ -340,7 +340,7 @@ int path_lookup_hash(dentry_t *base, qstr_t *name, dentry_t **dentry) {
         return 0;
     }
 
-    dentry_t *dentry_new = dentry_alloc(base, name);
+    dentry_tdentry_new = dentry_alloc(base, name);
     if (dentry_new == NULL) {
         return ENOMEM;
     }
@@ -356,7 +356,7 @@ int path_lookup_hash(dentry_t *base, qstr_t *name, dentry_t **dentry) {
     return ret;
 }
 
-int path_lookup_create(namei_t *ni, dentry_t **dentry) {
+int path_lookup_create(namei_t* ni, dentry_t** dentry) {
     int err = 0;
 
     // 在调用完path_lookup_create后调用 up 操作
@@ -375,11 +375,11 @@ int path_lookup_create(namei_t *ni, dentry_t **dentry) {
     return err;
 }
 
-int path_open_namei(const char *path, int flags, int mode, namei_t *ni) {
+int path_open_namei(const char* path, int flags, int mode, namei_t* ni) {
     int ret = 0;
-    dentry_t *dentry = NULL;
-    dentry_t *dir = NULL;
-    inode_t *inode = NULL;
+    dentry_tdentry = NULL;
+    dentry_tdir = NULL;
+    inode_tinode = NULL;
 
     if ((flags & O_CREAT) == 0) {
         path_init(path, flags, ni);
index d58471b5873182fc91b4a4d3605f0b444372b01e..ef4c42cd98eb5120cf78c8830e6c2a5a7841c7f2 100644 (file)
@@ -29,9 +29,9 @@ typedef struct ramfs_inode {
     inode_t vfs_inode;
 } ramfs_inode_t;
 
-static kmem_cache_t *g_ramfs_inode_cache = 0;
+static kmem_cache_tg_ramfs_inode_cache = 0;
 
-inode_t *ramfs_get_inode(superblock_t *sb, umode_t mode, dev_t dev);
+inode_t* ramfs_get_inode(superblock_t* sb, umode_t mode, dev_t dev);
 
 // static inode_t *ramfs_alloc_inode(superblock_t *sb) {
 //     ramfs_inode_t *inode = kmem_cache_alloc(g_ramfs_inode_cache, 0);
@@ -60,10 +60,10 @@ static const address_space_operations_t ramfs_address_space_operations = {
     .write_end = NULL,
 };
 
-static int ramfs_mknod(inode_t *dir, dentry_t *dentry, umode_t mode) {
+static int ramfs_mknod(inode_t* dir, dentry_t* dentry, umode_t mode) {
     int ret = 0;
 
-    inode_t *inode = NULL;
+    inode_tinode = NULL;
 
     inode = ramfs_get_inode(dir->i_sb, mode, 0);
     if (inode == NULL) {
@@ -79,15 +79,15 @@ static int ramfs_mknod(inode_t *dir, dentry_t *dentry, umode_t mode) {
     return ret;
 }
 
-static int ramfs_create(inode_t *dir, dentry_t *dentry, umode_t mode, namei_t *ni) {
+static int ramfs_create(inode_t* dir, dentry_t* dentry, umode_t mode, namei_t* ni) {
     return ramfs_mknod(dir, dentry, mode | S_IFREG);
 }
 
-static int ramfs_mkdir(inode_t *dir, dentry_t *dentry, umode_t mode) {
+static int ramfs_mkdir(inode_t* dir, dentry_t* dentry, umode_t mode) {
     return ramfs_mknod(dir, dentry, mode | S_IFDIR);
 }
 
-static dentry_t *ramfs_lookup(inode_t *dir, dentry_t *dentry) {
+static dentry_t* ramfs_lookup(inode_t* dir, dentry_t* dentry) {
     // 不用上dir去找了,直接用dentry就可以了
 
     // dentry对应的inode在ramfs_mkdir等里去分配的
@@ -102,13 +102,13 @@ static const inode_operations_t ramfs_dir_inode_operations = {
     .mkdir = ramfs_mkdir,
 };
 
-void ramfs_debug_set_f_ops(file_t *filp) {
+void ramfs_debug_set_f_ops(file_tfilp) {
     //
     filp->f_ops = &ramfs_file_operations;
 }
 
-inode_t *ramfs_get_inode(superblock_t *sb, umode_t mode, dev_t dev) {
-    inode_t *inode = alloc_inode(sb);
+inode_t* ramfs_get_inode(superblock_t* sb, umode_t mode, dev_t dev) {
+    inode_tinode = alloc_inode(sb);
 
     if (NULL == inode) {
         return inode;
@@ -144,14 +144,14 @@ static sb_operations_t ramfs_ops = {
     // .alloc_inode = ramfs_alloc_inode,
 };
 
-int ramfs_fill_super_cb(superblock_t *sb, void *data) {
+int ramfs_fill_super_cb(superblock_t* sb, void* data) {
     int err = 0;
 
     // assert(sb->sb_ops != NULL);
-    inode_t *fs_root_inode = ramfs_get_inode(sb, S_IFDIR, 0);
+    inode_tfs_root_inode = ramfs_get_inode(sb, S_IFDIR, 0);
     assert(fs_root_inode != NULL);
 
-    dentry_t *fs_root_dentry = 0;
+    dentry_tfs_root_dentry = 0;
     fs_root_dentry = dentry_alloc_root(fs_root_inode);
     assert(fs_root_dentry != NULL);
 
@@ -160,7 +160,7 @@ int ramfs_fill_super_cb(superblock_t *sb, void *data) {
     return err;
 }
 
-int ramfs_read_super(fs_type_t *type, int flags, const char *name, void *data, vfsmount_t *mnt) {
+int ramfs_read_super(fs_type_t* type, int flags, const char* name, void* data, vfsmount_t* mnt) {
     int ret = 0;
 
     ret = read_super_for_nodev(type, flags, data, ramfs_fill_super_cb, mnt);
index 4f7da19fbf89591e1bdc43f6971e25a9de042704..7bb1bfc0e7d65d7441eede07a2b117aadbfd2f7a 100644 (file)
--- a/fs/read.c
+++ b/fs/read.c
 #include <sched.h>
 #include <types.h>
 
-ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_pos) {
+ssize_t vfs_generic_file_read(file_t* file, char* buf, size_t size, loff_t* p_pos) {
     ssize_t ret = 0;
 
     loff_t pos = *p_pos;
 
-    inode_t *inode = file->f_dentry->d_inode;
-    address_space_t *mapping = inode->i_mapping;
+    inode_tinode = file->f_dentry->d_inode;
+    address_space_tmapping = inode->i_mapping;
 
     assert(S_ISREG(inode->i_mode));
 
@@ -30,7 +30,7 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po
     size_t left = size;
 
     while (left > 0) {
-        page_t *page = NULL;
+        page_tpage = NULL;
         uint32_t end_index = inode->i_size >> PAGE_SHIFT;
         if (index > end_index) {
             break;
@@ -47,7 +47,7 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po
         bytes = bytes - offset;
 
         // 在hash里找page
-        page_t *find_hash_page(address_space_t * mapping, uint32_t index);
+        page_tfind_hash_page(address_space_t * mapping, uint32_t index);
         page = find_hash_page(mapping, index);
         if (NULL == page) {
             goto no_cached_page_in_hash;
@@ -58,7 +58,7 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po
 
         // copy data
         bytes = bytes < left ? bytes : left;
-        void *addr = page2va(page);
+        voidaddr = page2va(page);
         // printk("memcpy bytes %u index %u\n", bytes, index);
         // printk("read addr %x bytes %u index %u offset %u\n", addr, bytes, index, offset);
         memcpy(buf, addr + offset, bytes);
@@ -102,15 +102,15 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po
     return ret;
 }
 
-ssize_t sysc_read(int fd, void *buf, size_t count) {
+ssize_t sysc_read(int fd, voidbuf, size_t count) {
     ssize_t ret = 0;
 
-    file_t *file = get_file(fd);
+    file_tfile = get_file(fd);
     if (NULL == file) {
         return EBADF;
     }
 
-    inode_t *inode = file->f_dentry->d_inode;
+    inode_tinode = file->f_dentry->d_inode;
 
     assert(file->f_ops != 0);
     assert(file->f_ops->read != 0);
@@ -118,7 +118,7 @@ ssize_t sysc_read(int fd, void *buf, size_t count) {
     assert(inode->i_fops->read != 0);
     assert(file->f_ops->read == inode->i_fops->read);
 
-    ssize_t (*read)(file_t *, char *, size_t, loff_t *);
+    ssize_t (*read)(file_t*, char*, size_t, loff_t*);
     read = file->f_ops->read;
 
     loff_t pos = file->f_pos;
index 482b3e1b15834d865eb3c96435aefad13d874f6b..a9127f1834ff4f2529966ae34d23f6280951ed26 100644 (file)
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -14,7 +14,7 @@
 #include <sched.h>
 #include <stat.h>
 #include <types.h>
-int sysc_stat(int fd, struct stat *stat) {
+int sysc_stat(int fd, struct statstat) {
 #if 0
     if(fd<0 || fd>=NR_OPENS)
         return -EBADF;
index 2fffc62f42d5c20690a25c8ea59bbe7482231944..8caf94089f99921e19466fd74319e2f87110b8b2 100644 (file)
@@ -15,9 +15,9 @@
 
 LIST_HEAD(g_superblocks);
 
-static superblock_t *alloc_super(fs_type_t *type) {
-    superblock_t *s;
-    s = (superblock_t *)kzalloc(sizeof(superblock_t), 0);
+static superblock_t* alloc_super(fs_type_t* type) {
+    superblock_ts;
+    s = (superblock_t*)kzalloc(sizeof(superblock_t), 0);
     if (0 == s) {
         panic("alloc superblock for %s", type->name);
         return s;
@@ -33,14 +33,14 @@ static superblock_t *alloc_super(fs_type_t *type) {
 }
 
 static uint32_t __minor = 0;
-int set_anonymous_super(superblock_t *s, void *data) {
+int set_anonymous_super(superblock_t* s, void* data) {
     s->sb_dev = MAKE_DEV(0, ++__minor);
     return 0;
 }
 
-int read_super_for_nodev(fs_type_t *type, int flags, void *data, fill_super_cb_t fill_super, vfsmount_t *mnt) {
+int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, vfsmount_t* mnt) {
     int err = 0;
-    superblock_t *s = 0;
+    superblock_ts = 0;
 
     // 分配superblock
     err = sget(type, NULL, set_anonymous_super, NULL, &s);
@@ -61,11 +61,11 @@ int read_super_for_nodev(fs_type_t *type, int flags, void *data, fill_super_cb_t
     return err;
 }
 
-int sget(fs_type_t *type,                      //
-         int (*test)(superblock_t *, void *),  //
-         int (*set)(superblock_t *, void *),   //
-         void *data,                           //
-         superblock_t **s                      //
+int sget(fs_type_t* type,                    //
+         int (*test)(superblock_t*, void*),  //
+         int (*set)(superblock_t*, void*),   //
+         void* data,                         //
+         superblock_t** s                    //
 ) {
     int err = 0;
 
index 836a28540fc035bbaed651ff496bd3a54a084fc4..5ca52750f11bb26c4297ef099fbdb9404b8ac08c 100644 (file)
--- a/fs/vfs.c
+++ b/fs/vfs.c
 // 所谓“安装“就是从一个存储设备上读入超级块,在内存中建立起一个superblock结构。进而将此设备上的根目录
 // 与文件系统中已经存在的一个空白目录挂上钩。
 // 系统初始化时整个文件系统只有一个空白目录"/",所以根设备的根目录就安装到这个节点上。
-dentry_t *root_entry = 0;
+dentry_troot_entry = 0;
 
 fs_type_t file_systems = {"filesystems", 0, 0};
 
-int vfs_register_filesystem(fs_type_t *fs) {
+int vfs_register_filesystem(fs_type_tfs) {
     int ret = 0;
 
     assert(fs != NULL);
@@ -39,11 +39,11 @@ int vfs_register_filesystem(fs_type_t *fs) {
 
     INIT_LIST_HEAD(&fs->sbs);
 
-    fs_type_t *add = &file_systems;
+    fs_type_tadd = &file_systems;
 
     // TODO: 加锁、解锁保护
 
-    for (fs_type_t *fst = &file_systems; fst != 0; fst = fst->next) {
+    for (fs_type_tfst = &file_systems; fst != 0; fst = fst->next) {
         if (strcmp(fst->name, fs->name) == 0) {
             return -EBUSY;
         }
@@ -55,8 +55,8 @@ int vfs_register_filesystem(fs_type_t *fs) {
     return 0;
 }
 
-fs_type_t *vfs_find_filesystem(const char *name) {
-    for (fs_type_t *fs = &file_systems; fs != 0; fs = fs->next) {
+fs_type_t* vfs_find_filesystem(const char* name) {
+    for (fs_type_tfs = &file_systems; fs != 0; fs = fs->next) {
         if (strcmp(fs->name, name) == 0) {
             return fs;
         }
@@ -77,16 +77,16 @@ fs_type_t *vfs_find_filesystem(const char *name) {
 // }
 
 /////////
-vfsmount_t *vfsmnt_get(vfsmount_t *m) {
+vfsmount_t* vfsmnt_get(vfsmount_t* m) {
     panic("todo");
     return NULL;
 }
-void vfsmnt_put(vfsmount_t *m) {
+void vfsmnt_put(vfsmount_tm) {
     //
     panic("todo");
 }
 
-int vfs_create(inode_t *dir, dentry_t *dentry, int mode, namei_t *ni) {
+int vfs_create(inode_t* dir, dentry_t* dentry, int mode, namei_t* ni) {
     int ret = 0;
 
     assert(dir->i_ops != NULL);
@@ -97,7 +97,7 @@ int vfs_create(inode_t *dir, dentry_t *dentry, int mode, namei_t *ni) {
     return ret;
 }
 
-int vfs_mkdir(inode_t *dir, dentry_t *dentry, int mode) {
+int vfs_mkdir(inode_t* dir, dentry_t* dentry, int mode) {
     int ret = 0;
 
     // TODO REMOVE
index effc7c2f020f220cfd171e9fec452b888db8d486..833ad06b68e8c671e59baaf31ab653ea72912d51 100644 (file)
--- a/fs/vfs.h
+++ b/fs/vfs.h
@@ -16,7 +16,7 @@
 #include <types.h>
 
 typedef struct qstr {
-    const char *name;
+    const charname;
     unsigned int len;
     uint64_t hash;
 } qstr_t;
@@ -34,8 +34,8 @@ typedef struct address_space_operations address_space_operations_t;
 typedef struct address_space address_space_t;
 
 struct path {
-    dentry_t *dentry;
-    vfsmount_t *mnt;
+    dentry_tdentry;
+    vfsmount_tmnt;
 };
 
 #define PATH_LOOKUP_PARENT /*    */ 0x00000001
@@ -60,16 +60,16 @@ typedef struct namei {
 typedef struct file file_t;
 
 typedef struct file_operations {
-    int (*open)(inode_t *, file_t *);
-    int (*release)(inode_t *, file_t *);
-    ssize_t (*read)(file_t *, char *, size_t, loff_t *);
-    ssize_t (*write)(file_t *, const char *, size_t, loff_t *);
+    int (*open)(inode_t*, file_t*);
+    int (*release)(inode_t*, file_t*);
+    ssize_t (*read)(file_t*, char*, size_t, loff_t*);
+    ssize_t (*write)(file_t*, const char*, size_t, loff_t*);
 } file_operations_t;
 
 struct file {
     // 多个打开的文件可能是同一个文件
-    dentry_t *f_dentry;
-    const file_operations_t *f_ops;
+    dentry_tf_dentry;
+    const file_operations_tf_ops;
 
     loff_t f_pos;
     uint32_t f_flags;
@@ -80,14 +80,14 @@ struct file {
 // super block
 typedef struct superblock {
     // 该超级起的根目录的 dentry
-    dentry_t *sb_root;
+    dentry_tsb_root;
 
     int sb_flags;
 
     //
-    void *sb_private;
+    voidsb_private;
     //
-    sb_operations_t *sb_ops;
+    sb_operations_tsb_ops;
 
     list_head_t sb_list;
     list_head_t sb_instance;
@@ -96,17 +96,17 @@ typedef struct superblock {
 } superblock_t;
 
 struct address_space_operations {
-    int (*write_page)(page_t *);
-    int (*read_page)(file_t *file, page_t *);
-    int (*write_begin)(file_t *file, page_t *, loff_t pos, int len);
-    int (*write_end)(file_t *file, page_t *, loff_t pos, int len);
+    int (*write_page)(page_t*);
+    int (*read_page)(file_t* file, page_t*);
+    int (*write_begin)(file_t* file, page_t*, loff_t pos, int len);
+    int (*write_end)(file_t* file, page_t*, loff_t pos, int len);
 };
 
 struct address_space {
     list_head_t pages;
     uint32_t total_pages;
-    inode_t *a_inode;
-    const address_space_operations_t *a_ops;
+    inode_ta_inode;
+    const address_space_operations_ta_ops;
 };
 
 // dentry和inode为什么不合二为一?
@@ -118,17 +118,17 @@ struct address_space {
 // 而inode结构代表的是物理意义上的文件
 // 它们之间的关系是多对一的关系
 struct inode {
-    superblock_t *i_sb;
+    superblock_ti_sb;
 
-    void *i_private;
+    voidi_private;
 
     semaphore_t i_sem;
 
     // fops - file ops 的副本
-    const file_operations_t *i_fops;
+    const file_operations_ti_fops;
 
     // ops - inode ops
-    const inode_operations_t *i_ops;
+    const inode_operations_ti_ops;
 
     // 缓存的pages
     list_head_t i_pages;
@@ -140,7 +140,7 @@ struct inode {
 
     umode_t i_mode;  // FILE DIR CHR BLK FIFO SOCK
 
-    address_space_t *i_mapping;
+    address_space_ti_mapping;
     address_space_t i_as;
 };
 
@@ -159,7 +159,7 @@ struct dentry {
     atomic_t d_count;
 
     //
-    dentry_t *d_parent;
+    dentry_td_parent;
 
     // 同一目录里所有结点通过d_child链接在一起
     // 并连到它们父目录的d_subdirs队列中
@@ -169,11 +169,11 @@ struct dentry {
     list_head_t d_hash;
 
     //
-    superblock_t *d_sb;
+    superblock_td_sb;
 
     // 每一个dentry指向一个inode
     // 但多个dentry可以指向同一个inode(不实现)
-    inode_t *d_inode;
+    inode_td_inode;
 
     // 需要一个标记自己已经成为挂载点的标志?
     // uint32_t d_flags;
@@ -182,15 +182,15 @@ struct dentry {
     list_head_t d_vfsmnt;  // 所有挂载到这个目录的挂载点
 
     //
-    dentry_operations_t *d_ops;
+    dentry_operations_td_ops;
 
     //
-    void *d_private;
+    voidd_private;
 };
 
 struct sb_operations {
     // alloc inode
-    inode_t *(*alloc_inode)(superblock_t *sb);
+    inode_t* (*alloc_inode)(superblock_t* sb);
     // read_inode
 };
 
@@ -205,13 +205,13 @@ struct sb_operations {
 // };
 struct inode_operations {
     // 用于在inode下找一个dentry->d_small_name的目录项
-    dentry_t *(*lookup)(inode_t *, dentry_t *);
+    dentry_t* (*lookup)(inode_t*, dentry_t*);
 
     // 在inode下创建一个dentry->d_small_name的文件
-    int (*create)(inode_t *, dentry_t *, umode_t, namei_t *);
+    int (*create)(inode_t*, dentry_t*, umode_t, namei_t*);
 
     // 创建文件夹
-    int (*mkdir)(inode_t *, dentry_t *, umode_t);
+    int (*mkdir)(inode_t*, dentry_t*, umode_t);
 
     // link
     // unlink
@@ -244,15 +244,15 @@ struct dentry_operations {
 // 将vfsmount与被安装设备的根目录dentry关联
 #define MAX_VFSMNT_NAME_LEN 32
 struct vfsmount {
-    dentry_t *mnt_point;   // 挂载点 dentry
-    dentry_t *mnt_root;    // 设备根目录 dentry
-    superblock_t *mnt_sb;  // 被安装的设备的superblock
-    struct vfsmount *mnt_parent;  // 如果多个设备挂载到同一个目录,则每个vfsmount的parent都指向同一个vfsmount
+    dentry_t* mnt_point;          // 挂载点 dentry
+    dentry_t* mnt_root;           // 设备根目录 dentry
+    superblock_t* mnt_sb;         // 被安装的设备的superblock
+    struct vfsmountmnt_parent;  // 如果多个设备挂载到同一个目录,则每个vfsmount的parent都指向同一个vfsmount
     // sb->sb_ops->read_inode得到被安装设备根目录的inode
 
     list_head_t mnt_list;  // vfsmount 链表
 
-    vfsmount_t *hash_next;
+    vfsmount_thash_next;
 
     char mnt_devname[MAX_VFSMNT_NAME_LEN];
 
@@ -266,65 +266,65 @@ struct vfsmount {
 
 typedef struct fs_type fs_type_t;
 struct fs_type {
-    const char *name;
+    const charname;
     // superblock_t *(*read_super)(superblock_t *, void *);
-    int (*read_super)(fs_type_t *type, int flags, const char *name, void *data, vfsmount_t *mnt);
+    int (*read_super)(fs_type_t* type, int flags, const char* name, void* data, vfsmount_t* mnt);
     int flags;  // FS_REQUIRES_DEV or NODEV
-    struct fs_type *next;
+    struct fs_typenext;
     // 同属于这个文件系统的所有超级块链表
     // 因为同名文件系统可能有多个实例,所有的该文件系统的实例的superblock,都通过sbs这个链到一起
     list_head_t sbs;
 };
 
-extern superblock_t *root_sb;
+extern superblock_troot_sb;
 
-int vfs_register_filesystem(fs_type_t *fs);
-fs_type_t *vfs_find_filesystem(const char *name);
+int vfs_register_filesystem(fs_type_tfs);
+fs_type_t* vfs_find_filesystem(const char* name);
 /////
 
-int vfs_create(inode_t *dir, dentry_t *dentry, int mode, namei_t *ni);
-int vfs_mkdir(inode_t *dir, dentry_t *dentry, int mode);
+int vfs_create(inode_t* dir, dentry_t* dentry, int mode, namei_t* ni);
+int vfs_mkdir(inode_t* dir, dentry_t* dentry, int mode);
 ////
 
-inode_t *alloc_inode(superblock_t *sb);
-void init_special_inode(inode_t *inode, umode_t mode, dev_t rdev);
+inode_t* alloc_inode(superblock_t* sb);
+void init_special_inode(inode_tinode, umode_t mode, dev_t rdev);
 ////
 
-int dentry_cached_lookup(dentry_t *parent,  //
-                         qstr_t *s,         //
-                         dentry_t **dentry  // OUT
+int dentry_cached_lookup(dentry_tparent,  //
+                         qstr_ts,         //
+                         dentry_t** dentry  // OUT
 );
 
-int dentry_real_lookup(dentry_t *parent,  //
-                       qstr_t *s,         //
-                       dentry_t **dentry  // OUT
+int dentry_real_lookup(dentry_tparent,  //
+                       qstr_ts,         //
+                       dentry_t** dentry  // OUT
 );
 
-dentry_t *dentry_alloc_root(inode_t *root_inode);
-dentry_t *dentry_alloc(dentry_t *parent, const qstr_t *s);
-void dentry_add(dentry_t *dentry, inode_t *inode);
-void dentry_attach_inode(dentry_t *dentry, inode_t *inode);
+dentry_t* dentry_alloc_root(inode_t* root_inode);
+dentry_t* dentry_alloc(dentry_t* parent, const qstr_t* s);
+void dentry_add(dentry_t* dentry, inode_t* inode);
+void dentry_attach_inode(dentry_t* dentry, inode_t* inode);
 
-vfsmount_t *vfsmnt_get(vfsmount_t *m);
-void vfsmnt_put(vfsmount_t *m);
+vfsmount_t* vfsmnt_get(vfsmount_t* m);
+void vfsmnt_put(vfsmount_tm);
 
-dentry_t *dentry_get(dentry_t *dentry);
-void dentry_get_locked(dentry_t *dentry);
+dentry_t* dentry_get(dentry_t* dentry);
+void dentry_get_locked(dentry_tdentry);
 
-void dentry_put(dentry_t *dentry);
+void dentry_put(dentry_tdentry);
 
 //
-bool path_init(const char *path, unsigned int flags, namei_t *ni);
-int path_walk(const char *path, namei_t *ni);
-int path_lookup_create(namei_t *ni,       //
-                       dentry_t **dentry  // OUT
+bool path_init(const char* path, unsigned int flags, namei_t* ni);
+int path_walk(const char* path, namei_t* ni);
+int path_lookup_create(namei_tni,       //
+                       dentry_t** dentry  // OUT
 );
 
-int path_open_namei(const char *path, int flags, int mode, namei_t *ni);
+int path_open_namei(const char* path, int flags, int mode, namei_t* ni);
 
 //
-ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_pos);
-ssize_t vfs_generic_file_write(file_t *file, const char *buf, size_t size, loff_t *p_pos);
+ssize_t vfs_generic_file_read(file_t* file, char* buf, size_t size, loff_t* p_pos);
+ssize_t vfs_generic_file_write(file_t* file, const char* buf, size_t size, loff_t* p_pos);
 
 // file
-file_t *get_empty_filp();
+file_tget_empty_filp();
index 1271fceb97a3f1be08442a5e7c1d8ada33e9f081..2618a5b035612acc76546f6023bb2b75a0f50ed6 100644 (file)
@@ -23,9 +23,9 @@
 #include <string.h>
 #include <types.h>
 
-page_t *get_cached_page(address_space_t *mapping, uint32_t index);
+page_t* get_cached_page(address_space_t* mapping, uint32_t index);
 
-ssize_t vfs_generic_file_write(file_t *file, const char *buf, size_t size, loff_t *p_pos) {
+ssize_t vfs_generic_file_write(file_t* file, const char* buf, size_t size, loff_t* p_pos) {
     ssize_t ret = 0;
 
     loff_t pos = *p_pos;
@@ -36,10 +36,10 @@ ssize_t vfs_generic_file_write(file_t *file, const char *buf, size_t size, loff_
     assert(file->f_dentry->d_inode != NULL);
     assert((file->f_flags & O_APPEND) == O_APPEND);  // 目前只支持这个
 
-    inode_t *inode = file->f_dentry->d_inode;
+    inode_tinode = file->f_dentry->d_inode;
     assert(inode != NULL);
 
-    address_space_t *mapping = inode->i_mapping;
+    address_space_tmapping = inode->i_mapping;
     assert(mapping->a_inode == inode);
     assert(mapping->a_ops != NULL);
     // assert(mapping->a_ops->read_page != NULL);
@@ -57,12 +57,12 @@ ssize_t vfs_generic_file_write(file_t *file, const char *buf, size_t size, loff_
 
         // 找出page
         // 若找不出,则分配一个,并加到cache里
-        page_t *page = get_cached_page(mapping, index);
+        page_tpage = get_cached_page(mapping, index);
         assert(page != NULL);
         assert(page->index == index);
         assert(page->mapping == mapping);
 
-        void *addr = page2va(page);
+        voidaddr = page2va(page);
 
         // TODO
         // ...
@@ -89,17 +89,17 @@ end:
     return ret;
 }
 
-ssize_t sysc_write(int fd, const char *buf, size_t size) {
+ssize_t sysc_write(int fd, const charbuf, size_t size) {
     ssize_t ret = 0;
 
-    file_t *file = get_file(fd);
+    file_tfile = get_file(fd);
     if (NULL == file) {
         return EBADF;
     }
 
     // TODO 检查文件是否有写权限
 
-    inode_t *inode = file->f_dentry->d_inode;
+    inode_tinode = file->f_dentry->d_inode;
 
     assert(file->f_ops != 0);
     assert(file->f_ops->write != 0);
@@ -107,7 +107,7 @@ ssize_t sysc_write(int fd, const char *buf, size_t size) {
     assert(inode->i_fops->write != 0);
     assert(file->f_ops->write == inode->i_fops->write);
 
-    ssize_t (*write)(file_t *, const char *, size_t, loff_t *);
+    ssize_t (*write)(file_t*, const char*, size_t, loff_t*);
     write = file->f_ops->write;
 
     ret = write(file, buf, size, &file->f_pos);
index f6b82d660b552cc6988fd5825d1a2c2d211b7d08..c7c02626bcc7539e964fd5ef7bab6d139635bdaf 100644 (file)
@@ -16,7 +16,7 @@
 #include <global.h>
 
 #ifndef ASM
-void assert_fail(char *exp, char *file, unsigned int line, const char *func);
+void assert_fail(char* exp, char* file, unsigned int line, const char* func);
 #define assert(exp) ((exp) ? (void)(0) : assert_fail(__STRING(exp), __FILE__, __LINE__, __PRETTY_FUNCTION__))
 #endif
 
index f16af72ccf7d4c72a16b78345789e655df707c6d..27168727155d36f5a183ef13fee7e52630daaff1 100644 (file)
@@ -17,12 +17,20 @@ typedef struct atomic {
     volatile int counter;
 } atomic_t;
 
-static inline void atomic_inc(atomic_t *v) { __sync_add_and_fetch(&(v->counter), 1); }
-static inline void atomic_dec(atomic_t *v) { __sync_sub_and_fetch(&(v->counter), 1); }
-
-static inline int atomic_read(atomic_t *v) { return *((int *)(&(v->counter))); }
-
-static inline void atomic_set(atomic_t *v, int i) { __sync_lock_test_and_set(&(v->counter), i); }
+static inline void atomic_inc(atomic_t* v) {
+    __sync_add_and_fetch(&(v->counter), 1);
+}
+static inline void atomic_dec(atomic_t* v) {
+    __sync_sub_and_fetch(&(v->counter), 1);
+}
+
+static inline int atomic_read(atomic_t* v) {
+    return *((int*)(&(v->counter)));
+}
+
+static inline void atomic_set(atomic_t* v, int i) {
+    __sync_lock_test_and_set(&(v->counter), i);
+}
 
 #else
 
index c9389933e48ef88b66447b137c40fa51b992957b..a2ba8e25125eb35def330a539040dd638d7b0af3 100644 (file)
 #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(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 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)); }
+static inline void btc(unsigned int* v, unsigned int b) {
+    asm("btc %1,%0" : "=m"(*v) : "Ir"(b));
+}
 
-static inline int test_and_set_bit(unsigned int nr, volatile unsigned long *addr) {
+static inline int test_and_set_bit(unsigned int nr, volatile unsigned longaddr) {
     int oldbit;
 
     asm("bts %2,%1\n\t"
         "sbb %0,%0"
-        : "=r"(oldbit), "+m"(*(volatile long *)(addr))
+        : "=r"(oldbit), "+m"(*(volatile long*)(addr))
         : "Ir"(nr));
     return oldbit;
 }
 
-static inline int test_and_clear_bit(unsigned int nr, volatile unsigned long *addr) {
+static inline int test_and_clear_bit(unsigned int nr, volatile unsigned longaddr) {
     int oldbit;
 
     asm volatile(
         "btr %2,%1\n\t"
         "sbb %0,%0"
-        : "=r"(oldbit), "+m"(*(volatile long *)(addr))
+        : "=r"(oldbit), "+m"(*(volatile long*)(addr))
         : "Ir"(nr)
         : "memory");
 
@@ -60,13 +62,13 @@ static inline int test_and_clear_bit(unsigned int nr, volatile unsigned long *ad
  * This operation is atomic and cannot be reordered.
  * It also implies a memory barrier.
  */
-static inline int test_and_change_bit(int nr, volatile unsigned long *addr) {
+static inline int test_and_change_bit(int nr, volatile unsigned longaddr) {
     int oldbit;
 
     asm volatile(
         "btc %2,%1\n\t"
         "sbb %0,%0"
-        : "=r"(oldbit), "+m"(*(volatile long *)(addr))
+        : "=r"(oldbit), "+m"(*(volatile long*)(addr))
         : "Ir"(nr)
         : "memory");
 
@@ -82,12 +84,12 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr) {
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void change_bit(int nr, volatile unsigned long *addr) {
-    asm volatile("btc %1,%0" : "+m"(*(volatile long *)(addr)) : "Ir"(nr));
+static inline void change_bit(int nr, volatile unsigned longaddr) {
+    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) {
-    return ((1UL << (nr % BITS_PER_LONG)) & (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
+static inline int constant_test_bit(unsigned int nr, const volatile unsigned longaddr) {
+    return ((1UL << (nr % BITS_PER_LONG)) & (((unsigned long*)addr)[nr / BITS_PER_LONG])) != 0;
 }
 
 /**
@@ -98,7 +100,7 @@ static inline int constant_test_bit(unsigned int nr, const volatile unsigned lon
  * Returns the bit-number of the first set bit, not the number of the byte
  * containing a bit.
  */
-static inline int find_first_bit(const unsigned long *addr, unsigned size) {
+static inline int find_first_bit(const unsigned longaddr, unsigned size) {
     int d0, d1;
     int res;
 
@@ -126,11 +128,12 @@ static inline int find_first_bit(const unsigned long *addr, unsigned size) {
  * Returns the bit-number of the first zero bit, not the number of the byte
  * containing a bit.
  */
-static inline int find_first_zero_bit(const unsigned long *addr, unsigned size) {
+static inline int find_first_zero_bit(const unsigned longaddr, unsigned size) {
     int d0, d1, d2;
     int res;
 
-    if (!size) return 0;
+    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"
@@ -155,8 +158,8 @@ static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
  * @offset: The bitnumber to start searching at
  * @size: The maximum size to search
  */
-static inline int find_next_zero_bit(const unsigned long *addr, int size, int offset) {
-    unsigned long *p = ((unsigned long *)addr) + (offset >> 5);
+static inline int find_next_zero_bit(const unsigned longaddr, int size, int offset) {
+    unsigned long* p = ((unsigned long*)addr) + (offset >> 5);
     int set = 0, bit = offset & 31, res;
 
     if (bit) {
@@ -170,25 +173,26 @@ static inline int find_next_zero_bit(const unsigned long *addr, int size, int of
             "1:"
             : "=r"(set)
             : "r"(~(*p >> bit)));
-        if (set < (32 - bit)) return set + offset;
+        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));
+    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) {
+static inline int variable_test_bit(int nr, volatile const unsigned longaddr) {
     int oldbit;
 
     asm volatile(
         "bt %2,%1\n\t"
         "sbb %0,%0"
         : "=r"(oldbit)
-        : "m"(*(unsigned long *)addr), "Ir"(nr));
+        : "m"(*(unsigned long*)addr), "Ir"(nr));
 
     return oldbit;
 }
index b4157566900e82f4a33dfc78afbcf3bacfb70a35..b3bfcf09bb28063acb5ee6818efedc76bc927f44 100644 (file)
 #include <system.h>
 typedef struct bbuffer {
     uint32_t block;  // block number
-    void *data;      //
+    voiddata;      //
     atomic_t ref_count;
     dev_t dev;
-    page_t *page;
+    page_tpage;
     list_head_t node;
     completion_t io_done;
     uint16_t block_size;  // block size
     uint16_t uptodate : 1;
 } bbuffer_t;
 
-bbuffer_t *bread(dev_t dev, uint64_t block, uint32_t size);
+bbuffer_tbread(dev_t dev, uint64_t block, uint32_t size);
 
-void brelse(bbuffer_t *b);
+void brelse(bbuffer_tb);
index e18af1d612cf1d5d60428e3c587ae2c5b5db8fa4..fb4ae1a431097a8d40d384b40c302635853b82d6 100644 (file)
@@ -15,7 +15,8 @@
         panic("BUG!");                                        \
     } while (0)
 
-#define BUG_ON(condition)                      \
-    do {                                       \
-        if (unlikely((condition) != 0)) BUG(); \
+#define BUG_ON(condition)               \
+    do {                                \
+        if (unlikely((condition) != 0)) \
+            BUG();                      \
     } while (0)
index a367a86ed342053eb170de5e54e87207111ad944..a91a4c9678dd43060278f9656f7ad90a03bf1a2b 100644 (file)
@@ -16,15 +16,14 @@ typedef struct completion {
     wait_queue_head_t wait;
 
     // 仅用于调试
-    char *name;
+    charname;
 } completion_t;
 
-#define COMPLETION_INITIALIZER(x) \
-    { 0, WAIT_QUEUE_HEAD_INITIALIZER(x).wait }
+#define COMPLETION_INITIALIZER(x) {0, WAIT_QUEUE_HEAD_INITIALIZER(x).wait}
 
-void init_completion(completion_t *x);
+void init_completion(completion_tx);
 
-void wait_completion(completion_t *x);
+void wait_completion(completion_tx);
 
 // 一次只唤醒一个进程
-void complete(completion_t *x);
+void complete(completion_tx);
index 522ad4c6364d45197832d6f80b84bbe83774b905..d7ceb499a23964a1c8357c3224ed8c5938e78765 100644 (file)
@@ -9,10 +9,8 @@
 
 #pragma once
 
-
 typedef struct cpuid_regs {
     unsigned long eax, ebx, ecx, edx;
 } cpuid_regs_t;
 
-
 cpuid_regs_t cpuid(unsigned long op);
index 90fc202056e66ca22ae26cd9401a4ca0aa4700e0..a0dd42f82bfb502a91686943c20974e8801f8570 100644 (file)
@@ -24,8 +24,8 @@ typedef struct disk_request {
     dev_t dev;
     uint64_t pos;    // 扇区号
     uint16_t count;  // 扇区数
-    void *buf;       // 到的缓冲区
-    bbuffer_t *bb;
+    voidbuf;       // 到的缓冲区
+    bbuffer_tbb;
     disk_request_cmd_t command;  // 命令
     list_head_t list;
     semaphore_t sem;
@@ -41,4 +41,4 @@ typedef struct {
     semaphore_t sem;
 } disk_request_queue_t;
 
-int send_disk_request(disk_request_t *r);
+int send_disk_request(disk_request_tr);
index 3e21fb025bdfe4123a2c6965700f2808df064088..f13099eaf8a5cb8372520ebf788006fe499bbc6f 100644 (file)
 #define NR_FILES (1)
 #define NR_OPENS (1)
 
-unsigned int namei(const char *path);
+unsigned int namei(const charpath);
 
 #define MAX_SUPT_FILE_SIZE (EXT2_IND_BLOCK * EXT2_BLOCK_SIZE)
 
 typedef struct chrdev {
-    int (*read)(char *buf, size_t count);
+    int (*read)(charbuf, size_t count);
 } chrdev_t;
 
 enum { CHRDEV_CNSL, CHRDEV_SIZE };
 
-extern chrdev_t *chrdev[];
+extern chrdev_tchrdev[];
 
-typedef int (*fill_super_cb_t)(superblock_t *sb, void *data);
-int read_super_for_nodev(fs_type_t *type, int flags, void *data, fill_super_cb_t fill_super, vfsmount_t *mnt);
+typedef int (*fill_super_cb_t)(superblock_t* sb, void* data);
+int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, vfsmount_t* mnt);
 
-int sget(fs_type_t *type,                      //
-         int (*test)(superblock_t *, void *),  //
-         int (*set)(superblock_t *, void *),   //
-         void *data,                           //
-         superblock_t **s                      // OUT
+int sget(fs_type_t* type,                    //
+         int (*test)(superblock_t*, void*),  //
+         int (*set)(superblock_t*, void*),   //
+         void* data,                         //
+         superblock_t** s                    // OUT
 );
 
-file_t *get_file(int fd);
+file_tget_file(int fd);
 
 #endif  //_FS_H
index c4c81fc16f32bdee990d8e6333f68ff0fa9b3a27..ab27185987edc2bd18d14223e6338b7c9408dde8 100644 (file)
@@ -55,7 +55,7 @@
     })
 
 #define BUILDIO(bwl, type)                                                     \
-    static inline void ins##bwl(int port, void *buf, unsigned long count) {    \
+    static inline void ins##bwl(int port, voidbuf, unsigned long count) {    \
         asm volatile("cld;rep;ins" #bwl : "+c"(count), "+D"(buf) : "d"(port)); \
     }
 
index 647d4699490d347eaa9fe42b89beca3a68d3438b..8554286f061265932fd72ab07e6bd036f3f53340 100644 (file)
@@ -23,7 +23,7 @@
 #define NR_IRQS (0xFF - FIRST_IRQ_VECT)
 
 typedef struct irq_chip {
-    const char *name;
+    const charname;
     int (*enable)(unsigned int irq);
     int (*disable)(unsigned int irq);
     void (*ack)(unsigned int irq);
@@ -31,23 +31,23 @@ typedef struct irq_chip {
 
 typedef struct irqaction {
     // void (*handler)(pt_regs_t * regs, unsigned int irq);
-    void (*handler)(unsigned int irq, pt_regs_t *regs, void *dev_id);
-    const char *dev_name;
-    void *dev_id;
-    struct irqaction *next;
+    void (*handler)(unsigned int irq, pt_regs_t* regs, void* dev_id);
+    const chardev_name;
+    voiddev_id;
+    struct irqactionnext;
 } irq_action_t;
 
 typedef struct irq_desc {
-    irq_chip_t *chip;
-    irq_action_t *action;
+    irq_chip_tchip;
+    irq_action_taction;
     unsigned int status;
     unsigned int depth;
 } irq_desc_t;
 
 typedef struct irq_bh_action {
     void (*handler)();
-    void *arg;
-    struct irq_bh_action *next;
+    voidarg;
+    struct irq_bh_actionnext;
 } irq_bh_action_t;
 
 extern irq_chip_t i8259_chip;
@@ -55,9 +55,9 @@ extern irq_desc_t irq_desc[];
 extern irq_desc_t no_irq_desc;
 int request_irq(unsigned int irq,
                 // void (*handler)(pt_regs_t *, unsigned int),
-                void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname, void *dev_id);
+                void (*handler)(unsigned int, pt_regs_t*, void*), const char* devname, void* dev_id);
 
-void add_irq_bh_handler(void (*handler)(), void *arg);
+void add_irq_bh_handler(void (*handler)(), voidarg);
 
 int open_irq(unsigned int irq);
 int close_irq(unsigned int irq);
@@ -79,13 +79,11 @@ bool irq_disabled();
 void enter_critical_zone();
 void exit_critical_zone();
 
-#define ENTER_CRITICAL_ZONE(x) \
-        volatile uint32_t __critical_zone_eflags_##x = 0; \
-        irq_save(__critical_zone_eflags_##x);
+#define ENTER_CRITICAL_ZONE(x)                        \
+    volatile uint32_t __critical_zone_eflags_##x = 0; \
+    irq_save(__critical_zone_eflags_##x);
 
-
-#define EXIT_CRITICAL_ZONE(x) \
-        irq_restore(__critical_zone_eflags_##x);
+#define EXIT_CRITICAL_ZONE(x) irq_restore(__critical_zone_eflags_##x);
 
 #define IRQ_CLOCK 0x00
 #define IRQ_KEYBOARD 0x01
index e995408718f56b003c859fe5751382f84fe7e5ff..7edc575f334d7ff1d18dc2d7c8f2c73d9eeb2b89 100644 (file)
@@ -21,8 +21,7 @@ typedef struct list_head {
     struct list_head *prev, *next;
 } list_head_t;
 
-#define LIST_HEAD_INIT(name) \
-    { &(name), &(name) }
+#define LIST_HEAD_INIT(name) {&(name), &(name)}
 #define LIST_HEAD(name) list_head_t name = LIST_HEAD_INIT(name)
 
 #define INIT_LIST_HEAD(ptr)  \
@@ -31,7 +30,7 @@ typedef struct list_head {
         (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_first_entry(ptr, type, member) list_entry((ptr)->next, type, member)
 
@@ -45,29 +44,39 @@ typedef struct list_head {
         tmp = list_entry(pos->member.next, typeof(*pos), member); \
          &pos->member != (head); pos = tmp, tmp = list_entry(tmp->member.next, typeof(*tmp), member))
 
-static inline void _list_add(list_head_t *pnew, list_head_t *prev, list_head_t *next) {
+static inline void _list_add(list_head_t* pnew, list_head_t* prev, list_head_t* next) {
     next->prev = pnew;
     pnew->next = next;
     pnew->prev = prev;
     prev->next = pnew;
 }
 
-static inline void list_add(list_head_t *pnew, list_head_t *head) { _list_add(pnew, head, head->next); }
+static inline void list_add(list_head_t* pnew, list_head_t* head) {
+    _list_add(pnew, head, head->next);
+}
 
-static inline void list_add_tail(list_head_t *pnew, list_head_t *head) { _list_add(pnew, head->prev, head); }
+static inline void list_add_tail(list_head_t* pnew, list_head_t* head) {
+    _list_add(pnew, head->prev, head);
+}
 
-static inline void _list_del(list_head_t *prev, list_head_t *next) {
+static inline void _list_del(list_head_t* prev, list_head_t* next) {
     next->prev = prev;
     prev->next = next;
 }
 
-static inline void list_del(list_head_t *entry) { _list_del(entry->prev, entry->next); }
+static inline void list_del(list_head_t* entry) {
+    _list_del(entry->prev, entry->next);
+}
 
-static inline void list_del_init(list_head_t *entry) {
+static inline void list_del_init(list_head_tentry) {
     _list_del(entry->prev, entry->next);
     INIT_LIST_HEAD(entry);
 }
 
-static inline int list_empty(list_head_t *head) { return head->next == head; }
+static inline int list_empty(list_head_t* head) {
+    return head->next == head;
+}
 
-static inline void list_init(list_head_t *head) { INIT_LIST_HEAD(head); }
+static inline void list_init(list_head_t* head) {
+    INIT_LIST_HEAD(head);
+}
index 442f1d044703e08d5fd522ee22af898f493a01b5..a307fb86fc70b33d4d1698b479e9a2cad40fb9f9 100644 (file)
 #define BOOTMEM_PAGE_FREE 0
 #define BOOTMEM_PAGE_USED 1
 
-void *alloc_bootmem(unsigned long size, unsigned long align);
+voidalloc_bootmem(unsigned long size, unsigned long align);
 unsigned long bootmem_max_pfn();
 unsigned long bootmem_page_state(unsigned long pfn);
 
-kmem_cache_t *kmem_cache_create(const char *name, size_t size, size_t align);
-void *kmem_cache_alloc(kmem_cache_t *cache, gfp_t gfpflags);
-void *kmem_cache_zalloc(kmem_cache_t *cache, gfp_t gfpflags);
+kmem_cache_t* kmem_cache_create(const char* name, size_t size, size_t align);
+void* kmem_cache_alloc(kmem_cache_t* cache, gfp_t gfpflags);
+void* kmem_cache_zalloc(kmem_cache_t* cache, gfp_t gfpflags);
 
 #define VM_READ 0x00000001
 #define VM_WRITE 0x00000002
@@ -34,5 +34,5 @@ typedef struct vm_area {
 
     uint32_t vm_flags;
 
-    struct vm_area *vm_next;
+    struct vm_areavm_next;
 } vm_area_t;
index d25761e736243c787d9a0e090b9e1a1ee4982791..c4c7debe2db64c6259c902bea01486e73cc0df5b 100644 (file)
@@ -25,8 +25,6 @@
 // bit[12:MAXPHYADDR] 用于配置APIC寄存器组的物理基地址
 #define MSR_IA32_APIC_BASE 0x1B
 
-
-
 #define MSR_SYSENTER_CS 0x174
 #define MSR_SYSENTER_ESP 0x175
 #define MSR_SYSENTER_EIP 0x176
@@ -34,7 +32,6 @@
 #define MSR_IA32_PERF_STATUS 0x198
 #define MSR_IA32_PERF_CRTL 0x199
 
-
 // APIC的ID寄存器
 #define MSR_IA32_X2APIC_APICID 0x802
 // APIC的版本寄存器
index 4fb2d287dfb009b70d8d8fbb66b896430f428aa4..4aff24d8d99ce382e5c93bb0edc75fe57c54f6d2 100644 (file)
@@ -105,11 +105,11 @@ typedef unsigned long pte_t;
 #define PAGE_FLAGS(addr) ((addr) - PAGE_ALIGN(addr))
 
 #define va2pa(x) (((unsigned long)(x)) - PAGE_OFFSET)
-#define pa2va(x) ((void *)(((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 pfn2pa(pfn) ((void *)((pfn) << PAGE_SHIFT))
+#define pfn2pa(pfn) ((void*)((pfn) << PAGE_SHIFT))
 
 #define va2pfn(addr) pa2pfn(va2pa(addr))
 #define pfn2va(pfn) pa2va(pfn2pa(pfn))
@@ -128,8 +128,8 @@ static inline unsigned long get_cr3() {
     return cr3;
 }
 
-static inline pde_t *get_pgd() {
-    return (pde_t *)(get_cr3() & PAGE_MASK);
+static inline pde_tget_pgd() {
+    return (pde_t*)(get_cr3() & PAGE_MASK);
 }
 
 typedef unsigned int gfp_t;
@@ -152,41 +152,49 @@ typedef struct page {
 
     list_head_t list;
 
-    struct page *head_page;  // buddy system
+    struct pagehead_page;  // buddy system
     unsigned int order;
 
-    void **freelist;  // for slub
+    void** freelist;  // for slub
 
     unsigned long index;
-    struct page *hash_next;
-    struct address_space *mapping;
+    struct pagehash_next;
+    struct address_spacemapping;
 
-    kmem_cache_t *cache;
+    kmem_cache_tcache;
 
     unsigned long inuse;
 
     //
-    struct blk_buffer *buffers;
+    struct blk_bufferbuffers;
 } page_t;
 
-void *page2va(page_t *page);
-void *page2pa(page_t *page);
-page_t *_va2page(unsigned long addr);
-page_t *_pa2page(unsigned long addr);
+void* page2va(page_t* page);
+void* page2pa(page_t* page);
+page_t_va2page(unsigned long addr);
+page_t_pa2page(unsigned long addr);
 
 #define va2page(addr) _va2page(PAGE_ALIGN(addr))
 #define pa2page(addr) _pa2page(PAGE_ALIGN(addr))
 
-static inline page_t *get_head_page(page_t *page) { return page->head_page; }
+static inline page_t* get_head_page(page_t* page) {
+    return page->head_page;
+}
 
-#define __GETPAGEFLAG(name) \
-    static inline int Page##name(page_t *page) { return constant_test_bit(PG_##name, &page->flags); }
+#define __GETPAGEFLAG(name)                                \
+    static inline int Page##name(page_t* page) {           \
+        return constant_test_bit(PG_##name, &page->flags); \
+    }
 
-#define __SETPAGEFLAG(name) \
-    static inline int SetPage##name(page_t *page) { return test_and_set_bit(PG_##name, &page->flags); }
+#define __SETPAGEFLAG(name)                               \
+    static inline int SetPage##name(page_t* page) {       \
+        return test_and_set_bit(PG_##name, &page->flags); \
+    }
 
-#define __CLEARPAGEFLAG(name) \
-    static inline int ClearPage##name(page_t *page) { return test_and_clear_bit(PG_##name, &page->flags); }
+#define __CLEARPAGEFLAG(name)                               \
+    static inline int ClearPage##name(page_t* page) {       \
+        return test_and_clear_bit(PG_##name, &page->flags); \
+    }
 
 __GETPAGEFLAG(Private)
 __SETPAGEFLAG(Private)
@@ -197,13 +205,13 @@ typedef struct free_area {
     list_head_t free_list;
 } free_area_t;
 
-page_t *alloc_pages(unsigned int gfp_mask, unsigned int order);
+page_talloc_pages(unsigned int gfp_mask, unsigned int order);
 void free_pages(unsigned long addr);
 
 #define alloc_one_page(gfp_mask) alloc_pages(gfp_mask, 0)
 
 struct kmem_cache {
-    const char *name;
+    const charname;
 
     // 预期分配的大小
     unsigned long objsize;
@@ -225,12 +233,11 @@ struct kmem_cache {
     list_head_t partial;
 
     // 正在分配的页
-    page_t *page;
+    page_tpage;
 
     list_head_t list;
 };
 
-
 void page_map(vaddr_t vaddr, paddr_t paddr, uint32_t flags);
 
 #endif  // ASM
index 184da524704769b7eb4825c304c15aac989240ba..724c2df2f2b230fac62a6a6ef580d2bc334e8dce 100644 (file)
@@ -265,10 +265,12 @@ typedef union pci_device
 #define PCI_VENDORID_NVIDIA 0x10DE
 #define PCI_VENDORID_REALTEK 0x10EC
 
-pci_device_t *pci_find_device(unsigned int vendor, unsigned int device);
-pci_device_t *pci_find_device_by_classcode(unsigned int classcode);
+pci_device_tpci_find_device(unsigned int vendor, unsigned int device);
+pci_device_tpci_find_device_by_classcode(unsigned int classcode);
 
-static inline u32 pci_cmd(pci_device_t *pci, unsigned int reg) { return PCI_CMD(pci->bus, pci->dev, pci->devfn, reg); }
+static inline u32 pci_cmd(pci_device_t* pci, unsigned int reg) {
+    return PCI_CMD(pci->bus, pci->dev, pci->devfn, reg);
+}
 
 int pci_read_config_byte(int cmd);
 int pci_read_config_word(int cmd);
index 001d5d4839ba6d7a6bfc97df21a2ede2d7a7265d..f34b2c69749c44b0da947d8699f3ea79d19837f4 100644 (file)
@@ -16,9 +16,9 @@
 
 #pragma once
 
-int printk(const char *fmtstr, ...);
-int printd(const char *fmtstr, ...);
-int printlo(unsigned int line, unsigned int offset, const char *fmtstr, ...);
+int printk(const charfmtstr, ...);
+int printd(const charfmtstr, ...);
+int printlo(unsigned int line, unsigned int offset, const charfmtstr, ...);
 
 #define printl(line, fmt, args...) printlo(1, line, fmt, ##args)
 #define printll(line, fmt, args...) printlo(0, line, fmt, ##args)
@@ -54,4 +54,4 @@ enum {
     MPO_IDE = 1,
 };
 
-int sprintf(char *str, const char *fmtstr, ...);
+int sprintf(char* str, const char* fmtstr, ...);
index 587eac5427ba552ace2838e59d508315954167b9..3180c1014de316a7e76f7028736ac4a554a8c2e3 100644 (file)
@@ -102,7 +102,9 @@ extern Desc gdt[NGDT];
 #define TRAP_GATE 0x0F  // Keep  'IF' bit.
 #define TSS_DESC 0x09
 
-static inline void _init_desc(pDesc desc) { memset((char *)desc, 0, sizeof(Desc)); }
+static inline void _init_desc(pDesc desc) {
+    memset((char*)desc, 0, sizeof(Desc));
+}
 
 static inline Desc _create_seg(u8 type, u8 DPL) {
     Desc d;
@@ -136,7 +138,9 @@ static inline Desc _create_gate(u32 handler, u8 type, u8 DPL) {
 
     return d;
 }
-static inline void set_idt_gate(u32 vec, u32 handler, u8 type, u8 DPL) { idt[vec] = _create_gate(handler, type, DPL); }
+static inline void set_idt_gate(u32 vec, u32 handler, u8 type, u8 DPL) {
+    idt[vec] = _create_gate(handler, type, DPL);
+}
 
 #define set_sys_int(vect, type, DPL, handler)        \
     do {                                             \
index 1c6da97bbfeb0d9e60640558239bf43ffe841ad3..969482b76e078a147bb728600bb8399cf6ecbac9 100644 (file)
@@ -27,7 +27,7 @@ void schedule();
 
 extern task_t root_task;
 
-extern void load_cr3(task_t *tsk);
+extern void load_cr3(task_ttsk);
 
 extern list_head_t all_tasks;
 extern list_head_t delay_tasks;
index cd826def333fd56f9d3100ad58f882e4aa4b9e52..d811a3882d17c93cbb3f93ff08c13450570b81fd 100644 (file)
@@ -16,24 +16,22 @@ typedef struct semaphore {
     list_head_t wait_list;
 } semaphore_t;
 
-#define SEMAPHORE_INITIALIZER(name, n) \
-    { .cnt = (n), .wait_list = LIST_HEAD_INIT((name).wait_list) }
+#define SEMAPHORE_INITIALIZER(name, n) {.cnt = (n), .wait_list = LIST_HEAD_INIT((name).wait_list)}
 
-void semaphore_init(semaphore_t *s, unsigned int v);
+void semaphore_init(semaphore_ts, unsigned int v);
 
 // down
 // 如果s->cnt > 0不会立即重新调度进程
 // 如果s->cnt == 0 会重新调度进程
-volatile void down(semaphore_t *s);
+volatile void down(semaphore_ts);
 
 // up
 // 只会唤醒进程,但不会立即重新调度进程
-volatile void up(semaphore_t *s);
+volatile void up(semaphore_ts);
 
 typedef semaphore_t mutex_t;
 
-#define MUTEX_INITIALIZER(name) \
-    { .cnt = (1), .wait_list = LIST_HEAD_INIT((name).wait_list) }
+#define MUTEX_INITIALIZER(name) {.cnt = (1), .wait_list = LIST_HEAD_INIT((name).wait_list)}
 
 #define DECLARE_MUTEX(name) mutex_t name = MUTEX_INITIALIZER(name)
 
@@ -42,6 +40,6 @@ typedef semaphore_t mutex_t;
         (ptr)->cnt = 1;                      \
         INIT_LIST_HEAD(&((ptr)->wait_list)); \
     } while (0)
-void mutex_init(mutex_t *);
-void mutex_lock(mutex_t *);
-void mutex_unlock(mutex_t *);
+void mutex_init(mutex_t*);
+void mutex_lock(mutex_t*);
+void mutex_unlock(mutex_t*);
index 042c2690f2ff37d49950f2431256d565dd035a95..20c6552651f3212acba189a0323a36d8035c79fc 100644 (file)
 #define _STDIO_H
 #include <string.h>
 #include <syscall.h>
-extern int write(int fd, const char *buf, unsigned long size);
-extern int vsprintf(char *buf, const char *fmt, char *args);
-static inline int printf(const char *fmt, ...) {
+extern int write(int fd, const charbuf, unsigned long size);
+extern int vsprintf(char* buf, const char* fmt, char* args);
+static inline int printf(const charfmt, ...) {
     char ptfbuf[512];
-    char *args = (char *)(((char *)&fmt) + 4);
+    char* args = (char*)(((char*)&fmt) + 4);
     vsprintf(ptfbuf, fmt, args);
     return write(0, ptfbuf, strlen(ptfbuf));
 }
index f368d9dd47b37446e09888a74d07b661d645dc91..44224036ed0c7ac16a3973fe7a317dcdf5ab847b 100644 (file)
@@ -13,6 +13,6 @@
 #ifndef _STDLIB_H
 #define _STDLIB_H
 
-extern int atoi(const char *s);
+extern int atoi(const chars);
 
 #endif  //_STDLIB_H
index 15d42c88e928f1c5e2cf5f1918edf90feaa9714d..872a4669dabf05883003b67e9d123e81241d9a20 100644 (file)
 
 #include "types.h"
 
-char *strcpy(char *dest, const char *src);
-char *strncpy(char *dst, const char *src, size_t len);
-size_t strlcpy(char *dst, const char *src, size_t size);
-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);
-char *strstr(const char *a, const char *b);
+char* strcpy(char* dest, const char* src);
+char* strncpy(char* dst, const char* src, size_t len);
+size_t strlcpy(char* dst, const char* src, size_t size);
+size_t strlen(const charstr);
+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);
+char* strstr(const char* a, const char* b);
 
-void *memcpy(void *dest, const void *src, size_t size);
-void memset(void *dest, char ch, size_t size);
-int memcmp(const void *a, const void *b, size_t count);
+void* memcpy(void* dest, const void* src, size_t size);
+void memset(voiddest, char ch, size_t size);
+int memcmp(const void* a, const void* b, size_t count);
 
 #endif  //_STRING_H
index 439b6b302a4e7708b15fa64bd70c34adad32d9ab..d053ae4bedab0d86d0ffe01889eb62299ecc42e0 100644 (file)
@@ -54,9 +54,9 @@
         1;                             \
     })
 
-void *kmalloc(size_t size, gfp_t gfpflags);
-void *kzalloc(size_t size, gfp_t gfpflags);
-void kfree(void *addr);
+voidkmalloc(size_t size, gfp_t gfpflags);
+voidkzalloc(size_t size, gfp_t gfpflags);
+void kfree(voidaddr);
 
 #define panic(msg, ...)                                                                                         \
     do {                                                                                                        \
@@ -102,7 +102,6 @@ extern char etext, edata, end;
 // 之后要将这个地址映射到显存的物理地址
 #define VRAM_VADDR_BASE (PAGE_OFFSET + MAX_SUPT_PHYMM_SIZE)
 
-
 // 算出固定映射区的线性地址
 #define FIXED_MAP_VADDR_BASE (VRAM_VADDR_BASE + VRAM_VADDR_SIZE)
 
@@ -162,13 +161,13 @@ typedef struct system {
 
     u32 page_bitmap;
 
-    u32 *page_dir;
-    u32 *pte_start;
-    u32 *pte_end;
+    u32page_dir;
+    u32pte_start;
+    u32pte_end;
 
-    void *kernel_begin;
-    void *kernel_end;
-    void *bootmem_bitmap_begin;
+    voidkernel_begin;
+    voidkernel_end;
+    voidbootmem_bitmap_begin;
 
     // +-------+-------+-------+-------+
     // | drive | part1 | part2 | part3 |
@@ -182,11 +181,11 @@ typedef struct system {
     u16 x_resolution;
     u16 y_resolution;
 
-    void *rsdt_addr;
+    voidrsdt_addr;
 
     dev_t root_dev;
 #define CMD_LINE_SIZE 128
-    const char *cmdline;
+    const charcmdline;
 
     u32 debug;
 
index 7f9fc2f37e4084c75f84be78dd24af922a4d554a..886346146e537a3048b7fd52e463cc0fe9b71508 100644 (file)
@@ -45,7 +45,7 @@ enum {
 #define NR_TASK_OPEN_CNT 32
 typedef struct task_files {
     // 暂时先不用bitmap,直接线性搜索
-    file_t *fds[NR_TASK_OPEN_CNT];
+    file_tfds[NR_TASK_OPEN_CNT];
 } task_files_t;
 
 typedef union task_union {
@@ -67,7 +67,7 @@ typedef union task_union {
         pid_t ppid;
 
         volatile unsigned int state;
-        const char *reason;
+        const charreason;
 
         long exit_code;
         uint32_t cr3;
@@ -81,7 +81,7 @@ typedef union task_union {
         path_t root;
         path_t pwd;
 
-        vm_area_t *vma_list;
+        vm_area_tvma_list;
 
         list_head_t list;  // 所有进程串成一个链表
 
@@ -100,19 +100,21 @@ typedef union task_union {
     unsigned char stack[TASK_SIZE];
 } task_t;
 
-task_t *alloc_task_t();
+task_talloc_task_t();
 
-static inline task_t *get_current() {
-    task_t *tsk;
+static inline task_tget_current() {
+    task_ttsk;
     asm("andl %%esp, %0;" : "=r"(tsk) : "0"(~(TASK_SIZE - 1)));
     return tsk;
 }
 
 #define current get_current()
 
-static inline pid_t sysc_getpid() { return current->pid; }
+static inline pid_t sysc_getpid() {
+    return current->pid;
+}
 
-task_t *find_task(pid_t pid);
+task_tfind_task(pid_t pid);
 
 #define ROOT_TSK_PID (0)
 
index f526b89338661d5deb415d7c2714dbae94c2c6b0..54a0b966de0ad7795e6660e6f90acf94e3c670b2 100644 (file)
@@ -41,15 +41,15 @@ typedef struct tty {
 
 void init_ttys();
 
-void tty_write(tty_t *tty, const char *buf, size_t size);
-void tty_write_at(tty_t *tty, int xpos, int ypos, const char *buf, size_t size);
-void tty_color_putc(tty_t *tty, char c, unsigned int fg_color, unsigned bg_color);
+void tty_write(tty_t* tty, const char* buf, size_t size);
+void tty_write_at(tty_t* tty, int xpos, int ypos, const char* buf, size_t size);
+void tty_color_putc(tty_ttty, char c, unsigned int fg_color, unsigned bg_color);
 
-void tty_set_cursor(tty_t *tty);
-void tty_switch(tty_t *tty);
+void tty_set_cursor(tty_ttty);
+void tty_switch(tty_ttty);
 
 void tty_switch_to_next();
 
-void tty_clear(tty_t *tty);
+void tty_clear(tty_ttty);
 
-extern tty_t *current_tty;
+extern tty_tcurrent_tty;
index 8b51fdc47eb6beb1230e0550ffec28567a31e096..10b30fef76fbb183fb7a4fbd93fc5834611e5c91 100644 (file)
@@ -50,7 +50,6 @@ typedef long int32_t;
 typedef unsigned long long uint64_t;
 typedef long long int64_t;
 
-
 typedef uint32_t uintptr_t;
 typedef uint32_t paddr_t;
 typedef uint32_t vaddr_t;
@@ -63,7 +62,7 @@ typedef uint32_t umode_t;
 typedef unsigned long pid_t;
 typedef unsigned long mode_t;
 
-#define NULL ((void *)0)
+#define NULL ((void*)0)
 
 typedef enum { false, true } bool;
 
index 2f726d4e2d920a9a148c589dc07027fb0069f4f5..ba922fcfd29877753cccb49b7ced7d35eab4ddd2 100644 (file)
@@ -21,36 +21,34 @@ typedef struct wait_queue_head {
 } wait_queue_head_t;
 
 typedef struct {
-    task_t *task;
+    task_ttask;
     list_head_t entry;
 } wait_queue_entry_t;
 
-#define WAIT_QUEUE_HEAD_INITIALIZER(name) \
-    { .task_list = LIST_HEAD_INIT((name).task_list) }
+#define WAIT_QUEUE_HEAD_INITIALIZER(name) {.task_list = LIST_HEAD_INIT((name).task_list)}
 
 #define DECLARE_WAIT_QUEUE_HEAD(name) wait_queue_head_t name = WAIT_QUEUE_HEAD_INITIALIZER(name)
 
-#define WAIT_QUEUE_ENTRY_INITIALIZER(name, tsk) \
-    { .task = tsk, .entry = LIST_HEAD_INIT((name).entry) }
+#define WAIT_QUEUE_ENTRY_INITIALIZER(name, tsk) {.task = tsk, .entry = LIST_HEAD_INIT((name).entry)}
 
 #define DECLARE_WAIT_QUEUE_ENTRY(name, tsk) wait_queue_entry_t name = WAIT_QUEUE_ENTRY_INITIALIZER(name, tsk)
 
-void init_wait_queue_head(wait_queue_head_t *wqh);
-void add_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wq);
-void del_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wq);
+void init_wait_queue_head(wait_queue_head_twqh);
+void add_wait_queue(wait_queue_head_t* head, wait_queue_entry_t* wq);
+void del_wait_queue(wait_queue_head_t* head, wait_queue_entry_t* wq);
 
 // prepare_to_wait 不会调用schedule
-void prepare_to_wait(wait_queue_head_t *head, wait_queue_entry_t *wq, unsigned int state);
+void prepare_to_wait(wait_queue_head_t* head, wait_queue_entry_t* wq, unsigned int state);
 
-void __end_wait(wait_queue_entry_t *wq);
+void __end_wait(wait_queue_entry_twq);
 
 // 使用这个函数的时候需要注意
 // 设置condition为真的语句和wake_up原子地执行
 // wake_up只唤醒不立即重新调度
-void wake_up(wait_queue_head_t *head);
+void wake_up(wait_queue_head_thead);
 
 // nr == 0 代表唤醒所有
-void __wake_up(wait_queue_head_t *head, int nr);
+void __wake_up(wait_queue_head_thead, int nr);
 
 // 以下wait_event被定义成宏,而不是函数是因为condition
 // condition可能是一个表达式,如果定义成函数,往下传递就直接变成了一个值
index b89913793fb2413c420c119bd5a42e09e3fc4f38..d4ae8e9fc3b3623cc648b603232881ccd73cd0f1 100644 (file)
 #include <cpuid.h>
 #include <system.h>
 
- void lapic_init() {
+void lapic_init() {
     cpuid_regs_t r;
     r = cpuid(1);
-    if(r.edx & (1 << 9)) {
+    if (r.edx & (1 << 9)) {
         printk("local apic supported\n");
-        if(r.ecx & (1 << 21)) {
+        if (r.ecx & (1 << 21)) {
             printk("x2apic supported\n");
         } else {
             panic("x2apic not supported\n");
@@ -28,7 +28,6 @@
     uint64_t apic_base = read_msr(MSR_IA32_APIC_BASE);
     printk("apic base: %016lx\n", apic_base);
 
-
     // apic 必然已经开启
     assert((apic_base & (1 << 11)) != 0);
 
     uint64_t apic_version = read_msr(MSR_IA32_X2APIC_VERSION);
     printk("apic version: %08lx\n", apic_version);
 
-
     paddr_t apic_phys_base_addr = apic_base & 0xFFFFF000;
     vaddr_t apic_virt_base_addr = apic_phys_base_addr;
-    #if 0
+#if 0
     unsigned long ddd = 0xFEC00000;
     while(ddd < 0xFF000000)  {
         page_map((void*)ddd, (void*)ddd, PAGE_P);
         ddd += 0x1000;
     }
-    #endif
+#endif
     page_map((vaddr_t)apic_virt_base_addr, (paddr_t)apic_phys_base_addr, PAGE_P);
 
     {
-        volatile uint32_t *base = (volatile uint32_t *)apic_virt_base_addr;
-        uint32_t id = base[0x20/4]; // APIC ID 偏移
-        uint32_t version = base[0x30/4];
+        volatile uint32_t* base = (volatile uint32_t*)apic_virt_base_addr;
+        uint32_t id = base[0x20 / 4];  // APIC ID 偏移
+        uint32_t version = base[0x30 / 4];
         printk("APIC id %08x version %08x\n", id, version);
     }
-
 }
 
-
 void init_apic() {
 #if 0
     lapic_init();
index 933c95fd64a5ef75d5f7ddc2196a1004ed9f476f..34070ffac81f9fd18e414b2fd95e16f655ef4dc9 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <printk.h>
 
-void assert_fail(char *exp, char *file, unsigned int line, const char *func) {
+void assert_fail(char* exp, char* file, unsigned int line, const char* func) {
     asm("cli");
     printl(MPL_DEBUG, "%s:%d: %s: Assertion \'%s\' failed.\n", file, line, func, exp);
     printk("%s:%d: %s: Assertion \'%s\' failed.\n", file, line, func, exp);
index 37397fb04f0fd2807453b00917c4f3cb3285e9e6..2a4bbb4bbf95263705155792da6e37d712aa77df 100644 (file)
 
 volatile uint64_t jiffies = 0;  // TODO uint64: undefined reference to `__umoddi3'
 
-unsigned int sys_clock() { return jiffies; }
+unsigned int sys_clock() {
+    return jiffies;
+}
 
 void debug_print_all_tasks();
 
 void dump_irq_nr_stack();
-void clk_bh_handler(void *arg);
+void clk_bh_handler(voidarg);
 
 extern volatile bool enable_clock_irq_delay;
 
-void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) {
+void clk_handler(unsigned int irq, pt_regs_t* regs, void* dev_id) {
     // if (jiffies % 100 == 0) {
     // printl(MPL_CLOCK, "clock irq: %d", jiffies);
     printlxy(MPL_IRQ, MPO_CLOCK, "CLK irq: %d", jiffies);
@@ -73,12 +75,11 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) {
 
 // 开中断执行这个函数
 // 后续放到一个内核任务中去做,需要先把禁止内核抢占做了
-const char *task_state(unsigned int state);
-void clk_bh_handler(void *arg) {
-
-    task_t *p = 0;
-    list_head_t *t = 0;
-    list_head_t *pos = 0;
+const char* task_state(unsigned int state);
+void clk_bh_handler(void* arg) {
+    task_t* p = 0;
+    list_head_t* t = 0;
+    list_head_t* pos = 0;
     list_for_each_safe(pos, t, &delay_tasks) {
         p = list_entry(pos, task_t, pend);
         // printk("%s state: %s\n", p->name, task_state(p->state));
@@ -123,10 +124,10 @@ void setup_i8254(uint16_t hz) {
     // 8254的最低频率为18.2Hz(1193180/65536,最大计数值是65536是因为往计数器里写0就从65536开始计数)
     assert(hz >= 19);
 
-    const uint8_t counter_no = 0;  // 第0个计数器
+    const uint8_t counter_no = 0;        // 第0个计数器
     const uint8_t read_write_latch = 3;  // 0 锁存数据供CPU读;1只读写低字节;2只读写高字节;3先读写低字节,后读写高字节
-    const uint8_t mode = 2;  //
-    const uint8_t BCD = 0;   // 0 二进制;1 BCD码
+    const uint8_t mode = 2;              //
+    const uint8_t BCD = 0;               // 0 二进制;1 BCD码
 
     const uint8_t cmd =
         ((counter_no & 0x03) << 6) | ((read_write_latch & 0x03) << 4) | ((mode & 0x07) << 1) | ((BCD & 0x01) << 0);
index ea7d7b4dc7cc73c96de97f5b85b12afffc15e01d..d7f14a02b984b2b1fe3bfd4db248aea558b494b4 100644 (file)
 #include <completion.h>
 #include <sched.h>
 
-void wait_completion(completion_t *x) {
+void wait_completion(completion_tx) {
     wait_event(&x->wait, (x->done != 0));
     x->done--;
 }
 
-void complete(completion_t *x) {
+void complete(completion_tx) {
     uint32_t iflags;
     irq_save(iflags);
     x->done++;
@@ -23,7 +23,7 @@ void complete(completion_t *x) {
     irq_restore(iflags);
 }
 
-void init_completion(completion_t *x) {
+void init_completion(completion_tx) {
     x->done = 0;
     init_wait_queue_head(&x->wait);
 
index 57e1874bf4870c3f619633df8638542e9c2512c1..3fc1a24b5bf5a6c6720d26edebeafd9b9fb099c7 100644 (file)
 #include <string.h>
 #include <cpuid.h>
 
-#define TEST_FEATURE(val, bit, fea)                  \
-    do {                                             \
-        if (ISSET_BIT(val, bit)) printk(" %s", fea); \
+#define TEST_FEATURE(val, bit, fea) \
+    do {                            \
+        if (ISSET_BIT(val, bit))    \
+            printk(" %s", fea);     \
     } while (0);
 
 cpuid_regs_t cpuid(unsigned long op) {
@@ -70,7 +71,7 @@ void detect_cpu() {
     r = cpuid(1);
     pn = ((r.ebx & 0x00FF0000) >> 16);
     printk(" x %d Cores\n", pn);
-    if(((r.ecx >> 21) & 0x01) == 1) {
+    if (((r.ecx >> 21) & 0x01) == 1) {
         printk("x2APIC\n");
     }
     printk("ECX %x\n", r.ecx);
index 0a328c3ac8d4200fada542e442071cc520be8aaf..056bc90ae657ed3c86288eeae10e0e248de8ea93 100644 (file)
@@ -22,7 +22,7 @@
 #include <syscall.h>
 #include <types.h>
 
-extern void *syscall_exit;
+extern voidsyscall_exit;
 
 void put_paging(unsigned long vaddr, unsigned long paddr, unsigned long flags) {
     assert(PAGE_ALIGN(vaddr) == vaddr);
@@ -31,13 +31,13 @@ void put_paging(unsigned long vaddr, unsigned long paddr, unsigned long flags) {
     unsigned int npde = get_npde(vaddr);
     unsigned int npte = get_npte(vaddr);
 
-    pde_t *page_dir = (pde_t *)pa2va(current->cr3);
-    pte_t *page_table = (pte_t *)PAGE_ALIGN(page_dir[npde]);
+    pde_t* page_dir = (pde_t*)pa2va(current->cr3);
+    pte_t* page_table = (pte_t*)PAGE_ALIGN(page_dir[npde]);
 
     if (page_table == 0) {
-        page_table = (pte_t *)page2va(alloc_one_page(0));
+        page_table = (pte_t*)page2va(alloc_one_page(0));
         memset(page_table, 0, PAGE_SIZE);
-        page_table = (pte_t *)va2pa(page_table);
+        page_table = (pte_t*)va2pa(page_table);
         assert(page_table != 0);
     }
 
@@ -46,27 +46,28 @@ void put_paging(unsigned long vaddr, unsigned long paddr, unsigned long flags) {
     page_table[npte] = paddr | flags;
 }
 
-int sysc_exec(const char *path, char *const argv[]) {
+int sysc_exec(const char* path, char* const argv[]) {
     assert(argv == NULL);  // unsupport now
 
     unsigned int ino = namei(path);
-    if (ino == 0) return -ENOENT;
+    if (ino == 0)
+        return -ENOENT;
 
     ext2_inode_t inode;
 
     ext2_read_inode(ino, &inode);
 
-    Elf32_Ehdr *ehdr = (Elf32_Ehdr *)(page2va(alloc_one_page(0)));
+    Elf32_Ehdr* ehdr = (Elf32_Ehdr*)(page2va(alloc_one_page(0)));
     assert(ehdr != 0);
-    ext2_read_data(&inode, 0, PAGE_SIZE, (char *)ehdr);
-    printk("%08x\n", *((unsigned long *)ehdr->e_ident));
+    ext2_read_data(&inode, 0, PAGE_SIZE, (char*)ehdr);
+    printk("%08x\n", *((unsigned long*)ehdr->e_ident));
     assert(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG) - 1) == 0);
     printk("Elf Entry: %08x\n", ehdr->e_entry);
 
     int i, j;
     for (i = 0; i < ehdr->e_phnum; ++i) {
-        Elf32_Phdr *phdr;
-        phdr = (Elf32_Phdr *)(((unsigned long)ehdr) + ehdr->e_phoff + (i * ehdr->e_phentsize));
+        Elf32_Phdrphdr;
+        phdr = (Elf32_Phdr*)(((unsigned long)ehdr) + ehdr->e_phoff + (i * ehdr->e_phentsize));
 
         printk("Type %08x Off %08x Va %08x Pa %08x Fsz %08x Mmsz %08x\n", phdr->p_type, phdr->p_offset, phdr->p_vaddr,
                phdr->p_paddr, phdr->p_filesz, phdr->p_memsz);
@@ -76,20 +77,22 @@ int sysc_exec(const char *path, char *const argv[]) {
         unsigned long mmsz = phdr->p_memsz;
         unsigned long filesz = phdr->p_filesz;
 
-        if (phdr->p_type != PT_LOAD) continue;
+        if (phdr->p_type != PT_LOAD)
+            continue;
 
         assert(mmsz >= filesz);
 
         unsigned int pgcnt = (mmsz + PAGE_SIZE - 1) / PAGE_SIZE;
         unsigned int blkcnt = (filesz + EXT2_BLOCK_SIZE - 1) / EXT2_BLOCK_SIZE;
 
-        void *buf = kmalloc(pgcnt * PAGE_SIZE, PAGE_SIZE);
+        voidbuf = kmalloc(pgcnt * PAGE_SIZE, PAGE_SIZE);
         assert(PAGE_ALIGN(buf) == (unsigned long)buf);
         assert(buf != 0);
 
         printk("vvvbufsz %08x datasz %08x\n", pgcnt * PAGE_SIZE, blkcnt * EXT2_BLOCK_SIZE);
 
-        if (filesz > 0) ext2_read_data(&inode, offset, blkcnt * EXT2_BLOCK_SIZE, buf);
+        if (filesz > 0)
+            ext2_read_data(&inode, offset, blkcnt * EXT2_BLOCK_SIZE, buf);
 
         for (j = 0; j < pgcnt; ++j) {
             put_paging(vaddr + j * PAGE_SIZE, (unsigned long)(va2pa(buf)) + j * PAGE_SIZE, 7);
@@ -100,9 +103,9 @@ int sysc_exec(const char *path, char *const argv[]) {
 
     disable_irq();
 
-    pt_regs_t *regs = ((pt_regs_t *)(TASK_SIZE + (unsigned long)current)) - 1;
+    pt_regs_t* regs = ((pt_regs_t*)(TASK_SIZE + (unsigned long)current)) - 1;
 #if 1
-    memset((void *)regs, 0, sizeof(pt_regs_t));
+    memset((void*)regs, 0, sizeof(pt_regs_t));
     regs->ss = SELECTOR_USER_DS;
     regs->ds = SELECTOR_USER_DS;
     regs->es = SELECTOR_USER_DS;
index d57dc4198b880d36a58a87fedf94e09803535f45..19906dc64b37a9d3c4ba660ad40333cf7a3f23a5 100644 (file)
@@ -19,7 +19,7 @@ int sysc_exit(int status) {
     irq_save(flags);
     current->state = TASK_EXITING;
 
-    task_t *t = current;
+    task_tt = current;
 
     irq_restore(flags);
 
index dc99843812a4b5be974bbc0c0de89e0493544c0f..95621192247afbb3373f84e0b1e5ee37074d04ce 100644 (file)
@@ -18,8 +18,8 @@ extern void ret_from_fork_krnl();
 extern pid_t get_next_pid();
 extern list_head_t all_tasks;
 
-int do_fork(pt_regs_t *regs, unsigned long flags) {
-    task_t *tsk;
+int do_fork(pt_regs_tregs, unsigned long flags) {
+    task_ttsk;
     tsk = alloc_task_t();
 
     printd("fork task %08x flags %08x\n", tsk, flags);
@@ -43,10 +43,10 @@ int do_fork(pt_regs_t *regs, unsigned long flags) {
     assert(tsk->cr3 != 0);
 
     unsigned int i, j;
-    pde_t *pde_src = (pde_t *)pa2va(current->cr3);
-    pde_t *pde_dst = (pde_t *)pa2va(tsk->cr3);
+    pde_t* pde_src = (pde_t*)pa2va(current->cr3);
+    pde_t* pde_dst = (pde_t*)pa2va(tsk->cr3);
 
-    memcpy((void *)pa2va(tsk->cr3), (void *)pa2va(current->cr3), PAGE_SIZE);
+    memcpy((void*)pa2va(tsk->cr3), (void*)pa2va(current->cr3), PAGE_SIZE);
 
     for (i = 0; i < PAGE_PDE_CNT; ++i) {
         unsigned long spde = (unsigned long)pde_src[i];
@@ -69,7 +69,7 @@ int do_fork(pt_regs_t *regs, unsigned long flags) {
         if (PAGE_ALIGN(spde) != 0) {
             dpde = page2va(alloc_one_page(0));
             assert(dpde != 0);
-            memset((void *)dpde, 0, PAGE_SIZE);
+            memset((void*)dpde, 0, PAGE_SIZE);
             dpde = PAGE_FLAGS(spde) | (unsigned long)va2pa(dpde);
         } else {
             pde_dst[i] = 0;
@@ -77,8 +77,8 @@ int do_fork(pt_regs_t *regs, unsigned long flags) {
         }
         pde_dst[i] = dpde;
 
-        pte_t *pte_src = pa2va(PAGE_ALIGN(spde));
-        pte_t *pte_dst = pa2va(PAGE_ALIGN(dpde));
+        pte_tpte_src = pa2va(PAGE_ALIGN(spde));
+        pte_tpte_dst = pa2va(PAGE_ALIGN(dpde));
         for (j = 0; j < PAGE_PTE_CNT; ++j) {
             pte_src[j] &= ~PAGE_WR;
             pte_dst[j] = pte_src[j];
@@ -87,13 +87,13 @@ int do_fork(pt_regs_t *regs, unsigned long flags) {
                 continue;
             }
             printk("----pde[%u] pte_src[%u] %08x\n", i, j, pte_src[j]);
-            page_t *page = pa2page(pte_src[j]);
+            page_tpage = pa2page(pte_src[j]);
             page->count++;
         }
 #endif
     }
 
-    pt_regs_t *child_regs = ((pt_regs_t *)(TASK_SIZE + (unsigned long)tsk)) - 1;
+    pt_regs_t* child_regs = ((pt_regs_t*)(TASK_SIZE + (unsigned long)tsk)) - 1;
 
     // printd("child regs: %x %x\n", child_regs, regs);
     memcpy(child_regs, regs, sizeof(*regs));
@@ -101,10 +101,10 @@ int do_fork(pt_regs_t *regs, unsigned long flags) {
     // child_regs->eflags |= 0x200;
 
     if (flags & FORK_KRNL) {
-        strcpy(tsk->name, (char *)(child_regs->eax));
+        strcpy(tsk->name, (char*)(child_regs->eax));
         child_regs->eax = 0;
     } else {
-        child_regs->eip = *((unsigned long *) && fork_child);
+        child_regs->eip = *((unsigned long*) && fork_child);
     }
     printk("%s fork %s EFLAGS %08x\n", current->name, tsk->name, regs->eflags);
 
@@ -135,4 +135,6 @@ fork_child:
     return 0;
 }
 
-int sysc_fork(pt_regs_t regs) { return do_fork(&regs, 0); }
+int sysc_fork(pt_regs_t regs) {
+    return do_fork(&regs, 0);
+}
index 7bd29ebe93515f1feb93f1bce06b466af2a357b9..f9ef9f1bef62218b3faf066d17be4c458f648a67 100644 (file)
@@ -137,9 +137,10 @@ irq_chip_t i8259_chip = {
     .ack = ack_i8259_irq,
 };
 
-void do_i8259_IRQ(pt_regs_t *regs, unsigned int irq) {}
+void do_i8259_IRQ(pt_regs_t* regs, unsigned int irq) {
+}
 
-__attribute__((regparm(1))) void boot_irq_handler(pt_regs_t *regs) {
+__attribute__((regparm(1))) void boot_irq_handler(pt_regs_tregs) {
     unsigned int irq = regs->irq;
     if (irq != 0 && irq != 1) {
         panic("invalid irq %d\n", irq);
index b92da0ac5625a3d957996f181698fa82bbf4161f..76b3b680665c983d412937046b9719855275b016 100644 (file)
     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 (1)                                                                                        \
+            ;                                                                                            \
     } while (0);
 
-void doDivideError(pt_regs_t regs) { DIE_MSG(); }
-void doDebug(pt_regs_t regs) { DIE_MSG(); }
-void doNMI(pt_regs_t regs) { DIE_MSG(); }
-void doBreakPoint(pt_regs_t regs) { DIE_MSG(); }
-void doOverFlow(pt_regs_t regs) { DIE_MSG(); }
-void doBoundsCheck(pt_regs_t regs) { DIE_MSG(); }
-void doInvalidOpcode(pt_regs_t regs) { DIE_MSG(); }
-void doDeviceNotAvailable(pt_regs_t regs) { DIE_MSG(); }
-void doDoubleFault(pt_regs_t regs) { DIE_MSG(); }
-void doCoprocSegOverRun(pt_regs_t regs) { DIE_MSG(); }
-void doInvalidTss(pt_regs_t regs) { DIE_MSG(); }
-void doSegNotPresent(pt_regs_t regs) { DIE_MSG(); }
-void doStackFault(pt_regs_t regs) { DIE_MSG(); }
-void doGeneralProtection(pt_regs_t regs) { DIE_MSG(); }
+void doDivideError(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doDebug(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doNMI(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doBreakPoint(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doOverFlow(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doBoundsCheck(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doInvalidOpcode(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doDeviceNotAvailable(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doDoubleFault(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doCoprocSegOverRun(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doInvalidTss(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doSegNotPresent(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doStackFault(pt_regs_t regs) {
+    DIE_MSG();
+}
+void doGeneralProtection(pt_regs_t regs) {
+    DIE_MSG();
+}
 
-void do_no_page(void *);
-void do_wp_page(void *);
+void do_no_page(void*);
+void do_wp_page(void*);
 void do_page_fault(pt_regs_t regs) {
 #if 0
 US RW  P - Description
@@ -61,7 +90,7 @@ US RW  P - Description
     bit 2: 0 supervisor mode; 1 user mode
 #endif
     // DIE_MSG();
-    void *addr;
+    voidaddr;
     u32 errcode = regs.errcode;
 
     asm("movl %%cr2,%%eax" : "=a"(addr));
@@ -78,4 +107,6 @@ US RW  P - Description
     }
 }
 
-void doCoprocError(pt_regs_t regs) { DIE_MSG(); }
+void doCoprocError(pt_regs_t regs) {
+    DIE_MSG();
+}
index 283068a0de90fc3135121fab83d5553ecacb981f..2eea8a5286ca3d40564d3f48f607094026ca961b 100644 (file)
@@ -22,8 +22,8 @@
 #include <task.h>
 
 irq_desc_t irq_desc[NR_IRQS];
-irq_bh_action_t *irq_bh_actions = NULL;
-irq_bh_action_t *irq_bh_actions_end = NULL;
+irq_bh_action_tirq_bh_actions = NULL;
+irq_bh_action_tirq_bh_actions_end = NULL;
 
 void irq_bh_handler();
 void schedule();
@@ -32,15 +32,15 @@ volatile int reenter_count = 0;
 
 volatile uint32_t clk_irq_cnt = 0;
 
-__attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) {
+__attribute__((regparm(1))) void irq_handler(pt_regs_tregs) {
     assert(current->magic == TASK_MAGIC);
     unsigned int irq = regs->irq;
     if (irq >= NR_IRQS) {
         panic("invalid irq %d\n", irq);
     }
 
-    irq_desc_t *p = irq_desc + irq;
-    irq_action_t *action = p->action;
+    irq_desc_tp = irq_desc + irq;
+    irq_action_taction = p->action;
 
     // 在qemu启动后如果gdb有加断点,就很会一直触发中断重入
     reenter++;
@@ -133,7 +133,7 @@ void irq_bh_handler() {
 #endif
     {
         while (true) {
-            irq_bh_action_t *action = NULL;
+            irq_bh_action_taction = NULL;
 
 #if 1
             disable_irq();
@@ -166,7 +166,7 @@ void irq_bh_handler() {
 
             while (action != NULL) {
                 action->handler(action->arg);
-                irq_bh_action_t *p = action;
+                irq_bh_action_tp = action;
                 action = action->next;
                 kfree(p);
             }
@@ -201,9 +201,8 @@ void irq_bh_handler() {
     // 而是会延迟到这次中断返回后下一次的中断的下半部分处理逻辑
 }
 
-int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname,
-                void *dev_id) {
-    irq_action_t *p;
+int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t*, void*), const char* devname, void* dev_id) {
+    irq_action_t* p;
 
     if (irq >= NR_IRQS) {
         return -EINVAL;
@@ -221,7 +220,7 @@ int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, voi
         p = p->next;
     }
 
-    p = (irq_action_t *)kmalloc(sizeof(irq_action_t), 0);
+    p = (irq_action_t*)kmalloc(sizeof(irq_action_t), 0);
     if (p == NULL) {
         return -ENOMEM;
     }
@@ -239,15 +238,15 @@ int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, voi
     return 0;
 }
 
-void add_irq_bh_handler(void (*handler)(), void *arg) {
+void add_irq_bh_handler(void (*handler)(), voidarg) {
     // 只能在中断处理函数中调用
     assert(irq_disabled());
     assert(reenter >= 0);
 
     // 本函数不用考虑临界问题
 
-    irq_bh_action_t *p;
-    p = (irq_bh_action_t *)kmalloc(sizeof(irq_bh_action_t), 0);
+    irq_bh_action_tp;
+    p = (irq_bh_action_t*)kmalloc(sizeof(irq_bh_action_t), 0);
     assert(p != NULL);
 
     p->handler = handler;
@@ -265,9 +264,13 @@ void add_irq_bh_handler(void (*handler)(), void *arg) {
     p->next = NULL;
 }
 
-int open_irq(unsigned int irq) { return irq_desc[irq].chip->enable(irq); }
+int open_irq(unsigned int irq) {
+    return irq_desc[irq].chip->enable(irq);
+}
 
-int close_irq(unsigned int irq) { return irq_desc[irq].chip->disable(irq); }
+int close_irq(unsigned int irq) {
+    return irq_desc[irq].chip->disable(irq);
+}
 
 bool irq_enabled() {
     uint32_t flags;
@@ -280,10 +283,16 @@ bool irq_enabled() {
     return false;
 }
 
-bool irq_disabled() { return !irq_enabled(); }
+bool irq_disabled() {
+    return !irq_enabled();
+}
 
-int enable_no_irq_chip(unsigned int irq) { return 0; }
-int disable_no_irq_chip(unsigned int irq) { return 0; }
+int enable_no_irq_chip(unsigned int irq) {
+    return 0;
+}
+int disable_no_irq_chip(unsigned int irq) {
+    return 0;
+}
 
 irq_chip_t no_irq_chip = {.name = "none", .enable = enable_no_irq_chip, .disable = disable_no_irq_chip};
 irq_desc_t no_irq_desc = {.chip = &no_irq_chip, .action = NULL, .status = 0, .depth = 0};
@@ -293,5 +302,9 @@ irq_desc_t no_irq_desc = {.chip = &no_irq_chip, .action = NULL, .status = 0, .de
 // __critical_zone_eflags的值会被统一设置为最里层时的eflags
 // 意味着如果IF置位了的话,必定会丢失这个信息
 static volatile uint32_t __critical_zone_eflags;
-void enter_critical_zone() { irq_save(__critical_zone_eflags); }
-void exit_critical_zone() { irq_restore(__critical_zone_eflags); }
+void enter_critical_zone() {
+    irq_save(__critical_zone_eflags);
+}
+void exit_critical_zone() {
+    irq_restore(__critical_zone_eflags);
+}
index b5a5ef8783cde3478d52bcbb5ee6bffd2e5d0fbc..3ea2c80dccdf2542ff6745bcf1df63693f8bee2e 100644 (file)
 #include <irq.h>
 #include <system.h>
 #include <tty.h>
-int vsprintf(char *buf, const char *fmt, char *args);
+int vsprintf(char* buf, const char* fmt, char* args);
 
-void serial_write(const char *buf, size_t size);
+void serial_write(const charbuf, size_t size);
 
-
-extern tty_t *const default_tty;
-int printk(const char *fmtstr, ...) {
+extern tty_t* const default_tty;
+int printk(const char* fmtstr, ...) {
     static char pkbuf[1024];
 
     ENTER_CRITICAL_ZONE(EFLAGS);
 
-    char *args = (char *)(((char *)&fmtstr) + 4);
+    char* args = (char*)(((char*)&fmtstr) + 4);
     int size = vsprintf(pkbuf, fmtstr, args);
     tty_write(default_tty, pkbuf, (size_t)size);
     serial_write(pkbuf, (size_t)size);
@@ -38,12 +37,12 @@ int printk(const char *fmtstr, ...) {
     return 0;
 }
 
-extern tty_t *const debug_tty;
-int printd(const char *fmtstr, ...) {
+extern tty_tconst debug_tty;
+int printd(const charfmtstr, ...) {
     static char pdbuf[1024];
     ENTER_CRITICAL_ZONE(EFLAGS);
 
-    char *args = (char *)(((char *)&fmtstr) + 4);
+    char* args = (char*)(((char*)&fmtstr) + 4);
     int size = vsprintf(pdbuf, fmtstr, args);
     tty_write(debug_tty, pdbuf, (size_t)size);
     serial_write(pdbuf, (size_t)size);
@@ -52,11 +51,10 @@ int printd(const char *fmtstr, ...) {
     return 0;
 }
 
-
-extern tty_t *const monitor_tty;
-int printlo(unsigned int xpos, unsigned int ypos, const char *fmtstr, ...) {
+extern tty_t* const monitor_tty;
+int printlo(unsigned int xpos, unsigned int ypos, const char* fmtstr, ...) {
     static char plobuf[1024];
-    char *args = (char *)(((char *)&fmtstr) + 4);
+    char* args = (char*)(((char*)&fmtstr) + 4);
     ENTER_CRITICAL_ZONE(EFLAGS);
     int size = vsprintf(plobuf, fmtstr, args);
 
index 48dd2c0f1be5bf1ce13d28e9039ae4c938870f03..f7e7fff13928ccc503e3746941c6932d1bc6d556 100644 (file)
@@ -40,7 +40,9 @@ pid_t get_next_pid() {
     return pid;
 }
 
-void load_cr3(task_t *tsk) { set_cr3(tsk->cr3); }
+void load_cr3(task_t* tsk) {
+    set_cr3(tsk->cr3);
+}
 
 extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
 
@@ -91,7 +93,7 @@ void init_root_task() {
     printk("init_root_task tss.esp0 %08x\n", tss.esp0);
 }
 
-kmem_cache_t *task_t_cache;
+kmem_cache_ttask_t_cache;
 
 void setup_tasks() {
     INIT_LIST_HEAD(&all_tasks);
@@ -105,9 +107,9 @@ void setup_tasks() {
     }
 }
 
-task_t *alloc_task_t() {
-    task_t *task;
-    task = (task_t *)kmem_cache_alloc(task_t_cache, 0);
+task_talloc_task_t() {
+    task_ttask;
+    task = (task_t*)kmem_cache_alloc(task_t_cache, 0);
     return task;
 }
 
@@ -121,7 +123,7 @@ void switch_to() {
 #endif
 }
 
-void context_switch(task_t *prev, task_t *next) {
+void context_switch(task_t* prev, task_t* next) {
     unsigned long eax, ebx, ecx, edx, esi, edi;
     asm volatile(
         "pushfl;"
@@ -140,8 +142,8 @@ void context_switch(task_t *prev, task_t *next) {
         : "memory");
 }
 
-task_t *find_task(pid_t pid) {
-    task_t *p = 0;
+task_tfind_task(pid_t pid) {
+    task_tp = 0;
     list_head_t *pos = 0, *tmp = 0;
 
     unsigned long iflags;
@@ -157,7 +159,7 @@ task_t *find_task(pid_t pid) {
     return p;
 }
 
-const char *task_state(unsigned int state) {
+const chartask_state(unsigned int state) {
     static const char s[][8] = {
         " ERROR", "\x10\x07RUN\x07", " READY", " WAIT ", " INIT ", " EXIT ",
     };
@@ -170,9 +172,9 @@ const char *task_state(unsigned int state) {
 }
 
 void debug_print_all_tasks() {
-    task_t *p = 0;
+    task_tp = 0;
     list_head_t *pos = 0, *t = 0;
-    printl(MPL_TASK_TITLE, "         NAME      STATE TK/PI REASON     TICKS  SCHED     KEEP      TURN");
+    printl(MPL_TASK_TITLE, "         NAME      STATE TK/PI REASON     SCHED     KEEP      TURN");
     list_for_each_safe(pos, t, &all_tasks) {
         p = list_entry(pos, task_t, list);
         printl(MPL_TASK_0 + p->pid, "%08x %-6s:%u %s %02u/%02u %-10s %-9u %-9u %-9u", p, p->name, p->pid,
@@ -181,9 +183,9 @@ void debug_print_all_tasks() {
 }
 
 void schedule() {
-    task_t *root = &root_task;
-    task_t *sel = 0;
-    task_t *p = 0;
+    task_troot = &root_task;
+    task_tsel = 0;
+    task_tp = 0;
     list_head_t *pos = 0, *t = 0;
 
     assert(current->ticks >= 0);
@@ -245,8 +247,8 @@ void schedule() {
 #endif
     }
 
-    task_t *prev = current;
-    task_t *next = sel != 0 ? sel : root;
+    task_tprev = current;
+    task_tnext = sel != 0 ? sel : root;
 
     prev->need_resched = 0;
 
@@ -269,6 +271,6 @@ void schedule() {
 }
 
 void debug_sched() {
-    task_t *p = list_entry(current->list.next, task_t, list);
+    task_tp = list_entry(current->list.next, task_t, list);
     p->state = (p->state == TASK_READY) ? TASK_WAIT : TASK_READY;
 }
index 7207a3ec743a74766c021cc4831eb2ed598d517b..0e5867f204425dd4a1cde540c2ed3e56e1a2ceeb 100644 (file)
@@ -13,7 +13,7 @@
 
 typedef struct semaphore_waiter {
     list_head_t list;
-    task_t *task;
+    task_ttask;
 
     // 在Linux内核中这个结构体有一个up字段,这个字段的作用是防止进程被错误地唤醒
     // 例如
@@ -23,12 +23,12 @@ typedef struct semaphore_waiter {
 
 } semaphore_waiter_t;
 
-void semaphore_init(semaphore_t *s, unsigned int v) {
+void semaphore_init(semaphore_ts, unsigned int v) {
     s->cnt = v;
     INIT_LIST_HEAD(&(s->wait_list));
 }
 
-volatile void down(semaphore_t *s) {
+volatile void down(semaphore_ts) {
     unsigned long iflags;
     irq_save(iflags);
 
@@ -36,7 +36,7 @@ volatile void down(semaphore_t *s) {
         s->cnt--;
         irq_restore(iflags);
     } else {
-        task_t *task = current;
+        task_ttask = current;
         semaphore_waiter_t waiter;
         waiter.task = task;
         INIT_LIST_HEAD(&waiter.list);
@@ -51,7 +51,7 @@ volatile void down(semaphore_t *s) {
     }
 }
 
-volatile void up(semaphore_t *s) {
+volatile void up(semaphore_ts) {
     unsigned long iflags;
     irq_save(iflags);
 
@@ -59,10 +59,10 @@ volatile void up(semaphore_t *s) {
         s->cnt++;
         irq_restore(iflags);
     } else {
-        semaphore_waiter_t *waiter = list_first_entry(&s->wait_list, semaphore_waiter_t, list);
+        semaphore_waiter_twaiter = list_first_entry(&s->wait_list, semaphore_waiter_t, list);
         assert(waiter != 0);
         list_del(&waiter->list);
-        task_t *task = waiter->task;
+        task_ttask = waiter->task;
 
         task->state = TASK_READY;
         task->reason = "up";
@@ -78,6 +78,12 @@ volatile void up(semaphore_t *s) {
     }
 }
 
-void mutex_init(mutex_t *s) { INIT_MUTEX(s); }
-void mutex_lock(semaphore_t *s) { down(s); }
-void mutex_unlock(semaphore_t *s) { up(s); }
+void mutex_init(mutex_t* s) {
+    INIT_MUTEX(s);
+}
+void mutex_lock(semaphore_t* s) {
+    down(s);
+}
+void mutex_unlock(semaphore_t* s) {
+    up(s);
+}
index f224520ca13706f9a2c797c9b5448ceee724a296..056d47a6c11b019a4c9b420d80dc2402ddcbf362 100644 (file)
@@ -39,16 +39,14 @@ extern void reboot();
 extern void cnsl_init();
 
 #define VERSION "0.3.1"
-const char *version = "KERNEL v" VERSION " @" BUILDER
-                      " ["__DATE__
-                      " " __TIME__
+const char* version = "KERNEL v" VERSION " @" BUILDER " [" __DATE__ " " __TIME__
                       "]"
                       "\n\n";
 
 void print_kernel_version() {
     //
-    extern tty_t *const default_tty;
-    tty_t *const tty = default_tty;
+    extern tty_tconst default_tty;
+    tty_tconst tty = default_tty;
 
     int len = strlen(version);
 
@@ -65,7 +63,7 @@ void print_kernel_version() {
         bg_color = TTY_CYAN;
 
         //
-        char *dst = (char *)tty->base_addr;
+        char* dst = (char*)tty->base_addr;
 
         //
         dst[i * 2 + 0] = c;
@@ -76,7 +74,7 @@ void print_kernel_version() {
     printk(version);
 }
 
-void parse_rsdt(void *addr);
+void parse_rsdt(voidaddr);
 
 void setup_kernel() {
     printk("sysenter esp mode: %s\n",
@@ -91,12 +89,12 @@ void setup_kernel() {
 
     init_buffer();
 
-    #if 0
+#if 0
     parse_rsdt(system.rsdt_addr);
 
     void init_apic();
     init_apic();
-    #endif
+#endif
 
     void init_mount();
     init_mount();
@@ -110,7 +108,7 @@ void setup_kernel() {
     cnsl_init();
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
 
-    const char *title = "KERNEL MONITOR";
+    const chartitle = "KERNEL MONITOR";
     printlxy(MPL_TITLE, (80 - strlen(title)) / 2, title);
 
     setup_fs();
@@ -130,7 +128,7 @@ void setup_kernel() {
     print_kernel_version();
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
 
-    extern tty_t *const monitor_tty;
+    extern tty_tconst monitor_tty;
     // tty_switch(monitor_tty);
 
     boot_delay(DEFAULT_BOOT_DELAY_TICKS);
index b28c2135e5bc612af1623d9c63f5004f92413409..7610022d6fb1f56284803e7d732c24cfb7dd222f 100644 (file)
@@ -63,8 +63,10 @@ int sysc_wait(int ticks) {
     return 0;
 }
 
-int sysc_test() {}
-int sysc_pause() {}
+int sysc_test() {
+}
+int sysc_pause() {
+}
 
 int sysc_debug(unsigned int v) {
     static unsigned int cnt = 0;
@@ -79,7 +81,8 @@ int sysc_rand() {
 
 void init_sysc_handler_table() {
     int i;
-    for (i = 0; i < SYSC_NUM; i++) sysc_handler_table[i] = (unsigned long)sysc_none;
+    for (i = 0; i < SYSC_NUM; i++)
+        sysc_handler_table[i] = (unsigned long)sysc_none;
 
 #define _sysc_(nr, sym)                              \
     do {                                             \
index 8c354143d480a0bf9efebbd409aecd1b525c113d..f8382e7b4e640cbee09b23954313a176fbbdba68 100644 (file)
@@ -44,9 +44,9 @@ void setup_gdt() {
     asm volatile("sgdt gdtr");
 
     // 复制旧的GDT
-    memcpy(gdt, (void *)pa2va(*((uint32_t *)(gdtr + 2))), *((uint16_t *)(gdtr + 0)));
-    *((unsigned short *)gdtr) = NGDT * sizeof(Desc);
-    *((unsigned long *)(gdtr + 2)) = (unsigned long)gdt;
+    memcpy(gdt, (void*)pa2va(*((uint32_t*)(gdtr + 2))), *((uint16_t*)(gdtr + 0)));
+    *((unsigned short*)gdtr) = NGDT * sizeof(Desc);
+    *((unsigned long*)(gdtr + 2)) = (unsigned long)gdt;
 
     asm volatile("lgdt gdtr");
 
@@ -62,8 +62,8 @@ void setup_gdt() {
 // 通过中断门进入中断服务程序CPU会自动将中断关闭,也就是将EFLAGS的IF位清0
 // 通过陷阱门进入服务程序时则维持IF标志位不变
 void setup_idt() {
-    *((unsigned short *)idtr) = NIDT * sizeof(Gate);
-    *((unsigned long *)(idtr + 2)) = (unsigned long)idt;
+    *((unsigned short*)idtr) = NIDT * sizeof(Gate);
+    *((unsigned long*)(idtr + 2)) = (unsigned long)idt;
     asm volatile("lidt idtr");
 }
 
@@ -96,7 +96,9 @@ void setup_gates() {
 
 void ide_irq();
 
-void default_irq_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { printk("default irq handler %d \n", irq); }
+void default_irq_handler(unsigned int irq, pt_regs_t* regs, void* dev_id) {
+    printk("default irq handler %d \n", irq);
+}
 
 void init_i8259();
 
@@ -126,8 +128,8 @@ void setup_irqs() {
         }
     }
 
-    void kbd_handler(unsigned int irq, pt_regs_t *regs, void *dev_id);
-    void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id);
+    void kbd_handler(unsigned int irq, pt_regs_t* regs, void* dev_id);
+    void clk_handler(unsigned int irq, pt_regs_t* regs, void* dev_id);
     void clk_bh_handler();
 
     request_irq(0x00, clk_handler, "Intel 8254", "Clock Chip");
@@ -188,8 +190,8 @@ void set_tss_gate(u32 vec, u32 addr, u32 limit) {
 }
 
 void set_tss() {
-    TSS_t *p = &tss;
-    memset((void *)p, sizeof(TSS_t), 0);
+    TSS_tp = &tss;
+    memset((void*)p, sizeof(TSS_t), 0);
     p->esp0 = 0;  // delay to init root_task
     p->ss0 = SELECTOR_KRNL_DS;
     p->ss = SELECTOR_KRNL_DS;
index bc3b5df76e5ee44a919c44779a6f6e3ccc0e9b1e..094acd729447e2e31f3ece32ef346c9a6977b029 100644 (file)
 #include <sched.h>
 
 void ata_read_identify(int drv, int disable_intr);
-void ata_pio_read_data(int drvid, int sect_cnt, void *dst);
-void ata_dma_read_ext(int drv, uint64_t pos, uint16_t count, void *dest);
+void ata_pio_read_data(int drvid, int sect_cnt, voiddst);
+void ata_dma_read_ext(int drv, uint64_t pos, uint16_t count, voiddest);
 
-int send_disk_request(disk_request_t *r) {
+int send_disk_request(disk_request_tr) {
     if (NULL == r) {
         panic("null disk request");
     }
 
-    ide_drive_t *drv = ide_get_drive(r->dev);
+    ide_drive_tdrv = ide_get_drive(r->dev);
 
     assert(drv->present == 1);
 
@@ -63,11 +63,11 @@ int send_disk_request(disk_request_t *r) {
     return r->ret;
 }
 
-void disk_task_entry(void *arg) {
+void disk_task_entry(voidarg) {
     int r_cnt = 0;
     while (1) {
         int channel = (int)arg;
-        ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
+        ide_pci_controller_tide_ctrl = ide_pci_controller + channel;
 
 #if 1
         // 为了在DEBUG时看到RUN
@@ -82,7 +82,7 @@ void disk_task_entry(void *arg) {
         // printk("hard disk channel %d\n", channel);
 
         mutex_lock(&ide_ctrl->request_mutex);
-        disk_request_t *r;
+        disk_request_tr;
         r = list_first_entry(&ide_ctrl->request_queue.list, disk_request_t, list);
         if (NULL == r) {
             panic("no disk request");
@@ -92,7 +92,7 @@ void disk_task_entry(void *arg) {
         atomic_inc(&ide_ctrl->consumed_cnt);
         mutex_unlock(&ide_ctrl->request_mutex);
 
-        ide_drive_t *drv = ide_get_drive(r->dev);
+        ide_drive_tdrv = ide_get_drive(r->dev);
         int drvid = drv->drvid;
         if (drv->present == 0) {
             panic("disk not present");
@@ -126,7 +126,7 @@ void disk_task_entry(void *arg) {
             assert(r->buf != NULL || r->bb->data != NULL);
             // printk("DISK READ drvid %u pos %u count %u bb %x\n", drvid, (uint32_t)pos, r->count, r->bb);
             if (pio_mode) {
-                int ata_pio_read_ext(int drvid, uint64_t pos, uint16_t count, int timeout, void *dest);
+                int ata_pio_read_ext(int drvid, uint64_t pos, uint16_t count, int timeout, voiddest);
                 if (r->bb != 0) {
                     ata_pio_read_ext(drvid, pos, r->count, 100, r->bb->data);
                 } else {
index 2d987cba7c65e5bc34323df6fa42b110835dbb44..7b0eae75fbd14167141f9e3430d395943dfa9ba8 100644 (file)
@@ -12,7 +12,7 @@
 #include <system.h>
 #include <types.h>
 int sysc_wait(int ticks);
-void kernel_task(char *name, void *entry, void *arg);
+void kernel_task(char* name, void* entry, void* arg);
 
 // 测试用的代码
 // 这里存的是下标对应的每个扇区的最后2个字节
@@ -39,7 +39,7 @@ uint64_t get_next_deubug_sect_nr() {
     return debug_sect_nr;
 }
 
-void verify_hd_data(uint64_t sect_nr, uint16_t *buf, const char *name) {
+void verify_hd_data(uint64_t sect_nr, uint16_t* buf, const char* name) {
     uint16_t vfp = hd_sect_data_fingerprint[sect_nr];
 
     uint16_t fp = buf[255];
@@ -139,13 +139,13 @@ void init_task_entry() {
 #endif
 
 #if 1
-    extern __attribute__((regparm(0))) long sysc_mkdir(const char *path, int mode);
+    extern __attribute__((regparm(0))) long sysc_mkdir(const charpath, int mode);
     sysc_mkdir("/root", 0777);
     sysc_mkdir("/root/sbin/", 0777);
 
     {
         namei_t ni;
-        const char *path = "/root/sbin/init.elf";
+        const charpath = "/root/sbin/init.elf";
         // path_init(path, PATH_LOOKUP_PARENT, &ni);
         // path_walk(path, &ni);
 
@@ -175,7 +175,7 @@ void init_task_entry() {
     init_rootfs();
 
 #if 1
-    kernel_task("ide/0", disk_task_entry, (void *)0);
+    kernel_task("ide/0", disk_task_entry, (void*)0);
 
     void ide_read_partions();
     ide_read_partions();
@@ -193,7 +193,7 @@ void init_task_entry() {
 #endif
 
 #if 1
-    kernel_task("ide/1", disk_task_entry, (void *)1);
+    kernel_task("ide/1", disk_task_entry, (void*)1);
     kernel_task("user", user_task_entry, NULL);
     kernel_task("tskA", taskA_entry, NULL);
     kernel_task("tskB", taskB_entry, NULL);
@@ -256,13 +256,13 @@ void init_task_entry() {
 
 void init_rootfs() {
 #if 1
-    void *mod_start = pa2va(boot_params.boot_module_begin);
+    voidmod_start = pa2va(boot_params.boot_module_begin);
 
-    const uint32_t mod_magic = *(uint32_t *)(mod_start + 0);
-    const uint32_t mod_head_size = *(uint32_t *)(mod_start + 4);
-    const uint32_t mod_timestamp = *(uint32_t *)(mod_start + 8);
-    const uint32_t mod_file_entry_cnt = *(uint32_t *)(mod_start + 12);
-    const char *mod_name = (const char *)mod_start + 16;
+    const uint32_t mod_magic = *(uint32_t*)(mod_start + 0);
+    const uint32_t mod_head_size = *(uint32_t*)(mod_start + 4);
+    const uint32_t mod_timestamp = *(uint32_t*)(mod_start + 8);
+    const uint32_t mod_file_entry_cnt = *(uint32_t*)(mod_start + 12);
+    const char* mod_name = (const char*)mod_start + 16;
 
     printk("%x %x\n", boot_params.boot_module_begin, boot_params.boot_module_end);
     printk("module magic %08x header size %u timestamp %u file entry cnt %u name %s \n", mod_magic, mod_head_size,
@@ -270,22 +270,22 @@ void init_rootfs() {
 
     int file_entry_offset = mod_head_size;
     for (int i = 0; i < mod_file_entry_cnt; i++) {
-        void *fe = mod_start + file_entry_offset;
+        voidfe = mod_start + file_entry_offset;
 
-        const uint32_t fe_size = *(uint32_t *)(fe + 0);
-        const uint32_t fe_type = *(uint32_t *)(fe + 4);
-        const uint32_t fe_filesz = *(uint32_t *)(fe + 8);
-        const uint32_t fe_offset = *(uint32_t *)(fe + 12);
-        const char *fe_name = (const char *)(fe + 16);
+        const uint32_t fe_size = *(uint32_t*)(fe + 0);
+        const uint32_t fe_type = *(uint32_t*)(fe + 4);
+        const uint32_t fe_filesz = *(uint32_t*)(fe + 8);
+        const uint32_t fe_offset = *(uint32_t*)(fe + 12);
+        const char* fe_name = (const char*)(fe + 16);
 
         file_entry_offset += fe_size;
 
-        void *fc = mod_start + fe_offset;
+        voidfc = mod_start + fe_offset;
 
         printk(">[fe:%u:%u] file size %u type %u name %s\n", i, fe_size, fe_filesz, fe_type, fe_name);
 
         for (int k = 0; k < 16; k++) {
-            uint8_t c = *(uint8_t *)(fc + k);
+            uint8_t c = *(uint8_t*)(fc + k);
             printk("%02X ", c);
         }
         printk("\n");
@@ -294,19 +294,19 @@ void init_rootfs() {
             // TODO支持带多层目录的fe_name
 
             namei_t ni;
-            const char *path = fe_name;
+            const charpath = fe_name;
             const int flags = O_CREAT | O_APPEND;
 #define bufsz 5223
             static char buf[bufsz] = {'b', 'u', 'f'};
 #if 1
-            int sysc_open(const char *path, int flags, int mode);
+            int sysc_open(const charpath, int flags, int mode);
             int fd = sysc_open(path, flags, 0700);
             assert(fd >= 0);
 
-            ssize_t sysc_write(int fd, const char *buf, size_t size);
+            ssize_t sysc_write(int fd, const charbuf, size_t size);
             sysc_write(fd, fc, fe_filesz);
 
-            ssize_t sysc_read(int fd, void *buf, size_t count);
+            ssize_t sysc_read(int fd, voidbuf, size_t count);
             sysc_read(fd, buf, bufsz);
 #else
             path_open_namei(path, flags, S_IFREG, &ni);
index cccf543e66a4800d835dda833693dedbaa314545..3faac65b8d09478c1c87ca4b02546271c82bac61 100644 (file)
 #include <system.h>
 #include <types.h>
 
-int do_fork(pt_regs_t *regs, unsigned long flags);
+int do_fork(pt_regs_tregs, unsigned long flags);
 int sysc_wait(int ticks);
 
 #define get_eflags(x) __asm__ __volatile__("pushfl; popl %0;" : "=g"(x)::"memory")
 
-void kernel_task(char *name, void *entry, void *arg) {
+void kernel_task(char* name, void* entry, void* arg) {
     pt_regs_t regs;
 
-    memset((void *)&regs, 0, sizeof(regs));
+    memset((void*)&regs, 0, sizeof(regs));
 
     // 内核任务入口
     regs.edx = (unsigned long)entry;
index 535da79828987c120495b4dcca17fee20fc0bd5e..b43c3242a731a4356844067d0e1a88d57b908737 100644 (file)
 #include <page.h>
 
 void flush_tlb() {
-    asm volatile("movl %%cr3, %%eax;"
-                "movl %%eax, %%cr3;"
-                :
-                :
-                : "eax");
+    asm volatile(
+        "movl %%cr3, %%eax;"
+        "movl %%eax, %%cr3;"
+        :
+        :
+        : "eax");
 }
 
 void user_task_entry() {
@@ -34,24 +35,23 @@ void user_task_entry() {
     // ring3的地址直接是物理地址
     extern uint8_t ring3_page_begin;
 
-    paddr_t ring3_page_addr = (paddr_t)&ring3_page_begin; // 不在内核空间的物理地址
+    paddr_t ring3_page_addr = (paddr_t)&ring3_page_begin;  // 不在内核空间的物理地址
     paddr_t ring3_stack_top = ring3_page_addr + PAGE_SIZE;
 
-    vaddr_t ring3_page_vaddr = 0x08000000; // 指定的ring3的虚拟地址
+    vaddr_t ring3_page_vaddr = 0x08000000;  // 指定的ring3的虚拟地址
     vaddr_t ring3_stack_top_vaddr = PAGE_OFFSET - 0x100000;
 
     page_map(ring3_page_vaddr, ring3_page_addr, PAGE_P | PAGE_US);
 
     // 这里减去PAGE_SIZE是因为栈是向下生长的,所以得把栈顶虚拟地址空间的前一页映射到ring3_page
-    page_map((ring3_stack_top_vaddr-PAGE_SIZE), ring3_page_addr, PAGE_P | PAGE_US | PAGE_WR);
-
+    page_map((ring3_stack_top_vaddr - PAGE_SIZE), ring3_page_addr, PAGE_P | PAGE_US | PAGE_WR);
 
     {
         // 在ring3_page里非代码的地方插入特征值方便调试
         extern uint8_t ring3_text_end;
         uint32_t ring3_text_size = (&ring3_text_end) - (&ring3_page_begin);
-        for(uint32_t i = ring3_text_size; i<PAGE_SIZE; i++) {
-            ((uint8_t *)(pa2va(ring3_page_addr)))[i] = 0xCC;
+        for (uint32_t i = ring3_text_size; i < PAGE_SIZE; i++) {
+            ((uint8_t*)(pa2va(ring3_page_addr)))[i] = 0xCC;
         }
     }
 
index 3cae10226fdb3c9e3b5420f838325f6bb3436486..cff4ab3e714f166418668d612b44c9661e30a474 100644 (file)
@@ -17,7 +17,9 @@
 
 uint32_t days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
-int is_leap_year(uint32_t year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); }
+int is_leap_year(uint32_t year) {
+    return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
+}
 
 void timestamp_to_date(uint32_t timestamp) {
     // 将时间戳转换为东8区时间
index 132d02c3769e30071514e346339bb2579be56fa6..9431a001f375e8b41dfb7c09efc027327f3b0842 100644 (file)
@@ -31,12 +31,12 @@ tty_t ttys[NR_TTYS];
 #define BYTES_PER_LINE (CHARS_PER_LINE * 2)
 #define TAB_SPACE 4
 
-tty_t *const default_tty = ttys + 0;
-tty_t *const monitor_tty = ttys + 1;
-tty_t *const debug_tty = ttys + 2;
+tty_tconst default_tty = ttys + 0;
+tty_tconst monitor_tty = ttys + 1;
+tty_tconst debug_tty = ttys + 2;
 
-void tty_clear(tty_t *tty) {
-    char *dst = (char *)tty->base_addr;
+void tty_clear(tty_ttty) {
+    char* dst = (char*)tty->base_addr;
     for (int src = 0; src < (MAX_Y * BYTES_PER_LINE); src += 2) {
         *dst++ = 0;
         *dst++ = (tty->bg_color << 4) | tty->fg_color;
@@ -49,7 +49,7 @@ void tty_clear(tty_t *tty) {
 // 而如果输出字符颜色与光标所处位置已经设置的颜色不一致的话
 // 就需要将输出的这个字符的后一个位置的颜色设置成与之一致
 // 这样光标颜色才与输出字符一致
-void __tty_set_next_pos_color(tty_t *tty, char color) {
+void __tty_set_next_pos_color(tty_ttty, char color) {
     unsigned int xpos = tty->xpos;
     unsigned int ypos = tty->ypos;
 
@@ -59,13 +59,13 @@ void __tty_set_next_pos_color(tty_t *tty, char color) {
     xpos %= CHARS_PER_LINE;
 
     if (ypos < MAX_Y) {
-        char *dst = (char *)(tty->base_addr + ypos * BYTES_PER_LINE + 2 * xpos);
+        char* dst = (char*)(tty->base_addr + ypos * BYTES_PER_LINE + 2 * xpos);
         dst[0] = 0;
         dst[1] = color;
     }
 }
 
-void init_tty(tty_t *tty, const char *name, unsigned long base) {
+void init_tty(tty_t* tty, const char* name, unsigned long base) {
     assert(0 != tty);
     assert(NR_TTYS >= 1);
     assert(NR_TTYS <= MAX_NR_TTYS);
@@ -81,7 +81,7 @@ void init_tty(tty_t *tty, const char *name, unsigned long base) {
     tty->base_addr = base;
 
     for (int i = 0; i < TTY_VRAM_SIZE; i += 2) {
-        uint8_t *p = (uint8_t *)base;
+        uint8_t* p = (uint8_t*)base;
         p[i + 0] = ' ';
         p[i + 1] = (tty->bg_color << 4) | tty->fg_color;
     }
@@ -91,7 +91,7 @@ void init_ttys() {
     assert(irq_disabled());
 
     for (int i = 0; i < NR_TTYS; i++) {
-        tty_t *tty = ttys + i;
+        tty_ttty = ttys + i;
         char name[sizeof(tty->name)];
         sprintf(name, "tty.%u", i);
         init_tty(tty, name, VADDR + i * TTY_VRAM_SIZE);
@@ -115,13 +115,13 @@ void init_ttys() {
     debug_tty->bg_color = TTY_BLACK;  // TTY_CYAN;
 
     for (int i = 0; i < NR_TTYS; i++) {
-        tty_t *tty = ttys + i;
+        tty_ttty = ttys + i;
         tty_clear(tty);
     }
     current_tty = default_tty;
 }
 
-void tty_do_scroll_up(tty_t *tty) {
+void tty_do_scroll_up(tty_ttty) {
     // 没越过最后一行不需要上卷
     if (tty->ypos < MAX_Y - 1) {
         return;
@@ -135,13 +135,13 @@ void tty_do_scroll_up(tty_t *tty) {
     // 如果是default_tty则保留用来显示内核版本及编译时间信息
     const int keep = tty != default_tty ? 0 : BYTES_PER_LINE;
 
-    char *dst = (char *)tty->base_addr + keep;
+    char* dst = (char*)tty->base_addr + keep;
     for (int src = BYTES_PER_LINE + keep; src < (MAX_Y * BYTES_PER_LINE); src++) {
-        *dst++ = *(char *)(tty->base_addr + src);
+        *dst++ = *(char*)(tty->base_addr + src);
     }
 
     // 清空最后一行
-    dst = (char *)(tty->base_addr + ((MAX_Y - 1) * BYTES_PER_LINE));
+    dst = (char*)(tty->base_addr + ((MAX_Y - 1) * BYTES_PER_LINE));
     for (int i = 0; i < BYTES_PER_LINE; i += 2) {
         *dst++ = 0;
         *dst++ = (tty->bg_color << 4) | tty->fg_color;
@@ -151,7 +151,7 @@ void tty_do_scroll_up(tty_t *tty) {
     tty->ypos = MAX_Y - 1;
 }
 
-void tty_color_putc(tty_t *tty, char c, unsigned int fg_color, unsigned bg_color) {
+void tty_color_putc(tty_ttty, char c, unsigned int fg_color, unsigned bg_color) {
     bool display = false;
     bool move_to_next_pos = true;
     switch (c) {
@@ -193,7 +193,7 @@ void tty_color_putc(tty_t *tty, char c, unsigned int fg_color, unsigned bg_color
     // 显示
     if (display) {
         unsigned int pos = tty->ypos * BYTES_PER_LINE + tty->xpos * 2;
-        char *va = (char *)(tty->base_addr + pos);
+        char* va = (char*)(tty->base_addr + pos);
         va[0] = c;
         va[1] = (bg_color << 4) | fg_color;
 
@@ -209,9 +209,11 @@ void tty_color_putc(tty_t *tty, char c, unsigned int fg_color, unsigned bg_color
     tty_set_cursor(tty);
 }
 
-void tty_putc(tty_t *tty, char c) { tty_color_putc(tty, c, tty->fg_color, tty->bg_color); }
+void tty_putc(tty_t* tty, char c) {
+    tty_color_putc(tty, c, tty->fg_color, tty->bg_color);
+}
 
-void tty_write(tty_t *tty, const char *buf, size_t size) {
+void tty_write(tty_t* tty, const char* buf, size_t size) {
     assert(0 != tty);
     if (0 == buf) {
         return;
@@ -222,7 +224,7 @@ void tty_write(tty_t *tty, const char *buf, size_t size) {
     }
 }
 
-void tty_write_at(tty_t *tty, int xpos, int ypos, const char *buf, size_t size) {
+void tty_write_at(tty_t* tty, int xpos, int ypos, const char* buf, size_t size) {
     assert(0 != tty);
     assert(xpos < BYTES_PER_LINE);
     assert(ypos < MAX_Y);
@@ -238,7 +240,7 @@ void tty_write_at(tty_t *tty, int xpos, int ypos, const char *buf, size_t size)
 #define VGA_CRTC_CURSOR_H 0xE
 #define VGA_CRTC_CURSOR_L 0xF
 
-void tty_set_cursor(tty_t *tty) {
+void tty_set_cursor(tty_ttty) {
     if (tty != current_tty) {
         return;
     }
@@ -253,7 +255,7 @@ void tty_set_cursor(tty_t *tty) {
     irq_restore(flags);
 }
 
-void tty_switch(tty_t *tty) {
+void tty_switch(tty_ttty) {
     if (0 == tty) {
         return;
     }
@@ -274,8 +276,8 @@ void tty_switch(tty_t *tty) {
 }
 
 void tty_switch_to_next() {
-    tty_t *tty = ttys + ((current_tty - ttys + 1) % NR_TTYS);
+    tty_ttty = ttys + ((current_tty - ttys + 1) % NR_TTYS);
     tty_switch(tty);
 }
 
-tty_t *current_tty;
+tty_tcurrent_tty;
index 9536f1f009ec6239c4d01ad464c49e0869e80dfe..d301c6a4e1504f4dd38e1f03ee6c6a6b903a49e4 100644 (file)
 #include <sched.h>
 #include <wait.h>
 
-volatile void init_wait_queue_head(wait_queue_head_t *wqh) { INIT_LIST_HEAD(&(wqh->task_list)); }
+volatile void init_wait_queue_head(wait_queue_head_t* wqh) {
+    INIT_LIST_HEAD(&(wqh->task_list));
+}
 
-volatile void prepare_to_wait(wait_queue_head_t *head, wait_queue_entry_t *wqe, unsigned int state) {
+volatile void prepare_to_wait(wait_queue_head_t* head, wait_queue_entry_t* wqe, unsigned int state) {
     unsigned long flags;
     irq_save(flags);
     // 进程可能等待一个condition满足后被唤醒
@@ -29,7 +31,7 @@ volatile void prepare_to_wait(wait_queue_head_t *head, wait_queue_entry_t *wqe,
     irq_restore(flags);
 }
 
-volatile void __end_wait(wait_queue_entry_t *wqe) {
+volatile void __end_wait(wait_queue_entry_twqe) {
     set_current_state(TASK_READY);
     current->reason = "e_wait";
     unsigned long flags;
@@ -38,21 +40,21 @@ volatile void __end_wait(wait_queue_entry_t *wqe) {
     irq_restore(flags);
 }
 
-volatile void add_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wqe) {
+volatile void add_wait_queue(wait_queue_head_t* head, wait_queue_entry_t* wqe) {
     unsigned long flags;
     irq_save(flags);
     list_add_tail(&wqe->entry, &head->task_list);
     irq_restore(flags);
 }
 
-volatile void del_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wqe) {
+volatile void del_wait_queue(wait_queue_head_t* head, wait_queue_entry_t* wqe) {
     unsigned long flags;
     irq_save(flags);
     list_del(&wqe->entry);
     irq_restore(flags);
 }
 
-volatile void __wake_up(wait_queue_head_t *head, int nr) {
+volatile void __wake_up(wait_queue_head_thead, int nr) {
     unsigned long flags;
     wait_queue_entry_t *p, *tmp;
     irq_save(flags);
@@ -74,7 +76,7 @@ volatile void __wake_up(wait_queue_head_t *head, int nr) {
     // no schedule() here.
 }
 
-volatile void wake_up(wait_queue_head_t *head) {
+volatile void wake_up(wait_queue_head_thead) {
     //
     __wake_up(head, 0);  // wake up all
 }
index a8bf90603c1a17d94c188fd4b5d5e4fadb0fa95d..ea9d58dd79a4cbfa9950d90407a6bf6a97951d4b 100644 (file)
@@ -11,4 +11,6 @@
  */
 #include <syscall.h>
 
-int execv(const char *path, char *const argv[]) { return syscall2(SYSC_EXEC, path, argv); }
+int execv(const char* path, char* const argv[]) {
+    return syscall2(SYSC_EXEC, path, argv);
+}
index ee192973f21da9e95eb3a4fa80e15cf2dc825b37..ef46e6ba113462179216ff55fbf7baa55a8deb1d 100644 (file)
@@ -11,4 +11,6 @@
  */
 
 #include <syscall.h>
-int exit(int status) { syscall1(SYSC_EXIT, status); }
+int exit(int status) {
+    syscall1(SYSC_EXIT, status);
+}
index cbd4a7400628efc9b35350551fd87d765a65a784..53af61ff1438254587c19a4e16816e5a2fb82d14 100644 (file)
@@ -116,7 +116,7 @@ unsigned int _parse_kbd(int ScanCode)
 
     if(ScanCode & 0x80)    // Make Or Break Code ?
         goto    BreakCode;
-#if 0    
+#if 0
     // Ctrl    + Alt + Del
     if( IS_L_CTRL_DOWN(key) && IS_L_ALT_DOWN(key))
     {
@@ -152,7 +152,7 @@ unsigned int _parse_kbd(int ScanCode)
         E0Flag?SET_R_ALT_DOWN(key):SET_L_ALT_DOWN(key);
         goto End;
     }
-        
+
     goto    End;
 
 BreakCode:
index 72dfdeb2548bd8fcacf9e73941c98d3156a42304..149ddd1b5b49f2175fd2e24db7fea862e29bf9ef 100644 (file)
--- a/lib/lib.c
+++ b/lib/lib.c
 #include <syscall.h>
 #include <system.h>
 
-int isdigit(char c) { return ('0' <= c && c <= '9'); }
+int isdigit(char c) {
+    return ('0' <= c && c <= '9');
+}
 
-int atoi(const char *s) {
+int atoi(const chars) {
     int i = 0;
     while (isdigit(*s)) {
         i *= 10;
@@ -34,9 +36,9 @@ int atoi(const char *s) {
 
 // int pause(unsigned long tick) { return syscall1(SYSC_PAUSE, tick); }
 
-int vsprintf(char *buf, const char *fmt, char *args);
-int sprintf(char *str, const char *fmtstr, ...) {
-    char *args = (char *)(((char *)&fmtstr) + 4);
+int vsprintf(char* buf, const char* fmt, char* args);
+int sprintf(char* str, const char* fmtstr, ...) {
+    char* args = (char*)(((char*)&fmtstr) + 4);
 
     vsprintf(str, fmtstr, args);
 
index bffe2c5852659e6f129f04e2ef923f13c74edde2..e85b2e8d84ca54aeb707e918fbb160fd8a51bde0 100644 (file)
@@ -30,4 +30,4 @@ _start:
     nop
     nop
 die:
-    jmp die 
+    jmp die
index c4072fb739123872b775f1f4e1e5273e4a8952f7..acf89b194e7b78c5877128bb9f208838edde841f 100644 (file)
@@ -10,7 +10,7 @@
  *--------------------------------------------------------------------------
  */
 #include <syscall.h>
-int open(const char *path, int flags, ...) {
+int open(const charpath, int flags, ...) {
     // 不支持第三个参数
     return syscall3(SYSC_OPEN, path, flags, 0);
 }
index 6376610a3cba688b3858073650ad2f5901db7767..60067ede6ec182d4ad2ab0427d08e740baa14436 100644 (file)
@@ -11,4 +11,6 @@
  */
 #include <syscall.h>
 #include <types.h>
-ssize_t read(int fd, void *buf, size_t count) { return (ssize_t)syscall3(SYSC_READ, fd, buf, count); }
+ssize_t read(int fd, void* buf, size_t count) {
+    return (ssize_t)syscall3(SYSC_READ, fd, buf, count);
+}
index 7e5fa32aa07d2aeaa7b61637fdeb374eb17186f3..8a6ce1c3d85f15030ef2f742bbe55bb4c93cb928 100644 (file)
@@ -13,5 +13,9 @@
 #include <syscall.h>
 #include <types.h>
 
-int _stat(int fd, struct stat *stat) { return syscall2(SYSC_STAT, fd, stat); }
-int fstat(int fd, struct stat *buf) { return _stat(fd, buf); }
+int _stat(int fd, struct stat* stat) {
+    return syscall2(SYSC_STAT, fd, stat);
+}
+int fstat(int fd, struct stat* buf) {
+    return _stat(fd, buf);
+}
index 0b227ddcaced75eb41b04b81d4bc7b4b248b249d..8f6bdc6bfa1bd1654ef397e0221da33d67c65bba 100644 (file)
@@ -5,14 +5,14 @@
 
 #include "string.h"
 
-char *strcpy(char *dest, const char *src) {
-    char *p = dest;
+char* strcpy(char* dest, const char* src) {
+    charp = dest;
     while ((*dest++ = *src++))
         ;
     return p;
 }
 
-char *strncpy(char *dst, const char *src, size_t len) {
+char* strncpy(char* dst, const char* src, size_t len) {
     for (size_t i = 0; i < len; i++) {
         dst[i] = src[i];
         if (src[i] == 0) {
@@ -23,7 +23,7 @@ char *strncpy(char *dst, const char *src, size_t len) {
     return dst;
 }
 
-size_t strlcpy(char *dst, const char *src, size_t size) {
+size_t strlcpy(char* dst, const char* src, size_t size) {
     size_t i = 0;
 
     if (size == 0) {
@@ -42,22 +42,24 @@ size_t strlcpy(char *dst, const char *src, size_t size) {
     return i;
 }
 
-size_t strlen(const char *str) {
+size_t strlen(const charstr) {
     int i = 0;
-    while (*str++) i++;
+    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;
+        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) {
@@ -65,9 +67,11 @@ int strncmp(const char *a, const char *b, size_t count) {
         c2 = *b++;
 
         delta = c1 - c2;
-        if (delta != 0) return delta;
+        if (delta != 0)
+            return delta;
 
-        if (c1 == 0) break;
+        if (c1 == 0)
+            break;
 
         count--;
     }
@@ -75,16 +79,17 @@ int strncmp(const char *a, const char *b, size_t count) {
     return 0;
 }
 
-char *strcat(char *dest, const char *src) {
-    char *tmp = dest;
-    while (*dest) dest++;
+char* strcat(char* dest, const char* src) {
+    char* tmp = dest;
+    while (*dest)
+        dest++;
     while (*dest++ = *src++)
         ;
     return tmp;
 }
-void *memcpy(void *dest, const void *src, size_t size) {
-    char *d = (char *)dest;
-    char *s = (char *)src;
+void* memcpy(void* dest, const void* src, size_t size) {
+    char* d = (char*)dest;
+    char* s = (char*)src;
     while (size-- > 0) {
         *d = *s;
         d++;
@@ -93,30 +98,33 @@ void *memcpy(void *dest, const void *src, size_t size) {
     return dest;
 }
 
-void memset(void *dest, char ch, size_t size) {
-    char *p = (char *)dest;
+void memset(voiddest, char ch, size_t size) {
+    char* p = (char*)dest;
     for (size_t i = 0; i < size; i++) {
         *p = ch;
         p++;
     }
 }
 
-int memcmp(const void *a, const void *b, size_t count) {
+int memcmp(const void* a, const void* b, size_t count) {
     const unsigned char *sa, *sb;
     int delta = 0;
     for (sa = a, sb = b; count > 0; ++sa, ++sb, --count)
-        if ((delta = *sa - *sb) != 0) break;
+        if ((delta = *sa - *sb) != 0)
+            break;
     return delta;
 }
 
-char *strstr(const char *a, const char *b) {
+char* strstr(const char* a, const char* b) {
     size_t la, lb;
     lb = strlen(b);
-    if (lb == 0) return (char *)a;
+    if (lb == 0)
+        return (char*)a;
     la = strlen(a);
     while (la >= lb) {
         la--;
-        if (memcmp(a, b, lb) == 0) return (char *)a;
+        if (memcmp(a, b, lb) == 0)
+            return (char*)a;
         a++;
     }
 
index e16be0e3f36ca3beff66e37a54b8b52e4cdab19c..1570296dba05bf3f5d378ed8bac43e2e89645323 100644 (file)
@@ -48,13 +48,21 @@ static int __volatile__ __syscall4(int nr, unsigned long a, unsigned long b, uns
     return __sysc_ret__;
 }
 
-int _syscall0(int nr) { return __syscall0(nr); }
+int _syscall0(int nr) {
+    return __syscall0(nr);
+}
 
-int _syscall1(int nr, unsigned long a) { return __syscall1(nr, a); }
+int _syscall1(int nr, unsigned long a) {
+    return __syscall1(nr, a);
+}
 
-int _syscall2(int nr, unsigned long a, unsigned long b) { return __syscall2(nr, a, b); }
+int _syscall2(int nr, unsigned long a, unsigned long b) {
+    return __syscall2(nr, a, b);
+}
 
-int _syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) { return __syscall3(nr, a, b, c); }
+int _syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) {
+    return __syscall3(nr, a, b, c);
+}
 
 int _syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) {
     return __syscall4(nr, a, b, c, d);
index 21488e18ff286c4dd4fe5616e69142cbeb360b1c..b15c67218c42c8ef07a9d05f8caff3077a6ba0a8 100644 (file)
@@ -9,18 +9,19 @@
 
 #include "string.h"
 
-char *itoa(char *s, int n);
-char *itou(char *s, unsigned int n);
-char *itoo(char *s, unsigned int n);
-char *itox(char *s, unsigned int n, int upper);
-char *i64tou(char *s, uint64_t n);
-char *i64too(char *s, uint64_t n);
-char *i64tox(char *s, uint64_t n, int upper);
+char* itoa(char* s, int n);
+char* itou(char* s, unsigned int n);
+char* itoo(char* s, unsigned int n);
+char* itox(char* s, unsigned int n, int upper);
+char* i64tou(char* s, uint64_t n);
+char* i64too(char* s, uint64_t n);
+char* i64tox(char* s, uint64_t n, int upper);
 
 enum { ALIGN_RIGHT, ALIGN_LEFT };
 
-int write_buf(char *buf, const char *str, char fillch, int charcnt, int align) {
-    if (str == 0) return 0;
+int write_buf(char* buf, const char* str, char fillch, int charcnt, int align) {
+    if (str == 0)
+        return 0;
 
     int len = strlen(str);
     int delta_char_cnt = charcnt - len;
@@ -43,8 +44,8 @@ int write_buf(char *buf, const char *str, char fillch, int charcnt, int align) {
     return charcnt > len ? charcnt : len;
 }
 
-int vsprintf(char *buf, const char *fmt, char *args) {
-    char *p = buf;
+int vsprintf(char* buf, const char* fmt, char* args) {
+    charp = buf;
     int char_cnt;
     char tmp[64];
 
@@ -81,41 +82,41 @@ int vsprintf(char *buf, const char *fmt, char *args) {
             *p++ = *args;
             break;
         case 'd':
-            itoa(tmp, *((int *)args));
+            itoa(tmp, *((int*)args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);
             break;
         case 'l':
             fmt++;
             if (*fmt == 'u' || *fmt == 'd') {  // d u都当成u来处理
-                i64tou(tmp, *((int64_t *)args));
+                i64tou(tmp, *((int64_t*)args));
                 p += write_buf(p, tmp, char_fill, char_cnt, align);
                 args += 4;
             } else if (*fmt == 'o') {
-                i64too(tmp, *((uint64_t *)args));
+                i64too(tmp, *((uint64_t*)args));
                 p += write_buf(p, tmp, char_fill, char_cnt, align);
                 args += 4;
             } else if (*fmt == 'x' || *fmt == 'X') {
                 // i64tox(tmp, *((uint64_t *)args), *fmt == 'X' ? 1 : 0);
-                i64tox(tmp, *((uint64_t *)args), 1);  // x X都强制为大写
+                i64tox(tmp, *((uint64_t*)args), 1);  // x X都强制为大写
                 p += write_buf(p, tmp, char_fill, char_cnt, align);
                 args += 4;
             }
             break;
         case 's':
-            p += write_buf(p, (const char *)*((unsigned int *)args), char_fill, char_cnt, align);
+            p += write_buf(p, (const char*)*((unsigned int*)args), char_fill, char_cnt, align);
             break;
         case 'u':
-            itou(tmp, *((unsigned int *)args));
+            itou(tmp, *((unsigned int*)args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);
             break;
         case 'x':
         case 'X':
             // itox(tmp, *((unsigned int *)args), *fmt == 'X' ? 1 : 0);
-            itox(tmp, *((unsigned int *)args), 1);  // x X都强制为大写
+            itox(tmp, *((unsigned int*)args), 1);  // x X都强制为大写
             p += write_buf(p, tmp, char_fill, char_cnt, align);
             break;
         case 'o':
-            itoo(tmp, *((unsigned *)args));
+            itoo(tmp, *((unsigned*)args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);
             break;
         default:
@@ -129,16 +130,16 @@ int vsprintf(char *buf, const char *fmt, char *args) {
     return p - buf;
 }
 
-void swap_char(char *a, char *b) {
+void swap_char(char* a, char* b) {
     char c;
     c = *a;
     *a = *b;
     *b = c;
 }
 
-char *itoa(char *s, int n) {
+char* itoa(char* s, int n) {
     int i = 0;
-    char *p = 0;
+    charp = 0;
 
     if (n & 0x80000000) {
         n = ~n + 1;
@@ -161,7 +162,7 @@ char *itoa(char *s, int n) {
     }
 }
 
-char *i64tou(char *s, uint64_t n) {
+char* i64tou(char* s, uint64_t n) {
     itou(s, n >> 32);
     int i = 0;
     if ((n >> 32) > 0) {
@@ -170,9 +171,9 @@ char *i64tou(char *s, uint64_t n) {
     itou(s + i, n & 0xFFFFFFFF);
 }
 
-char *itou(char *s, unsigned int n) {
+char* itou(char* s, unsigned int n) {
     char c;
-    char *p = s;
+    charp = s;
 
     do {
         *p++ = (n % 10) + '0';
@@ -188,8 +189,8 @@ char *itou(char *s, unsigned int n) {
     }
 }
 
-char *_itoo(char *s, uint64_t n, int bgn) {
-    char *p = s;
+char* _itoo(char* s, uint64_t n, int bgn) {
+    charp = s;
     char ch;
     int i;
     bool flag = false;
@@ -217,18 +218,18 @@ char *_itoo(char *s, uint64_t n, int bgn) {
     return s;
 }
 
-char *itoo(char *s, unsigned int n) {
+char* itoo(char* s, unsigned int n) {
     //
     return _itoo(s, n, 30);
 }
 
-char *i64too(char *s, uint64_t n) {
+char* i64too(char* s, uint64_t n) {
     //
     return _itoo(s, n, 63);
 }
 
-char *_itox(char *s, uint64_t n, int upper, int bgn) {
-    char *p = s;
+char* _itox(char* s, uint64_t n, int upper, int bgn) {
+    charp = s;
     char ch;
     int i;
     bool flag = false;
@@ -261,12 +262,12 @@ char *_itox(char *s, uint64_t n, int upper, int bgn) {
     return s;
 }
 
-char *itox(char *s, unsigned int n, int upper) {
+char* itox(char* s, unsigned int n, int upper) {
     //
     return _itox(s, n, upper, 28);
 }
 
-char *i64tox(char *s, uint64_t n, int upper) {
+char* i64tox(char* s, uint64_t n, int upper) {
     //
     return _itox(s, n, upper, 60);
 }
index 2b902b79fc258bcaf73c47bdcce31a3a791564d6..83865d6091b7d3c52304015f3bfac7cd9e83dd50 100644 (file)
@@ -8,4 +8,6 @@
  */
 
 #include <syscall.h>
-int wait(unsigned long pid) { syscall1(SYSC_WAIT, pid); }
+int wait(unsigned long pid) {
+    syscall1(SYSC_WAIT, pid);
+}
index 04353c6f4fab8be1fe9a3f8347a5821af331f160..b5e94a654c4a78efc126e15b56c815e6f903c80f 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <syscall.h>
 
-int write(int fd, const char *buf, unsigned long size) {
+int write(int fd, const charbuf, unsigned long size) {
     // asm(""::"c"(size),"d"(buf),"b"(fd));
     // sysenter(0);
     // syscall3(0, fd, buf, size);
index f7f8853c486663983bdf883cd9ca432a09b55492..99af4795605b93d36351300cefba8dec700f005a 100644 (file)
@@ -12,8 +12,8 @@
 #include <string.h>
 #include <system.h>
 
-static void get_e820_size(uint32_t size, char *buf) {
-    const char *fmt = "%3u %s";
+static void get_e820_size(uint32_t size, charbuf) {
+    const charfmt = "%3u %s";
     if (size < (1 << 10)) {
         sprintf(buf, fmt, size, "B");
     } else if (size < (1 << 20)) {
@@ -48,7 +48,7 @@ static void get_e820_size(uint32_t size, char *buf) {
 //     }
 // }
 
-static void get_e820_type(uint32_t type, char *buf) {
+static void get_e820_type(uint32_t type, charbuf) {
     switch (type) {
     case E820_RAM:
         sprintf(buf, "%s", "RAM");
@@ -73,7 +73,7 @@ static void get_e820_type(uint32_t type, char *buf) {
 
 // op: 0 clear bit, 1 set bit
 void fast_init_bootmem_bitmap(unsigned long bgn_pfn, unsigned long end_pfn, int op) {
-    int (*bit_func)(unsigned int, volatile unsigned long *);
+    int (*bit_func)(unsigned int, volatile unsigned long*);
 
     bit_func = op == 0 ? test_and_clear_bit : test_and_set_bit;
 
@@ -89,7 +89,7 @@ void fast_init_bootmem_bitmap(unsigned long bgn_pfn, unsigned long end_pfn, int
     unsigned int bytes = (end_pfn - i) / 8;
 
     // 直接清零或设置
-    memset((char *)(bootmem_data.bitmap) + (i / 8), data, bytes);
+    memset((char*)(bootmem_data.bitmap) + (i / 8), data, bytes);
 
     // 最后设置尾部不是整字节的比特
     for (i += bytes * 8; i < end_pfn; i++) {
@@ -100,7 +100,7 @@ void fast_init_bootmem_bitmap(unsigned long bgn_pfn, unsigned long end_pfn, int
 void e820_print_map() {
     unsigned int i = 0;
     for (i = 0; i < boot_params.e820map.map_cnt; ++i) {
-        struct e820_entry *p = boot_params.e820map.map + i;
+        struct e820_entryp = boot_params.e820map.map + i;
 
         // printk(" [%02d] 0x%010lX - 0x%010lX size %- 10u %8dKB %5dMB ", i, p->addr, (p->addr + p->size - 1),
         //        (uint32_t)p->size, (uint32_t)(p->size >> 10), (uint32_t)(p->size >> 20));
@@ -114,9 +114,13 @@ void e820_print_map() {
 
 bootmem_data_t bootmem_data;
 
-unsigned long bootmem_max_pfn() { return bootmem_data.max_pfn; }
+unsigned long bootmem_max_pfn() {
+    return bootmem_data.max_pfn;
+}
 
-unsigned long bootmem_page_state(unsigned long pfn) { return constant_test_bit(pfn, bootmem_data.bitmap); }
+unsigned long bootmem_page_state(unsigned long pfn) {
+    return constant_test_bit(pfn, bootmem_data.bitmap);
+}
 
 void e820_init_bootmem_data() {
     unsigned int i = 0;
@@ -126,7 +130,7 @@ void e820_init_bootmem_data() {
     bootmem_data.max_pfn = 0;
 
     for (i = 0; i < boot_params.e820map.map_cnt; ++i) {
-        struct e820_entry *p = boot_params.e820map.map + i;
+        struct e820_entryp = boot_params.e820map.map + i;
 
         if (p->type != E820_RAM) {
             continue;
@@ -167,7 +171,7 @@ void e820_init_bootmem_data() {
 
 void register_bootmem_pages() {
     for (unsigned int i = 0; i < boot_params.e820map.map_cnt; ++i) {
-        struct e820_entry *p = boot_params.e820map.map + i;
+        struct e820_entryp = boot_params.e820map.map + i;
 
         if (p->type != E820_RAM) {
             continue;
@@ -203,7 +207,9 @@ void reserve_bootmem(unsigned long bgn_pfn, unsigned long end_pfn) {
 #endif
 }
 
-void reserve_kernel_pages() { reserve_bootmem(PFN_DW(va2pa(system.kernel_begin)), PFN_UP(va2pa(system.kernel_end))); }
+void reserve_kernel_pages() {
+    reserve_bootmem(PFN_DW(va2pa(system.kernel_begin)), PFN_UP(va2pa(system.kernel_end)));
+}
 
 void reserve_bootmem_bitmap() {
     unsigned long bgn_pfn = PFN_DW(va2pa(bootmem_data.bitmap));
@@ -254,11 +260,11 @@ void init_bootmem() {
 
 // 由于只有在构建buddy system的时候才会用到
 // 所以这里就简单实现
-void *alloc_from_bootmem(unsigned long size, char *title) {
-    void *region = NULL;
+void* alloc_from_bootmem(unsigned long size, char* title) {
+    voidregion = NULL;
     unsigned long pfn_cnt = PFN_UP(size);
 
-    bootmem_data_t *pbd = &bootmem_data;
+    bootmem_data_tpbd = &bootmem_data;
 
     // 从该处开始查找空闲区间
     unsigned long search_bgn_pfn = pbd->prepare_alloc_pfn;
index e2a16e2eca9bf42b8380aedf8a2652e0e134a467..9f251a5a765b72ae3f26d0e3e4082fe8803653a7 100644 (file)
 #include <sysctl.h>
 
 struct buddy_system {
-    page_t *page_map;
-    page_t *page_map_end;
+    page_tpage_map;
+    page_tpage_map_end;
     free_area_t free_area[MAX_ORDER];
 };
 
 struct buddy_system buddy_system;
 
-int buddy_is_free(page_t *page, unsigned int order) {
-    if (PagePrivate(page) && page->private == order) return 1;
+int buddy_is_free(page_t* page, unsigned int order) {
+    if (PagePrivate(page) && page->private == order)
+        return 1;
 
     return 0;
 }
 
-page_t *_va2page(unsigned long addr) {
-    page_t *page = buddy_system.page_map + va2pfn(addr);
+page_t_va2page(unsigned long addr) {
+    page_tpage = buddy_system.page_map + va2pfn(addr);
 
     assert(page >= buddy_system.page_map);
     // assert(page < buddy_system.page_map_end);
@@ -40,19 +41,23 @@ page_t *_va2page(unsigned long addr) {
 
     return page;
 }
-page_t *_pa2page(unsigned long paddr) {
+page_t_pa2page(unsigned long paddr) {
     unsigned long vaddr = (unsigned long)pa2va(paddr);
     // printk("%s paddr %08x vaddr %08x\n", __func__, paddr, vaddr);
     return va2page(vaddr);
 }
 
-void *page2va(page_t *page) { return pfn2va((page)-buddy_system.page_map); }
-void *page2pa(page_t *page) { return pfn2pa((page)-buddy_system.page_map); }
+void* page2va(page_t* page) {
+    return pfn2va((page)-buddy_system.page_map);
+}
+void* page2pa(page_t* page) {
+    return pfn2pa((page)-buddy_system.page_map);
+}
 
-page_t *__alloc_pages(unsigned int order) {
+page_t__alloc_pages(unsigned int order) {
     //
-    page_t *page = 0;
-    free_area_t *area;
+    page_tpage = 0;
+    free_area_tarea;
     unsigned int select_order;
     unsigned int i;
 
@@ -81,7 +86,7 @@ found:
         select_order--;
         unsigned long buddy_offset = 1UL << select_order;
 
-        page_t *buddy_page = page + buddy_offset;
+        page_tbuddy_page = page + buddy_offset;
         list_add(&(buddy_page->lru), &(area->free_list));
         area->free_count++;
         buddy_page->private = select_order;
@@ -90,7 +95,7 @@ found:
 
     // 初始化这一连续的page块
     for (i = 0; i < (1UL << order); ++i) {
-        page_t *p = page + i;
+        page_tp = page + i;
         p->head_page = page;
         p->order = order;
     }
@@ -112,13 +117,13 @@ found:
     return page;
 }
 
-page_t *alloc_pages(unsigned int gfp_mask, unsigned int order) {
+page_talloc_pages(unsigned int gfp_mask, unsigned int order) {
     // gfp_mask
     // ...
 
     unsigned long flags;
     irq_save(flags);
-    page_t *page = __alloc_pages(order);
+    page_tpage = __alloc_pages(order);
     irq_restore(flags);
 
     // unsigned long addr = (unsigned long)page2va(page);
@@ -127,11 +132,12 @@ page_t *alloc_pages(unsigned int gfp_mask, unsigned int order) {
     return page;
 }
 
-void __free_pages(page_t *page, unsigned int order) {
-    if (order > MAX_ORDER) return;
+void __free_pages(page_t* page, unsigned int order) {
+    if (order > MAX_ORDER)
+        return;
 
-    page_t *buddy = 0;
-    page_t *base = buddy_system.page_map;
+    page_tbuddy = 0;
+    page_tbase = buddy_system.page_map;
     unsigned long page_inx = page - base;
     while (order < (MAX_ORDER - 1)) {
         unsigned long buddy_inx = page_inx ^ (1UL << order);
@@ -151,7 +157,7 @@ void __free_pages(page_t *page, unsigned int order) {
         order++;
     }
 
-    page_t *p = base + page_inx;
+    page_tp = base + page_inx;
     p->private = order;
     p->index = page_inx;
     SetPagePrivate(p);
@@ -164,7 +170,7 @@ void free_pages(unsigned long addr) {
         BUG_ON(!valid_va(addr));
     }
 
-    page_t *page = va2page(addr);
+    page_tpage = va2page(addr);
 
     unsigned long flags;
     irq_save(flags);
@@ -178,8 +184,8 @@ void dump_buddy_system() {
         printk("order %2d free_count %d ", i, buddy_system.free_area[i].free_count);
 
         if (buddy_system.free_area[i].free_count < 1000) {
-            list_head_t *p;
-            page_t *page;
+            list_head_tp;
+            page_tpage;
             printk("pfn:");
             list_for_each(p, &buddy_system.free_area[i].free_list) {
                 page = list_entry(p, page_t, lru);
@@ -192,7 +198,7 @@ void dump_buddy_system() {
 }
 
 void init_buddy_system() {
-    page_t *page;
+    page_tpage;
     unsigned long i;
     unsigned long pfn_cnt = bootmem_max_pfn();
 
@@ -205,12 +211,13 @@ void init_buddy_system() {
 
     // init page map
     unsigned long page_map_size = pfn_cnt * sizeof(page_t);
-    void *alloc_from_bootmem(unsigned long size, char *title);
+    void* alloc_from_bootmem(unsigned long size, char* title);
     buddy_system.page_map = alloc_from_bootmem(page_map_size, "buddy");
     buddy_system.page_map = pa2va(buddy_system.page_map);
     if (0 == buddy_system.page_map) {
         printk("can not go on playing...\n");
-        while (1);
+        while (1)
+            ;
     }
 
     buddy_system.page_map_end = buddy_system.page_map + pfn_cnt + 1;
@@ -218,7 +225,7 @@ void init_buddy_system() {
            pfn_cnt, sizeof(page_t));
     for (i = 0; i < pfn_cnt; ++i) {
         page = buddy_system.page_map + i;
-        memset((void *)page, 0, sizeof(page_t));
+        memset((void*)page, 0, sizeof(page_t));
         page->private = 0;
         page->index = i;
         INIT_LIST_HEAD(&(page->lru));
index dc31f38f19d615e7bc1f4d6355bee5b898138623..e500cc0c632161777b6f92d5bc5cecc1c98df120 100644 (file)
--- a/mm/kmem.c
+++ b/mm/kmem.c
@@ -16,7 +16,7 @@
 static list_head_t slub_caches = LIST_HEAD_INIT(slub_caches);
 static kmem_cache_t kmalloc_caches[SLUB_INIT_CACHE_SIZE];
 
-bool calculate_params(kmem_cache_t *cache) {
+bool calculate_params(kmem_cache_tcache) {
     // calculate size
     unsigned long size = cache->objsize;
     unsigned long align = cache->align;
@@ -24,7 +24,7 @@ bool calculate_params(kmem_cache_t *cache) {
     align = KMALLOC_MIN_ALIGN > align ? KMALLOC_MIN_ALIGN : align;
 
     size = ALIGN(size, align);
-    size = ALIGN(size, sizeof(void *));
+    size = ALIGN(size, sizeof(void*));
 
     cache->size = size;
     cache->align = align;
@@ -51,7 +51,7 @@ bool calculate_params(kmem_cache_t *cache) {
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-bool kmem_cache_init(kmem_cache_t *cache, const char *name, size_t size, size_t align) {
+bool kmem_cache_init(kmem_cache_t* cache, const char* name, size_t size, size_t align) {
     memset(cache, 0, sizeof(kmem_cache_t));
 
     cache->name = name;
@@ -71,26 +71,28 @@ err:
     return false;
 }
 
-void *kmem_cache_alloc(kmem_cache_t *cache, gfp_t gfpflags) { return slub_alloc(cache, gfpflags); }
+void* kmem_cache_alloc(kmem_cache_t* cache, gfp_t gfpflags) {
+    return slub_alloc(cache, gfpflags);
+}
 
-void *kmem_cache_zalloc(kmem_cache_t *cache, gfp_t gfpflags) {
-    void *p = slub_alloc(cache, gfpflags);
+void* kmem_cache_zalloc(kmem_cache_t* cache, gfp_t gfpflags) {
+    voidp = slub_alloc(cache, gfpflags);
     if (0 != p) {
         memset(p, 0, cache->objsize);
     }
     return p;
 }
 
-void kmem_cache_free(kmem_cache_t *cache, void *addr) {
-    page_t *page = 0;
+void kmem_cache_free(kmem_cache_t* cache, void* addr) {
+    page_tpage = 0;
 
     page = get_head_page(va2page((unsigned long)addr));
 
     slub_free(cache, page, addr);
 }
 
-kmem_cache_t *kmem_cache_create(const char *name, size_t size, size_t align) {
-    kmem_cache_t *cache = kmalloc(sizeof(kmem_cache_t), 0);
+kmem_cache_t* kmem_cache_create(const char* name, size_t size, size_t align) {
+    kmem_cache_tcache = kmalloc(sizeof(kmem_cache_t), 0);
     if (cache == 0) {
         return 0;
     }
@@ -109,13 +111,13 @@ kmem_cache_t *kmem_cache_create(const char *name, size_t size, size_t align) {
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void *kmalloc(size_t size, gfp_t gfpflags) {
+voidkmalloc(size_t size, gfp_t gfpflags) {
     unsigned int i;
-    kmem_cache_t *cache = 0;
-    void *addr = 0;
+    kmem_cache_tcache = 0;
+    voidaddr = 0;
 
     for (i = 0; i < SLUB_INIT_CACHE_SIZE; ++i) {
-        kmem_cache_t *p = kmalloc_caches + i;
+        kmem_cache_tp = kmalloc_caches + i;
         if (p->objsize >= size) {
             cache = p;
             break;
@@ -129,8 +131,8 @@ void *kmalloc(size_t size, gfp_t gfpflags) {
     return addr;
 }
 
-void *kzalloc(size_t size, gfp_t gfpflags) {
-    void *p = kmalloc(size, gfpflags);
+voidkzalloc(size_t size, gfp_t gfpflags) {
+    voidp = kmalloc(size, gfpflags);
     if (0 != p) {
         memset(p, 0, size);
     }
@@ -138,9 +140,9 @@ void *kzalloc(size_t size, gfp_t gfpflags) {
     return p;
 }
 
-void kfree(void *addr) {
-    page_t *page = get_head_page(va2page((unsigned long)addr));
-    kmem_cache_t *cache = page->cache;
+void kfree(voidaddr) {
+    page_tpage = get_head_page(va2page((unsigned long)addr));
+    kmem_cache_tcache = page->cache;
 
     slub_free(cache, page, addr);
 }
@@ -149,7 +151,7 @@ void kfree(void *addr) {
 
 void init_kmem_caches() {
     unsigned int i;
-    kmem_cache_t *cache;
+    kmem_cache_tcache;
 
     for (i = SLUB_MIN_SHIFT; i < SLUB_MAX_SHIFT; ++i) {
         cache = kmalloc_caches + i - SLUB_MIN_SHIFT;
diff --git a/mm/mm.c b/mm/mm.c
index 0eda2da76d9b7354da670fcc10dcd6369c020c17..5119dfaa0238ab61345842f7ccea18f8c60496b5 100644 (file)
--- a/mm/mm.c
+++ b/mm/mm.c
@@ -29,23 +29,23 @@ extern char etext, edata, end;
 pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
 pte_t __initdata init_pgt[PTECNT_PER_PAGE * BOOT_INIT_PAGETBL_CNT] __attribute__((__aligned__(PAGE_SIZE)));
 
-void set_page_shared(void *x) {
+void set_page_shared(voidx) {
     unsigned long addr = (unsigned long)x;
     addr = PAGE_ALIGN(addr);
     unsigned int npd = get_npde(addr);
     init_pgd[npd] |= PAGE_US;
 
-    pte_t *pte = pa2va(init_pgd[npd] & PAGE_MASK);
+    pte_tpte = pa2va(init_pgd[npd] & PAGE_MASK);
     pte[get_npte(addr)] |= PAGE_US;
 }
 
-char *paging_page = "paging";
+charpaging_page = "paging";
 
 void init_paging() {
     unsigned int i;
     unsigned long pfn = 0;
-    pte_t *pg_table = 0;
-    void *alloc_from_bootmem(unsigned long size, char *title);
+    pte_tpg_table = 0;
+    void* alloc_from_bootmem(unsigned long size, char* title);
 
     // 在multiboot.S是已经初始化了BOOT_INIT_PAGETBL_CNT个页
     // 这里接着初始化剩余的页
@@ -54,12 +54,12 @@ void init_paging() {
         unsigned long npte = pfn % PAGE_PTE_CNT;
         unsigned long page_addr = (unsigned long)pfn2pa(pfn);
         if (npte == 0) {
-            pg_table = (pte_t *)alloc_from_bootmem(PAGE_SIZE, paging_page);
+            pg_table = (pte_t*)alloc_from_bootmem(PAGE_SIZE, paging_page);
             if (0 == pg_table) {
                 panic("no pages for paging...");
             }
 
-            memset((void *)pg_table, 0, PAGE_SIZE);
+            memset((void*)pg_table, 0, PAGE_SIZE);
 
             init_pgd[get_npde(page_addr)] = (pde_t)((unsigned long)(pg_table) | PAGE_P | PAGE_WR);
         }
@@ -79,31 +79,28 @@ void init_paging() {
     // 这部分页表在pgd里的pde就不再允许修改了
     // 这样,无论内核空间映射如何变化,这部分空间所有进程都能共享到变化
     for (i = kernel_npde_base; i < PDECNT_PER_PAGE; ++i) {
-        if(0 != init_pgd[i]) {
+        if (0 != init_pgd[i]) {
             continue;
         }
 
         // 分配一个页表
-        pte_t *pg_table = (pte_t *)alloc_from_bootmem(PAGE_SIZE, paging_page);
-        if(0 == pg_table) {
+        pte_t* pg_table = (pte_t*)alloc_from_bootmem(PAGE_SIZE, paging_page);
+        if (0 == pg_table) {
             panic("no pages for paging...");
         }
 
         // 清空页表
-        memset((void *)pg_table, 0xAC, PAGE_SIZE);
+        memset((void*)pg_table, 0xAC, PAGE_SIZE);
 
         // 把页表地址填入pgd
         init_pgd[i] = (pde_t)((unsigned long)(pg_table) | PAGE_P | PAGE_WR);
     }
 
-
     // 建立完内核空间的页映射,需要清空用户空间的映射
     for (i = 0; i < kernel_npde_base; ++i) {
         init_pgd[i] = 0;
     }
 
-
-
 #if 0
     // 接下来为显存建立页映射
     unsigned long vram_phys_addr = system.vbe_phys_addr;
@@ -174,7 +171,7 @@ void init_paging() {
 
 extern void init_ttys();
 
-kmem_cache_t *g_vma_kmem_cache = NULL;
+kmem_cache_tg_vma_kmem_cache = NULL;
 
 void init_mm() {
     printk("init bootmem alloc...\n");
@@ -200,8 +197,8 @@ void init_mm() {
     assert(g_vma_kmem_cache != NULL);
 }
 
-vm_area_t *vma_alloc() {
-    vm_area_t *vma = kmem_cache_alloc(g_vma_kmem_cache, 0);
+vm_area_tvma_alloc() {
+    vm_area_tvma = kmem_cache_alloc(g_vma_kmem_cache, 0);
     vma->vm_bgn = 0;
     vma->vm_end = 0;
     vma->vm_flags = 0;
@@ -209,12 +206,12 @@ vm_area_t *vma_alloc() {
     return vma;
 }
 
-void vma_insert(task_t *tsk, vm_area_t *vma_new) {
+void vma_insert(task_t* tsk, vm_area_t* vma_new) {
     //
-    vm_area_t **p = &tsk->vma_list;
+    vm_area_t** p = &tsk->vma_list;
 
     while (*p != NULL) {
-        vm_area_t *v = *p;
+        vm_area_tv = *p;
 
         assert(v->vm_bgn < v->vm_end);
         assert(vma_new->vm_bgn < vma_new->vm_end);
@@ -232,10 +229,10 @@ void vma_insert(task_t *tsk, vm_area_t *vma_new) {
     *p = vma_new;
 }
 
-vm_area_t *vma_find(task_t *tsk, vm_area_t *vma, uint32_t addr) {
-    vm_area_t **p = &tsk->vma_list;
+vm_area_t* vma_find(task_t* tsk, vm_area_t* vma, uint32_t addr) {
+    vm_area_t** p = &tsk->vma_list;
     while (*p != NULL) {
-        vm_area_t *v = *p;
+        vm_area_tv = *p;
 
         if (addr <= v->vm_end) {
             break;
index 58924b352e01e7de0230987c4a27877c57c6c955..f6d345f6b2ac1a9d254d8523f29771817480d395 100644 (file)
--- a/mm/page.c
+++ b/mm/page.c
@@ -17,9 +17,9 @@
 #include <sched.h>
 #include <types.h>
 
-void do_no_page(void *addr) {
-    pde_t *page_dir = (pde_t *)pa2va(current->cr3);
-    pte_t *page_tbl = 0;
+void do_no_page(voidaddr) {
+    pde_t* page_dir = (pde_t*)pa2va(current->cr3);
+    pte_tpage_tbl = 0;
 
     unsigned long page = (unsigned long)page2va(alloc_one_page(0));
     assert(page != 0);
@@ -28,21 +28,21 @@ void do_no_page(void *addr) {
     int npte = get_npte(addr);
 
     if (page_dir[npde] == 0) {
-        page_tbl = (pte_t *)page2va(alloc_one_page(0));
+        page_tbl = (pte_t*)page2va(alloc_one_page(0));
         assert(page_tbl != 0);
 
-        memset((void *)page_tbl, 0, PAGE_SIZE);
+        memset((void*)page_tbl, 0, PAGE_SIZE);
 
         page_dir[npde] = va2pa(page_tbl) | PAGE_P | PAGE_WR | PAGE_US;
     }
 
-    page_tbl = (pte_t *)pa2va(PAGE_ALIGN(page_dir[npde]));
+    page_tbl = (pte_t*)pa2va(PAGE_ALIGN(page_dir[npde]));
     page_tbl[npte] = va2pa(page) | PAGE_P | PAGE_WR | PAGE_US;
 
     load_cr3(current);
 }
 
-void do_wp_page(void *addr) {
+void do_wp_page(voidaddr) {
     // printk("%s   addr %08x current %08x\n", __func__, (unsigned long)addr, current);
     if ((unsigned long)addr >= PAGE_OFFSET) {
         panic("%s invalid addr", __func__);
@@ -51,8 +51,8 @@ void do_wp_page(void *addr) {
     int npde = get_npde(addr);
     int npte = get_npte(addr);
 
-    pde_t *page_dir = (pde_t *)pa2va(current->cr3);
-    pde_t *pde = page_dir + npde;
+    pde_t* page_dir = (pde_t*)pa2va(current->cr3);
+    pde_tpde = page_dir + npde;
 
     // 如果是因为PDE被写保护
     if (*pde & PDE_RW == 0) {
@@ -61,11 +61,11 @@ void do_wp_page(void *addr) {
         assert(newtbl != 0);
 
         // 2. 拷贝页表
-        pte_t *oldtbl = pa2va(PAGE_ALIGN(page_dir[npde]));
-        memcpy((void *)newtbl, (void *)oldtbl, PAGE_SIZE);
+        pte_toldtbl = pa2va(PAGE_ALIGN(page_dir[npde]));
+        memcpy((void*)newtbl, (void*)oldtbl, PAGE_SIZE);
 
         // 3. 对所有PTE加上写保护
-        pte_t *pte = (pte_t *)newtbl;
+        pte_t* pte = (pte_t*)newtbl;
         for (int i = 0; i < PTECNT_PER_PAGE; i++) {
             *pte &= ~PTE_RW;
             pte++;
@@ -82,8 +82,8 @@ void do_wp_page(void *addr) {
         *pde |= PDE_RW;
     }
 
-    pte_t *page_tbl = pa2va(PAGE_ALIGN(page_dir[npde]));
-    pte_t *pte = page_tbl + npte;
+    pte_tpage_tbl = pa2va(PAGE_ALIGN(page_dir[npde]));
+    pte_tpte = page_tbl + npte;
 
     // 如果PTE的位置被写保护
     if (*pte & PTE_RW == 0) {
@@ -92,8 +92,8 @@ void do_wp_page(void *addr) {
         assert(newaddr != 0);
 
         // 2. 拷贝页表
-        pte_t *oldaddr = pa2va(PAGE_ALIGN(page_dir[npde]));
-        memcpy((void *)newaddr, (void *)oldaddr, PAGE_SIZE);
+        pte_toldaddr = pa2va(PAGE_ALIGN(page_dir[npde]));
+        memcpy((void*)newaddr, (void*)oldaddr, PAGE_SIZE);
 
         // 3. 解除PTE的写保护
         *pte |= PTE_RW;
@@ -132,7 +132,6 @@ void do_wp_page(void *addr) {
     load_cr3(current);
 }
 
-
 void page_map(vaddr_t vaddr, paddr_t paddr, uint32_t flags) {
     assert(PAGE_ALIGN(vaddr) == vaddr);
     assert(PAGE_ALIGN(paddr) == paddr);
@@ -142,15 +141,15 @@ void page_map(vaddr_t vaddr, paddr_t paddr, uint32_t flags) {
     int npte = get_npte(vaddr);
 
     // 获取页目录地址
-    pde_t *pgd = (pde_t *) pa2va(get_pgd());
+    pde_t* pgd = (pde_t*)pa2va(get_pgd());
 
-    pte_t *pgt = 0;
+    pte_tpgt = 0;
     pde_t pde = pgd[npde];
-    if(pde & PAGE_P) {
-        pgt = (pte_t *)pa2va(PAGE_ALIGN(pde));
+    if (pde & PAGE_P) {
+        pgt = (pte_t*)pa2va(PAGE_ALIGN(pde));
     } else {
         // 分配页表
-        pgt = (pte_t *)page2va(alloc_one_page(0));
+        pgt = (pte_t*)page2va(alloc_one_page(0));
 
         // 清空页表
         memset(pgt, 0, PAGE_SIZE);
@@ -162,6 +161,5 @@ void page_map(vaddr_t vaddr, paddr_t paddr, uint32_t flags) {
     // 页表指向物理地址
     pgt[npte] = PAGE_ALIGN(paddr) | flags;
 
-
     asm volatile("invlpg (%0)" : : "r"(vaddr));
 }
index 92e48e82dc7fa65a5a86f3f99b5f9a7f40da360a..ff171b585da3cb3cb30d8e348a985a4cdd4c7508 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
 #include <string.h>
 #include <system.h>
 
-page_t *get_partial(kmem_cache_t *cache, gfp_t gfpflags) {
-    if (list_empty(&cache->partial)) return 0;
+page_t* get_partial(kmem_cache_t* cache, gfp_t gfpflags) {
+    if (list_empty(&cache->partial))
+        return 0;
 
-    list_head_t *p = cache->partial.next;
+    list_head_tp = cache->partial.next;
     list_del(p);
 
-    page_t *page = 0;
+    page_tpage = 0;
 
     page = list_entry(p, page_t, lru);
 
@@ -27,8 +28,8 @@ page_t *get_partial(kmem_cache_t *cache, gfp_t gfpflags) {
 }
 
 // 从伙伴系统批发页,并将之初始化成一个链表
-page_t *new_slub(kmem_cache_t *cache, gfp_t gfpflags) {
-    page_t *page = alloc_pages(gfpflags, cache->order);
+page_t* new_slub(kmem_cache_t* cache, gfp_t gfpflags) {
+    page_tpage = alloc_pages(gfpflags, cache->order);
     if (0 == page) {
         return 0;
     }
@@ -42,23 +43,23 @@ page_t *new_slub(kmem_cache_t *cache, gfp_t gfpflags) {
     // 第一遍会将 bgn[0]的地址赋值给bgn[0],也就是 bgn[0] = bgn + 0
     // 第二遍开始就是 bgn[n-1] = bgn + n
     for (addr = bgn; addr < end; addr += cache->size) {
-        *((void **)last) = (void *)addr;
+        *((void**)last) = (void*)addr;
         last = addr;
     }
 
     // 最后一个赋值为0
-    *((void **)last) = 0;
+    *((void**)last) = 0;
 
-    page->freelist = (void **)bgn;
+    page->freelist = (void**)bgn;
     page->inuse = 0;
     page->cache = cache;
 
     return page;
 }
 
-void *__slub_alloc(kmem_cache_t *cache, gfp_t gfpflags) {
-    void **object = 0;
-    page_t *page = 0;
+void* __slub_alloc(kmem_cache_t* cache, gfp_t gfpflags) {
+    void** object = 0;
+    page_tpage = 0;
 
     if (cache->page == 0) {
         page = get_partial(cache, gfpflags);
@@ -86,8 +87,8 @@ void *__slub_alloc(kmem_cache_t *cache, gfp_t gfpflags) {
     return object;
 }
 
-void *slub_alloc(kmem_cache_t *cache, gfp_t gfpflags) {
-    void **object = 0;
+void* slub_alloc(kmem_cache_t* cache, gfp_t gfpflags) {
+    void** object = 0;
 
     if (cache == 0) {
         return 0;
@@ -114,9 +115,9 @@ void *slub_alloc(kmem_cache_t *cache, gfp_t gfpflags) {
     return object;
 }
 
-void __slub_free(kmem_cache_t *cache, page_t *page, void *addr) {
-    void *prior;
-    void **object = addr;
+void __slub_free(kmem_cache_t* cache, page_t* page, void* addr) {
+    voidprior;
+    void** object = addr;
 
     prior = object[0] = page->freelist;
     page->freelist = object;
@@ -131,11 +132,11 @@ void __slub_free(kmem_cache_t *cache, page_t *page, void *addr) {
     }
 }
 
-void slub_free(kmem_cache_t *cache, page_t *page, void *addr) {
+void slub_free(kmem_cache_t* cache, page_t* page, void* addr) {
     unsigned long flags;
     irq_save(flags);
 
-    void **object = addr;
+    void** object = addr;
 
     page->inuse--;
 
index b1ac9359633b4d0e2172807facbaca03fd003f94..94c41cd54d7bdc4d28c6ae4de999253481ea154d 100644 (file)
--- a/mm/slub.h
+++ b/mm/slub.h
@@ -15,5 +15,5 @@
 #define KMALLOC_MIN_SIZE (1UL << (SLUB_MIN_SHIFT))
 #define KMALLOC_MIN_ALIGN (1UL << (SLUB_MIN_SHIFT))
 
-void *slub_alloc(kmem_cache_t *cache, gfp_t gfpflags);
-void slub_free(kmem_cache_t *cache, page_t *page, void *addr);
\ No newline at end of file
+void* slub_alloc(kmem_cache_t* cache, gfp_t gfpflags);
+void slub_free(kmem_cache_t* cache, page_t* page, void* addr);
index c519fc07a205594b4f7c0c6f3fe2225ff4167725..6bc771b17d533a55e0ebf5ce1dee08c886381786 100755 (executable)
@@ -7,7 +7,7 @@
 # Description: none
 # ------------------------------------------------------------------------
 import re
-import requests 
+import requests
 from bs4 import BeautifulSoup
 
 members = {}
@@ -35,7 +35,7 @@ for page in range(0, 10) :
         ids = int(ids)
 
         members[ids] = name
-        
+
 
 for ids in sorted(members.keys()) :
     print("""{{0x{0:X}, "{1}"}},""".format(ids, members[ids]))
diff --git a/scripts/archived/README.md b/scripts/archived/README.md
deleted file mode 100644 (file)
index b44640b..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-这两个脚本开始是为了解决宿主机和 docker 容器无法及时同步文件的问题.
-
-但这样写感觉不太优雅,废弃
-
-如果要再使用,注意的是要放在正确的目录
-
-host.mkiso.sh 放到 kernel/mkiso.sh
-container.mkiso.sh 放到 kernel/scripts/mkiso.sh
-
-host.mkiso.sh要在宿主机调用
-container.mkiso.sh会提交到 docker 容器执行
index 88e874670dd111a4650f01ba255d1dc5c0722466..36d9a9818c35d41ef80922c38ae29fa3886057f3 100644 (file)
@@ -6,8 +6,7 @@ typedef struct list_head {
     struct list_head *prev, *next;
 } list_head_t;
 
-#define LIST_HEAD_INIT(name) \
-    { &(name), &(name) }
+#define LIST_HEAD_INIT(name) {&(name), &(name)}
 #define LIST_HEAD(name) list_head_t name = LIST_HEAD_INIT(name)
 
 #define INIT_LIST_HEAD(ptr)  \
@@ -16,7 +15,7 @@ typedef struct list_head {
         (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_first_entry(ptr, type, member) list_entry((ptr)->next, type, member)
 
@@ -30,34 +29,40 @@ typedef struct list_head {
         tmp = list_entry(pos->member.next, typeof(*pos), member); \
          &pos->member != (head); pos = tmp, tmp = list_entry(tmp->member.next, typeof(*tmp), member))
 
-static inline void _list_add(list_head_t *pnew, list_head_t *prev, list_head_t *next) {
+static inline void _list_add(list_head_t* pnew, list_head_t* prev, list_head_t* next) {
     next->prev = pnew;
     pnew->next = next;
     pnew->prev = prev;
     prev->next = pnew;
 }
 
-static inline void list_add(list_head_t *pnew, list_head_t *head) { _list_add(pnew, head, head->next); }
+static inline void list_add(list_head_t* pnew, list_head_t* head) {
+    _list_add(pnew, head, head->next);
+}
 
-static inline void list_add_tail(list_head_t *pnew, list_head_t *head) { _list_add(pnew, head->prev, head); }
+static inline void list_add_tail(list_head_t* pnew, list_head_t* head) {
+    _list_add(pnew, head->prev, head);
+}
 
-static inline void _list_del(list_head_t *prev, list_head_t *next) {
+static inline void _list_del(list_head_t* prev, list_head_t* next) {
     next->prev = prev;
     prev->next = next;
 }
 
-static inline void list_del(list_head_t *entry) {
+static inline void list_del(list_head_tentry) {
     _list_del(entry->prev, entry->next);
     entry->prev = NULL;
     entry->next = NULL;
 }
 
-static inline void list_del_init(list_head_t *entry) {
+static inline void list_del_init(list_head_tentry) {
     _list_del(entry->prev, entry->next);
     INIT_LIST_HEAD(entry);
 }
 
-static inline int list_empty(list_head_t *head) { return head->next == head; }
+static inline int list_empty(list_head_t* head) {
+    return head->next == head;
+}
 
 typedef struct node {
     int id;
@@ -73,7 +78,7 @@ int main() {
     INIT_LIST_HEAD(&pendH);
 
     for (int i = 0; i < 10; i++) {
-        node_t *n = (node_t *)malloc(sizeof(node_t));
+        node_t* n = (node_t*)malloc(sizeof(node_t));
         n->id = i;
         list_add(&n->list, &allH);
         if (n->id % 3 == 0) {
@@ -81,8 +86,8 @@ int main() {
         }
     }
 
-    list_head_t *pos;
-    list_head_t *tmp;
+    list_head_tpos;
+    list_head_ttmp;
     node_t *p, *p1;
     list_for_each_safe(pos, tmp, &allH) {
         p = list_entry(pos, node_t, list);
@@ -117,4 +122,4 @@ int main() {
         p = list_entry(pos, node_t, pend);
         printf("pendH: %d\n", p->id);
     }
-}
\ No newline at end of file
+}