Get VFS workng and start on fputc. Debugger is currently broken :(
This commit is contained in:
parent
fb61bb2806
commit
7974c1e026
26
.gdbinit
26
.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
|
||||
|
2
Makefile
2
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
|
||||
|
12
file
Normal file
12
file
Normal 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 (<unknown process>)
|
BIN
fsdrv/fsdrv
BIN
fsdrv/fsdrv
Binary file not shown.
@ -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();
|
||||
}
|
||||
|
29
init/main.c
29
init/main.c
@ -7,6 +7,7 @@
|
||||
#include <memory.h>
|
||||
#include <tasking.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
|
@ -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);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <mailboxes.h>
|
||||
|
||||
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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
46
libc/stdio.c
46
libc/stdio.c
@ -4,7 +4,7 @@
|
||||
#include <ipc/vfs.h>
|
||||
#include <stdio.h>
|
||||
#include <tasking.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
36
vfs/main.c
36
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:
|
||||
|
Loading…
Reference in New Issue
Block a user