[c21d4d6] | 1 | #
|
---|
| 2 | # Copyright (c) 2005 Martin Decky
|
---|
| 3 | # All rights reserved.
|
---|
| 4 | #
|
---|
| 5 | # Redistribution and use in source and binary forms, with or without
|
---|
| 6 | # modification, are permitted provided that the following conditions
|
---|
| 7 | # are met:
|
---|
| 8 | #
|
---|
| 9 | # - Redistributions of source code must retain the above copyright
|
---|
| 10 | # notice, this list of conditions and the following disclaimer.
|
---|
| 11 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | # documentation and/or other materials provided with the distribution.
|
---|
| 14 | # - The name of the author may not be used to endorse or promote products
|
---|
| 15 | # derived from this software without specific prior written permission.
|
---|
| 16 | #
|
---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | #
|
---|
| 28 |
|
---|
[2fff3c4] | 29 |
|
---|
| 30 | arch_src = []
|
---|
| 31 |
|
---|
[63660a3] | 32 | # Fills arch_src.
|
---|
[5f176da] | 33 | subdir('arch' / KARCH)
|
---|
[63660a3] | 34 |
|
---|
| 35 | # Defines genarch_src.
|
---|
[2fff3c4] | 36 | subdir('genarch')
|
---|
[63660a3] | 37 |
|
---|
| 38 | # Defines generic_src, instrumentable_src.
|
---|
[2fff3c4] | 39 | subdir('generic')
|
---|
[63660a3] | 40 |
|
---|
| 41 | # Defines test_src
|
---|
[2fff3c4] | 42 | subdir('test')
|
---|
| 43 |
|
---|
[63660a3] | 44 | kernel_include_dirs = include_directories(
|
---|
[2fff3c4] | 45 | 'generic/include',
|
---|
| 46 | 'genarch/include',
|
---|
[5f176da] | 47 | 'arch' / KARCH / 'include',
|
---|
| 48 | '..' / 'abi' / 'arch' / KARCH / 'include',
|
---|
[2fff3c4] | 49 | '..' / 'abi' / 'include',
|
---|
[b169619] | 50 | '..' / 'common' / 'include',
|
---|
[2fff3c4] | 51 | 'test',
|
---|
| 52 | )
|
---|
| 53 |
|
---|
| 54 | kernel_defs = [
|
---|
[2e2cefdb] | 55 | '-imacros', meson.build_root() / 'config.h',
|
---|
[2fff3c4] | 56 | '-D_HELENOS_SOURCE',
|
---|
| 57 | '-DKERNEL',
|
---|
[6068476] | 58 | '-DHELENOS_RELEASE=' + HELENOS_RELEASE,
|
---|
| 59 | '-DHELENOS_COPYRIGHT=' + HELENOS_COPYRIGHT,
|
---|
| 60 | '-DHELENOS_CODENAME=' + HELENOS_CODENAME,
|
---|
[2fff3c4] | 61 | '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
|
---|
| 62 | ]
|
---|
| 63 |
|
---|
[63660a3] | 64 | # Preprocess linker script using C preprocessor.
|
---|
[2fff3c4] | 65 | kernel_ldscript = custom_target('_link.ld',
|
---|
[5f176da] | 66 | input: 'arch' / KARCH / '_link.ld.in',
|
---|
[2fff3c4] | 67 | output: '_link.ld',
|
---|
| 68 | command: [
|
---|
| 69 | cc.cmd_array(),
|
---|
[41408d94] | 70 | arch_kernel_c_args,
|
---|
[2fff3c4] | 71 | kernel_defs,
|
---|
[5f176da] | 72 | '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
|
---|
[2fff3c4] | 73 | '-D__ASSEMBLER__',
|
---|
| 74 | '-D__LINKER__',
|
---|
| 75 | '-E',
|
---|
| 76 | '-P',
|
---|
| 77 | '-x', 'c',
|
---|
| 78 | '@INPUT@',
|
---|
| 79 | ],
|
---|
| 80 | capture: true,
|
---|
[d3357e9] | 81 | build_by_default: true,
|
---|
[2fff3c4] | 82 | )
|
---|
| 83 |
|
---|
[63660a3] | 84 | kernel_link_args = arch_kernel_link_args + [
|
---|
[2fff3c4] | 85 | '-Wl,--nmagic',
|
---|
| 86 | '-T', meson.current_build_dir() / '_link.ld',
|
---|
| 87 | ]
|
---|
[62721d5] | 88 | # The kernel is built as ELF but then copied as a blob of bytes and
|
---|
| 89 | # the permissions are not relevant anyway (needed for binutils 2.39+).
|
---|
| 90 | kernel_link_args += ldflags_ignore_rwx_segments
|
---|
[2fff3c4] | 91 |
|
---|
[971849b1] | 92 | if CONFIG_LTO
|
---|
| 93 | kernel_link_args += [ '-flto' ]
|
---|
| 94 | endif
|
---|
| 95 |
|
---|
[63660a3] | 96 | kernel_c_args = arch_kernel_c_args + kernel_defs + [
|
---|
[2fff3c4] | 97 | '-ffreestanding',
|
---|
[2fbb42f] | 98 | '-fdebug-prefix-map=../../kernel/=',
|
---|
| 99 | '-fdebug-prefix-map=../../../kernel/=',
|
---|
[abb70fc3] | 100 |
|
---|
| 101 | cc.get_supported_arguments([
|
---|
| 102 | # TODO: remove this flag
|
---|
| 103 | '-Wno-cast-function-type',
|
---|
| 104 |
|
---|
| 105 | # When accessing specific memory addresses that are below
|
---|
| 106 | # normal page size, the compiler may assume that we actually
|
---|
| 107 | # dereferenced NULL pointer and warns us about that.
|
---|
| 108 | # But in kernel we often need to access these addresses
|
---|
| 109 | # directly hence we need to ignore these warnings.
|
---|
| 110 | #
|
---|
| 111 | # TODO: might make more sense to disable this selectively
|
---|
| 112 | # in specific files (or better yet, for specific lines).
|
---|
| 113 | '--param=min-pagesize=0',
|
---|
| 114 | ]),
|
---|
[2fff3c4] | 115 | ]
|
---|
| 116 |
|
---|
[2fbb42f] | 117 | if not CONFIG_LINE_DEBUG
|
---|
| 118 | # Keep the debug info needed to get file names for kernel stack traces.
|
---|
[d231a54] | 119 | kernel_c_args += cc.get_supported_arguments([ '-gdwarf-5', '-g1', '-gno-statement-frontiers' ])
|
---|
[2fbb42f] | 120 | endif
|
---|
| 121 |
|
---|
[971849b1] | 122 | if CONFIG_LTO
|
---|
| 123 | kernel_c_args += [ '-flto' ]
|
---|
| 124 | endif
|
---|
| 125 |
|
---|
[2fff3c4] | 126 | if cc.get_id() == 'clang'
|
---|
| 127 | kernel_c_args += [
|
---|
| 128 | '-fno-stack-protector',
|
---|
| 129 | '-fno-PIC',
|
---|
| 130 | '-mllvm', '-asm-macro-max-nesting-depth=1000',
|
---|
| 131 | ]
|
---|
| 132 | endif
|
---|
| 133 |
|
---|
| 134 | instrumentables = static_library('instrumentables', instrumentable_src,
|
---|
[63660a3] | 135 | include_directories: kernel_include_dirs,
|
---|
[2fff3c4] | 136 | implicit_include_directories: false,
|
---|
| 137 | c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
|
---|
| 138 | pic: false,
|
---|
| 139 | )
|
---|
| 140 |
|
---|
| 141 | noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
|
---|
[63660a3] | 142 | include_directories: kernel_include_dirs,
|
---|
[2fff3c4] | 143 | implicit_include_directories: false,
|
---|
| 144 | c_args: kernel_c_args,
|
---|
| 145 | pic: false,
|
---|
| 146 | )
|
---|
| 147 |
|
---|
| 148 | all_kernel_objects = [ instrumentables, noninstrumentables ]
|
---|
| 149 |
|
---|
[da13982] | 150 | kernel_name = 'kernel.elf'
|
---|
| 151 | kernel_map_name = kernel_name + '.map'
|
---|
| 152 | kernel_map_path = meson.current_build_dir() / kernel_map_name
|
---|
[2fff3c4] | 153 |
|
---|
[da13982] | 154 | kernel_elf = executable(kernel_name,
|
---|
| 155 | include_directories: kernel_include_dirs,
|
---|
| 156 | implicit_include_directories: false,
|
---|
| 157 | c_args: kernel_c_args,
|
---|
| 158 | link_args: kernel_c_args + kernel_link_args + [
|
---|
| 159 | '-Wl,-Map,' + kernel_map_path,
|
---|
| 160 | ],
|
---|
| 161 | link_depends: kernel_ldscript,
|
---|
| 162 | link_whole: all_kernel_objects,
|
---|
| 163 | pie: false,
|
---|
| 164 | )
|
---|
[2fff3c4] | 165 |
|
---|
[da13982] | 166 | kernel_dbg = custom_target('kernel.dbg',
|
---|
| 167 | output: 'kernel.dbg',
|
---|
| 168 | input: kernel_elf,
|
---|
| 169 | command: [
|
---|
| 170 | objcopy,
|
---|
| 171 | '--only-keep-debug',
|
---|
| 172 | '@INPUT@',
|
---|
| 173 | '@OUTPUT@',
|
---|
| 174 | ],
|
---|
| 175 | )
|
---|
| 176 |
|
---|
| 177 | kernel_elf_stripped = custom_target(kernel_name + '.stripped',
|
---|
| 178 | output: kernel_name + '.stripped',
|
---|
| 179 | input: kernel_elf,
|
---|
| 180 | command: [
|
---|
| 181 | objcopy,
|
---|
| 182 | '--strip-unneeded',
|
---|
| 183 | '@INPUT@',
|
---|
| 184 | '@OUTPUT@',
|
---|
| 185 | ],
|
---|
[2fff3c4] | 186 | )
|
---|
| 187 |
|
---|
[da13982] | 188 | rd_init_binaries += [[ kernel_elf_stripped, 'boot/kernel.elf' ]]
|
---|
| 189 | install_files += [[ 'boot', kernel_elf_stripped.full_path(), 'kernel.elf' ]]
|
---|
| 190 | install_deps += [ kernel_elf_stripped ]
|
---|
| 191 |
|
---|
| 192 | if CONFIG_SYMTAB
|
---|
| 193 | rd_init_binaries += [[ kernel_dbg, 'kernel.dbg' ]]
|
---|
| 194 | install_files += [[ 'boot', kernel_dbg.full_path(), 'kernel.dbg' ]]
|
---|
| 195 | install_deps += [ kernel_dbg ]
|
---|
| 196 | endif
|
---|
[740e952] | 197 |
|
---|
[b2695b9] | 198 | kernel_disasm = custom_target('kernel.elf.disasm',
|
---|
[2fff3c4] | 199 | command: [ objdump, '-S', '@INPUT@' ],
|
---|
| 200 | input: kernel_elf,
|
---|
[b2695b9] | 201 | output: 'kernel.elf.disasm',
|
---|
[2fff3c4] | 202 | capture: true,
|
---|
| 203 | build_by_default: true,
|
---|
| 204 | )
|
---|
[740e952] | 205 |
|
---|
| 206 | # TODO: Add configuration option for installing debug files
|
---|
| 207 | if false
|
---|
| 208 | install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
|
---|
[b2695b9] | 209 | install_deps += [ kernel_disasm ]
|
---|
[740e952] | 210 | endif
|
---|