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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 116 sybreon
/* $Id: hook.hh,v 1.3 2008-04-12 13:46:02 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
namespace aemb {
38
 
39 111 sybreon
  extern "C" void _program_init();
40
  extern "C" void _program_clean();
41 116 sybreon
  extern "C" void __malloc_lock();
42
  extern "C" void __malloc_unlock();
43
  extern "C" void __env_lock();
44
  extern "C" void __env_unlock();
45 107 sybreon
 
46
  /**
47 116 sybreon
     Finalisation hook
48
 
49
     This function executes during the shutdown phase after the
50
     finalisation routine is called. It will merge the changes made
51
     during initialisation.
52 107 sybreon
  */
53
 
54 111 sybreon
  void _program_clean()
55 107 sybreon
  {
56 116 sybreon
    // unify the stack backwards for thread 1
57
    if (aemb::isThread1())
58
      {
59
        aemb::setStack(aemb::getStack() + (aemb::getStackSize() >> 1));
60
      }
61 107 sybreon
  }
62
 
63
  /**
64 116 sybreon
     Initialisation hook
65 107 sybreon
 
66 116 sybreon
     This function executes during the startup phase before the
67
     initialisation routine is called. It splits the stack between the
68
     threads.
69 107 sybreon
  */
70
 
71 111 sybreon
  void _program_init()
72 107 sybreon
  {
73 116 sybreon
    // split and shift the stack for thread 1
74
    if (aemb::isThread1())
75
      {
76
        aemb::setStack(aemb::getStack() - (aemb::getStackSize() >> 1));
77
      }
78
    else
79
      {
80
        for(int i=0; i<10; ++i)
81
          {
82
            asm volatile ("nop"); // delay loop to offset thread 0
83
          }
84
      }
85 107 sybreon
  }
86
 
87 116 sybreon
  // FIXME: Implement with a single hardware mutex
88
 
89
  semaphore __malloc_mutex(1); ///< private mutex
90
 
91
  /**
92
     Heap Lock
93
 
94
     This function is called during malloc() to lock out the shared
95
     heap to avoid data corruption.
96
   */
97
 
98
  void __malloc_lock()
99
  {
100
    __malloc_mutex.wait();
101
  }
102
 
103
  /**
104
     Heap Unlock
105
 
106
     This function is called during malloc() to indicate that the
107
     shared heap is now available for another thread.
108
  */
109
 
110
  void __malloc_unlock()
111
  {
112
    __malloc_mutex.signal();
113
  }
114
 
115
}
116
 
117 107 sybreon
#endif
118
 
119 116 sybreon
#ifndef __OPTIMIZE__
120
// The main programme needs to be compiled with optimisations turned
121
// on (at least -O1).
122
OPTIMISATION_REQUIRED XXX
123
#endif
124
 
125 107 sybreon
/*
126
  $Log: not supported by cvs2svn $
127 116 sybreon
  Revision 1.2  2008/04/11 15:20:31  sybreon
128
  added static assert hack
129
 
130 111 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
131
  Added new C++ files
132
 
133 107 sybreon
*/

powered by: WebSVN 2.1.0

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