Move out libmsl functionality into separate libs
All checks were successful
Build documentation / build-and-deploy (push) Successful in 26s

This commit is contained in:
2026-02-12 22:57:33 +01:00
parent f37c34958e
commit ec6cd43a14
25 changed files with 112 additions and 29 deletions

View File

@@ -5,4 +5,6 @@ include make/kernel.mk
include make/dist.mk
include make/docs.mk
include make/libmsl.mk
include make/liballoc.mk
include make/libterminal.mk
include make/libprocess.mk

View File

@@ -9,6 +9,8 @@ else
fi
make -B all_libmsl
make -B all_liballoc
make -B all_libprocess
make -B all_libterminal
make -B all_apps
make -B all_dist

View File

@@ -4,4 +4,7 @@ set -x
make -B format_kernel
make -B format_libmsl
make -B format_libterminal
make -B format_libprocess
make -B format_liballoc
make -B format_apps

View File

@@ -1,4 +1,7 @@
ldflags += -L ../libterminal/build -l:libterminal.a
cflags += -isystem ../libterminal
include ../make/ufuncs.mk
$(eval $(call add_lib,libterminal))
$(eval $(call add_lib,liballoc))
$(eval $(call add_lib,libprocess))
include ../make/user.mk

View File

@@ -1,6 +1,5 @@
#include <limits.h>
#include <proc/local.h>
#include <proc/proc.h>
#include <process/process.h>
#include <stddef.h>
#include <stdint.h>
#include <string/string.h>
@@ -8,10 +7,10 @@
#define MUTEX 2000
LOCAL volatile char letter = 'c';
__thread volatile char letter = 'c';
void app_proc (void) {
char arg_letter = (char)(uintptr_t)argument_ptr ();
char arg_letter = (char)(uintptr_t)process_argument ();
letter = arg_letter;
@@ -32,9 +31,9 @@ void app_main (void) {
letter = 'a';
/* process_spawn (&app_proc, (void*)'b'); */
/* process_spawn (&app_proc, (void*)'c'); */
/* process_spawn (&app_proc, (void*)'d'); */
process_spawn (&app_proc, (void*)'b');
process_spawn (&app_proc, (void*)'c');
process_spawn (&app_proc, (void*)'d');
for (;;) {
mutex_lock (MUTEX);

28
liballoc/Makefile Normal file
View File

@@ -0,0 +1,28 @@
cc := clang
o :=
c :=
cflags := -isystem . -isystem ../libmsl
buildtype ?= release
include src.mk
include ../generic/flags.mk
include ../$(platform)/flags.mk
all: build/liballoc.a
build/liballoc.a: $(o)
llvm-ar rcs $@ $^
%.o: %.c
$(cc) -c -o $@ $(cflags) $<
%.o: %.S
$(cc) -c -o $@ $(cflags) $<
clean:
rm -f $(o) build/liballoc.a
format:
clang-format -i $$(git ls-files '*.c' '*.h')
.PHONY: all clean format

1
liballoc/src.mk Normal file
View File

@@ -0,0 +1 @@
include alloc/src.mk

View File

@@ -1,7 +1,7 @@
cc := clang
o :=
c :=
cflags := -isystem .
cflags := -isystem . -isystem ../liballoc
buildtype ?= release
include src.mk

View File

@@ -1,6 +0,0 @@
#ifndef _LIBMSL_PROC_TLS_H
#define _LIBMSL_PROC_TLS_H
#define LOCAL __thread
#endif // _LIBMSL_PROC_TLS_H

View File

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

View File

@@ -2,5 +2,3 @@ include $(platform)/src.mk
include init/src.mk
include m/src.mk
include string/src.mk
include alloc/src.mk
include proc/src.mk

28
libprocess/Makefile Normal file
View File

@@ -0,0 +1,28 @@
cc := clang
o :=
c :=
cflags := -isystem . -isystem ../libmsl -isystem ../liballoc
buildtype ?= release
include src.mk
include ../generic/flags.mk
include ../$(platform)/flags.mk
all: build/libprocess.a
build/libprocess.a: $(o)
llvm-ar rcs $@ $^
%.o: %.c
$(cc) -c -o $@ $(cflags) $<
%.o: %.S
$(cc) -c -o $@ $(cflags) $<
clean:
rm -f $(o) build/libprocess.a
format:
clang-format -i $$(git ls-files '*.c' '*.h')
.PHONY: all clean format

View File

@@ -1,16 +1,16 @@
#include <alloc/liballoc.h>
#include <m/status.h>
#include <m/system.h>
#include <proc/proc.h>
#include <process/process.h>
#include <stddef.h>
#include <stdint.h>
int process_spawn (process_func_t func, void* argument_ptr) {
void* stack = malloc (PROC_STACK_SIZE);
void* stack = malloc (STACK_SIZE);
if (stack == NULL)
return -ST_OOM_ERROR;
uintptr_t top = (uintptr_t)stack + PROC_STACK_SIZE;
uintptr_t top = (uintptr_t)stack + STACK_SIZE;
return clone (top, func, argument_ptr);
}

View File

@@ -1,9 +1,9 @@
#ifndef _LIBMSL_PROC_PROC_H
#define _LIBMSL_PROC_PROC_H
#ifndef _LIBPROCESS_PROCESS_PROCESS_H
#define _LIBPROCESS_PROCESS_PROCESS_H
#include <m/system.h>
#define PROC_STACK_SIZE 256 * PAGE_SIZE
#define STACK_SIZE (256 * PAGE_SIZE)
typedef void (*process_func_t) (void);
@@ -11,4 +11,4 @@ int process_spawn (process_func_t func, void* argument_ptr);
int process_quit (void);
void* process_argument (void);
#endif // _LIBMSL_PROC_PROC_H
#endif // _LIBPROCESS_PROCESS_PROCESS_H

View File

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

1
libprocess/src.mk Normal file
View File

@@ -0,0 +1 @@
include process/src.mk

View File

@@ -1,7 +1,7 @@
#include <m/system.h>
#include <stddef.h>
#include <terminal/device.h>
#include <terminal/terminal.h>
#include <m/system.h>
void terminal_print (const char* string, size_t len) {
device_do (TERMINAL_DEVICE, TERMINAL_PUTSTR, (void*)string, &len, NULL, NULL);

10
make/liballoc.mk Normal file
View File

@@ -0,0 +1,10 @@
all_liballoc:
make -C liballoc platform=$(platform) all
clean_liballoc:
make -C liballoc platform=$(platform) clean
format_liballoc:
make -C liballoc platform=$(platform) format
.PHONY: all_liballoc clean_liballoc format_liballoc

10
make/libprocess.mk Normal file
View File

@@ -0,0 +1,10 @@
all_libprocess:
make -C libprocess platform=$(platform) all
clean_libprocess:
make -C libprocess platform=$(platform) clean
format_libprocess:
make -C libprocess platform=$(platform) format
.PHONY: all_libprocess clean_libprocess format_libprocess

4
make/ufuncs.mk Normal file
View File

@@ -0,0 +1,4 @@
define add_lib
ldflags += -L ../$(1)/build -l:$(1).a
cflags += -isystem ../$(1)
endef