1 /* 2 * Copyright (c) 2010, 2012, 2014 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Macros to generate structure member offset definitions 10 * 11 * This header contains macros to allow a kernel implementation to generate 12 * absolute symbols whose values represents the member offsets for various 13 * kernel structures. These absolute symbols are typically utilized by 14 * assembly source files rather than hardcoding the values in some local header 15 * file. 16 * 17 * WARNING: Absolute symbols can potentially be utilized by external tools -- 18 * for example, to locate a specific field within a data structure. 19 * Consequently, changes made to such symbols may require modifications to the 20 * associated tool(s). Typically, relocating a member of a structure merely 21 * requires that a tool be rebuilt; however, moving a member to another 22 * structure (or to a new sub-structure within an existing structure) may 23 * require that the tool itself be modified. Likewise, deleting, renaming, or 24 * changing the meaning of an absolute symbol may require modifications to a 25 * tool. 26 * 27 * The macro "GEN_OFFSET_SYM(structure, member)" is used to generate a single 28 * absolute symbol. The absolute symbol will appear in the object module 29 * generated from the source file that utilizes the GEN_OFFSET_SYM() macro. 30 * Absolute symbols representing a structure member offset have the following 31 * form: 32 * 33 * __<structure>_<member>_OFFSET 34 * 35 * The macro "GEN_NAMED_OFFSET_SYM(structure, member, name)" is also provided 36 * to create the symbol with the following form: 37 * 38 * __<structure>_<name>_OFFSET 39 * 40 * This header also defines the GEN_ABSOLUTE_SYM macro to simply define an 41 * absolute symbol, irrespective of whether the value represents a structure 42 * or offset. 43 * 44 * The following sample file illustrates the usage of the macros available 45 * in this file: 46 * 47 * <START of sample source file: offsets.c> 48 * 49 * #include <gen_offset.h> 50 * /@ include struct definitions for which offsets symbols are to be 51 * generated @/ 52 * 53 * #include <zephyr/kernel_structs.h> 54 * GEN_ABS_SYM_BEGIN (_OffsetAbsSyms) /@ the name parameter is arbitrary @/ 55 * /@ _kernel_t structure member offsets @/ 56 * 57 * GEN_OFFSET_SYM (_kernel_t, nested); 58 * GEN_OFFSET_SYM (_kernel_t, irq_stack); 59 * GEN_OFFSET_SYM (_kernel_t, current); 60 * GEN_OFFSET_SYM (_kernel_t, idle); 61 * 62 * GEN_ABSOLUTE_SYM (___kernel_t_SIZEOF, sizeof(_kernel_t)); 63 * 64 * GEN_ABS_SYM_END 65 * <END of sample source file: offsets.c> 66 * 67 * Compiling the sample offsets.c results in the following symbols in offsets.o: 68 * 69 * $ nm offsets.o 70 * 00000000 A ___kernel_t_nested_OFFSET 71 * 00000004 A ___kernel_t_irq_stack_OFFSET 72 * 00000008 A ___kernel_t_current_OFFSET 73 * 0000000c A ___kernel_t_idle_OFFSET 74 */ 75 76 #ifndef ZEPHYR_KERNEL_INCLUDE_GEN_OFFSET_H_ 77 #define ZEPHYR_KERNEL_INCLUDE_GEN_OFFSET_H_ 78 79 #include <zephyr/toolchain.h> 80 #include <stddef.h> 81 82 /* definition of the GEN_OFFSET_SYM() macros is toolchain independent */ 83 84 #define GEN_OFFSET_SYM(S, M) \ 85 GEN_ABSOLUTE_SYM(__##S##_##M##_##OFFSET, offsetof(S, M)) 86 87 #define GEN_OFFSET_STRUCT(S, M) \ 88 GEN_ABSOLUTE_SYM(__struct_##S##_##M##_##OFFSET, offsetof(struct S, M)) 89 90 #define GEN_NAMED_OFFSET_SYM(S, M, N) \ 91 GEN_ABSOLUTE_SYM(__##S##_##N##_##OFFSET, offsetof(S, M)) 92 93 #define GEN_NAMED_OFFSET_STRUCT(S, M, N) \ 94 GEN_ABSOLUTE_SYM(__struct_##S##_##N##_##OFFSET, offsetof(struct S, M)) 95 96 #endif /* ZEPHYR_KERNEL_INCLUDE_GEN_OFFSET_H_ */ 97