Add syscall macros and remove mailbox IPC

This commit is contained in:
pjht 2020-07-12 14:30:16 -05:00
parent ac7cc05113
commit 679b5a3b8d
18 changed files with 580 additions and 709 deletions

View File

@ -30,7 +30,7 @@ debug: os.iso kernel/kernel.elf
@$(GDB) @$(GDB)
#gdbgui -g i386-elf-gdb --project $(CWD) #gdbgui -g i386-elf-gdb --project $(CWD)
os.iso: kernel/kernel.elf init vfs devfs initrd vga_drv initrd_drv pci os.iso: kernel/kernel.elf init # vfs devfs initrd vga_drv initrd_drv pci
@cp kernel/kernel.elf sysroot/boot @cp kernel/kernel.elf sysroot/boot
@cd initrd; tar -f ../sysroot/boot/initrd.tar -c * @cd initrd; tar -f ../sysroot/boot/initrd.tar -c *
@grub-mkrescue -o $@ sysroot >/dev/null 2>/dev/null @grub-mkrescue -o $@ sysroot >/dev/null 2>/dev/null
@ -39,27 +39,27 @@ crts: kernel/crt0.o
@cp $^ sysroot/usr/lib @cp $^ sysroot/usr/lib
init: crts libc init: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
vfs: crts libc vfs: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
devfs: crts libc devfs: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
pci: crts libc pci: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
vga_drv: crts libc vga_drv: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
initrd_drv: crts libc initrd_drv: crts libc
@cd $@ && make cd $@ && make
@cp $@/$@ initrd/$@ @cp $@/$@ initrd/$@
kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) sysroot/usr/lib/libc.a kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) sysroot/usr/lib/libc.a

View File

