From 1c5a986e6dde123baa5a82e721bc245b9d3ad2d1 Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 20 Oct 2019 09:44:33 -0500 Subject: [PATCH] Start work on an initrd driver and attempt to debug pg fault on msg send --- Makefile | 6 +- devfs/main.c | 74 ++++++++++++++--- init/main.c | 41 +++++++++- initrd_drv/Makefile | 13 +++ initrd_drv/initrd_drv | Bin 0 -> 34492 bytes initrd_drv/main.c | 147 ++++++++++++++++++++++++++++++++++ kernel/cpu/i386/cpu_init.c | 2 +- kernel/cpu/i386/isr.c | 4 + kernel/cpu/i386/mailboxes.c | 14 ++-- kernel/cpu/i386/paging.c | 22 +++++ kernel/cpu/i386/paging.h | 2 + kernel/cpu/i386/tasking.c | 5 +- sysroot/usr/include/ipc/vfs.h | 6 +- 13 files changed, 313 insertions(+), 23 deletions(-) create mode 100755 initrd_drv/initrd_drv create mode 100644 initrd_drv/main.c diff --git a/Makefile b/Makefile index d0034a8..9f2ad0e 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ debug: os.iso kernel/kernel.elf @$(GDB) #gdbgui -g i386-elf-gdb --project $(CWD) -os.iso: kernel/kernel.elf init vfs devfs initrd vga_drv pci +os.iso: kernel/kernel.elf init vfs devfs initrd vga_drv initrd_drv pci @cp kernel/kernel.elf sysroot/boot @cd initrd; tar -f ../sysroot/boot/initrd.tar -c * @grub-mkrescue -o $@ sysroot >/dev/null 2>/dev/null @@ -58,6 +58,10 @@ vga_drv: crts libc @cd $@ && make @cp $@/$@ initrd/$@ +initrd_drv: crts libc + @cd $@ && make + @cp $@/$@ initrd/$@ + kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) sysroot/usr/lib/libc.a @$(CC) -z max-page-size=4096 -Xlinker -n -T kernel/cpu/$(PLAT)/linker.ld -o $@ $(CFLAGS) -nostdlib $^ -lgcc diff --git a/devfs/main.c b/devfs/main.c index f2e21ba..724793a 100644 --- a/devfs/main.c +++ b/devfs/main.c @@ -77,6 +77,7 @@ char devfs_puts(vfs_message* vfs_msg) { msg.size=vfs_msg->data; msg.msg=data; mailbox_send_msg(&msg); + free(data); return 0; } @@ -92,18 +93,36 @@ char devfs_gets(vfs_message* vfs_msg) { } char* devfs_gets_finish(vfs_message* vfs_msg) { + char str[256]; + int_to_ascii(vfs_msg->data,str); + serial_print("gets_finish: Driver wants "); + serial_print(str); + serial_print(" bytes of gets data\n"); if (vfs_msg->flags) { return NULL; } char* gets_data=malloc(sizeof(vfs_msg->data)); Message msg; msg.msg=gets_data; - mailbox_get_msg(devfs_drv_box,&msg,vfs_msg->data); - while (msg.from==0 && msg.size==0) { - yield(); - mailbox_get_msg(devfs_drv_box,&msg,sizeof(vfs_message)); - } + int_to_ascii(vfs_msg->data,str); + serial_print("gets_finish: Driver now wants "); + serial_print(str); + serial_print(" bytes of gets data\n"); + mailbox_get_msg(devfs_drv_box,&msg,(uint32_t)vfs_msg->data); + // while (msg.from==0 && msg.size==0) { + // serial_print("Yielding to wait for data msg\n"); + // yield(); + // mailbox_get_msg(devfs_drv_box,&msg,(uint32_t)vfs_msg->data); + // } + int_to_ascii(vfs_msg->data,str); + serial_print("gets_finish: Again, driver now wants "); + serial_print(str); + serial_print(" bytes of gets data\n"); vfs_msg->flags=0; + int_to_ascii(vfs_msg->data,str); + serial_print("gets_finish: Sending "); + serial_print(str); + serial_print(" bytes of gets data\n"); return gets_data; } @@ -127,8 +146,18 @@ char devfs_mount(vfs_message* vfs_msg) { } void process_vfs_msg(vfs_message* vfs_msg, uint32_t from) { - if (vfs_msg->in_progress&2) { + char str[256]; + int_to_ascii(vfs_msg->data,str); + serial_print("vfs_msg->data="); + serial_print(str); + serial_print("\n"); + if (from!=vfs_box) { if (vfs_msg->flags) { + serial_print("vfs_msg->flags="); + char str[256]; + int_to_ascii(vfs_msg->flags,str); + serial_print(str); + serial_print("\n"); if (vfs_msg->type==VFS_OPEN) { free((void*)vfs_msg->data); } @@ -148,7 +177,13 @@ void process_vfs_msg(vfs_message* vfs_msg, uint32_t from) { vfs_msg->flags=0; break; case VFS_GETS: + int_to_ascii(vfs_msg->data,str); + serial_print("process_vfs_msg: Driver sending "); + serial_print(str); + serial_print(" bytes of gets data\n"); + serial_print("GETS_FINISH\n"); gets_data=devfs_gets_finish(vfs_msg); + serial_print("GETS_FINISH DONE\n"); break; case VFS_MOUNT: vfs_msg->flags=0; @@ -163,27 +198,42 @@ void process_vfs_msg(vfs_message* vfs_msg, uint32_t from) { msg.msg=vfs_msg; mailbox_send_msg(&msg); if (gets_data) { + serial_print("Gets data\n"); + char str[256]; + int_to_ascii(vfs_msg->data,str); + serial_print("Sending "); + serial_print(str); + serial_print(" bytes of gets data\n"); msg.size=vfs_msg->data; msg.msg=gets_data; mailbox_send_msg(&msg); + free(gets_data); + } else { + serial_print("No gets data\n"); } } } else { char send_msg; - vfs_msg->in_progress=vfs_msg->in_progress|2; switch (vfs_msg->type) { case VFS_OPEN: + serial_print("OPEN\n"); send_msg=devfs_open(vfs_msg); + serial_print("OPEN DONE\n"); break; case VFS_PUTS: + serial_print("PUTS\n"); send_msg=devfs_puts(vfs_msg); + serial_print("PUTS DONE\n"); break; case VFS_GETS: + serial_print("GETS\n"); send_msg=devfs_gets(vfs_msg); + serial_print("GETS DONE\n"); break; case VFS_MOUNT: - serial_print("Mount\n"); + serial_print("MOUNT\n"); send_msg=devfs_mount(vfs_msg); + serial_print("MOUNT DONE\n"); break; default: vfs_msg->flags=1; @@ -223,6 +273,7 @@ int main() { } else { vfs_message* vfs_msg=(vfs_message*)msg.msg; process_vfs_msg(vfs_msg,msg.from); + free(msg.msg); } mailbox_get_msg(devfs_drv_box,&msg,sizeof(vfs_message)); if (msg.from==0) { @@ -230,10 +281,13 @@ int main() { } else { vfs_message* vfs_msg=(vfs_message*)msg.msg; process_vfs_msg(vfs_msg,msg.from); + free(msg.msg); } msg.msg=malloc(sizeof(devfs_message)); mailbox_get_msg(devfs_reg_box,&msg,sizeof(devfs_message)); - if (msg.from!=0) { + if (msg.from==0) { + free(msg.msg); + } else { devfs_message* devfs_msg=(devfs_message*)msg.msg; if (num_devs==max_devs) { max_devs+=32; @@ -246,8 +300,8 @@ int main() { dev_mboxes[num_devs]=devfs_msg->mbox; dev_types[num_devs]=devfs_msg->dev_type; num_devs++; + free(msg.msg); } - free(msg.msg); yield(); } } diff --git a/init/main.c b/init/main.c index 055c538..91f300e 100644 --- a/init/main.c +++ b/init/main.c @@ -59,6 +59,11 @@ char load_task(uint32_t datapos,char* initrd) { int pos=0; elf_header header; pos=datapos; + char str[256]; + int_to_ascii(pos,str); + serial_print("POS:"); + serial_print(str); + serial_print("\n"); char* hdr_ptr=(char*)&header; for (size_t i=0;i0) { + fseek(initrd,pheader.offset+datapos,SEEK_SET); + fread(ptr,sizeof(char),pheader.memsz,initrd); + } + copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr); + } + createTaskCr3((void*)header.entry,cr3); + } + return 1; +} + + int main() { long size=initrd_sz(); char* initrd=malloc(size); @@ -103,10 +137,15 @@ int main() { datapos=find_loc("devfs",initrd); load_task(datapos,initrd); yieldToPID(3); - datapos=find_loc("vga_drv",initrd); + datapos=find_loc("initrd_drv",initrd); load_task(datapos,initrd); yieldToPID(4); mount("","devfs","/dev/"); + datapos=find_loc("vga_drv",initrd); + serial_print("Making vga task\n"); + load_task_devfs(datapos); + serial_print("Made vga task\n"); + yieldToPID(5); FILE* file; do { file=fopen("/dev/vga","w"); diff --git a/initrd_drv/Makefile b/initrd_drv/Makefile index e69de29..d0d6f7c 100644 --- a/initrd_drv/Makefile +++ b/initrd_drv/Makefile @@ -0,0 +1,13 @@ +C_SOURCES = $(wildcard *.c) +OBJ = $(C_SOURCES:.c=.o ) +CFLAGS = -Wall -g +CC = i386-myos-gcc + +initrd_drv: $(OBJ) ../libc/* + @$(CC) -o $@ $(CFLAGS) $(OBJ) + +%.o: %.c + @$(CC) $(CFLAGS) -c $< -o $@ + +clean: + @rm -rf *.o initrd_drv diff --git a/initrd_drv/initrd_drv b/initrd_drv/initrd_drv new file mode 100755 index 0000000000000000000000000000000000000000..4f1eec76f4bd36d14ae9ec6b13884212812efe6f GIT binary patch literal 34492 zcmeHwd3;pW+5f#W_srbPOp?h)!Y0EepppbvkVOy%MHV9v1($}9Ocu;$GC{CXkbn|n zDzVx%b;Gu{)mQueT5GGdh*q$#^~I$MtySI@?Ow?Sz8Cd)n>=iUy5Iok*sE@PsRZ{$h5ECr2$ zzip=*2LA*LgNDMF;`&kG@t2RwEfWpH<6O^ zDVz!+7Yaq2ntncjjHtgp()_G{m|(+N}7pXVY_Q~5tx_7x`r4A7&f zcW*uXaXenOGm?+*7f7W&3?6+~eyX)ex3vzmL%yD2T&5mPc)Z1~)70vA%3vJ@)VLmjvb z_DSLWeICik>k+bQ84h7ZG01v>ddbF{?dRQ@O`i#?%8 z6a2rMS`|T}`UMrDxQ`Rm4BhV)NHGZ7?nUFQj)O-B z#jo!y6m*6UbcLTqER@CD55%rhfd(o<3zBkOv0tjr6pP~AcN5&bjN$dnM9R(KGXTq<5>e3`pj~B{wn*c~H@$kk>oNbwu*8 zTMonud8LEgL?jQpF`83+pzbNgli!gw53=s#0qrfvv0cP2f!dI(vV6y3IW#aq#N3Ll z8i%^d?ane}lK$sr3&bNbSAJ(1e29yp&axtj7=eJNJpek(Ms{on7|{Y;ckJ{?PawFy zuDV*shM-1`m#AP_Y_mdvUM9Vc!xOct!)VAps=7l(piH=jMzb5J6gXPdoyqyh^?9-| z5DPf6j``O5RE<9=r>w#31Bo-<9>6Tbmc9wW$or@|B3_D>{TYMr8@t0XIs-hr!*7(u z?nv~3HLloOYM_=CF)lkp?;Ge^8x>jK1k?lJV<#oNToHDK4`6V9xhwpJ%x*_+HMZ=G z4grYzWwAF^Lr5d~CX=NVt3f|Nt0AvrVDDl}9PY$HRd`rc&;tk>Rr|6KwUsZgI4+z0 zao8X4I}M#-Tlg=}g+EY13uFI+1ffPbM2i5vPe@v)bq3)mQaPesEjW3NDLI`-&p#XF zJVXif+#3E1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+fDrC1eie>jTie;|AiQ9R_XaFFZ8ym6u zM_FWbdu;_)eN9|aIiOtFYt-u1j2{PTsBensYbc^Go$AcT(ziiYDq-YiU8 zZ4k%bX#8n9j`Q0Ax3kds1)cK*oHZTCH{77&%Ylg>ar{ljAFq*_4X(R_pzFuA{^>gB zpg_}cePWHpIHHljaXjEpzWj(Yh7Gk&D@~WH>E;7Xex&32hhGd$VVB^yIE9Y$s37Px z51 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VFS_PID 2 +#define DEVFS_PID 3 + +uint32_t box; +char* initrd; +long size; + +void initrd_puts(vfs_message* vfs_msg) { + char* data=malloc(sizeof(char)*vfs_msg->data); + Message msg; + msg.msg=data; + mailbox_get_msg(box,&msg,vfs_msg->data); + while (msg.from==0 && msg.size==0) { + yield(); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + } + if (msg.from==0) { + serial_print("Could not recieve fputs data from the VFS\n"); + vfs_msg->flags=2; + return; + } + free(data); + vfs_msg->flags=2; + return; +} + +char* initrd_gets(vfs_message* vfs_msg) { + char str[256]; + serial_print("File pos initrd:"); + int_to_ascii(vfs_msg->pos,str); + serial_print(str); + serial_print("\n"); + long max_data=size-vfs_msg->pos; + serial_print("max_data="); + int_to_ascii(max_data,str); + serial_print(str); + serial_print("\n"); + serial_print("Amount requested:"); + int_to_ascii(vfs_msg->data,str); + serial_print(str); + serial_print("\n"); + if (vfs_msg->data>max_data) { + serial_print("OVER\n"); + vfs_msg->flags=2; + return NULL; + } + char* data=malloc(sizeof(char)*vfs_msg->data); + for (long i=0;idata;i++) { + data[i]=(uint8_t)initrd[i+vfs_msg->pos]; + // if (iflags=0; + return data; +} + +void process_vfs_msg(vfs_message* vfs_msg, uint32_t from) { + char* gets_data; + switch (vfs_msg->type) { + case VFS_PUTS: + initrd_puts(vfs_msg); + break; + case VFS_GETS: + gets_data=initrd_gets(vfs_msg); + break; + break; + default: + vfs_msg->flags=1; + } + Message msg; + msg.to=from; + msg.from=box; + msg.size=sizeof(vfs_message); + msg.msg=vfs_msg; + serial_print("Sending message with flags of "); + char str[256]; + int_to_ascii(vfs_msg->flags,str); + serial_print(str); + serial_print("\n"); + mailbox_send_msg(&msg); + if (gets_data) { + serial_print("Amount sending:"); + char str[256]; + int_to_ascii(vfs_msg->data,str); + serial_print(str); + serial_print("\n"); + msg.size=vfs_msg->data; + msg.msg=gets_data; + mailbox_send_msg(&msg); + free(gets_data); + } +} + + +int main() { + size=initrd_sz(); + initrd=malloc(size); + initrd_get(initrd); + box=mailbox_new(16,"initrd"); + devfs_message* msg_data=malloc(sizeof(devfs_message)); + msg_data->msg_type=DEVFS_REGISTER; + msg_data->dev_type=DEV_GLOBAL; + msg_data->mbox=box; + strcpy(&msg_data->name[0],"initrd"); + Message msg; + msg.from=box; + msg.to=mailbox_find_by_name("devfs_register"); + msg.size=sizeof(devfs_message); + msg.msg=msg_data; + mailbox_send_msg(&msg); + free(msg_data); + yieldToPID(DEVFS_PID); + for (;;) { + Message msg; + msg.msg=malloc(sizeof(vfs_message)); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + if (msg.from==0) { + free(msg.msg); + } else { + vfs_message* vfs_msg=(vfs_message*)msg.msg; + process_vfs_msg(vfs_msg,msg.from); + free(vfs_msg); + yieldToPID(VFS_PID); + } + yield(); + } +} diff --git a/kernel/cpu/i386/cpu_init.c b/kernel/cpu/i386/cpu_init.c index dd855e7..78c9a8f 100644 --- a/kernel/cpu/i386/cpu_init.c +++ b/kernel/cpu/i386/cpu_init.c @@ -9,8 +9,8 @@ void cpu_init(struct multiboot_boot_header_tag* tags) { gdt_init(); isr_install(); asm volatile("sti"); + serial_init(); pmem_init(tags); paging_init(); tasking_init(); - serial_init(); } diff --git a/kernel/cpu/i386/isr.c b/kernel/cpu/i386/isr.c index 7484740..ba4840d 100644 --- a/kernel/cpu/i386/isr.c +++ b/kernel/cpu/i386/isr.c @@ -132,8 +132,12 @@ __attribute__((unused)) static char *exception_messages[] = { }; void isr_handler(registers_t r) { + if (r.int_no!=80 && r.int_no!=14) { + vga_write_string(exception_messages[r.int_no]); + } switch (r.int_no) { case 14: { + serial_write_string("PAGE FAULT\n"); uint32_t addr; asm("movl %%cr2,%0": "=r"(addr)); vga_write_string("In PID "); diff --git a/kernel/cpu/i386/mailboxes.c b/kernel/cpu/i386/mailboxes.c index a683d61..c6a77f3 100644 --- a/kernel/cpu/i386/mailboxes.c +++ b/kernel/cpu/i386/mailboxes.c @@ -40,17 +40,15 @@ void kernel_mailbox_send_msg(Message* user_msg) { } Mailbox mailbox=mailboxes[user_msg->to]; uint32_t num_pages=(user_msg->size/4096)+1; + serial_printf("Storing data in pmem\n"); void* phys_addr=pmem_alloc(num_pages); void* virt_addr=find_free_pages(num_pages); - // char* msg_data=kmalloc(user_msg->size); map_pages(virt_addr,phys_addr,num_pages,0,1); - // if (msg_data==NULL) { - // serial_print("Cannot allocate kernel msg data!\n"); - // vga_write_string("Cannot allocate kernel msg data!\n"); - // for(;;); - // } + serial_printf("Mapped into vmem\n"); + serial_printf("memcpy(%x,%x,%d)\n",virt_addr,user_msg->msg,user_msg->size); memcpy(virt_addr,user_msg->msg,user_msg->size); unmap_pages(virt_addr,num_pages); + serial_printf("Stored data in pmem\n"); mailbox.msg_store[mailbox.wr].msg=phys_addr; mailbox.msg_store[mailbox.wr].from=user_msg->from; mailbox.msg_store[mailbox.wr].to=user_msg->to; @@ -89,12 +87,16 @@ void kernel_mailbox_get_msg(uint32_t box, Message* recv_msg, uint32_t buffer_sz) mailboxes[box]=mailbox; return; } + if (buffer_sz>mailbox.msg_store[mailbox.rd].size) { + serial_printf("Warning: buffer sized for message %d big, but got message sized %d.\n",buffer_sz,mailbox.msg_store[mailbox.rd].size); + } Message msg=mailbox.msg_store[mailbox.rd]; uint32_t num_pages=(msg.size/4096)+1; void* virt_addr=find_free_pages(num_pages); map_pages(virt_addr,msg.msg,num_pages,0,1); memcpy(recv_msg->msg,virt_addr,mailbox.msg_store[mailbox.rd].size); unmap_pages(virt_addr,num_pages); + pmem_free(((uint32_t)msg.msg)>>12,num_pages); // kfree(mailbox.msg_store[mailbox.rd].msg); mailbox.msg_store[mailbox.rd].from=0; uint32_t orig_rd=mailbox.rd; diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index 648eee4..5e68f92 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -176,6 +176,28 @@ void unmap_pages(void* start_virt,uint32_t num_pages) { } } +char make_protector(int page) { + int table=page>>10; + if (is_page_present(page)) return 0; + page=page&0x3FF; + smap_page_tables[table+1]=(smap[table]&0xFFFFFC00)|0x3; + uint32_t page_val=smap[(1024+(1024*table))+page]; + page_val=page_val&(~0x6); + page_val=page_val|0x800; + smap[(1024+(1024*table))+page]=page_val; + return 1; +} + +char is_in_protector(uint32_t* addr) { + int page=((uint32_t)addr)>>12; + if (is_page_present(page)) return 0; + int table=page>>10; + page=page&0x3FF; + smap_page_tables[table+1]=(smap[table]&0xFFFFFC00)|0x3; + return smap[(1024+(1024*table))+page]&0x800; + return 1; +} + void paging_init() { for (uint32_t i=0;i>12; + make_protector(buffer_pg_num); + // uint32_t* user_stack=(uint32_t*)(((uint32_t)alloc_pages(1))+0x1000); user_stack-=2; user_stack[0]=param1; user_stack[1]=param2; diff --git a/sysroot/usr/include/ipc/vfs.h b/sysroot/usr/include/ipc/vfs.h index 3a88182..bfe251d 100644 --- a/sysroot/usr/include/ipc/vfs.h +++ b/sysroot/usr/include/ipc/vfs.h @@ -13,17 +13,17 @@ typedef enum { } vfs_message_type; typedef struct { + char flags; vfs_message_type type; uint8_t id; char mode[10]; uint32_t fd; - char path[4096]; uint32_t pos; - char flags; int data; char in_progress; uint32_t orig_mbox; void* fs_data; -} vfs_message; + char path[4096]; +} __attribute__((packed)) vfs_message; #endif