[TOOLCHAIN] Making musl portable
This commit is contained in:
@@ -3,26 +3,41 @@ ifeq ($(MITTOS64),)
|
||||
endif
|
||||
|
||||
LIBDIR := $(SYSROOT)/usr/lib
|
||||
LIBC := $(LIBDIR)/libc.a
|
||||
|
||||
CRT := crt0
|
||||
CRT_OBJ := $(addprefix obj/, $(patsubst %,%.o,$(CRT)))
|
||||
SRC := $(filter-out $(CRT).%, $(wildcard *.[cS]))
|
||||
OBJ := $(addprefix obj/, $(patsubst %,%.o, $(basename $(SRC))))
|
||||
|
||||
libfile := mittos64.o
|
||||
LIB_OBJ := $(LIBC)($(libfile))
|
||||
|
||||
CFLAGS := -Wall -Wextra -ggdb -O0
|
||||
ASFLAGS := -ggdb
|
||||
|
||||
all: $(CRT_OBJ)
|
||||
all: $(CRT_OBJ) $(OBJ)
|
||||
|
||||
OBJ_DIRS := $(sort $(dir $(CRT_OBJ)))
|
||||
OBJ_DIRS := $(sort $(dir $(CRT_OBJ) $(OBJ)))
|
||||
$(CRT_OBJ): | $(OBJ_DIRS)
|
||||
$(OBJ_DIRS):
|
||||
mkdir -p $@
|
||||
|
||||
obj/%.o:%.c
|
||||
$(COMPILE.c) $^ -o $@
|
||||
obj/%.o:%.S
|
||||
$(COMPILE.S) $^ -o $@
|
||||
obj/$(libfile):$(OBJ)
|
||||
$(LD) -r $^ -o $@
|
||||
|
||||
$(LIBC)(%):obj/%
|
||||
$(AR) -d $@ $<
|
||||
$(AR) -rs $@ $<
|
||||
|
||||
$(LIBDIR)/%: obj/%
|
||||
cp $< $@
|
||||
|
||||
install: $(patsubst %,$(LIBDIR)/%.o,$(CRT))
|
||||
install: $(patsubst %,$(LIBDIR)/%.o,$(CRT)) $(LIB_OBJ)
|
||||
|
||||
clean:
|
||||
rm -rf obj/
|
||||
|
||||
3
libc/syscall_num.h
Normal file
3
libc/syscall_num.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define SYS_DEBUG 0x3FF
|
||||
53
libc/syscalls.c
Normal file
53
libc/syscalls.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "syscalls.h"
|
||||
|
||||
long kernel_syscall(int num, ...)
|
||||
{
|
||||
va_list varg;
|
||||
va_start(varg, num);
|
||||
long a1 = va_arg(varg, long);
|
||||
long a2 = va_arg(varg, long);
|
||||
long a3 = va_arg(varg, long);
|
||||
register long r10 __asm__("r10") = va_arg(varg, long);
|
||||
register long r8 __asm__("r8") = va_arg(varg, long);
|
||||
register long r9 __asm__("r9") = va_arg(varg, long);
|
||||
va_end(varg);
|
||||
|
||||
long ret;
|
||||
__asm__ __volatile__("syscall" : "=a" (ret) : "a" (num), "D" (a1), "S" (a2), "d" (a3), "r" (r10), "r" (r8), "r" (r9) : "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
char debug_buffer[256];
|
||||
void kernel_debug(char *fmt, ...)
|
||||
{
|
||||
va_list varg;
|
||||
va_start(varg, fmt);
|
||||
vsprintf(debug_buffer, fmt, varg);
|
||||
va_end(varg);
|
||||
kernel_syscall(SYS_DEBUG, (long)debug_buffer);
|
||||
}
|
||||
|
||||
long __syscall_common(long num, ...)
|
||||
{
|
||||
va_list varg;
|
||||
va_start(varg, num);
|
||||
long a1 = va_arg(varg, long);
|
||||
long a2 = va_arg(varg, long);
|
||||
long a3 = va_arg(varg, long);
|
||||
long a4 = va_arg(varg, long);
|
||||
long a5 = va_arg(varg, long);
|
||||
long a6 = va_arg(varg, long);
|
||||
va_end(varg);
|
||||
|
||||
kernel_debug("==> SYSCALL %ld (%lx, %lx, %lx, %lx, %lx, %lx)\n", num, a1, a2, a3, a4, a5, a6);
|
||||
|
||||
while(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct pthread *__pthread_self()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
36
libc/syscalls.h
Normal file
36
libc/syscalls.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "syscall_num.h"
|
||||
|
||||
#define SYSCALL_DEF(name) \
|
||||
long __syscall_##name(long num, long _a1, long _a2, long _a3, long _a4, long _a5, long _a6)
|
||||
|
||||
#define _SYSCALL_INIT6(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,t6,n6) \
|
||||
(void)num; \
|
||||
t1 n1 = (t1)_a1; \
|
||||
(void)n1; \
|
||||
t2 n2 = (t2)_a2; \
|
||||
(void)n2; \
|
||||
t3 n3 = (t3)_a3; \
|
||||
(void)n3; \
|
||||
t4 n4 = (t4)_a4; \
|
||||
(void)n4; \
|
||||
t5 n5 = (t5)_a5; \
|
||||
(void)n5; \
|
||||
t6 n6 = (t6)_a6; \
|
||||
(void)n6;
|
||||
#define _SYSCALL_INIT5(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5) _SYSCALL_INIT6(t1,n1,t2,n2,t3,n3,t4,n4,t5,n5,long,__a6)
|
||||
#define _SYSCALL_INIT4(t1,n1,t2,n2,t3,n3,t4,n4) _SYSCALL_INIT6(t1,n1,t2,n2,t3,n3,t4,n4,long,__a5,long,__a6)
|
||||
#define _SYSCALL_INIT3(t1,n1,t2,n2,t3,n3) _SYSCALL_INIT6(t1,n1,t2,n2,t3,n3,long,__a4,long,__a5,long,__a6)
|
||||
#define _SYSCALL_INIT2(t1,n1,t2,n2) _SYSCALL_INIT6(t1,n1,t2,n2,long,__a3,long,__a4,long,__a5,long,__a6)
|
||||
#define _SYSCALL_INIT1(t1,n1) _SYSCALL_INIT6(t1,n1,long,__a2,long,__a3,long,__a4,long,__a5,long,__a6)
|
||||
#define _SYSCALL_INIT0() _SYSCALL_INIT6(long,__a1,long,__a2,long,__a3,long,__a4,long,__a5,long,__a6)
|
||||
|
||||
#define __SYSCALL_NARGS(a0,b0,a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,n,...) n
|
||||
#define _SYSCALL_NARGS(...) __SYSCALL_NARGS(__VA_ARGS__,6,6,5,5,4,4,3,3,2,2,1,1,0,0)
|
||||
#define __SYSCALL_CONCAT(a,b) a##b
|
||||
#define _SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT(a,b)
|
||||
#define _SYSCALL_INIT(a,...) _SYSCALL_CONCAT(a, _SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define SYSCALL_INIT(...) _SYSCALL_INIT(_SYSCALL_INIT,__VA_ARGS__)
|
||||
|
||||
long kernel_syscall(int num, ...);
|
||||
void kernel_debug(char *fmt, ...);
|
||||
Reference in New Issue
Block a user