libparanut
A Hardware Abstraction Layer for ParaNut Architectures.
common.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2020 Anna Pfuetzner (<annakerstin.pfuetzner@gmail.com>)
3  * Alexander Bahle (<alexander.bahle@hs-augsburg.de>)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
41 /*Includes*********************************************************************/
42 
43 #include "paranut.h"
44 
45 /*Commonly Used Defines********************************************************/
46 
70 #define COPU_CHECK if (coreid_as() != 0) return PN_ERR_COPU;
71 
80 #define ALL_HALTED if (read_PNCE_as() > 1) return PN_ERR_MATCH;
81 
90 #define BEGIN_THREADED_LINKED_SEC_CHECK \
91  COPU_CHECK \
92  ALL_HALTED \
93  if ((numcores > numcores_as()) || (numcores <= 1)) \
94  return PN_ERR_PARAM; \
95  if (numcores >= PN_RWIDTH) \
96  return PN_ERR_NOIMP;
97 
104 #define BEGIN_THREADED_LINKED_SEC_CHECK_M \
105  COPU_CHECK \
106  ALL_HALTED \
107  if (!(coremask & 0b1)) \
108  return PN_ERR_PARAM; \
109 
116 #define CREATE_THREAD_SEC_CHECK_M \
117  COPU_CHECK \
118  if (!(coremask & 0b1)) \
119  return PN_ERR_PARAM; \
120 
127  extern int shared_mem_size;
128 #define BEGIN_LINKED_STACK_FRAME_CHECK \
129  if (frame_adr != NULL && \
130  (frame_adr < stack_ptr_as() || \
131  frame_adr > (stack_ptr_as() + shared_mem_size))) \
132  return PN_ERR_PARAM; \
133 
139 #define CONVERT_NUMC_TO_MASK \
140  for (i = 2; i < numcores; i++) \
141  coremask |= (1 << i);
142 
148 #define TERMNL "\n\r"
149 
158 /*Global Variables*************************************************************/
159 
181 int sp_loc;
182 
188 int tp_loc;
189 
198 /*Commonly Used Assembly Functions*********************************************/
199 
200 extern void halt_as(void);
201 extern PN_NUMC numcores_as(void);
202 extern PN_CID coreid_as(void);
203 extern PN_CMSK read_PNCE_as(void);
204 extern PN_CMSK read_PNLM_as(void);
205 extern void enable_CPU_as(PN_CMSK coremask);
206 extern PN_CMSK m2cap_as(void);
207 extern int simulation_as(void);
208 
209 /*EOF**************************************************************************/
int32_t PN_CID
Signed type that can be used to address any core in this architecture.
Definition: paranut.h:356
int32_t PN_NUMC
Signed type that can hold the maximum number of cores in this architecture.
Definition: paranut.h:357
uint32_t PN_CMSK
Unsigned type that can act as a core mask.
Definition: paranut.h:358