1# Copyright 2016 The Fuchsia Authors
2# Copyright (c) 2008-2015 Travis Geiselbrecht
3#
4# Use of this source code is governed by a MIT-style
5# license that can be found in the LICENSE file or at
6# https://opensource.org/licenses/MIT
7
8LOCAL_DIR := $(GET_LOCAL_DIR)
9
10MODULE := $(LOCAL_DIR)
11
12BOOT_HEADER_SIZE ?= 0x70
13KERNEL_LOAD_OFFSET ?= 0x00100000 # 1MB
14KERNEL_BASE ?= 0xffffffff80100000 # has KERNEL_LOAD_OFFSET baked into it
15KERNEL_SIZE ?= 0x40000000 # 1GB
16KERNEL_ASPACE_BASE ?= 0xffffff8000000000UL # -512GB
17KERNEL_ASPACE_SIZE ?= 0x0000008000000000UL
18USER_ASPACE_BASE   ?= 0x0000000001000000UL # 16MB
19# We set the top of user address space to be (1 << 47) - 4k.  See
20# docs/sysret_problem.md for why we subtract 4k here.  Subtracting
21# USER_ASPACE_BASE from that value gives the value for USER_ASPACE_SIZE
22# below.
23USER_ASPACE_SIZE   ?= 0x00007ffffefff000UL
24
25LOCAL_BUILDDIR := $(call TOBUILDDIR,$(LOCAL_DIR))
26
27KERNEL_DEFINES += \
28	ARCH_$(ARCH)=1 \
29	KERNEL_BASE=$(KERNEL_BASE) \
30	KERNEL_SIZE=$(KERNEL_SIZE) \
31	KERNEL_LOAD_OFFSET=$(KERNEL_LOAD_OFFSET)
32
33GLOBAL_DEFINES += \
34	KERNEL_ASPACE_BASE=$(KERNEL_ASPACE_BASE) \
35	KERNEL_ASPACE_SIZE=$(KERNEL_ASPACE_SIZE) \
36	USER_ASPACE_BASE=$(USER_ASPACE_BASE) \
37	USER_ASPACE_SIZE=$(USER_ASPACE_SIZE)
38
39MODULE_SRCS += \
40	$(LOCAL_DIR)/acpi.S \
41	$(LOCAL_DIR)/arch.cpp \
42	$(LOCAL_DIR)/asm.S \
43	$(LOCAL_DIR)/bp_percpu.c \
44	$(LOCAL_DIR)/cache.cpp \
45	$(LOCAL_DIR)/cpu_topology.cpp \
46	$(LOCAL_DIR)/debugger.cpp \
47	$(LOCAL_DIR)/descriptor.cpp \
48	$(LOCAL_DIR)/exceptions.S \
49	$(LOCAL_DIR)/faults.cpp \
50	$(LOCAL_DIR)/feature.cpp \
51	$(LOCAL_DIR)/gdt.S \
52	$(LOCAL_DIR)/hwp.cpp \
53	$(LOCAL_DIR)/idt.cpp \
54	$(LOCAL_DIR)/ioapic.cpp \
55	$(LOCAL_DIR)/ioport.cpp \
56	$(LOCAL_DIR)/lapic.cpp \
57	$(LOCAL_DIR)/mexec.S \
58	$(LOCAL_DIR)/mmu.cpp \
59	$(LOCAL_DIR)/mmu_mem_types.cpp \
60	$(LOCAL_DIR)/mmu_tests.cpp \
61	$(LOCAL_DIR)/mp.cpp \
62	$(LOCAL_DIR)/ops.S \
63	$(LOCAL_DIR)/perf_mon.cpp \
64	$(LOCAL_DIR)/proc_trace.cpp \
65	$(LOCAL_DIR)/pvclock.cpp \
66	$(LOCAL_DIR)/registers.cpp \
67	$(LOCAL_DIR)/start.S \
68	$(LOCAL_DIR)/syscall.S \
69	$(LOCAL_DIR)/thread.cpp \
70	$(LOCAL_DIR)/timer_freq.cpp \
71	$(LOCAL_DIR)/tsc.cpp \
72	$(LOCAL_DIR)/user_copy.S \
73	$(LOCAL_DIR)/user_copy.cpp \
74	$(LOCAL_DIR)/uspace_entry.S \
75
76MODULE_DEPS += \
77	kernel/arch/x86/page_tables \
78	kernel/dev/iommu/dummy \
79	kernel/dev/iommu/intel \
80	kernel/lib/bitmap \
81	kernel/lib/crashlog \
82	kernel/lib/code_patching \
83	kernel/lib/fbl \
84	kernel/object
85
86include $(LOCAL_DIR)/toolchain.mk
87
88MODULE_SRCS += \
89	$(LOCAL_DIR)/bootstrap16.cpp \
90	$(LOCAL_DIR)/smp.cpp \
91	$(LOCAL_DIR)/start16.S
92
93# default to 16 cpu max support
94SMP_MAX_CPUS ?= 16
95KERNEL_DEFINES += \
96	SMP_MAX_CPUS=$(SMP_MAX_CPUS)
97
98# set the default toolchain to x86 elf and set a #define
99ifndef TOOLCHAIN_PREFIX
100TOOLCHAIN_PREFIX := $(ARCH_x86_64_TOOLCHAIN_PREFIX)
101endif
102
103#$(warning ARCH_x86_TOOLCHAIN_PREFIX = $(ARCH_x86_TOOLCHAIN_PREFIX))
104#$(warning ARCH_x86_64_TOOLCHAIN_PREFIX = $(ARCH_x86_64_TOOLCHAIN_PREFIX))
105#$(warning TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
106
107cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`"; \
108	then echo "$(2)"; else echo "$(3)"; fi ;)
109
110# disable SSP if the compiler supports it; it will break stuff
111GLOBAL_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
112
113# set the default architecture
114GLOBAL_COMPILEFLAGS += -march=x86-64 -mcx16
115
116CLANG_ARCH := x86_64
117ifeq ($(call TOBOOL,$(USE_CLANG)),true)
118GLOBAL_LDFLAGS += -m elf_x86_64
119GLOBAL_MODULE_LDFLAGS += -m elf_x86_64
120endif
121GLOBAL_LDFLAGS += -z max-page-size=4096
122ifeq ($(call TOBOOL,$(USE_CLANG)),false)
123KERNEL_COMPILEFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=4
124# Don't over-align data by default, which GCC always did before.
125# Newer binutils complains about over-aligned SHT_NOTE sections.
126GLOBAL_COMPILEFLAGS += -malign-data=abi
127endif
128
129# hard disable floating point in the kernel
130KERNEL_COMPILEFLAGS += -msoft-float -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -mno-avx -mno-avx2
131ifeq ($(call TOBOOL,$(USE_CLANG)),false)
132KERNEL_COMPILEFLAGS += -mno-80387 -mno-fp-ret-in-387
133endif
134
135KERNEL_COMPILEFLAGS += -fPIE -include kernel/include/hidden.h
136KERNEL_COMPILEFLAGS += -mno-red-zone
137
138# Clang needs -mcmodel=kernel to tell it to use the right safe-stack ABI for
139# the kernel.
140ifeq ($(call TOBOOL,$(USE_CLANG)),true)
141KERNEL_COMPILEFLAGS += -mcmodel=kernel
142endif
143
144# optimization: since fpu is disabled, do not pass flag in rax to varargs routines
145# that floating point args are in use.
146ifeq ($(call TOBOOL,$(USE_CLANG)),false)
147KERNEL_COMPILEFLAGS += -mskip-rax-setup
148endif
149
150ifeq ($(call TOBOOL,$(ENABLE_NEW_BOOTDATA)),true)
151MODULE_DEFINES += ENABLE_NEW_BOOTDATA=1
152endif
153
154include make/module.mk
155