forked from beehive-lab/Maxine-VM
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[riscv][wip] Added skeleton substrate for RISC-V.
- Loading branch information
1 parent
bdf8577
commit ac957c1
Showing
12 changed files
with
360 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (c) 2017-2018, APT Group, School of Computer Science, | ||
* The University of Manchester. All rights reserved. | ||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#include "isa.h" | ||
#include "log.h" | ||
|
||
void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_CanonicalIntegerRegisters c) { | ||
|
||
#if os_LINUX | ||
#define CANONICALIZE(reg) c->x##reg = (Word) os->regs[reg] | ||
#else | ||
#define CANONICALIZE(reg, ucReg) c_UNIMPLEMENTED() | ||
#endif | ||
|
||
// CANONICALIZE(0); | ||
CANONICALIZE(1); | ||
// CANONICALIZE(2); this is SP | ||
CANONICALIZE(3); | ||
CANONICALIZE(4); | ||
CANONICALIZE(5); | ||
CANONICALIZE(6); | ||
CANONICALIZE(7); | ||
CANONICALIZE(8); | ||
CANONICALIZE(9); | ||
CANONICALIZE(10); | ||
CANONICALIZE(11); | ||
CANONICALIZE(12); | ||
CANONICALIZE(13); | ||
CANONICALIZE(14); | ||
CANONICALIZE(15); | ||
CANONICALIZE(16); | ||
CANONICALIZE(17); | ||
CANONICALIZE(18); | ||
CANONICALIZE(19); | ||
CANONICALIZE(20); | ||
CANONICALIZE(21); | ||
CANONICALIZE(22); | ||
CANONICALIZE(23); | ||
CANONICALIZE(24); | ||
CANONICALIZE(25); | ||
CANONICALIZE(26); | ||
CANONICALIZE(27); | ||
CANONICALIZE(28); | ||
CANONICALIZE(29); | ||
CANONICALIZE(30); | ||
CANONICALIZE(31); | ||
|
||
#undef CANONICALIZE | ||
} | ||
|
||
void isa_canonicalizeTeleFloatingPointRegisters(isa_OsTeleFloatingPointRegisters os, isa_CanonicalFloatingPointRegisters c) { | ||
log_println("Riscv64: isa_canonicalizeTeleFloatingPointRegisters is not implemented!"); | ||
} | ||
|
||
void isa_canonicalizeTeleStateRegisters(isa_OsTeleStateRegisters os, isa_CanonicalStateRegisters c) { | ||
c->sp = (Word) os->regs[2]; | ||
c->pc = (Word) os->pc; | ||
// TODO ask about this. Not sure what it is. | ||
// c->pstate = (Word) os->pstate; | ||
} | ||
|
||
void isa_printCanonicalIntegerRegisters(isa_CanonicalIntegerRegisters c) { | ||
#define PRINT_REG(reg) log_println(#reg " = %p [%ld]", c->reg, c->reg) | ||
|
||
// PRINT_REG(r0); | ||
PRINT_REG(x1); | ||
// PRINT_REG(x2); // This is SP | ||
PRINT_REG(x3); | ||
PRINT_REG(x4); | ||
PRINT_REG(x5); | ||
PRINT_REG(x6); | ||
PRINT_REG(x7); | ||
PRINT_REG(x8); | ||
PRINT_REG(x9); | ||
PRINT_REG(x10); | ||
PRINT_REG(x11); | ||
PRINT_REG(x12); | ||
PRINT_REG(x13); | ||
PRINT_REG(x14); | ||
PRINT_REG(x15); | ||
PRINT_REG(x16); | ||
PRINT_REG(x17); | ||
PRINT_REG(x18); | ||
PRINT_REG(x19); | ||
PRINT_REG(x20); | ||
PRINT_REG(x21); | ||
PRINT_REG(x22); | ||
PRINT_REG(x23); | ||
PRINT_REG(x24); | ||
PRINT_REG(x25); | ||
PRINT_REG(x26); | ||
PRINT_REG(x27); | ||
PRINT_REG(x28); | ||
PRINT_REG(x29); | ||
PRINT_REG(x30); | ||
PRINT_REG(x31); | ||
|
||
#undef PRINT_REG | ||
} | ||
|
||
void isa_printCanonicalFloatingPointRegisters(isa_CanonicalFloatingPointRegisters c) { | ||
log_println("Riscv64: isa_printCanonicalFloatingPointRegisters is not implemented!"); | ||
} | ||
|
||
void isa_printCanonicalStateRegisters(isa_CanonicalStateRegisters canonicalStateRegisters) { | ||
log_println("sp = %p [%ld]", canonicalStateRegisters->sp, canonicalStateRegisters->sp); | ||
log_println("pc = %p [%ld]", canonicalStateRegisters->pc, canonicalStateRegisters->pc); | ||
// log_println("pstate = %p [%ld]", canonicalStateRegisters->pstate, canonicalStateRegisters->pstate); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2017-2018, APT Group, School of Computer Science, | ||
* The University of Manchester. All rights reserved. | ||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#ifndef __riscv64_h__ | ||
#define __riscv64_h__ 1 | ||
|
||
#include "word.h" | ||
|
||
#if os_LINUX | ||
# include <sys/ucontext.h> | ||
# include <sys/user.h> | ||
// For some reason sys/user.h for RISC-V lacks definitions of user_regs_struct and user_fpsimd_struct. We have to manually define those in our own userriscv64.h | ||
# include "userriscv64.h" | ||
typedef struct user_regs_struct *riscv64_OsTeleIntegerRegisters; | ||
typedef struct user_fpsimd_struct *riscv64_OsTeleFloatingPointRegisters; | ||
typedef struct user_regs_struct *riscv64_OsTeleStateRegisters; | ||
typedef struct { | ||
Word low; | ||
Word high; | ||
}XMMRegister; | ||
#else | ||
# error | ||
#endif | ||
typedef struct riscv64_CanonicalIntegerRegisters { | ||
Word x1; | ||
Word x2; | ||
Word x3; | ||
Word x4; | ||
Word x5; | ||
Word x6; | ||
Word x7; | ||
Word x8; | ||
Word x9; | ||
Word x10; | ||
Word x11; | ||
Word x12; | ||
Word x13; | ||
Word x14; | ||
Word x15; | ||
Word x16; | ||
Word x17; | ||
Word x18; | ||
Word x19; | ||
Word x20; | ||
Word x21; | ||
Word x22; | ||
Word x23; | ||
Word x24; | ||
Word x25; | ||
Word x26; | ||
Word x27; | ||
Word x28; | ||
Word x29; | ||
Word x30; | ||
Word x31; | ||
} riscv64_CanonicalIntegerRegistersAggregate, *riscv64_CanonicalIntegerRegisters; | ||
typedef struct riscv64_CanonicalFloatingPointRegisters { | ||
Word f0; | ||
Word f1; | ||
Word f2; | ||
Word f3; | ||
Word f4; | ||
Word f5; | ||
Word f6; | ||
Word f7; | ||
Word f8; | ||
Word f9; | ||
Word f10; | ||
Word f11; | ||
Word f12; | ||
Word f13; | ||
Word f14; | ||
Word f15; | ||
Word f16; | ||
Word f17; | ||
Word f18; | ||
Word f19; | ||
Word f20; | ||
Word f21; | ||
Word f22; | ||
Word f23; | ||
Word f24; | ||
Word f25; | ||
Word f26; | ||
Word f27; | ||
Word f28; | ||
Word f29; | ||
Word f30; | ||
Word f31; | ||
} riscv64_CanonicalFloatingRegistersAggregate, *riscv64_CanonicalFloatingPointRegisters; | ||
|
||
typedef struct riscv64_CanonicalStateRegisters { | ||
Word sp; | ||
union { | ||
Word pc; | ||
Word rip; | ||
}; | ||
// Word pstate; | ||
} riscv64_CanonicalStateRegistersAggregate, *riscv64_CanonicalStateRegisters; | ||
|
||
extern void riscv64_canonicalizeTeleIntegerRegisters(riscv64_OsTeleIntegerRegisters, riscv64_CanonicalIntegerRegisters); | ||
|
||
extern void riscv64_canonicalizeTeleFloatingPointRegisters(riscv64_OsTeleFloatingPointRegisters, riscv64_CanonicalFloatingPointRegisters); | ||
|
||
extern void riscv64_canonicalizeTeleStateRegisters(riscv64_OsTeleStateRegisters osTeleStateRegisters, riscv64_CanonicalStateRegisters canonicalStateRegisters); | ||
|
||
extern void riscv64_printCanonicalIntegerRegisters(riscv64_CanonicalIntegerRegisters canonicalIntegerRegisters); | ||
|
||
extern void riscv64_printCanonicalFloatingPointRegisters(riscv64_CanonicalFloatingPointRegisters canonicalFloatingPointRegisters); | ||
|
||
extern void riscv64_printCanonicalStateRegisters(riscv64_CanonicalStateRegisters canonicalStateRegisters); | ||
#endif /*__riscv64__*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// TODO: check this is actually working. | ||
// This file has been adapted from https://github.com/riscv/riscv-glibc/blob/riscv-glibc-2.26/sysdeps/unix/sysv/linux/aarch64/sys/user.h | ||
|
||
#define STRINGIFY(s) XSTRINGIFY(s) | ||
#define XSTRINGIFY(s) #s | ||
|
||
// #pragma message ("_SYS_USER_H=" STRINGIFY(_SYS_USER_H)) | ||
|
||
#ifndef _SYS_USER_H | ||
#define _SYS_USER_H 1 | ||
#endif | ||
|
||
#ifndef CREATED_REG_DESCRIPTION | ||
#define CREATED_REG_DESCRIPTION 1 | ||
|
||
// #pragma message ("INSIDEEEEEE") | ||
|
||
struct user_regs_struct | ||
{ | ||
unsigned long long regs[31]; | ||
// unsigned long long sp; | ||
unsigned long long pc; | ||
// unsigned long long pstate; | ||
}; | ||
|
||
struct user_fpsimd_struct | ||
{ | ||
__uint128_t vregs[32]; | ||
// unsigned int fpsr; | ||
// unsigned int fpcr; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.