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
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:
parent
5ba306c74e
commit
acad179de2
7 changed files with 49 additions and 47 deletions
|
@ -21,5 +21,5 @@ set_target_properties(
|
|||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(
|
||||
am-native
|
||||
PUBLIC SDL2::SDL2
|
||||
PUBLIC SDL2::SDL2 dl
|
||||
PRIVATE klib_interface am_interface)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <sys/mman.h>
|
||||
#include <sys/auxv.h>
|
||||
#include "platform.h"
|
||||
#include <dlfcn.h>
|
||||
#include <elf.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "platform.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define MAX_CPU 16
|
||||
#define TRAP_PAGE_START (void *)0x100000
|
||||
|
@ -70,12 +70,12 @@ static void init_platform() {
|
|||
assert(ret2 == 0);
|
||||
|
||||
pmem = mmap(PMEM_START, PMEM_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_SHARED | MAP_FIXED, pmem_fd, 0);
|
||||
MAP_SHARED | MAP_FIXED, pmem_fd, 0);
|
||||
assert(pmem != (void *)-1);
|
||||
|
||||
// allocate private per-cpu structure
|
||||
thiscpu = mmap(NULL, sizeof(*thiscpu), PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
assert(thiscpu != (void *)-1);
|
||||
thiscpu->cpuid = 0;
|
||||
thiscpu->vm_head = NULL;
|
||||
|
@ -83,7 +83,7 @@ static void init_platform() {
|
|||
// create trap page to receive syscall and yield by SIGSEGV
|
||||
int sys_pgsz = sysconf(_SC_PAGESIZE);
|
||||
void *ret = mmap(TRAP_PAGE_START, sys_pgsz, PROT_NONE,
|
||||
MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
||||
MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
||||
assert(ret != (void *)-1);
|
||||
|
||||
// save the address of memcpy() in glibc, since it may be linked with klib
|
||||
|
@ -94,7 +94,7 @@ static void init_platform() {
|
|||
Elf64_Phdr *phdr = (void *)getauxval(AT_PHDR);
|
||||
int phnum = (int)getauxval(AT_PHNUM);
|
||||
int i;
|
||||
for (i = 0; i < phnum; i ++) {
|
||||
for (i = 0; i < phnum; i++) {
|
||||
if (phdr[i].p_type == PT_LOAD && (phdr[i].p_flags & PF_W)) {
|
||||
// allocate temporary memory
|
||||
extern char end;
|
||||
|
@ -102,7 +102,8 @@ static void init_platform() {
|
|||
uintptr_t pad = (uintptr_t)vaddr & 0xfff;
|
||||
void *vaddr_align = vaddr - 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);
|
||||
|
||||
// save data and bss sections
|
||||
|
@ -110,11 +111,13 @@ static void init_platform() {
|
|||
|
||||
// save the address of mmap() which will be used after munamp(),
|
||||
// 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);
|
||||
// load the address of memcpy() on stack, which can still be accessed
|
||||
// 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
|
||||
ret2 = munmap(vaddr_align, size);
|
||||
|
@ -122,7 +125,7 @@ static void init_platform() {
|
|||
|
||||
// map the sections again with MAP_SHARED, which will be shared across fork()
|
||||
ret = mmap_libc(vaddr_align, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_SHARED | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
|
||||
MAP_SHARED | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
|
||||
assert(ret == vaddr_align);
|
||||
|
||||
// restore the data in the sections
|
||||
|
@ -176,7 +179,8 @@ static void init_platform() {
|
|||
void __am_exit_platform(int code) {
|
||||
// let Linux clean up other resource
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -185,10 +189,12 @@ void __am_pmem_map(void *va, void *pa, int prot) {
|
|||
int mmap_prot = PROT_NONE;
|
||||
// we do not support executable bit, so mark
|
||||
// all readable pages executable as well
|
||||
if (prot & MMAP_READ) mmap_prot |= PROT_READ | PROT_EXEC;
|
||||
if (prot & MMAP_WRITE) mmap_prot |= PROT_WRITE;
|
||||
void *ret = mmap(va, __am_pgsize, mmap_prot,
|
||||
MAP_SHARED | MAP_FIXED, pmem_fd, (uintptr_t)(pa - pmem));
|
||||
if (prot & MMAP_READ)
|
||||
mmap_prot |= PROT_READ | PROT_EXEC;
|
||||
if (prot & MMAP_WRITE)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -205,26 +211,21 @@ void __am_get_intr_sigmask(sigset_t *s) {
|
|||
memcpy_libc(s, &__am_intr_sigmask, sizeof(__am_intr_sigmask));
|
||||
}
|
||||
|
||||
int __am_is_sigmask_sti(sigset_t *s) {
|
||||
return !sigismember(s, SIGVTALRM);
|
||||
}
|
||||
int __am_is_sigmask_sti(sigset_t *s) { return !sigismember(s, SIGVTALRM); }
|
||||
|
||||
void __am_send_kbd_intr() {
|
||||
kill(getpid(), SIGUSR1);
|
||||
}
|
||||
void __am_send_kbd_intr() { kill(getpid(), SIGUSR1); }
|
||||
|
||||
void __am_pmem_protect() {
|
||||
// int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_NONE);
|
||||
// assert(ret == 0);
|
||||
// int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_NONE);
|
||||
// assert(ret == 0);
|
||||
}
|
||||
|
||||
void __am_pmem_unprotect() {
|
||||
// int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
// assert(ret == 0);
|
||||
// int ret = mprotect(PMEM_START, PMEM_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
// assert(ret == 0);
|
||||
}
|
||||
|
||||
// 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
|
||||
// file set. Without it, the constructor of @_init_platform will not be linked.
|
||||
void __am_platform_dummy() {
|
||||
}
|
||||
void __am_platform_dummy() {}
|
||||
|
|
|
@ -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}
|
||||
${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})
|
||||
|
||||
target_include_directories(am-riscv-nemu PRIVATE ${NEMU_INCLUDE_DIRECTORIES})
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
set(NEMU_COMPILE_OPTIONS -fdata-sections -ffunction-sections)
|
||||
set(NEMU_LINK_OPTIONS
|
||||
-nostartfiles
|
||||
-nolibc
|
||||
--defsym=_pmem_start=0x80000000
|
||||
--defsym=_entry_offset=0x0
|
||||
--gc-sections
|
||||
-e _start)
|
||||
set(NEMU_INCLUDE_DIRECTORIES
|
||||
${CMAKE_SOURCE_DIR}/am/src/platform/nemu/include)
|
||||
file(GLOB_RECURSE NEMU_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/am/src/platform/nemu/*.[cS])
|
||||
-e
|
||||
_start)
|
||||
set(NEMU_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/include)
|
||||
file(GLOB_RECURSE NEMU_SOURCES ${CMAKE_SOURCE_DIR}/am/src/platform/nemu/*.[cS])
|
||||
set(INCLUDE_LINKER_SCRIPT ON)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{ stdenv,
|
||||
lib,
|
||||
cmake,
|
||||
SDL2,
|
||||
isa ? "native",
|
||||
platform ? [ ]
|
||||
{ stdenv
|
||||
, lib
|
||||
, cmake
|
||||
, SDL2
|
||||
, glibc
|
||||
, isa ? "native"
|
||||
, platform ? [ ]
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
pname = "abstract-machine";
|
||||
|
@ -11,7 +12,7 @@ stdenv.mkDerivation {
|
|||
|
||||
src = ./.;
|
||||
|
||||
cmakeFlags = [
|
||||
cmakeFlags = [
|
||||
(lib.cmakeFeature "ISA" isa)
|
||||
] ++ map (p: (lib.cmakeBool "__PLATFORM_${lib.strings.toUpper p}__" true)) platform;
|
||||
|
||||
|
@ -24,7 +25,7 @@ stdenv.mkDerivation {
|
|||
|
||||
buildInputs = [
|
||||
|
||||
] ++ (if isa=="native" then [ SDL2 ] else [ ]);
|
||||
] ++ (if isa == "native" then [ SDL2 ] else [ ]);
|
||||
|
||||
doCheck = true;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ set(SOURCES cpp.c int64.c stdio.c stdlib.c string.c
|
|||
add_library(klib ${SOURCES})
|
||||
target_link_libraries(klib PUBLIC am_interface klib_interface)
|
||||
target_compile_options(klib PUBLIC -fno-builtin)
|
||||
target_link_options(klib PUBLIC -nostartfiles -nolibc)
|
||||
|
||||
install(
|
||||
TARGETS klib
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
url = "git+https://git.xinyang.life/xin/nur.git";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
# diffu.url = "github:xinyangli/diffu";
|
||||
# am-kernels.url = "git+https://git.xinyang.life/xin/am-kernels.git";
|
||||
diffu.url = "git+https://git.xinyang.life/xin/diffu.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:
|
||||
|
|
Loading…
Reference in a new issue