f3a13366abdd2ccaec9ef223c797969c8e982c57
[barrelfish] / hake / XScale.hs
1 --------------------------------------------------------------------------
2 -- Copyright (c) 2007-2015, 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 XScale with XScale cpu.
12 --
13 --------------------------------------------------------------------------
14
15 module XScale where
16
17 import HakeTypes
18 import qualified Config
19 import qualified ArchDefaults
20
21 -------------------------------------------------------------------------
22 --
23 -- Architecture specific definitions for ARM
24 --
25 -------------------------------------------------------------------------
26
27 arch = "xscale"
28 archFamily = "arm"
29
30 compiler    = Config.arm_cc
31 objcopy     = Config.arm_objcopy
32 objdump     = Config.arm_objdump
33 ar          = Config.arm_ar
34 ranlib      = Config.arm_ranlib
35 cxxcompiler = Config.arm_cxx
36
37 ourCommonFlags = [ Str "-Wno-packed-bitfield-compat",
38                    Str "-Wno-format",
39                    Str "-fno-unwind-tables",
40                    Str "-fshort-enums",
41                    Str "-mcpu=xscale",
42                    Str "-mbig-endian",
43                    Str "-mapcs",
44                    Str "-mabi=aapcs-linux",
45                    Str "-msingle-pic-base",
46                    Str "-mpic-register=r10",
47                    Str "-DPIC_REGISTER=R10",
48                    Str "-fpic",
49                    Str "-ffixed-r9",
50                    Str "-DTHREAD_REGISTER=R9",
51                    Str "-D__ARM_ARCH_5__" ]
52
53 cFlags = ArchDefaults.commonCFlags 
54          ++ ArchDefaults.commonFlags
55          ++ ourCommonFlags
56
57 cxxFlags = ArchDefaults.commonCxxFlags
58            ++ ArchDefaults.commonFlags
59            ++ ourCommonFlags
60
61 cDefines = ArchDefaults.cDefines options
62
63 ourLdFlags = [ Str "-Wl,-section-start,.text=0x400000",
64                Str "-Wl,-section-start,.data=0x600000",
65                Str "-mcpu=xscale",
66                Str "-mbig-endian" ]
67
68 ldFlags = ArchDefaults.ldFlags arch ++ ourLdFlags
69 ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
70
71 stdLibs = ArchDefaults.stdLibs arch ++ [ Str "-lgcc" ]
72
73 options = (ArchDefaults.options arch archFamily) { 
74             optFlags = cFlags,
75             optCxxFlags = cxxFlags,
76             optDefines = cDefines,
77             optDependencies = 
78                 [ PreDep InstallTree arch "/include/errors/errno.h",
79                   PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
80                   PreDep InstallTree arch "/include/asmoffsets.h", 
81                   PreDep InstallTree arch "/include/romfs_size.h" ],
82             optLdFlags = ldFlags,
83             optLdCxxFlags = ldCxxFlags,
84             optLibs = stdLibs,
85             optInterconnectDrivers = ["lmp"],
86             optFlounderBackends = ["lmp"]
87           }
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 -- The kernel is "different"
105 --
106
107 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
108                                 "-fno-unwind-tables",
109                                 "-fshort-enums",
110                                 "-nostdinc",
111                                 "-std=c99",
112                                 "-mcpu=xscale",
113                                 "-mbig-endian",
114                                 "-mapcs",
115                                 "-mabi=aapcs-linux",
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                                 "-Wno-implicit-function-declaration",
126                                 "-Wredundant-decls",
127                                 "-Werror",
128                                 "-imacros deputy/nodeputy.h",
129                                 "-fpie",
130                                 "-fno-stack-check",
131                                 "-ffreestanding",
132                                 "-fomit-frame-pointer",
133                                 "-mno-long-calls",
134                                 "-Wno-missing-noreturn",
135                                 "-Wno-format",
136                                 "-mno-apcs-stack-check",
137                                 "-mno-apcs-reentrant",
138                                 "-msingle-pic-base",
139                                 "-mpic-register=r10",
140                                 "-DPIC_REGISTER=R10",
141                                 "-ffixed-r9",
142                                 "-DTHREAD_REGISTER=R9",
143                                 "-D__ARM_ARCH_5__" ]]
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           Str "-mcpu=xscale",
151           Str "-mbig-endian"
152                 ]
153
154
155 --
156 -- Link the kernel (CPU Driver)
157 --
158 linkKernel :: Options -> [String] -> [String] -> String -> HRule
159 linkKernel opts objs libs kbin =
160     let linkscript = "/kernel/linker.lds"
161         kbootable  = kbin ++ ".bin"
162     in
163         Rules [ Rule ([ Str compiler ] ++
164                       map Str Config.cOptFlags ++
165                       [ NStr "-T", In BuildTree arch linkscript,
166                         Str "-o", Out arch kbin
167                       ]
168                     ++ (optLdFlags opts)
169                     ++
170                     [ In BuildTree arch o | o <- objs ]
171                     ++
172                     [ In BuildTree arch l | l <- libs ]
173                     ++
174                     [ Str "-lgcc" ]
175                    ),
176               -- Edit ELF header so qemu-system-arm will treat it as a Linux kernel
177               Rule [ In SrcTree "src" "/tools/arm-mkbootelf.sh",
178                      Str objdump, In BuildTree arch kbin, Out arch (kbootable)],
179               -- Generate kernel assembly dump
180               Rule [ Str (objdump ++ " -d -M reg-names-raw"),
181                     In SrcTree arch kbin, Str ">", Out arch (kbin ++ ".asm")],
182               Rule [ Str "cpp",
183                      NStr "-I", NoDep SrcTree "src" "/kernel/include/arch/xscale",
184                      Str "-D__ASSEMBLER__",
185                      Str "-P", In SrcTree "src" "/kernel/arch/xscale/linker.lds.in",
186                      Out arch linkscript
187                    ]
188             ]