[libj6] Move remaining j6 headers out of src/include

This means the kernel now depends on libj6. I've added the macro
definition __j6kernel when building for the kernel target, so I can
remove parts with #ifdefs.
This commit is contained in:
Justin C. Miller
2022-01-12 16:04:16 -08:00
parent 2ff7a0864b
commit 950360fddc
19 changed files with 31 additions and 14 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
/// \file errors.h
/// Collection of constants for the j6_status_t type
#define j6_status_error 0x8000000000000000
#define j6_err(x) ((x) | j6_status_error)
#define j6_is_err(x) (((x) & j6_status_error) == j6_status_error)
#define j6_status_ok 0x0000
#define j6_status_closed 0x1000
#define j6_status_destroyed 0x1001
#define j6_status_exists 0x1002
#define j6_err_nyi j6_err(0x0001)
#define j6_err_unexpected j6_err(0x0002)
#define j6_err_invalid_arg j6_err(0x0003)
#define j6_err_not_ready j6_err(0x0004)
#define j6_err_insufficient j6_err(0x0005)

View File

@@ -0,0 +1,10 @@
#pragma once
/// \file flags.h
/// Enums used as flags for syscalls
enum j6_vm_flags {
#define VM_FLAG(name, v) j6_vm_flag_ ## name = v,
#include <j6/tables/vm_flags.inc>
#undef VM_FLAG
j6_vm_flag_MAX
};

View File

@@ -0,0 +1,37 @@
#pragma once
/// \file init.h
/// Types used in process and thread initialization
#include <stdint.h>
#include <j6/types.h>
enum j6_init_type { // `value` is a:
j6_init_handle_self, // Handle to the system
j6_init_handle_other, // Handle to this process
j6_init_desc_framebuffer // Pointer to a j6_init_framebuffer descriptor
};
struct j6_typed_handle {
enum j6_object_type type;
j6_handle_t handle;
};
struct j6_init_value {
enum j6_init_type type;
union {
struct j6_typed_handle handle;
void *data;
};
};
/// Structure defining a framebuffer.
/// `flags` has the following bits:
/// 0-3: Pixel layout. 0000: rgb8, 0001: bgr8
struct j6_init_framebuffer {
uintptr_t addr;
size_t size;
uint32_t vertical;
uint32_t horizontal;
uint32_t scanline;
uint32_t flags;
};

View File

@@ -0,0 +1,74 @@
#pragma once
/// \file signals.h
/// Collection of constants for the j6_signal_t type
// Signals 0-15 are common to all types
#define j6_signal_no_handles (1ull << 0)
#define j6_signal_closed (1ull << 1)
// Signals 16-47 are defined per-object-type
// Event signals
#define j7_signal_event00 (1ull << 16)
#define j7_signal_event01 (1ull << 17)
#define j7_signal_event02 (1ull << 18)
#define j7_signal_event03 (1ull << 19)
#define j7_signal_event04 (1ull << 20)
#define j7_signal_event05 (1ull << 21)
#define j7_signal_event06 (1ull << 22)
#define j7_signal_event07 (1ull << 23)
#define j7_signal_event08 (1ull << 24)
#define j7_signal_event09 (1ull << 25)
#define j7_signal_event10 (1ull << 26)
#define j7_signal_event11 (1ull << 27)
#define j7_signal_event12 (1ull << 28)
#define j7_signal_event13 (1ull << 29)
#define j7_signal_event14 (1ull << 30)
#define j7_signal_event15 (1ull << 31)
#define j7_signal_event16 (1ull << 32)
#define j7_signal_event17 (1ull << 33)
#define j7_signal_event18 (1ull << 34)
#define j7_signal_event19 (1ull << 35)
#define j7_signal_event20 (1ull << 36)
#define j7_signal_event21 (1ull << 37)
#define j7_signal_event22 (1ull << 38)
#define j7_signal_event23 (1ull << 39)
#define j7_signal_event24 (1ull << 40)
#define j7_signal_event25 (1ull << 41)
#define j7_signal_event26 (1ull << 42)
#define j7_signal_event27 (1ull << 43)
#define j7_signal_event28 (1ull << 44)
#define j7_signal_event29 (1ull << 45)
#define j7_signal_event30 (1ull << 46)
#define j7_signal_event31 (1ull << 47)
// System signals
#define j6_signal_system_has_log (1ull << 16)
// Channel signals
#define j6_signal_channel_can_send (1ull << 16)
#define j6_signal_channel_can_recv (1ull << 17)
// Endpoint signals
#define j6_signal_endpoint_can_send (1ull << 16)
#define j6_signal_endpoint_can_recv (1ull << 17)
// Signals 48-63 are user-defined signals
#define j6_signal_user0 (1ull << 48)
#define j6_signal_user1 (1ull << 49)
#define j6_signal_user2 (1ull << 50)
#define j6_signal_user3 (1ull << 51)
#define j6_signal_user4 (1ull << 52)
#define j6_signal_user5 (1ull << 53)
#define j6_signal_user6 (1ull << 54)
#define j6_signal_user7 (1ull << 55)
#define j6_signal_user8 (1ull << 56)
#define j6_signal_user9 (1ull << 57)
#define j6_signal_user10 (1ull << 58)
#define j6_signal_user11 (1ull << 59)
#define j6_signal_user12 (1ull << 60)
#define j6_signal_user13 (1ull << 61)
#define j6_signal_user14 (1ull << 62)
#define j6_signal_user15 (1ull << 63)
#define j6_signal_user_mask (0xffffull << 48)

