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.hh] - Blame information for rev 17

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

Line No. Rev Author Line
1 17 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 
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 .
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
    void _program_init();
42
    void _program_clean();
43
 
44
    // newlib locks
45
    void __malloc_lock(struct _reent *reent);
46
    void __malloc_unlock(struct _reent *reent);
47
    //void __env_lock(struct _reent *reent);
48
    //void __env_unlock(struct _reent *reent);
49
 
50
  /**
51
     Finalisation hook
52
 
53
     This function executes during the shutdown phase after the
54
     finalisation routine is called. It will merge the changes made
55
     during initialisation.
56
  */
57
 
58
  void _program_clean()
59
  {
60
    _aembLockMTX(); // enter critical section
61
 
62
    // unify the stack backwards
63
    if (aembIsThread0())
64
      {
65
        aembSetStack(aembGetStack() + (aembGetStackSize() >> 1));
66
      }
67
 
68
    _aembFreeMTX(); // exit critical section
69
  }
70
 
71
  /**
72
     Initialisation hook
73
 
74
     This function executes during the startup phase before the
75
     initialisation routine is called. It splits the stack between the
76
     threads. For now, it will lock up T0 for compatibility purposes.
77
  */
78
 
79
  void _program_init()
80
  {
81
    _aembLockMTX(); // enter critical section
82
 
83
    // split and shift the stack for thread 1
84
    if (aembIsThread0()) // main thread
85
      {
86
        // NOTE: Dupe the stack otherwise it will FAIL!
87
        int oldstk = aembGetStack();
88
        int newstk = aembSetStack(aembGetStack() - (aembGetStackSize() >> 1));
89
        aembDupStack((unsigned int *)newstk,
90
                     (unsigned int *)oldstk,
91
                     (unsigned int *)aembGetStackTop());
92
        _aembFreeMTX(); // exit critical section
93
        while (1) asm volatile ("nop"); // lock thread
94
      }
95
 
96
    _aembFreeMTX(); // exit critical section
97
  }
98
 
99
  /**
100
     Heap Lock
101
 
102
     This function is called during malloc() to lock out the shared
103
     heap to avoid data corruption.
104
   */
105
 
106
  void __malloc_lock(struct _reent *reent)
107
  {
108
    _aembLockMTX();
109
  }
110
 
111
  /**
112
     Heap Unlock
113
 
114
     This function is called during malloc() to indicate that the
115
     shared heap is now available for another thread.
116
  */
117
 
118
  void __malloc_unlock(struct _reent *reent)
119
  {
120
    _aembFreeMTX();
121
  }
122
 
123
#ifdef __cplusplus
124
}
125
#endif
126
 
127
#endif
128
 
129
#ifndef __OPTIMIZE__
130
// The main programme needs to be compiled with optimisations turned
131
// on (at least -O1). If not, the MUTEX value will be written to the
132
// same RAM location, giving both threads the same value.
133
OPTIMISATION_REQUIRED OPTIMISATION_REQUIRED
134
#endif
135
 
136
/*
137
  $Log: not supported by cvs2svn $
138
  Revision 1.10  2008/04/28 20:29:15  sybreon
139
  Made files C compatible under C++.
140
 
141
  Revision 1.9  2008/04/27 16:33:42  sybreon
142
  License change to GPL3.
143
 
144
  Revision 1.8  2008/04/27 16:04:42  sybreon
145
  Minor cosmetic changes.
146
 
147
  Revision 1.7  2008/04/26 19:31:35  sybreon
148
  Made headers C compatible.
149
 
150
  Revision 1.6  2008/04/26 18:04:31  sybreon
151
  Updated software to freeze T0 and run T1.
152
 
153
  Revision 1.5  2008/04/23 14:19:39  sybreon
154
  Fixed minor bugs.
155
  Initial use of hardware mutex.
156
 
157
  Revision 1.4  2008/04/20 16:35:53  sybreon
158
  Added C/C++ compatible #ifdef statements
159
 
160
  Revision 1.3  2008/04/12 13:46:02  sybreon
161
  Added malloc() lock and unlock routines
162
 
163
  Revision 1.2  2008/04/11 15:20:31  sybreon
164
  added static assert hack
165
 
166
  Revision 1.1  2008/04/09 19:48:37  sybreon
167
  Added new C++ files
168
 
169
*/

powered by: WebSVN 2.1.0

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