summaryrefslogtreecommitdiffstats
path: root/src/ssx/pgp/ssx.mk
blob: 21a605c088f7d49293c174a20a417479e026e504 (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# $Id: ssx.mk,v 1.2 2014/06/26 12:55:39 cmolsen Exp $
# $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/ssx/pgp/ssx.mk,v $
#  Make header for PgP SSX builds
#
# The application may define the following variables to control the
# build process:
#
# APP_INCLUDES       : Aplication-specific header search paths
#
# DEFS               : A string of -D<symbol>[=<value>] to control compilation
#
# SSX                : Default ..; The path to the SSX source code.
#                      The default is set for building the SSX
#                      subdirectories. 
#
# SSX_THREAD_SUPPORT : (0/1, default 1); Compile SSX thread and
#                      semaphore suppprt 
#
# SSX_TIMER_SUPPORT  : (0/1, default 1); Compile SSX timer suppprt
#
# PPC405_MMU_SUPPORT : (0/1, default 1); Compile for PPC405 simple MMU protection
#
# SIMICS_ENVIRONMENT : (0/1, current default 0); Compile for Simics
#
# SIMICS_MAGIC_PANIC : (0/1, current default 0); Use Simics Magic
#                      breakpoint for SSX_PANIC() instead of PowerPC trap.
#                      Note that Simics does not model trap correctly in
#                      external debug mode.
#
# GCC-O-LEVEL        : The optimization level passed to GCC (default -Os). May
#                      also be defined empty (GCC-O-LEVEL=) to disable
#                      optimization. This variable can also be used to pass
#                      any other non-default setting to GCC, e.g.
#                      make GCC-O-LEVEL="-Os -fno-branch-count-reg"
#
# GCC-TOOL-PREFIX    : The full path (including executable file prefixes) to
#                      the GCC cross-development tools to use.  The default is 
#                      "ppcnf-mcp5-"
#
# POREPATH           : Overrideable path to the PORE binutils

export OCCROOT = $(dir $(lastword $(MAKEFILE_LIST)))../../

ifndef SIMICS_ENVIRONMENT
SIMICS_ENVIRONMENT=0
endif

ifndef GCC-TOOL-PREFIX

# CROSS_PREFIX may be set by
# op-build/openpower/package/occ/occ.mk

ifdef CROSS_PREFIX
GCC-TOOL-PREFIX = $(CROSS_PREFIX)
else
GCC-TOOL-PREFIX = powerpc64-unknown-linux-gnu-
endif

endif

ifndef HOST-PREFIX
HOST-PREFIX = x86_64-pc-linux-gnu-
endif

CC_ASM  = $(GCC-TOOL-PREFIX)gcc
CC      = $(TRACEPP) $(GCC-TOOL-PREFIX)gcc
LD      = $(GCC-TOOL-PREFIX)ld
OBJDUMP = $(GCC-TOOL-PREFIX)objdump

JAIL    = $(HOST-PREFIX)jail

ifndef OCC_OP_BUILD
AS      = $(JAIL) /usr/bin/as
AR      = $(JAIL) /usr/bin/ar
OBJCOPY = $(JAIL) /usr/bin/objcopy
CPP     = $(JAIL) /usr/bin/cpp
else
AS      = $(GCC-TOOL-PREFIX)as
AR      = $(GCC-TOOL-PREFIX)ar
OBJCOPY = $(GCC-TOOL-PREFIX)objcopy
CPP     = $(GCC-TOOL-PREFIX)cpp
endif

ifndef POREPATH
$(warning The POREPATH variable is not defined; Defaulting to current PATH)
endif

PORE-AS      = $(POREPATH)pore-elf64-as
PORE-AS      = $(POREPATH)pore-elf64-as
PORE-LD      = $(POREPATH)pore-elf64-ld
PORE-OBJCOPY = $(POREPATH)pore-elf64-objcopy

ifeq "$(SSX)" ""
SSX = ..
endif

ifeq "$(LIB)" ""
LIB = ../../lib
endif

ifeq "$(SSX_TIMER_SUPPORT)" ""
SSX_TIMER_SUPPORT  = 1
endif

ifeq "$(SSX_THREAD_SUPPORT)" ""
SSX_THREAD_SUPPORT = 1
endif

ifeq "$(PPC405_MMU_SUPPORT)" ""
PPC405_MMU_SUPPORT = 1
endif

ifeq "$(PGP_ASYNC_SUPPORT)" ""
PGP_ASYNC_SUPPORT = 1
endif

ifndef GCC-O-LEVEL
GCC-O-LEVEL = -Os
endif

GCC-DEFS += -DSIMICS_ENVIRONMENT=$(SIMICS_ENVIRONMENT)
GCC-DEFS += -DSSX_TIMER_SUPPORT=$(SSX_TIMER_SUPPORT) 
GCC-DEFS += -DSSX_THREAD_SUPPORT=$(SSX_THREAD_SUPPORT) 
GCC-DEFS += -DPPC405_MMU_SUPPORT=$(PPC405_MMU_SUPPORT)
DEFS += $(GCC-DEFS) -DPGAS_PPC=1 -DCONFIGURE_PTS_SLW=0
PORE-DEFS += $(GCC-DEFS)

############################################################################

INCLUDES += $(APP_INCLUDES) \
	-I$(SSX)/ssx -I$(SSX)/ppc32 -I$(SSX)/ppc405 \
	-I$(SSX)/pgp -I$(SSX)/pgp/registers \
	-I$(LIB)

PIPE-CFLAGS = -pipe -Wa,-m405

GCC-CFLAGS += -g -Wall -fsigned-char -msoft-float  \
	-m32 -mcpu=405 -mmultiple -mstring \
	-meabi -msdata=eabi -ffreestanding -fno-common \
	-fno-inline-functions-called-once

CFLAGS      =  -c $(GCC-CFLAGS) $(PIPE-CFLAGS) $(GCC-O-LEVEL) $(INCLUDES) 
PORE-CFLAGS =  -E $(GCC-CFLAGS) $(OPT) $(INCLUDES) 
CPPFLAGS += -m32 -mcpu=405 -msdata=eabi -meabi -mstring -mmultiple

############################################################################

# Build object code
#
# %.o: %.c - Compile C code
#
# %.o: %.S - Compile PowerPC assembler (including PGAS-PPC assembly)

%.o: %.c
	$(CC) $(CFLAGS) $(DEFS) -o $@ $<

%.o: %.S
	$(CC_ASM) $(CFLAGS) $(DEFS) -o $@ $<

#Temporary always use PGAS PPC Assembler for compiling .pS files.
#relocatable symbols are being added to the GPE (.pS) files and
#so need new way to compile using GNU assembler.
PGAS_PPC=1

# use "make PGAS_PPC=1" to compile .pS file using PGAS PPC assembler.
# If PGAS_PPC=1 is not part of the make command, then GNU assembler is
# used for compiling .pS files.
ifdef PGAS_PPC

ifneq ($(MAKE_PORE_HOOKS),)

# This Makefile included here defines how to convert *.pS into both the object
# file and the hooks object file.

include $(MAKE_PORE_HOOKS)

else

%.o: %.pS
	$(CC_ASM) -x assembler-with-cpp $(PORE-CFLAGS) $(PORE-DEFS)  $< | $(PORE-AS) - -o $@
endif

%.lst: %.pS
	$(CC_ASM) -x assembler-with-cpp  $(CFLAGS) $(DEFS) \
		-Wa,-al -Wa,--listing-cont-lines=20 $< > $@

else
%.o: %.pS
	$(CPP_ASM) -x assembler-with-cpp $(PORE-CFLAGS) $(PORE-DEFS)  $< | $(PORE-AS) - -o $@
endif

# Other useful targets
#
# %.S: %.c - See what the assembler produces from the C code, however you can
# also just look at the final disassembly.
#
# %.lst: %.S - Get an assembler listing
#
# %.cpp: %.S - Preprocess PowerPC assembler source to stdout
#
# %.cpp: %.pS - Preprocess PORE assembler source to stdout
#
# %.cpp: %.c - Preprocess C source to stdout

%.S: %.c
	$(CC) $(CFLAGS) $(DEFS) -S -o $@ $<

%.lst: %.S
	$(CC_ASM) $(CFLAGS) $(DEFS) -Wa,-al -Wa,--listing-cont-lines=20 $< > $@

%.cpp: %.S
	$(CC_ASM) $(CFLAGS) $(DEFS) -E $<

%.cpp: %.pS
	$(CC) -x assembler-with-cpp $(CFLAGS) $(DEFS) -E $<

%.cpp: %.c
	$(CC) $(CFLAGS) $(DEFS) -E $<

# From the GNU 'Make' manual - these scripts uses the preprocessor to
# create dependency files (*.d), then mungs them slightly to make them
# work as Make targets. The *.d files are include-ed in the
# subdirectory Makefiles.

%.d: %.c
	@set -e; rm -f $@; \
	$(CC_ASM) -MM $(INCLUDES) $(CPPFLAGS) $(DEFS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

%.d: %.S
	@set -e; rm -f $@; \
	$(CC_ASM) -MM $(INCLUDES) $(CPPFLAGS) $(DEFS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

%.d: %.pS
	@set -e; rm -f $@; \
	$(CC_ASM) -MM $(INCLUDES) $(CPPFLAGS) -x assembler-with-cpp $(DEFS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

############################################################################
#
# GCC Compiler flags used in these builds.  Comments, or reasons for
# non-obvious choices appear in [] after the GCC documentation.
#
#`-Os'
#     Optimize for size.  `-Os' enables all `-O2' optimizations that do
#     not typically increase code size.  It also performs further
#     optimizations designed to reduce code size.
#
#     `-Os' disables the following optimization flags:
#          -falign-functions  -falign-jumps  -falign-loops
#          -falign-labels  -freorder-blocks  -freorder-blocks-and-partition
#          -fprefetch-loop-arrays  -ftree-vect-loop-version
#
#     If you use multiple `-O' options, with or without level numbers,
#     the last such option is the one that is effective.
#
#`-g'
#     Produce debugging information in the operating system's native
#     format (stabs, COFF, XCOFF, or DWARF 2).  GDB can work with this
#     debugging information.
#
#     On most systems that use stabs format, `-g' enables use of extra
#     debugging information that only GDB can use; this extra information
#     makes debugging work better in GDB but will probably make other
#     debuggers crash or refuse to read the program.  If you want to
#     control for certain whether to generate the extra information, use
#     `-gstabs+', `-gstabs', `-gxcoff+', `-gxcoff', or `-gvms' (see
#     below).
#
#     GCC allows you to use `-g' with `-O'.  The shortcuts taken by
#     optimized code may occasionally produce surprising results: some
#     variables you declared may not exist at all; flow of control may
#     briefly move where you did not expect it; some statements may not
#     be executed because they compute constant results or their values
#     were already at hand; some statements may execute in different
#     places because they were moved out of loops.
#
#     Nevertheless it proves possible to debug optimized output.  This
#     makes it reasonable to use the optimizer for programs that might
#     have bugs.
#
#`-Wall'
#     Turns on all optional warnings which are desirable for normal code.
#     At present this is `-Wcomment', `-Wtrigraphs', `-Wmultichar' and a
#     warning about integer promotion causing a change of sign in `#if'
#     expressions.  Note that many of the preprocessor's warnings are on
#     by default and have no options to control them.
#
#`-Werror'
#     Make all warnings into errors.
#  
#`-fsigned-char'
#     Let the type `char' be signed, like `signed char'.
#
#     Note that this is equivalent to `-fno-unsigned-char', which is the
#     negative form of `-funsigned-char'.  Likewise, the option
#     `-fno-signed-char' is equivalent to `-funsigned-char'.
#
#`-msoft-float'
#     Generate output containing library calls for floating point.
#     *Warning:* the requisite libraries are not available for all ARM
#     targets.  Normally the facilities of the machine's usual C
#     compiler are used, but this cannot be done directly in
#     cross-compilation.  You must make your own arrangements to provide
#     suitable library functions for cross-compilation.
#
#     `-msoft-float' changes the calling convention in the output file;
#     therefore, it is only useful if you compile _all_ of a program with
#     this option.  In particular, you need to compile `libgcc.a', the
#     library that comes with GCC, with `-msoft-float' in order for this
#     to work.
#
#`-pipe'
#     Use pipes rather than temporary files for communication between the
#     various stages of compilation.  This fails to work on some systems
#     where the assembler is unable to read from a pipe; but the GNU
#     assembler has no trouble.
#
#`-mmultiple'
#`-mno-multiple'
#     Generate code that uses (does not use) the load multiple word
#     instructions and the store multiple word instructions.  These
#     instructions are generated by default on POWER systems, and not
#     generated on PowerPC systems.  Do not use `-mmultiple' on little
#     endian PowerPC systems, since those instructions do not work when
#     the processor is in little endian mode.  The exceptions are PPC740
#     and PPC750 which permit the instructions usage in little endian
#     mode.
#
#`-mstring'
#`-mno-string'
#     Generate code that uses (does not use) the load string instructions
#     and the store string word instructions to save multiple registers
#     and do small block moves.  These instructions are generated by
#     default on POWER systems, and not generated on PowerPC systems.
#     Do not use `-mstring' on little endian PowerPC systems, since those
#     instructions do not work when the processor is in little endian
#     mode.  The exceptions are PPC740 and PPC750 which permit the
#     instructions usage in little endian mode.
#
#`-meabi'
#`-mno-eabi'
#     On System V.4 and embedded PowerPC systems do (do not) adhere to
#     the Embedded Applications Binary Interface (eabi) which is a set of
#     modifications to the System V.4 specifications.  Selecting `-meabi'
#     means that the stack is aligned to an 8 byte boundary, a function
#     `__eabi' is called to from `main' to set up the eabi environment,
#     and the `-msdata' option can use both `r2' and `r13' to point to
#     two separate small data areas.  Selecting `-mno-eabi' means that
#     the stack is aligned to a 16 byte boundary, do not call an
#     initialization function from `main', and the `-msdata' option will
#     only use `r13' to point to a single small data area.  The `-meabi'
#     option is on by default if you configured GCC using one of the
#     `powerpc*-*-eabi*' options.
#
# [We elected to use the EABI to reduce stack requirements and possibly reduce
# code size and improve performance.  In practice it probably has little real
# effect since the code size and performance improvements only apply to global
# variables <= 8 bytes, and our applications will not have deeply nested call
# trees. Still, much of the assembler code requires/assumes the EABI is in
# place, and it certainly doesn't hurt anything to use it.]
#
#`-msdata=eabi'
#     On System V.4 and embedded PowerPC systems, put small initialized
#     `const' global and static data in the `.sdata2' section, which is
#     pointed to by register `r2'.  Put small initialized non-`const'
#     global and static data in the `.sdata' section, which is pointed
#     to by register `r13'.  Put small uninitialized global and static
#     data in the `.sbss' section, which is adjacent to the `.sdata'
#     section.  The `-msdata=eabi' option is incompatible with the
#     `-mrelocatable' option.  The `-msdata=eabi' option also sets the
#     `-memb' option.
#
#`-memb'
#     On embedded PowerPC systems, set the PPC_EMB bit in the ELF flags
#     header to indicate that `eabi' extended relocations are used.
#
#`-ffreestanding'
#     Assert that compilation takes place in a freestanding environment.
#     This implies `-fno-builtin'.  A freestanding environment is one
#     in which the standard library may not exist, and program startup
#     may not necessarily be at `main'.  The most obvious example is an
#     OS kernel.  This is equivalent to `-fno-hosted'.
#
#`-fno-common'
#     In C, allocate even uninitialized global variables in the data
#     section of the object file, rather than generating them as common
#     blocks.  This has the effect that if the same variable is declared
#     (without `extern') in two different compilations, you will get an
#     error when you link them.  The only reason this might be useful is
#     if you wish to verify that the program will work on other systems
#     which always work this way.
#
# [It is always assumed to be an error if two C source files declare global
# variables of the same name, since it is not clear whether this was intended
# or not.]
# 
#`-finline-functions-called-once'
#`-fno-inline-functions-called-once'
#     Consider all `static' functions called once for inlining into their
#     caller even if they are not marked `inline'.  If a call to a given
#     function is integrated, then the function is not output as
#     assembler code in its own right.
#
#     Enabled if `-funit-at-a-time' is enabled.
#
# [There is a 'bug' in GCC related to inlining static, called-once
# functions. GCC allocates stack space in the caller for the stacks of ALL
# inlined functions of this type, even if they are called sequentially,
# leading in some cases to kilobytes of wasted stack space. If you want to
# inline a static called-once function you will need to explicity declare it
# as 'inline'.]


OpenPOWER on IntegriCloud