summaryrefslogtreecommitdiff
path: root/misc/Obsoleted/arch/8051/src/Makefile.sdccl
blob: 0e424924bce74585d9726a874b05080286fbf195 (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
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
############################################################################
# arch/8051/src/Makefile.sdccl
#
#   Copyright (C) 2007, 2008, 2011-2012, 2014 Gregory Nutt. All rights reserved.
#   Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
#    used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################

-include $(TOPDIR)/Make.defs

# Tools
# CFLAGS, CPPFLAGS, ASFLAGS, LDFLAGS are set in $(TOPDIR)/Make.defs

CFLAGS += -I$(TOPDIR)/sched
CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -D__ASSEMBLY__

LDFLAGS += --model-large --nostdlib --data-loc $(DEF_STACK_BASE) \
           --iram-size $(IRAM_SIZE) --code-loc 0x2100 --code-size 0x5f40 \
           --xram-loc $(IRAM_SIZE) --xram-size 0x1f00

# Files and directories
# There should be one head source (.asm file)

HEAD_SSRC = up_head.S
HEAD_ASRC = $(HEAD_SSRC:.S=$(ASMEXT))
HEAD_OBJ = $(HEAD_ASRC:$(ASMEXT)=$(OBJEXT))

# Assembly sources and objects

SSRCS =
ASRCS = $(SSRCS:.S=$(ASMEXT))
AOBJS = $(ASRCS:$(ASMEXT)=$(OBJEXT))

# C sources and objects

CSRCS = up_initialize.c up_idle.c up_interruptcontext.c up_initialstate.c \
        up_unblocktask.c up_blocktask.c up_releasepending.c \
        up_reprioritizertr.c up_exit.c up_assert.c up_allocateheap.c \
        up_irq.c up_savecontext.c up_restorecontext.c up_putc.c \
        up_debug.c up_delay.c

ifneq ($(CONFIG_SCHED_TICKLESS),y)
CSRCS += up_timerisr.c
endif

COBJS = $(CSRCS:.c=$(OBJEXT))

# All sources and objcts

SRCS = $(SSRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)

DEPSRCS = $(SRCS) $(HEAD_SSRC)

# Board path

BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board

# Source path

VPATH = chip:common:board

# Libraries

SDCCLIBS = -llibfloat.lib -llibint.lib -lliblong.lib -llibmysdcc.lib -lmcs51.lib

LINKLIBS ?=
LIBPATHS = -L"$(TOPDIR)/lib"
LDLIBS =  $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS)))

# Test sources

TESTSRCS = up_irqtest.c
TESTOBJS = $(TESTSRCS:.c=$(OBJEXT))
TESTLINKOBJS = up_head$(OBJEXT)
TESTEXTRAOBJS = up_savecontext$(OBJEXT) up_restorecontext$(OBJEXT)

# Memory

HEAP1_BASE = ${shell \
			if [ -e pass1.mem ]; then \
				cat pass1.mem | grep "EXTERNAL RAM" | \
				sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f5 ; \
			else \
				echo $(IRAM_SIZE) ; \
			fi \
		   }
DEF_HEAP2_BASE = 0x6000
HEAP2_BASE = ${shell \
			if [ -e pass1.mem ]; then \
				cat pass1.mem | grep "ROM/EPROM/FLASH" | \
				sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f4 ; \
			else \
				echo $(DEF_HEAP2_BASE) ; \
			fi \
		   }
STACK_BASE = ${shell \
			if [ -e pass1.mem ]; then \
				cat pass1.mem | grep "Stack starts" | \
				cut -d' ' -f4 ; \
			else \
				echo $(DEF_STACK_BASE) ; \
			fi \
		   }

# Targets

all: up_head$(OBJEXT) libarch$(LIBEXT)

.PHONY: board/libboard$(LIBEXT)

$(ASRCS) $(HEAD_ASRC): %$(ASMEXT): %.S
	$(CPP) -P $(CPPFLAGS) $< -o $@

$(AOBJS) $(HEAD_OBJ): $(ASRCS) $(HEAD_ASRC)
	$(call ASSEMBLE, $<, $@)

$(COBJS) $(TESTOBJS): %$(OBJEXT): %.c
	$(call COMPILE, $<, $@)

# This is a kludge to work around some conflicting symbols in the SDCC libraries

