Rename libmsl to libsystem
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m6s

This commit is contained in:
2026-02-21 12:00:59 +01:00
parent b43127e023
commit 7601ea68e2
28 changed files with 29 additions and 30 deletions

4
libsystem/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.o
*.json
docs/
.cache/

7
libsystem/Makefile Normal file
View File

@@ -0,0 +1,7 @@
include ../make/ufuncs.mk
$(eval $(call add_include,liballoc))
libname := libsystem
include ../make/lib.mk

1
libsystem/amd64/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

8
libsystem/amd64/_start.S Normal file
View File

@@ -0,0 +1,8 @@
.global _start
_start:
xorq %rbp, %rbp
movq %rsp, %rbp
andq $-16, %rsp
subq $8, %rsp
callq __premain

6
libsystem/amd64/src.mk Normal file
View File

@@ -0,0 +1,6 @@
c += amd64/syscall.c
S += amd64/_start.S
o += amd64/_start.o \
amd64/syscall.o

17
libsystem/amd64/syscall.c Normal file
View File

@@ -0,0 +1,17 @@
#include <amd64/syscall.h>
#include <stddef.h>
#include <stdint.h>
uintptr_t amd64_syscall (int syscall_num, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
uintptr_t a5, uintptr_t a6) {
uint64_t result;
__asm__ volatile ("movq %[a4], %%r10\n"
"movq %[a5], %%r8\n"
"movq %[a6], %%r9\n"
"syscall\n"
: "=a"(result)
: "a"(syscall_num), "D"(a1), "S"(a2),
"d"(a3), [a4] "r"(a4), [a5] "r"(a5), [a6] "r"(a6)
: "r10", "r8", "r9", "r11", "rcx", "cc", "memory");
return result;
}

10
libsystem/amd64/syscall.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _LIBMSL_AMD64_SYSCALL_H
#define _LIBMSL_AMD64_SYSCALL_H
#include <stdint.h>
/* Performs a syscall for the AMD64 */
uintptr_t amd64_syscall (int syscall_num, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
uintptr_t a5, uintptr_t a6);
#endif // _LIBMSL_AMD64_SYSCALL_H

1
libsystem/init/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

View File

@@ -0,0 +1,27 @@
#include <liballoc.h>
#include <stdint.h>
#include <system.h>
extern volatile uint8_t __bss_start[];
extern volatile uint8_t __bss_end[];
extern void app_main (void);
static void clear_bss (void) {
uint8_t* p = (uint8_t*)__bss_start;
while (p < __bss_end) {
*p++ = 0;
}
}
void __premain (void) {
clear_bss ();
liballoc_init ();
app_main ();
liballoc_deinit ();
quit ();
}

3
libsystem/init/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += init/__premain.c
o += init/__premain.o

6
libsystem/src.mk Normal file
View File

@@ -0,0 +1,6 @@
include $(platform)/src.mk
include init/src.mk
c += system.c
o += system.o

11
libsystem/syscall.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef _LIBMSL_M_SYSCALL_H
#define _LIBMSL_M_SYSCALL_H
#include <m/syscall_defs.h>
#if defined(__x86_64__)
#include <amd64/syscall.h>
#define syscall amd64_syscall
#endif
#endif // _LIBMSL_M_SYSCALL_H

66
libsystem/system.c Normal file
View File

