3e76897f3fbecb0038d0958b752499a20bfb0cd7
[barrelfish] / hake / K1om.hs
1 --------------------------------------------------------------------------
2 -- Copyright (c) 2007-2016, 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 x86_mic.
10 --
11 -- This architecture is used to build for the Intel Xeon Phi architecture.
12 --
13 --------------------------------------------------------------------------
14
15 module K1om where
16
17 import HakeTypes
18 import qualified Config
19 import qualified ArchDefaults
20
21 -------------------------------------------------------------------------
22 --
23 -- Architecture specific definitions for X86_64-k1om
24 --
25 -------------------------------------------------------------------------
26
27 arch = "k1om"
28 archFamily = "k1om"
29
30 compiler    = Config.k1om_cc
31 objcopy     = Config.k1om_objcopy
32 objdump     = Config.k1om_objdump
33 ar          = Config.k1om_ar
34 ranlib      = Config.k1om_ranlib
35 cxxcompiler = Config.k1om_cxx
36
37 ourCommonFlags = [ Str "-m64",
38                    Str "-mno-red-zone",
39                    Str "-fPIE",
40                    Str "-fno-stack-protector",
41                    Str "-Wno-unused-but-set-variable",
42                    Str "-Wno-packed-bitfield-compat",
43                    Str "-fno-tree-vectorize",
44                    Str "-Wa,-march=k1om+noavx",
45                    Str "-march=knc",
46                    Str "-mtune=knc",
47                    Str "-mknc",
48                    Str "-mno-mmx",
49                    Str "-mno-sse",
50                    Str "-mno-sse2",
51                    Str "-mno-sse3",
52                    Str "-mno-sse4.1",
53                    Str "-mno-sse4.2",
54                    Str "-mno-sse4",
55                    Str "-mno-sse4a",
56                    Str "-mno-3dnow",
57 -- Apparently the MPSS gcc somehow incudes CMOVES?
58                    Str "-fno-if-conversion",
59 -- specific Xeon Phi architecture
60                    Str "-D__x86__",
61                    Str "-D__k1om__" ]
62
63
64 cFlags = ArchDefaults.commonCFlags
65                ++ ArchDefaults.commonFlags
66                ++ ourCommonFlags
67                ++ [Str "-fno-builtin" ]
68
69 cxxFlags = ArchDefaults.commonCxxFlags
70                  ++ ArchDefaults.commonFlags
71                  ++ ourCommonFlags
72                  ++ [Str "-std=gnu++11"]
73
74 cDefines = ArchDefaults.cDefines options
75
76 -- TODO> -m elf_i386
77 ourLdFlags = [ Str "-Wl,-z,max-page-size=0x1000",
78                Str "-Wl,--build-id=none",
79                Str "-Wl,-melf_k1om",
80                Str "-m64" ]
81
82
83 ldFlags = ArchDefaults.ldFlags arch ++ ourLdFlags
84 ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
85
86 -- adding x86_64 includes to the K1OM architecture
87 kernelOptIncludes = [NoDep SrcTree "src" ("/kernel/include/arch/x86_64"),
88                      NoDep SrcTree "src" ("/include/target/x86_64"),
89                      NoDep SrcTree "src" ("/include/arch/x86_64")]
90
91 options = (ArchDefaults.options arch archFamily) {
92             optFlags = cFlags,
93             optCxxFlags = cxxFlags,
94             optDefines = cDefines,
95             optLdFlags = ldFlags,
96             optLdCxxFlags = ldCxxFlags,
97             optInterconnectDrivers = ["lmp", "ump", "multihop", "local"],
98             optFlounderBackends = ["lmp", "ump", "multihop", "local"],
99             optIncludes = ArchDefaults.cStdIncs arch archFamily
100                           ++
101                           [NoDep SrcTree "src" ("/include/target/x86_64"),
102                            NoDep SrcTree "src" ("/include/arch/x86_64")]
103           }
104
105 --
106 -- The kernel is "different"
107 --
108
109 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
110                                 "-nostdinc",
111                                 "-std=c99",
112                                 "-m64",
113                                 "-fPIE",
114                                 "-e start",
115                                 "-mno-red-zone",
116                                 "-Wa,-march=k1om",
117                                 "-fno-stack-protector",
118                                 "-fomit-frame-pointer",
119                                 "-U__linux__",
120                                 "-D__k1om__",
121                                 "-D__x86__",
122                                 "-mtune=knc",
123                                 "-Wall",
124                                 "-Wshadow",
125                                 "-Wstrict-prototypes",
126                                 "-Wold-style-definition",
127                                 "-Wmissing-prototypes",
128                                 "-Wmissing-declarations",
129                                 "-Wmissing-field-initializers",
130                                 "-Wredundant-decls",
131                                 "-Wno-packed-bitfield-compat",
132                                 "-Wno-unused-but-set-variable",
133                                 "-Werror",
134                                 "-imacros deputy/nodeputy.h",
135                                 "-fno-tree-vectorize",
136                                 "-mno-mmx",
137                                 "-mno-sse",
138                                 "-mno-sse2",
139                                 "-mno-sse3",
140                                 "-mno-sse4.1",
141                                 "-mno-sse4.2",
142                                 "-mno-sse4",
143                                 "-mno-sse4a",
144                                 "-mno-3dnow",
145 -- Apparently the MPSS gcc somehow incudes CMOVES?
146                                 "-fno-if-conversion" ] ]
147
148 kernelLdFlags = [ Str s | s <- [ "-Wl,-N ",
149                                  "-pie ",
150                                  "-Wl,-melf_k1om ",
151                                  "-fno-builtin ",
152                                  "-e start",
153                                  "-nostdlib ",
154                                  "-Wl,--fatal-warnings ",
155                                  "-m64 " ] ]
156
157
158 ------------------------------------------------------------------------
159 --
160 -- Now, commands to actually do something
161 --
162 ------------------------------------------------------------------------
163
164 --
165 -- Compilers
166 --
167 cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
168 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
169 makeDepend = ArchDefaults.makeDepend arch compiler
170 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
171 cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
172 assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
173 archive = ArchDefaults.archive arch
174 linker = ArchDefaults.linker arch compiler
175 strip = ArchDefaults.strip arch objcopy
176 debug = ArchDefaults.debug arch objcopy
177 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
178
179 --
180 -- Link the kernel (CPU Driver)
181 --
182 linkKernel :: Options -> [String] -> [String]  -> String -> HRule
183 linkKernel opts objs libs kbin =
184     let linkscript = "/kernel/linker.lds"
185     in
186       Rules [ Rule ([ Str compiler ] ++
187                     map Str Config.cOptFlags ++
188                     [ NStr "-T", In BuildTree arch "/kernel/linker.lds",
189                       Str "-o", Out arch kbin
190                     ]
191                     ++ (optLdFlags opts)
192                     ++
193                     [ In BuildTree arch o | o <- objs ]
194                     ++
195                     [ In BuildTree arch l | l <- libs ]
196                     ++
197                     [ NL, NStr "bash -c \"echo -e '\\0002'\" | dd of=",
198                       Out arch kbin,
199                       Str "bs=1 seek=16 count=1 conv=notrunc status=noxfer"
200                     ]
201                    ),
202               Rule [ Str "cpp",
203                      NStr "-I", NoDep SrcTree "src" "/kernel/include/",
204                      Str "-D__ASSEMBLER__",
205                      Str "-P", In SrcTree "src" "/kernel/arch/k1om/linker.lds.in",
206                      Out arch linkscript
207                    ],
208               -- Produce a stripped binary
209               Rule [ Str objcopy,
210                      Str "-g",
211                      In BuildTree arch kbin,
212                      Out arch (kbin ++ ".stripped")
213                    ]
214             ]