この記事で関係するターゲット
qemu ターゲット
[zephyr_base]/Makefile
qemu: zephyr (省略)詳細は 前の記事 参照。
zephyrターゲット
[zephyr_base]/Makefile
zephyr: $(zephyr-deps) $(KERNEL_BIN_NAME)
$(zephyr-deps)
[zephyr_base]/Makefile
$(zephyr-deps) := $(KBUILD_LDS) $(KBUILD_ZEPHYR_MAIN)TODO 後で調べる
$(KERNEL_BIN_NAME)
zephyr.bin[zephyr_base]/samples/hello_world/microkernel/outdir/.config
CONFIG_KERNEL_BIN_NAME="zephyr"TODO .config の生成方法(ct-ng makemenuconfigがベース?)、.config の Makefile中のinlcude箇所。
[zephyr_base]/Makefile
KERNEL_NAME = $(subst $(DQUOTE),,$(CONFIG_KERNEL_BIN_NAME)) KERNEL_BIN_NAME = $(KERNEL_NAME).bin
$(KERNEL_BIN_NAME) ターゲット
[zephyr_base]/Makefile
ifeq ($(ARCH),x86) $(KERNEL_ELF_NAME): staticIdt.o final-linker.cmd $(call cmd,lnk_elf) @$(WARN_ABOUT_ASSERT) else $(KERNEL_ELF_NAME): $(TMP_ELF) @cp $(TMP_ELF) $(KERNEL_ELF_NAME) @$(WARN_ABOUT_ASSERT) endif今回は、ARCHがx86の場合を調べる。
staticIdt.o
次の記事 参照final-linker.cmd
TODO 調査$(KERNEL_ELF_NAME)
zephyr.elf[zephyr_base]/Makefile
KERNEL_ELF_NAME = $(KERNEL_NAME).elf // $(KERNEL_NAME)は上記参照
$(call cmd,lnk_elf)
cmd_lnk_elf ファンクションを実行。cmd ファンクション
[zephyr_base]/scripts/Kbuild.include
cmd = @$(echo-cmd) $(cmd_$(1))cmdは処理内容を表示後(echo-cmd)に、処理(cmd_lnk_elf)を実行。
cmd_lnk_elf ファンクション
[zephyr_base]/Makefile
cmd_lnk_elf = \ ( \ $(CC) -T final-linker.cmd @$(KERNEL_NAME).lnk staticIdt.o int_vector_alloc.o \ irq_int_vector_map.o -o $@;・・・① \ ${OBJCOPY} --change-section-address intList=${CONFIG_PHYS_LOAD_ADDR} $@ elf.tmp; ・・・②\ $(OBJCOPY) -R intList elf.tmp $@;・・・③ \ rm elf.tmp \ )
① $(CC) -T final-linker.cmd @$(KERNEL_NAME).lnk staticIdt.o int_vector_alloc.o irq_int_vector_map.o -o $@
リンカスクリプト (final-linker.cmd)、リンカオプション(zephyr.lnk)を使い、staticIdt.o、int_vector_alloc.o、irq_int_vector_map.o から zephyr.elf を生成する。/Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-gcc -T final-linker.cmd @zephyr.lnk staticIdt.o int_vector_alloc.o irq_int_vector_map.o -o zephyr.elf
$(CC)
[zephyr_base]/Makefile
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) CC = $(CCACHE) $(CROSS_COMPILE)gcc
[zephyr_base]/scripts/Makefile.toolchain.xtools
CROSS_COMPILE: /Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-TODO scripts/Makefile.toolchain.xtools がどこで include されるか
i586-pc-elf-gcc --help
-T script Use script as the linker script. This option is supported by most systems using the GNU linker. On some targets, such as bare-board targets without an operating system, the -T option may be required when linking to avoid references to undefined symbols. https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html @file Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed. Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively. https://sourceware.org/binutils/docs/ld/Options.html#Options
①後の、zephyr.elf の readelf 結果
$ /Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-readelf -a before_changing_address_zephyr.elf (省略) Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] text PROGBITS 00100000 0001c0 002f64 00 AX 0 0 16 [ 2] devconfig PROGBITS 00102f64 003124 00006c 00 WA 0 0 4 [ 3] rodata PROGBITS 00102fe0 0031a0 000b60 00 WA 0 0 32 [ 4] datas PROGBITS 00103b40 003d00 0006a0 00 WA 0 0 32 [ 5] initlevel PROGBITS 001041e0 0043a0 00006c 00 WA 0 0 4 [ 6] _k_task_list PROGBITS 0010424c 00440c 000080 00 WA 0 0 32 [ 7] _k_task_ptr PROGBITS 001042cc 00448c 000008 00 WA 0 0 4 [ 8] _k_event_list PROGBITS 001042d4 004494 000010 00 WA 0 0 4 [ 9] bss NOBITS 001042e8 0044a4 000048 00 WA 0 0 8 [10] noinit NOBITS 00104340 0044a4 001900 00 WA 0 0 32 [11] intList PROGBITS 00000800 000074 00014c 00 WA 0 0 4 [12] .comment PROGBITS 00000000 0044a4 00002e 01 MS 0 0 1 [13] .debug_aranges PROGBITS 00000000 0044d8 0012d0 00 0 0 8 [14] .debug_line PROGBITS 00000000 0057a8 00c29b 00 0 0 1 [15] .debug_info PROGBITS 00000000 011a43 028743 00 0 0 1 [16] .debug_abbrev PROGBITS 00000000 03a186 008dd5 00 0 0 1 [17] .debug_loc PROGBITS 00000000 042f5b 00894c 00 0 0 1 [18] .debug_ranges PROGBITS 00000000 04b8a8 001568 00 0 0 8 [19] .debug_str PROGBITS 00000000 04ce10 004f76 01 MS 0 0 1 [20] .debug_frame PROGBITS 00000000 051d88 0037f4 00 0 0 4 [21] .shstrtab STRTAB 00000000 05557c 0000ea 00 0 0 1 [22] .symtab SYMTAB 00000000 055a28 0021a0 10 23 175 4 [23] .strtab STRTAB 00000000 057bc8 002893 00 0 0 1 (省略)
② ${OBJCOPY} --change-section-address intList=${CONFIG_PHYS_LOAD_ADDR} $@ elf.tmp
/Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-objcopy --change-section-address intList=0x00100000 zephyr.elf elf.tmp
i586-pc-elf-objcopy --help
{--change-section-address|--adjust-section-vma}{=|+|-} Change LMA and VMA of section by
${OBJCOPY}
OBJCOPY = $(CROSS_COMPILE)objcopy
${CONFIG_PHYS_LOAD_ADDR}
[zephyr_base]/samples/hello_world/microkernel/outdir/.config
CONFIG_PHYS_LOAD_ADDR=0x00100000
intList
[zephyr_base]/samples/hello_world/microkernel/outdir/final-linker.cmd
intList () : { KEEP(*(.spurIsr)) KEEP(*(.spurNoErrIsr)) __INT_LIST_START__ = .; LONG((__INT_LIST_END__ - __INT_LIST_START__) / 0x14) KEEP(*(.intList)) __INT_LIST_END__ = .; } > IDT_LISTTODO ISRの中身は後で
②後の、objdumpの結果
(省略) Disassembly of section intList: 00100000 <__isr___SpuriousIntHandler>: 100000: f3 2a 10 repz sub (%eax),%dl ... 00100004 <__isr___SpuriousIntNoErrCodeHandler>: 100004: f1 icebp 100005: 2a 10 sub (%eax),%dl ... 00100008 <__INT_LIST_START__>: 100008: 10 00 adc %al,(%eax) 10000a: 00 00 add %al,(%eax) 10000c: 2d 04 10 00 02 sub $0x2001004,%eax 100011: 00 00 add %al,(%eax) 100013: 00 04 00 add %al,(%eax,%eax,1) 100016: 00 00 add %al,(%eax) 100018: ff (bad) 100019: ff (bad) 10001a: ff (bad) 10001b: ff 00 incl (%eax) 10001d: 00 00 add %al,(%eax) ... (省略)
②後の、zephyr.elf の readelf 結果
(省略) Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] text PROGBITS 00100000 0001c0 002f64 00 AX 0 0 16 [ 2] devconfig PROGBITS 00102f64 003124 00006c 00 WA 0 0 4 [ 3] rodata PROGBITS 00102fe0 0031a0 000b60 00 WA 0 0 32 [ 4] datas PROGBITS 00103b40 003d00 0006a0 00 WA 0 0 32 [ 5] initlevel PROGBITS 001041e0 0043a0 00006c 00 WA 0 0 4 [ 6] _k_task_list PROGBITS 0010424c 00440c 000080 00 WA 0 0 32 [ 7] _k_task_ptr PROGBITS 001042cc 00448c 000008 00 WA 0 0 4 [ 8] _k_event_list PROGBITS 001042d4 004494 000010 00 WA 0 0 4 [ 9] bss NOBITS 001042e8 0044a4 000048 00 WA 0 0 8 [10] noinit NOBITS 00104340 0044a4 001900 00 WA 0 0 32 [11] intList PROGBITS 00100000 00007400014c 00 WA 0 0 4 [12] .comment PROGBITS 00000000 0044a4 00002e 01 MS 0 0 1 [13] .debug_aranges PROGBITS 00000000 0044d8 0012d0 00 0 0 8 [14] .debug_line PROGBITS 00000000 0057a8 00c29b 00 0 0 1 [15] .debug_info PROGBITS 00000000 011a43 028743 00 0 0 1 [16] .debug_abbrev PROGBITS 00000000 03a186 008dd5 00 0 0 1 [17] .debug_loc PROGBITS 00000000 042f5b 00894c 00 0 0 1 [18] .debug_ranges PROGBITS 00000000 04b8a8 001568 00 0 0 8 [19] .debug_str PROGBITS 00000000 04ce10 004f76 01 MS 0 0 1 [20] .debug_frame PROGBITS 00000000 051d88 0037f4 00 0 0 4 [21] .shstrtab STRTAB 00000000 05557c 0000ea 00 0 0 1 [22] .symtab SYMTAB 00000000 055a28 0021a0 10 23 175 4 [23] .strtab STRTAB 00000000 057bc8 002893 00 0 0 1 (省略)
③ $(OBJCOPY) -R intList elf.tmp $@
zephyr.elfのintListセクションの削除。各セクションの(バイナリファイル内の?)オフセット位置が前方にずれる。/Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-objcopy -R intList elf.tmp zephyr.elf
i586-pc-elf-objcopy --help
-R --remove-sectionRemove section from the output
②後の、zephyr.elf の readelf 結果
(省略) Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] text PROGBITS 00100000 000060 002f64 00 AX 0 0 16 [ 2] devconfig PROGBITS 00102f64 002fc4 00006c 00 WA 0 0 4 [ 3] rodata PROGBITS 00102fe0 003040 000b60 00 WA 0 0 32 [ 4] datas PROGBITS 00103b40 003ba0 0006a0 00 WA 0 0 32 [ 5] initlevel PROGBITS 001041e0 004240 00006c 00 WA 0 0 4 [ 6] _k_task_list PROGBITS 0010424c 0042ac 000080 00 WA 0 0 32 [ 7] _k_task_ptr PROGBITS 001042cc 00432c 000008 00 WA 0 0 4 [ 8] _k_event_list PROGBITS 001042d4 004334 000010 00 WA 0 0 4 [ 9] bss NOBITS 001042e8 004344 000048 00 WA 0 0 8 [10] noinit NOBITS 00104340 004344 001900 00 WA 0 0 32 [11] .comment PROGBITS 00000000 004344 00002e 01 MS 0 0 1 [12] .debug_aranges PROGBITS 00000000 004378 0012d0 00 0 0 8 [13] .debug_line PROGBITS 00000000 005648 00c29b 00 0 0 1 [14] .debug_info PROGBITS 00000000 0118e3 028743 00 0 0 1 [15] .debug_abbrev PROGBITS 00000000 03a026 008dd5 00 0 0 1 [16] .debug_loc PROGBITS 00000000 042dfb 00894c 00 0 0 1 [17] .debug_ranges PROGBITS 00000000 04b748 001568 00 0 0 8 [18] .debug_str PROGBITS 00000000 04ccb0 004f76 01 MS 0 0 1 [19] .debug_frame PROGBITS 00000000 051c28 0037f4 00 0 0 4 [20] .shstrtab STRTAB 00000000 05541c 0000e2 00 0 0 1 [21] .symtab SYMTAB 00000000 055898 002060 10 22 159 4 [22] .strtab STRTAB 00000000 0578f8 002612 00 0 0 1 (省略)疑問:intListセクションが削除されてしまったがよいのか?
推測:この処理(intListセクションのアドレス変更、セクション削除)は、ARCHがx86の時だけなので、別の所でなんらかの対処がされているはず。
コメント