Cleanup
[barrelfish] / hake / X86_64.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 x86_64.
10 -- 
11 --------------------------------------------------------------------------
12
13 module X86_64 where
14
15 import HakeTypes
16 import qualified Config
17 import qualified ArchDefaults
18
19 -------------------------------------------------------------------------
20 --
21 -- Architecture specific definitions for x86_64
22 --
23 -------------------------------------------------------------------------
24
25 arch = "x86_64"
26 archFamily = "x86_64"
27
28 compiler    = Config.x86_cc
29 cxxcompiler = Config.x86_cxx
30
31 ourCommonFlags = [ Str "-m64",
32                    Str "-mno-red-zone",
33                    Str "-fPIE",
34                    Str "-fno-stack-protector", 
35                    Str "-Wno-unused-but-set-variable",
36                    Str "-Wno-packed-bitfield-compat",
37                    Str "-D__x86__" ]
38
39 cFlags = ArchDefaults.commonCFlags
40                ++ ArchDefaults.commonFlags
41                ++ ourCommonFlags
42
43 cxxFlags = ArchDefaults.commonCxxFlags
44                  ++ ArchDefaults.commonFlags
45                  ++ ourCommonFlags
46                  ++ [Str "-std=gnu++11"]
47
48 cDefines = ArchDefaults.cDefines options
49
50 ourLdFlags = [ Str "-Wl,-z,max-page-size=0x1000",
51                Str "-Wl,--build-id=none",
52                Str "-m64" ]
53
54 ldFlags = ArchDefaults.ldFlags arch ++ ourLdFlags
55 ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
56
57 options = (ArchDefaults.options arch archFamily) { 
58             optFlags = cFlags,
59             optCxxFlags = cxxFlags,
60             optDefines = cDefines,
61             optLdFlags = ldFlags,
62             optLdCxxFlags = ldCxxFlags,
63             optInterconnectDrivers = ["lmp", "ump", "multihop"],
64             optFlounderBackends = ["lmp", "ump", "multihop"]
65           }
66
67 --
68 -- The kernel is "different"
69 --
70
71 kernelCFlags = [ Str s | s <- [ "-fno-builtin",
72                                 "-nostdinc",
73                                 "-std=c99",
74                                 "-m64",
75                                 "-mno-red-zone",
76                                 "-fPIE",
77                                 "-fno-stack-protector",
78                                 "-U__linux__",
79                                 "-Wall",
80                                 "-Wshadow",
81                                 "-Wstrict-prototypes",
82                                 "-Wold-style-definition",
83                                 "-Wmissing-prototypes",
84                                 "-Wmissing-declarations",
85                                 "-Wmissing-field-initializers",
86                                 "-Wredundant-decls",
87                                 "-Wno-packed-bitfield-compat",
88                                 "-Wno-unused-but-set-variable",
89                                 "-Werror",
90                                 "-imacros deputy/nodeputy.h",
91                                 "-mno-mmx",
92                                 "-mno-sse",
93                                 "-mno-sse2",
94                                 "-mno-sse3",
95                                 "-mno-sse4.1",
96                                 "-mno-sse4.2",
97                                 "-mno-sse4",
98                                 "-mno-sse4a",
99                                 "-mno-3dnow" ]]
100
101 kernelLdFlags = [ Str s | s <- [ "-Wl,-N",
102                                 "-pie",
103                                  "-fno-builtin",
104                                 "-nostdlib",
105                                 "-Wl,--fatal-warnings",
106                                 "-m64" ] ]
107
108
109 ------------------------------------------------------------------------
110 --
111 -- Now, commands to actually do something
112 --
113 ------------------------------------------------------------------------
114
115 --
116 -- Compilers
117 --
118 cCompiler = ArchDefaults.cCompiler arch compiler
119 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
120 makeDepend = ArchDefaults.makeDepend arch compiler
121 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
122 cToAssembler = ArchDefaults.cToAssembler arch compiler
123 assembler = ArchDefaults.assembler arch compiler
124 archive = ArchDefaults.archive arch
125 linker = ArchDefaults.linker arch compiler
126 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
127
128 --
129 -- Link the kernel (CPU Driver)
130 -- 
131 linkKernel :: Options -> [String] -> [String] -> String -> HRule
132 linkKernel opts objs libs kbin = 
133     let linkscript = "/kernel/linker.lds"
134     in
135       Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
136                       NStr "-T", In BuildTree arch "/kernel/linker.lds",
137                       Str "-o", Out arch kbin 
138                     ]
139                     ++ (optLdFlags opts)
140                     ++
141                     [ In BuildTree arch o | o <- objs ]
142                     ++
143                     [ In BuildTree arch l | l <- libs ]
144                     ++ 
145                     [ NL, NStr "/bin/echo -e '\\0002' | dd of=",
146                       Out arch kbin, 
147                       Str "bs=1 seek=16 count=1 conv=notrunc status=noxfer"
148                     ]
149                    ),
150               Rule [ Str "cpp", 
151                      NStr "-I", NoDep SrcTree "src" "/kernel/include/",
152                      Str "-D__ASSEMBLER__", 
153                      Str "-P", In SrcTree "src" "/kernel/arch/x86_64/linker.lds.in",
154                      Out arch linkscript 
155                    ]
156             ]