View File

@@ -1,6 +1,10 @@
#pragma once
// vim: ft=cpp
// The kernel depends on libj6 for some shared code,
// but should not include the user-specific code.
#ifndef __j6kernel
#include <j6/types.h>
#ifdef __cplusplus
@@ -42,3 +46,5 @@ for id, scope, method in syscalls.methods:
#ifdef __cplusplus
}
#endif
#endif // __j6kernel

View File

@@ -0,0 +1,16 @@
LOG(apic, info);
LOG(boot, debug);
LOG(clock, debug);
LOG(device, debug);
LOG(driver, info);
LOG(fs, info);
LOG(irq, info);
LOG(loader, debug);
LOG(memory, debug);
LOG(objs, debug);
LOG(paging, info);
LOG(sched, info);
LOG(syscall,info);
LOG(task, debug);
LOG(timer, debug);
LOG(vmem, debug);

View File

@@ -0,0 +1,12 @@
OBJECT_TYPE( none, 0x00 )
OBJECT_TYPE( system, 0x01 )
OBJECT_TYPE( event, 0x02 )
OBJECT_TYPE( channel, 0x03 )
OBJECT_TYPE( endpoint, 0x04 )
OBJECT_TYPE( vma, 0x05 )
OBJECT_TYPE( process, 0x06 )
OBJECT_TYPE( thread, 0x07 )

View File

@@ -0,0 +1,36 @@
SYSCALL(0x00, system_log, const char *)
SYSCALL(0x01, system_noop, void)
SYSCALL(0x02, system_get_log, j6_handle_t, void *, size_t *)
SYSCALL(0x03, system_bind_irq, j6_handle_t, j6_handle_t, unsigned)
SYSCALL(0x04, system_map_phys, j6_handle_t, j6_handle_t *, uintptr_t, size_t, uint32_t)
SYSCALL(0x08, object_koid, j6_handle_t, j6_koid_t *)
SYSCALL(0x09, object_wait, j6_handle_t, j6_signal_t, j6_signal_t *)
SYSCALL(0x0a, object_wait_many, j6_handle_t *, uint32_t, j6_signal_t, j6_handle_t *, j6_signal_t *)
SYSCALL(0x0b, object_signal, j6_handle_t, j6_signal_t)
SYSCALL(0x0c, object_close, j6_handle_t)
SYSCALL(0x10, process_create, j6_handle_t *)
SYSCALL(0x11, process_start, j6_handle_t, uintptr_t, j6_handle_t *, size_t)
SYSCALL(0x11, process_kill, j6_handle_t)
SYSCALL(0x17, process_exit, int32_t)
SYSCALL(0x18, thread_create, void *, j6_handle_t *)
SYSCALL(0x19, thread_exit, int32_t)
SYSCALL(0x1a, thread_pause, void)
SYSCALL(0x1b, thread_sleep, uint64_t)
SYSCALL(0x20, channel_create, j6_handle_t *)
SYSCALL(0x21, channel_send, j6_handle_t, size_t *, void *)
SYSCALL(0x22, channel_receive, j6_handle_t, size_t *, void *)
SYSCALL(0x28, endpoint_create, j6_handle_t *)
SYSCALL(0x29, endpoint_send, j6_handle_t, j6_tag_t, size_t, void *)
SYSCALL(0x2a, endpoint_receive, j6_handle_t, j6_tag_t *, size_t *, void *)
SYSCALL(0x2b, endpoint_sendrecv, j6_handle_t, j6_tag_t *, size_t *, void *)
SYSCALL(0x30, vma_create, j6_handle_t *, size_t, uint32_t)
SYSCALL(0x31, vma_create_map, j6_handle_t *, size_t, uintptr_t, uint32_t)
SYSCALL(0x32, vma_map, j6_handle_t, j6_handle_t, uintptr_t)
SYSCALL(0x33, vma_unmap, j6_handle_t, j6_handle_t)
SYSCALL(0x34, vma_resize, j6_handle_t, size_t *)

