1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/error.gni") 18import("$dir_pw_build/target_types.gni") 19import("$dir_pw_docgen/docs.gni") 20 21declare_args() { 22 # This should be set to the path of the llvm compiler-rt/builtins directory. 23 dir_pw_third_party_llvm_builtins = "" 24 25 # Points to a pw_source_set that enumerates builtins specific to 26 # the current toolchain. 27 pw_third_party_llvm_builtins_TARGET_BUILTINS = "" 28 29 # List of files to be excluded from the builtins repo. 30 pw_third_party_llvm_builtins_ignore_list = [] 31} 32 33config("no-warnings") { 34 cflags = [ 35 "-Wno-double-promotion", 36 "-Wno-undef", 37 "-Wno-unused-parameter", 38 "-Wno-strict-prototypes", 39 ] 40} 41 42# Source files that are common between ARMv6M and ARMv7M. 43generic_sources = [ 44 "absvdi2.c", 45 "absvsi2.c", 46 "absvti2.c", 47 "adddf3.c", 48 "addvdi3.c", 49 "addvsi3.c", 50 "addvti3.c", 51 "ashldi3.c", 52 "ashlti3.c", 53 "ashrdi3.c", 54 "ashrti3.c", 55 "clzti2.c", 56 "cmpdi2.c", 57 "cmpti2.c", 58 "comparedf2.c", 59 "ctzdi2.c", 60 "ctzsi2.c", 61 "ctzti2.c", 62 "divdc3.c", 63 "divdf3.c", 64 "divdi3.c", 65 "divmoddi4.c", 66 "divmodti4.c", 67 "divsc3.c", 68 "divsf3.c", 69 "divti3.c", 70 "extendhfsf2.c", 71 "extendsfdf2.c", 72 "ffsdi2.c", 73 "ffssi2.c", 74 "ffsti2.c", 75 "fixdfdi.c", 76 "fixdfsi.c", 77 "fixdfti.c", 78 "fixsfdi.c", 79 "fixsfsi.c", 80 "fixsfti.c", 81 "fixunsdfdi.c", 82 "fixunsdfsi.c", 83 "fixunsdfti.c", 84 "fixunssfdi.c", 85 "fixunssfsi.c", 86 "fixunssfti.c", 87 "floatdidf.c", 88 "floatdisf.c", 89 "floatsidf.c", 90 "floatsisf.c", 91 "floattidf.c", 92 "floattisf.c", 93 "floatundidf.c", 94 "floatundisf.c", 95 "floatunsidf.c", 96 "floatunsisf.c", 97 "floatuntidf.c", 98 "floatuntisf.c", 99 "int_util.c", 100 "lshrdi3.c", 101 "lshrti3.c", 102 "moddi3.c", 103 "modti3.c", 104 "muldc3.c", 105 "muldf3.c", 106 "muldi3.c", 107 "mulodi4.c", 108 "mulosi4.c", 109 "muloti4.c", 110 "mulsc3.c", 111 "mulsf3.c", 112 "multi3.c", 113 "mulvdi3.c", 114 "mulvsi3.c", 115 "mulvti3.c", 116 "negdf2.c", 117 "negdi2.c", 118 "negsf2.c", 119 "negti2.c", 120 "negvdi2.c", 121 "negvsi2.c", 122 "negvti2.c", 123 "os_version_check.c", 124 "paritydi2.c", 125 "paritysi2.c", 126 "parityti2.c", 127 "popcountdi2.c", 128 "popcountsi2.c", 129 "popcountti2.c", 130 "powidf2.c", 131 "powisf2.c", 132 "subdf3.c", 133 "subsf3.c", 134 "subvdi3.c", 135 "subvsi3.c", 136 "subvti3.c", 137 "trampoline_setup.c", 138 "truncdfhf2.c", 139 "truncdfsf2.c", 140 "truncsfhf2.c", 141 "ucmpdi2.c", 142 "ucmpti2.c", 143 "udivdi3.c", 144 "udivmoddi4.c", 145 "udivmodti4.c", 146 "udivti3.c", 147 "umoddi3.c", 148 "umodti3.c", 149] 150 151generic_tf_sources = [ 152 "addtf3.c", 153 "comparetf2.c", 154 "divtc3.c", 155 "divtf3.c", 156 "extenddftf2.c", 157 "extendhftf2.c", 158 "extendsftf2.c", 159 "fixtfdi.c", 160 "fixtfsi.c", 161 "fixtfti.c", 162 "fixunstfdi.c", 163 "fixunstfsi.c", 164 "fixunstfti.c", 165 "floatditf.c", 166 "floatsitf.c", 167 "floattitf.c", 168 "floatunditf.c", 169 "floatunsitf.c", 170 "floatuntitf.c", 171 "multc3.c", 172 "multf3.c", 173 "powitf2.c", 174 "subtf3.c", 175 "trunctfdf2.c", 176 "trunctfhf2.c", 177 "trunctfsf2.c", 178] 179 180armv7m_only_sources = [ 181 "addsf3.c", 182 ## Assembly equivalent version of these following sources are 183 ## provided by arm_or_thumb2_base_sources 184 # "bswapdi2.c", 185 # "bswapsi2.c", 186 # "clzdi2.c", 187 # "clzsi2.c", 188 # "comparesf2.c", 189 # "divmodsi4.c", 190 # "divsi3.c", 191 # "fp_mode.c", 192 # "modsi3.c", 193 # "udivmodsi4.c", 194 # "udivsi3.c", 195 # "umodsi3.c", 196] 197 198armv6m_only_sources = [ 199 "bswapdi2.c", 200 "bswapsi2.c", 201 "clzdi2.c", 202 "clzsi2.c", 203 "divmodsi4.c", 204 "fp_mode.c", 205 "modsi3.c", 206 "udivmodsi4.c", 207 "umodsi3.c", 208 209 ## Assembly equivalent version of these following sources are 210 ## provided by thumb1_base_sources 211 # "addsf3.c", 212 # "divsi3.c", 213 # "udivsi3.c", 214 # "comparesf2.c", 215] 216 217arm_or_thumb2_base_sources = [ 218 "arm/bswapdi2.S", 219 "arm/bswapsi2.S", 220 "arm/clzdi2.S", 221 "arm/clzsi2.S", 222 "arm/comparesf2.S", 223 "arm/divmodsi4.S", 224 "arm/divsi3.S", 225 "arm/fp_mode.c", 226 "arm/modsi3.S", 227 "arm/udivmodsi4.S", 228 "arm/udivsi3.S", 229 "arm/umodsi3.S", 230] 231 232arm_sync_sources = [ 233 "arm/sync_fetch_and_add_4.S", 234 "arm/sync_fetch_and_add_8.S", 235 "arm/sync_fetch_and_and_4.S", 236 "arm/sync_fetch_and_and_8.S", 237 "arm/sync_fetch_and_max_4.S", 238 "arm/sync_fetch_and_max_8.S", 239 "arm/sync_fetch_and_min_4.S", 240 "arm/sync_fetch_and_min_8.S", 241 "arm/sync_fetch_and_nand_4.S", 242 "arm/sync_fetch_and_nand_8.S", 243 "arm/sync_fetch_and_or_4.S", 244 "arm/sync_fetch_and_or_8.S", 245 "arm/sync_fetch_and_sub_4.S", 246 "arm/sync_fetch_and_sub_8.S", 247 "arm/sync_fetch_and_umax_4.S", 248 "arm/sync_fetch_and_umax_8.S", 249 "arm/sync_fetch_and_umin_4.S", 250 "arm/sync_fetch_and_umin_8.S", 251 "arm/sync_fetch_and_xor_4.S", 252 "arm/sync_fetch_and_xor_8.S", 253] 254 255# builtin support for Thumb-only targets with very limited Thumb2 technology, 256# such as v6-m and v8-m.baseline 257thumb1_base_sources = [ 258 "arm/addsf3.S", 259 "arm/comparesf2.S", 260 "arm/divsi3.S", 261 "arm/udivsi3.S", 262] 263 264arm_eabi_sources = [ 265 "arm/aeabi_cdcmp.S", 266 "arm/aeabi_cdcmpeq_check_nan.c", 267 "arm/aeabi_cfcmp.S", 268 "arm/aeabi_cfcmpeq_check_nan.c", 269 "arm/aeabi_dcmp.S", 270 "arm/aeabi_div0.c", 271 "arm/aeabi_drsub.c", 272 "arm/aeabi_fcmp.S", 273 "arm/aeabi_frsub.c", 274 "arm/aeabi_idivmod.S", 275 "arm/aeabi_ldivmod.S", 276 "arm/aeabi_memcmp.S", 277 "arm/aeabi_memcpy.S", 278 "arm/aeabi_memmove.S", 279 "arm/aeabi_memset.S", 280 "arm/aeabi_uidivmod.S", 281 "arm/aeabi_uldivmod.S", 282] 283 284arm_thumb1_jt_sources = [ 285 "arm/switch16.S", 286 "arm/switch32.S", 287 "arm/switch8.S", 288 "arm/switchu8.S", 289] 290 291arm_thumb1_icache_sources = [ "arm/sync_synchronize.S" ] 292 293# thumb1 calling into Arm to cover support 294arm_thumb1_sources = arm_thumb1_jt_sources + arm_thumb1_icache_sources 295 296arm_sources = arm_or_thumb2_base_sources + arm_sync_sources + arm_eabi_sources + 297 arm_thumb1_sources + generic_sources + armv7m_only_sources + 298 generic_tf_sources 299 300thumb1_sources = thumb1_base_sources + arm_eabi_sources + generic_sources + 301 armv6m_only_sources + generic_tf_sources 302 303armv6m_sources = thumb1_sources 304armv7m_sources = arm_sources 305 306# ARM builtins for ARMv7-M. 307# Because this is unconditionally added to all clang-based ARM toolchains, 308# this library should be a no-op if `dir_pw_third_party_llvm_builtins` is 309# not configured. 310pw_source_set("arm_builtins_armv7m") { 311 configs = [ ":no-warnings" ] 312 remove_configs = [ "//pw_build:extra_strict_warnings" ] 313 314 sources = [] 315 316 arm_files = armv7m_sources 317 318 if (dir_pw_third_party_llvm_builtins != "") { 319 effective_arm_files = 320 filter_exclude(arm_files, pw_third_party_llvm_builtins_ignore_list) 321 foreach(file, effective_arm_files) { 322 sources += [ "$dir_pw_third_party_llvm_builtins/$file" ] 323 } 324 } else { 325 not_needed([ "arm_files" ]) 326 } 327} 328 329# ARM builtins for ARMv6-M. 330# Because this is unconditionally added to all clang-based ARM toolchains, 331# this library should be a no-op if `dir_pw_third_party_llvm_builtins` is 332# not configured. 333pw_source_set("arm_builtins_armv6m") { 334 configs = [ ":no-warnings" ] 335 remove_configs = [ "//pw_build:extra_strict_warnings" ] 336 337 sources = [] 338 339 arm_files = armv6m_sources 340 341 if (dir_pw_third_party_llvm_builtins != "") { 342 effective_arm_files = 343 filter_exclude(arm_files, pw_third_party_llvm_builtins_ignore_list) 344 foreach(file, effective_arm_files) { 345 sources += [ "$dir_pw_third_party_llvm_builtins/$file" ] 346 } 347 } else { 348 not_needed([ "arm_files" ]) 349 } 350} 351 352# Because this is unconditionally added to all clang-based ARM toolchains, 353# this library should be a no-op if `dir_pw_third_party_llvm_builtins` is 354# not configured. 355pw_static_library("llvm_builtins") { 356 add_global_link_deps = false 357 configs = [ ":no-warnings" ] 358 remove_configs = [ "//pw_build:extra_strict_warnings" ] 359 sources = [] 360 361 # Architecture specific pw_source_set created from LLVM builtins 362 # source files. e.g. arm_builtins_armv6m. 363 # If this property is not set, no architecture specific builtin 364 # functions will be included from the repo. 365 if (pw_third_party_llvm_builtins_TARGET_BUILTINS != "") { 366 deps = [ pw_third_party_llvm_builtins_TARGET_BUILTINS ] 367 } 368} 369 370pw_doc_group("docs") { 371 sources = [ "docs.rst" ] 372} 373