-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
195 lines (146 loc) · 5.34 KB
/
Makefile
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
#############################################################################
# Makefile for building: armv8bin
# Generated by hand from a qmake template
#############################################################################
####### Compiler, tools and options
## TARGET is either USER or SYS, default to USER
# see make help for details
TARGET=USER
# for linux
AS = aarch64-linux-gnu-as
ASFLAGS = -mverbose-error -I include --defsym $(TARGET)=1
LD = aarch64-linux-gnu-ld
# linker script for kernel
LDFLAGS = -T src/linker.ld
# for creating STDLIB
AR = ar
ARFLAGS = -rcs
####### for Qemu
QEMU_SYSTEM_AARCH64 = qemu-system-aarch64
QEMU_AARCH64 = qemu-aarch64
####### Files
BINDIR = bin
LIBDIR = lib
HEADERS = include/macros.s \
include/globals.s \
include/fcntl.s \
include/fs.s
### Kernel
KERNEL = armv8bin
KERNEL_OBJS = src/main.o \
src/debug.o \
src/mem.o \
src/except.o \
### STDLIB
STDLIB = stdlib.a
STDLIB_OBJS = src/stdio.o \
src/string.o \
src/stdlib.o \
src/usermodesys.o
### userland programs
CAT = cat
CAT_OBJS = userland/cat.o
DISARM64 = disarm64
DISARM64_OBJS = userland/disarm64.o userland/elf.o userland/decode.o
HEXDUMP = hexdump
HEXDUMP_OBJS = userland/hexdump.o
NEWFILE = newfile
NEWFILE_OBJS = userland/newfile.o
READELF = readelf
READELF_OBJS = userland/readelf.o userland/elf.o
## compilation of all userland programs
USERLAND_PROGS = build_hook $(CAT) $(DISARM64) $(HEXDUMP) $(NEWFILE) $(READELF)
USERLAND_OBJS = $(CAT_OBJS) $(DISARM64_OBJS) $(HEXDUMP_OBJS) $(NEWFILE_OBJS) $(READELF_OBJS)
## assembly and linking
all: build_hook $(STDLIB) $(KERNEL) $(USERLAND_PROGS)
build_hook:
mkdir -p $(BINDIR) $(LIBDIR) tests/bin
$(STDLIB): $(STDLIB_OBJS) $(HEADERS)
$(AR) $(ARFLAGS) $(LIBDIR)/$(STDLIB) $(STDLIB_OBJS)
$(KERNEL): $(KERNEL_OBJS) $(STDLIB) $(HEADERS)
$(LD) $(LDFLAGS) -o $(BINDIR)/$(KERNEL) $(KERNEL_OBJS) $(LIBDIR)/$(STDLIB)
userprogs: $(USERLAND_PROGS)
$(CAT): $(STDLIB) $(CAT_OBJS) $(HEADERS)
$(LD) -o $(BINDIR)/$(CAT) $(CAT_OBJS) $(LIBDIR)/$(STDLIB)
$(DISARM64): $(STDLIB) $(DISARM64_OBJS) $(HEADERS)
$(LD) -o $(BINDIR)/$(DISARM64) $(DISARM64_OBJS) $(LIBDIR)/$(STDLIB)
$(HEXDUMP): $(STDLIB) $(HEXDUMP_OBJS) $(HEADERS)
$(LD) -o $(BINDIR)/$(HEXDUMP) $(HEXDUMP_OBJS) $(LIBDIR)/$(STDLIB)
$(NEWFILE): $(STDLIB) $(NEWFILE_OBJS) $(HEADERS)
$(LD) -o $(BINDIR)/$(NEWFILE) $(NEWFILE_OBJS) $(LIBDIR)/$(STDLIB)
$(READELF): $(STDLIB) $(READELF_OBJS) $(HEADERS)
$(LD) -o $(BINDIR)/$(READELF) $(READELF_OBJS) $(LIBDIR)/$(STDLIB)
clean:
rm -f $(KERNEL_OBJS) $(STDLIB_OBJS) $(USERLAND_OBJS)
rm -f $(KERNEL)
rm -rf $(BINDIR) $(LIBDIR)
rm -rf tests/*.o
rm -rf tests/bin
rm -rf tests/*.txt
####### Compile
main.o: src/main.s
$(AS) $(ASFLAGS) -o @ src/main.s
except.o: src/except.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/except.s
stdio.o: src/stdio.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/stdio.s
debug.o: src/debug.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/debug.s
string.o: src/string.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/string.s
stdlib.o: src/stdlib.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/stdlib.s
mem.o: src/mem.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/mem.s
usermodesys.o: src/usermodesys.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ src/usermodesys.s
## userland
cat.o: userland/cat.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ userland/cat.s
disarm64.o: userland/disarm64.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ userland/disarm64.s
newfile.o: userland/newfile.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ userland/newfile.s
readelf.o: userland/readelf.s $(HEADERS)
$(AS) $(ASFLAGS) -o @ userland/readelf.s
elf.o: userland/elf.s $(HEADERS) userland/elf.o
$(AS) $(ASFLAGS) -o @ userland/elf.s
### tests
check: build_hook disarm_loadstore.o disarm_branches.o disarm_cmp.o disarm_data.o disarm_arithmetic.o disarm64
tests/opcodes.test
rm tests/actual.txt tests/expected.txt
disarm_loadstore.o: tests/disarm_loadstore.s
$(AS) $(ASFLAGS) -o tests/disarm_loadstore.o tests/disarm_loadstore.s
$(LD) -o tests/bin/disarm_loadstore tests/disarm_loadstore.o
disarm_branches.o: tests/disarm_branches.s
$(AS) $(ASFLAGS) -o tests/disarm_branches.o tests/disarm_branches.s
$(LD) -o tests/bin/disarm_branches tests/disarm_branches.o
disarm_cmp.o: tests/disarm_cmp.s
$(AS) $(ASFLAGS) -o tests/disarm_cmp.o tests/disarm_cmp.s
$(LD) -o tests/bin/disarm_cmp tests/disarm_cmp.o
disarm_data.o: tests/disarm_data.s
$(AS) $(ASFLAGS) -o tests/disarm_data.o tests/disarm_data.s
$(LD) -o tests/bin/disarm_data tests/disarm_data.o
disarm_arithmetic.o: tests/disarm_arithmetic.s
$(AS) $(ASFLAGS) -o tests/disarm_arithmetic.o tests/disarm_arithmetic.s
$(LD) -o tests/bin/disarm_arithmetic tests/disarm_arithmetic.o
####### Install
install: FORCE
uninstall: FORCE
FORCE:
run: system-run
system-run: $(KERNEL)
@echo running in full system emulation mode. See that you make TARGET=SYS
$(QEMU_SYSTEM_AARCH64) -machine virt -cpu cortex-a57 -nographic -smp 1 -m 512M -kernel $(KERNEL) --append "console=ttyAMA0"
help:
@echo "possible configurations:"
@echo "what to make:"
@echo "make => make all"
@echo "make $(KERNEL) => just kernel"
@echo "make $(STDLIB) => just stdlib"
@echo "make userprogs => just userland programs"
@echo "how to make:"
@echo "make TARGET=USER (default) => using linux syscalls"
@echo "make TARGET=SYS => system emulation mode, no syscalls"
@echo "how to run:"
@echo "make system-run => run kernel in qemu full system emulation"