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