0a27488b0e1299f1a8279d1b49e38b1c4b531f54
[barrelfish] / hake / ARMv5.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, Universit√§tstasse 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 ARMv5 where
17
18 import HakeTypes
19 import qualified Config
20 import qualified ArchDefaults
21
22 -------------------------------------------------------------------------
23 --
24 -- Architecture specific definitions for ARMv5
25 --
26 -------------------------------------------------------------------------
27
28 arch = "armv5"
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 "-mcpu=arm926ej-s",
41                    Str "-mapcs",
42                    Str "-mabi=aapcs-linux",
43                    Str "-msingle-pic-base",
44                    Str "-mpic-register=r10",
45                    Str "-DPIC_REGISTER=R10",
46                    Str "-fpic",
47                    Str "-ffixed-r9",
48                    Str "-DTHREAD_REGISTER=R9",
49                    Str "-D__ARM_ARCH_5__",
50                    Str "-fno-stack-check",
51                    Str "-fno-stack-protector",
52                    Str "-Wno-unused-but-set-variable",
53                    Str "-Wno-format" ]
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/errors/errno.h",
80                   PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
81                   PreDep InstallTree arch "/include/asmoffsets.h", 
82                   PreDep InstallTree arch "/include/romfs_size.h" ],
83             optLdFlags = ldFlags,
84             optLdCxxFlags = ldCxxFlags,
85             optLibs = stdLibs,
86             optInterconnectDrivers = ["lmp"],
87             optFlounderBackends = ["lmp"]
88           }
89
90 --
91 -- Compilers
92 --
93 cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
94 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
95 makeDepend = ArchDefaults.makeDepend arch compiler
96 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
97 cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
98 assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
99 archive = ArchDefaults.archive arch
100 linker = ArchDefaults.linker arch compiler
101 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
102
103
104 --
105 -- The kernel is "different"
106 --
107
108 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
109                                 "-fno-unwind-tables",
110                                 "-nostdinc",
111                                 "-std=c99",
112                                 "-mcpu=arm926ej-s",
113                                 "-mapcs",
114                                 "-mabi=aapcs-linux",
115                                 "-fPIE",
116                                 "-U__linux__",
117                                 "-Wall",
118                                 "-Wshadow",
119                                 "-Wstrict-prototypes",
120                                 "-Wold-style-definition",
121                                 "-Wmissing-prototypes",
122                                 "-Wmissing-declarations",
123                                 "-Wmissing-field-initializers",
124                                 "-Wredundant-decls",
125                                 "-Werror",
126                                 "-imacros deputy/nodeputy.h",
127                                 "-fpie",
128                                 "-fno-stack-check",
129                                 "-fno-stack-protector",
130                                 "-ffreestanding",
131                                 "-fomit-frame-pointer",
132                                 "-mno-long-calls",
133                                 "-Wmissing-noreturn",
134                                 "-mno-apcs-stack-check",
135                                 "-mno-apcs-reentrant",
136                                 "-msingle-pic-base",
137                                 "-mpic-register=r10",
138                                 "-DPIC_REGISTER=R10",
139                                 "-ffixed-r9",
140                                 "-DTHREAD_REGISTER=R9",
141                                 "-D__ARM_ARCH_5__",
142                                 "-Wno-unused-but-set-variable",
143                                 "-Wno-format" ]]
144
145 kernelLdFlags = [ Str "-Wl,-N",
146                   NStr "-Wl,-Map,", Out arch "kernel.map",
147                   Str "-fno-builtin",
148                   Str "-nostdlib",
149                   Str "-Wl,--fatal-warnings"
150                 ]
151
152
153 --
154 -- Link the kernel (CPU Driver)
155 --
156 linkKernel :: Options -> [String] -> [String] -> String -> HRule
157 linkKernel opts objs libs kbin =
158     let linkscript = "/kernel/linker.lds"
159         kbootable  = kbin ++ ".bin"
160     in
161         Rules [ Rule ([ Str compiler ] ++
162                       map Str Config.cOptFlags ++
163                     [ NStr "-T", In BuildTree arch linkscript,
164                       Str "-o", Out arch kbin
165                     ]
166                     ++ (optLdFlags opts)
167                     ++
168                     [ In BuildTree arch o | o <- objs ]
169                     ++
170                     [ In BuildTree arch l | l <- libs ]
171                     ++
172                     [ Str "-lgcc" ]
173                    ),
174               -- Edit ELF header so qemu-system-arm will treat it as a Linux kernel
175               Rule [ In SrcTree "src" "/tools/arm-mkbootelf.sh",
176                      Str objdump, In BuildTree arch kbin, Out arch (kbootable)],
177               -- Generate kernel assembly dump
178               Rule [ Str (objdump ++ " -d -M reg-names-raw"),
179                     In BuildTree arch kbin, Str ">", Out arch (kbin ++ ".asm")],
180               Rule [ Str "cpp",
181                      NStr "-I", NoDep SrcTree "src" "/kernel/include/arch/armv5",
182                      Str "-D__ASSEMBLER__",
183                      Str "-P", In SrcTree "src" "/kernel/arch/armv5/linker.lds.in",
184                      Out arch linkscript
185                    ]
186             ]