OpenCores
URL https://opencores.org/ocsvn/potato/potato/trunk

Subversion Repositories potato

[/] [potato/] [trunk/] [benchmarks/] [potato.h] - Blame information for rev 44

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 skordal
// The Potato Processor
2
// (c) Kristian Klomsten Skordal 2015 <kristian.skordal@wafflemail.net>
3
// Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4
 
5
#ifndef POTATO_H
6
#define POTATO_H
7
 
8
// This file contains various defines neccessary for using the Potato processor
9
// with current RISC-V compilers. It also makes sure that applications keep
10
// working even though the supervisor extension specification should change.
11
 
12
// Control and status registers:
13
#define CSR_SUP0        0x500
14
#define CSR_SUP1        0x501
15
#define CSR_EPC         0x502
16
#define CSR_BADVADDR    0x503
17
#define CSR_EVEC        0x508
18
#define CSR_CAUSE       0x509
19
#define CSR_STATUS      0x50a
20
#define CSR_HARTID      0x50b
21
#define CSR_TOHOST      0x51e
22
#define CSR_FROMHOST    0x51f
23
#define CSR_CYCLE       0xc00
24
#define CSR_CYCLEH      0xc80
25
#define CSR_TIME        0xc01
26
#define CSR_TIMEH       0xc81
27
#define CSR_INSTRET     0xc02
28
#define CSR_INSTRETH    0xc82
29
 
30
// Exception cause values:
31
#define CAUSE_INSTR_MISALIGN    0x00
32
#define CAUSE_INSTR_FETCH       0x01
33
#define CAUSE_INVALID_INSTR     0x02
34
#define CAUSE_SYSCALL           0x06
35
#define CAUSE_BREAKPOINT        0x07
36
#define CAUSE_LOAD_MISALIGN     0x08
37
#define CAUSE_STORE_MISALIGN    0x09
38
#define CAUSE_LOAD_ERROR        0x0a
39
#define CAUSE_STORE_ERROR       0x0b
40
#define CAUSE_FROMHOST          0x1e
41
 
42
#define CAUSE_IRQ_BASE          0x10
43
 
44
// Status register bit indices:
45
#define STATUS_EI       2               // Enable Interrupts
46
#define STATUS_PEI      3               // Previous value of Enable Interrupts
47
#define STATUS_IM_MASK  0x00ff0000      // Interrupt Mask
48
#define STATUS_PIM_MASK 0xff000000      // Previous Interrupt Mask
49
 
50
#define potato_enable_interrupts()      asm volatile("csrsi %[status], 1 << %[ei_bit]\n" \
51
                :: [status] "i" (CSR_STATUS), [ei_bit] "i" (STATUS_EI))
52
#define potato_disable_interrupts()     asm volatile("csrci %[status], 1 << %[ei_bit] | 1 << %[pei_bit]\n" \
53
                :: [status] "i" (CSR_STATUS), [ei_bit] "i" (STATUS_EI), [pei_bit] "i" (STATUS_PEI))
54
 
55
#define potato_enable_irq(n) \
56
        do { \
57
                register uint32_t temp = 0; \
58
                asm volatile( \
59
                        "li %[temp], 1 << %[shift]\n" \
60
                        "csrs %[status], %[temp]\n" \
61
                        :: [temp] "r" (temp), [shift] "i" (n + 16), [status] "i" (CSR_STATUS)); \
62
        } while(0)
63
 
64
#define potato_disable_irq(n) \
65
        do { \
66
                register uint32_t temp = 0; \
67
                asm volatile( \
68
                        "li %[temp], 1 << %[shift]\n" \
69
                        "csrc %[status], %[temp]\n" \
70
                        :: [temp] "r" (temp), [shift] "i" (n + 24), [status] "i" (CSR_STATUS)); \
71
        } while(0)
72
 
73
#define potato_get_badvaddr(n) \
74
        do { \
75 22 skordal
                register uint32_t __temp = 0; \
76 13 skordal
                asm volatile ( \
77 22 skordal
                        "csrr %[temp], %[badvaddr]\n" \
78
                        : [temp] "=r" (__temp) : [badvaddr] "i" (CSR_BADVADDR)); \
79
                n = __temp; \
80 13 skordal
        } while(0)
81
 
82
#endif
83
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.