bztsrc/raspi3-tutorial

How does the .bss get cleared?

connorkuehl opened this issue · 2 comments

Does x1 get incremented somehow? I think x1 has the same value throughout the loop so it looks like with every iteration a zero is being written to the same place.

In start.S:

    // clear bss
    ldr     x1, =__bss_start
    ldr     w2, =__bss_size
3:  cbz     w2, 4f
    str     xzr, [x1], #8
    sub     w2, w2, #1
    cbnz    w2, 3b

I'm also curious about the immediate offset in the str instruction. Is it necessary?

Actually, after stepping through it with gdb it would appear the str instruction can update the base register. See the "Index Modes" sub section in the ARM Cortex-A Series Programmer's Guide for ARMv8

Hi,

That's right. The #8 constant in the str instruction tells the CPU to adjust the offset register by 8 bytes.

Cheers,
bzt