View File

@@ -0,0 +1,8 @@
VM_FLAG( none, 0x00000000)
VM_FLAG( write, 0x00000001)
VM_FLAG( exec, 0x00000002)
VM_FLAG( contiguous, 0x00000020)
VM_FLAG( large_pages, 0x00000100)
VM_FLAG( huge_pages, 0x00000200)
VM_FLAG( write_combine, 0x00001000)
VM_FLAG( mmio, 0x00010000)

View File

@@ -0,0 +1,45 @@
#pragma once
/// \file types.h
/// Basic kernel types exposed to userspace
#include <stdint.h>
/// All interactable kernel objects have a uniqe kernel object id
typedef uint64_t j6_koid_t;
/// Syscalls return status as this type
typedef uint64_t j6_status_t;
/// Some objects have signals, which are a bitmap of 64 possible signals
typedef uint64_t j6_signal_t;
/// The first word of IPC messages are the tag. Tags with the high bit
/// set are reserved for the system.
typedef uint64_t j6_tag_t;
#define j6_tag_system_flag 0x8000000000000000
#define j6_tag_invalid 0x0000000000000000
/// If all high bits except the last 16 are set, then the tag represents
/// an IRQ.
#define j6_tag_irq_base 0xffffffffffff0000
#define j6_tag_is_irq(x) (((x) & j6_tag_irq_base) == j6_tag_irq_base)
#define j6_tag_from_irq(x) ((x) | j6_tag_irq_base)
#define j6_tag_to_irq(x) ((x) & ~j6_tag_irq_base)
/// Handles are references and capabilities to other objects. The least
/// significant 32 bits are an identifier, and the most significant 32
/// bits are a bitmask of capabilities this handle has on that object.
typedef uint64_t j6_handle_t;
#define j6_handle_rights_shift 4
#define j6_handle_id_mask 0xffffffffull
#define j6_handle_invalid 0xffffffffull
enum j6_object_type {
#define OBJECT_TYPE( name, val ) j6_object_type_ ## name = val,
#include <j6/tables/object_types.inc>
#undef OBJECT_TYPE
j6_object_type_max
};

View File

@@ -1,3 +1,7 @@
// The kernel depends on libj6 for some shared code,
// but should not include the user-specific code.
#ifndef __j6kernel
#include <stdint.h>
#include <j6/init.h>
#include <j6/types.h>
@@ -39,3 +43,5 @@ _init_libj6(uint64_t *rsp)
}
}
}
#endif // __j6kernel

View File

@@ -5,10 +5,15 @@ j6 = module("j6",
includes = [ "include" ],
sources = [
"init.cpp",
"include/j6/syscalls.h.cog",
"syscalls.s.cog",
])
from glob import glob
definitions = glob('definitions/**/*.def', recursive=True)
j6.add_input("include/j6/syscalls.h.cog", deps=definitions)
j6.add_input("syscalls.s.cog", deps=definitions)
j6.add_depends([
"include/j6/syscalls.h.cog",
"syscalls.s.cog",
], definitions)

View File

@@ -27,11 +27,12 @@
; ctx.parse("syscalls.def")
; syscalls = ctx.interfaces['syscalls']
;
; for id, scope, method in syscalls.methods:
; if scope:
; name = f"{scope.name}_{method.name}"
; else:
; name = method.name
; cog.outl(f"define_syscall {name:20}, {id}")
; if target != "kernel":
; for id, scope, method in syscalls.methods:
; if scope:
; name = f"{scope.name}_{method.name}"
; else:
; name = method.name
; cog.outl(f"define_syscall {name:20}, {id}")
; ]]]
; [[[end]]]