Skip to content

Commit

Permalink
Merge pull request #1191 from avdgrinten/managarm-riscv
Browse files Browse the repository at this point in the history
sysdeps/managarm: Fix crti.S + crtn.S and sys_tcb_set()
  • Loading branch information
avdgrinten authored Nov 28, 2024
2 parents b115980 + 53c05fa commit 8487c65
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
builds: mlibc
compiler: clang
name: Build mlibc
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: ghcr.io/managarm/mlibc-crossers:latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-libc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [pull_request, merge_group]
jobs:
check-bindings:
name: Verify bindings generation
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: ghcr.io/managarm/mlibc-crossers:latest
steps:
Expand Down
35 changes: 19 additions & 16 deletions sysdeps/linux/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,26 @@ if not headers_only
install_dir: get_option('libdir')
)

custom_target('crti',
build_by_default: true,
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
input: host_machine.cpu_family() / 'crt-src/crti.S',
output: 'crti.o',
install: true,
install_dir: get_option('libdir')
)
# On RISC-V, crti.o and crtn.o are provided by GCC.
if host_machine.cpu_family() != 'riscv64'
custom_target('crti',
build_by_default: true,
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
input: host_machine.cpu_family() / 'crt-src/crti.S',
output: 'crti.o',
install: true,
install_dir: get_option('libdir')
)

custom_target('crtn',
build_by_default: true,
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
input: host_machine.cpu_family() / 'crt-src/crtn.S',
output: 'crtn.o',
install: true,
install_dir: get_option('libdir')
)
custom_target('crtn',
build_by_default: true,
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
input: host_machine.cpu_family() / 'crt-src/crtn.S',
output: 'crtn.o',
install: true,
install_dir: get_option('libdir')
)
endif

wrapper_conf = configuration_data()
wrapper_conf.set('LIBDIR', get_option('libdir'))
Expand Down
11 changes: 0 additions & 11 deletions sysdeps/linux/riscv64/crt-src/crti.S

This file was deleted.

7 changes: 0 additions & 7 deletions sysdeps/linux/riscv64/crt-src/crtn.S

This file was deleted.

10 changes: 0 additions & 10 deletions sysdeps/managarm/riscv64/crt-src/crti.S
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
.section .init
.global _init
_init:
unimp

.section .fini
.global _fini
_fini:
unimp
.section .note.GNU-stack,"",%progbits

6 changes: 0 additions & 6 deletions sysdeps/managarm/riscv64/crt-src/crtn.S
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
.section .init
unimp

.section .fini
unimp
.section .note.GNU-stack,"",%progbits

9 changes: 7 additions & 2 deletions sysdeps/managarm/rtld-generic/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ HelHandleResult *parseHandle(void *&element) {
namespace mlibc {

int sys_tcb_set(void *pointer) {
#if defined(__aarch64__)
#if defined(__x86_64__)
HEL_CHECK(helWriteFsBase(pointer));
#elif defined(__aarch64__)
uintptr_t addr = reinterpret_cast<uintptr_t>(pointer);
addr += sizeof(Tcb) - 0x10;
asm volatile ("msr tpidr_el0, %0" :: "r"(addr));
#elif defined(__riscv) && __riscv_xlen == 64
uintptr_t tp = reinterpret_cast<uintptr_t>(pointer) + sizeof(Tcb);
asm volatile ("mv tp, %0" : : "r"(tp) : "memory");
#else
HEL_CHECK(helWriteFsBase(pointer));
#error Unknown architecture
#endif
return 0;
}
Expand Down

0 comments on commit 8487c65

Please sign in to comment.