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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [upcalls/] [upcall-basic.c] - Blame information for rev 352

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

Line No. Rev Author Line
1 93 jeremybenn
/* upcall-basic.c. Test of Or1ksim basic handling of upcalls
2
 
3
   Copyright (C) 2010 Embecosm Limited
4
 
5
   Contributors various OpenCores participants
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
22
 
23
/* ----------------------------------------------------------------------------
24
   This code is commented throughout for use with Doxygen.
25
   --------------------------------------------------------------------------*/
26
 
27
#include "support.h"
28
#include "spr-defs.h"
29
#include "board.h"
30
 
31
 
32
/*!Alignment exception handler defined here. */
33
unsigned long excpt_align;
34
 
35
 
36
/* --------------------------------------------------------------------------*/
37
/*!Write a memory mapped byte register
38
 
39
   @param[in] addr   Memory mapped address
40
   @param[in] value  Value to set                                            */
41
/* --------------------------------------------------------------------------*/
42
static void
43
setreg8 (unsigned long int  addr,
44
         unsigned char      value)
45
{
46
  *((volatile unsigned char *) addr) = value;
47
  printf ("Wrote byte at 0x%08lx = 0x%02x.\n", addr, value);
48
 
49
}       /* setreg8 () */
50
 
51
 
52
/* --------------------------------------------------------------------------*/
53
/*!Write a memory mapped half word register
54
 
55
   @param[in] addr   Memory mapped address
56
   @param[in] value  Value to set                                            */
57
/* --------------------------------------------------------------------------*/
58
static void
59
setreg16 (unsigned long int   addr,
60
          unsigned short int  value)
61
{
62
  *((volatile unsigned short int *) addr) = value;
63
  printf ("Wrote half word at 0x%08lx = 0x%04x.\n", addr, value);
64
 
65
}       /* setreg16 () */
66
 
67
 
68
/* --------------------------------------------------------------------------*/
69
/*!Write a memory mapped full word register
70
 
71
   @param[in] addr   Memory mapped address
72
   @param[in] value  Value to set                                            */
73
/* --------------------------------------------------------------------------*/
74
static void
75
setreg32 (unsigned long int  addr,
76
          unsigned long int  value)
77
{
78
  *((volatile unsigned long int *) addr) = value;
79
  printf ("Wrote full word at 0x%08lx = 0x%08lx.\n", addr, value);
80
 
81
}       /* setreg32 () */
82
 
83
 
84
/* --------------------------------------------------------------------------*/
85
/*!Read a memory mapped byte register
86
 
87
   @param[in] addr   Memory mapped address
88
 
89
   @return  Value read                                                       */
90
/* --------------------------------------------------------------------------*/
91
unsigned char
92
getreg8 (unsigned long int  addr)
93
{
94
  unsigned char  res = *((volatile unsigned char *) addr);
95
  printf ("Read byte at 0x%08lx = 0x%02x.\n", addr, res);
96
  return  res;
97
 
98
}       /* getreg8 () */
99
 
100
 
101
/* --------------------------------------------------------------------------*/
102
/*!Read a memory mapped half word register
103
 
104
   @param[in] addr   Memory mapped address
105
 
106
   @return  Value read                                                       */
107
/* --------------------------------------------------------------------------*/
108
unsigned short int
109
getreg16 (unsigned long int  addr)
110
{
111
  unsigned short int  res = *((volatile unsigned short int *) addr);
112
  printf ("Read half word at 0x%08lx = 0x%04x.\n", addr, res);
113
  return  res;
114
 
115
}       /* getreg16 () */
116
 
117
 
118
/* --------------------------------------------------------------------------*/
119
/*!Read a memory mapped full word register
120
 
121
   @param[in] addr   Memory mapped address
122
 
123
   @return  Value read                                                       */
124
/* --------------------------------------------------------------------------*/
125
unsigned long int
126
getreg32 (unsigned long int  addr)
127
{
128
  unsigned long int  res = *((volatile unsigned long int *) addr);
129
  printf ("Read full word at 0x%08lx = 0x%08lx.\n", addr, res);
130
  return  res;
131
 
132
}       /* getreg32 () */
133
 
134
 
135
/* --------------------------------------------------------------------------*/
136
/*! Exception handler for misalignment.
137
 
138
  Notes what has happened.                                                   */
139
/* --------------------------------------------------------------------------*/
140
void align_handler (void)
141
{
142
  printf ("Misaligned access.\n");
143
 
144
}       /* align_handler () */
145
 
146
 
147
/* --------------------------------------------------------------------------*/
148
/*!Main program to read and write memory mapped registers
149
 
150
   All these calls should be correctly aligned, but we set an handler, just in
151
   case.
152
 
153
   @return  The return code from the program (always zero).                  */
154
/* --------------------------------------------------------------------------*/
155
int
156
main ()
157
{
158
  /* Set the exception handler */
159
  printf ("Setting alignment exception handler.\n");
160
  excpt_align = (unsigned long)align_handler;
161
 
162
  /* Write some registers */
163
  printf ("Writing registers.\n");
164
 
165
  /* Byte aligned */
166
  setreg8 (GENERIC_BASE,     0xde);
167
  setreg8 (GENERIC_BASE + 1, 0xad);
168
  setreg8 (GENERIC_BASE + 2, 0xbe);
169
  setreg8 (GENERIC_BASE + 3, 0xef);
170
 
171
  /* Half word aligned */
172
  setreg16 (GENERIC_BASE + 4, 0xbaad);
173
  setreg16 (GENERIC_BASE + 6, 0xf00d);
174
 
175
  /* Full word aligned */
176
  setreg32 (GENERIC_BASE + 8, 0xcafebabe);
177
 
178
  /* Read some registers, but mix up which size from where. */
179
  printf ("Reading registers.\n");
180
 
181
  /* Full word aligned */
182
  (void)getreg32 (GENERIC_BASE + 0);
183
 
184
  /* Byte aligned */
185
  (void)getreg8 (GENERIC_BASE + 4);
186
  (void)getreg8 (GENERIC_BASE + 5);
187
  (void)getreg8 (GENERIC_BASE + 6);
188
  (void)getreg8 (GENERIC_BASE + 7);
189
 
190
  /* Half word aligned */
191
  (void)getreg16 (GENERIC_BASE +  8);
192
  (void)getreg16 (GENERIC_BASE + 10);
193
 
194
  /* All done */
195
  printf ("All done.\n");
196
  report (0xdeaddead);
197
  return 0;
198
 
199
}       /* main () */

powered by: WebSVN 2.1.0

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