ci: fix am native tests
Some checks failed
Build abstract machine with nix / build-packages (abstract-machine) (push) Failing after 9s
Build abstract machine with nix / build-packages (nemu) (push) Failing after 6s
Build abstract machine with nix / build-packages (nemu-lib) (push) Failing after 6s
Build abstract machine with nix / build-packages (rv32Cross.abstract-machine) (push) Failing after 6s
Build npc tests / npc-build (flow) (push) Successful in 8s
Build npc tests / npc-build (flow-simlib) (push) Successful in 9s

This commit is contained in:
xinyangli 2024-08-15 11:56:34 +08:00
parent 5ba306c74e
commit acad179de2
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
7 changed files with 49 additions and 47 deletions

View file

@ -21,5 +21,5 @@ set_target_properties(
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
target_link_libraries( target_link_libraries(
am-native am-native
PUBLIC SDL2::SDL2 PUBLIC SDL2::SDL2 dl
PRIVATE klib_interface am_interface) PRIVATE klib_interface am_interface)

View file

@ -1,11 +1,11 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <sys/mman.h> #include "platform.h"
#include <sys/auxv.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <elf.h> #include <elf.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "platform.h" #include <stdlib.h>
#include <sys/auxv.h>
#include <sys/mman.h>
#define MAX_CPU 16 #define MAX_CPU 16
#define TRAP_PAGE_START (void *)0x100000 #define TRAP_PAGE_START (void *)0x100000
@ -102,7 +102,8 @@ static void init_platform() {
uintptr_t pad = (uintptr_t)vaddr & 0xfff; uintptr_t pad = (uintptr_t)vaddr & 0xfff;
void *vaddr_align = vaddr - pad; void *vaddr_align = vaddr - pad;
uintptr_t size = phdr[i].p_memsz + pad; uintptr_t size = phdr[i].p_memsz + pad;
void *temp_mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); void *temp_mem = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert(temp_mem != (void *)-1); assert(temp_mem != (void *)-1);
// save data and bss sections // save data and bss sections
@ -110,11 +111,13 @@ static void init_platform() {
// save the address of mmap() which will be used after munamp(), // save the address of mmap() which will be used after munamp(),
// since calling the library functions requires accessing GOT, which will be unmapped // since calling the library functions requires accessing GOT, which will be unmapped
void *(*mmap_libc)(void *, size_t, int, int, int, off_t) = dlsym(RTLD_NEXT, "mmap"); void *(*mmap_libc)(void *, size_t, int, int, int, off_t) =
dlsym(RTLD_NEXT, "mmap");
assert(mmap_libc != NULL); assert(mmap_libc != NULL);
// load the address of memcpy() on stack, which can still be accessed // load the address of memcpy() on stack, which can still be accessed
// after the data section is unmapped // after the data section is unmapped
void *(*volatile memcpy_libc_temp)(void *, const void *, size_t) = memcpy_libc; void *(*volatile memcpy_libc_temp)(void *, const void *, size_t) =
memcpy_libc;
// unmap the data and bss sections // unmap the data and bss sections
ret2 = munmap(vaddr_align, size); ret2 = munmap(vaddr_align, size);
@ -176,7 +179,8 @@ static void init_platform() {
void __am_exit_platform(int code) { void __am_exit_platform(int code) {
// let Linux clean up other resource // let Linux clean up other resource
extern int __am_mpe_init; extern int __am_mpe_init;
if (__am_mpe_init && cpu_count() > 1) kill(0, SIGKILL); if (__am_mpe_init && cpu_count() > 1)
kill(0, SIGKILL);
exit(code); exit(code);
} }
@ -185,10 +189,12 @@ void __am_pmem_map(void *va, void *pa, int prot) {
int mmap_prot = PROT_NONE; int mmap_prot = PROT_NONE;
// we do not support executable bit, so mark // we do not support executable bit, so mark
// all readable pages executable as well // all readable pages executable as well
if (prot & MMAP_READ) mmap_prot |= PROT_READ | PROT_EXEC; if (prot & MMAP_READ)
if (prot & MMAP_WRITE) mmap_prot |= PROT_WRITE; mmap_prot |= PROT_READ | PROT_EXEC;
void *ret = mmap(va, __am_pgsize, mmap_prot, if (prot & MMAP_WRITE)
MAP_SHARED | MAP_FIXED, pmem_fd, (uintptr_t)(pa - pmem)); mmap_prot |= PROT_WRITE;
void *ret = mmap(va, __am_pgsize, mmap_prot, MAP_SHARED | MAP_FIXED, pmem_fd,
(uintptr_t)(pa - pmem));
assert(ret != (void *)-1); assert(ret != (void *)-1);
} }
@ -205,13 +211,9 @@ void __am_get_intr_sigmask(sigset_t *s) {
memcpy_libc(s, &__am_intr_sigmask, sizeof(__am_intr_sigmask)); memcpy_libc(s, &__am_intr_sigmask, sizeof(__am_intr_sigmask));
} }
int __am_is_sigmask_sti(sigset_t *s) { int __am_is_sigmask_sti(sigset_t *s) { return !sigismember(s, SIGVTALRM); }
return !sigismember(s, SIGVTALRM);
}
void __am_send_kbd_intr() { void __am_send_kbd_intr() { kill(getpid(), SIGUSR1); }
kill(getpid(), SIGUSR1);
}
void __am_pmem_protect() { void __am_pmem_protect() {
// int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_NONE); // int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_NONE);
@ -226,5 +228,4 @@ void __am_pmem_unprotect() {
// This dummy function will be called in trm.c. // This dummy function will be called in trm.c.
// The purpose of this dummy function is to let linker add this file to the object // The purpose of this dummy function is to let linker add this file to the object
// file set. Without it, the constructor of @_init_platform will not be linked. // file set. Without it, the constructor of @_init_platform will not be linked.
void __am_platform_dummy() { void __am_platform_dummy() {}
}

View file

@ -6,7 +6,7 @@ add_library(am-riscv-nemu cte.c start.S trap.S vme.c ${NEMU_SOURCES})
target_compile_options(am-riscv-nemu PRIVATE ${NEMU_COMPILE_OPTIONS} target_compile_options(am-riscv-nemu PRIVATE ${NEMU_COMPILE_OPTIONS}
${RISCV_COMPILE_OPTIONS}) ${RISCV_COMPILE_OPTIONS})
target_link_options(am-riscv-nemu PRIVATE ${NEMU_LINK_OPITIONS} target_link_options(am-riscv-nemu INTERFACE ${NEMU_LINK_OPITIONS}
${RISCV_LINK_OPTIONS}) ${RISCV_LINK_OPTIONS})
target_include_directories(am-riscv-nemu PRIVATE ${NEMU_INCLUDE_DIRECTORIES}) target_include_directories(am-riscv-nemu PRIVATE ${NEMU_INCLUDE_DIRECTORIES})

View file

@ -1,11 +1,12 @@
set(NEMU_COMPILE_OPTIONS -fdata-sections -ffunction-sections) set(NEMU_COMPILE_OPTIONS -fdata-sections -ffunction-sections)
set(NEMU_LINK_OPTIONS set(NEMU_LINK_OPTIONS
-nostartfiles
-nolibc
--defsym=_pmem_start=0x80000000 --defsym=_pmem_start=0x80000000
--defsym=_entry_offset=0x0 --defsym=_entry_offset=0x0
--gc-sections --gc-sections
-e _start) -e
set(NEMU_INCLUDE_DIRECTORIES _start)
${CMAKE_SOURCE_DIR}/am/src/platform/nemu/include) set(NEMU_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/include)
file(GLOB_RECURSE NEMU_SOURCES file(GLOB_RECURSE NEMU_SOURCES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/*.[cS])
${CMAKE_SOURCE_DIR}/am/src/platform/nemu/*.[cS])
set(INCLUDE_LINKER_SCRIPT ON) set(INCLUDE_LINKER_SCRIPT ON)

View file

@ -1,9 +1,10 @@
{ stdenv, { stdenv
lib, , lib
cmake, , cmake
SDL2, , SDL2
isa ? "native", , glibc
platform ? [ ] , isa ? "native"
, platform ? [ ]
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "abstract-machine"; pname = "abstract-machine";

View file

@ -9,7 +9,6 @@ set(SOURCES cpp.c int64.c stdio.c stdlib.c string.c
add_library(klib ${SOURCES}) add_library(klib ${SOURCES})
target_link_libraries(klib PUBLIC am_interface klib_interface) target_link_libraries(klib PUBLIC am_interface klib_interface)
target_compile_options(klib PUBLIC -fno-builtin) target_compile_options(klib PUBLIC -fno-builtin)
target_link_options(klib PUBLIC -nostartfiles -nolibc)
install( install(
TARGETS klib TARGETS klib

View file

@ -11,8 +11,8 @@
url = "git+https://git.xinyang.life/xin/nur.git"; url = "git+https://git.xinyang.life/xin/nur.git";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
# diffu.url = "github:xinyangli/diffu"; diffu.url = "git+https://git.xinyang.life/xin/diffu.git";
# am-kernels.url = "git+https://git.xinyang.life/xin/am-kernels.git"; am-kernels.url = "git+https://git.xinyang.life/xin/am-kernels.git";
}; };
outputs = { self, flake-utils, nixpkgs, nixpkgs-circt162, pre-commit-hooks, nur-xin }@inputs: outputs = { self, flake-utils, nixpkgs, nixpkgs-circt162, pre-commit-hooks, nur-xin }@inputs: