^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/arch/arm/boot/bootp/init.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2000-2003 Russell King.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * "Header" file for splitting kernel + initrd. Note that we pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * r0 through to r3 straight through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This demonstrates how to append code to the start of the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * zImage, and boot the kernel without copying it around. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * example would be simpler; if we didn't have an object of unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * size immediately following the kernel, we could build this into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * a binary blob, and concatenate the zImage using the cat command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .section .start, "ax"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .type _start, #function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .globl _start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) _start: add lr, pc, #-0x8 @ lr = current load addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) adr r13, data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ldmia r13!, {r4-r6} @ r5 = dest, r6 = length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) add r4, r4, lr @ r4 = initrd_start + load addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) bl move @ move the initrd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Setup the initrd parameters to pass to the kernel. This can only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * passed in via the tagged list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ldmia r13, {r5-r9} @ get size and addr of initrd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) @ r5 = ATAG_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) @ r6 = ATAG_INITRD2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) @ r7 = initrd start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) @ r8 = initrd end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) @ r9 = param_struct address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ldr r10, [r9, #4] @ get first tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) teq r10, r5 @ is it ATAG_CORE?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * If we didn't find a valid tag list, create a dummy ATAG_CORE entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) movne r10, #0 @ terminator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) movne r4, #2 @ Size of this entry (2 words)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) stmiane r9, {r4, r5, r10} @ Size, ATAG_CORE, terminator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * find the end of the tag list, and then add an INITRD tag on the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * If there is already an INITRD tag, then we ignore it; the last INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * tag takes precedence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) taglist: ldr r10, [r9, #0] @ tag length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) teq r10, #0 @ last tag (zero length)?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) addne r9, r9, r10, lsl #2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) bne taglist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mov r5, #4 @ Size of initrd tag (4 words)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) stmia r9, {r5, r6, r7, r8, r10}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) b kernel_start @ call kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Move the block of memory length r6 from address r4 to address r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) move: ldmia r4!, {r7 - r10} @ move 32-bytes at a time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) stmia r5!, {r7 - r10}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ldmia r4!, {r7 - r10}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) stmia r5!, {r7 - r10}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) subs r6, r6, #8 * 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) bcs move
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) mov pc, lr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .size _start, . - _start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .align
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .type data,#object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) data: .word initrd_start @ source initrd address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .word initrd_phys @ destination initrd address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .word initrd_size @ initrd size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .word 0x54410001 @ r5 = ATAG_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .word 0x54420005 @ r6 = ATAG_INITRD2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .word initrd_phys @ r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .word initrd_size @ r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .word params_phys @ r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .size data, . - data