Rewrite init app in C, introduce MSL (MOP3 System Library)
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
This commit is contained in:
28
libmsl/Makefile
Normal file
28
libmsl/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
cc := clang
|
||||
o :=
|
||||
c :=
|
||||
cflags := -isystem .
|
||||
buildtype ?= release
|
||||
|
||||
include src.mk
|
||||
include ../generic/flags.mk
|
||||
include ../$(platform)/flags.mk
|
||||
|
||||
all: build/libmsl.a
|
||||
|
||||
build/libmsl.a: $(o)
|
||||
llvm-ar rcs $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(cc) -c -o $@ $(cflags) $<
|
||||
|
||||
%.o: %.S
|
||||
$(cc) -c -o $@ $(cflags) $<
|
||||
|
||||
clean:
|
||||
rm -f $(o) build/libmsl.a
|
||||
|
||||
format:
|
||||
clang-format -i $$(git ls-files '*.c' '*.h')
|
||||
|
||||
.PHONY: all clean format
|
||||
1
libmsl/amd64/.gitignore
vendored
Normal file
1
libmsl/amd64/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.o
|
||||
8
libmsl/amd64/_start.S
Normal file
8
libmsl/amd64/_start.S
Normal file
@@ -0,0 +1,8 @@
|
||||
.global _start
|
||||
_start:
|
||||
xorq %rbp, %rbp
|
||||
movq %rsp, %rbp
|
||||
andq $-16, %rsp
|
||||
subq $8, %rsp
|
||||
|
||||
callq __premain
|
||||
6
libmsl/amd64/src.mk
Normal file
6
libmsl/amd64/src.mk
Normal file
@@ -0,0 +1,6 @@
|
||||
c += amd64/syscall.c
|
||||
|
||||
S += amd64/_start.S
|
||||
|
||||
o += amd64/_start.o \
|
||||
amd64/syscall.o
|
||||
23
libmsl/amd64/syscall.c
Normal file
23
libmsl/amd64/syscall.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <amd64/syscall.h>
|
||||
|
||||
int msl_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 %1, %%rax\n"
|
||||
"movq %2, %%rdi\n"
|
||||
"movq %3, %%rsi\n"
|
||||
"movq %4, %%rdx\n"
|
||||
"movq %5, %%r10\n"
|
||||
"movq %6, %%r8\n"
|
||||
"movq %7, %%r9\n"
|
||||
"syscall\n"
|
||||
"movq %%rax, %0\n"
|
||||
: "=r"(result)
|
||||
: "r"((uint64_t)syscall_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6)
|
||||
: "memory", "cc", "rcx", "r11"
|
||||
);
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
8
libmsl/amd64/syscall.h
Normal file
8
libmsl/amd64/syscall.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _LIBMSL_AMD64_SYSCALL_H
|
||||
#define _LIBMSL_AMD64_SYSCALL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int msl_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
libmsl/init/.gitignore
vendored
Normal file
1
libmsl/init/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.o
|
||||
22
libmsl/init/__premain.c
Normal file
22
libmsl/init/__premain.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdint.h>
|
||||
#include <m/proc.h>
|
||||
|
||||
extern volatile uint8_t __bss_start[];
|
||||
extern volatile uint8_t __bss_end[];
|
||||
|
||||
extern void app_main (void);
|
||||
|
||||
static void msl_clear_bss (void) {
|
||||
uint8_t *p = (uint8_t*)__bss_start;
|
||||
while (p < __bss_end) {
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void __premain (void) {
|
||||
msl_clear_bss ();
|
||||
|
||||
app_main ();
|
||||
|
||||
m_proc_quit ();
|
||||
}
|
||||
3
libmsl/init/src.mk
Normal file
3
libmsl/init/src.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
c += init/__premain.c
|
||||
|
||||
o += init/__premain.o
|
||||
1
libmsl/m/.gitignore
vendored
Normal file
1
libmsl/m/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.o
|
||||
10
libmsl/m/proc.c
Normal file
10
libmsl/m/proc.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <m/syscall.h>
|
||||
#include <m/syscall_defs.h>
|
||||
|
||||
int m_proc_quit (void) {
|
||||
return m_syscall (SYS_PROC_QUIT, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int m_proc_test (void) {
|
||||
return m_syscall (SYS_PROC_TEST, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
8
libmsl/m/proc.h
Normal file
8
libmsl/m/proc.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _LIBMSL_M_PROC_H
|
||||
#define _LIBMSL_M_PROC_H
|
||||
|
||||
int m_proc_quit (void);
|
||||
|
||||
int m_proc_test (void);
|
||||
|
||||
#endif // _LIBMSL_M_PROC_H
|
||||
3
libmsl/m/src.mk
Normal file
3
libmsl/m/src.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
c += m/proc.c
|
||||
|
||||
o += m/proc.o
|
||||
11
libmsl/m/syscall.h
Normal file
11
libmsl/m/syscall.h
Normal 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 m_syscall msl_amd64_syscall
|
||||
#endif
|
||||
|
||||
#endif // _LIBMSL_M_SYSCALL_H
|
||||
3
libmsl/src.mk
Normal file
3
libmsl/src.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
include $(platform)/src.mk
|
||||
include init/src.mk
|
||||
include m/src.mk
|
||||
Reference in New Issue
Block a user