Merge all libs into libu
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 40s
Build documentation / build-and-deploy (push) Successful in 26s

This commit is contained in:
2026-04-12 13:45:37 +02:00
parent 55ff95c897
commit 6c01de8b0d
160 changed files with 131 additions and 692 deletions

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

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

7
libu/amd64/_start.S Normal file
View File

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

7
libu/amd64/clone_tramp.S Normal file
View File

@@ -0,0 +1,7 @@
.global _clone_tramp
_clone_tramp:
xorq %rbp, %rbp
movq %rsp, %rbp
andq $-16, %rsp
callq _clone_tramp1

12
libu/amd64/clone_tramp1.c Normal file
View File

@@ -0,0 +1,12 @@
#include <malloc.h>
#include <process.h>
#include <system.h>
void _clone_tramp1 (void) {
struct process_data* pdata = argument_ptr ();
pdata->fn (pdata->arg_ptr);
free (pdata);
quit ();
}

12
libu/amd64/src.mk Normal file
View File

@@ -0,0 +1,12 @@
c += amd64/syscall.c \
amd64/stall.c \
amd64/clone_tramp1.c
S += amd64/_start.S \
amd64/clone_tramp.S
o += amd64/_start.o \
amd64/syscall.o \
amd64/stall.o \
amd64/clone_tramp.o \
amd64/clone_tramp1.o

30
libu/amd64/stall.c Normal file
View File

@@ -0,0 +1,30 @@
#include <stall.h>
#include <stdint.h>
static uint64_t stall_read_tsc (void) {
uint32_t lo, hi;
__asm__ volatile ("rdtsc" : "=a"(lo), "=d"(hi));
return ((uint64_t)hi << 32) | lo;
}
static uint64_t stall_get_tsc_freq_hz (void) {
uint32_t eax, ebx, ecx, edx;
__asm__ volatile ("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(0x15));
if (eax == 0 || ebx == 0 || ecx == 0)
return 2500000000ULL;
return (uint64_t)ecx * ebx / eax;
}
void stall_ms (uint64_t ms) {
uint64_t freq_hz = stall_get_tsc_freq_hz ();
uint64_t cycles = freq_hz / 1000;
uint64_t wait_cycles = ms * cycles;
uint64_t now = stall_read_tsc ();
while ((stall_read_tsc () - now) < wait_cycles)
__asm__ volatile ("pause" ::: "memory");
}

17
libu/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
libu/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