From 9144d9f3bf3b46a12b8aa4f29cdee59f700d67ab Mon Sep 17 00:00:00 2001 From: xiaoyi1212 Date: Sat, 25 May 2024 18:35:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A1=B9=E7=9B=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.py | 43 ++++--- include/date.h | 7 -- include/pcat.h | 17 --- {boot => src/boot}/asmfunc.asm | 0 {boot => src/boot}/boot.asm | 0 {boot => src/boot}/graphics.asm | 0 {boot => src/boot}/interrupt.asm | 0 {boot => src/boot}/io.asm | 0 {driver => src/driver}/acpi.c | 0 {driver => src/driver}/cmos.c | 0 {driver => src/driver}/dma.c | 0 {driver => src/driver}/ide.c | 0 {driver => src/driver}/keyboard.c | 0 {driver => src/driver}/pci.c | 5 +- {driver => src/driver}/vbe.c | 46 +++++-- {driver => src/driver}/vdisk.c | 0 {driver => src/driver}/vga.c | 0 {fs => src/fs}/fat.c | 0 {fs => src/fs}/iso9660.c | 0 {fs => src/fs}/vfs.c | 0 {include => src/include}/acpi.h | 0 {include => src/include}/arp.h | 0 {include => src/include}/cmos.h | 0 {include => src/include}/common.h | 0 {include => src/include}/cpp.h | 0 {include => src/include}/description_table.h | 0 {include => src/include}/dhcp.h | 0 {include => src/include}/dma.h | 0 {include => src/include}/dns.h | 0 {include => src/include}/etherframe.h | 0 {include => src/include}/fat.h | 0 {include => src/include}/fifo.h | 0 {include => src/include}/graphics.h | 0 {include => src/include}/ide.h | 0 {include => src/include}/io.h | 0 {include => src/include}/ipv4.h | 0 {include => src/include}/iso9660.h | 0 {include => src/include}/isr.h | 0 {include => src/include}/keyboard.h | 0 {include => src/include}/list.h | 0 {include => src/include}/memory.h | 6 +- {include => src/include}/multiboot.h | 0 {include => src/include}/multiboot2.h | 0 {include => src/include}/net.h | 2 +- src/include/panic.h | 4 + {include => src/include}/pci.h | 0 {include => src/include}/pcnet.h | 0 {include => src/include}/printf.h | 0 {include => src/include}/queue.h | 0 {include => src/include}/rtl8139.h | 0 {include => src/include}/shell.h | 0 {include => src/include}/socket.h | 0 {include => src/include}/syscall.h | 0 {include => src/include}/task.h | 0 {include => src/include}/tcp.h | 0 {include => src/include}/timer.h | 0 {include => src/include}/udp.h | 0 {include => src/include}/vdisk.h | 2 +- {include => src/include}/vfs.h | 0 {kernel => src/kernel}/fifo.c | 0 {kernel => src/kernel}/gdt.c | 0 {kernel => src/kernel}/idt.c | 0 {kernel => src/kernel}/kernel.c | 10 +- {kernel => src/kernel}/kheap.c | 0 {kernel => src/kernel}/memory.c | 11 +- {kernel => src/kernel}/multiboot2.c | 0 {kernel => src/kernel}/page.c | 3 + {kernel => src/kernel}/syscall.c | 3 + {kernel => src/kernel}/task.c | 1 - {kernel => src/kernel}/timer.c | 0 {network => src/network}/arp.c | 0 {network => src/network}/dhcp.c | 0 {network => src/network}/dns.c | 0 {network => src/network}/etherframe.c | 0 {network => src/network}/ipv4.c | 0 {network => src/network}/net.c | 0 {network => src/network}/pcnet.c | 0 {network => src/network}/rtl8139.c | 0 {network => src/network}/socket.c | 0 {network => src/network}/tcp.c | 0 {network => src/network}/udp.c | 0 src/sysapp/panic.c | 1 + {sysapp => src/sysapp}/shell.c | 28 ++++- {util => src/util}/base.cpp | 0 {util => src/util}/common.c | 0 {util => src/util}/font.c | 0 {util => src/util}/list.c | 0 {util => src/util}/printf.c | 0 {util => src/util}/queue.c | 0 {util => src/util}/rand.c | 0 sysapp/date.c | 32 ----- sysapp/pcat.c | 126 ------------------- 92 files changed, 115 insertions(+), 232 deletions(-) delete mode 100644 include/date.h delete mode 100644 include/pcat.h rename {boot => src/boot}/asmfunc.asm (100%) rename {boot => src/boot}/boot.asm (100%) rename {boot => src/boot}/graphics.asm (100%) rename {boot => src/boot}/interrupt.asm (100%) rename {boot => src/boot}/io.asm (100%) rename {driver => src/driver}/acpi.c (100%) rename {driver => src/driver}/cmos.c (100%) rename {driver => src/driver}/dma.c (100%) rename {driver => src/driver}/ide.c (100%) rename {driver => src/driver}/keyboard.c (100%) rename {driver => src/driver}/pci.c (98%) rename {driver => src/driver}/vbe.c (79%) rename {driver => src/driver}/vdisk.c (100%) rename {driver => src/driver}/vga.c (100%) rename {fs => src/fs}/fat.c (100%) rename {fs => src/fs}/iso9660.c (100%) rename {fs => src/fs}/vfs.c (100%) rename {include => src/include}/acpi.h (100%) rename {include => src/include}/arp.h (100%) rename {include => src/include}/cmos.h (100%) rename {include => src/include}/common.h (100%) rename {include => src/include}/cpp.h (100%) rename {include => src/include}/description_table.h (100%) rename {include => src/include}/dhcp.h (100%) rename {include => src/include}/dma.h (100%) rename {include => src/include}/dns.h (100%) rename {include => src/include}/etherframe.h (100%) rename {include => src/include}/fat.h (100%) rename {include => src/include}/fifo.h (100%) rename {include => src/include}/graphics.h (100%) rename {include => src/include}/ide.h (100%) rename {include => src/include}/io.h (100%) rename {include => src/include}/ipv4.h (100%) rename {include => src/include}/iso9660.h (100%) rename {include => src/include}/isr.h (100%) rename {include => src/include}/keyboard.h (100%) rename {include => src/include}/list.h (100%) rename {include => src/include}/memory.h (91%) rename {include => src/include}/multiboot.h (100%) rename {include => src/include}/multiboot2.h (100%) rename {include => src/include}/net.h (91%) create mode 100644 src/include/panic.h rename {include => src/include}/pci.h (100%) rename {include => src/include}/pcnet.h (100%) rename {include => src/include}/printf.h (100%) rename {include => src/include}/queue.h (100%) rename {include => src/include}/rtl8139.h (100%) rename {include => src/include}/shell.h (100%) rename {include => src/include}/socket.h (100%) rename {include => src/include}/syscall.h (100%) rename {include => src/include}/task.h (100%) rename {include => src/include}/tcp.h (100%) rename {include => src/include}/timer.h (100%) rename {include => src/include}/udp.h (100%) rename {include => src/include}/vdisk.h (97%) rename {include => src/include}/vfs.h (100%) rename {kernel => src/kernel}/fifo.c (100%) rename {kernel => src/kernel}/gdt.c (100%) rename {kernel => src/kernel}/idt.c (100%) rename {kernel => src/kernel}/kernel.c (92%) rename {kernel => src/kernel}/kheap.c (100%) rename {kernel => src/kernel}/memory.c (86%) rename {kernel => src/kernel}/multiboot2.c (100%) rename {kernel => src/kernel}/page.c (99%) rename {kernel => src/kernel}/syscall.c (89%) rename {kernel => src/kernel}/task.c (99%) rename {kernel => src/kernel}/timer.c (100%) rename {network => src/network}/arp.c (100%) rename {network => src/network}/dhcp.c (100%) rename {network => src/network}/dns.c (100%) rename {network => src/network}/etherframe.c (100%) rename {network => src/network}/ipv4.c (100%) rename {network => src/network}/net.c (100%) rename {network => src/network}/pcnet.c (100%) rename {network => src/network}/rtl8139.c (100%) rename {network => src/network}/socket.c (100%) rename {network => src/network}/tcp.c (100%) rename {network => src/network}/udp.c (100%) create mode 100644 src/sysapp/panic.c rename {sysapp => src/sysapp}/shell.c (94%) rename {util => src/util}/base.cpp (100%) rename {util => src/util}/common.c (100%) rename {util => src/util}/font.c (100%) rename {util => src/util}/list.c (100%) rename {util => src/util}/printf.c (100%) rename {util => src/util}/queue.c (100%) rename {util => src/util}/rand.c (100%) delete mode 100644 sysapp/date.c delete mode 100644 sysapp/pcat.c diff --git a/build.py b/build.py index 42b9f8f..39e71f5 100644 --- a/build.py +++ b/build.py @@ -21,6 +21,7 @@ if check_os() == "Windows": cd = os.getcwd() # 获取当前执行目录 'D:\CrashPowerDOS-main\' out = "target" dir_ = "\\" + src = "src\\" elif check_os() == "Linux": gcc = 'gcc.exe -w -std=gnu99 -I include/ -std=gnu99 -ffreestanding -c -Wincompatible-pointer-types ' asm = 'gcc.exe' @@ -29,6 +30,7 @@ elif check_os() == "Linux": cd = os.getcwd() # 获取当前执行目录 '\mnt\d\CrashPowerDOS-main\' out = "target" dir_ = "/" + src = "./src/" def clean(): @@ -41,13 +43,13 @@ def clean(): def build_boot(): # 构建引导程序 print("Building boot source code...") status = True - for file in os.listdir(cd + dir_ + 'boot'): + for file in os.listdir(cd + dir_ + src + 'boot'): if status and file == 'boot.asm': - cmd = cd + asm + " " + cd + dir_ + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \ + cmd = cd + asm + " " + cd + dir_ + src + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \ file.split(".")[0] + ".o" status = False else: - cmd = nasm + " " + cd + dir_ + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \ + cmd = nasm + " " + cd + dir_ + src + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \ file.split(".")[0] + ".o" e = os.system(cmd) # os.system 执行命令 e为返回值(非0即不正常退出,可做判断终止构建流程) if e != 0: @@ -57,8 +59,17 @@ def build_boot(): # 构建引导程序 def build_driver(): # 构建内置驱动程序 print("Building driver source code...") - for file in os.listdir(cd + dir_ + 'driver'): - cmd = cd + gcc + "-O2 " + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + status_pci = True + status_ide = True + for file in os.listdir(cd + dir_ + src + 'driver'): + if status_pci and (file == 'pci.c'): + cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + status_pci = False + elif status_ide and (file == 'ide.c'): + cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + status_ide = False + else: + cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -67,8 +78,8 @@ def build_driver(): # 构建内置驱动程序 def build_kernel(): # 构建内核本体 print("Building kernel source code...") - for file in os.listdir(cd + dir_ + 'kernel'): - cmd = cd + gcc + "-O2 " + "kernel" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + for file in os.listdir(cd + dir_ + src + 'kernel'): + cmd = cd + gcc + "-O0 " + src + "kernel" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -77,8 +88,8 @@ def build_kernel(): # 构建内核本体 def build_data(): # 构建常用工具 print("Building util source code...") - for file in os.listdir(cd + dir_ + 'util'): - cmd = cd + gcc + "-O2 " + "util" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + for file in os.listdir(cd + dir_ + src + 'util'): + cmd = cd + gcc + "-O2 " + src + "util" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -87,8 +98,8 @@ def build_data(): # 构建常用工具 def build_sysapp(): # 构建内置系统应用 print("Building sysapp source code...") - for file in os.listdir(cd + dir_ + 'sysapp'): - cmd = cd + gcc + "-O2 " + "sysapp" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + for file in os.listdir(cd + dir_ + src + 'sysapp'): + cmd = cd + gcc + "-O0 " + src + "sysapp" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -97,8 +108,8 @@ def build_sysapp(): # 构建内置系统应用 def build_network(): # 构建网络系统 print("Building network source code...") - for file in os.listdir(cd + dir_ + 'network'): - cmd = cd + gcc + "-O2 " + "network" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + for file in os.listdir(cd + dir_ + src + 'network'): + cmd = cd + gcc + "-O0 " + src + "network" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -107,8 +118,8 @@ def build_network(): # 构建网络系统 def build_fs(): # 构建文件系统 print("Building fs source code...") - for file in os.listdir(cd + dir_ + 'fs'): - cmd = cd + gcc + " " + "fs" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" + for file in os.listdir(cd + dir_ + src + 'fs'): + cmd = cd + gcc + " " + src + "fs" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o" e = os.system(cmd) if e != 0: return -1 @@ -162,3 +173,5 @@ a = linker() if a != 0: exit(-1) print("Launching i386 vm...") + +# launch() diff --git a/include/date.h b/include/date.h deleted file mode 100644 index a764a02..0000000 --- a/include/date.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef CRASHPOWEROS_DATE_H -#define CRASHPOWEROS_DATE_H - -int setup_date(); -void launch_date(); - -#endif //CRASHPOWEROS_DATE_H diff --git a/include/pcat.h b/include/pcat.h deleted file mode 100644 index 34c54b0..0000000 --- a/include/pcat.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CRASHPOWEROS_PCAT_H -#define CRASHPOWEROS_PCAT_H - -#include "task.h" - -struct pcat_process{ - uint32_t line; - uint32_t chars; - uint32_t buf_x,buf_y; - uint32_t buffer_screen; - int keys; - struct File *file; -}; - -void pcat_launch(struct File *file); - -#endif diff --git a/boot/asmfunc.asm b/src/boot/asmfunc.asm similarity index 100% rename from boot/asmfunc.asm rename to src/boot/asmfunc.asm diff --git a/boot/boot.asm b/src/boot/boot.asm similarity index 100% rename from boot/boot.asm rename to src/boot/boot.asm diff --git a/boot/graphics.asm b/src/boot/graphics.asm similarity index 100% rename from boot/graphics.asm rename to src/boot/graphics.asm diff --git a/boot/interrupt.asm b/src/boot/interrupt.asm similarity index 100% rename from boot/interrupt.asm rename to src/boot/interrupt.asm diff --git a/boot/io.asm b/src/boot/io.asm similarity index 100% rename from boot/io.asm rename to src/boot/io.asm diff --git a/driver/acpi.c b/src/driver/acpi.c similarity index 100% rename from driver/acpi.c rename to src/driver/acpi.c diff --git a/driver/cmos.c b/src/driver/cmos.c similarity index 100% rename from driver/cmos.c rename to src/driver/cmos.c diff --git a/driver/dma.c b/src/driver/dma.c similarity index 100% rename from driver/dma.c rename to src/driver/dma.c diff --git a/driver/ide.c b/src/driver/ide.c similarity index 100% rename from driver/ide.c rename to src/driver/ide.c diff --git a/driver/keyboard.c b/src/driver/keyboard.c similarity index 100% rename from driver/keyboard.c rename to src/driver/keyboard.c diff --git a/driver/pci.c b/src/driver/pci.c similarity index 98% rename from driver/pci.c rename to src/driver/pci.c index 306bd52..f9acb23 100644 --- a/driver/pci.c +++ b/src/driver/pci.c @@ -105,6 +105,7 @@ void pci_config(unsigned int bus, unsigned int f, unsigned int equipment, unsign void init_pci(){ printf("[\035kernel\036]: Loading pci device...\n"); + int PCI_NUM = 0; PCI_ADDR_BASE = kmalloc(1 * 1024 * 1024); unsigned int i, BUS, Equipment, F, ADDER, *i1; @@ -144,7 +145,7 @@ void init_pci(){ PCI_DATA1 += 4; int i = ((uint32_t)(bar.address)); memcpy(PCI_DATA1, &i, 4); - printf("[pci]: Device Address: %08x Size: %d\n",bar.address,bar.size); + PCI_NUM++; } } PCI_DATA = PCI_DATA + 0x110 + 4; @@ -154,4 +155,6 @@ void init_pci(){ } } } + + printf("[pci]: Device Loaded: %d\n",PCI_NUM); } diff --git a/driver/vbe.c b/src/driver/vbe.c similarity index 79% rename from driver/vbe.c rename to src/driver/vbe.c index 853224c..af98eac 100644 --- a/driver/vbe.c +++ b/src/driver/vbe.c @@ -17,12 +17,35 @@ extern uint8_t plfont[]; bool vbe_status; +static void copy_char(uint32_t *vram, int off_x, int off_y, int x, int y, int x1, + int y1, int xsize) { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 8; j++) { + vram[(y + i + off_y) * xsize + (j + x + off_x)] = + vram[(y1 + i + off_y) * xsize + (j + x1 + off_x)]; + } + } +} + void vbe_scroll() { if (cx > c_width) { cx = 0; cy++; } else cx++; + if (cy >= c_height){ + cy = c_height - 1; + memcpy((void *)screen, + (void *)screen + width * 16 * sizeof(uint32_t), + width * (height - 16) * sizeof(uint32_t)); + for (int i = (width * (height - 16)); + i != (width * height); i++) { + screen[i] = back_color; + } + } + + + /* if (cy >= c_height) { cy = c_height - 1; for (int i = 0; i < height; i++) { @@ -44,6 +67,7 @@ void vbe_scroll() { screen[height * (width + j) + i] = back_color; } } + */ } void vbe_draw_char(char c, int32_t x, int32_t y) { @@ -56,8 +80,9 @@ void vbe_draw_char(char c, int32_t x, int32_t y) { return; } - unsigned char *font; - font = plfont; + + uint8_t *font = ascfont; + font += c * 16; for (int i = 0; i < 16; i++) { for (int j = 0; j < 9; j++) { @@ -95,6 +120,10 @@ void vbe_putchar(char ch) { return; } else if (ch == '\r') { cx = 0; + return; + } else if(ch == '\t'){ + vbe_putchar(" "); + return; } else if (ch == '\b' && cx > 0) { cx -= 1; if (cx == 0) { @@ -139,19 +168,10 @@ void initVBE(multiboot_t *info) { screen = (uint32_t) info->framebuffer_addr; width = info->framebuffer_width; height = info->framebuffer_height; - color = 0xFFFFFF; - back_color = 0x310924; + color = 0xc6c6c6; + back_color = 0x191f42; c_width = width / 9; c_height = height / 16; vbe_clear(); - - /* - for (int i = 0; i < c_height; i++){ - vbe_putchar('A'); - vbe_putchar('\n'); - } - - while (1) io_hlt(); - */ } diff --git a/driver/vdisk.c b/src/driver/vdisk.c similarity index 100% rename from driver/vdisk.c rename to src/driver/vdisk.c diff --git a/driver/vga.c b/src/driver/vga.c similarity index 100% rename from driver/vga.c rename to src/driver/vga.c diff --git a/fs/fat.c b/src/fs/fat.c similarity index 100% rename from fs/fat.c rename to src/fs/fat.c diff --git a/fs/iso9660.c b/src/fs/iso9660.c similarity index 100% rename from fs/iso9660.c rename to src/fs/iso9660.c diff --git a/fs/vfs.c b/src/fs/vfs.c similarity index 100% rename from fs/vfs.c rename to src/fs/vfs.c diff --git a/include/acpi.h b/src/include/acpi.h similarity index 100% rename from include/acpi.h rename to src/include/acpi.h diff --git a/include/arp.h b/src/include/arp.h similarity index 100% rename from include/arp.h rename to src/include/arp.h diff --git a/include/cmos.h b/src/include/cmos.h similarity index 100% rename from include/cmos.h rename to src/include/cmos.h diff --git a/include/common.h b/src/include/common.h similarity index 100% rename from include/common.h rename to src/include/common.h diff --git a/include/cpp.h b/src/include/cpp.h similarity index 100% rename from include/cpp.h rename to src/include/cpp.h diff --git a/include/description_table.h b/src/include/description_table.h similarity index 100% rename from include/description_table.h rename to src/include/description_table.h diff --git a/include/dhcp.h b/src/include/dhcp.h similarity index 100% rename from include/dhcp.h rename to src/include/dhcp.h diff --git a/include/dma.h b/src/include/dma.h similarity index 100% rename from include/dma.h rename to src/include/dma.h diff --git a/include/dns.h b/src/include/dns.h similarity index 100% rename from include/dns.h rename to src/include/dns.h diff --git a/include/etherframe.h b/src/include/etherframe.h similarity index 100% rename from include/etherframe.h rename to src/include/etherframe.h diff --git a/include/fat.h b/src/include/fat.h similarity index 100% rename from include/fat.h rename to src/include/fat.h diff --git a/include/fifo.h b/src/include/fifo.h similarity index 100% rename from include/fifo.h rename to src/include/fifo.h diff --git a/include/graphics.h b/src/include/graphics.h similarity index 100% rename from include/graphics.h rename to src/include/graphics.h diff --git a/include/ide.h b/src/include/ide.h similarity index 100% rename from include/ide.h rename to src/include/ide.h diff --git a/include/io.h b/src/include/io.h similarity index 100% rename from include/io.h rename to src/include/io.h diff --git a/include/ipv4.h b/src/include/ipv4.h similarity index 100% rename from include/ipv4.h rename to src/include/ipv4.h diff --git a/include/iso9660.h b/src/include/iso9660.h similarity index 100% rename from include/iso9660.h rename to src/include/iso9660.h diff --git a/include/isr.h b/src/include/isr.h similarity index 100% rename from include/isr.h rename to src/include/isr.h diff --git a/include/keyboard.h b/src/include/keyboard.h similarity index 100% rename from include/keyboard.h rename to src/include/keyboard.h diff --git a/include/list.h b/src/include/list.h similarity index 100% rename from include/list.h rename to src/include/list.h diff --git a/include/memory.h b/src/include/memory.h similarity index 91% rename from include/memory.h rename to src/include/memory.h index 55529d7..f1a2ef9 100644 --- a/include/memory.h +++ b/src/include/memory.h @@ -47,7 +47,7 @@ typedef union header { uint32_t memory_usage(); -void *memcpy(void *dst_, const void *src_, uint32_t size); +void* memcpy(void* s, const void* ct, size_t n); int memcmp(const void *a_, const void *b_, uint32_t size); @@ -89,6 +89,8 @@ void memclean(char *s, int len); void *realloc(void *ptr, uint32_t size); -page_t *get_phy_page(uint32_t address, int make, page_directory_t *dir); +void alloc_frame_line(page_t *page, unsigned line,int is_kernel, int is_writable); + +void free_frame(page_t *page); #endif //CRASHPOWEROS_MEMORY_H diff --git a/include/multiboot.h b/src/include/multiboot.h similarity index 100% rename from include/multiboot.h rename to src/include/multiboot.h diff --git a/include/multiboot2.h b/src/include/multiboot2.h similarity index 100% rename from include/multiboot2.h rename to src/include/multiboot2.h diff --git a/include/net.h b/src/include/net.h similarity index 91% rename from include/net.h rename to src/include/net.h index 58ef110..55140c2 100644 --- a/include/net.h +++ b/src/include/net.h @@ -1,7 +1,7 @@ #ifndef CRASHPOWEROS_NET_H #define CRASHPOWEROS_NET_H -#include "../include/common.h" +#include "common.h" typedef struct { bool (*find)(); diff --git a/src/include/panic.h b/src/include/panic.h new file mode 100644 index 0000000..44d25ca --- /dev/null +++ b/src/include/panic.h @@ -0,0 +1,4 @@ +#ifndef CRASHPOWEROS_PANIC_H +#define CRASHPOWEROS_PANIC_H + +#endif diff --git a/include/pci.h b/src/include/pci.h similarity index 100% rename from include/pci.h rename to src/include/pci.h diff --git a/include/pcnet.h b/src/include/pcnet.h similarity index 100% rename from include/pcnet.h rename to src/include/pcnet.h diff --git a/include/printf.h b/src/include/printf.h similarity index 100% rename from include/printf.h rename to src/include/printf.h diff --git a/include/queue.h b/src/include/queue.h similarity index 100% rename from include/queue.h rename to src/include/queue.h diff --git a/include/rtl8139.h b/src/include/rtl8139.h similarity index 100% rename from include/rtl8139.h rename to src/include/rtl8139.h diff --git a/include/shell.h b/src/include/shell.h similarity index 100% rename from include/shell.h rename to src/include/shell.h diff --git a/include/socket.h b/src/include/socket.h similarity index 100% rename from include/socket.h rename to src/include/socket.h diff --git a/include/syscall.h b/src/include/syscall.h similarity index 100% rename from include/syscall.h rename to src/include/syscall.h diff --git a/include/task.h b/src/include/task.h similarity index 100% rename from include/task.h rename to src/include/task.h diff --git a/include/tcp.h b/src/include/tcp.h similarity index 100% rename from include/tcp.h rename to src/include/tcp.h diff --git a/include/timer.h b/src/include/timer.h similarity index 100% rename from include/timer.h rename to src/include/timer.h diff --git a/include/udp.h b/src/include/udp.h similarity index 100% rename from include/udp.h rename to src/include/udp.h diff --git a/include/vdisk.h b/src/include/vdisk.h similarity index 97% rename from include/vdisk.h rename to src/include/vdisk.h index fd0ec34..aa830cf 100644 --- a/include/vdisk.h +++ b/src/include/vdisk.h @@ -3,7 +3,7 @@ #define SECTORS_ONCE 8 -#include "../include/common.h" +#include "common.h" typedef struct { void (*Read)(char drive, unsigned char *buffer, unsigned int number, diff --git a/include/vfs.h b/src/include/vfs.h similarity index 100% rename from include/vfs.h rename to src/include/vfs.h diff --git a/kernel/fifo.c b/src/kernel/fifo.c similarity index 100% rename from kernel/fifo.c rename to src/kernel/fifo.c diff --git a/kernel/gdt.c b/src/kernel/gdt.c similarity index 100% rename from kernel/gdt.c rename to src/kernel/gdt.c diff --git a/kernel/idt.c b/src/kernel/idt.c similarity index 100% rename from kernel/idt.c rename to src/kernel/idt.c diff --git a/kernel/kernel.c b/src/kernel/kernel.c similarity index 92% rename from kernel/kernel.c rename to src/kernel/kernel.c index b345a75..294b986 100644 --- a/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -9,7 +9,6 @@ #include "../include/cmos.h" #include "../include/keyboard.h" #include "../include/shell.h" -#include "../include/date.h" #include "../include/acpi.h" #include "../include/syscall.h" #include "../include/vdisk.h" @@ -85,7 +84,7 @@ void kernel_main(multiboot_t *multiboot) { printf("[kernel]: Keyboard driver load success!\n"); io_sti(); - kernel_thread(cur_task,NULL,"CPOS-VBE-SERVICE"); + //kernel_thread(cur_task,NULL,"CPOS-VBE-SERVICE"); init_pit(); init_pci(); @@ -99,22 +98,17 @@ void kernel_main(multiboot_t *multiboot) { vfs_mount_disk('A','A'); if(vfs_change_disk('A')) printf("[FileSystem]: Change disk win!\n"); - else { - for(;;); - } + if(pcnet_find_card()){ //init_pcnet_card(); } else printf("[kernel]: Cannot found pcnet.\n"); print_cpu_id(); - //printf("Memory: %dMB.",(multiboot->mem_upper + multiboot->mem_lower)/1024/1024); - clock_sleep(25); int pid = kernel_thread(setup_shell, NULL, "CPOS-Shell"); kernel_thread(check_task,&pid,"CPOS-SHELL-CHECK"); - launch_date(); for (;;) { io_hlt(); diff --git a/kernel/kheap.c b/src/kernel/kheap.c similarity index 100% rename from kernel/kheap.c rename to src/kernel/kheap.c diff --git a/kernel/memory.c b/src/kernel/memory.c similarity index 86% rename from kernel/memory.c rename to src/kernel/memory.c index a0f1dca..af7d092 100644 --- a/kernel/memory.c +++ b/src/kernel/memory.c @@ -9,11 +9,12 @@ void memclean(char *s, int len) { return; } -void *memcpy(void *dst_, const void *src_, uint32_t size) { - uint8_t *dst = dst_; - const uint8_t *src = src_; - while (size-- > 0) *dst++ = *src++; - return (void *) src_; +void* memcpy(void* s, const void* ct, size_t n) { + if (NULL == s || NULL == ct || n <= 0) + return NULL; + while (n--) + *(char*)s++ = *(char*)ct++; + return s; } int memcmp(const void *a_, const void *b_, uint32_t size) { diff --git a/kernel/multiboot2.c b/src/kernel/multiboot2.c similarity index 100% rename from kernel/multiboot2.c rename to src/kernel/multiboot2.c diff --git a/kernel/page.c b/src/kernel/page.c similarity index 99% rename from kernel/page.c rename to src/kernel/page.c index 68f14b1..fecd9cb 100644 --- a/kernel/page.c +++ b/src/kernel/page.c @@ -76,6 +76,7 @@ void alloc_frame_line(page_t *page, unsigned line,int is_kernel, int is_writable page->frame = line / 0x1000; } + void free_frame(page_t *page) { uint32_t frame = page->frame; if (!frame) return; @@ -211,6 +212,8 @@ void init_page(multiboot_t *mboot) { alloc_frame_line(get_page(j,1,kernel_directory),j,0,0); j += 0x1000; } + + for (int i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i++) { alloc_frame(get_page(i, 1, kernel_directory), 0, 0); } diff --git a/kernel/syscall.c b/src/kernel/syscall.c similarity index 89% rename from kernel/syscall.c rename to src/kernel/syscall.c index 24b9028..6b78b5a 100644 --- a/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -1,4 +1,5 @@ #include "../include/syscall.h" +#include "../include/printf.h" #include "../include/isr.h" void syscall_handler(registers_t *regs){ @@ -7,6 +8,8 @@ void syscall_handler(registers_t *regs){ void *location = NULL;//syscalls[regs->eax]; + printf("Syscall Win: %08x\n",regs->eax); + int ret; asm volatile (" \ push %1; \ diff --git a/kernel/task.c b/src/kernel/task.c similarity index 99% rename from kernel/task.c rename to src/kernel/task.c index 0d7410c..5ed51ba 100644 --- a/kernel/task.c +++ b/src/kernel/task.c @@ -159,7 +159,6 @@ void change_task_to(struct task_struct *next) { switch_page_directory(current->pgd_dir); switch_to(&(prev->context), &(current->context)); - } } diff --git a/kernel/timer.c b/src/kernel/timer.c similarity index 100% rename from kernel/timer.c rename to src/kernel/timer.c diff --git a/network/arp.c b/src/network/arp.c similarity index 100% rename from network/arp.c rename to src/network/arp.c diff --git a/network/dhcp.c b/src/network/dhcp.c similarity index 100% rename from network/dhcp.c rename to src/network/dhcp.c diff --git a/network/dns.c b/src/network/dns.c similarity index 100% rename from network/dns.c rename to src/network/dns.c diff --git a/network/etherframe.c b/src/network/etherframe.c similarity index 100% rename from network/etherframe.c rename to src/network/etherframe.c diff --git a/network/ipv4.c b/src/network/ipv4.c similarity index 100% rename from network/ipv4.c rename to src/network/ipv4.c diff --git a/network/net.c b/src/network/net.c similarity index 100% rename from network/net.c rename to src/network/net.c diff --git a/network/pcnet.c b/src/network/pcnet.c similarity index 100% rename from network/pcnet.c rename to src/network/pcnet.c diff --git a/network/rtl8139.c b/src/network/rtl8139.c similarity index 100% rename from network/rtl8139.c rename to src/network/rtl8139.c diff --git a/network/socket.c b/src/network/socket.c similarity index 100% rename from network/socket.c rename to src/network/socket.c diff --git a/network/tcp.c b/src/network/tcp.c similarity index 100% rename from network/tcp.c rename to src/network/tcp.c diff --git a/network/udp.c b/src/network/udp.c similarity index 100% rename from network/udp.c rename to src/network/udp.c diff --git a/src/sysapp/panic.c b/src/sysapp/panic.c new file mode 100644 index 0000000..8a224f4 --- /dev/null +++ b/src/sysapp/panic.c @@ -0,0 +1 @@ +#include "../include/panic.h" diff --git a/sysapp/shell.c b/src/sysapp/shell.c similarity index 94% rename from sysapp/shell.c rename to src/sysapp/shell.c index 83321c2..180e6b6 100644 --- a/sysapp/shell.c +++ b/src/sysapp/shell.c @@ -213,6 +213,27 @@ void cmd_cd(int argc, char **argv) { if (vfs_change_path(argv[1]) == 0) printf("Invalid path.\n"); } +void cmd_type(int argc,char ** argv){ + if (argc == 1) { + print("[Shell-TYPE]: If there are too few parameters, please specify the path.\n"); + return; + } + char *buffer; + buffer = (char*) kmalloc(vfs_filesize(argv[1])); + + if(buffer == NULL){ + printf("Cannot read file.\n"); + return; + } + + if(vfs_readfile(argv[1],buffer)) + printf("%s",buffer); + else printf("Cannot read file.\n"); + + kfree(buffer); + print("\n"); +} + void cmd_disk(int argc, char **argv) { if (argc > 1) { if (!strcmp("list", argv[1])) { @@ -285,6 +306,7 @@ char *user() { void setup_shell() { char *user1 = "default";//user(); + screen_clear(); printf("Welcome to %s %s (CPOS Kernel x86_64)\n" @@ -324,8 +346,8 @@ void setup_shell() { if (!strcmp("version", argv[0])) printf("%s for x86 [%s]\n", OS_NAME, OS_VERSION); - else if (!strcmp("echo", argv[0])) - cmd_echo(argc, argv); + else if (!strcmp("type", argv[0])) + cmd_type(argc, argv); else if (!strcmp("clear", argv[0])) screen_clear(); else if (!strcmp("proc", argv[0])) @@ -352,7 +374,7 @@ void setup_shell() { print("-=[CoolPotShell Helper]=-\n"); print("help ? h Print shell help info.\n"); print("version Print os version.\n"); - print("echo Print message.\n"); + print("type Read a file.\n"); print("ls List all files.\n"); print("mkdir Make a directory.\n"); print("del rm Delete a file.\n"); diff --git a/util/base.cpp b/src/util/base.cpp similarity index 100% rename from util/base.cpp rename to src/util/base.cpp diff --git a/util/common.c b/src/util/common.c similarity index 100% rename from util/common.c rename to src/util/common.c diff --git a/util/font.c b/src/util/font.c similarity index 100% rename from util/font.c rename to src/util/font.c diff --git a/util/list.c b/src/util/list.c similarity index 100% rename from util/list.c rename to src/util/list.c diff --git a/util/printf.c b/src/util/printf.c similarity index 100% rename from util/printf.c rename to src/util/printf.c diff --git a/util/queue.c b/src/util/queue.c similarity index 100% rename from util/queue.c rename to src/util/queue.c diff --git a/util/rand.c b/src/util/rand.c similarity index 100% rename from util/rand.c rename to src/util/rand.c diff --git a/sysapp/date.c b/sysapp/date.c deleted file mode 100644 index cb22618..0000000 --- a/sysapp/date.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "../include/date.h" -#include "../include/cmos.h" -#include "../include/graphics.h" -#include "../include/timer.h" -#include "../include/common.h" - -extern uint16_t *terminal_buffer; -extern uint8_t terminal_color; -extern bool vbe_status; - -int date_pid; - -void launch_date(){ - if(!vbe_status) - date_pid = kernel_thread(setup_date, NULL, "CPOS-Date"); -} - -int setup_date(){ - char* date_info; - int i; - while (1){ - clock_sleep(5); - date_info = get_date_time(); //11 - i = 0; - for(size_t x = VGA_WIDTH - 19; x < VGA_WIDTH ; x++){ - const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x; - terminal_buffer[index] = vga_entry(date_info[i],terminal_color); - i++; - } - } - return 0; -} diff --git a/sysapp/pcat.c b/sysapp/pcat.c deleted file mode 100644 index 7834ee4..0000000 --- a/sysapp/pcat.c +++ /dev/null @@ -1,126 +0,0 @@ -#include "../include/pcat.h" -#include "../include/graphics.h" -#include "../include/keyboard.h" -#include "../include/date.h" -#include "../include/shell.h" -#include "../include/common.h" - -struct task_struct *father_pcat; -struct pcat_process *this_process; -uint32_t pid_pcat; -extern KEY_STATUS *key_status; -extern uint16_t *terminal_buffer; -extern uint16_t cursor_x, cursor_y; // 光标位置 -extern int date_pid; - -static void pcat_movcur(){ - cursor_x = this_process->buf_x; - cursor_y = this_process->buf_y; - move_cursor(); -} - -static void pcat_char(char c){ - uint16_t *location; - uint8_t attribute = vga_entry_color(VGA_COLOR_DARK_GREY,VGA_COLOR_BLACK); - if(c == '\n'){ - this_process->buf_y++; - this_process->buf_x = 0; - pcat_movcur(); - return; - } else if (c == 0x09) { - location = terminal_buffer + (this_process->buf_y * 80 + this_process->buf_x); - *location = ' ' | attribute; - this_process->buf_x = (this_process->buf_x + 8) & ~(8 - 1); - pcat_movcur(); - return; - } else if (c == '\b') { - if(this_process->buf_x){ - this_process->buf_x--; - location = terminal_buffer + (this_process->buf_y * 80 + this_process->buf_x); - *location = ' ' | attribute; - } else{ - if(this_process->buf_y){ - this_process->buf_y--; - } - } - char* cc = (char*) this_process->buffer_screen; - int i = (this_process->chars)--; - cc[i] = '\0'; - pcat_movcur(); - return; - } - - vga_putentryat(c, attribute,this_process->buf_x,this_process->buf_y); - this_process->buf_x++; - if (this_process->buf_x >= 80) { - this_process->buf_x = 0; - this_process->buf_y++; - } - pcat_movcur(); - char* cc = (char*) this_process->buffer_screen; - int i = (this_process->chars)++; - cc[i] = c; -} - -static void draw_string(const char *data){ - size_t size = strlen(data); - for (size_t i = 0; i < size; i++) - pcat_char(data[i]); -} - -static void draw_menu(){ - for (size_t x = 0; x < VGA_WIDTH; x++) { - vga_putentryat(' ',vga_entry_color(VGA_COLOR_BLACK,VGA_COLOR_LIGHT_GREY),x,(VGA_HEIGHT - 1)); - } -} - -static int input_handler(){ - int index = 0; - char c; - while (1) { - c = getc(); - - if(c == 27){ - this_process->keys = 1; - return 0; - } - - if (c == '\b') { - if (index > 0) { - index--; - draw_string("\b \b"); - } - } else { - index++; - pcat_char(c); - } - } -} - -static int check_exit(){ - return this_process->keys; -} - -void pcat_launch(struct File *file){ - screen_clear(); task_kill(date_pid); vga_clear(); - this_process = (struct pcat_process*) kmalloc(sizeof(struct pcat_process)); - this_process->buf_x = this_process->buf_y = 0; - this_process->line = 1; - this_process->chars = 0; - this_process->buffer_screen = (uint16_t) kmalloc(VGA_WIDTH * (VGA_HEIGHT - 1)); - this_process->file = file; - this_process->keys = 0; - - int pid = kernel_thread(input_handler,NULL,"CPOS-pcat"); - - while (1){ - if(check_exit()){ - break; - } - draw_menu(); - input_handler(); - } - task_kill(pid); - screen_clear(); - date_pid = kernel_thread(setup_date, NULL, "CPOS-Date"); -} \ No newline at end of file