Compare commits

...

17 Commits

Author SHA1 Message Date
wash 1ec33767ab meta: replace cmake mono-build system with a custom build co-ordinator
every system component now has its own self-contained build system, and a
seed file describing the component and its build system and dependencies.

a new tool, meadow, collects and uses these seed files to build the
components into a full system. meadow also manages the target system root
and a host prefix where toolchain tools are installed to.

the build system has also been updated to use a new $ARCH-rosetta-gcc
compiler, and the patches files necessary to build it have been
added to toolchain/cross-compiler.
2026-07-19 13:34:32 +01:00
wash 59034be9e6 toolchain: xpcg: update fx path api usage 2026-07-19 13:33:05 +01:00
wash 7c2f59c7b1 herdd: update fx serial api includes 2026-07-19 13:32:19 +01:00
wash 810f741442 libc: pthread: implement mutexes 2026-07-19 13:31:22 +01:00
wash 6317060138 libc: runtime: add more required runtime objects 2026-07-19 13:30:49 +01:00
wash 34b3b8359b libc: add headers and definitions required by libgcc 2026-07-19 13:30:19 +01:00
wash 8aa76b5b7f libc: core: implement strrchr 2026-07-19 13:29:14 +01:00
wash 67b460e4e1 libc: io: implement puts 2026-07-19 13:28:49 +01:00
wash 9e20e0032d libc: io: implement putchar 2026-07-19 13:28:33 +01:00
wash 5c9ab75dbc libc: io: fix ringbuf_read/write not returning the correct values 2026-07-19 13:27:57 +01:00
wash 12df8d517d meta: update kernel 2026-06-07 13:50:01 +01:00
wash 55f5a8e82a librosetta: add a bootstrap channel marker for a namespace channel 2026-06-07 13:49:53 +01:00
wash 98343f1e12 libc: core: add mitigation for a potential bochs issue in strtoll 2026-06-07 13:49:32 +01:00
wash 46cb969019 interface: fs: add function for mounting a filesystem service into a namespace 2026-06-07 13:49:03 +01:00
wash 3f9e0abc49 toolchain: mxdbg: fix incorrect memory allocation size for packets 2026-06-07 13:48:24 +01:00
wash 9af5aa2acf toolchain: mxdbg: fix extra context threads hanging on exit 2026-06-07 13:48:04 +01:00
wash 01ee992791 toolchain: mxdbg: link client to threading library 2026-06-07 13:47:03 +01:00
134 changed files with 7407 additions and 300 deletions
+2 -2
View File
@@ -243,7 +243,6 @@ docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
@@ -341,5 +340,6 @@ pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/c,vim,linux,macos,windows,cmake,python
build*
build
build-native
.cache
+35 -5
View File
@@ -1,10 +1,12 @@
set(CMAKE_SYSTEM_NAME Rosetta)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
#set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
find_program(C_COMPILER x86_64-elf-gcc REQUIRED)
find_program(CXX_COMPILER x86_64-elf-g++ REQUIRED)
find_program(C_COMPILER x86_64-rosetta-gcc REQUIRED)
find_program(CXX_COMPILER x86_64-rosetta-g++ REQUIRED)
#find_program(ASM_COMPILER x86_64-elf-as REQUIRED)
add_compile_definitions(__magenta__=1 __rosetta__=1)
@@ -13,17 +15,45 @@ set(CMAKE_C_COMPILER ${C_COMPILER})
set(CMAKE_CXX_COMPILER ${CXX_COMPILER})
#set(CMAKE_ASM_COMPILER ${ASM_COMPILER})
SET(CMAKE_C_FLAGS "-ffreestanding -nostdlib -z max-page-size=0x1000 -m64 -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -D_64BIT -DBYTE_ORDER=1234" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-shared" CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS "-z max-page-size=0x1000 -m64 -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -D_64BIT -DBYTE_ORDER=1234" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-shared" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--unresolved-symbols=report-all,--dynamic-linker=/lib/ld64.so" CACHE STRING "" FORCE)
set(CMAKE_C_LINK_OPTIONS_PIE "-pie")
set(CMAKE_C_LINK_PIE_SUPPORTED TRUE)
set(CMAKE_C_LINK_NO_PIE_SUPPORTED TRUE)
SET(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")
if ("$ENV{ROSETTA_SYSROOT}" STREQUAL "")
message(FATAL_ERROR "No system root has been specified. Please define the $ROSETTA_SYSROOT environment variable")
endif ()
set(CMAKE_SYSROOT $ENV{ROSETTA_SYSROOT})
set(CMAKE_SYSTEM_LIBRARY_PATH
$ENV{ROSETTA_SYSROOT}/lib
$ENV{ROSETTA_SYSROOT}/usr/lib)
set(CMAKE_C_OUTPUT_EXTENSION .o)
set(CMAKE_CXX_OUTPUT_EXTENSION .o)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_DL_LIBS "dl")
set(CMAKE_INSTALL_RPATH \$ORIGIN/../lib)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
#set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
#set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
set(CMAKE_C_LINK_GROUP_USING_cross_refs_SUPPORTED TRUE)
set(CMAKE_C_LINK_GROUP_USING_cross_refs
"LINKER:--start-group"
"LINKER:--end-group"
)
set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
link_libraries(-lgcc)
+7
View File
@@ -0,0 +1,7 @@
[seed]
name = 'cdrom'
[build]
build_system = 'cmake'
# vim: ft=toml
+5
View File
@@ -0,0 +1,5 @@
[command]
name = 'debug'
description = 'Run the system under a debugger'
# vim: ft=toml
+12
View File
@@ -0,0 +1,12 @@
[command]
name = 'run-kernel'
description = 'Run the kernel image directly under QEMU'
[dependency]
commands = [ 'qemu-system-x86_64' ]
seeds = [ 'magenta', 'bsp' ]
[exec]
args = [ 'src:run-kernel.py']
# vim: ft=toml
+30
View File
@@ -0,0 +1,30 @@
import os
import shutil
import subprocess
sysroot = os.environ['MEADOW_SYSROOT']
native_root = os.environ['MEADOW_NATIVE_ROOT']
tmp = os.environ['MEADOW_TEMP']
bsp = os.path.join(sysroot, 'boot', 'rosetta-system.bsp')
kernel_exe = os.path.join(sysroot, 'boot', 'magenta_kernel')
kernel_exe_elf32 = os.path.join(tmp, 'magenta_kernel.elf32')
e64patch = os.path.join(native_root, 'bin', 'e64patch')
shutil.copyfile(kernel_exe, kernel_exe_elf32)
subprocess.run([ e64patch, kernel_exe_elf32 ])
qemu_args = [
'qemu-system-x86_64',
'-m', '128M',
'-cpu', 'qemu64,+rdrand',
'-kernel', kernel_exe_elf32,
'-initrd', bsp,
'-serial', 'stdio',
'--append', 'kernel.early-console=ttyS0'
]
try:
subprocess.run(qemu_args)
except KeyboardInterrupt:
pass
+19
View File
@@ -0,0 +1,19 @@
[platform]
name = 'x86_64-pc'
arch = 'x86_64'
[cmake]
module_paths = [ '.' ]
system_name = 'Rosetta'
toolchain_file = 'Platform/Rosetta.cmake'
[extension]
commands = [
'command/run-kernel.command',
]
seeds = [
'cdrom.seed'
]
# vim: ft=toml
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'base'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'source-only'
build_for = 'target'
watch_files = [ 'src:**' ]
[install]
"/" = [ 'src:boot' ]
# vim: ft=toml
+1
View File
@@ -37,6 +37,7 @@ function(add_interface)
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(iflib-${arg_NAME} ifgen-${arg_NAME})
add_library(interface::${arg_NAME} ALIAS iflib-${arg_NAME})
install(FILES ${header_path} DESTINATION include/${arg_PARENT_DIR})
endfunction(add_interface)
function(iface_get_header_path)
+12
View File
@@ -0,0 +1,12 @@
[seed]
name = 'libmagenta'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'cmake'
source_dir = 'kernel/libmagenta'
watch_files = [ 'src:**/*.c', 'src:**/*.h' ]
# vim: ft=toml
+22
View File
@@ -0,0 +1,22 @@
[seed]
name = 'magenta-headers'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'source-only'
build_for = 'target'
source_dir = 'kernel/libmagenta'
watch_files = [
'src:include/magenta/*.h',
'src:include-user/magenta/*.h',
]
[install]
"/usr/include/magenta" = [
'src:include/magenta/*.h',
'src:include-user/magenta/*.h',
]
# vim: ft=toml
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'magenta-tools'
[dependency]
no_standard_dependencies = true
[build]
build_for = 'host'
build_system = 'cmake'
source_dir = 'kernel/tools'
[publish]
path = [ 'install:bin/' ]
# vim: ft=toml
+18
View File
@@ -0,0 +1,18 @@
[seed]
name = 'magenta'
[dependency]
no_standard_dependencies = true
seeds = [
'magenta-tools'
]
[build]
build_system = 'cmake'
source_dir = 'kernel'
watch_files = [ 'src:**/*.c', 'src:**/*.h' ]
[install]
prefix = "/"
# vim: ft=toml
+5 -1
View File
@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.31)
project(rosetta-interface)
include(Msg-Interface)
file(GLOB if_files *.xpc)
foreach (file ${if_files})
get_filename_component(name ${file} NAME_WLE)
add_interface(NAME ${name} PATH ${file} PARENT_DIR rosetta)
sysroot_add_interface(NAME ${name} DEST_DIR /usr/include)
endforeach (file)
+1
View File
@@ -11,3 +11,4 @@ func seek[4](offset: offset, origin: int) -> (err: int, new_pos: offset);
func map[5](prot: int, flags: int) -> (err: int, vmo: handle);
func getdents[6]() -> (err: int, dents: buffer);
func mount[7](path: string, nd: int, pid: int, chid: int) -> (err: int);
+13
View File
@@ -0,0 +1,13 @@
[seed]
name = 'librosetta-interface'
[dependency]
no_standard_dependencies = true
seeds = [ 'xpcg' ]
[build]
build_system = 'cmake'
watch_files = [ 'src:*.xpc' ]
module_paths = [ 'root-src:cmake/' ]
# vim: ft=toml
+1 -1
Submodule kernel updated: c425d6e389...a14d0173c8
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'libfx-host'
[dependency]
no_standard_dependencies = true
[build]
build_for = 'host'
build_system = 'cmake'
source_dir = 'lib/libfx'
[publish.cmake]
module_paths = [ 'src:cmake/' ]
# vim: ft=toml
+16
View File
@@ -0,0 +1,16 @@
[seed]
name = 'libfx'
[build]
build_system = 'cmake'
source_dir = 'lib/libfx'
configure_args = [
'-Dfx_assemblies=fx.runtime;fx.collections;fx.serial;fx.io;fx.term;fx.cmdline',
'-Dfx_enable_floating_point=0',
'-Dfx_enable_tests=0',
]
[publish.cmake]
module_paths = [ 'src:cmake/' ]
# vim: ft=toml
+12 -21
View File
@@ -1,10 +1,12 @@
cmake_minimum_required(VERSION 3.31)
project(libc C ASM)
set(source_dirs core malloc io exec)
set(LIBC_STANDALONE FALSE)
set(public_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(runtime)
foreach (dir ${source_dirs})
add_subdirectory(${dir})
set(sources ${sources} ${component_sources})
@@ -12,22 +14,11 @@ foreach (dir ${source_dirs})
set(public_include_dirs ${public_include_dirs} ${component_public_include_dirs})
endforeach (dir)
rosetta_add_library(SHARED
NAME libc
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
SOURCES ${sources}
HEADERS ${headers})
sysroot_add_library(
NAME libc
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
bsp_add_library(
NAME libc
LIB_DIR /usr/lib)
target_link_libraries(libc PRIVATE librosetta libxpc-static liblaunch-static interface::fs)
target_link_libraries(libc PUBLIC libmagenta)
target_compile_definitions(libc PRIVATE ENABLE_GLOBAL_HEAP=1)
add_subdirectory(pthread)
add_library(libc SHARED ${sources} ${headers})
target_include_directories(libc PUBLIC ${public_include_dirs})
target_link_libraries(libc PRIVATE rosetta libxpc.a liblaunch.a libmagenta.a)
target_compile_options(libc PRIVATE -ffreestanding -nostdlib)
target_link_options(libc PRIVATE -ffreestanding -nostdlib)
target_compile_definitions(libc PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_SHARED=1)
set_target_properties(libc PROPERTIES PREFIX "")
install(TARGETS libc)
+16 -13
View File
@@ -1,3 +1,8 @@
if (LIBC_STANDALONE)
cmake_minimum_required(VERSION 3.31)
project(libc-core C ASM)
endif ()
set(source_dirs assert stdio stdlib string errno ctype wctype unistd)
foreach (dir ${source_dirs})
@@ -12,18 +17,16 @@ file(GLOB sys_sources
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.S)
set(component_sources ${sources} ${sys_sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
rosetta_add_library(STATIC
NAME libc-core
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
SOURCES ${sources} ${sys_sources}
HEADERS ${headers})
sysroot_add_library(
NAME libc-core
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
if (NOT LIBC_STANDALONE)
set(component_sources ${sources} ${sys_sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
return ()
endif ()
add_library(libc-core STATIC ${sources} ${sys_sources} ${headers})
target_include_directories(libc-core PUBLIC ${public_include_dirs})
target_link_libraries(libc-core PRIVATE libmagenta librosetta)
target_compile_definitions(libc-core PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
set_target_properties(libc-core PROPERTIES
PREFIX "")
install(TARGETS libc-core)
+18
View File
@@ -0,0 +1,18 @@
[seed]
name = 'libc-core'
[dependency]
no_standard_dependencies = true
seeds = [
'libc-headers',
'libmagenta',
'librosetta'
]
[build]
build_system = 'cmake'
configure_args = [
'-DLIBC_STANDALONE=TRUE'
]
# vim: ft=toml
+29 -6
View File
@@ -28,14 +28,14 @@
* SUCH DAMAGE.
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <magenta/log.h>
#include <stdio.h>
long long strtoll(
const char *restrict ptr,
char **restrict endptr,
register int base)
long long strtoll(const char *restrict ptr, char **restrict endptr, int base)
{
const char *s = ptr;
long long acc;
@@ -64,8 +64,31 @@ long long strtoll(
base = c == '0' ? 8 : 10;
}
cutoff = (long long)LLONG_MAX / (long long)base;
cutlim = (long long)LLONG_MAX % (long long)base;
/* XXX cannot just divide by base here. Doing so results in a #DE
* exception when running under Bochs. Not sure if this is a bug in the
* kernel or in Bochs, but this switch statement is here as a workaround
* until the issue is resolved. */
switch (base) {
case 2:
cutoff = (long long)LLONG_MAX / (long long)2;
cutlim = (long long)LLONG_MAX % (long long)2;
break;
case 8:
cutoff = (long long)LLONG_MAX / (long long)8;
cutlim = (long long)LLONG_MAX % (long long)8;
break;
case 10:
cutoff = (long long)LLONG_MAX / (long long)10;
cutlim = (long long)LLONG_MAX % (long long)10;
break;
case 16:
cutoff = (long long)LLONG_MAX / (long long)16;
cutlim = (long long)LLONG_MAX % (long long)16;
break;
default:
return -1;
}
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) {
c -= '0';
+14
View File
@@ -0,0 +1,14 @@
#include <string.h>
char *strrchr(const char *str, int c)
{
size_t len = strlen(str);
for (int i = len - 1; i > 0; i--) {
if (str[i] == c) {
return (char *)&str[i];
}
}
return NULL;
}
+17 -16
View File
@@ -1,5 +1,10 @@
set(source_dirs unistd spawn)
if (LIBC_STANDALONE)
cmake_minimum_required(VERSION 3.31)
project(libc-exec C ASM)
endif ()
file(GLOB sources *.c *.h)
foreach (dir ${source_dirs})
@@ -13,21 +18,17 @@ endforeach (dir)
file(GLOB_RECURSE sub_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
set(headers ${headers} ${sub_headers})
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
rosetta_add_library(STATIC
NAME libc-exec
PUBLIC_INCLUDE_DIRS
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include
SOURCES ${sources}
HEADERS ${headers})
sysroot_add_library(
NAME libc-exec
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
if (NOT LIBC_STANDALONE)
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
endif ()
add_library(libc-exec STATIC ${sources} ${headers})
target_include_directories(libc-exec PUBLIC
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(libc-exec libc-core libc-io libmagenta liblaunch-static)
target_compile_definitions(libc-exec PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
set_target_properties(libc-exec PROPERTIES PREFIX "")
install(TARGETS libc-exec)
+18
View File
@@ -0,0 +1,18 @@
[seed]
name = 'libc-exec'
[dependency]
seeds = [
'libc-core',
'libc-io',
'libmagenta',
'liblaunch-static',
]
[build]
build_system = 'cmake'
configure_args = [
'-DLIBC_STANDALONE=TRUE'
]
# vim: ft=toml
+8
View File
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.31)
project(libc-headers C)
file(GLOB headers *.h)
file(GLOB sys_headers sys/*.h)
install(FILES ${headers} DESTINATION include)
install(FILES ${sys_headers} DESTINATION include/sys)
+45
View File
@@ -1,6 +1,8 @@
#ifndef FCNTL_H_
#define FCNTL_H_
#include <sys/types.h>
#define O_RDONLY 0x0000 /* open for reading only */
#define O_WRONLY 0x0001 /* open for writing only */
#define O_RDWR 0x0002 /* open for reading and writing */
@@ -50,4 +52,47 @@
#define AT_SYMLINK_NOFOLLOW_ANY \
0x0800 /* Path should not contain any symlinks */
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000
#define R_OK 4
#define W_OK 2
#define X_OK 1
#define F_OK 0
#define F_RDLCK 0
#define F_WRLCK 1
#define F_SETLKW 7
struct flock {
short l_type;
short l_whence;
off_t l_start;
off_t l_len;
pid_t l_pid;
};
struct flock64 {
short l_type;
short l_whence;
off_t l_start;
off_t l_len;
pid_t l_pid;
};
extern int fcntl(int fd, int op, ...);
#endif
+16
View File
@@ -0,0 +1,16 @@
[seed]
name = 'libc-headers'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'source-only'
build_for = 'target'
watch_files = [ 'src:**' ]
[install]
"/usr/include" = [ 'src:*.h' ]
"/usr/include/sys" = [ 'src:sys/*.h' ]
# vim: ft=toml
+5
View File
@@ -26,6 +26,7 @@ extern int printf(const char *format, ...);
extern int vprintf(const char *format, va_list arg);
extern int fprintf(FILE *stream, const char *format, ...);
extern int vfprintf(FILE *stream, const char *format, va_list arg);
extern int sprintf(char *buffer, const char *format, ...);
extern int snprintf(char *buffer, size_t count, const char *format, ...);
extern int vsnprintf(
char *buffer,
@@ -34,6 +35,8 @@ extern int vsnprintf(
va_list va);
extern FILE *fopen(const char *path, const char *mode);
extern FILE *fdopen(int fildes, const char *mode);
extern int fclose(FILE *stream);
extern int feof(FILE *stream);
@@ -53,12 +56,14 @@ static inline int putc(int c, FILE *stream)
{
return fputc(c, stream);
}
extern int putchar(int c);
extern char *fgets(char *restrict str, int count, FILE *restrict stream);
extern int fputs(const char *restrict str, FILE *restrict stream);
extern long ftell(FILE *stream);
extern int fseek(FILE *stream, long offset, int origin);
extern int fflush(FILE *stream);
extern int sscanf(
const char *restrict buffer,
+5
View File
@@ -8,6 +8,11 @@ extern void abort(void);
extern void exit(int result);
extern int atexit(void (*func)(void));
extern int abs(int v);
extern int atoi(const char *str);
extern char *getenv(const char *name);
extern void *malloc(size_t count);
extern void *calloc(size_t count, size_t size);
extern void *realloc(void *p, size_t count);
+2
View File
@@ -10,7 +10,9 @@ extern size_t strlen(const char *s);
extern size_t strcspn(const char *dest, const char *src);
extern char *strcat(char *dest, const char *src);
extern char *strchr(const char *str, int c);
extern char *strrchr(const char *str, int ch);
extern int strcmp(const char *s1, const char *s2);
extern int strncmp(const char *s1, const char *s2, unsigned long n);
+8
View File
@@ -0,0 +1,8 @@
#ifndef SYS_STAT_H_
#define SYS_STAT_H_
#include <sys/types.h>
extern int mkdir(const char *path, mode_t mode);
#endif
+1 -1
View File
@@ -8,7 +8,7 @@
#define SEEK_END 2
typedef size_t ino_t;
typedef long pid_t;
typedef int pid_t;
typedef long mode_t;
struct dentry {
+7 -1
View File
@@ -4,12 +4,14 @@
#include <stddef.h>
#include <sys/types.h>
extern int open(const char *path, int flags);
extern int open(const char *path, int flags, ...);
extern int close(int fd);
extern int read(int fd, void *buf, size_t count);
extern int write(int fd, const void *buf, size_t count);
extern int access(const char *path, int mode);
extern off_t lseek(int fd, off_t offset, int whence);
extern long getdents(int fd, struct dentry *dirp, unsigned int count);
@@ -20,7 +22,11 @@ extern int execl(const char *path, const char *arg, ...);
extern int execlp(const char *file, const char *arg, ...);
extern int execle(const char *path, const char *arg, ...);
extern int execv(const char *path, char *const argv[]);
extern int execve(const char *path, char *const argv[], char *const envp[]);
extern int execvp(const char *file, char *const argv[]);
extern int execvpe(const char *file, char *const argv[], char *const envp[]);
extern pid_t getpid(void);
extern pid_t getppid(void);
#endif
+19 -17
View File
@@ -1,5 +1,10 @@
set(source_dirs unistd stdio)
if (LIBC_STANDALONE)
cmake_minimum_required(VERSION 3.31)
project(libc-io C ASM)
endif ()
file(GLOB sources *.c *.h)
foreach (dir ${source_dirs})
@@ -13,21 +18,18 @@ endforeach (dir)
file(GLOB_RECURSE sub_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
set(headers ${headers} ${sub_headers})
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
if (NOT LIBC_STANDALONE)
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
return ()
endif ()
rosetta_add_library(STATIC
NAME libc-io
PUBLIC_INCLUDE_DIRS
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include
SOURCES ${sources}
HEADERS ${headers})
sysroot_add_library(
NAME libc-io
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
target_link_libraries(libc-io libc-core interface::fs libxpc-static libmagenta)
add_library(libc-io STATIC ${sources} ${headers})
target_include_directories(libc-io PUBLIC
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(libc-io libc-core libxpc.a libmagenta)
target_compile_definitions(libc-io PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
set_target_properties(libc-io PROPERTIES PREFIX "")
install(TARGETS libc-io)
+19
View File
@@ -0,0 +1,19 @@
[seed]
name = 'libc-io'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
'libc-core',
'librosetta-interface',
'libxpc-static'
]
[build]
build_system = 'cmake'
configure_args = [
'-DLIBC_STANDALONE=TRUE'
]
# vim: ft=toml
+6
View File
@@ -0,0 +1,6 @@
#include <stdio.h>
int putchar(int c)
{
return fputc(c, stdout);
}
+36
View File
@@ -0,0 +1,36 @@
#include "file.h"
#include <stdio.h>
extern int __fputc(int c, struct __opaque_file *stream);
int puts(const char *restrict str)
{
struct __opaque_file *stream = stdout;
__libc_file_lock(stream);
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
__libc_file_unlock(stream);
return EOF;
}
size_t i = 0;
int err = 0;
for (i = 0; str[i]; i++) {
err = __fputc(str[i], stream);
if (err < 0) {
break;
}
}
if (err >= 0) {
err = __fputc('\n', stream);
}
__libc_file_unlock(stream);
if (i > 0) {
return i;
}
return err;
}
+2 -2
View File
@@ -145,7 +145,7 @@ long __libc_ringbuf_read(struct ringbuf *buf, void *p, size_t count)
memcpy(dest, src, to_copy);
nr_read += available;
nr_read += to_copy;
__libc_ringbuf_put_read_buffer(buf, &src, &to_copy);
}
@@ -183,7 +183,7 @@ long __libc_ringbuf_write(struct ringbuf *buf, const void *p, size_t count)
memcpy(dest, src, to_copy);
nr_written += available;
nr_written += to_copy;
__libc_ringbuf_put_write_buffer(buf, &dest, &to_copy);
}
+17
View File
@@ -0,0 +1,17 @@
[seed]
name = 'libc'
[dependency]
seeds = [
'libc-headers',
'libmagenta',
'librosetta',
'libxpc-static',
'liblaunch-static',
'librosetta-interface'
]
[build]
build_system = 'cmake'
# vim: ft=toml
+16 -16
View File
@@ -1,5 +1,10 @@
set(source_dirs stdlib string)
if (LIBC_STANDALONE)
cmake_minimum_required(VERSION 3.31)
project(libc-malloc C ASM)
endif ()
file(GLOB sources *.c *.h)
foreach (dir ${source_dirs})
@@ -13,22 +18,17 @@ endforeach (dir)
file(GLOB_RECURSE sub_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
set(headers ${headers} ${sub_headers})
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
rosetta_add_library(STATIC
NAME libc-malloc
PUBLIC_INCLUDE_DIRS
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include
SOURCES ${sources}
HEADERS ${headers})
sysroot_add_library(
NAME libc-malloc
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
if (NOT LIBC_STANDALONE)
set(component_sources ${sources} PARENT_SCOPE)
set(component_headers ${headers} PARENT_SCOPE)
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
endif ()
add_library(libc-malloc STATIC ${sources} ${headers})
target_compile_definitions(libc-malloc PRIVATE LIBC_STATIC=1 ENABLE_GLOBAL_HEAP=1)
target_include_directories(libc-malloc PUBLIC ${public_include_dirs} include)
target_compile_definitions(libc-malloc PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
target_link_libraries(libc-malloc libc-core libmagenta)
set_target_properties(libc-malloc PROPERTIES PREFIX "")
install(TARGETS libc-malloc)
install(FILES ${sub_headers} DESTINATION include/heap)
+17
View File
@@ -0,0 +1,17 @@
[seed]
name = 'libc-malloc'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
'libc-core'
]
[build]
build_system = 'cmake'
configure_args = [
'-DLIBC_STANDALONE=TRUE'
]
# vim: ft=toml
+27 -27
View File
@@ -1,4 +1,7 @@
set(pthread_source_dirs thread)
cmake_minimum_required(VERSION 3.31)
project(libc-pthread C ASM)
set(pthread_source_dirs thread mutex)
foreach (dir ${pthread_source_dirs})
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
@@ -17,30 +20,27 @@ set(pthread_sources ${pthread_sources} ${pthread_sys_sources})
set(pthread_headers ${pthread_headers} ${CMAKE_CURRENT_SOURCE_DIR}/include/pthread.h)
set(pthread_public_include_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
rosetta_add_library(STATIC
NAME libc-pthread
PUBLIC_INCLUDE_DIRS ${pthread_public_include_dir}
SOURCES ${pthread_sources}
HEADERS ${pthread_headers})
rosetta_add_library(SHARED
NAME libpthread
PUBLIC_INCLUDE_DIRS ${pthread_public_include_dir}
SOURCES ${pthread_sources}
HEADERS ${pthread_headers})
if (PTHREAD_STATIC)
add_library(libc-pthread STATIC ${pthread_sources} ${pthread_headers})
target_link_libraries(libc-pthread PRIVATE libc-io libmagenta)
target_include_directories(libc-pthread PUBLIC
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(libc-pthread PROPERTIES PREFIX "")
target_compile_definitions(libc-pthread PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_STATIC=1)
install(TARGETS libc-pthread)
else ()
add_library(libpthread SHARED ${pthread_sources} ${pthread_headers})
target_link_libraries(libpthread PRIVATE magenta)
target_link_libraries(libpthread PUBLIC c)
target_include_directories(libpthread PUBLIC
${public_include_dirs}
${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(libpthread PROPERTIES PREFIX "")
target_compile_options(libpthread PRIVATE -ffreestanding -nostdlib)
target_link_options(libpthread PRIVATE -ffreestanding -nostdlib)
target_compile_definitions(libpthread PRIVATE ENABLE_GLOBAL_HEAP=1 BUILD_SHARED=1)
install(TARGETS libpthread)
endif ()
sysroot_add_library(
NAME libc-pthread
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
sysroot_add_library(
NAME libpthread
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
bsp_add_library(
NAME libpthread
LIB_DIR /usr/lib)
target_link_libraries(libc-pthread PRIVATE libc-io libmagenta)
target_link_libraries(libpthread PRIVATE libmagenta)
target_link_libraries(libpthread PUBLIC libc)
install(FILES include/pthread.h DESTINATION include)
+7 -1
View File
@@ -3,7 +3,9 @@
#include <magenta/types.h>
#define __PTHREAD_ATTR_SIZE__ 32
#define __PTHREAD_ATTR_SIZE__ 32
#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) {.__v = 0})
typedef struct __pthread *pthread_t;
@@ -28,4 +30,8 @@ extern int pthread_join(pthread_t thread, void **retval);
extern int pthread_detach(pthread_t thread);
extern void pthread_exit(void *retval);
extern int pthread_mutex_lock(pthread_mutex_t *mut);
extern int pthread_mutex_trylock(pthread_mutex_t *mut);
extern int pthread_mutex_unlock(pthread_mutex_t *mut);
#endif
+17
View File
@@ -0,0 +1,17 @@
[seed]
name = 'libc-pthread'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
'libc-io'
]
[build]
build_system = 'cmake'
configure_args = [
'-DPTHREAD_STATIC=TRUE'
]
# vim: ft=toml
+7
View File
@@ -0,0 +1,7 @@
[seed]
name = 'libpthread'
[build]
build_system = 'cmake'
# vim: ft=toml
@@ -0,0 +1,24 @@
#include <errno.h>
#include <magenta/futex.h>
#include <pthread.h>
int pthread_mutex_lock(pthread_mutex_t *mut)
{
kern_futex_t expected = 0;
while (1) {
expected = 0;
if (__atomic_compare_exchange_n(
&mut->__v,
&expected,
1,
0,
__ATOMIC_ACQUIRE,
__ATOMIC_ACQUIRE)) {
return 0;
}
futex_wait(&mut->__v, 1, FUTEX_PRIVATE);
}
return __set_errno(EAGAIN);
}
@@ -0,0 +1,18 @@
#include <errno.h>
#include <pthread.h>
int pthread_mutex_trylock(pthread_mutex_t *mut)
{
kern_futex_t expected = 0;
if (__atomic_compare_exchange_n(
&mut->__v,
&expected,
1,
0,
__ATOMIC_ACQUIRE,
__ATOMIC_ACQUIRE)) {
return 0;
}
return __set_errno(EBUSY);
}
@@ -0,0 +1,8 @@
#include <magenta/futex.h>
#include <pthread.h>
int pthread_mutex_unlock(pthread_mutex_t *mut)
{
mut->__v = 0;
futex_wake(&mut->__v, 1, FUTEX_PRIVATE);
}
+12 -6
View File
@@ -1,10 +1,16 @@
cmake_minimum_required(VERSION 3.31)
project(libc-runtime C ASM)
file(GLOB runtime_sources
${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/*.s)
rosetta_add_object_library(
NAME libc-runtime STATIC
SOURCES ${runtime_sources})
foreach (s ${runtime_sources})
get_filename_component(object_name ${s} NAME)
get_filename_component(object_basename ${s} NAME_WE)
# TODO find a better way of finding the compiled object files
set(object_path
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/libc-runtime.dir/${CMAKE_SYSTEM_PROCESSOR}/${object_name}.obj)
install(FILES ${object_path} DESTINATION lib RENAME "${object_basename}.o")
endforeach (s)
sysroot_add_object_library(
NAME libc-runtime
LIB_DIR /usr/lib)
add_library(libc-runtime OBJECT ${runtime_sources})
+13
View File
@@ -0,0 +1,13 @@
[seed]
name = 'libc-runtime'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'cmake'
configure_args = [
'-DLIBC_STANDALONE=TRUE'
]
# vim: ft=toml
+22
View File
@@ -0,0 +1,22 @@
.code64
.global _start
.type _start, @function
.extern __libc_init
.type __libc_init, @function
_start:
# %rdi: (struct rosetta_bootstrap *)bs_info
mov %rdi, %rbx
call __libc_init
mov 0(%rbx), %rdi # argc
mov 8(%rbx), %rsi # argv
mov 24(%rbx), %rdx # envp
call main
mov %rax, %rdi
mov $9, %rax
syscall
1: jmp 1b
-23
View File
@@ -1,24 +1 @@
.code64
.global _start
.type _start, @function
.extern __libc_init
.type __libc_init, @function
.extern task_exit
.type task_exit, @function
_start:
# %rdi: (struct rosetta_bootstrap *)bs_info
mov %rdi, %rbx
call __libc_init
mov 0(%rbx), %rdi # argc
mov 8(%rbx), %rsi # argv
mov 24(%rbx), %rdx # envp
call main
mov %rax, %rdi
call task_exit
1: jmp 1b
+22
View File
@@ -0,0 +1,22 @@
.code64
.global _start
.type _start, @function
.extern __libc_init
.type __libc_init, @function
_start:
# %rdi: (struct rosetta_bootstrap *)bs_info
mov %rdi, %rbx
call __libc_init
mov 0(%rbx), %rdi # argc
mov 8(%rbx), %rsi # argv
mov 24(%rbx), %rdx # envp
call main
mov %rax, %rdi
mov $9, %rax
syscall
1: jmp 1b
+7
View File
@@ -0,0 +1,7 @@
.code64
.global _crtbeginS
.type _crtbeginS, @function
_crtbeginS:
ret
+7
View File
@@ -0,0 +1,7 @@
.code64
.global _crtendS
.type _crtendS, @function
_crtendS:
ret
+16 -22
View File
@@ -1,33 +1,27 @@
cmake_minimum_required(VERSION 3.31)
project(fs C ASM)
file(GLOB sources
${CMAKE_CURRENT_SOURCE_DIR}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/interface/*.c)
file(GLOB headers
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/fs/*.h)
file(GLOB public_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/fs/*.h)
set(public_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/include)
rosetta_add_library(
NAME libfs SHARED STATIC
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
SOURCES ${sources}
HEADERS ${headers})
if (FS_STATIC)
add_library(fs STATIC ${sources} ${headers})
target_link_libraries(fs magenta libc-core libxpc.a)
set_target_properties(fs PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
else ()
add_library(fs SHARED ${sources} ${headers})
target_link_libraries(fs magenta c xpc)
endif ()
sysroot_add_library(
NAME libfs
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
sysroot_add_library(
NAME libfs-static
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
bsp_add_library(
NAME libfs
LIB_DIR /usr/lib)
target_link_libraries(libfs libmagenta interface::fs libc libxpc)
target_link_libraries(libfs-static libmagenta interface::fs libc-core libxpc-static)
set_target_properties(libfs-static PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
target_include_directories(fs PUBLIC include)
install(TARGETS fs)
install(FILES ${public_headers} DESTINATION include/fs)
+16
View File
@@ -0,0 +1,16 @@
[seed]
name = 'libfs-static'
[dependency]
no_standard_dependencies = true
seeds = [
'libxpc-static',
'liblaunch-static',
'librosetta-interface'
]
[build]
build_system = 'cmake'
configure_args = [ '-DFS_STATIC=TRUE' ]
# vim: ft=toml
+13
View File
@@ -0,0 +1,13 @@
[seed]
name = 'libfs'
[dependency]
seeds = [
'libxpc',
'librosetta-interface'
]
[build]
build_system = 'cmake'
# vim: ft=toml
+15 -15
View File
@@ -1,25 +1,25 @@
cmake_minimum_required(VERSION 3.31)
project(launch C ASM)
file(GLOB sources
${CMAKE_CURRENT_SOURCE_DIR}/*.c)
file(GLOB headers
${CMAKE_CURRENT_SOURCE_DIR}/include/launch.h
${CMAKE_CURRENT_SOURCE_DIR}/*.h)
file(GLOB public_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/launch.h)
set(public_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/include)
rosetta_add_library(
NAME liblaunch SHARED STATIC
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
SOURCES ${sources}
HEADERS ${headers})
if (LAUNCH_STATIC)
add_library(launch STATIC ${sources} ${headers})
target_link_libraries(launch PRIVATE librosetta libmagenta libc-core)
else ()
add_library(launch SHARED ${sources} ${headers})
target_link_libraries(launch PRIVATE rosetta magenta c)
endif ()
sysroot_add_library(
NAME liblaunch
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
bsp_add_library(
NAME liblaunch
LIB_DIR /usr/lib)
target_link_libraries(liblaunch-static PRIVATE librosetta libmagenta libc-core)
target_link_libraries(liblaunch PRIVATE librosetta libmagenta libc)
target_include_directories(launch PUBLIC include)
install(TARGETS launch)
install(FILES ${public_headers} DESTINATION include)
+16
View File
@@ -0,0 +1,16 @@
[seed]
name = 'liblaunch-static'
[dependency]
no_standard_dependencies = true
seeds = [
'librosetta',
'libmagenta',
'libc-core'
]
[build]
build_system = 'cmake'
configure_args = [ '-DLAUNCH_STATIC=TRUE' ]
# vim: ft=toml
+7
View File
@@ -0,0 +1,7 @@
[seed]
name = 'liblaunch'
[build]
build_system = 'cmake'
# vim: ft=toml
+8 -10
View File
@@ -1,15 +1,13 @@
cmake_minimum_required(VERSION 3.31)
project(librosetta C ASM)
file(GLOB sources *.c)
file(GLOB headers include/rosetta/*.h)
rosetta_add_library(
NAME librosetta STATIC
PUBLIC_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
SOURCES ${sources}
HEADERS ${headers})
add_library(rosetta STATIC ${sources} ${headers})
target_include_directories(rosetta PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
sysroot_add_library(
NAME librosetta
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
target_link_libraries(rosetta PRIVATE libmagenta)
target_link_libraries(librosetta PRIVATE libmagenta)
install(TARGETS rosetta)
install(FILES ${headers} DESTINATION include/rosetta)
@@ -12,6 +12,7 @@ enum rosetta_bootstrap_handle_type {
enum rosetta_bootstrap_channel_type {
RSBS_CHANNEL_NONE,
RSBS_CHANNEL_SYSTEM,
RSBS_CHANNEL_NAMESPACE,
};
struct rosetta_bootstrap_handle {
+13
View File
@@ -0,0 +1,13 @@
[seed]
name = 'librosetta'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
]
[build]
build_system = 'cmake'
# vim: ft=toml
+16 -16
View File
@@ -1,28 +1,28 @@
cmake_minimum_required(VERSION 3.31)
project(xpc C ASM)
file(GLOB sources
${CMAKE_CURRENT_SOURCE_DIR}/*.c)
file(GLOB headers
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/xpc/*.h)
file(GLOB public_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/xpc/*.h)
set(public_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/include)
rosetta_add_library(
NAME libxpc SHARED STATIC
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
SOURCES ${sources}
HEADERS ${headers})
if (XPC_STATIC)
add_library(xpc STATIC ${sources} ${headesr})
target_link_libraries(xpc magenta libc-core)
else ()
add_library(xpc SHARED ${sources} ${headesr})
target_link_libraries(xpc magenta c)
endif ()
sysroot_add_library(
NAME libxpc
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
sysroot_add_library(
NAME libxpc-static
HEADER_DIR /usr/include
LIB_DIR /usr/lib)
target_link_libraries(libxpc libmagenta libc)
target_link_libraries(libxpc-static libmagenta libc-core)
target_include_directories(xpc PUBLIC ${public_include_dirs})
install(TARGETS xpc)
install(FILES ${public_headers} DESTINATION include/xpc)
#set_target_properties(libxpc-static PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'libxpc-static'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
'libc-core'
]
[build]
build_system = 'cmake'
configure_args = [ '-DXPC_STATIC=TRUE' ]
# vim: ft=toml
+7
View File
@@ -0,0 +1,7 @@
[seed]
name = 'libxpc'
[build]
build_system = 'cmake'
# vim: ft=toml
Executable
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ ! -d "$SCRIPT_DIR/build" ]; then
mkdir build
fi
if [ ! -d "$SCRIPT_DIR/build/meadow_venv" ]; then
echo 'Initialising meadow...'
python3 -m venv $SCRIPT_DIR/build/meadow_venv
source $SCRIPT_DIR/build/meadow_venv/bin/activate
pip install -r $SCRIPT_DIR/toolchain/meadow/requirements.txt
else
source $SCRIPT_DIR/build/meadow_venv/bin/activate
fi
python3 $SCRIPT_DIR/toolchain/meadow/main.py "$@"
+1
View File
@@ -3,6 +3,7 @@ file(GLOB items *)
set(bshell_interactive 0)
set(bshell_verbose 0)
set(bshell_enable_floating_point 0)
set(bshell_enable_native_commands 0)
foreach(item ${items})
if (NOT IS_DIRECTORY ${item})
+18
View File
@@ -0,0 +1,18 @@
[seed]
name = 'bshell'
[dependency]
seeds = [
'libfx',
]
[build]
build_system = 'cmake'
source_dir = 'programs/bshell'
configure_args = [
'-Dbshell_interactive=FALSE',
'-Dbshell_enable_native_commands=FALSE',
'-Dbshell_enable_floating_point=FALSE',
]
# vim: ft=toml
+8 -16
View File
@@ -1,17 +1,9 @@
rosetta_add_misc_service(
NAME bshell-test
CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/bshell-test.service)
cmake_minimum_required(VERSION 3.31)
project(bshell-test)
rosetta_service_add_file(
NAME bshell-test
SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test.bshell
DEST_DIR /sbin)
sysroot_add_service(
NAME bshell-test
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
bsp_add_service(
NAME bshell-test
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/bshell-test.service
DESTINATION etc/herdd/services)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/test.bshell
DESTINATION sbin)
+12
View File
@@ -0,0 +1,12 @@
[seed]
name = 'bshell-test'
[build]
build_system = 'cmake'
[install]
prefix = "/"
'/etc/herdd/services' = [ 'bshell-test.service' ]
'/sbin' = [ 'test.bshell' ]
# vim: ft=toml
+6 -14
View File
@@ -1,15 +1,7 @@
file(GLOB sources *.c)
rosetta_add_service(
NAME devmd
SOURCES ${sources}
CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/devmd.service)
target_link_libraries(devmd libc libc-runtime)
cmake_minimum_required(VERSION 3.31)
project(devmd C)
sysroot_add_service(
NAME devmd
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
bsp_add_service(
NAME devmd
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
file(GLOB sources *.c)
add_executable(devmd ${sources})
target_link_libraries(devmd c -l:crt0.o)
install(TARGETS devmd)
+10
View File
@@ -0,0 +1,10 @@
[seed]
name = 'devmd'
[build]
build_system = 'cmake'
[install]
"/etc/herdd/services" = [ 'src:devmd.service' ]
# vim: ft=toml
+6 -8
View File
@@ -1,13 +1,11 @@
cmake_minimum_required(VERSION 3.31)
project(herdd C)
file(GLOB sources *.c)
add_executable(herdd ${sources})
target_link_libraries(herdd
libc libc-runtime
libmagenta libpthread liblaunch librosetta
c -l:crt0.o
magenta pthread launch rosetta
fx.runtime fx.collections fx.serial)
sysroot_add_program(
NAME herdd
BIN_DIR /usr/bin)
bsp_add_program(
NAME herdd
BIN_DIR /usr/bin)
install(TARGETS herdd)
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'herdd'
[dependency]
seeds = [
'liblaunch',
'librosetta',
'libfx'
]
[build]
build_system = 'cmake'
watch_files = [ 'src:*.c', 'src:*.h' ]
# vim: ft=toml
+2 -1
View File
@@ -5,7 +5,8 @@
#include <errno.h>
#include <fx/collections/array.h>
#include <fx/collections/hashtable.h>
#include <fx/serial.h>
#include <fx/serial/ctx.h>
#include <fx/serial/toml.h>
#include <fx/string.h>
#include <fx/stringstream.h>
#include <launch.h>
+2 -1
View File
@@ -6,7 +6,8 @@
#include <errno.h>
#include <fx/collections/array.h>
#include <fx/collections/hashtable.h>
#include <fx/serial.h>
#include <fx/serial/ctx.h>
#include <fx/serial/toml.h>
#include <fx/string.h>
#include <fx/stringstream.h>
#include <magenta/log.h>
+6 -14
View File
@@ -1,15 +1,7 @@
file(GLOB sources *.c)
rosetta_add_service(
NAME nsd
SOURCES ${sources}
CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/nsd.service)
target_link_libraries(nsd libc libc-runtime)
cmake_minimum_required(VERSION 3.31)
project(nsd C)
sysroot_add_service(
NAME nsd
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
bsp_add_service(
NAME nsd
BIN_DIR /usr/bin
SVC_DIR /etc/herdd/services)
file(GLOB sources *.c)
add_executable(nsd ${sources})
target_link_libraries(nsd c -l:crt0.o)
install(TARGETS nsd)
+10
View File
@@ -0,0 +1,10 @@
[seed]
name = 'nsd'
[build]
build_system = 'cmake'
[install]
"/etc/herdd/services" = [ 'src:nsd.service' ]
# vim: ft=toml
+15
View File
@@ -0,0 +1,15 @@
[seed]
name = 'herdd-targets'
[dependency]
no_standard_dependencies = true
[build]
build_system = 'source-only'
build_for = 'target'
watch_files = [ 'src:*.target' ]
[install]
"/etc/herdd/targets" = [ 'src:*.target' ]
# vim: ft=toml
+11 -6
View File
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.31)
project(bootstrap C ASM)
file(GLOB c_sources *.c *.h)
file(GLOB arch_sources arch/${CMAKE_SYSTEM_PROCESSOR}/*.S)
add_executable(bootstrap ${c_sources} ${arch_sources})
set(static_deps
magenta rosetta
libc-core.a libc-malloc.a libc-io.a
libfs.a
liblaunch.a
libxpc.a)
target_link_libraries(bootstrap
libmagenta librosetta
libc-core libc-malloc libc-pthread
libfs-static
liblaunch-static
libxpc-static
interface::fs)
"$<LINK_GROUP:cross_refs,${static_deps}>")
target_compile_options(bootstrap PRIVATE
-fno-stack-protector -nostdlib -ffreestanding -fno-PIC)
@@ -17,3 +21,4 @@ target_link_options(bootstrap PRIVATE
-static -nostdlib -ffreestanding)
set_target_properties(bootstrap PROPERTIES POSITIION_INDEPENDENT_CODE FALSE)
install(TARGETS bootstrap DESTINATION boot)
+24
View File
@@ -0,0 +1,24 @@
[seed]
name = 'bootstrap'
[dependency]
no_standard_dependencies = true
seeds = [
'libmagenta',
'librosetta',
'libc-core',
'libc-malloc',
'libc-pthread',
'libfs-static',
'liblaunch-static',
'libxpc-static',
'librosetta-interface',
]
[build]
build_system = 'cmake'
[install]
prefix = "/"
# vim: ft=toml
+38
View File
@@ -0,0 +1,38 @@
[seed]
name = 'bsp'
[build]
build_system = 'generic'
build_command = {
args = [
'root-src:toolchain/mkbsp/mkbsp',
'--preset',
'src:rosetta.preset',
'--sysroot',
'install:.',
'--out',
'bin:rosetta-system.bsp',
],
}
watch_files = [ 'install:**' ]
[dependency]
seeds = [
'ld',
'bshell',
'libc',
'libpthread',
'libfx',
'liblaunch',
'libfs',
'libxpc',
'herdd',
'herdd-targets',
'nsd',
'devmd',
]
[install]
"/boot" = [ 'bin:rosetta-system.bsp' ]
# vim: ft=toml
+8
View File
@@ -0,0 +1,8 @@
[bootstrap]
bootstrap_exec = '/boot/bootstrap'
[contents]
"/lib" = [ '/lib/ld64.so' ]
"/usr/bin" = [ '/usr/bin/herdd' ]
# vim: ft=toml
+16
View File
@@ -0,0 +1,16 @@
[contents]
"/usr/lib" = [
'/usr/lib/libc.so',
'/usr/lib/libpthread.so',
'/usr/lib/libfs.so',
'/usr/lib/libfx.runtime.so',
'/usr/lib/libfx.collections.so',
'/usr/lib/libfx.io.so',
'/usr/lib/libfx.serial.so',
'/usr/lib/libfx.term.so',
'/usr/lib/libfx.cmdline.so',
'/usr/lib/liblaunch.so',
'/usr/lib/libxpc.so',
]
# vim: ft=toml
+12
View File
@@ -0,0 +1,12 @@
[contents]
"/usr/bin" = [
'/usr/bin/devmd',
'/usr/bin/nsd',
]
"/etc/herdd/services" = [
'/etc/herdd/services/devmd.service',
'/etc/herdd/services/nsd.service',
]
# vim: ft=toml
+7
View File
@@ -0,0 +1,7 @@
[contents]
"/etc/herdd/targets" = [
'/etc/herdd/targets/minimal.target',
'/etc/herdd/targets/single-user.target',
]
# vim: ft=toml
+8
View File
@@ -0,0 +1,8 @@
[contents]
"/usr/bin" = [ '/usr/bin/bshell' ]
"/usr/lib" = [
'/usr/lib/libbshell.runtime.so',
'/usr/lib/libbshell.core.so',
]
# vim: ft=toml
+8 -9
View File
@@ -1,3 +1,6 @@
cmake_minimum_required(VERSION 3.31)
project(ld C ASM)
file(GLOB c_sources *.c *.h)
file(GLOB arch_sources arch/${CMAKE_SYSTEM_PROCESSOR}/*.S)
@@ -7,9 +10,11 @@ set_target_properties(ld PROPERTIES
OUTPUT_NAME "ld64"
SUFFIX ".so")
set(libc_deps
libc-core.a libc-malloc.a libc-io.a)
target_link_libraries(ld
libc-core libc-malloc libc-io libmagenta librosetta libxpc-static
interface::fs)
"$<LINK_GROUP:cross_refs,${libc_deps}>"
libmagenta.a librosetta.a -l:libxpc.a)
target_compile_options(ld PRIVATE
-fvisibility=hidden
@@ -19,10 +24,4 @@ target_link_options(ld PRIVATE
# -Wl,--entry="_ld_start"
-T ${CMAKE_CURRENT_SOURCE_DIR}/arch/${CMAKE_SYSTEM_PROCESSOR}/layout.ld
-fPIC -nostdlib -ffreestanding -Wl,-shared)
sysroot_add_program(
NAME ld
BIN_DIR /lib)
bsp_add_program(
NAME ld
BIN_DIR /lib)
install(TARGETS ld DESTINATION lib)
+23
View File
@@ -0,0 +1,23 @@
[seed]
name = 'ld'
[dependency]
no_standard_dependencies = true
seeds = [
'libc-core',
'libc-malloc',
'libc-io',
'libc-headers',
'libxpc-static',
'libmagenta',
'librosetta',
'librosetta-interface',
]
[build]
build_system = 'cmake'
[install]
prefix = "/"
# vim: ft=toml
+42
View File
@@ -0,0 +1,42 @@
[target]
name = 'rosetta'
base_components = [
'libmagenta',
'libc',
'libpthread',
'libc-headers',
]
default_prefix = '/usr'
[dependency]
seeds = [
'libfx-host',
'xpcg',
'magenta',
'libmagenta',
'librosetta',
'libc',
'libpthread',
'libc-core',
'libc-io',
'libc-runtime',
'libc-pthread',
'libc-exec',
'libc-malloc',
'librosetta-interface',
'ld',
'bootstrap',
'bshell',
'libfs',
'libxpc',
'libfx',
'base',
'herdd',
'herdd-targets',
'nsd',
'devmd',
'bsp'
]
# vim: ft=toml
@@ -0,0 +1,139 @@
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 4dde5321f23..94c1a871ec2 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -242,7 +242,17 @@ esac
case "${targ}" in
# START OF targmatch.h
+ i[3-7]86-*-rosetta*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs=
+ targ64_selvecs=x86_64_elf64_vec
+ ;;
#ifdef BFD64
+ x86_64-*-rosetta*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
aarch64-*-darwin*)
targ_defvec=aarch64_mach_o_vec
targ_selvecs="arm_mach_o_vec mach_o_le_vec mach_o_be_vec mach_o_fat_vec"
diff --git a/config.sub b/config.sub
index 3d35cde174d..19cd8f07cd7 100755
--- a/config.sub
+++ b/config.sub
@@ -2102,6 +2102,7 @@ case $os in
| rhapsody* \
| riscix* \
| riscos* \
+ | rosetta* \
| rtems* \
| rtmk* \
| rtu* \
diff --git a/gas/configure.tgt b/gas/configure.tgt
index f0ea55d9def..4f194e70501 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -126,6 +126,7 @@ esac
generic_target=${cpu_type}-$vendor-$os
# Note: This table is alpha-sorted, please try to keep it that way.
case ${generic_target} in
+ i386-*-rosetta*) fmt=elf em=gnu;;
aarch64*-*-elf*) fmt=elf;;
aarch64*-*-fuchsia*) fmt=elf;;
aarch64*-*-haiku*) fmt=elf em=haiku ;;
diff --git a/ld/Makefile.am b/ld/Makefile.am
index c219662d2e3..8d17fed7581 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -153,6 +153,7 @@ endif
# These all start with e so 'make clean' can find them.
ALL_EMULATION_SOURCES = \
+ eelf_i386_rosetta.c \
eaix5ppc.c \
eaix5rs6.c \
eaixppc.c \
@@ -373,6 +374,7 @@ ALL_EMULATION_SOURCES = \
ALL_EMULATIONS = $(ALL_EMULATION_SOURCES:.c=.@OBJEXT@)
ALL_64_EMULATION_SOURCES = \
+ eelf_x86_64_rosetta.c \
eaarch64elf.c \
eaarch64elf32.c \
eaarch64elf32b.c \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index f1ba6af5269..a4d76c4cc0b 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -668,6 +668,7 @@ LIBIBERTY = ../libiberty/libiberty.a
# These all start with e so 'make clean' can find them.
ALL_EMULATION_SOURCES = \
+ eelf_i386_rosetta.c \
eaix5ppc.c \
eaix5rs6.c \
eaixppc.c \
@@ -887,6 +888,7 @@ ALL_EMULATION_SOURCES = \
ALL_EMULATIONS = $(ALL_EMULATION_SOURCES:.c=.@OBJEXT@)
ALL_64_EMULATION_SOURCES = \
+ eelf_x86_64_rosetta.c \
eaarch64elf.c \
eaarch64elf32.c \
eaarch64elf32b.c \
@@ -1474,6 +1476,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_rosetta.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_sol2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_vxworks.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_iamcu.Po@am__quote@
@@ -1482,6 +1485,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_rosetta.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_sol2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eh8300elf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eh8300elf_linux.Po@am__quote@
diff --git a/ld/configure.tgt b/ld/configure.tgt
index 3e158913b89..53c091fb78f 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -82,6 +82,13 @@ fi
# Please try to keep this table more or less in alphabetic order - it
# makes it much easier to lookup a specific archictecture.
case "${targ}" in
+i[3-7]86-*-rosetta*) targ_emul=elf_i386_rosetta
+ targ_extra_emuls=elf_i386
+ targ64_extra_emuls="elf_x86_64_rosetta elf_x86_64"
+ ;;
+x86_64-*-rosetta*) targ_emul=elf_x86_64_rosetta
+ targ_extra_emuls="elf_i386_rosetta elf_x86_64 elf_i386"
+ ;;
aarch64_be-*-elf) targ_emul=aarch64elfb
targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b armelfb armelf"
;;
diff --git a/ld/emulparams/elf_i386_rosetta.sh b/ld/emulparams/elf_i386_rosetta.sh
new file mode 100644
index 00000000000..002e918bc53
--- /dev/null
+++ b/ld/emulparams/elf_i386_rosetta.sh
@@ -0,0 +1,4 @@
+source_sh ${srcdir}/emulparams/elf_i386.sh
+TEXT_START_ADDR=0x08000000
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
diff --git a/ld/emulparams/elf_x86_64_rosetta.sh b/ld/emulparams/elf_x86_64_rosetta.sh
new file mode 100644
index 00000000000..4ddde5ab2a5
--- /dev/null
+++ b/ld/emulparams/elf_x86_64_rosetta.sh
@@ -0,0 +1,3 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
@@ -0,0 +1,14 @@
[command]
name = 'build-compiler'
description = 'Build a GCC cross-compiler that targets the Rosetta operating system'
[dependency]
seeds = [
'libc-headers',
'magenta-headers',
]
[exec]
args = [ 'src:build.py']
# vim: ft=toml
+31
View File
@@ -0,0 +1,31 @@
import os
class Builder:
def get_prefix(self):
return os.environ.get('MEADOW_NATIVE_ROOT', None)
def get_target(self):
env = os.environ
target = os.environ.get('MEADOW_TARGET_PLATFORM', None)
parts = target.split('-')
return f'{parts[0]}-rosetta'
def download(self):
pass
def configure(self):
pass
def build(self):
pass
def install(self):
pass
print(f'building cross compiler for {get_gcc_target()}, installed to {get_prefix()}')
@@ -0,0 +1 @@
../binutils-gdb/configure --target=x86_64-rosetta --prefix=/opt/cross-rosetta --with-sysroot=/opt/cross-rosetta --disable-nls --disable-werror --enable-default-execstack=no --with-gmp=/opt/homebrew --enable-shared

Some files were not shown because too many files have changed in this diff Show More