caveat: introduce header guards
[cavatools.git] / caveat / core.h
1 /*
2 Copyright (c) 2020 Peter Hsu. All Rights Reserved. See LICENCE file for details.
3 */
4
5 #pragma once
6
7 #define sex(rd) IR(rd).l = IR(rd).l << 32 >> 32
8 #define zex(rd) IR(rd).ul = IR(rd).ul << 32 >> 32
9 #define box(rd)
10
11 extern unsigned long lrsc_set; // globally shared location for atomic lock
12 extern long regval[];
13
14 struct core_t {
15 struct fifo_t* tb;
16 struct reg_t reg[64]; // Register files, IR[0-31], FR[32-63]
17 #define IR(rn) cpu->reg[rn]
18 #define FR(rn) cpu->reg[rn]
19 Addr_t pc; // Next instruction to be executed
20 Addr_t holding_pc; // For verification tracing
21
22 struct {
23 long coreid;
24 long ustatus;
25 long mcause;
26 Addr_t mepc;
27 long mtval;
28 union {
29 struct {
30 unsigned flags : 5;
31 unsigned rmode : 3;
32 } fcsr;
33 unsigned long fcsr_v;
34 };
35 } state;
36
37 struct {
38 long insn_executed;
39 long start_tick;
40 struct timeval start_timeval;
41 } counter;
42
43 struct {
44 Addr_t breakpoint; /* entrypoint of traced function */
45 long after; /* countdown, negative=start tracing */
46 long every; /* but only trace once per n-1 calls */
47 long skip; /* skip until negative, reset to every */
48 long report;
49 long flags;
50 long quiet;
51 } params;
52 };
53
54
55 extern struct fifo_t verify;
56
57 void init_core(struct core_t* cpu, long start_tick, const struct timeval* start_timeval);
58 int run_program(struct core_t* cpu);
59 int outer_loop(struct core_t* cpu);
60 void fast_sim(struct core_t*, long max_count);
61 void slow_sim(struct core_t*, long max_count);
62 int proxy_ecall( struct core_t* cpu );
63 void proxy_csr( struct core_t* cpu, const struct insn_t* p, int which );
64 void status_report(struct core_t* cpu, FILE*);