1 /* 2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HDF_DEVICE_SECTION_H 10 #define HDF_DEVICE_SECTION_H 11 12 #if !defined(NON_HDF_DRIVER_SECTION) 13 #define USED_ATTR __attribute__((used)) 14 #define HDF_SECTION __attribute__((section(".hdf.driver"))) 15 #define HDF_DRIVER_INIT(module) \ 16 const size_t USED_ATTR module##HdfEntry HDF_SECTION = (size_t)(&(module)) 17 18 #if (defined(__GNUC__) || defined(__clang__)) 19 #define HDF_DRIVER_SEC_NAME(type, name) \ 20 ({extern type name; \ 21 &(name); \ 22 }) 23 #define HDF_DRIVER_BEGIN() HDF_DRIVER_SEC_NAME(size_t, _hdf_drivers_start) 24 #define HDF_DRIVER_END() HDF_DRIVER_SEC_NAME(size_t, _hdf_drivers_end) 25 26 #elif defined(__ICCARM__) 27 #define HDF_DRIVER_BEGIN() __section_begin(".hdf.driver") 28 #define HDF_DRIVER_END() __section_end(".hdf.driver") 29 #pragma section = ".hdf.driver" 30 #else 31 #error "No support section begin and section end!" 32 #endif /* defined(__GNUC__) || defined(__clang__) */ 33 #endif /* NON_HDF_DRIVER_SECTION */ 34 35 #endif /* HDF_DEVICE_SECTION_H */ 36 37