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

Subversion Repositories potato

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

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 45 skordal
#define potato_write_host(data) \
56
        do { \
57
                register uint32_t temp = data; \
58
                asm volatile("csrw %[tohost], %[temp]\n" \
59
                        :: [tohost] "i" (CSR_TOHOST), [temp] "r" (temp)); \
60
        } while(0);
61
 
62 13 skordal
#define potato_enable_irq(n) \
63
        do { \
64
                register uint32_t temp = 0; \
65
                asm volatile( \
66
                        "li %[temp], 1 << %[shift]\n" \
67
                        "csrs %[status], %[temp]\n" \
68
                        :: [temp] "r" (temp), [shift] "i" (n + 16), [status] "i" (CSR_STATUS)); \
69
        } while(0)
70
 
71
#define potato_disable_irq(n) \
72
        do { \
73
                register uint32_t temp = 0; \
74
                asm volatile( \
75
                        "li %[temp], 1 << %[shift]\n" \
76
                        "csrc %[status], %[temp]\n" \
77
                        :: [temp] "r" (temp), [shift] "i" (n + 24), [status] "i" (CSR_STATUS)); \
78
        } while(0)
79
 
80
#define potato_get_badvaddr(n) \
81
        do { \
82 22 skordal
                register uint32_t __temp = 0; \
83 13 skordal
                asm volatile ( \
84 22 skordal
                        "csrr %[temp], %[badvaddr]\n" \
85
                        : [temp] "=r" (__temp) : [badvaddr] "i" (CSR_BADVADDR)); \
86
                n = __temp; \
87 13 skordal
        } while(0)
88
 
89
#endif
90
 

powered by: WebSVN 2.1.0

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