4a037d7a7048e855e6625faccfce938002b72f30
[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 --                              "-Wno-unused-but-set-variable",
98                                 "-mno-sse4",
99                                 "-mno-sse4a",
100                                 "-mno-3dnow" ]]
101
102 kernelLdFlags = [ Str s | s <- [ "-Wl,-N",
103                                 "-pie",
104                                  "-fno-builtin",
105                                 "-nostdlib",
106                                 "-Wl,--fatal-warnings",
107                                 "-m64" ] ]
108
109
110 ------------------------------------------------------------------------
111 --
112 -- Now, commands to actually do something
113 --
114 ------------------------------------------------------------------------
115
116 --
117 -- Compilers
118 --
119 cCompiler = ArchDefaults.cCompiler arch compiler
120 cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
121 makeDepend = ArchDefaults.makeDepend arch compiler
122 makeCxxDepend  = ArchDefaults.makeCxxDepend arch cxxcompiler
123 cToAssembler = ArchDefaults.cToAssembler arch compiler
124 assembler = ArchDefaults.assembler arch compiler
125 archive = ArchDefaults.archive arch
126 linker = ArchDefaults.linker arch compiler
127 cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
128
129 --
130 -- Link the kernel (CPU Driver)
131 -- 
132 linkKernel :: Options -> [String] -> [String] -> String -> HRule
133 linkKernel opts objs libs kbin = 
134     let linkscript = "/kernel/linker.lds"
135     in
136       Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
137                       NStr "-T", In BuildTree arch "/kernel/linker.lds",
138                       Str "-o", Out arch kbin 
139                     ]
140                     ++ (optLdFlags opts)
141                     ++
142                     [ In BuildTree arch o | o <- objs ]
143                     ++
144                     [ In BuildTree arch l | l <- libs ]
145                     ++ 
146                     [ NL, NStr "/bin/echo -e '\\0002' | dd of=",
147                       Out arch kbin, 
148                       Str "bs=1 seek=16 count=1 conv=notrunc status=noxfer"
149                     ]
150                    ),
151               Rule [ Str "cpp", 
152                      NStr "-I", NoDep SrcTree "src" "/kernel/include/",
153                      Str "-D__ASSEMBLER__", 
154                      Str "-P", In SrcTree "src" "/kernel/arch/x86_64/linker.lds.in",
155                      Out arch linkscript 
156                    ]
157             ]