@ -2,7 +2,6 @@
#include <grub/text_fb_info.h> #include <grub/text_fb_info.h>
#include <ipc/vfs.h> #include <ipc/vfs.h>
#include <elf.h> #include <elf.h>
#include <mailboxes.h>
#include <memory.h> #include <memory.h>
#include <tasking.h> #include <tasking.h>
#include <stdlib.h> #include <stdlib.h>
@ -97,38 +96,38 @@ char load_task(uint32_t datapos,char* initrd) {
return 1; return 1;
} }
char load_task_devfs(uint32_t datapos) { // char load_task_devfs(uint32_t datapos) {
serial_print("load_task_devfs\n"); // serial_print("load_task_devfs\n");
FILE* initrd=fopen("/dev/initrd","r"); // FILE* initrd=fopen("/dev/initrd","r");
elf_header header; // elf_header header;
fseek(initrd,datapos,SEEK_SET); // fseek(initrd,datapos,SEEK_SET);
fread(&header,sizeof(elf_header),1,initrd); // fread(&header,sizeof(elf_header),1,initrd);
if (header.magic!=ELF_MAGIC) { // if (header.magic!=ELF_MAGIC) {
serial_print("Bad magic number\n"); // serial_print("Bad magic number\n");
return 0; // return 0;
} else { // } else {
void* cr3=new_address_space(); // void* cr3=new_address_space();
for (int i=0;i<header.pheader_ent_nm;i++) { // for (int i=0;i<header.pheader_ent_nm;i++) {
elf_pheader pheader; // elf_pheader pheader;
fseek(initrd,(header.prog_hdr)+(header.pheader_ent_sz*i)+datapos,SEEK_SET); // fseek(initrd,(header.prog_hdr)+(header.pheader_ent_sz*i)+datapos,SEEK_SET);
fread(&pheader,sizeof(elf_pheader),1,initrd); // fread(&pheader,sizeof(elf_pheader),1,initrd);
serial_print("pheader.memsz="); // serial_print("pheader.memsz=");
char str[256]; // char str[256];
hex_to_ascii(pheader.memsz,str); // hex_to_ascii(pheader.memsz,str);
serial_print(str); // serial_print(str);
serial_print("\n"); // serial_print("\n");
char* ptr=alloc_memory(((pheader.memsz)/4096)+1); // char* ptr=alloc_memory(((pheader.memsz)/4096)+1);
memset(ptr,0,pheader.memsz); // memset(ptr,0,pheader.memsz);
if (pheader.filesz>0) { // if (pheader.filesz>0) {
fseek(initrd,pheader.offset+datapos,SEEK_SET); // fseek(initrd,pheader.offset+datapos,SEEK_SET);
fread(ptr,sizeof(char),pheader.filesz,initrd); // fread(ptr,sizeof(char),pheader.filesz,initrd);
} // }
copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr); // copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr);
} // }
createTaskCr3((void*)header.entry,cr3); // createTaskCr3((void*)header.entry,cr3);
} // }
return 1; // return 1;
} // }
int main() { int main() {

Binary file not shown.

View File

@ -9,13 +9,11 @@
#include "../tasking.h" #include "../tasking.h"
#include "interrupt.h" #include "interrupt.h"
#include "address_spaces.h" #include "address_spaces.h"
#include "mailboxes.h"
#include <mailboxes.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include "serial.h" #include "serial.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/syscalls.h>
void irq_handler(registers_t* r); void irq_handler(registers_t* r);
static isr_t interrupt_handlers[256]; static isr_t interrupt_handlers[256];
@ -194,33 +192,34 @@ void isr_handler(registers_t* r) {
halt(); halt();
break; break;
case 80: case 80:
if (r->eax==1) { switch (r->eax) {
tss_stack_reset(); case SYSCALL_YIELD:
tasking_yield(r); tasking_yield(r);
// r->ds=0x23; break;
// r->ss=0x23; case SYSCALL_CREATEPROC_NEW_ADDR_SPACE:
// r->cs=0x1B;
} else if (r->eax==2) {
tasking_createTask((void*)r->ebx); tasking_createTask((void*)r->ebx);
} else if (r->eax==3) { break;
case SYSCALL_ALLOC_MEM:
serial_printf("PID %d is allocating %d pages\n",getPID(),r->ebx); serial_printf("PID %d is allocating %d pages\n",getPID(),r->ebx);
r->ebx=(uint32_t)alloc_pages(r->ebx); r->ebx=(uint32_t)alloc_pages(r->ebx);
} else if (r->eax==4) { break;
case SYSCALL_ALLOC_MEM_VIRT:
alloc_pages_virt(r->ebx,(void*)r->ecx); alloc_pages_virt(r->ebx,(void*)r->ecx);
} else if (r->eax==5) { break;
case SYSCALL_GET_ERRNO_ADDR:
r->ebx=(uint32_t)tasking_get_errno_address(); r->ebx=(uint32_t)tasking_get_errno_address();
} else if (r->eax==6) { break;
kernel_mailbox_get_msg(r->ebx,(Message*)r->ecx,r->edx); case SYSCALL_NEW_ADDR_SPACE:
} else if (r->eax==7) {
kernel_mailbox_send_msg((Message*)r->ebx);
} else if (r->eax==8) {
r->ebx=(uint32_t)paging_new_address_space(); r->ebx=(uint32_t)paging_new_address_space();
} else if (r->eax==9) { break;
case SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE:
tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,0,0,0,0); tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,0,0,0,0);
} else if (r->eax==10) { break;
case SYSCALL_ADDR_SPACES_COPY_DATA:
serial_printf("address_spaces_copy_data(0x%x,0x%x,0x%x,0x%x);\n",(void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi); serial_printf("address_spaces_copy_data(0x%x,0x%x,0x%x,0x%x);\n",(void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi);
address_spaces_copy_data((void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi); address_spaces_copy_data((void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi);
} else if (r->eax==11) { break;
case SYSCALL_PRIV_MAP_PAGES:
if (!currentTask->priv) { if (!currentTask->priv) {
r->ebx=0; r->ebx=0;
return; return;
@ -228,32 +227,41 @@ void isr_handler(registers_t* r) {
void* virt_addr=find_free_pages(r->ecx); void* virt_addr=find_free_pages(r->ecx);
map_pages(virt_addr,(void*)r->ebx,r->ecx,1,1); map_pages(virt_addr,(void*)r->ebx,r->ecx,1,1);
r->ebx=(uint32_t)virt_addr; r->ebx=(uint32_t)virt_addr;
} else if (r->eax==12) { break;
case SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS:
tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,1,r->edx,1,r->esi); tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,1,r->edx,1,r->esi);
} else if (r->eax==13) { break;
case SYSCALL_ADDR_SPACES_PUT_DATA:
r->ebx=(uint32_t)address_spaces_put_data((void*)r->ebx,(void*)r->ecx,r->edx); r->ebx=(uint32_t)address_spaces_put_data((void*)r->ebx,(void*)r->ecx,r->edx);
} else if (r->eax==14) { break;
r->ebx=kernel_mailbox_new((uint16_t)r->ebx,(char*)r->ecx); case SYSCALL_YIELD_TO_PID:
} else if (r->eax==15) {
tasking_yieldToPID(r->ebx); tasking_yieldToPID(r->ebx);
} else if (r->eax==16) { break;
case SYSCALL_SERIAL_PRINT:
serial_write_string((char*)r->ebx); serial_write_string((char*)r->ebx);
} else if (r->eax==17) { break;
case SYSCALL_EXIT:
tasking_exit((uint8_t)r->ebx); tasking_exit((uint8_t)r->ebx);
} else if (r->eax==18) { break;
case SYSCALL_GET_INITRD_SZ:
serial_printf("Initrd size is %d bytes\n",initrd_sz); serial_printf("Initrd size is %d bytes\n",initrd_sz);
r->ebx=initrd_sz; r->ebx=initrd_sz;
} else if (r->eax==19) { break;
case SYSCALL_COPY_INITRD:
serial_printf("Copying initrd\n"); serial_printf("Copying initrd\n");
memcpy((char*)r->ebx,initrd,initrd_sz); memcpy((char*)r->ebx,initrd,initrd_sz);
} else if (r->eax==20) { break;
case SYSCALL_GET_PID:
r->ebx=(pid_t)getPID(); r->ebx=(pid_t)getPID();
} else if (r->eax==21) { break;
r->ebx=kernel_mailbox_find_by_name((char*)r->ebx); case SYSCALL_BLOCK:
} else if (r->eax==22) {
tasking_block(r->ebx); tasking_block(r->ebx);
} else if (r->eax==23) { break;
case SYSCALL_UNBLOCK:
tasking_unblock(r->ebx); tasking_unblock(r->ebx);
break;
default:
break;
} }
break; break;
} }

View File

@ -1,120 +0,0 @@
#include "mailboxes.h"
#include "kmalloc.h"
#include <string.h>
#include <stdint.h>
#include <mailboxes.h>
#include "serial.h"
#include "paging.h"
#include "pmem.h"
#include "../tasking.h"
Mailbox* mailboxes=(Mailbox*)0xF6400000;
uint32_t next_box=1;
uint32_t kernel_mailbox_new(uint16_t size,char* name) {
if (next_box==262144) {
serial_printf("Attempted to create a mailbox, but failed\n");
return 0xFFFFFFFF;
}
mailboxes[next_box].rd=0;
mailboxes[next_box].wr=0;
mailboxes[next_box].size=size;
mailboxes[next_box].msg_store=kmalloc(sizeof(Message)*size);
if (strlen(name)>19) {
name[20]='\0';
}
strcpy(mailboxes[next_box].name,name);
serial_printf("PID %d created mailbox %s\n",getPID(),mailboxes[next_box].name);
next_box++;
return next_box-1;
}
void kernel_mailbox_free(uint32_t box) {
kfree(mailboxes[box].msg_store);
}
void kernel_mailbox_send_msg(Message* user_msg) {
if (user_msg->to==0) {
serial_printf("Box %s attempted to send to box 0!\n",mailboxes[user_msg->from].name);
return;
}
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);
map_pages(virt_addr,phys_addr,num_pages,0,1);
serial_printf("Mapped into vmem\n");
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;
mailbox.msg_store[mailbox.wr].size=user_msg->size;
mailbox.wr++;
if (mailbox.wr==mailbox.size) {
mailbox.wr=0;
}
if (mailbox.wr==mailbox.rd) {
mailbox.wr--;
if (mailbox.wr==(2^32)-1) {
mailbox.wr=mailbox.size-1;
}
}
mailboxes[user_msg->to]=mailbox;
serial_printf("Message sent from box %s to box %s\n",mailboxes[user_msg->from].name,mailboxes[user_msg->to].name);
}
void kernel_mailbox_get_msg(uint32_t box, Message* recv_msg, uint32_t buffer_sz) {
Mailbox mailbox=mailboxes[box];
if (mailbox.msg_store[mailbox.rd].from==0) {
recv_msg->size=0;
recv_msg->from=0;
serial_printf("Box %s attempted to get a message, but there were none.\n",mailboxes[box].name);
mailboxes[box]=mailbox;
return;
}
recv_msg->from=mailbox.msg_store[mailbox.rd].from;
recv_msg->to=mailbox.msg_store[mailbox.rd].to;
recv_msg->size=mailbox.msg_store[mailbox.rd].size;
if (buffer_sz<mailbox.msg_store[mailbox.rd].size) {
recv_msg->size=mailbox.msg_store[mailbox.rd].size;
recv_msg->from=0;
serial_printf("Box %s attempted to get the message from box %s, but the buffer was too small.\n",mailboxes[box].name,mailboxes[mailbox.msg_store[mailbox.rd].from].name);
serial_printf("Expected message at most %d big, but got message sized %d.\n",buffer_sz,mailbox.msg_store[mailbox.rd].size);
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;
mailbox.rd++;
if (mailbox.rd==mailbox.size) {
mailbox.rd=0;
}
if (mailbox.rd>mailbox.wr && !(orig_rd>mailbox.wr)) {
mailbox.rd=mailbox.wr;
}
serial_printf("Box %s got a message from box %s.\n",mailboxes[box].name,mailboxes[recv_msg->from].name);
mailboxes[box]=mailbox;
}
uint32_t kernel_mailbox_find_by_name(char* name) {
for (uint32_t i=1;i<next_box;i++) {
if (strcmp(mailboxes[i].name,name)==0) {
return i;
}
}
return 0;
}

View File

@ -1,13 +0,0 @@
#ifndef KERNEL_MAILBOXES_H
#define KERNEL_MAILBOXES_H
#include <stdint.h>
#include <mailboxes.h>
uint32_t kernel_mailbox_new(uint16_t size,char* name);
void kernel_mailbox_free(uint32_t box);
void kernel_mailbox_send_msg(Message* user_msg);
void kernel_mailbox_get_msg(uint32_t box, Message* recv_msg, uint32_t buffer_sz);
uint32_t kernel_mailbox_find_by_name(char* name);
#endif

8
kernel/rpc.c Normal file
View File

@ -0,0 +1,8 @@
#include "cpu/tasking.h"
#include <string.h>
#include "rpc.h"
void rpc_init_struct(TaskRPCStruct* info) {
info->pendingrpc = 0;
info->callingpid = 0;
}

17
kernel/rpc.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef RPC_H
#define RPC_H
typedef struct RPCFuncInfo {
char name[32];
char* (*code)(char*);
} RPCFuncInfo;
typedef struct TaskRPCStruct {
int pendingrpc;
int callingpid;
} TaskRPCStruct;
void rpc_init_struct(TaskRPCStruct* info);
#endif

View File

@ -1,7 +1,12 @@
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
int* __get_errno_address() { int* __get_errno_address() {
int* address; int* address;
asm volatile(" \ asm volatile(" \
mov $5, %%eax; \ mov $" QU(SYSCALL_GET_ERRNO_ADDR) ", %%eax; \
int $80; \ int $80; \
":"=b"(address):); ":"=b"(address):);
return address; return address;

View File

@ -1,7 +1,12 @@
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
long initrd_sz() { long initrd_sz() {
long size; long size;
asm volatile(" \ asm volatile(" \
mov $18, %%eax; \ mov $" QU(SYSCALL_GET_INITRD_SZ) ", %%eax; \
int $80; \ int $80; \
":"=b"(size)); ":"=b"(size));
return size; return size;
@ -9,7 +14,7 @@ long initrd_sz() {
void initrd_get(char* initrd) { void initrd_get(char* initrd) {
asm volatile(" \ asm volatile(" \
mov $19, %%eax; \ mov $" QU(SYSCALL_COPY_INITRD) ", %%eax; \
int $80; \ int $80; \
"::"b"(initrd)); "::"b"(initrd));
} }

View File

@ -1,35 +0,0 @@
#include <stdint.h>
#include <mailboxes.h>
uint32_t mailbox_new(uint16_t size,char* name) {
uint32_t box;
asm volatile(" \
mov $14, %%eax; \
int $80; \
":"=b"(box):"b"(size),"c"(name));
return box;
}
void mailbox_send_msg(Message* msg) {
asm volatile(" \
mov $7, %%eax; \
int $80; \
"::"b"(msg));
}
void mailbox_get_msg(uint32_t box, Message* recv_msg, uint32_t buffer_sz) {
asm volatile(" \
mov $6, %%eax; \
int $80; \
"::"b"(box),"c"(recv_msg),"d"(buffer_sz));
}
uint32_t mailbox_find_by_name(char* name) {
uint32_t box;
asm volatile(" \
mov $21, %%eax; \
int $80; \
":"=b"(box):"b"(name));
return box;
}

View File

@ -1,9 +1,13 @@
#include <stdint.h> #include <stdint.h>
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
void* alloc_memory(uint32_t num_pages) { void* alloc_memory(uint32_t num_pages) {
void* address; void* address;
asm volatile(" \ asm volatile(" \
mov $3, %%eax; \ mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
int $80; \ int $80; \
":"=b"(address):"b"(num_pages)); ":"=b"(address):"b"(num_pages));
return address; return address;
@ -11,7 +15,7 @@ void* alloc_memory(uint32_t num_pages) {
void alloc_memory_virt(uint32_t num_pages,void* addr) { void alloc_memory_virt(uint32_t num_pages,void* addr) {
asm volatile(" \ asm volatile(" \
mov $4, %%eax; \ mov $" QU(SYSCALL_ALLOC_MEM_VIRT) ", %%eax; \
int $80; \ int $80; \
"::"b"(num_pages),"c"(addr)); "::"b"(num_pages),"c"(addr));
} }
@ -19,7 +23,7 @@ void alloc_memory_virt(uint32_t num_pages,void* addr) {
void* new_address_space() { void* new_address_space() {
void* cr3; void* cr3;
asm volatile(" \ asm volatile(" \
mov $8, %%eax; \ mov $" QU(SYSCALL_NEW_ADDR_SPACE) ", %%eax; \
int $80; \ int $80; \
":"=b"(cr3)); ":"=b"(cr3));
return cr3; return cr3;
@ -27,7 +31,7 @@ void* new_address_space() {
void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) { void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
asm volatile(" \ asm volatile(" \
mov $10, %%eax; \ mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
int $80; \ int $80; \
"::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr)); "::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr));
} }
@ -35,7 +39,7 @@ void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
void* put_data(void* cr3, void* data,uint32_t size) { void* put_data(void* cr3, void* data,uint32_t size) {
void* virt_addr; void* virt_addr;
asm volatile(" \ asm volatile(" \
mov $13, %%eax; \ mov $" QU(SYSCALL_ADDR_SPACES_PUT_DATA) ", %%eax; \
int $80; \ int $80; \
":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size)); ":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size));
return virt_addr; return virt_addr;
@ -44,7 +48,7 @@ void* put_data(void* cr3, void* data,uint32_t size) {
void* map_phys(void* phys_addr,uint32_t num_pages) { void* map_phys(void* phys_addr,uint32_t num_pages) {
void* virt_addr; void* virt_addr;
asm volatile(" \ asm volatile(" \
mov $11, %%eax; \ mov $" QU(SYSCALL_PRIV_MAP_PAGES) ", %%eax; \
int $80; \ int $80; \
":"=b"(virt_addr):"b"(phys_addr),"c"(num_pages)); ":"=b"(virt_addr):"b"(phys_addr),"c"(num_pages));
return virt_addr; return virt_addr;

View File

@ -1,4 +1,3 @@
#include <mailboxes.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <ipc/vfs.h> #include <ipc/vfs.h>
@ -7,447 +6,447 @@
#include <dbg.h> #include <dbg.h>
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#define VFS_PID 2 // #define VFS_PID 2
static uint32_t box; // static uint32_t box;
static uint32_t vfs_box; // static uint32_t vfs_box;
FILE* __stdio_stdin; FILE* __stdio_stdin;
FILE* __stdio_stdout; FILE* __stdio_stdout;
FILE* __stdio_stderr; FILE* __stdio_stderr;
void __stdio_init() { void __stdio_init() {
char name[256]; // char name[256];
strcpy(name,"stdio"); // strcpy(name,"stdio");
int name_end_index=strlen(name); // int name_end_index=strlen(name);
char* name_end=&name[name_end_index]; // char* name_end=&name[name_end_index];
int_to_ascii(getpid(),name_end); // int_to_ascii(getpid(),name_end);
box=mailbox_new(16,name); // box=mailbox_new(16,name);
__stdio_stdin=malloc(sizeof(FILE*)); // __stdio_stdin=malloc(sizeof(FILE*));
*__stdio_stdin=0; // *__stdio_stdin=0;
__stdio_stdout=malloc(sizeof(FILE*)); // __stdio_stdout=malloc(sizeof(FILE*));
*__stdio_stdout=1; // *__stdio_stdout=1;
__stdio_stderr=malloc(sizeof(FILE*)); // __stdio_stderr=malloc(sizeof(FILE*));
*__stdio_stderr=2; // *__stdio_stderr=2;
vfs_box=mailbox_find_by_name("vfs"); // vfs_box=mailbox_find_by_name("vfs");
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("Cannot find VFS box\n"); // serial_print("Cannot find VFS box\n");
} // }
} }
static vfs_message* make_msg(vfs_message_type type,const char* mode,const char* path, uint32_t fd, int data) { // static vfs_message* make_msg(vfs_message_type type,const char* mode,const char* path, uint32_t fd, int data) {
vfs_message* msg_data=malloc(sizeof(vfs_message)); // vfs_message* msg_data=malloc(sizeof(vfs_message));
msg_data->type=type; // msg_data->type=type;
msg_data->id=0; // msg_data->id=0;
msg_data->fd=fd; // msg_data->fd=fd;
msg_data->data=data; // msg_data->data=data;
msg_data->in_progress=0; // msg_data->in_progress=0;
msg_data->orig_mbox=box; // msg_data->orig_mbox=box;
if (mode!=NULL) { // if (mode!=NULL) {
strcpy(&msg_data->mode[0],mode); // strcpy(&msg_data->mode[0],mode);
} // }
if (path!=NULL) { // if (path!=NULL) {
strcpy(&msg_data->path[0],path); // strcpy(&msg_data->path[0],path);
} // }
return msg_data; // return msg_data;
} // }
FILE* fopen(char* filename,char* mode) { // FILE* fopen(char* filename,char* mode) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return NULL; // return NULL;
} // }
if (strlen(filename)>4096 || strlen(mode)>10) { // if (strlen(filename)>4096 || strlen(mode)>10) {
return NULL; // return NULL;
} // }
vfs_message* msg_data=make_msg(VFS_OPEN,mode,filename,0,0); // vfs_message* msg_data=make_msg(VFS_OPEN,mode,filename,0,0);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(msg.msg); // free(msg.msg);
return NULL; // return NULL;
} else { // } else {
FILE* file=malloc(sizeof(FILE)); // FILE* file=malloc(sizeof(FILE));
*file=vfs_msg->fd; //We're using pointers to FILE even though it's a uint32_t so we can expand to a struct if needed // *file=vfs_msg->fd; //We're using pointers to FILE even though it's a uint32_t so we can expand to a struct if needed
free(msg.msg); // free(msg.msg);
return file; // return file;
} // }
} // }
int putc(int c, FILE* stream) __attribute__ ((alias ("fputc"))); // int putc(int c, FILE* stream) __attribute__ ((alias ("fputc")));
int fputc(int c, FILE* stream) { // int fputc(int c, FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return EOF; // return EOF;
} // }
char str[]={c,'\0'}; // char str[]={c,'\0'};
if (fputs(str,stream)==0) { // if (fputs(str,stream)==0) {
return c; // return c;
} else { // } else {
return EOF; // return EOF;
} // }
return EOF; // return EOF;
} // }
int getc(FILE* stream) __attribute__ ((alias ("fgetc"))); // int getc(FILE* stream) __attribute__ ((alias ("fgetc")));
int fgetc(FILE* stream) { // int fgetc(FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return EOF; // return EOF;
} // }
char c[2]; // char c[2];
if (fgets(&c[0],1,stream)==NULL) { // if (fgets(&c[0],1,stream)==NULL) {
return EOF; // return EOF;
} else { // } else {
return c[0]; // return c[0];
} // }
return EOF; // return EOF;
} // }
char* gets(char* s) { // char* gets(char* s) {
return fgets(s,INT_MAX,stdin); // return fgets(s,INT_MAX,stdin);
} // }
char* fgets(char* str,int count,FILE* stream) { // char* fgets(char* str,int count,FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return NULL; // return NULL;
} // }
vfs_message* msg_data=make_msg(VFS_GETS,NULL,NULL,*stream,count); // vfs_message* msg_data=make_msg(VFS_GETS,NULL,NULL,*stream,count);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(vfs_msg); // free(vfs_msg);
return NULL; // return NULL;
} else { // } else {
msg.msg=str; // msg.msg=str;
mailbox_get_msg(box,&msg,count); // mailbox_get_msg(box,&msg,count);
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,count); // mailbox_get_msg(box,&msg,count);
} // }
str[vfs_msg->data]='\0'; // str[vfs_msg->data]='\0';
free(vfs_msg); // free(vfs_msg);
return str; // return str;
} // }
free(vfs_msg); // free(vfs_msg);
return NULL; // return NULL;
} // }
size_t fread(void* buffer_ptr,size_t size,size_t count,FILE* stream) { // size_t fread(void* buffer_ptr,size_t size,size_t count,FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return 0; // return 0;
} // }
char* buffer=(char*)buffer_ptr; // char* buffer=(char*)buffer_ptr;
size_t bytes=size*count; // size_t bytes=size*count;
vfs_message* msg_data=make_msg(VFS_GETS,NULL,NULL,*stream,bytes); // vfs_message* msg_data=make_msg(VFS_GETS,NULL,NULL,*stream,bytes);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(vfs_msg); // free(vfs_msg);
return 0; // return 0;
} else { // } else {
msg.msg=buffer; // msg.msg=buffer;
mailbox_get_msg(box,&msg,bytes); // mailbox_get_msg(box,&msg,bytes);
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,bytes); // mailbox_get_msg(box,&msg,bytes);
} // }
free(vfs_msg); // free(vfs_msg);
return count; // return count;
} // }
free(vfs_msg); // free(vfs_msg);
return 0; // return 0;
} // }
int puts(const char *s) { // int puts(const char *s) {
char* str=malloc(sizeof(char)*(strlen(s)+2)); // char* str=malloc(sizeof(char)*(strlen(s)+2));
strcpy(str,s); // strcpy(str,s);
str[strlen(s)]='\n'; // str[strlen(s)]='\n';
str[strlen(s)+1]='\0'; // str[strlen(s)+1]='\0';
serial_print(str); // serial_print(str);
int code=fputs(str,stdout); // int code=fputs(str,stdout);
free(str); // free(str);
return code; // return code;
} // }
int fputs(const char* s, FILE* stream) { // int fputs(const char* s, FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return EOF; // return EOF;
} // }
vfs_message* msg_data=make_msg(VFS_PUTS,NULL,NULL,*stream,strlen(s)); // vfs_message* msg_data=make_msg(VFS_PUTS,NULL,NULL,*stream,strlen(s));
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
msg.msg=(char*)s; // msg.msg=(char*)s;
msg.size=strlen(s); // msg.size=strlen(s);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
msg.msg=msg_data; // msg.msg=msg_data;
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(msg.msg); // free(msg.msg);
return EOF; // return EOF;
} else { // } else {
free(msg.msg); // free(msg.msg);
return 0; // return 0;
} // }
free(msg.msg); // free(msg.msg);
return EOF; // return EOF;
} // }
size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream) { // size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return 0; // return 0;
} // }
char* buffer=(char*)buffer_ptr; // char* buffer=(char*)buffer_ptr;
size_t bytes=size*count; // size_t bytes=size*count;
vfs_message* msg_data=make_msg(VFS_PUTS,NULL,NULL,*stream,bytes); // vfs_message* msg_data=make_msg(VFS_PUTS,NULL,NULL,*stream,bytes);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
msg.msg=buffer; // msg.msg=buffer;
msg.size=bytes; // msg.size=bytes;
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
msg.msg=msg_data; // msg.msg=msg_data;
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(msg.msg); // free(msg.msg);
return 0; // return 0;
} else { // } else {
free(msg.msg); // free(msg.msg);
return count; // return count;
} // }
free(msg.msg); // free(msg.msg);
return 0; // return 0;
} // }
void register_fs(const char* name,uint32_t mbox) { // void register_fs(const char* name,uint32_t mbox) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return; // return;
} // }
vfs_message* msg_data=make_msg(VFS_REGISTER_FS,name,NULL,mbox,0); // vfs_message* msg_data=make_msg(VFS_REGISTER_FS,name,NULL,mbox,0);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
free(msg.msg); // free(msg.msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
msg.msg=malloc(sizeof(vfs_message)); // msg.msg=malloc(sizeof(vfs_message));
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
free(msg.msg); // free(msg.msg);
} // }
void mount(char* file,char* type,char* path) { // void mount(char* file,char* type,char* path) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return; // return;
} // }
vfs_message* msg_data=make_msg(VFS_MOUNT,type,path,0,strlen(file)+1); // vfs_message* msg_data=make_msg(VFS_MOUNT,type,path,0,strlen(file)+1);
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
msg.msg=file; // msg.msg=file;
msg.size=strlen(file)+1; // msg.size=strlen(file)+1;
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
msg.msg=msg_data; // msg.msg=msg_data;
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
free(msg.msg); // free(msg.msg);
} // }
int vfprintf(FILE* stream,const char* format,va_list arg) { // int vfprintf(FILE* stream,const char* format,va_list arg) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return EOF; // return EOF;
} // }
int c; // int c;
for(;*format!='\0';format++) { // for(;*format!='\0';format++) {
if(*format!='%') { // if(*format!='%') {
c=fputc(*format,stream); // c=fputc(*format,stream);
if (c==EOF) { // if (c==EOF) {
return EOF; // return EOF;
} // }
continue; // continue;
} // }
format++; // format++;
switch(*format) { // switch(*format) {
case 'c': { // case 'c': {
int i=va_arg(arg,int); // int i=va_arg(arg,int);
c=fputc(i,stream); // c=fputc(i,stream);
if (c==EOF) { // if (c==EOF) {
return EOF; // return EOF;
} // }
break; // break;
} // }
case 'd': { // case 'd': {
int i=va_arg(arg,int); //Fetch Decimal/Integer argument // int i=va_arg(arg,int); //Fetch Decimal/Integer argument
if(i<0) { // if(i<0) {
i=-i; // i=-i;
fputc('-',stream); // fputc('-',stream);
} // }
char str[11]; // char str[11];
int_to_ascii(i,str); // int_to_ascii(i,str);
c=fputs(str,stream); // c=fputs(str,stream);
if (c==EOF) { // if (c==EOF) {
return EOF; // return EOF;
} // }
break; // break;
} // }
// case 'o': { // // case 'o': {
// int i=va_arg(arg,unsigned int); //Fetch Octal representation // // int i=va_arg(arg,unsigned int); //Fetch Octal representation
// puts(convert(i,8)); // // puts(convert(i,8));
// break; // // break;
// } // // }
case 's': { // case 's': {
char* s=va_arg(arg,char*); // char* s=va_arg(arg,char*);
c=fputs(s,stream); // c=fputs(s,stream);
if (c==EOF) { // if (c==EOF) {
return EOF; // return EOF;
} // }
break; // break;
} // }
case 'x': { // case 'x': {
uint32_t i=va_arg(arg,uint32_t); // uint32_t i=va_arg(arg,uint32_t);
char str[11]; // char str[11];
str[0]='\0'; // str[0]='\0';
hex_to_ascii(i,str); // hex_to_ascii(i,str);
c=fputs(str,stream); // c=fputs(str,stream);
if (c==EOF) { // if (c==EOF) {
return EOF; // return EOF;
} // }
break; // break;
} // }
} // }
} // }
return 1; // return 1;
} // }
int fprintf(FILE* stream,const char* format,...) { // int fprintf(FILE* stream,const char* format,...) {
va_list arg; // va_list arg;
int code; // int code;
va_start(arg,format); // va_start(arg,format);
code=vfprintf(stream,format,arg); // code=vfprintf(stream,format,arg);
va_end(arg); // va_end(arg);
if (code) { // if (code) {
return strlen(format); // return strlen(format);
} else { // } else {
return EOF; // return EOF;
} // }
} // }
int printf(const char* format,...) { // int printf(const char* format,...) {
va_list arg; // va_list arg;
int code; // int code;
va_start(arg,format); // va_start(arg,format);
code=vfprintf(stdout,format,arg); // code=vfprintf(stdout,format,arg);
va_end(arg); // va_end(arg);
if (code) { // if (code) {
return strlen(format); // return strlen(format);
} else { // } else {
return EOF; // return EOF;
} // }
} // }
int fseek(FILE* stream,long offset,int origin) { // int fseek(FILE* stream,long offset,int origin) {
if (vfs_box==0) { // if (vfs_box==0) {
serial_print("The VFS box has not been found\n"); // serial_print("The VFS box has not been found\n");
return -1; // return -1;
} // }
vfs_message* msg_data=make_msg(VFS_SEEK,NULL,NULL,*stream,origin); // vfs_message* msg_data=make_msg(VFS_SEEK,NULL,NULL,*stream,origin);
msg_data->pos=offset; // msg_data->pos=offset;
Message msg; // Message msg;
msg.from=box; // msg.from=box;
msg.to=vfs_box; // msg.to=vfs_box;
msg.msg=msg_data; // msg.msg=msg_data;
msg.size=sizeof(vfs_message); // msg.size=sizeof(vfs_message);
mailbox_send_msg(&msg); // mailbox_send_msg(&msg);
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
while (msg.from==0) { // while (msg.from==0) {
yieldToPID(VFS_PID); // yieldToPID(VFS_PID);
mailbox_get_msg(box,&msg,sizeof(vfs_message)); // mailbox_get_msg(box,&msg,sizeof(vfs_message));
} // }
vfs_message* vfs_msg=(vfs_message*)msg.msg; // vfs_message* vfs_msg=(vfs_message*)msg.msg;
if (vfs_msg->flags) { // if (vfs_msg->flags) {
free(vfs_msg); // free(vfs_msg);
return -1; // return -1;
} else { // } else {
free(vfs_msg); // free(vfs_msg);
return 0; // return 0;
} // }
} // }
void rescan_vfs() { // void rescan_vfs() {
vfs_box=mailbox_find_by_name("vfs"); // vfs_box=mailbox_find_by_name("vfs");
} // }