@@ -0,0 +1,66 @@
#include <stddef.h>
#include <stdint.h>
#include <syscall.h>
#include <system.h>
#define do_syscall1(id, a1, a2, a3, a4, a5, a6, ...) \
syscall (id, (uintptr_t)a1, (uintptr_t)a2, (uintptr_t)a3, (uintptr_t)a4, (uintptr_t)a5, \
(uintptr_t)a6)
#define do_syscall(...) do_syscall1 (__VA_ARGS__, 0, 0, 0, 0, 0, 0)
int quit (void) { return do_syscall (SYS_QUIT, 0); }
int test (char c) { return do_syscall (SYS_TEST, c); }
int sched (void) { return do_syscall (SYS_SCHED, 0); }
void* map (uintptr_t vaddr, size_t pages, uint32_t flags) {
return (void*)do_syscall (SYS_MAP, vaddr, pages, flags);
}
int unmap (uintptr_t vaddr, size_t pages) { return do_syscall (SYS_UNMAP, vaddr, pages); }
int clone (uintptr_t vstack_top, void (*entry) (void), void* argument_ptr) {
return do_syscall (SYS_CLONE, vstack_top, entry, argument_ptr);
}
int mutex_create (int mutex_rid) { return do_syscall (SYS_MUTEX_CREATE, mutex_rid); }
int mutex_delete (int mutex_rid) { return do_syscall (SYS_MUTEX_DELETE, mutex_rid); }
int mutex_lock (int mutex_rid) { return do_syscall (SYS_MUTEX_LOCK, mutex_rid); }
int mutex_unlock (int mutex_rid) { return do_syscall (SYS_MUTEX_UNLOCK, mutex_rid); }
void* argument_ptr (void) { return (void*)do_syscall (SYS_ARGUMENT_PTR, 0); }
int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4) {
return (int)do_syscall (SYS_DEVICE_DO, device_id, cmd, a1, a2, a3, a4);
}
int exec (const char* path) { return (int)do_syscall (SYS_EXEC, path); }
int open (const char* path) { return (int)do_syscall (SYS_OPEN, path); }
int close (const char* path) { return (int)do_syscall (SYS_CLOSE, path); }
int read (const char* path, size_t off, uint8_t* buffer, size_t size) {
return (int)do_syscall (SYS_READ, path, off, buffer, size);
}
int describe (const char* path, struct fs_desc_buffer* desc) {
return (int)do_syscall (SYS_DESCRIBE, path, desc);
}
int mail_send (int pgid, void* mesg, size_t mesg_size) {
return (int)do_syscall (SYS_MAIL_SEND, pgid, mesg, mesg_size);
}
int mail_receive (void* mesg, size_t mesg_size) {
return (int)do_syscall (SYS_MAIL_RECEIVE, mesg, mesg_size);
}
int get_procgroup (int pid) { return (int)do_syscall (SYS_GET_PROCGROUP, pid); }
int get_exec_pid (void) { return (int)do_syscall (SYS_GET_EXEC_PID, 0); }

80
libsystem/system.h Normal file
View File

@@ -0,0 +1,80 @@
#ifndef _LIBMSL_M_SYSTEM_H
#define _LIBMSL_M_SYSTEM_H
#include <m/fs_desc_buffer.h>
#include <stddef.h>
#include <stdint.h>
#if defined(__x86_64__)
#define PAGE_SIZE 4096
#endif
#define MAP_PRESENT (1 << 0)
#define MAP_RW (1 << 1)
#define MAP_USER (1 << 2)
#define MAP_FLAGS (MAP_PRESENT | MAP_USER)
/* Quit the current running process */
int quit (void);
/* Test syscall */
int test (char c);
/* Give the CPU to another process */
int sched (void);
/* map memory into this procgrou[ */
void* map (uintptr_t vaddr, size_t pages, uint32_t flags);
/* unmap memory from this procgrou[ */
int unmap (uintptr_t vaddr, size_t pages);
/* Clone process with argument and entry point */
int clone (uintptr_t vstack_top, void (*entry) (void), void* argument_ptr);
/* Create a mutex */
int mutex_create (int mutex_rid);
/* Delete a mutex. Will wake up waiters */
int mutex_delete (int mutex_rid);
/* Lock a mutex */
int mutex_lock (int mutex_rid);
/* Unlock a mutex */
int mutex_unlock (int mutex_rid);
/* get current process argument pointer */
void* argument_ptr (void);
/* Call a device command */
int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4);
/* Run external ELF program */
int exec (const char* path);
/* Open a file */
int open (const char* path);
/* Close a file */
int close (const char* path);
/* Read a file */
int read (const char* path, size_t off, uint8_t* buffer, size_t size);
/* describe a file */
int describe (const char* path, struct fs_desc_buffer* desc);
/* send a message to a procgroup's mail */
int mail_send (int pgid, void* mesg, size_t mesg_size);
/* receive a message from mail */
int mail_receive (void* mesg, size_t mesg_size);
/* get procgroup id of a perticular process */
int get_procgroup (int pid);
/* get PID of process, which exec'ed the current process */
int get_exec_pid (void);
#endif // _LIBMSL_M_SYSTEM_H