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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [c/] [libaemb.h] - Blame information for rev 207

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

Line No. Rev Author Line
1 87 sybreon
/* $Id: libaemb.h,v 1.3 2007-12-16 03:26:37 sybreon Exp $
2 78 sybreon
**
3
** AEMB2 CUSTOM LIBRARY
4
**
5
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
**
7
** This file is part of AEMB.
8
**
9
** AEMB is free software: you can redistribute it and/or modify it
10
** under the terms of the GNU Lesser General Public License as
11
** published by the Free Software Foundation, either version 3 of the
12
** License, or (at your option) any later version.
13
**
14
** AEMB is distributed in the hope that it will be useful, but WITHOUT
15
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
17
** Public License for more details.
18
**
19
** You should have received a copy of the GNU Lesser General Public
20
** License along with AEMB. If not, see <http:**www.gnu.org/licenses/>.
21
*/
22
 
23
#ifndef LIBAEMB_H
24
#define LIBAEMB_H
25
 
26 87 sybreon
#define AEMB_TXE 0x0100
27
#define AEMB_TXP 0x0400
28
#define AEMB_TX0 0x0300
29
#define AEMB_TX1 0x0700
30
#define AEMB_MSK 0x0F00
31 80 sybreon
 
32 87 sybreon
#define AEMB_BIP 0x0008
33
#define AEMB_CCC 0x0004
34
#define AEMB_ITE 0x0002
35
#define AEMB_BLE 0x0001
36 78 sybreon
 
37 87 sybreon
 
38
// Linker symbols
39
extern void* _STACK_SIZE;
40
extern void* _stack_end;
41
 
42
 
43
void aemb_hook_init () asm ("_program_init");
44
void aemb_hook_clean () asm ("_program_clean");
45
 
46 78 sybreon
inline void aemb_enable_interrupt ();
47
inline void aemb_disable_interrupt ();
48
inline int aemb_isthread1();
49
inline int aemb_isthread0();
50 87 sybreon
inline int aemb_isthreaded();
51 78 sybreon
 
52
/*!
53
* Assembly macro to enable MSR_IE
54
*/
55
void aemb_enable_interrupt ()
56
{
57
  int msr, tmp;
58
  asm volatile ("mfs %0, rmsr;"
59
                "ori %1, %0, 0x02;"
60
                "mts rmsr, %1;"
61
                : "=r"(msr)
62
                : "r" (tmp)
63
                );
64
}
65
 
66
/*!
67
* Assembly macro to disable MSR_IE
68
*/
69
void aemb_disable_interrupt ()
70
{
71
  int msr, tmp;
72
  asm volatile ("mfs %0, rmsr;"
73
                "andi %1, %0, 0xFD;"
74
                "mts rmsr, %1;"
75
                : "=r"(msr)
76
                : "r" (tmp)
77
                );
78
}
79
 
80
/*!
81
* Bootstrap Hook Override
82
*/
83
 
84 87 sybreon
void aemb_hook_init ()
85 78 sybreon
{
86 87 sybreon
  int msr, tmp;
87
  int stk_end, stk_siz;
88 80 sybreon
 
89
  /*
90 87 sybreon
  // Check to see if hardware threads are enabled
91
  if (((msr & AEMB_TXE) != AEMB_TXE) ||
92
  // Check to see if second thread is started
93
      ((msr & AEMB_TX1) == AEMB_TX1)) return;
94
  */
95
  //return;
96
  asm volatile ("mfs %0, rmsr;"
97
                // Check for BIP
98
                "andi %1, %0, %5;"
99
                "xori %1, %1, %5;"
100
                "beqi %1, 44;"
101 78 sybreon
 
102 87 sybreon
                // Check for TXE
103
                "andi %1, %0, %2;"
104
                "xori %1, %1, %2;"
105
                "bnei %1, 36;"
106
 
107
                // Check for TX1
108
                "andi %1, %0, %3;"
109
                "xori %1, %1, %3;"
110
                "beqi %1, 20;"
111
 
112
                // reallocate stack pointer for T0
113
                "ori %1, r0, %4;"
114
                "sra %1, %1;"
115
                "rsubk r1, %1, r1;"
116
 
117
                // reboot the machine
118
                //"brki r0, _crtinit;"
119
                "brid 0;"
120 78 sybreon
                "nop;"
121
 
122 87 sybreon
                // clear BIP
123
                "andni %1, %0, %5;"
124
                "mts rmsr, %1;"
125
 
126
                :"=r"(msr), "=r"(tmp)
127
                :"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE), "i"(AEMB_BIP)
128
                );
129 78 sybreon
 
130 87 sybreon
}
131 78 sybreon
 
