[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',
|
---|
| 50 | 'test',
|
---|
| 51 | )
|
---|
| 52 |
|
---|
| 53 | kernel_defs = [
|
---|
[2e2cefdb] | 54 | '-imacros', meson.build_root() / 'config.h',
|
---|
[2fff3c4] | 55 | '-D_HELENOS_SOURCE',
|
---|
| 56 | '-DKERNEL',
|
---|
[6068476] | 57 | '-DHELENOS_RELEASE=' + HELENOS_RELEASE,
|
---|
| 58 | '-DHELENOS_COPYRIGHT=' + HELENOS_COPYRIGHT,
|
---|
| 59 | '-DHELENOS_CODENAME=' + HELENOS_CODENAME,
|
---|
[2fff3c4] | 60 | '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
|
---|
| 61 | ]
|
---|
| 62 |
|
---|
[63660a3] | 63 | # Preprocess linker script using C preprocessor.
|
---|
[2fff3c4] | 64 | kernel_ldscript = custom_target('_link.ld',
|
---|
[5f176da] | 65 | input: 'arch' / KARCH / '_link.ld.in',
|
---|
[2fff3c4] | 66 | output: '_link.ld',
|
---|
| 67 | command: [
|
---|
| 68 | cc.cmd_array(),
|
---|
[41408d94] | 69 | arch_kernel_c_args,
|
---|
[2fff3c4] | 70 | kernel_defs,
|
---|
[5f176da] | 71 | '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
|
---|
[2fff3c4] | 72 | '-D__ASSEMBLER__',
|
---|
| 73 | '-D__LINKER__',
|
---|
| 74 | '-E',
|
---|
| 75 | '-P',
|
---|
| 76 | '-x', 'c',
|
---|
| 77 | '@INPUT@',
|
---|
| 78 | ],
|
---|
| 79 | capture: true,
|
---|
[d3357e9] | 80 | build_by_default: true,
|
---|
[2fff3c4] | 81 | )
|
---|
| 82 |
|
---|
[63660a3] | 83 | kernel_link_args = arch_kernel_link_args + [
|
---|
[2fff3c4] | 84 | '-Wl,--nmagic',
|
---|
| 85 | '-T', meson.current_build_dir() / '_link.ld',
|
---|
| 86 | ]
|
---|
[62721d5] | 87 | # The kernel is built as ELF but then copied as a blob of bytes and
|
---|
| 88 | # the permissions are not relevant anyway (needed for binutils 2.39+).
|
---|
| 89 | kernel_link_args += ldflags_ignore_rwx_segments
|
---|
[2fff3c4] | 90 |
|
---|
[971849b1] | 91 | if CONFIG_LTO
|
---|
| 92 | kernel_link_args += [ '-flto' ]
|
---|
| 93 | endif
|
---|
| 94 |
|
---|
[63660a3] | 95 | kernel_c_args = arch_kernel_c_args + kernel_defs + [
|
---|
[2fff3c4] | 96 | '-ffreestanding',
|
---|
[2fbb42f] | 97 | '-fdebug-prefix-map=../../kernel/=',
|
---|
| 98 | '-fdebug-prefix-map=../../../kernel/=',
|
---|
[abb70fc3] | 99 |
|
---|
| 100 | cc.get_supported_arguments([
|
---|
| 101 | # TODO: remove this flag
|
---|
| 102 | '-Wno-cast-function-type',
|
---|
| 103 |
|
---|
| 104 | # When accessing specific memory addresses that are below
|
---|
| 105 | # normal page size, the compiler may assume that we actually
|
---|
| 106 | # dereferenced NULL pointer and warns us about that.
|
---|
| 107 | # But in kernel we often need to access these addresses
|
---|
| 108 | # directly hence we need to ignore these warnings.
|
---|
| 109 | #
|
---|
| 110 | # TODO: might make more sense to disable this selectively
|
---|
| 111 | # in specific files (or better yet, for specific lines).
|
---|
| 112 | '--param=min-pagesize=0',
|
---|
| 113 | ]),
|
---|
[2fff3c4] | 114 | ]
|
---|
| 115 |
|
---|
[2fbb42f] | 116 | if not CONFIG_LINE_DEBUG
|
---|
| 117 | # Keep the debug info needed to get file names for kernel stack traces.
|
---|
| 118 | kernel_c_args += [ '-gdwarf-5', '-g1', '-gno-statement-frontiers' ]
|
---|
| 119 | endif
|
---|
| 120 |
|
---|
[971849b1] | 121 | if CONFIG_LTO
|
---|
| 122 | kernel_c_args += [ '-flto' ]
|
---|
| 123 | endif
|
---|
| 124 |
|
---|
[2fff3c4] | 125 | if cc.get_id() == 'clang'
|
---|
| 126 | kernel_c_args += [
|
---|
| 127 | '-fno-stack-protector',
|
---|
| 128 | '-fno-PIC',
|
---|
| 129 | '-mllvm', '-asm-macro-max-nesting-depth=1000',
|
---|
| 130 | ]
|
---|
| 131 | endif
|
---|
| 132 |
|
---|
| 133 | instrumentables = static_library('instrumentables', instrumentable_src,
|
---|
[63660a3] | 134 | include_directories: kernel_include_dirs,
|
---|
[2fff3c4] | 135 | implicit_include_directories: false,
|
---|
| 136 | c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
|
---|
| 137 | pic: false,
|
---|
| 138 | )
|
---|
| 139 |
|
---|
| 140 | noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
|
---|
[63660a3] | 141 | include_directories: kernel_include_dirs,
|
---|
[2fff3c4] | 142 | implicit_include_directories: false,
|
---|
| 143 | c_args: kernel_c_args,
|
---|
| 144 | pic: false,
|
---|
| 145 | )
|
---|
| 146 |
|
---|
| 147 | all_kernel_objects = [ instrumentables, noninstrumentables ]
|
---|
| 148 |
|
---|
[da13982] | 149 | kernel_name = 'kernel.elf'
|
---|
| 150 | kernel_map_name = kernel_name + '.map'
|
---|
| 151 | kernel_map_path = meson.current_build_dir() / kernel_map_name
|
---|
[2fff3c4] | 152 |
|
---|
[da13982] | 153 | kernel_elf = executable(kernel_name,
|
---|
| 154 | include_directories: kernel_include_dirs,
|
---|
| 155 | implicit_include_directories: false,
|
---|
| 156 | c_args: kernel_c_args,
|
---|
| 157 | link_args: kernel_c_args + kernel_link_args + [
|
---|
| 158 | '-Wl,-Map,' + kernel_map_path,
|
---|
| 159 | ],
|
---|
| 160 | link_depends: kernel_ldscript,
|
---|
| 161 | link_whole: all_kernel_objects,
|
---|
| 162 | pie: false,
|
---|
| 163 | )
|
---|
[2fff3c4] | 164 |
|
---|
[da13982] | 165 | kernel_dbg = custom_target('kernel.dbg',
|
---|
| 166 | output: 'kernel.dbg',
|
---|
| 167 | input: kernel_elf,
|
---|
| 168 | command: [
|
---|
| 169 | objcopy,
|
---|
| 170 | '--only-keep-debug',
|
---|
| 171 | '@INPUT@',
|
---|
| 172 | '@OUTPUT@',
|
---|
| 173 | ],
|
---|
| 174 | )
|
---|
| 175 |
|
---|
| 176 | kernel_elf_stripped = custom_target(kernel_name + '.stripped',
|
---|
| 177 | output: kernel_name + '.stripped',
|
---|
| 178 | input: kernel_elf,
|
---|
| 179 | command: [
|
---|
| 180 | objcopy,
|
---|
| 181 | '--strip-unneeded',
|
---|
| 182 | '@INPUT@',
|
---|
| 183 | '@OUTPUT@',
|
---|
| 184 | ],
|
---|
[2fff3c4] | 185 | )
|
---|
| 186 |
|
---|
[da13982] | 187 | rd_init_binaries += [[ kernel_elf_stripped, 'boot/kernel.elf' ]]
|
---|
| 188 | install_files += [[ 'boot', kernel_elf_stripped.full_path(), 'kernel.elf' ]]
|
---|
| 189 | install_deps += [ kernel_elf_stripped ]
|
---|
| 190 |
|
---|
| 191 | if CONFIG_SYMTAB
|
---|
| 192 | rd_init_binaries += [[ kernel_dbg, 'kernel.dbg' ]]
|
---|
| 193 | install_files += [[ 'boot', kernel_dbg.full_path(), 'kernel.dbg' ]]
|
---|
| 194 | install_deps += [ kernel_dbg ]
|
---|
| 195 | endif
|
---|
[740e952] | 196 |
|
---|
[b2695b9] | 197 | kernel_disasm = custom_target('kernel.elf.disasm',
|
---|
[2fff3c4] | 198 | command: [ objdump, '-S', '@INPUT@' ],
|
---|
| 199 | input: kernel_elf,
|
---|
[b2695b9] | 200 | output: 'kernel.elf.disasm',
|
---|
[2fff3c4] | 201 | capture: true,
|
---|
| 202 | build_by_default: true,
|
---|
| 203 | )
|
---|
[740e952] | 204 |
|
---|
| 205 | # TODO: Add configuration option for installing debug files
|
---|
| 206 | if false
|
---|
| 207 | install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
|
---|
[b2695b9] | 208 | install_deps += [ kernel_disasm ]
|
---|
[740e952] | 209 | endif
|
---|