armv7-m needs to avoid -O2.
Signed-off-by: David Cock <david.cock@inf.ethz.ch>
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
let linkscript = "/kernel/linker.lds"
kbootable = kbin ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
Str "-o", Out arch kbin
]
++ (optLdFlags opts)
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
let linkscript = "/kernel/linker.lds"
kbootable = kbin ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
Str "-o", Out arch kbin
]
++ (optLdFlags opts)
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
kbinary = "/sbin/" ++ name
kbootable = kbinary ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
Str "-o", Out arch kbinary,
NStr "-Wl,-Map,", Out arch kernelmap
]
import HakeTypes
import qualified Config
import qualified ArchDefaults
+import Data.List
-------------------------------------------------------------------------
--
arch = "armv7-m"
archFamily = "arm"
-compiler = Config.arm_cc
-objcopy = Config.arm_objcopy
-objdump = Config.arm_objdump
-ar = Config.arm_ar
-ranlib = Config.arm_ranlib
-cxxcompiler = Config.arm_cxx
+compiler = Config.thumb_cc
+objcopy = Config.thumb_objcopy
+objdump = Config.thumb_objdump
+ar = Config.thumb_ar
+ranlib = Config.thumb_ranlib
+cxxcompiler = Config.thumb_cxx
ourCommonFlags = [ Str "-fno-unwind-tables",
Str "-Wno-packed-bitfield-compat",
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+
+-- Heavy optimisation causes GCC to fail with unresolvable register spill.
+v7m_optFlags = (Config.cOptFlags \\ ["-O2", "-O3"]) ++ ["-Os"]
+
+cCompiler = ArchDefaults.cCompiler arch compiler v7m_optFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler v7m_optFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler v7m_optFlags
+assembler = ArchDefaults.assembler arch compiler v7m_optFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
kbinary = "/sbin/" ++ name
kbootable = kbinary ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
Str "-o", Out arch kbinary,
NStr "-Wl,-Map,", Out arch kernelmap
]
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
kbinary = "/sbin/" ++ name
kbootable = kbinary ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
Str "-o", Out arch kbinary,
NStr "-Wl,-Map,", Out arch kernelmap
]
NoDep BuildTree arch "." ]
ldFlags arch =
- [ Str Config.cOptFlags,
- In InstallTree arch "/lib/crt0.o",
+ map Str Config.cOptFlags ++
+ [ In InstallTree arch "/lib/crt0.o",
In InstallTree arch "/lib/crtbegin.o",
Str "-fno-builtin",
Str "-nostdlib" ]
ldCxxFlags arch =
- [ Str Config.cOptFlags,
- In InstallTree arch "/lib/crt0.o",
+ map Str Config.cOptFlags ++
+ [ In InstallTree arch "/lib/crt0.o",
In InstallTree arch "/lib/crtbegin.o",
Str "-fno-builtin",
Str "-nostdlib" ]
--
-- C compiler
--
-cCompiler arch compiler opts phase src obj =
+cCompiler :: String -> String -> [String] -> Options -> String ->
+ String -> String -> [RuleToken]
+cCompiler arch compiler opt_flags opts phase src obj =
let incls = (extraIncludes opts) ++ (optIncludes opts)
flags = (optFlags opts)
++ (optDefines opts)
++ [ Str f | f <- extraDefines opts ]
deps = (optDependencies opts) ++ (extraDependencies opts)
in
- [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
+ [ Str compiler ] ++ flags ++ (map Str opt_flags)
++ concat [ [ NStr "-I", i ] | i <- incls ]
++ [ Str "-o", Out arch obj,
Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
++ deps
+
--
-- the C preprocessor, like C compiler but with -E
--
-cPreprocessor arch compiler opts phase src obj =
+cPreprocessor :: String -> String -> [String] -> Options -> String ->
+ String -> String -> [RuleToken]
+cPreprocessor arch compiler opt_flags opts phase src obj =
let incls = (extraIncludes opts) ++ (optIncludes opts)
flags = (optFlags opts)
++ (optDefines opts)
++ [ Str f | f <- extraFlags opts ]
++ [ Str f | f <- extraDefines opts ]
deps = (optDependencies opts) ++ (extraDependencies opts)
- cOptFlags = unwords ((words Config.cOptFlags) \\ ["-g"])
+ cOptFlags = opt_flags \\ ["-g"]
in
- [ Str compiler ] ++ flags ++ [ Str cOptFlags ]
+ [ Str compiler ] ++ flags ++ (map Str cOptFlags)
++ concat [ [ NStr "-I", i ] | i <- incls ]
++ [ Str "-o", Out arch obj,
Str "-E", In (if phase == "src" then SrcTree else BuildTree) phase src ]
--
-- C++ compiler
--
-cxxCompiler arch cxxcompiler opts phase src obj =
+cxxCompiler arch cxxcompiler opt_flags opts phase src obj =
let incls = (extraIncludes opts) ++ (optIncludes opts)
flags = (optCxxFlags opts)
++ (optDefines opts)
++ [ Str f | f <- extraDefines opts ]
deps = (optDependencies opts) ++ (extraDependencies opts)
in
- [ Str cxxcompiler ] ++ flags ++ [ Str Config.cOptFlags ]
+ [ Str cxxcompiler ] ++ flags ++ (map Str opt_flags)
++ concat [ [ NStr "-I", i ] | i <- incls ]
++ [ Str "-o", Out arch obj,
Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
--
-- Compile a C program to assembler
--
-cToAssembler :: String -> String -> Options -> String -> String -> String -> String -> [ RuleToken ]
-cToAssembler arch compiler opts phase src afile objdepfile =
+cToAssembler :: String -> String -> [String] -> Options -> String -> String ->
+ String -> String -> [ RuleToken ]
+cToAssembler arch compiler opt_flags opts phase src afile objdepfile =
let incls = (extraIncludes opts) ++ (optIncludes opts)
flags = (optFlags opts)
++ (optDefines opts)
++ [ Str f | f <- extraFlags opts ]
++ [ Str f | f <- extraDefines opts ]
- deps = [ Dep BuildTree arch objdepfile ] ++ (optDependencies opts) ++ (extraDependencies opts)
+ deps = [ Dep BuildTree arch objdepfile ] ++
+ (optDependencies opts) ++
+ (extraDependencies opts)
in
- [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
+ [ Str compiler ] ++ flags ++ (map Str opt_flags)
++ concat [ [ NStr "-I", i ] | i <- incls ]
++ [ Str "-o ", Out arch afile,
Str "-S ", In (if phase == "src" then SrcTree else BuildTree) phase src ]
--
-- Assemble an assembly language file
--
-assembler :: String -> String -> Options -> String -> String -> [ RuleToken ]
-assembler arch compiler opts src obj =
+assembler :: String -> String -> [ String ] -> Options -> String ->
+ String -> [ RuleToken ]
+assembler arch compiler opt_flags opts src obj =
let incls = (extraIncludes opts) ++ (optIncludes opts)
flags = (optFlags opts)
++ (optDefines opts)
++ [ Str f | f <- extraDefines opts ]
deps = (optDependencies opts) ++ (extraDependencies opts)
in
- [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
+ [ Str compiler ] ++ flags ++ (map Str opt_flags)
++ concat [ [ NStr "-I", i ] | i <- incls ]
++ [ Str "-o ", Out arch obj, Str "-c ", In SrcTree "src" src ]
++ deps
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
--
findTool path prefix tool = path </> (prefix ++ tool)
+-- ARM toolchain
arm_gnu_path = ""
arm_gnu_prefix = "arm-linux-gnueabi-"
arm_gnu_tool = findTool arm_gnu_path arm_gnu_prefix
arm_ranlib = arm_gnu_tool "ranlib"
arm_cxx = arm_gnu_tool "g++"
-x86_cc = "gcc"
-x86_cxx = "g++"
+-- ARM thumb (e.g. -M profile) toolchain
+thumb_gnu_path = "/opt/gcc-arm-none-eabi-4_6-2012q4/bin"
+thumb_gnu_prefix = "arm-none-eabi-"
+thumb_gnu_tool = findTool thumb_gnu_path thumb_gnu_prefix
+thumb_cc = thumb_gnu_tool "gcc"
+thumb_objcopy = thumb_gnu_tool "objcopy"
+thumb_objdump = thumb_gnu_tool "objdump"
+thumb_ar = thumb_gnu_tool "ar"
+thumb_ranlib = thumb_gnu_tool "ranlib"
+thumb_cxx = thumb_gnu_tool "g++"
+
+-- X86 (32/64) toolchain
+x86_gnu_path = ""
+x86_gnu_prefix = ""
+x86_gnu_tool = findTool x86_gnu_path x86_gnu_prefix
+
+x86_cc = x86_gnu_tool "gcc"
+x86_cxx = x86_gnu_tool "g++"
+
+-- Xeon Phi toolchain
k1om_gnu_path = ""
k1om_gnu_prefix = "k1om-mpss-linux-"
k1om_gnu_tool = findTool k1om_gnu_path k1om_gnu_prefix
-- architectures = undefined -- (set by hake.sh, see end of file)
-- Optimisation flags (-Ox -g etc.) passed to compiler
-cOptFlags :: String
-cOptFlags = "-g -O2"
+cOptFlags :: [String]
+cOptFlags = ["-g", "-O2"]
-- Selects which libc to compile with, "oldc" or "newlib"
libc :: String
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
linkKernel opts objs libs kbin =
let linkscript = "/kernel/linker.lds"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch "/kernel/linker.lds",
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch "/kernel/linker.lds",
Str "-o", Out arch kbin
]
++ (optLdFlags opts)
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
--
linkKernel :: Options -> [String] -> [String] -> String -> HRule
linkKernel opts objs libs kbin =
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch "/kernel/linker.lds",
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch "/kernel/linker.lds",
Str "-o", Out arch kbin
]
++ (optLdFlags opts)
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
linkKernel opts objs libs kbin =
let linkscript = "/kernel/linker.lds"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch "/kernel/linker.lds",
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch "/kernel/linker.lds",
Str "-o", Out arch kbin
]
++ (optLdFlags opts)
--
-- Compilers
--
-cCompiler = ArchDefaults.cCompiler arch compiler
-cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler
+cCompiler = ArchDefaults.cCompiler arch compiler Config.cOptFlags
+cxxCompiler = ArchDefaults.cxxCompiler arch cxxcompiler Config.cOptFlags
makeDepend = ArchDefaults.makeDepend arch compiler
makeCxxDepend = ArchDefaults.makeCxxDepend arch cxxcompiler
-cToAssembler = ArchDefaults.cToAssembler arch compiler
-assembler = ArchDefaults.assembler arch compiler
+cToAssembler = ArchDefaults.cToAssembler arch compiler Config.cOptFlags
+assembler = ArchDefaults.assembler arch compiler Config.cOptFlags
archive = ArchDefaults.archive arch
linker = ArchDefaults.linker arch compiler
cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
let linkscript = "/kernel/linker.lds"
kbootable = kbin ++ ".bin"
in
- Rules [ Rule ([ Str compiler, Str Config.cOptFlags,
- NStr "-T", In BuildTree arch linkscript,
- Str "-o", Out arch kbin
- ]
+ Rules [ Rule ([ Str compiler ] ++
+ map Str Config.cOptFlags ++
+ [ NStr "-T", In BuildTree arch linkscript,
+ Str "-o", Out arch kbin
+ ]
++ (optLdFlags opts)
++
[ In BuildTree arch o | o <- objs ]