e8695ddac6babccaa982b4d3aa06a52f5ff69579
[barrelfish] / hake / ARMv8.hs
1 --------------------------------------------------------------------------
2 -- Copyright (c) 2007-2010, ETH Zurich.
3 -- All rights reserved.
4 --
5 -- This file is distributed under the terms in the attached LICENSE file.
6 -- If you do not find this file, copies can be found by writing to:
7 -- ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 --
9 -- Architectural definitions for Barrelfish on ARMv5 ISA.
10 --
11 -- The build target is the integratorcp board on QEMU with the default
12 -- ARM926EJ-S cpu.
13 --
14 --------------------------------------------------------------------------
15
16 module ARMv8 where
17
18 import HakeTypes
19 import Path
20 import qualified Config
21 import qualified ArchDefaults
22
23 -------------------------------------------------------------------------
24 --
25 -- Architecture specific definitions for ARM
26 --
27 -------------------------------------------------------------------------
28
29 arch = "armv8"
30 archFamily = "aarch64"
31
32 compiler = "aarch64-apm-linux-gnu-gcc"
33 objcopy  = "aarch64-apm-linux-gnu-objcopy"
34 objdump  = "aarch64-apm-linux-gnu-objdump"
35 ar       = "aarch64-apm-linux-gnu-ar"
36 ranlib   = "aarch64-apm-linux-gnu-ranlib"
37 cxxcompiler = "aarch64-apm-linux-gnu-g++"
38
39 ourCommonFlags = [ Str "-fno-unwind-tables",
40                    Str "-Wno-packed-bitfield-compat",
41                    Str "-fno-stack-protector",
42                    Str "-mcpu=cortex-a57",
43                    Str "-march=armv8-a",
44                    Str "-mabi=lp64",
45                    Str "-DPIC_REGISTER=X10",
46                    Str "-fPIE",
47                    Str "-ffixed-r9",
48                    Str "-DTHREAD_REGISTER=X9",
49                    Str "-D__ARM_CORTEX__",
50                    Str "-D__ARM_ARCH_8A__",
51                    Str "-Wno-unused-but-set-variable",
52                    Str "-Wno-format"
53  ]
54
55 cFlags = ArchDefaults.commonCFlags 
56          ++ ArchDefaults.commonFlags
57          ++ ourCommonFlags
58
59 cxxFlags = ArchDefaults.commonCxxFlags
60            ++ ArchDefaults.commonFlags
61            ++ ourCommonFlags
62
63 cDefines = ArchDefaults.cDefines options
64
65 ourLdFlags = [ Str "-Wl,-section-start,.text=0x400000",
66                Str "-Wl,-section-start,.data=0x600000",
67                Str "-Wl,--build-id=none" ]
68
69 ldFlags = ArchDefaults.ldFlags arch ++ ourLdFlags
70 ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
71
72 stdLibs = ArchDefaults.stdLibs arch ++ [ Str "-lgcc" ]
73
74 options = (ArchDefaults.options arch archFamily) { 
75             optFlags = cFlags,
76             optCxxFlags = cxxFlags,
77             optDefines = cDefines,
78             optDependencies = 
79                 [ PreDep InstallTree arch "/include/trace_definitions/trace_defs.h",
80                   PreDep InstallTree arch "/include/errors/errno.h",
81                   PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
82                   PreDep InstallTree arch "/include/asmoffsets.h"
83                    ],
84             optLdFlags = ldFlags,
85             optLdCxxFlags = ldCxxFlags,
86             optLibs = stdLibs,
87             optInterconnectDrivers = ["lmp", "ump"],
88             optFlounderBackends = ["lmp", "ump"]
89           }
90
91 --
92 -- Compilers
93 --
94 cCompiler = ArchDefaults.cCompiler arch compiler
95 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
96 makeDepend = ArchDefaults.makeDepend arch compiler
97 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
98 cToAssembler = ArchDefaults.cToAssembler arch compiler
99 assembler = ArchDefaults.assembler arch compiler
100 archive = ArchDefaults.archive arch
101 linker = ArchDefaults.linker arch compiler
102 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
103
104
105 --
106 -- The kernel is "different"
107 --
108
109 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
110                                 "-fno-unwind-tables",
111                                 "-nostdinc",
112                                 "-std=c99",
113                                 "-mcpu=cortex-a57",
114                                 "-march=armv8-a",
115                                 "-mabi=lp64",
116                                 "-fPIE",
117                                 "-U__linux__",
118                                 "-Wall",
119                                 "-Wshadow",
120                                 "-Wstrict-prototypes",
121                                 "-Wold-style-definition",
122                                 "-Wmissing-prototypes",
123                                 "-Wmissing-declarations",
124                                 "-Wmissing-field-initializers",
125                                 "-Wredundant-decls",
126                                 "-Werror",
127                                 "-imacros deputy/nodeputy.h",
128                                 "-fno-stack-check",
129                                 "-ffreestanding",
130                                 "-fomit-frame-pointer",
131                                 "-Wmissing-noreturn",
132                                 "-ffixed-r9",
133                                 "-DTHREAD_REGISTER=X9",
134                                 "-D__ARM_CORTEX__",
135                                 "-D__ARM_ARCH_8A__",
136                                 "-Wno-unused-but-set-variable",
137                                 "-Wno-format"
138                               ]]
139
140 kernelLdFlags = [ Str "-Wl,-N",
141                   Str "-fno-builtin",
142                   Str "-nostdlib",
143                   Str "-pie",
144                   Str "-Wl,--fatal-warnings"
145                 ]
146
147
148 --
149 -- Link the kernel (CPU Driver)
150 --
151 linkKernel :: Options -> [String] -> [String] -> String -> HRule
152 linkKernel opts objs libs name =
153     let linkscript = "/kernel/" ++ name ++ ".lds"
154         kernelmap  = "/kernel/" ++ name ++ ".map"
155         kasmdump   = "/kernel/" ++ name ++ ".asm"
156         kbinary    = "/sbin/" ++ name
157         kbootable  = kbinary ++ ".bin"
158     in
159         Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
160                       NStr "-T", In BuildTree arch linkscript,
161                       Str "-o", Out arch kbinary,
162                       NStr "-Wl,-Map,", Out arch kernelmap
163                     ]
164                     ++ (optLdFlags opts)
165                     ++
166                     [ In BuildTree arch o | o <- objs ]
167                     ++
168                     [ In BuildTree arch l | l <- libs ]
169                     ++
170                     [ Str "-lgcc" ]
171                    ),
172               -- Generate kernel assembly dump
173               Rule [ Str objdump, 
174                      Str "-d", 
175                      Str "-M reg-names-raw",
176                      In BuildTree arch kbinary, 
177                      Str ">", Out arch kasmdump ],
178               Rule [ Str "cpp",
179                      NStr "-I", NoDep SrcTree "src" "/kernel/include/arch/armv8",
180                      Str "-D__ASSEMBLER__",
181                      Str "-P", In SrcTree "src" "/kernel/arch/armv8/linker.lds.in",
182                      Out arch linkscript
183                    ]
184             ]