View File

@ -1,38 +1,35 @@
#include <stdint.h> #include <stdint.h>
#include <tasking.h> #include <tasking.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
void yield() { void yield() {
asm volatile(" \ asm volatile(" \
mov $1, %eax; \ mov $" QU(SYSCALL_YIELD) ", %eax; \
int $80; \ int $80; \
"); ");
} }
void createTask(void* task) {
asm volatile(" \
mov $2, %%eax; \
int $80; \
"::"b"(task));
}
void createTaskCr3(void* task,void* cr3) { void createTaskCr3(void* task,void* cr3) {
asm volatile(" \ asm volatile(" \
mov $9, %%eax; \ mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE) ", %%eax; \
int $80; \ int $80; \
"::"b"(task),"c"(cr3)); "::"b"(task),"c"(cr3));
} }
void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2) { void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2) {
asm volatile(" \ asm volatile(" \
mov $12, %%eax; \ mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS) ", %%eax; \
int $80; \ int $80; \
"::"b"(task),"c"(cr3),"d"(param1),"S"(param2)); "::"b"(task),"c"(cr3),"d"(param1),"S"(param2));
} }
void yieldToPID(uint32_t pid) { void yieldToPID(uint32_t pid) {
asm volatile(" \ asm volatile(" \
mov $15, %%eax; \ mov $" QU(SYSCALL_YIELD_TO_PID) ", %%eax; \
int $80; \ int $80; \
"::"b"(pid)); "::"b"(pid));
} }
@ -40,7 +37,7 @@ void yieldToPID(uint32_t pid) {
__attribute__((noreturn)) void exit(int code) { __attribute__((noreturn)) void exit(int code) {
code=code&0xff; code=code&0xff;
asm volatile(" \ asm volatile(" \
mov $17, %%eax; \ mov $" QU(SYSCALL_EXIT) ", %%eax; \
int $80; \ int $80; \
"::"b"(code)); "::"b"(code));
for(;;); for(;;);
@ -49,14 +46,14 @@ __attribute__((noreturn)) void exit(int code) {
void blockTask(TaskState state) { void blockTask(TaskState state) {
asm volatile(" \ asm volatile(" \
mov $22, %%eax; \ mov $" QU(SYSCALL_BLOCK) ", %%eax; \
int $80; \ int $80; \
"::"b"(state)); "::"b"(state));
} }
void unblockTask(pid_t pid) { void unblockTask(pid_t pid) {
asm volatile(" \ asm volatile(" \
mov $23, %%eax; \ mov $" QU(SYSCALL_UNBLOCK) ", %%eax; \
int $80; \ int $80; \
"::"b"(pid)); "::"b"(pid));
} }

BIN
pci/pci

Binary file not shown.

View File

@ -1,26 +0,0 @@
#ifndef MAILBOXES_H
#define MAILBOXES_H
#include <stdint.h>
typedef struct {
void* msg;
uint32_t from;
uint32_t to;
uint32_t size;
} Message;
typedef struct {
uint32_t rd;
uint32_t wr;
uint16_t size;
Message* msg_store;
char name[20];
} Mailbox;
uint32_t mailbox_new(uint16_t size,char* name);
void mailbox_send_msg(Message* msg);
void mailbox_get_msg(uint32_t box, Message* recv_msg, uint32_t buffer_sz);
uint32_t mailbox_find_by_name(char* name);
#endif

View File

@ -0,0 +1,24 @@
#ifndef SYSCALLS_H
#define SYSCALLS_H
#define SYSCALL_YIELD 1
#define SYSCALL_CREATEPROC_NEW_ADDR_SPACE 2
#define SYSCALL_ALLOC_MEM 3
#define SYSCALL_ALLOC_MEM_VIRT 4
#define SYSCALL_GET_ERRNO_ADDR 5
#define SYSCALL_NEW_ADDR_SPACE 8
#define SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE 9
#define SYSCALL_ADDR_SPACES_COPY_DATA 10
#define SYSCALL_PRIV_MAP_PAGES 11
#define SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS 12
#define SYSCALL_ADDR_SPACES_PUT_DATA 13
#define SYSCALL_YIELD_TO_PID 15
#define SYSCALL_SERIAL_PRINT 16
#define SYSCALL_EXIT 17
#define SYSCALL_GET_INITRD_SZ 18
#define SYSCALL_COPY_INITRD 19
#define SYSCALL_GET_PID 20
#define SYSCALL_BLOCK 22
#define SYSCALL_UNBLOCK 23
#endif

View File

@ -16,7 +16,6 @@ typedef enum TaskState {
void yield(); void yield();
void yieldToPID(uint32_t pid); void yieldToPID(uint32_t pid);
void createTask(void* task);
void createTaskCr3(void* task,void* cr3); void createTaskCr3(void* task,void* cr3);
void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2); void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2);
char isPrivleged(uint32_t pid); char isPrivleged(uint32_t pid);