diff --git a/apps/Makefile b/apps/Makefile index 308b541..d372c9e 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,10 +1,10 @@ default: Makefile make -r -C libs make -r -C init - make -r -C base_service + make -r -C shell clean: rm ../isodir/apps/* make -r -C libs clean make -r -C init clean - make -r -C base_service clean \ No newline at end of file + make -r -C shell clean \ No newline at end of file diff --git a/apps/base_service/service.c b/apps/base_service/service.c deleted file mode 100644 index 0233207..0000000 --- a/apps/base_service/service.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "../include/stdio.h" - -int main(){ - while (1); - return 0; -} \ No newline at end of file diff --git a/apps/include/syscall.h b/apps/include/syscall.h index bbdc2a1..58326ed 100644 --- a/apps/include/syscall.h +++ b/apps/include/syscall.h @@ -7,6 +7,7 @@ #define SYSCALL_MALLOC 4 #define SYSCALL_FREE 5 #define SYSCALL_EXIT 6 +#define SYSCALL_G_CLEAN 7 #include #include @@ -17,5 +18,6 @@ char syscall_getc(); void* syscall_malloc(size_t size); void syscall_free(void *ptr); void syscall_exit(int code); +void syscall_g_clean(); #endif diff --git a/apps/init/init.c b/apps/init/init.c index 5baf018..35e9af4 100644 --- a/apps/init/init.c +++ b/apps/init/init.c @@ -1,9 +1,5 @@ #include "../include/stdio.h" -void hlt(){ - while (1); -} - int main(){ printf("User application %d\n",12); return -1; diff --git a/apps/libs/syscall.c b/apps/libs/syscall.c index 80bf9d8..07b5a09 100644 --- a/apps/libs/syscall.c +++ b/apps/libs/syscall.c @@ -39,6 +39,10 @@ void syscall_exit(int code){ uint32_t rets; uint32_t __arg1 = (uint32_t)(code); register uint32_t ebx asm("ebx") = __arg1; - asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXIT), "r"(ebx) : "memory", "cc"); - return rets; + asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXIT), "r"(ebx) : "memory", "cc");\ +} + +void syscall_g_clean(){ + uint32_t rets; + asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_G_CLEAN) : "memory", "cc"); } \ No newline at end of file diff --git a/apps/base_service/Makefile b/apps/shell/Makefile similarity index 67% rename from apps/base_service/Makefile rename to apps/shell/Makefile index 0ec2c6d..ae03727 100644 --- a/apps/base_service/Makefile +++ b/apps/shell/Makefile @@ -1,8 +1,8 @@ -OBJS_PACK = out/service.obj +OBJS_PACK = out/shell.obj include ../def.mk default: $(OBJS_PACK) - $(LINK) $(OBJS_PACK) $(BASIC_LIB_C) -o ../../isodir/apps/service.bin + $(LINK) $(OBJS_PACK) $(BASIC_LIB_C) -o ../../isodir/apps/shell.bin out/%.obj : %.c Makefile $(C) -c $*.c -o out/$*.obj out/%.obj : %.cpp Makefile diff --git a/apps/shell/shell.c b/apps/shell/shell.c new file mode 100644 index 0000000..5c79966 --- /dev/null +++ b/apps/shell/shell.c @@ -0,0 +1,11 @@ +#include +#include "../include/syscall.h" + +int main(){ + syscall_g_clean(); + printf("CoolPotOS UserShell v0.0.1\n"); + while (1){ + + } + return 0; +} \ No newline at end of file diff --git a/src/fs/fat.c b/src/fs/fat.c index 801e9ca..8eea678 100644 --- a/src/fs/fat.c +++ b/src/fs/fat.c @@ -25,6 +25,7 @@ static inline int get_fat_time(unsigned short hour, unsigned short minute) { time |= (minute & 0x3f) << 5; return time; } + void read_fat(unsigned char *img, int *fat, unsigned char *ff, int max, int type) { if (type == 12) { diff --git a/src/fs/vfs.c b/src/fs/vfs.c index b9548da..7155b61 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -9,9 +9,9 @@ #include "../include/fat.h" #include "../include/iso9660.h" +char root_disk = 'A'; vfs_t vfsstl[26]; vfs_t vfsMount_Stl[26]; -vfs_t *vfs_now; bool hasFS; static vfs_t *drive2fs(uint8_t drive) { @@ -24,7 +24,7 @@ static vfs_t *drive2fs(uint8_t drive) { } static vfs_t *ParsePath(char *result) { - vfs_t *vfs_result = vfs_now; + vfs_t *vfs_result = get_current()->vfs_now; if (result[1] == ':') { if (!(vfs_result = drive2fs(result[0]))) { printf("Mount Drive is not found!\n"); @@ -154,7 +154,7 @@ uint32_t vfs_filesize(char *filename) { List *vfs_listfile(char *dictpath) { // dictpath == "" 则表示当前路径 if (strcmp(dictpath, "") == 0) { - return vfs_now->ListFile(vfs_now, dictpath); + return get_current()->vfs_now->ListFile(get_current()->vfs_now, dictpath); } else { char *new_path = kmalloc(strlen(dictpath) + 1); strcpy(new_path, dictpath); @@ -188,7 +188,7 @@ bool vfs_change_path(char *dictName) { memcpy(buf, dictName, strlen(dictName) + 1); int i = 0; if (buf[i] == '/' || buf[i] == '\\') { - if (!vfs_now->cd(vfs_now, "/")) { + if (!get_current()->vfs_now->cd(get_current()->vfs_now, "/")) { kfree(r); return false; } @@ -199,14 +199,14 @@ bool vfs_change_path(char *dictName) { for (;; i++) { if (buf[i] == '/' || buf[i] == '\\') { buf[i] = 0; - if (!vfs_now->cd(vfs_now, buf)) { + if (!get_current()->vfs_now->cd(get_current()->vfs_now, buf)) { kfree(r); return false; } buf += strlen(buf) + 1; } if (buf[i] == 0) { - if (!vfs_now->cd(vfs_now, buf)) { + if (!get_current()->vfs_now->cd(get_current()->vfs_now, buf)) { kfree(r); return false; } @@ -329,15 +329,15 @@ vfs_file *get_cur_file(char* filename){ return file; } -bool vfs_change_disk(uint8_t drive) { - if (vfs_now != NULL) { - while (FindForCount(1, vfs_now->path) != NULL) { - kfree(FindForCount(vfs_now->path->ctl->all, vfs_now->path)->val); - DeleteVal(vfs_now->path->ctl->all, vfs_now->path); +bool vfs_change_disk(struct task_struct *task,uint8_t drive) { + if (task->vfs_now != NULL) { + while (FindForCount(1, task->vfs_now->path) != NULL) { + kfree(FindForCount(task->vfs_now->path->ctl->all, task->vfs_now->path)->val); + DeleteVal(task->vfs_now->path->ctl->all, task->vfs_now->path); } - kfree(vfs_now->cache); - DeleteList(vfs_now->path); - kfree(vfs_now); + kfree(task->vfs_now->cache); + DeleteList(task->vfs_now->path); + kfree(task->vfs_now); } vfs_t *f; @@ -345,11 +345,11 @@ bool vfs_change_disk(uint8_t drive) { return false; // 没有mount } - vfs_now = kmalloc(sizeof(vfs_t)); - memcpy(vfs_now, f, sizeof(vfs_t)); - f->CopyCache(vfs_now, f); - vfs_now->path = NewList(); - vfs_now->cd(vfs_now, "/"); + task->vfs_now = kmalloc(sizeof(vfs_t)); + memcpy(task->vfs_now, f, sizeof(vfs_t)); + f->CopyCache(task->vfs_now, f); + task->vfs_now->path = NewList(); + task->vfs_now->cd(task->vfs_now, "/"); return true; } @@ -357,12 +357,12 @@ void vfs_getPath(char *buffer) { char *path; List *l; buffer[0] = 0; - insert_char(buffer, 0, vfs_now->drive); + insert_char(buffer, 0, get_current()->vfs_now->drive); insert_char(buffer, 1, ':'); insert_char(buffer, 2, '\\'); int pos = strlen(buffer); - for (int i = 1; FindForCount(i, vfs_now->path) != NULL; i++) { - l = FindForCount(i, vfs_now->path); + for (int i = 1; FindForCount(i, get_current()->vfs_now->path) != NULL; i++) { + l = FindForCount(i, get_current()->vfs_now->path); path = (char *)l->val; insert_str(buffer, path, pos); pos += strlen(path); @@ -378,8 +378,8 @@ void vfs_getPath_no_drive(char *buffer) { buffer[0] = 0; int pos = strlen(buffer); int i; - for (i = 1; FindForCount(i, vfs_now->path) != NULL; i++) { - l = FindForCount(i, vfs_now->path); + for (i = 1; FindForCount(i, get_current()->vfs_now->path) != NULL; i++) { + l = FindForCount(i, get_current()->vfs_now->path); path = (char *)l->val; insert_char(buffer, pos, '/'); pos++; @@ -401,7 +401,7 @@ void init_vfs() { vfsMount_Stl[i].drive = 0; // PDEBUG("Set vfsstl[%d] & vfsMount_Stl[%d] OK.", i, i); } - vfs_now = NULL; + get_current()->vfs_now = NULL; klogf(true,"Virtual File System initialize.\n"); Register_fat_fileSys(); init_iso9660(); diff --git a/src/include/common.h b/src/include/common.h index f4c8a5d..0ca613c 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -2,7 +2,7 @@ #define CRASHPOWEROS_COMMON_H #define OS_NAME "CoolPotOS" -#define OS_VERSION "v0.2.9" +#define OS_VERSION "v0.3.0" // b 0x211972 // b 0x20d0a6 diff --git a/src/include/syscall.h b/src/include/syscall.h index 8c1db53..d590426 100644 --- a/src/include/syscall.h +++ b/src/include/syscall.h @@ -11,6 +11,7 @@ #define SYSCALL_MALLOC 4 #define SYSCALL_FREE 5 #define SYSCALL_EXIT 6 +#define SYSCALL_G_CLEAN 7 void syscall_install(); diff --git a/src/include/task.h b/src/include/task.h index ee06294..53cf7b6 100644 --- a/src/include/task.h +++ b/src/include/task.h @@ -43,6 +43,7 @@ struct task_struct { void *stack; // 进程的内核栈地址 header_t *head; // 进程堆 header_t *tail; + vfs_t *vfs_now; // 文件路径焦点 bool isUser; // 是否是用户进程 uint32_t program_break; // 进程堆基址 uint32_t program_break_end; // 进程堆尾 diff --git a/src/include/vfs.h b/src/include/vfs.h index 4597cd0..cc50470 100644 --- a/src/include/vfs.h +++ b/src/include/vfs.h @@ -67,7 +67,10 @@ bool vfs_renamefile(char *filename, char *filename_of_new); bool vfs_attrib(char *filename, ftype type); bool vfs_format(uint8_t disk_number, char *FSName); vfs_file *vfs_fileinfo(char *filename); -bool vfs_change_disk(uint8_t drive); + +#include "task.h" + +bool vfs_change_disk(struct task_struct *task,uint8_t drive); bool vfs_register_fs(vfs_t vfs); void init_vfs(); vfs_file *get_cur_file(char* filename); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3ae5ad5..2c4504f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -116,7 +116,9 @@ void kernel_main(multiboot_t *multiboot) { } hasFS = false; if(disk_id != '0'){ - if(vfs_change_disk(disk_id)){ + if(vfs_change_disk(get_current(),disk_id)){ + extern char root_disk; + root_disk = disk_id; klogf(true,"Chang default mounted disk.\n"); hasFS = true; } @@ -135,13 +137,13 @@ void kernel_main(multiboot_t *multiboot) { clock_sleep(25); - vfs_change_path("apps"); - //klogf(user_process("service.bin","Service") != -1,"Service base process init.\n"); - klogf(user_process("init.bin","Init") != -1,"Init base process init.\n"); + //vfs_change_path("apps"); + //klogf(user_process("shell.bin","Shell") != -1,"Shell process init.\n"); + //klogf(user_process("init.bin","Init") != -1,"Init base process init.\n"); - //int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell"); - //klogf(pid != -1,"Launch kernel shell.\n"); - //kernel_thread(check_task,&pid,"CPOS-CK"); + int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell"); + klogf(pid != -1,"Launch kernel shell.\n"); + kernel_thread(check_task,&pid,"CPOS-CK"); //panic_pane("System out of memory error!",OUT_OF_MEMORY); diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 99cee4b..70b38e2 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -37,6 +37,10 @@ static void syscall_free(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uin use_free(get_current(),ebx); } +static void syscall_g_clean(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ + screen_clear(); +} + void *sycall_handlers[MAX_SYSCALLS] = { [SYSCALL_PUTC] = syscall_puchar, [SYSCALL_PRINT] = syscall_print, @@ -44,6 +48,7 @@ void *sycall_handlers[MAX_SYSCALLS] = { [SYSCALL_MALLOC] = syscall_malloc, [SYSCALL_FREE] = syscall_free, [SYSCALL_EXIT] = syscall_exit, + [SYSCALL_G_CLEAN] = syscall_g_clean, }; typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t); diff --git a/src/kernel/task.c b/src/kernel/task.c index ece4bc4..0d77e23 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -216,6 +216,9 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 new_task->name = name; new_task->isUser = 1; + extern char root_disk; + vfs_change_disk(new_task,root_disk); + io_sti(); page_switch(page); diff --git a/src/sysapp/shell.c b/src/sysapp/shell.c index 4775e08..c5b0601 100644 --- a/src/sysapp/shell.c +++ b/src/sysapp/shell.c @@ -303,7 +303,7 @@ void cmd_disk(int argc, char **argv) { return; } if(have_vdisk(argv[2][0])){ - vfs_change_disk(argv[2][0]); + vfs_change_disk(get_current(),argv[2][0]); } else printf("[DISK]: Cannot found disk.\n"); return; } @@ -386,6 +386,9 @@ void setup_shell() { int argc = -1; char *buffer[255]; + extern char root_disk; + vfs_change_disk(get_current(),root_disk); + while (1) { if(hasFS) vfs_getPath(buffer); else{