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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [hook.hh] - Blame information for rev 128

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

Line No. Rev Author Line
1 128 sybreon
/* $Id: hook.hh,v 1.5 2008-04-23 14:19:39 sybreon Exp $
2 107 sybreon
**
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 Lesser General Public License as
10
** published by the Free Software Foundation, either version 3 of the
11
** License, or (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 Lesser General
16
** Public License for more details.
17
**
18
** You should have received a copy of the GNU Lesser General Public
19
** License along with AEMB. If not, see .
20
*/
21
 
22
/**
23
   Basic begin/end hooks
24
   @file hook.hh
25
 
26 116 sybreon
   These routines hook themselves onto parts of the main programme to
27
   enable the hardware threads to work properly.
28 107 sybreon
 */
29
 
30
#include "aemb/stack.hh"
31
#include "aemb/heap.hh"
32
#include "aemb/thread.hh"
33
 
34
#ifndef AEMB_HOOK_HH
35
#define AEMB_HOOK_HH
36
 
37 121 sybreon
#ifdef __cplusplus
38 107 sybreon
namespace aemb {
39 121 sybreon
  extern "C" {
40
    void _program_init();
41
    void _program_clean();
42
    void __malloc_lock();
43
    void __malloc_unlock();
44
    void __env_lock();
45
    void __env_unlock();
46 128 sybreon
 
47 121 sybreon
  }
48
#else
49
  void _program_init();
50
  void _program_clean();
51
  void __malloc_lock();
52
  void __malloc_unlock();
53
  void __env_lock();
54
  void __env_unlock();
55 128 sybreon
#endif
56 107 sybreon
 
57
  /**
58 116 sybreon
     Finalisation hook
59
 
60
     This function executes during the shutdown phase after the
61
     finalisation routine is called. It will merge the changes made
62
     during initialisation.
63 121 sybreon
  */
64 111 sybreon
  void _program_clean()
65 107 sybreon
  {
66 121 sybreon
    waitMutex(); // enter critical section
67
 
68 116 sybreon
    // unify the stack backwards for thread 1
69 121 sybreon
    if (isThread1())
70
      {
71
        setStack(getStack() + (getStackSize() >> 1));
72 128 sybreon
      }
73 121 sybreon
 
74
    signalMutex(); // exit critical section
75 107 sybreon
  }
76
 
77
  /**
78 116 sybreon
     Initialisation hook
79 107 sybreon
 
80 116 sybreon
     This function executes during the startup phase before the
81
     initialisation routine is called. It splits the stack between the
82
     threads.
83 121 sybreon
  */
84 111 sybreon
  void _program_init()
85 107 sybreon
  {
86 121 sybreon
    waitMutex(); // enter critical section
87
 
88 116 sybreon
    // split and shift the stack for thread 1
89 121 sybreon
    if (isThread1())
90 116 sybreon
      {
91 128 sybreon
        setStack(getStack() - (getStackSize() >> 1));
92 116 sybreon
      }
93 121 sybreon
 
94
    signalMutex(); // exit critical section
95 107 sybreon
  }
96
 
97 128 sybreon
  semaphore __malloc_mutex = 1;
98
 
99 116 sybreon
  /**
100
     Heap Lock
101
 
102
     This function is called during malloc() to lock out the shared
103
     heap to avoid data corruption.
104
   */
105
  void __malloc_lock()
106
  {
107 128 sybreon
    waitMutex();
108 116 sybreon
  }
109
 
110
  /**
111
     Heap Unlock
112
 
113
     This function is called during malloc() to indicate that the
114
     shared heap is now available for another thread.
115
  */
116
  void __malloc_unlock()
117
  {
118 121 sybreon
    signalMutex();
119 116 sybreon
  }
120 121 sybreon
 
121
#ifdef __cplusplus
122 116 sybreon
}
123 121 sybreon
#endif
124 116 sybreon
 
125 107 sybreon
#endif
126
 
127 116 sybreon
#ifndef __OPTIMIZE__
128
// The main programme needs to be compiled with optimisations turned
129
// on (at least -O1).
130
OPTIMISATION_REQUIRED XXX
131
#endif
132
 
133 107 sybreon
/*
134
  $Log: not supported by cvs2svn $
135 128 sybreon
  Revision 1.4  2008/04/20 16:35:53  sybreon
136
  Added C/C++ compatible #ifdef statements
137
 
138 121 sybreon
  Revision 1.3  2008/04/12 13:46:02  sybreon
139
  Added malloc() lock and unlock routines
140
 
141 116 sybreon
  Revision 1.2  2008/04/11 15:20:31  sybreon
142
  added static assert hack
143
 
144 111 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
145
  Added new C++ files
146
 
147 107 sybreon
*/

powered by: WebSVN 2.1.0

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