From 7974c1e02645ac58ae79f0ea16464d422e4745c9 Mon Sep 17 00:00:00 2001 From: pjht Date: Sat, 20 Jul 2019 11:03:27 -0500 Subject: [PATCH] Get VFS workng and start on fputc. Debugger is currently broken :( --- .gdbinit | 26 +++++++++++-------- Makefile | 2 +- file | 12 +++++++++ fsdrv/fsdrv | Bin 19264 -> 19872 bytes fsdrv/main.c | 3 ++- init/main.c | 29 ++++++++++----------- kernel/cpu/i386/isr.c | 37 ++++++++++++++------------- kernel/cpu/i386/mailboxes.c | 2 +- kernel/cpu/i386/paging.c | 4 +++ kernel/cpu/i386/tasking.c | 11 ++++++-- kernel/cpu/tasking.h | 1 + kernel/kernel.c | 2 +- libc/stdio.c | 46 +++++++++++++++++++++++++++++----- sysroot/usr/include/ipc/vfs.h | 3 ++- vfs/main.c | 36 +++++++++++++++++++++++--- 15 files changed, 154 insertions(+), 60 deletions(-) create mode 100644 file diff --git a/.gdbinit b/.gdbinit index deb01be..2a04306 100644 --- a/.gdbinit +++ b/.gdbinit @@ -1,17 +1,21 @@ +set pagination off target remote localhost:1234 symbol-file kernel/kernel.elf -add-symbol-file fsdrv/fsdrv -b tasking.c:120 +add-symbol-file init/init +b tasking.c:123 commands -disable breakpoints -symbol-file kernel/kernel.elf -if task->pid==2 - add-symbol-file fsdrv/fsdrv - enable breakpoints -else - enable breakpoints 1 -end -c +silent + disable breakpoints + symbol-file kernel/kernel.elf + p task->pid + if task->pid==1 + add-symbol-file init/init + enable breakpoints + else + enable breakpoints 1 + c + end + c end b main diff --git a/Makefile b/Makefile index d1fad2d..232b00d 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ run: os.iso debug: os.iso kernel/kernel.elf @$(EMU) -s $(QFLAGS) & @$(GDB) - # gdbgui -g i386-elf-gdb --project $(CWD) + #gdbgui -g i386-elf-gdb --project $(CWD) os.iso: kernel/kernel.elf init vfs fsdrv initrd/* @cp kernel/kernel.elf iso/boot diff --git a/file b/file new file mode 100644 index 0000000..4796d78 --- /dev/null +++ b/file @@ -0,0 +1,12 @@ +vfs/main.c: In function 'vfs_putc': +vfs/main.c:133:1: warning: control reaches end of non-void function [-Wreturn-type] + } + ^ +main.c: In function 'vfs_putc': +main.c:133:1: warning: control reaches end of non-void function [-Wreturn-type] + } + ^ +WARNING: Image format was not specified for 'ext2.img' and probing guessed raw. + Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted. + Specify the 'raw' format explicitly to remove the restrictions. +qemu-system-i386: terminating on signal 1 from pid 58353 () diff --git a/fsdrv/fsdrv b/fsdrv/fsdrv index 19997d6a1826cb62deff4d485add81251a6f5d8e..79ea118f0a477a7e3646e6e58c4233dc7adf714b 100755 GIT binary patch delta 7676 zcmd5=e{@vUoxktRdvD(S%FJYDl1Z8T4w3L92>~Sr2?-D&LEEV40U9MCfh3qfmQ483 zZ5?Pp83HEbb*Vq127#)qc2QXCwn~9&{n3M^XS-Wn5u=6EX-W5>$69(sv!CyM?_q-N z?)IGhW9OWC_xtA|&2aCC(pHc-mR{FmPu>NQ3#ENE!||GneKqIeHOao3 zPvSM_`f4uzY-lSu2R`=^ziK}{d%xpm(GZxu$MxP3 zeY6K&AJB!x-tYJ<7QE@Bu^wN2a*M%(f*Hsp1TxyACubXsIaH}l0YP*p3r$OxoEx1l zB0u&!2dW6>TDF!!3+~pkW zqXxCFMt_5Ev*q)Zw)f;q{k&4SHa2t$?MO4)?=ZqV8Grl4uq@F-9iqlSXOmF;G?D4C zXW#(nsBm01SOE99U!_j_Qb>J@boHxsg~>h^uNg5oo-rB+4)RfDQZ6||q$h^m@e^aX z&lvVHhfeXuYNq$F2yGt;SM3Kas!o>K03T8t6Ge z_dSJ&bb6Ps?t zetnT|z;Nm!-|Nk4dL2?b$#ZpzzC)hpQRVHgx)p^*KpMfn^rO+y`Lr!seA`@!1c>hj z{nn31NB<1?3Sa)C(9Z#BD)>|RAHCUXJ)oO-hA&%<0$R`K0D2G*=S_fK0`xB5;hR!8 z0_derM@JjRSzIP8P6Ex1?!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QTGj%_rt$hExyj2HGPWOqTR%)z{Qd`P$!{tE diff --git a/fsdrv/main.c b/fsdrv/main.c index 964d1d6..400bc3c 100644 --- a/fsdrv/main.c +++ b/fsdrv/main.c @@ -12,11 +12,12 @@ int main() { msg.msg=malloc(sizeof(vfs_message)); mailbox_get_msg(box,&msg,sizeof(vfs_message)); if (msg.from==0) { + yield(); } else { vfs_message* vfs_msg=(vfs_message*)msg.msg; msg.to=msg.from; msg.from=box; - vfs_msg->flags=13; + vfs_msg->flags=0; mailbox_send_msg(&msg); yield(); } diff --git a/init/main.c b/init/main.c index 0372fea..2baa09f 100644 --- a/init/main.c +++ b/init/main.c @@ -7,6 +7,7 @@ #include #include #include +#include typedef struct { char filename[100]; @@ -143,19 +144,6 @@ void test_vfs(char* path,uint32_t box,uint32_t fs_box) { free(msg.msg); yield(); vga_write_string("Getting fs_box message\n"); - msg.msg=malloc(sizeof(vfs_message)); - mailbox_get_msg(fs_box,&msg,sizeof(vfs_message)); - if (msg.from==0) { - vga_write_string("No message\n"); - } else { - vfs_message* vfs_msg=(vfs_message*)msg.msg; - display_msg(vfs_msg); - msg.to=msg.from; - msg.from=fs_box; - vfs_msg->flags=13; - mailbox_send_msg(&msg); - } - free(msg.msg); yield(); vga_write_string("Getting message\n"); msg.msg=malloc(sizeof(vfs_message)); @@ -175,10 +163,19 @@ int main(char* initrd, uint32_t initrd_sz) { info.width=80; info.height=25; vga_init(info); - vga_write_string("INIT"); - uint32_t datapos=find_loc("fsdrv",initrd); + vga_write_string("INIT\n"); + uint32_t datapos=find_loc("vfs",initrd); load_task(datapos,initrd); - // uint32_t box=mailbox_new(16); + yield(); + datapos=find_loc("fsdrv",initrd); + load_task(datapos,initrd); + yield(); + vga_write_string("CALLING FOPEN\n"); + FILE* file=fopen("/dev/sda","w"); + vga_write_string("FOPEN RETURNED\n"); + vga_write_string("CALLING FPUTC\n"); + fputc('a',file); + vga_write_string("FPUTC RETURNED\n"); // yield(); // // uint32_t fs_box=mailbox_new(16); // // test_vfs("/dev/sda",box,fs_box); diff --git a/kernel/cpu/i386/isr.c b/kernel/cpu/i386/isr.c index 7c0f223..199ed16 100644 --- a/kernel/cpu/i386/isr.c +++ b/kernel/cpu/i386/isr.c @@ -132,24 +132,27 @@ void isr_handler(registers_t r) { case 14: { uint32_t addr; asm("movl %%cr2,%0": "=r"(addr)); - if (r.err_code==0) { - vga_write_string("Kernel process tried to read a non-present page entry at address "); - } else if (r.err_code==1) { - vga_write_string("Kernel process tried to read a page and caused a protection fault at address "); - } else if (r.err_code==2) { - vga_write_string("Kernel process tried to write to a non-present page entry at address "); - } else if (r.err_code==3) { - vga_write_string("Kernel process tried to write a page and caused a protection fault at address "); - } else if (r.err_code==4) { - vga_write_string("User process tried to read a non-present page entry at address "); - } else if (r.err_code==5) { - vga_write_string("User process tried to read a page and caused a protection fault at address "); - } else if (r.err_code==6) { - vga_write_string("User process tried to write to a non-present page entry at address "); - } else if (r.err_code==7) { - vga_write_string("User process tried to write a page and caused a protection fault at address "); - } + vga_write_string("In PID "); char str[11]; + int_to_ascii(getPID(),str); + vga_write_string(str); + if (r.err_code==0) { + vga_write_string(", kernel process tried to read a non-present page entry at address "); + } else if (r.err_code==1) { + vga_write_string(", kernel process tried to read a page and caused a protection fault at address "); + } else if (r.err_code==2) { + vga_write_string(", kernel process tried to write to a non-present page entry at address "); + } else if (r.err_code==3) { + vga_write_string(", kernel process tried to write a page and caused a protection fault at address "); + } else if (r.err_code==4) { + vga_write_string(", user process tried to read a non-present page entry at address "); + } else if (r.err_code==5) { + vga_write_string(", user process tried to read a page and caused a protection fault at address "); + } else if (r.err_code==6) { + vga_write_string(", user process tried to write to a non-present page entry at address "); + } else if (r.err_code==7) { + vga_write_string(", user process tried to write a page and caused a protection fault at address "); + } str[0]='\0'; hex_to_ascii(addr,str); vga_write_string(str); diff --git a/kernel/cpu/i386/mailboxes.c b/kernel/cpu/i386/mailboxes.c index 2a76eee..2f4d7a0 100644 --- a/kernel/cpu/i386/mailboxes.c +++ b/kernel/cpu/i386/mailboxes.c @@ -5,7 +5,7 @@ #include Mailbox* mailboxes=(Mailbox*)0xF6400000; -uint32_t next_box=0; +uint32_t next_box=1; uint32_t kernel_mailbox_new(uint16_t size) { if (next_box==262144) { diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index f98724e..1e92e14 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -41,6 +41,10 @@ void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,ch flags=flags|((usr&1)<<2); smap[(1024+(1024*dir_entry))+table_entry]=phys_addr|flags; table_entry++; + if (table_entry==1024) { + table_entry=0; + dir_entry++; + } phys_addr+=0x1000; } } diff --git a/kernel/cpu/i386/tasking.c b/kernel/cpu/i386/tasking.c index 1ab8254..69817ab 100644 --- a/kernel/cpu/i386/tasking.c +++ b/kernel/cpu/i386/tasking.c @@ -21,6 +21,7 @@ uint32_t next_pid; Task* currentTask; static Task* headTask; +static Task* tailTask; Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg); void tasking_init(void* esp) { @@ -28,6 +29,7 @@ void tasking_init(void* esp) { next_pid=0; headTask=tasking_createTaskCr3KmodeParam(NULL,paging_new_address_space(),1,0,0,0,0); currentTask=headTask; + tailTask=headTask; } Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg) { @@ -89,8 +91,9 @@ Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1 if (next_pid>1024*32) { halt(); //Cannot ever create more than 32k tasks, as I don't currently reuse PIDs. } - if (currentTask) { - currentTask->next=task; + if (tailTask) { + tailTask->next=task; + tailTask=task; } return task; @@ -120,3 +123,7 @@ void tasking_yield(registers_t registers) { load_smap(task->cr3); switch_to_task(task); } + +uint32_t getPID() { + return currentTask->pid; +} diff --git a/kernel/cpu/tasking.h b/kernel/cpu/tasking.h index df832ed..a612354 100644 --- a/kernel/cpu/tasking.h +++ b/kernel/cpu/tasking.h @@ -9,4 +9,5 @@ void tasking_yield(); Task* tasking_createTask(void* eip); Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg); char isPrivleged(uint32_t pid); +uint32_t getPID(); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 0a59e67..1b25ea3 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -63,7 +63,7 @@ void kmain(struct multiboot_boot_header_tag* hdr) { if (tar_hdr->filename[0]=='\0') break; uint32_t size=getsize(tar_hdr->size); pos+=512; - if (strcmp(&tar_hdr->filename,"init")==0) { + if (strcmp(&tar_hdr->filename[0],"init")==0) { datapos=pos; break; } diff --git a/libc/stdio.c b/libc/stdio.c index 03cd71d..94e3119 100644 --- a/libc/stdio.c +++ b/libc/stdio.c @@ -4,7 +4,7 @@ #include #include #include -#define VFS_PID 1 +#define VFS_MBOX 3 static uint32_t box; @@ -13,14 +13,20 @@ void __stdio_init() { box=mailbox_new(16); } -static vfs_message* make_msg(vfs_message_type type, char* mode, char* path) { +static vfs_message* make_msg(vfs_message_type type, char* mode, char* path, uint32_t fd, int data) { static uint32_t id=0; vfs_message* msg_data=malloc(sizeof(vfs_message)); msg_data->type=type; msg_data->id=id; + msg_data->fd=fd; + msg_data->data=data; id++; - strcpy(&msg_data->mode[0],mode); - strcpy(&msg_data->path[0],path); + if (mode!=NULL) { + strcpy(&msg_data->mode[0],mode); + } + if (path!=NULL) { + strcpy(&msg_data->path[0],path); + } return msg_data; } @@ -28,16 +34,17 @@ FILE* fopen(char* filename,char* mode) { if (strlen(filename)>4096 || strlen(mode)>10) { return NULL; } - vfs_message* msg_data=make_msg(VFS_OPEN,mode,filename); + vfs_message* msg_data=make_msg(VFS_OPEN,mode,filename,0,0); Message msg; msg.from=box; - msg.to=VFS_PID; + msg.to=VFS_MBOX; msg.msg=msg_data; msg.size=sizeof(vfs_message); mailbox_send_msg(&msg); free(msg.msg); yield(); msg.msg=malloc(sizeof(vfs_message)); + yield(); mailbox_get_msg(box,&msg,sizeof(vfs_message)); while (msg.from==0) { yield(); @@ -54,3 +61,30 @@ FILE* fopen(char* filename,char* mode) { return file; } } + +int fputc(int c, FILE* stream) { + vfs_message* msg_data=make_msg(VFS_PUTC,0,0,*stream,c); + Message msg; + msg.from=box; + msg.to=VFS_MBOX; + msg.msg=msg_data; + msg.size=sizeof(vfs_message); + mailbox_send_msg(&msg); + free(msg.msg); + yield(); + msg.msg=malloc(sizeof(vfs_message)); + yield(); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + while (msg.from==0) { + yield(); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + } + vfs_message* vfs_msg=(vfs_message*)msg.msg; + if (vfs_msg->flags) { + free(msg.msg); + return EOF; + } else { + free(msg.msg); + return c; + } +} diff --git a/sysroot/usr/include/ipc/vfs.h b/sysroot/usr/include/ipc/vfs.h index 199430d..669c762 100644 --- a/sysroot/usr/include/ipc/vfs.h +++ b/sysroot/usr/include/ipc/vfs.h @@ -17,8 +17,9 @@ typedef struct { char mode[10]; uint32_t fd; char path[4096]; + uint32_t pos; char flags; - char data; + int data; } vfs_message; #endif diff --git a/vfs/main.c b/vfs/main.c index 95f01df..a9681c1 100644 --- a/vfs/main.c +++ b/vfs/main.c @@ -13,8 +13,9 @@ typedef struct _vfs_mapping_struct { } vfs_mapping; typedef struct { - char* mntpnt; + vfs_mapping* mntpnt; char* path; + char* mode; uint32_t pos; char error; } vfs_file; @@ -25,7 +26,7 @@ static uint32_t max_drvs; static uint32_t next_drv_indx; static vfs_mapping* head_mapping; static vfs_mapping* tail_mapping; -uint32_t* fd_tables[32768]; +vfs_file* fd_tables[32768]; uint16_t open_fds[32768]; vfs_message* get_message(Message* msg,uint32_t box) { @@ -52,7 +53,7 @@ static int vfsstrcmp(const char* s1,const char* s2) { void init_vfs() { drvs=malloc(sizeof(uint32_t)*32); - drvs[0]=2; + drvs[0]=5; drv_names=malloc(sizeof(const char**)*32); max_drvs=32; next_drv_indx=0; @@ -117,12 +118,40 @@ char vfs_fopen(vfs_message* vfs_msg,uint32_t from) { } uint16_t fd=open_fds[from]; open_fds[from]++; + fd_tables[from][fd].mntpnt=mntpnt; + fd_tables[from][fd].path=malloc(sizeof(char)*(strlen(&vfs_msg->path[0])+1)); + strcpy(fd_tables[from][fd].path,&vfs_msg->path[0]); + fd_tables[from][fd].mode=malloc(sizeof(char)*(strlen(&vfs_msg->mode[0])+1)); + strcpy(fd_tables[from][fd].mode,&vfs_msg->mode[0]); + fd_tables[from][fd].pos=0; + fd_tables[from][fd].error=0; vfs_msg->fd=fd; return 0; } return 1; } +char vfs_putc(vfs_message* vfs_msg,uint32_t from) { + uint32_t fd=vfs_msg->fd; + vfs_file file_info=fd_tables[from][fd]; + strcpy(&vfs_msg->path[0],file_info.path); + strcpy(&vfs_msg->mode[0],file_info.mode); + vfs_msg->pos=file_info.pos; + Message msg; + msg.from=1; + msg.to=file_info.mntpnt->type; + msg.size=sizeof(vfs_message); + msg.msg=vfs_msg; + mailbox_send_msg(&msg); + yield(); + vfs_msg=get_message(&msg,1); + if (vfs_msg->flags!=0) { + return vfs_msg->flags; + } + fd_tables[from][fd].pos++; + return 0; +} + int main() { init_vfs(); uint32_t box=mailbox_new(16); @@ -135,6 +164,7 @@ int main() { vfs_msg->flags=vfs_fopen(vfs_msg,msg.from); break; case VFS_PUTC: + vfs_msg->flags=vfs_putc(vfs_msg,msg.from); vfs_msg->flags=1; break; case VFS_GETC: