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