132 87 sybreon
/*!
133
 Undo the changes made by programme init
134
*/
135 78 sybreon
 
136 87 sybreon
void aemb_hook_clean ()
137
{
138
  int msr, tmp;
139 78 sybreon
  int stk_end, stk_siz;
140
 
141 87 sybreon
  /*
142
  // Check to see if hardware threads are enabled
143
  if (((msr & AEMB_TXE) != AEMB_TXE) ||
144
  // Check to see if second thread is started
145
      ((msr & AEMB_TX1) == AEMB_TX1)) return;
146
  */
147
  return;
148
  asm volatile ("mfs %0, rmsr;"
149
                "andi %1, %0, %2;"
150
                "xori %1, %1, %2;"
151
                "bnei %1, 28;"
152
                "andi %1, %0, %3;"
153
                "xori %1, %1, %3;"
154
                "beqi %1, 16;"
155
 
156
                // reallocate stack pointer for T0
157
                "ori %1, r0, %4;"
158
                "sra %1, %1;"
159
                "addk r1, %1, r1;"
160 78 sybreon
 
161 87 sybreon
                :"=r"(msr), "=r"(tmp)
162
                :"i"(AEMB_TXE), "i"(AEMB_TX1), "i"(&_STACK_SIZE)
163
                );
164 78 sybreon
 
165 87 sybreon
 
166
}
167 78 sybreon
 
168 87 sybreon
/* Checks if it's T1, and returns 0 if true */
169 78 sybreon
 
170
int aemb_isthread1 ()
171
{
172 87 sybreon
  int msr, tmp, res;
173
  asm volatile ("mfs %0, rmsr;"
174
                "andi %1, %0, %3;"
175
                "xori %1, %1, %3;"
176
                :"=r"(msr), "=r"(tmp)
177
                :"i"(AEMB_TXE), "i"(AEMB_TXP)
178
                );
179
  return tmp;
180 78 sybreon
}
181
 
182 87 sybreon
/* Checks if it's T0, and returns 0 if true */
183
 
184 78 sybreon
int aemb_isthread0 ()
185
{
186 87 sybreon
  int msr, tmp, res;
187
  asm volatile ("mfs %0, rmsr;"
188
                "andi %1, %0, %3;"
189
                "xori %1, %1, %2;"
190
                :"=r"(msr), "=r"(tmp)
191
                :"i"(AEMB_TXP), "i"(AEMB_MSK)
192
                );
193
  return tmp;
194 78 sybreon
}
195
 
196 87 sybreon
/* Checks if TXE is available, and returns 0 if true */
197
 
198
int aemb_isthreaded ()
199
{
200
  int msr, tmp, res;
201
  asm volatile ("mfs %0, rmsr;"
202
                "andi %1, %0, %2;"
203
                "xori %1, %1, %2;"
204
                :"=r"(msr), "=r"(tmp)
205
                :"i"(AEMB_TXE), "i"(AEMB_MSK)
206
                );
207
  return tmp;
208
}
209
 
210 78 sybreon
#endif
211
 
212 80 sybreon
/* $Log: not supported by cvs2svn $
213
/* Revision 1.1  2007/12/11 00:44:04  sybreon
214
/* initial import
215
/* */

powered by: WebSVN 2.1.0

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