d88b3ae0fd41fc45e4f4e0461d1a249dccec6054
[barrelfish] / hake / ARMv7.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, Universitaetstasse 6, 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 ARMv7 where
17
18 import HakeTypes
19 import qualified Config
20 import qualified ArchDefaults
21
22 -------------------------------------------------------------------------
23 --
24 -- Architecture specific definitions for ARM
25 --
26 -------------------------------------------------------------------------
27
28 arch = "armv7"
29 archFamily = "arm"
30
31 compiler    = Config.arm_cc
32 objcopy     = Config.arm_objcopy
33 objdump     = Config.arm_objdump
34 ar          = Config.arm_ar
35 ranlib      = Config.arm_ranlib
36 cxxcompiler = Config.arm_cxx
37
38 ourCommonFlags = [ Str "-fno-unwind-tables",
39                    Str "-Wno-packed-bitfield-compat",
40                    Str "-marm",
41                    Str "-fno-stack-protector",
42                    Str "-mcpu=cortex-a9",
43                    Str "-march=armv7-a",
44                    Str "-mapcs",
45                    Str "-mabi=aapcs-linux",
46                    Str "-mfloat-abi=hard",
47                    Str "-mfpu=vfpv3",
48                    Str "-msingle-pic-base",
49                    Str "-mpic-register=r9",
50                    Str "-DPIC_REGISTER=R9",
51                    Str "-fPIE",
52                    Str "-D__ARM_CORTEX__",
53                    Str "-D__ARM_ARCH_7A__",
54                    Str "-Wno-unused-but-set-variable",
55                    Str "-Wno-suggest-attribute=noreturn",
56                    Str "-Wno-format"
57  ]
58
59 cFlags = ArchDefaults.commonCFlags
60          ++ ArchDefaults.commonFlags
61          ++ ourCommonFlags
62
63 cxxFlags = ArchDefaults.commonCxxFlags
64            ++ ArchDefaults.commonFlags
65            ++ ourCommonFlags
66
67 cDefines = ArchDefaults.cDefines options
68
69 ourLdFlags = [ Str "-Wl,-section-start,.text=0x400000",
70                Str "-Wl,--build-id=none",
71                Str "-static" ]
72
73 ldFlags = ArchDefaults.ldFlags arch ++ ourLdFlags
74 ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
75
76 stdLibs = ArchDefaults.stdLibs arch
77
78 options = (ArchDefaults.options arch archFamily) {
79             optFlags = cFlags,
80             optCxxFlags = cxxFlags,
81             optDefines = cDefines,
82             optDependencies =
83                 [ PreDep InstallTree arch "/include/trace_definitions/trace_defs.h",
84                   PreDep InstallTree arch "/include/errors/errno.h",
85                   PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
86                   PreDep InstallTree arch "/include/asmoffsets.h"
87                    ],
88             optLdFlags = ldFlags,
89             optLdCxxFlags = ldCxxFlags,
90             optLibs = stdLibs,
91             optInterconnectDrivers = ["lmp", "ump"],
92             optFlounderBackends = ["lmp", "ump"]
93           }
94
95 --
96 -- Compilers
97 --
98 cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
99 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
100 makeDepend = ArchDefaults.makeDepend arch compiler
101 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
102 cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
103 assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
104 archive = ArchDefaults.archive arch
105 linker = ArchDefaults.linker arch compiler
106 strip = ArchDefaults.strip arch objcopy
107 debug = ArchDefaults.debug arch objcopy
108 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
109
110 --
111 -- The kernel is "different"
112 --
113
114 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
115                                 "-fno-unwind-tables",
116                                 "-nostdinc",
117                                 "-std=c99",
118                                 "-marm",
119                                 "-mcpu=cortex-a9",
120                                 "-march=armv7-a",
121                                 "-mapcs",
122                                 "-mabi=aapcs-linux",
123                                 "-mfloat-abi=hard",
124                                 "-fPIE",
125                                 "-U__linux__",
126                                 "-Wall",
127                                 "-Wshadow",
128                                 "-Wstrict-prototypes",
129                                 "-Wold-style-definition",
130                                 "-Wmissing-prototypes",
131                                 "-Wmissing-declarations",
132                                 "-Wmissing-field-initializers",
133                                 "-Wredundant-decls",
134                                 "-Werror",
135                                 "-imacros deputy/nodeputy.h",
136                                 "-fno-stack-check",
137                                 "-ffreestanding",
138                                 "-fomit-frame-pointer",
139                                 "-mno-long-calls",
140                                 "-Wmissing-noreturn",
141                                 "-mno-apcs-stack-check",
142                                 "-mno-apcs-reentrant",
143                                 "-msingle-pic-base",
144                                 "-mno-pic-data-is-text-relative",
145                                 "-mpic-register=r9",
146                                 "-DPIC_REGISTER=R9",
147                                 "-D__ARM_CORTEX__",
148                                 "-D__ARM_ARCH_7A__",
149                                 "-Wno-unused-but-set-variable",
150                                 "-Wno-suggest-attribute=noreturn",
151                                 "-Wno-format" ]]
152
153 kernelLdFlags = [ Str "-Wl,-N",
154                   Str "-fno-builtin",
155                   Str "-nostdlib",
156                   Str "-pie",
157                   Str "-Wl,--fatal-warnings",
158                   Str "-Wl,--dynamic-list-data",
159                   Str "-Wl,--export-dynamic"
160                 ]
161
162
163 --
164 -- Link the kernel (CPU Driver)
165 --
166 linkKernel :: Options -> [String] -> [String] -> String -> String -> HRule
167 linkKernel opts objs libs name driverType =
168     let linkscript = "/kernel/" ++ name ++ ".lds"
169         kernelmap  = "/kernel/" ++ name ++ ".map"
170         kasmdump   = "/kernel/" ++ name ++ ".asm"
171         kbinary    = "/sbin/" ++ name
172         kbootable  = kbinary ++ ".bin"
173     in
174         Rules [ Rule ([ Str compiler ] ++
175                     map Str Config.cOptFlags ++
176                     [ NStr "-T", In BuildTree arch linkscript,
177                       Str "-o", Out arch kbinary,
178                       NStr "-Wl,-Map,", Out arch kernelmap
179                     ]
180                     ++ (optLdFlags opts)
181                     ++
182                     [ In BuildTree arch o | o <- objs ]
183                     ++
184                     [ In BuildTree arch l | l <- libs ]
185                     ++
186                     (ArchDefaults.kernelLibs arch)
187                    ),
188               -- Generate kernel assembly dump
189               Rule [ Str objdump,
190                      Str "-d",
191                      Str "-M reg-names-raw",
192                      In BuildTree arch kbinary,
193                      Str ">", Out arch kasmdump ],
194               Rule [ Str "cpp",
195                      NStr "-I", NoDep SrcTree "src" "/kernel/include/arch/armv7",
196                      Str "-D__ASSEMBLER__",
197                      Str "-P",
198                         In SrcTree "src"
199                            ("/kernel/arch/armv7/"++driverType++".lds.in"),
200                      Out arch linkscript
201                    ],
202               -- Produce a stripped binary
203               Rule [ Str objcopy,
204                      Str "-g",
205                      In BuildTree arch kbinary,
206                      Out arch (kbinary ++ ".stripped")
207                    ]
208             ]