$(TOPDIR)/lib/$(SDCCLIB): $(SDCC_LIBDIR)/$(SDCCLIB)
	$(Q) cp $(SDCC_LIBDIR)/$(SDCCLIB) $(TOPDIR)/lib/$(SDCCLIB)
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _calloc.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _malloc.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _realloc.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _free.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) printf_large.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) sprintf.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) vprintf.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) strcpy.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) strlen.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcat.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strchr.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcmp.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcspn.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncat.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncmp.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncpy.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strpbrk.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strrchr.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strspn.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strstr.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strtok.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memchr.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memcmp.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memcpy.rel
	$(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memset.rel

# Create a header file that contains addressing information needed by the code

up_mem.h: pass1.mem
	@echo "#ifndef __ARCH_MEM_H" >up_mem.h
	@echo "#define __ARCH_MEM_H" >>up_mem.h
	@echo "" >>up_mem.h
	@echo "#define UP_DEFAULT_STACK_BASE $(DEF_STACK_BASE)" >>up_mem.h
	@echo "#define UP_DEFAULT_HEAP1_BASE $(IRAM_SIZE)" >> up_mem.h
	@echo "#define UP_DEFAULT_HEAP2_BASE $(DEF_HEAP2_BASE)" >> up_mem.h
	@echo "" >>up_mem.h
	@echo "#define UP_STACK_BASE         $(STACK_BASE)" >>up_mem.h
	@echo "#if UP_STACK_BASE > UP_DEFAULT_STACK_BASE" >>up_mem.h
	@echo "#  error \"Stack overlap:  $(DEF_STACK_BASE) < $(STACK_BASE)\""  >>up_mem.h
	@echo "#elif UP_STACK_BASE < UP_DEFAULT_STACK_BASE" >>up_mem.h
	@echo "#  warning \"Wasted stack: $(DEF_STACK_BASE) > $(STACK_BASE)\""  >>up_mem.h
	@echo "#endif" >>up_mem.h
	@echo "" >>up_mem.h
	@echo "#define UP_HEAP1_BASE          $(HEAP1_BASE)" >> up_mem.h
	@echo "#define UP_HEAP1_END           0x2000" >> up_mem.h
	@echo "" >>up_mem.h
	@echo "#define UP_HEAP2_BASE          $(HEAP2_BASE)" >> up_mem.h
	@echo "#define UP_HEAP2_END           0x8000" >> up_mem.h
	@echo "" >>up_mem.h
	@echo "#endif /* __ARCH_MEM_H */" >>up_mem.h

# Combine all objects in this directory into a library

libarch$(LIBEXT): up_mem.h $(OBJS)
	$(call ARCHIVE, $@, $(OBJS))

# This builds the libboard library in the board/ subdirectory

board/libboard$(LIBEXT):
	$(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)

# This target builds the final executable

pass1.hex: up_mem.h $(TOPDIR)/lib/$(SDCCLIB) $(HEAD_OBJ) board/libboard$(LIBEXT)
	@echo "LD:  $@"
	$(Q) "$(CC)" $(LDFLAGS) $(LIBPATHS) -L$(BOARDDIR) $(SDCCPATH) $(HEAD_OBJ) \
		$(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@
	$(Q) rm -f up_mem.h
	$(Q) rm -f up_allocateheap$(OBJEXT) libarch$(LIBEXT)
	$(Q) $(MAKE) TOPDIR=$(TOPDIR) libarch$(LIBEXT)

nuttx.hex: up_mem.h $(TOPDIR)/lib/$(SDCCLIB) $(HEAD_OBJ)
	@echo "LD:  $@"
	$(Q) "$(CC)" $(LDFLAGS) $(LIBPATHS) -L$(BOARDDIR) $(SDCCPATH) $(HEAD_OBJ) \
		$(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@

nuttx$(EXEEXT): pass1.hex nuttx.hex
	$(Q) rm -f pass1.*
	$(Q) packihx nuttx.hex > $(TOPDIR)/nuttx$(EXEEXT)
	$(Q) cp -f nuttx.map $(TOPDIR)/.

# This is part of the top-level export target

export_head: board/libboard$(LIBEXT) p_head$(OBJEXT)
	$(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \
		cp -f up_head$(OBJEXT) "$(EXPORT_DIR)/startup"; \
	 else \
		echo "$(EXPORT_DIR)/startup does not exist"; \
		exit 1; \
	 fi

# This target builds a test program to verify interrupt context switching.  irqtest is
# a PHONY target that just sets upt the up_irqtest build correctly

up_irqtest.hex: $(TESTOBJS)
	$(Q) "$(CC)" $(LDFLAGS) -L. $(SDCCPATH) $(TESTLINKOBJS) $(TESTOBJS) $(TESTEXTRAOBJS) $(SDCCLIBS) -o $@

irqtest:
	$(Q) $(MAKE) TOPDIR=../../.. up_irqtest.hex

# Build dependencies

.depend: Makefile up_mem.h $(DEPSRCS)
	$(Q) if [ -e board/Makefile ]; then \
		$(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \
	fi	
	$(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
	$(Q) touch $@

depend: .depend

clean:
	$(Q) if [ -e board/Makefile ]; then \
		$(MAKE) -C board TOPDIR=$(TOPDIR) clean ; \
	fi
	$(call DELFILE, libarch$(LIBEXT))
	$(call DELFILE, up_mem.h)
	$(call CLEAN)

distclean: clean
	$(Q) if [ -e board/Makefile ]; then \
		$(MAKE) -C board TOPDIR=$(TOPDIR) distclean ; \
	fi
	$(call DELFILE, Make.dep)
	$(call DELFILE, .depend)

-include Make.dep