[project] Generate syscalls from new interface DSL

This change adds a new interface DSL for specifying objects (with
methods) and interfaces (that expose objects, and optionally have their
own methods).

Significant changes:

- Add the new scripts/definitions Python module to parse the DSL
- Add the new definitions directory containing DSL definition files
- Use cog to generate syscall-related code in kernel and libj6
- Unify ordering of pointer + length pairs in interfaces
This commit is contained in:
Justin C. Miller
2021-08-30 01:05:32 -07:00
parent 80f815c020
commit 186724e751
52 changed files with 4025 additions and 206 deletions

View File

@@ -15,7 +15,7 @@ endpoint_create(j6_handle_t *handle)
}
j6_status_t
endpoint_send(j6_handle_t handle, j6_tag_t tag, size_t len, void *data)
endpoint_send(j6_handle_t handle, uint64_t tag, const void * data, size_t data_len)
{
if (tag & j6_tag_system_flag)
return j6_err_invalid_arg;
@@ -23,28 +23,28 @@ endpoint_send(j6_handle_t handle, j6_tag_t tag, size_t len, void *data)
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
return e->send(tag, len, data);
return e->send(tag, data, data_len);
}
j6_status_t
endpoint_receive(j6_handle_t handle, j6_tag_t *tag, size_t *len, void *data)
endpoint_receive(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len)
{
if (!tag || !len || (*len && !data))
if (!tag || !data_len || !data)
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
j6_tag_t out_tag = j6_tag_invalid;
size_t out_len = *len;
j6_status_t s = e->receive(&out_tag, &out_len, data);
size_t out_len = *data_len;
j6_status_t s = e->receive(&out_tag, data, &out_len);
*tag = out_tag;
*len = out_len;
*data_len = out_len;
return s;
}
j6_status_t
endpoint_sendrecv(j6_handle_t handle, j6_tag_t *tag, size_t *len, void *data)
endpoint_sendrecv(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len)
{
if (!tag || (*tag & j6_tag_system_flag))
return j6_err_invalid_arg;
@@ -52,15 +52,15 @@ endpoint_sendrecv(j6_handle_t handle, j6_tag_t *tag, size_t *len, void *data)
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
j6_status_t status = e->send(*tag, *len, data);
j6_status_t status = e->send(*tag, data, *data_len);
if (status != j6_status_ok)
return status;
j6_tag_t out_tag = j6_tag_invalid;
size_t out_len = *len;
j6_status_t s = e->receive(&out_tag, &out_len, data);
size_t out_len = *data_len;
j6_status_t s = e->receive(&out_tag, data, &out_len);
*tag = out_tag;
*len = out_len;
*data_len = out_len;
return s;
}

View File

