-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile.mips64
146 lines (119 loc) · 4.03 KB
/
Makefile.mips64
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
# Copyright (C) 2015 Gan Quan <coin2028@hotmail.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# Makefile for MIPS64
######## BEGIN CONFIG ########
# Cross-platform toolchain prefix.
# E.g. if
# CROSS_COMPILE = mips64-linux-gnu-
# then the cross-compiler should be
# mips64-linux-gnu-gcc
# The linker should be
# mips64-linux-gnu-ld
# etc.
CROSS_COMPILE = mips64el-n64-linux-uclibc-
# Machine name.
MACH = loongson3a
# Target device for kernel & bootloader installation.
#
# IMPORTANT:
# Make sure you select the correct device, or your own hard disk may become
# corrupted!
# I hadn't write the backup mechanism for kernel installation yet, but one
# can recover MBR in case of accidents. Refer to boot/Makefile.mips64 for
# more information.
INSTALLDEV = /dev/sdb
CCOMPILER = gcc
# Only needed if the installation needs sudo privileges
SUDO = sudo
# The partition number. DO NOT CHANGE THIS.
PARTNO = 2
######## END CONFIG ########
# Retrieve root directory.
# The expression $(shell <command>) executes the shell command and returns
# the output.
ROOTDIR = $(shell pwd)
# Capitalize $MACH, this is to be used for defining machine-specific
# macro MACH_$(UPPERMACH).
# E.g. if
# MACH = loongson3a
# then gcc compiles source code with
# MACH_LOONGSON3A
# defined.
UPPERMACH = $(shell echo $(MACH) | tr a-z- A-Z_)
# Cross-platform versions of GNU toolchain
CC = $(CROSS_COMPILE)$(CCOMPILER)
CPP = $(CROSS_COMPILE)cpp
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
# Specify all absolute include path, prepending each with -I (the include
# directory flag for gcc)
INCFLAG = -I. -I./include
INCFLAG += -I./include/arch/$(ARCH)
INCFLAG += -I./include/arch/$(ARCH)/asm/mach-$(MACH)
DEFS = -DMACH_$(UPPERMACH) -DELF64
# Compiling flags for GCC, see gcc(1) for details of each option.
CFLAGS = -O2 -G 0 -mno-abicalls -fno-pic -Wall -mabi=64 -fno-builtin
CFLAGS += -nostdinc -nostdlib -ggdb -mips64r2 -gstabs -EL -mno-mips16
CFLAGS += $(INCFLAG) $(DEFS)
# Linker script for ld(1)
LDSCRIPT = kern/arch/$(ARCH)/ldscript.ld
# Linker flag for ld(1)
LDFLAGS = -EL -N
# All object files
OBJS = kern/arch/$(ARCH)/start.o \
kern/arch/$(ARCH)/setup.o \
kern/init/main.o \
drivers/serial/uart16550.o \
drivers/serial/uart.o \
drivers/serial/uart-printf.o \
drivers/clock/mc146818.o \
lib/libc/stdio/snprintf.o \
lib/libc/string/memset.o
TEST_OBJS =
# Final program
BINARY = bootstrap
# Disassembly
DISASSEMBLY = $(BINARY).s
# Export all variables above to child make processes, which will
# spawn when compiling bootloader and userspace programs
export
# all: the default target when no target is specified in command
# line.
#
# Makes kernel and bootloader.
all: $(BINARY) boot tools
# elf: Make kernel by linking the object files and disassembling
# the binary program after all object files are compiled.
$(BINARY): $(OBJS) $(TEST_OBJS)
$(LD) $(LDFLAGS) -T $(LDSCRIPT) -o $(BINARY) $(OBJS) $(TEST_OBJS)
$(OBJDUMP) -S $(BINARY) >$(DISASSEMBLY)
# boot: Make bootloader.
# Change into boot/ directory and build there.
boot:
cd boot && make -f Makefile.$(ARCH)
# tools: Make tools
tools:
cd tools/stab && make
# install: Perform kernel and bootloader installation.
#
# First install bootloader by changing into boot/ directory and
# perform bootloader installation, then invoke the kernel installation
# perl script.
install: all
cd boot && make -f Makefile.$(ARCH) install
$(SUDO) dd if=$(BINARY) of=$(INSTALLDEV)$(PARTNO) conv=notrunc
# clean: Remove all files generated by make.
clean:
cd boot && make -f Makefile.$(ARCH) clean
cd tools/stab && make clean
rm -rf $(OBJS) $(BINARY)
# make by default doesn't know how to compile assemblies. So we specify
# the procedure here.
.S.o:
$(CC) $(CFLAGS) -c $< -o $*.o
.PHONY: all boot tools clean install test