forked from gramado/kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
496 lines (407 loc) · 11.3 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
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# License: BSD License
PRODUCT_NAME = Gramado Operating System
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 189
# See: config/version.h
# Documentation.
# See: docs/
# To see the targets execute "make help".
# That's our default target when none is given on the command line.
PHONY := _all
_all: all
@echo "That's all!"
# ==========================================
# Variables.
KERNELVERSION = $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR)$(if $(VERSION_BUILD),.$(VERSION_BUILD)))
export KBUILD_IMAGE ?= KERNEL.BIN
srctree := .
objtree := .
src := $(srctree)
obj := $(objtree)
# Make variables (CC, etc...)
AS = as
LD = ld
CC = gcc
AR = ar
MAKE = make
NASM = nasm
OBJCOPY = objcopy
OBJDUMP = objdump
LEX = flex
YACC = bison
PERL = perl
PYTHON = python
PYTHON2 = python2
PYTHON3 = python3
RUBY = ruby
# Verbose.
ifndef KBUILD_VERBOSE
KBUILD_VERBOSE = 1
endif
ifeq ($(KBUILD_VERBOSE),1)
Q =
else
Q = @
endif
#
# Begin.
#
## ===============================================================
## Step0 build-system-files - Libraries and apps.
## Step1 build-applications - setupx files.
## Step2 /mnt/gramadovhd - Creating the directory to mount the VHD.
## Step3 vhd-mount - Mounting the VHD.
## Step4 vhd-copy-files - Copying files into the mounted VHD.
## Step5 vhd-unmount - Unmounting the VHD.
## Step6 clean - Deleting the object files.
PHONY := all
# All the steps.
all: \
build-system-files \
build-applications \
/mnt/gramadovhd \
vhd-mount \
vhd-copy-files \
vhd-unmount \
clean \
clean-system-files
# Giving permitions to run ./run hahaha
chmod 755 ./run
# Product info:
@echo "$(PRODUCT_NAME) $(KERNELVERSION)"
# @echo "$(ARCH)"
#===================================================
#:::0
# ~ Step 0: Building system files.
PHONY := build-system-files
build-system-files: \
/usr/local/gramado-build \
ge-boot \
ge-kernel \
ge-rtl \
ge-lib \
ge-init \
ge-aurora \
ge-services
/usr/local/gramado-build:
-sudo mkdir /usr/local/gramado-build
ge-boot:
#::boot
@echo "=================== "
@echo "Compiling boot/ ... "
$(Q) $(NASM) ge/boot/x86/0vhd/main.asm -I ge/boot/x86/0vhd/ -o GRAMADO.VHD
$(Q) $(MAKE) -C ge/boot/x86/1bm/
$(Q) $(MAKE) -C ge/boot/x86/2bl/
sudo cp ge/boot/x86/bin/BM.BIN base/
sudo cp ge/boot/x86/bin/BM.BIN base/BOOT
sudo cp ge/boot/x86/bin/BM.BIN base/SBIN
sudo cp ge/boot/x86/bin/BL.BIN base/
sudo cp ge/boot/x86/bin/BL.BIN base/BOOT
sudo cp ge/boot/x86/bin/BL.BIN base/SBIN
# KERNEL.BIN - Creating the kernel image.
ge-kernel:
#::kernel
@echo "================================="
@echo "(Step 1) Creating the kernel image ..."
$(Q) $(MAKE) -C ge/kernel
sudo cp ge/kernel/KERNEL.BIN base/
sudo cp ge/kernel/KERNEL.BIN base/BOOT
sudo cp ge/kernel/KERNEL.BIN base/SBIN
ge-rtl:
#::rtl
@echo "==================="
@echo "Compiling rtl ..."
$(Q) $(MAKE) -C ge/rtl/
ge-lib:
#::lib
@echo "==================="
@echo "Compiling lib ..."
$(Q) $(MAKE) -C ge/lib/
ge-init:
#::init
@echo "==================="
@echo "Compiling init ..."
$(Q) $(MAKE) -C ge/init/
sudo cp ge/init/INIT.BIN base/
sudo cp ge/init/INIT.BIN base/SBIN
ge-aurora:
#::aurora Aurora Window Server.
@echo "==================="
@echo "Compiling Aurora window server ..."
$(Q) $(MAKE) -C ge/aurora/
# gws
-sudo cp ge/aurora/bin/GWS.BIN base/
-sudo cp ge/aurora/bin/GWSSRV.BIN base/
-sudo cp ge/aurora/bin/GWSSRV.BIN base/SBIN
ge-services:
#::services Services
@echo "==================="
@echo "Compiling services..."
$(Q) $(MAKE) -C ge/services/gnssrv/
# gns
-sudo cp ge/services/gnssrv/bin/GNS.BIN base/
-sudo cp ge/services/gnssrv/bin/GNSSRV.BIN base/
-sudo cp ge/services/gnssrv/bin/GNSSRV.BIN base/SBIN
#===================================================
#:::1
# ~ Step 1 Setup directories.
PHONY := build-applications
build-applications: \
setup0-grass \
setup1-apps \
setup1-net \
setup2-cmd
setup0-grass:
#::grass
$(Q) $(MAKE) -C setup0/grass/
sudo cp setup0/grass/bin/GDESHELL.BIN base/
sudo cp setup0/grass/bin/GDESHELL.BIN base/SBIN
# setup
#-sudo cp setup0/grass/bin/*.BIN base/
sudo cp setup0/grass/bin/LAUNCHER.BIN base/
sudo cp setup0/grass/bin/GRAMCODE.BIN base/
sudo cp setup0/grass/bin/GFE.BIN base/
sudo cp setup0/grass/bin/SYSMON.BIN base/
#sudo cp setup0/grass/bin/REBOOT2.BIN base/
#sudo cp setup0/grass/bin/NORATERM.BIN base/
#tests interpreters.
#sudo cp setup0/grass/bin/C4.BIN base/
#sudo cp setup0/grass/bin/GRAMC.BIN base/
sudo cp setup0/grass/bin/GRAMC4.BIN base/
#sudo cp setup0/grass/bin/GRAMCNF.BIN base/
# ====================================================
setup1-apps:
#::apps
$(Q) $(MAKE) -C setup1/apps/
# apps
# -sudo cp setup1/apps/bin/*.BIN base/
# -sudo cp setup1/apps/bin/*.BIN base/PROGRAMS
#-sudo cp setup1/apps/bin/GWM.BIN base/
-sudo cp setup1/apps/bin/EDITOR.BIN base/
-sudo cp setup1/apps/bin/FILEMAN.BIN base/
-sudo cp setup1/apps/bin/LAUNCH1.BIN base/
#-sudo cp setup1/apps/bin/TERMINAL.BIN base/
setup1-net:
#::net
$(Q) $(MAKE) -C setup1/net/
-sudo cp setup1/net/bin/*.BIN base/
# -sudo cp setup1/net/bin/*.BIN base/PROGRAMS
setup2-cmd:
#::cmd
$(Q) $(MAKE) -C setup2/cmd/
#-sudo cp setup2/cmd/bin/*.BIN base/
#-sudo cp setup2/cmd/bin/*.BIN base/BIN
-sudo cp setup2/cmd/bin/REBOOT.BIN base/
-sudo cp setup2/cmd/bin/CAT.BIN base/
#-sudo cp setup2/cmd/bin/FASM.BIN base/
# -sudo cp setup2/cmd/bin/TRUE.BIN base/
# -sudo cp setup2/cmd/bin/FALSE.BIN base/
# -sudo cp setup2/cmd/bin/SHOWFUN.BIN base/
#-sudo cp setup2/cmd/bin/MINIYACC.BIN base/
#-sudo cp setup2/cmd/bin/SHELL.BIN base/
#===================================================
#:::2
# Step 2: /mnt/gramadovhd - Creating the directory to mount the VHD.
/mnt/gramadovhd:
@echo "================================="
@echo "(Step 2) Creating the directory to mount the VHD ..."
sudo mkdir /mnt/gramadovhd
#===================================================
#:::3
# ~ Step 3: vhd-mount - Mounting the VHD.
vhd-mount:
@echo "================================="
@echo "(Step 3) Mounting the VHD ..."
-sudo umount /mnt/gramadovhd
sudo mount -t vfat -o loop,offset=32256 GRAMADO.VHD /mnt/gramadovhd/
#===================================================
#:::4
# ~ Step 4 vhd-copy-files - Copying files into the mounted VHD.
# Copying the base folder into the mounted VHD.
vhd-copy-files:
@echo "================================="
@echo "(Step 4) Copying files into the mounted VHD ..."
# Copy base
# sends everything from base to root.
sudo cp -r base/* /mnt/gramadovhd
#===================================================
#:::5
# ~ Step 5 vhd-unmount - Unmounting the VHD.
vhd-unmount:
@echo "================================="
@echo "(Step 5) Unmounting the VHD ..."
sudo umount /mnt/gramadovhd
#
# == clean ====================================
#
clean-all: \
clean clean2 clean3 clean4 clean-system-files
@echo "==================="
@echo "ok ?"
#===================================================
#:::6
# ~ Step 6 clean - Deleting the object files.
clean:
@echo "================================="
@echo "(Step 6) Deleting the object files ..."
-rm *.o
-rm -rf ge/rtl/obj/*.o
@echo "Success?"
# clean ISO and VHD.
clean2:
-rm *.ISO
-rm *.VHD
# clean setup
clean3:
-rm setup0/grass/bin/*.BIN
-rm setup1/apps/bin/*.BIN
-rm setup1/net/bin/*.BIN
-rm setup2/cmd/bin/*.BIN
# clean base
clean4:
-rm -rf base/*.BIN
-rm -rf base/BOOT/*.BIN
-rm -rf base/BIN/*.BIN
-rm -rf base/SBIN/*.BIN
# -rm -rf base/PROGRAMS/*.BIN
# -rm -rf base/SBIN/*.BIN
# clean system files.
PHONY := clean-system-files
clean-system-files:
@echo "==================="
@echo "Cleaning all system binaries ..."
# Gramado
-rm -rf ge/boot/x86/bin/*.BIN
-rm -rf ge/kernel/KERNEL.BIN
# Init
-rm -rf ge/init/*.BIN
# fonts
-rm -rf ge/fonts/bin/*.FON
# aurora
-rm -rf ge/aurora/bin/*.BIN
# Services
-rm -rf ge/services/gnssrv/bin/*.BIN
# ...
# Setup
-rm -rf setup0/grass/bin/*.BIN
-rm -rf setup1/apps/bin/*.BIN
-rm -rf setup1/net/bin/*.BIN
-rm -rf setup2/cmd/bin/*.BIN
# ...
## ==================================================================
## The extra stuff.
## 1) ISO support.
## 2) HDD support.
## 3) VM support.
## 4) Serial debug support.
## 5) Clean files support.
## 6) Usage support.
#
# ======== ISO ========
#
# test
# todo
# Create a .ISO file using nasm.
makeiso-x86:
#todo:
#nasm -I kernel/boot/x86/iso/stage1/ \
#-I kernel/boot/x86/iso/???/ kernel/boot/x86/iso/main.asm -o GRAMADO.ISO
@echo "#todo Create ISO using nasm"
# ISO
# Mount stage1.bin file with nasm.
# Create a .ISO file and move all the content of the /bin folder
# into the .ISO file.
geniso-x86:
#stage1
$(NASM) ge/kernel/boot/x86/iso/stage1/stage1.asm -f bin -o stage1.bin
cp stage1.bin bin/boot/gramado/
rm stage1.bin
#.ISO
# mkisofs -R -J -c boot/gramado/boot.catalog -b boot/gramado/stage1.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o GRAMADO.ISO bin
@echo "iso Success?"
#
# == HDD ================================
#
hdd-mount:
-sudo umount /mnt/gramadohdd
sudo mount -t vfat -o loop,offset=32256 /dev/sda /mnt/gramadohdd/
# sudo mount -t vfat -o loop,offset=32256 /dev/sdb /mnt/gramadohdd/
hdd-unmount:
-sudo umount /mnt/gramadohdd
hdd-copy-kernel:
sudo cp bin/boot/KERNEL.BIN /mnt/gramadohdd/BOOT
# Danger!!
# This is gonna copy th image into the real HD.
# My host is running on sdb and i copy the image into sda.
# It is because the sda is in primary master IDE.
danger-hdd-clone-vhd:
sudo dd if=./GRAMADO.VHD of=/dev/sda
# sudo dd if=./GRAMADO.VHD of=/dev/sdb
#
# == VM ====================
#
# Oracle Virtual Box
# This target runs the image in the virtual box emulator.
# I use a virtual machine called "Gramado"
oracle-virtual-box-test:
VBoxManage startvm "Gramado"
# qemu
# This target runs the image in the qemu emulator.
# You also van use a script called "./run".
qemu-test:
qemu-system-x86_64 -hda GRAMADO.VHD -m 512 -serial stdio
# qemu-system-x86_64 -hda GRAMADO.VHD -m 128 -device e1000 -show-cursor -serial stdio -device e1000
# ??
test-sda:
sudo qemu-system-i386 -m 512 -drive file=/dev/sda,format=raw
# ??
test-sdb:
sudo qemu-system-i386 -m 512 -drive file=/dev/sdb,format=raw
#install-kvm-qemu:
# sudo pacman -S virt-manager qemu vde2 ebtables dnsmasq bridge-utils openbsd-netcat
#
# == SERIAL DEBUG ===============================
#
# It shows the serial debug output file.
# fixme.
serial-debug:
# cat ./docs/sdebug.txt
#
# Image support.
#
kernel-version:
@echo $(KERNELVERSION)
image-name:
@echo $(KBUILD_IMAGE)
kernel-file-header:
# -rm docs/KFH.TXT
# readelf -h bin/boot/KERNEL.BIN > docs/KFH.TXT
# cat docs/KFH.TXT
kernel-program-headers:
# -rm docs/KPH.TXT
# readelf -l bin/boot/KERNEL.BIN > docs/KPH.TXT
# cat docs/KPH.TXT
kernel-section-headers:
-rm docs/KSH.TXT
readelf -S bin/boot/KERNEL.BIN > docs/KSH.TXT
cat docs/KSH.TXT
#
# gcc support
#
gcc-test:
# chmod 755 ./scripts/gcccheck
# ./scripts/gcccheck
#
# == USAGE ========
#
help:
@echo " help:"
@echo " all - make all"
@echo " clean - Remove all .o files"
@echo " clean2 - Remove .VHD and .ISO files"
@echo " vhd-mount - Mount VHD"
@echo " vhd-unmount - Unmount VHD"
@echo " qemu-test - Run on qemu"
@echo " oracle-virtual-box-test - Run on virtual-box"
@echo " ..."