OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_processor/] [aeMB/] [sw/] [aemb/] [hook.cc] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/* $Id: hook.hh,v 1.11 2008-04-28 20:31:40 sybreon Exp $
2
**
3
** AEMB2 HI-PERFORMANCE CPU
4
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17
**
18
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21
 
22
/**
23
   Basic begin/end hooks
24
   @file hook.hh
25
 
26
   These routines hook themselves onto parts of the main programme to
27
   enable the hardware threads to work properly.
28
 */
29
 
30
#include "stack.hh"
31
#include "heap.hh"
32
#include "thread.hh"
33
 
34
#ifndef _AEMB_HOOK_HH
35
#define _AEMB_HOOK_HH
36
 
37
#ifdef __cplusplus
38
extern "C" {
39
#endif
40
 
41
 
42
 
43
  /**
44
     Finalisation hook
45
 
46
     This function executes during the shutdown phase after the
47
     finalisation routine is called. It will merge the changes made
48
     during initialisation.
49
  */
50
 
51
  void _program_clean()
52
  {
53
    _aembLockMTX(); // enter critical section
54
 
55
    // unify the stack backwards
56
    if (aembIsThread0())
57
      {
58
        aembSetStack(aembGetStack() + (aembGetStackSize() >> 1));
59
      }
60
 
61
    _aembFreeMTX(); // exit critical section
62
  }
63
 
64
  /**
65
     Initialisation hook
66
 
67
     This function executes during the startup phase before the
68
     initialisation routine is called. It splits the stack between the
69
     threads. For now, it will lock up T0 for compatibility purposes.
70
  */
71
 
72
  void _program_init()
73
  {
74
    _aembLockMTX(); // enter critical section
75
 
76
    // split and shift the stack for thread 1
77
    if (aembIsThread0()) // main thread
78
      {
79
        // NOTE: Dupe the stack otherwise it will FAIL! 
80
        int oldstk = aembGetStack();
81
        int newstk = aembSetStack(aembGetStack() - (aembGetStackSize() >> 1));
82
        aembDupStack((unsigned int *)newstk,
83
                     (unsigned int *)oldstk,
84
                     (unsigned int *)aembGetStackTop());
85
        _aembFreeMTX(); // exit critical section
86
        while (1) asm volatile ("nop"); // lock thread
87
      }
88
 
89
    _aembFreeMTX(); // exit critical section
90
  }
91
 
92
  /**
93
     Heap Lock
94
 
95
     This function is called during malloc() to lock out the shared
96
     heap to avoid data corruption.
97
   */
98
 
99
  void __malloc_lock(struct _reent *reent)
100
  {
101
    _aembLockMTX();
102
  }
103
 
104
  /**
105
     Heap Unlock
106
 
107
     This function is called during malloc() to indicate that the
108
     shared heap is now available for another thread.
109
  */
110
 
111
  void __malloc_unlock(struct _reent *reent)
112
  {
113
    _aembFreeMTX();
114
  }
115
 
116
#ifdef __cplusplus
117
}
118
#endif
119
 
120
#endif
121
 
122
#ifndef __OPTIMIZE__
123
// The main programme needs to be compiled with optimisations turned
124
// on (at least -O1). If not, the MUTEX value will be written to the
125
// same RAM location, giving both threads the same value.
126
OPTIMISATION_REQUIRED OPTIMISATION_REQUIRED
127
#endif
128
 
129
/*
130
  $Log: not supported by cvs2svn $
131
  Revision 1.10  2008/04/28 20:29:15  sybreon
132
  Made files C compatible under C++.
133
 
134
  Revision 1.9  2008/04/27 16:33:42  sybreon
135
  License change to GPL3.
136
 
137
  Revision 1.8  2008/04/27 16:04:42  sybreon
138
  Minor cosmetic changes.
139
 
140
  Revision 1.7  2008/04/26 19:31:35  sybreon
141
  Made headers C compatible.
142
 
143
  Revision 1.6  2008/04/26 18:04:31  sybreon
144
  Updated software to freeze T0 and run T1.
145
 
146
  Revision 1.5  2008/04/23 14:19:39  sybreon
147
  Fixed minor bugs.
148
  Initial use of hardware mutex.
149
 
150
  Revision 1.4  2008/04/20 16:35:53  sybreon
151
  Added C/C++ compatible #ifdef statements
152
 
153
  Revision 1.3  2008/04/12 13:46:02  sybreon
154
  Added malloc() lock and unlock routines
155
 
156
  Revision 1.2  2008/04/11 15:20:31  sybreon
157
  added static assert hack
158
 
159
  Revision 1.1  2008/04/09 19:48:37  sybreon
160
  Added new C++ files
161
 
162
*/

powered by: WebSVN 2.1.0

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