Added simple IPC syscalls
This commit is contained in:
@@ -9,7 +9,11 @@ enum syscall_id_t
|
|||||||
SYSCALL_YIELD,
|
SYSCALL_YIELD,
|
||||||
SYSCALL_MMAP,
|
SYSCALL_MMAP,
|
||||||
SYSCALL_MUNMAP,
|
SYSCALL_MUNMAP,
|
||||||
SYSCALL_TERMINATE_SELF
|
SYSCALL_TERMINATE_SELF,
|
||||||
|
SYSCALL_SEND,
|
||||||
|
SYSCALL_RECEIVE,
|
||||||
|
SYSCALL_OPEN_PORT,
|
||||||
|
SYSCALL_CLOSE_PORT
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
@@ -48,3 +52,11 @@ size_t mmap(syscall_arg_t location, syscall_arg_t length, syscall_arg_t flags);
|
|||||||
size_t munmap(syscall_arg_t location, syscall_arg_t length);
|
size_t munmap(syscall_arg_t location, syscall_arg_t length);
|
||||||
|
|
||||||
size_t terminate_self();
|
size_t terminate_self();
|
||||||
|
|
||||||
|
size_t send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags);
|
||||||
|
|
||||||
|
size_t receive(syscall_arg_t buffer, syscall_arg_t flags);
|
||||||
|
|
||||||
|
size_t openport(syscall_arg_t id);
|
||||||
|
|
||||||
|
size_t closeport(syscall_arg_t id);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
menuentry "Quark OS" {
|
menuentry "Quark OS" {
|
||||||
multiboot2 /apps/quark-kernel
|
multiboot2 /apps/quark-kernel
|
||||||
module2 /apps/quark-testmod
|
module2 /apps/quark-testserver
|
||||||
module2 /apps/quark-testmod
|
module2 /apps/quark-testmod
|
||||||
module2 /apps/quark-testmod
|
module2 /apps/quark-testmod
|
||||||
module2 /apps/quark-testmod
|
module2 /apps/quark-testmod
|
||||||
|
|||||||
17
src/kernel.c
17
src/kernel.c
@@ -39,6 +39,10 @@ void kernel_initialize(struct boot_info_t *boot_info)
|
|||||||
set_syscall(SYSCALL_TEST, 1, 0, test_syscall);
|
set_syscall(SYSCALL_TEST, 1, 0, test_syscall);
|
||||||
set_syscall(SYSCALL_MMAP, 3, 0, mmap);
|
set_syscall(SYSCALL_MMAP, 3, 0, mmap);
|
||||||
set_syscall(SYSCALL_MUNMAP, 2, 0, munmap);
|
set_syscall(SYSCALL_MUNMAP, 2, 0, munmap);
|
||||||
|
set_syscall(SYSCALL_SEND, 3, 0, send);
|
||||||
|
set_syscall(SYSCALL_RECEIVE, 2, 0, receive);
|
||||||
|
set_syscall(SYSCALL_OPEN_PORT, 1, 0, openport);
|
||||||
|
set_syscall(SYSCALL_CLOSE_PORT, 1, 0, closeport);
|
||||||
for(int i = 0; i < boot_info->module_count; i++)
|
for(int i = 0; i < boot_info->module_count; i++)
|
||||||
{
|
{
|
||||||
if(load_module(&boot_info->modules[i]) != S_OK)
|
if(load_module(&boot_info->modules[i]) != S_OK)
|
||||||
@@ -232,7 +236,7 @@ struct process_context_t *next_process()
|
|||||||
if(kernel.active_process != NULL)
|
if(kernel.active_process != NULL)
|
||||||
{
|
{
|
||||||
paging_load_address_space(kernel.active_process->page_table);
|
paging_load_address_space(kernel.active_process->page_table);
|
||||||
printf("entering process %08x cr3=%08x ctx=%08x.\n", kernel.active_process, kernel.active_process->page_table, kernel.active_process->ctx);
|
printf("entering process %08x cr3=%08x ctx=%08x.\n", kernel.active_process->pid, kernel.active_process->page_table, kernel.active_process->ctx);
|
||||||
return kernel.active_process->ctx;
|
return kernel.active_process->ctx;
|
||||||
}
|
}
|
||||||
panic("no processes available to enter!");
|
panic("no processes available to enter!");
|
||||||
@@ -275,10 +279,11 @@ int open_port(unsigned long id)
|
|||||||
{
|
{
|
||||||
return S_EXISTS;
|
return S_EXISTS;
|
||||||
}
|
}
|
||||||
|
printf("opening port %i -> %i\n", id, kernel.active_process->pid);
|
||||||
struct port_t *port = kmalloc(sizeof(struct port_t));
|
struct port_t *port = kmalloc(sizeof(struct port_t));
|
||||||
port->id = id;
|
port->id = id;
|
||||||
port->owner_pid = kernel.active_process->pid;
|
port->owner_pid = kernel.active_process->pid;
|
||||||
avl_insert(kernel.port_table, id, port);
|
kernel.port_table = avl_insert(kernel.port_table, id, port);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +298,8 @@ int close_port(unsigned long id)
|
|||||||
{
|
{
|
||||||
return S_INVALID_ARGUMENT;
|
return S_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
avl_remove(kernel.port_table, id);
|
printf("closing port %i attached to %i\n", id, kernel.active_process->pid);
|
||||||
|
kernel.port_table = avl_remove(kernel.port_table, id);
|
||||||
kfree(port);
|
kfree(port);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
@@ -304,6 +310,7 @@ int send_message(int recipient, struct message_t *message, int flags)
|
|||||||
int dest_type = flags & IO_RECIPIENT_TYPE;
|
int dest_type = flags & IO_RECIPIENT_TYPE;
|
||||||
if((flags & ~(IO_OP | IO_RECIPIENT_TYPE)) != 0 || dest_type >= IO_MAILBOX)
|
if((flags & ~(IO_OP | IO_RECIPIENT_TYPE)) != 0 || dest_type >= IO_MAILBOX)
|
||||||
{
|
{
|
||||||
|
printf("Invalid flags on send_message\n");
|
||||||
return S_INVALID_ARGUMENT;
|
return S_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
if(dest_type == IO_PORT)
|
if(dest_type == IO_PORT)
|
||||||
@@ -315,6 +322,7 @@ int send_message(int recipient, struct message_t *message, int flags)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
printf("Port %i does not exist\n", recipient);
|
||||||
return S_DOESNT_EXIST;
|
return S_DOESNT_EXIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,6 +333,7 @@ int send_message(int recipient, struct message_t *message, int flags)
|
|||||||
}
|
}
|
||||||
else if(dest->message_buffer != NULL)
|
else if(dest->message_buffer != NULL)
|
||||||
{
|
{
|
||||||
|
printf("Sending message directly from %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||||
struct message_t kernel_buffer;
|
struct message_t kernel_buffer;
|
||||||
memcpy(&kernel_buffer, message, sizeof(struct message_t));
|
memcpy(&kernel_buffer, message, sizeof(struct message_t));
|
||||||
kernel_buffer.sender = kernel.active_process->pid;
|
kernel_buffer.sender = kernel.active_process->pid;
|
||||||
@@ -339,6 +348,7 @@ int send_message(int recipient, struct message_t *message, int flags)
|
|||||||
}
|
}
|
||||||
else if(op_type == IO_ASYNC)
|
else if(op_type == IO_ASYNC)
|
||||||
{
|
{
|
||||||
|
printf("Queueing message from %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||||
struct message_t *queued_msg = kmalloc(sizeof(struct message_t));
|
struct message_t *queued_msg = kmalloc(sizeof(struct message_t));
|
||||||
if(queued_msg == NULL)
|
if(queued_msg == NULL)
|
||||||
{
|
{
|
||||||
@@ -350,6 +360,7 @@ int send_message(int recipient, struct message_t *message, int flags)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
printf("Queueing process %i to %i\n", kernel.active_process->pid, dest->pid);
|
||||||
queue_insert(&dest->sending_queue, kernel.active_process);
|
queue_insert(&dest->sending_queue, kernel.active_process);
|
||||||
kernel.active_process->state = PROCESS_SENDING;
|
kernel.active_process->state = PROCESS_SENDING;
|
||||||
kernel.active_process = NULL;
|
kernel.active_process = NULL;
|
||||||
|
|||||||
@@ -91,3 +91,23 @@ size_t terminate_self()
|
|||||||
{
|
{
|
||||||
return terminate_process(active_process());
|
return terminate_process(active_process());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t send(syscall_arg_t recipient, syscall_arg_t message, syscall_arg_t flags)
|
||||||
|
{
|
||||||
|
return send_message(recipient.unsigned_int, message.ptr, flags.unsigned_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t receive(syscall_arg_t buffer, syscall_arg_t flags)
|
||||||
|
{
|
||||||
|
return receive_message(buffer.ptr, flags.unsigned_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t openport(syscall_arg_t id)
|
||||||
|
{
|
||||||
|
return open_port(id.unsigned_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t closeport(syscall_arg_t id)
|
||||||
|
{
|
||||||
|
return close_port(id.unsigned_int);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user