[libj6] Create libj6

Pull syscall code out of libc and create new libj6. This should
eventually become a vDSO, but for now it can still be a static lib.
Also renames all the _syscall_* symbol names to j6_*
This commit is contained in:
Justin C. Miller
2021-01-30 17:07:36 -08:00
parent c3dd65457d
commit 3595c3a440
7 changed files with 55 additions and 48 deletions

View File

@@ -120,12 +120,22 @@ modules:
source:
- src/libraries/cpu/cpu.cpp
j6:
kind: lib
output: libj6.a
includes:
- src/libraries/j6/include
target: user
source:
- src/libraries/j6/syscalls.s
libc:
kind: lib
output: libc.a
includes:
- src/libraries/libc/include
deps:
- j6
target: user
defines:
- DISABLE_SSE
@@ -144,7 +154,6 @@ modules:
- src/libraries/libc/arch/x86_64/_Exit.s
- src/libraries/libc/arch/x86_64/crt0.s
- src/libraries/libc/arch/x86_64/init_libc.c
- src/libraries/libc/arch/x86_64/syscalls.s
- src/libraries/libc/ctype/isalnum.c
- src/libraries/libc/ctype/isalpha.c
- src/libraries/libc/ctype/isblank.c

View File

@@ -5,10 +5,9 @@
#include "j6/init.h"
#include "j6/errors.h"
#include "j6/signals.h"
#include "j6/syscalls.h"
#include "j6/types.h"
#include <j6libc/syscalls.h>
#include "font.h"
#include "screen.h"
#include "scrollback.h"
@@ -32,7 +31,7 @@ struct entry
int
main(int argc, const char **argv)
{
_syscall_system_log("fb driver starting");
j6_system_log("fb driver starting");
size_t initc = 0;
j6_init_value *initv = nullptr;
@@ -47,7 +46,7 @@ main(int argc, const char **argv)
}
if (!fb || fb->addr == nullptr) {
_syscall_system_log("fb driver didn't find a framebuffer, exiting");
j6_system_log("fb driver didn't find a framebuffer, exiting");
return 1;
}
@@ -76,7 +75,7 @@ main(int argc, const char **argv)
char message_buffer[256];
while (true) {
size_t size = sizeof(message_buffer);
_syscall_system_get_log(__handle_sys, message_buffer, &size);
j6_system_get_log(__handle_sys, message_buffer, &size);
if (size != 0) {
entry *e = reinterpret_cast<entry*>(&message_buffer);
@@ -99,7 +98,7 @@ main(int argc, const char **argv)
}
_syscall_system_log("fb driver done, exiting");
j6_system_log("fb driver done, exiting");
return 0;
}

View File

