> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar  1 12:35:11 UTC 2024 x86_64 GNU/Linux
 17:50:37  up   4:56,  2 users,  load average: 0.87, 0.84, 0.60
This commit is contained in:
tracer-ysyx 2024-03-20 17:50:37 +08:00 committed by xinyangli
parent 48786c9988
commit 5eb7785adf
3 changed files with 28 additions and 6 deletions

View file

@ -9,8 +9,10 @@ typedef struct {
char * name;
} func_t;
func_t *func_table;
const char *get_func_name(vaddr_t addr);
extern func_t *func_table;
void ftrace_call(vaddr_t);
void ftrace_return(vaddr_t);
// const char *get_func_name(vaddr_t addr);
#endif
#endif

View file

@ -18,6 +18,7 @@
#include <cpu/cpu.h>
#include <cpu/ifetch.h>
#include <cpu/decode.h>
#include <ftrace.h>
#define R(i) gpr(i)
#define Mr vaddr_read
@ -59,6 +60,16 @@ static void do_branch(Decode *s, bool condition, word_t offset) {
}
}
static void ftrace(Decode *s, int rd, vaddr_t dst) {
uint32_t i = s->isa.inst.val;
int rs1 = BITS(i, 19, 15);
if(rs1 == 1 && rd == 0) {
ftrace_return(dst);
} else {
ftrace_call(dst);
}
}
static int decode_exec(Decode *s) {
int rd = 0;
word_t src1 = 0, src2 = 0, imm = 0;
@ -74,8 +85,8 @@ static int decode_exec(Decode *s) {
INSTPAT("??????? ????? ????? ??? ????? 01101 11", lui , U, R(rd) = imm);
INSTPAT("??????? ????? ????? ??? ????? 00101 11", auipc , U, R(rd) = s->pc + imm);
INSTPAT("??????? ????? ????? ??? ????? 11011 11", jal , J, do {s->dnpc = s->pc + imm; R(rd) = s->pc + 4; } while(0));
INSTPAT("??????? ????? ????? ??? ????? 11001 11", jalr , I, do {s->dnpc = src1 + imm; R(rd) = s->pc + 4; } while(0));
INSTPAT("??????? ????? ????? ??? ????? 11011 11", jal , J, do {s->dnpc = s->pc + imm; R(rd) = s->pc + 4; ftrace_call(s->pc + imm); } while(0));
INSTPAT("??????? ????? ????? ??? ????? 11001 11", jalr , I, do {s->dnpc = src1 + imm; R(rd) = s->pc + 4; ftrace(s, rd, src1 + imm); } while(0));
INSTPAT("??????? ????? ????? 000 ????? 11000 11", beq , B, do_branch(s, src1 == src2, imm));
INSTPAT("??????? ????? ????? 001 ????? 11000 11", bne , B, do_branch(s, src1 != src2, imm));
INSTPAT("??????? ????? ????? 100 ????? 11000 11", blt , B, do_branch(s, (sword_t)src1 < (sword_t)src2, imm));

View file

@ -2,7 +2,7 @@
#include <assert.h>
#include <common.h>
#include <elf.h>
#include <func.h>
#include <ftrace.h>
// Put this into another file
#ifdef CONFIG_FTRACE
@ -16,7 +16,7 @@ static int cmp_func_t(const void *a, const void *b) {
return ((func_t *)a)->start > ((func_t *)b)->start;
}
const char *get_func_name(vaddr_t addr) {
static const char *get_func_name(vaddr_t addr) {
int l = 0, r = func_table_len - 1;
while(l <= r) {
int mid = (l + r) / 2;
@ -98,3 +98,12 @@ failed_nosym:
Error("Failed reading elf file");
return;
}
void ftrace_call(vaddr_t addr) {
printf("call [%s@0x%x]", get_func_name(addr), addr);
}
void ftrace_return(vaddr_t addr) {
printf("ret [%s@0x%x]", get_func_name(addr), addr);
}