1 |
2 |
marcelos |
# Copyright (c) 2018, Marcelo Samsoniuk
|
2 |
|
|
# All rights reserved.
|
3 |
|
|
#
|
4 |
|
|
# Redistribution and use in source and binary forms, with or without
|
5 |
|
|
# modification, are permitted provided that the following conditions are met:
|
6 |
|
|
#
|
7 |
|
|
# * Redistributions of source code must retain the above copyright notice, this
|
8 |
|
|
# list of conditions and the following disclaimer.
|
9 |
|
|
#
|
10 |
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
11 |
|
|
# this list of conditions and the following disclaimer in the documentation
|
12 |
|
|
# and/or other materials provided with the distribution.
|
13 |
|
|
#
|
14 |
|
|
# * Neither the name of the copyright holder nor the names of its
|
15 |
|
|
# contributors may be used to endorse or promote products derived from
|
16 |
|
|
# this software without specific prior written permission.
|
17 |
|
|
#
|
18 |
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19 |
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20 |
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21 |
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22 |
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23 |
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24 |
|
|
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25 |
|
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26 |
|
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27 |
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 |
|
|
|
29 |
|
|
ifndef HOST_CC
|
30 |
|
|
HOST_CC = gcc
|
31 |
|
|
HOST_CFLAGS = -Wall -Wno-incompatible-library-redeclaration -I./include -Os
|
32 |
|
|
endif
|
33 |
|
|
|
34 |
|
|
ifndef CROSS
|
35 |
|
|
|
36 |
|
|
ARCH = rv32e
|
37 |
|
|
#ARCH = rv32i
|
38 |
|
|
|
39 |
|
|
#TODO: better way to switch little/big-endian:
|
40 |
|
|
#ENDIAN = _le # gcc for little-endian
|
41 |
|
|
#ENDIAN = _be # gcc for big-endian
|
42 |
|
|
|
43 |
|
|
CROSS = riscv32-embedded$(ENDIAN)-elf
|
44 |
|
|
#CROSS = riscv-elf
|
45 |
|
|
#CROSS = riscv32-unknown-elf
|
46 |
|
|
#CROSS = riscv32-embedded-elf
|
47 |
|
|
|
48 |
|
|
CCPATH = /usr/local/share/gcc-$(CROSS)/bin/
|
49 |
|
|
#CCPATH = /usr/local/share/toolchain-$(CROSS)/bin
|
50 |
|
|
HARVARD = 1
|
51 |
|
|
endif
|
52 |
|
|
|
53 |
|
|
ifndef BUILD
|
54 |
|
|
BUILD = $(shell date -R)
|
55 |
|
|
endif
|
56 |
|
|
|
57 |
|
|
CC = $(CCPATH)/$(CROSS)-gcc
|
58 |
|
|
AS = $(CCPATH)/$(CROSS)-as
|
59 |
|
|
LD = $(CCPATH)/$(CROSS)-ld
|
60 |
|
|
OC = $(CCPATH)/$(CROSS)-objcopy
|
61 |
|
|
OD = $(CCPATH)/$(CROSS)-objdump
|
62 |
|
|
CPP = $(CCPATH)/$(CROSS)-cpp
|
63 |
|
|
|
64 |
4 |
marcelos |
CCFLAGS = -Wall -fcommon -ffreestanding -I./include -O2 -march=$(ARCH) -mabi=ilp32e -D__RISCV__ -DBUILD="\"$(BUILD)\"" -DARCH="\"$(ARCH)\""
|
65 |
2 |
marcelos |
ASFLAGS = -march=$(ARCH)
|
66 |
|
|
LDFLAGS = -T$(PROJ).ld -Map=$(PROJ).map -m elf32lriscv # -Ttext=0
|
67 |
|
|
CPFLAGS = -P
|
68 |
|
|
|
69 |
4 |
marcelos |
CCFLAGS += -mcmodel=medany -mexplicit-relocs # relocable clode
|
70 |
2 |
marcelos |
|
71 |
|
|
ifdef HARVARD
|
72 |
|
|
CPFLAGS += -DHARVARD=1
|
73 |
|
|
endif
|
74 |
|
|
|
75 |
|
|
OCFLAGS = -O binary # --reverse-bytes=4 # workaround for darkriscv big-endian blockrams
|
76 |
|
|
ODFLAGS = -d
|
77 |
|
|
|
78 |
|
|
PROJ = darksocv
|
79 |
4 |
marcelos |
OBJS = main.o stdio.o io.o banner.o boot.o
|
80 |
|
|
ASMS = main.s stdio.s io.s banner.s
|
81 |
|
|
SRCS = main.c stdio.c io.c banner.c boot.s
|
82 |
2 |
marcelos |
|
83 |
|
|
#include app/Makefile.in
|
84 |
|
|
|
85 |
|
|
DEPS = $(SRCS) $(ASMS) $(OBJS) $(PROJ).ld $(PROJ).ld.src
|
86 |
|
|
|
87 |
|
|
ifdef HARVARD
|
88 |
|
|
TARGETS = $(PROJ).rom.mem $(PROJ).ram.mem
|
89 |
|
|
else
|
90 |
|
|
TARGETS = $(PROJ).mem
|
91 |
|
|
endif
|
92 |
|
|
|
93 |
|
|
.PHONY: all
|
94 |
|
|
|
95 |
|
|
all: $(TARGETS) $(DEPS)
|
96 |
|
|
echo sources ok.
|
97 |
|
|
|
98 |
|
|
clean:
|
99 |
4 |
marcelos |
-rm $(ASMS) $(OBJS) $(PROJ).{bin,lst,map,ram,rom,x86,text,data,bin,ld,o}
|
100 |
2 |
marcelos |
|
101 |
|
|
%.o: %.s
|
102 |
|
|
$(AS) $(ASFLAGS) -c $< -o $@
|
103 |
|
|
|
104 |
|
|
%.s: %.c
|
105 |
|
|
$(CC) $(CCFLAGS) -S $< -o $@
|
106 |
|
|
|
107 |
|
|
$(PROJ).ld: $(PROJ).ld.src
|
108 |
|
|
$(CPP) $(CPFLAGS) $(PROJ).ld.src $(PROJ).ld
|
109 |
|
|
|
110 |
|
|
$(PROJ).o: $(OBJS) $(PROJ).ld
|
111 |
|
|
$(LD) $(LDFLAGS) $(OBJS) -o $@
|
112 |
|
|
$(OD) $(ODFLAGS) $@ > $(PROJ).lst
|
113 |
|
|
|
114 |
|
|
$(PROJ).rom.mem: $(PROJ).o
|
115 |
|
|
$(OC) $(OCFLAGS) $< $(PROJ).text --only-section .text*
|
116 |
|
|
hexdump -ve '1/4 "%08x\n"' $(PROJ).text > $@
|
117 |
|
|
#xxd -p -c 4 -g 4 $< > $@
|
118 |
|
|
rm $(PROJ).text
|
119 |
|
|
wc -l $@
|
120 |
|
|
echo rom ok.
|
121 |
|
|
|
122 |
|
|
$(PROJ).ram.mem: $(PROJ).o
|
123 |
|
|
$(OC) $(OCFLAGS) $< $(PROJ).data --only-section .*data*
|
124 |
|
|
hexdump -ve '1/4 "%08x\n"' $(PROJ).data > $@
|
125 |
|
|
#xxd -p -c 4 -g 4 $< > $@
|
126 |
|
|
rm $(PROJ).data
|
127 |
|
|
wc -l $@
|
128 |
|
|
echo ram ok.
|
129 |
|
|
|
130 |
|
|
$(PROJ).mem: $(PROJ).o
|
131 |
|
|
$(OC) $(OCFLAGS) $< $(PROJ).bin
|
132 |
|
|
hexdump -ve '1/4 "%08x\n"' $(PROJ).bin > $@
|
133 |
|
|
#xxd -p -c 4 -g 4 $< > $@
|
134 |
|
|
rm $(PROJ).bin
|
135 |
|
|
wc -l $@
|
136 |
|
|
echo mem ok.
|
137 |
|
|
|
138 |
|
|
$(PROJ).x86: $(SRCS)
|
139 |
|
|
$(HOST_CC) $(HOST_CFLAGS) $(SRCS) -o $(PROJ).x86 -DBUILD="\"$(BUILD)\"" -DARCH="\"x86\""
|
140 |
|
|
echo x86 ok.
|