summaryrefslogtreecommitdiffstats
path: root/src/include/compiler.h
blob: df0a01a6ed20e618de1880d782b720762e70de22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef COMPILER_H
#define COMPILER_H

/* We export the symbol obj_OBJECT (OBJECT is defined on command-line)
 * as a global symbol, so that the linker can drag in selected object
 * files from the library using -u obj_OBJECT.
 *
 * Not quite sure why cpp requires two levels of macro call in order
 * to actually expand OBJECT...
 */
#undef _H1
#define _H1( x, y ) x ## y
#undef _H2
#define _H2( x, y ) _H1 ( x, y )
#define PREFIX_OBJECT(prefix) _H2 ( prefix, OBJECT )
#define OBJECT_SYMBOL PREFIX_OBJECT(obj_)
#undef _STR
#define _STR(s) #s
#undef _XSTR
#define _XSTR(s) _STR(s)
#define OBJECT_SYMBOL_STR _XSTR ( OBJECT_SYMBOL )

#ifdef ASSEMBLY

	.globl	OBJECT_SYMBOL
	.equ	OBJECT_SYMBOL, 0

#else /* ASSEMBLY */

__asm__ ( ".globl\t" OBJECT_SYMBOL_STR );
__asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );

/*
 * Macro to allow objects to explicitly drag in other objects by
 * object name.  Used by config.c.
 *
 */
#define REQUIRE_OBJECT(object) \
	__asm__ ( ".equ\tneed_" #object ", obj_" #object );

/*
 * If debug_OBJECT is set to a true value, the macro DBG(...) will
 * expand to printf(...) when compiling OBJECT, and the symbol
 * DEBUG_LEVEL will be inserted into the object file.
 *
 */
#define DEBUG_SYMBOL PREFIX_OBJECT(debug_)

#if DEBUG_SYMBOL
#include "console.h"
#define DEBUG_SYMBOL_STR _XSTR ( DEBUG_SYMBOL )
__asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
#endif

#define DBG_PRINT(...) printf ( __VA_ARGS__ )
#define DBG_DISCARD(...)
#define DBG  DBG_DISCARD
#define DBG2 DBG_DISCARD

#if DEBUG_SYMBOL >= 1
#undef DBG
#define DBG DBG_PRINT
#endif

#if DEBUG_SYMBOL >= 2
#undef DBG2
#define DBG2 DBG_PRINT
#endif

#define PACKED __attribute__((packed))
#define __unused __attribute__((unused))
#define __used __attribute__((used))

/*
 * To save space in the binary when multiple-driver images are
 * compiled, uninitialised data areas can be shared between drivers.
 * This will typically be used to share statically-allocated receive
 * and transmit buffers between drivers.
 *
 * Use as e.g.
 *
 *  struct {
 *	char	rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
 *	char	tx_buf[TX_BUF_SIZE];
 *  } my_static_data __shared;
 *
 */

#define __shared __asm__ ( "_shared_bss" );

#endif /* ASSEMBLY */

#endif /* COMPILER_H */