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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [cust/] [cust.c] - Blame information for rev 27

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

Line No. Rev Author Line
1 25 julius
/* Test three custom instructions.  */
2
 
3
#include "../support/support.h"
4
 
5
void buserr_except(){}
6
void dpf_except(){}
7
void ipf_except(){}
8
void lpint_except(){}
9
void align_except(){}
10
void illegal_except(){}
11
void hpint_except(){}
12
void dtlbmiss_except(){}
13
void itlbmiss_except(){}
14
void range_except(){}
15
void syscall_except(){}
16
void res1_except(){}
17
void trap_except(){}
18
void res2_except(){}
19
 
20
/* Custom instruction l.cust5: move byte
21
 
22
   Move byte custom instruction moves a least significant byte from source register rB and
23
   combines it with other bytes from source register rA and places combined result into rD. Location
24
   of the placed byte in rD depends on the immediate.
25
*/
26
#define MOVBYTE(dr,sr,sb,i) asm volatile ("l.cust5\t%0,%1,%2,%3,1" : "=r" (dr) : "r" (sr), "r" (sb), "i" (i)); report(dr)
27
 
28
/* Custom instruction l.cust5: set bit
29
 
30
   Take source register rA, set a specified bit to 1 and place result to destination register rD.
31
   Bit to be set is specified with an immediate.
32
*/
33
#define SETBIT(dr,sr,i) asm volatile ("l.cust5\t%0,%1,r0,%2,2" : "=r" (dr) : "r" (sr), "i" (i)); report(dr)
34
 
35
/* Custom instruction l.cust5: clear bit
36
 
37
   Take source register rA, clear a specified bit to 0 and place result to destination register rD.
38
   Bit to be cleared is specified with an immediate.
39
*/
40
#define CLRBIT(dr,sr,i) asm volatile ("l.cust5\t%0,%1,r0,%2,3" : "=r" (dr) : "r" (sr), "i" (i)); report(dr)
41
 
42
/* Test case for "move byte" custom instruction
43
 
44
   Move least significant byte from variable s into different byte positions of variable d.
45
   Every time a byte move is done compute checksum of variable d. Final checksum is used to verify
46
   correct operation.
47
 
48
*/
49
unsigned long test_movbyte()
50
{
51
        unsigned long s, d, r;
52
 
53
        s = 0x12345678;
54
        r = d = 0xaabbccdd;
55
 
56
        MOVBYTE (d, d, s, 0);
57
        r += d;
58
        MOVBYTE (d, d, s, 1);
59
        r += d;
60
        MOVBYTE (d, d, s, 2);
61
        r += d;
62
        MOVBYTE (d, d, s, 3);
63
        r += d;
64
 
65
        return (r);
66
}
67
 
68
/* Test case for "set bit" custom instruction
69
 
70
   Set a couple of bits of variable d to 1.
71
   Every time a bit is set compute checksum of variable d. Final checksum is used to verify
72
   correct operation.
73
 
74
*/
75
unsigned long test_setbit()
76
{
77
        unsigned long d, r;
78
 
79
        r = d = 0x00000000;
80
 
81
        SETBIT  (d, d, 10);
82
        r += d;
83
        SETBIT  (d, d, 15);
84
        r += d;
85
        SETBIT  (d, d, 19);
86
        r += d;
87
        SETBIT  (d, d, 25);
88
        r += d;
89
 
90
        return (r);
91
}
92
 
93
/* Test case for "clear bit" custom instruction
94
 
95
   Clear a couple of bits of variable d to 0.
96
   Every time a bit is cleared compute checksum of variable d. Final checksum is used to verify
97
   correct operation.
98
 
99
*/
100
unsigned long test_clrbit()
101
{
102
        unsigned long d, r;
103
 
104
        r = d = 0xffffffff;
105
 
106
        CLRBIT  (d, d, 10);
107
        r += d;
108
        CLRBIT  (d, d, 15);
109
        r += d;
110
        CLRBIT  (d, d, 19);
111
        r += d;
112
        CLRBIT  (d, d, 25);
113
        r += d;
114
 
115
        return (r);
116
}
117
 
118
int main()
119
{
120
        unsigned long result = 0;
121
 
122
        result += test_movbyte();
123
        result += test_setbit();
124
        result += test_clrbit();
125
 
126
        printf("RESULT: %.8lx\n", result);
127
        report(result);
128
        exit(result);
129
}

powered by: WebSVN 2.1.0

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