@@ -4,8 +4,7 @@
#include "j6/types.h"
#include "j6/errors.h"
#include "j6/signals.h"
#include <j6libc/syscalls.h>
#include "j6/syscalls.h"
#include "io.h"
#include "serial.h"
@@ -21,33 +20,33 @@ extern "C" {
void
thread_proc()
{
_syscall_system_log("sub thread starting");
j6_system_log("sub thread starting");
char buffer[512];
size_t len = sizeof(buffer);
j6_tag_t tag = 0;
j6_status_t result = _syscall_endpoint_receive(endp, &tag, &len, (void*)buffer);
j6_status_t result = j6_endpoint_receive(endp, &tag, &len, (void*)buffer);
if (result != j6_status_ok)
_syscall_thread_exit(result);
j6_thread_exit(result);
_syscall_system_log("sub thread received message");
j6_system_log("sub thread received message");
for (int i = 0; i < len; ++i)
if (buffer[i] >= 'A' && buffer[i] <= 'Z')
buffer[i] += 0x20;
tag++;
result = _syscall_endpoint_send(endp, tag, len, (void*)buffer);
result = j6_endpoint_send(endp, tag, len, (void*)buffer);
if (result != j6_status_ok)
_syscall_thread_exit(result);
j6_thread_exit(result);
_syscall_system_log("sub thread sent message");
j6_system_log("sub thread sent message");
for (int i = 1; i < 5; ++i)
_syscall_thread_sleep(i*10);
j6_thread_sleep(i*10);
_syscall_system_log("sub thread exiting");
_syscall_thread_exit(0);
j6_system_log("sub thread exiting");
j6_thread_exit(0);
}
int
@@ -56,10 +55,10 @@ main(int argc, const char **argv)
j6_handle_t child = j6_handle_invalid;
j6_signal_t out = 0;
_syscall_system_log("main thread starting");
j6_system_log("main thread starting");
for (int i = 0; i < argc; ++i)
_syscall_system_log(argv[i]);
j6_system_log(argv[i]);
void *base = malloc(0x1000);
if (!base)
@@ -69,48 +68,48 @@ main(int argc, const char **argv)
for (int i = 0; i < 3; ++i)
vma_ptr[i*100] = uint64_t(i);
_syscall_system_log("main thread wrote to memory area");
j6_system_log("main thread wrote to memory area");
j6_status_t result = _syscall_endpoint_create(&endp);
j6_status_t result = j6_endpoint_create(&endp);
if (result != j6_status_ok)
return result;
_syscall_system_log("main thread created endpoint");
j6_system_log("main thread created endpoint");
result = _syscall_thread_create(reinterpret_cast<void*>(&thread_proc), &child);
result = j6_thread_create(reinterpret_cast<void*>(&thread_proc), &child);
if (result != j6_status_ok)
return result;
_syscall_system_log("main thread created sub thread");
j6_system_log("main thread created sub thread");
char message[] = "MAIN THREAD SUCCESSFULLY CALLED SENDRECV IF THIS IS LOWERCASE";
size_t size = sizeof(message);
j6_tag_t tag = 16;
result = _syscall_endpoint_sendrecv(endp, &tag, &size, (void*)message);
result = j6_endpoint_sendrecv(endp, &tag, &size, (void*)message);
if (result != j6_status_ok)
return result;
if (tag != 17)
_syscall_system_log("GOT WRONG TAG FROM SENDRECV");
j6_system_log("GOT WRONG TAG FROM SENDRECV");
result = _syscall_system_bind_irq(__handle_sys, endp, 3);
result = j6_system_bind_irq(__handle_sys, endp, 3);
if (result != j6_status_ok)
return result;
_syscall_system_log(message);
j6_system_log(message);
_syscall_system_log("main thread waiting on child");
result = _syscall_object_wait(child, -1ull, &out);
j6_system_log("main thread waiting on child");
result = j6_object_wait(child, -1ull, &out);
if (result != j6_status_ok)
return result;
_syscall_system_log("main thread creating a new process");
j6_system_log("main thread creating a new process");
j6_handle_t child_proc = j6_handle_invalid;
result = _syscall_process_create(&child_proc);
result = j6_process_create(&child_proc);
if (result != j6_status_ok)
return result;
_syscall_system_log("main testing irqs");
j6_system_log("main testing irqs");
serial_port com2(COM2);
@@ -124,21 +123,21 @@ main(int argc, const char **argv)
size_t len = 0;
while (true) {
result = _syscall_endpoint_receive(endp, &tag, &len, nullptr);
result = j6_endpoint_receive(endp, &tag, &len, nullptr);
if (result != j6_status_ok)
return result;
if (j6_tag_is_irq(tag))
_syscall_system_log("main thread got irq!");
j6_system_log("main thread got irq!");
}
_syscall_system_log("main thread closing endpoint");
j6_system_log("main thread closing endpoint");
result = _syscall_object_close(endp);
result = j6_object_close(endp);
if (result != j6_status_ok)
return result;
_syscall_system_log("main thread done, exiting");
j6_system_log("main thread done, exiting");
return 0;
}

View File

@@ -6,7 +6,7 @@
extern "C" {
#endif
#define SYSCALL(n, name, ...) j6_status_t _syscall_ ## name (__VA_ARGS__);
#define SYSCALL(n, name, ...) j6_status_t j6_ ## name (__VA_ARGS__);
#include "j6/tables/syscalls.inc"
#undef SYSCALL

View File

@@ -1,6 +1,6 @@
%macro SYSCALL 2
global _syscall_%1
_syscall_%1:
global j6_%1
j6_%1:
push rbp
mov rbp, rsp

View File

@@ -1,5 +1,5 @@
extern _syscall_process_exit
extern j6_process_exit
global _PDCLIB_Exit
_PDCLIB_Exit:
; arg should already be in rdi
jmp _syscall_process_exit
jmp j6_process_exit

View File

@@ -1,6 +1,6 @@
#include <stdint.h>
#include <j6/errors.h>
#include <j6libc/syscalls.h>
#include <j6/syscalls.h>
//void *sbrk(intptr_t) __attribute__ ((weak));
static j6_handle_t __core_handle = 0;
@@ -19,7 +19,7 @@ void *sbrk(intptr_t i)
if (i < 0)
return (void*)-1;
j6_status_t result = _syscall_vma_create_map(&__core_handle, i, __core_base, 1);
j6_status_t result = j6_vma_create_map(&__core_handle, i, __core_base, 1);
if (result != j6_status_ok)
return (void*)-1;
@@ -28,7 +28,7 @@ void *sbrk(intptr_t i)
}
size_t new_size = __core_size + i;
j6_status_t result = _syscall_vma_resize(__core_handle, &new_size);
j6_status_t result = j6_vma_resize(__core_handle, &new_size);
if (result != j6_status_ok)
return (void*)-1;