Look at real operating systems to see how they size memory. (8)

なんか標題からどんどん脱線しているような気もしますが構わず続行。arch/arm/kernel/vmlinux.lds.S を確認してみます。
とりあえず以下から掘削してみます。

OUTPUT_ARCH(arm)
ENTRY(stext)

SECTION 云々は別途で。stext が始点らしい。

/*
 * Kernel startup entry point.
 * ---------------------------
 *
 * This is normally called from the decompressor code.  The requirements
 * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
 * r1 = machine nr, r2 = atags or dtb pointer.
 *
 * This code is mostly position independent, so if you link the kernel at
 * 0xc0008000, you call this at __pa(0xc0008000).
 *
 * See linux/arch/arm/tools/mach-types for the complete list of machine
 * numbers for r1.
 *
 * We're trying to keep crap to a minimum; DO NOT add any machine specific
 * crap here - that's what the boot loader (or in extreme, well justified
 * circumstances, zImage) is for.
 */
	__HEAD
ENTRY(stext)

うーん、微妙だなぁ。とりあえず手続きの中から呼び出されているのが以下らしい。

  • __lookup_processor_type
  • __vet_atags
  • __create_page_tables
  • __enable_mmu

あと、直前エントリでも引用した記憶がある記述が以下。

    ldr	r13, =__mmap_switched		@ address to jump to after
    					@ mmu has been enabled

コメントな記述が本当なのかどうか。とりあえず jmp するのが以下らしい。

/*
 * Setup common bits before finally enabling the MMU.  Essentially
 * this is just loading the page table pointer and domain access
 * registers.
 *
 *  r0  = cp#15 control register
 *  r1  = machine ID
 *  r2  = atags or dtb pointer
 *  r4  = page table pointer
 *  r9  = processor ID
 *  r13 = *virtual* address to jump to upon completion
 */
__enable_mmu:

確かに __enable_mmu から __turn_mmu_on に jmp した後、以下な記述がありますね。

	mov	r3, r13
	mov	pc, r3
__enable_mmu_end:
ENDPROC(__turn_mmu_on)

ここで、__mmap_switched に jmp する模様。この __mmap_switched から start_kernel が kickoff されるのか。
とりあえず最初からトレイスすることはできるようになったのかどうか。

TEXT_OFFSET

リンカスクリプトにアドレスな記述があまり無いのは若干不思議。以下なあたりの記述を掘削しておいた方が良さげ。

#ifdef CONFIG_XIP_KERNEL
	. = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR);
#else
	. = PAGE_OFFSET + TEXT_OFFSET;
#endif

とりあえず今日はこれで終了。