@@ -9,7 +9,7 @@
namespace syscalls {
j6_status_t
object_koid(j6_handle_t handle, j6_koid_t *koid)
kobject_koid(j6_handle_t handle, j6_koid_t *koid)
{
if (koid == nullptr)
return j6_err_invalid_arg;
@@ -23,7 +23,7 @@ object_koid(j6_handle_t handle, j6_koid_t *koid)
}
j6_status_t
object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
kobject_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
{
kobject *obj = get_handle<kobject>(handle);
if (!obj)
@@ -47,11 +47,11 @@ object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
}
j6_status_t
object_wait_many(j6_handle_t *handles, uint32_t count, j6_signal_t mask, j6_handle_t *handle, j6_signal_t *sigs)
kobject_wait_many(j6_handle_t * handles, size_t handles_count, uint64_t mask, j6_handle_t * handle, uint64_t * signals)
{
kutil::vector<kobject*> objects {count};
kutil::vector<kobject*> objects {uint32_t(handles_count)};
for (unsigned i = 0; i < count; ++i) {
for (unsigned i = 0; i < handles_count; ++i) {
j6_handle_t h = handles[i];
if (h == j6_handle_invalid)
continue;
@@ -62,7 +62,7 @@ object_wait_many(j6_handle_t *handles, uint32_t count, j6_signal_t mask, j6_hand
j6_signal_t current = obj->signals();
if ((current & mask) != 0) {
*sigs = current;
*signals = current;
*handle = h;
return j6_status_ok;
}
@@ -81,9 +81,9 @@ object_wait_many(j6_handle_t *handles, uint32_t count, j6_signal_t mask, j6_hand
return result;
*handle = j6_handle_invalid;
*sigs = th.get_wait_data();
*signals = th.get_wait_data();
j6_koid_t koid = th.get_wait_object();
for (unsigned i = 0; i < count; ++i) {
for (unsigned i = 0; i < handles_count; ++i) {
if (koid == objects[i]->koid())
*handle = handles[i];
else
@@ -96,7 +96,7 @@ object_wait_many(j6_handle_t *handles, uint32_t count, j6_signal_t mask, j6_hand
}
j6_status_t
object_signal(j6_handle_t handle, j6_signal_t signals)
kobject_signal(j6_handle_t handle, j6_signal_t signals)
{
if ((signals & j6_signal_user_mask) != signals)
return j6_err_invalid_arg;
@@ -110,7 +110,7 @@ object_signal(j6_handle_t handle, j6_signal_t signals)
}
j6_status_t
object_close(j6_handle_t handle)
kobject_close(j6_handle_t handle)
{
kobject *obj = get_handle<kobject>(handle);
if (!obj)

View File

@@ -16,14 +16,14 @@ process_create(j6_handle_t *handle)
}
j6_status_t
process_start(j6_handle_t handle, uintptr_t entrypoint, j6_handle_t *handles, size_t handle_count)
process_start(j6_handle_t handle, uintptr_t entrypoint, j6_handle_t * handles, size_t handles_count)
{
process &p = process::current();
process *c = get_handle<process>(handle);
if (handle_count && !handles)
if (handles_count && !handles)
return j6_err_invalid_arg;
for (size_t i = 0; i < handle_count; ++i) {
for (size_t i = 0; i < handles_count; ++i) {
kobject *o = p.lookup_handle(handles[i]);
if (o) c->add_handle(o);
}

View File

@@ -15,7 +15,7 @@ extern log::logger &g_logger;
namespace syscalls {
j6_status_t
system_log(const char *message)
log(const char *message)
{
if (message == nullptr)
return j6_err_invalid_arg;
@@ -26,7 +26,7 @@ system_log(const char *message)
}
j6_status_t
system_noop()
noop()
{
thread &th = thread::current();
log::debug(logs::syscall, "Thread %llx called noop syscall.", th.koid());
@@ -61,18 +61,18 @@ system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq)
}
j6_status_t
system_map_phys(j6_handle_t sys, j6_handle_t *vma_handle, uintptr_t phys_addr, size_t size, uint32_t flags)
system_map_phys(j6_handle_t handle, j6_handle_t * area, uintptr_t phys, size_t size, uint32_t flags)
{
// TODO: check capabilities on sys handle
if (!vma_handle) return j6_err_invalid_arg;
if (!area) return j6_err_invalid_arg;
// TODO: check to see if frames are already used? How would that collide with
// the bootloader's allocated pages already being marked used?
if (!(flags & vm_flags::mmio))
frame_allocator::get().used(phys_addr, memory::page_count(size));
frame_allocator::get().used(phys, memory::page_count(size));
vm_flags vmf = (static_cast<vm_flags>(flags) & vm_flags::driver_mask);
construct_handle<vm_area_fixed>(vma_handle, phys_addr, size, vmf);
construct_handle<vm_area_fixed>(area, phys, size, vmf);
return j6_status_ok;
}

View File

@@ -4,17 +4,18 @@
#include "log.h"
#include "objects/process.h"
#include "objects/thread.h"
#include "syscalls/helpers.h"
namespace syscalls {
j6_status_t
thread_create(void *rip, j6_handle_t *handle)
thread_create(j6_handle_t *handle, uintptr_t entrypoint)
{
thread &parent = thread::current();
process &p = parent.parent();
thread *child = p.create_thread();
child->add_thunk_user(reinterpret_cast<uintptr_t>(rip));
child->add_thunk_user(entrypoint);
*handle = child->self_handle();
child->clear_state(thread::state::loading);
child->set_state(thread::state::ready);
@@ -36,6 +37,18 @@ thread_exit(int32_t status)
return j6_err_unexpected;
}
j6_status_t
thread_kill(j6_handle_t handle)
{
thread *th = get_handle<thread>(handle);
if (!th)
return j6_err_invalid_arg;
log::debug(logs::task, "Killing thread %llx", th->koid());
th->exit(-1);
return j6_status_ok;
}
j6_status_t
thread_pause()
{