Search code examples
armgdbqemugnu-assemblergnu-arm

STR (ARM gnu Assembly)cannot change memory in


I want to change some bits in memory by STR instruction.

    .text
.equ    ram_address,0x4000
.equ    pattern,0x55
.equ    counter,50  
    mov r0,#pattern
    mov r1,#counter
    mov r2,#ram_address

back:   str r0,[r2]
    add r2,#4
    subs r1,r1,#1
    bne back
here:   b here
    
        .data
i:  .word 0xffffffff

and using such a makefile:

TOOLCHAIN=arm-none-eabi
Assembler=${TOOLCHAIN}-as
Linker=${TOOLCHAIN}-ld
Objcpy=${TOOLCHAIN}-objcopy
Compile_Options= -g
Link_Options=-Ttext=0x0 -Tbss=0x4000 # -Tdata=0x4000 # 
.PHONY : clean
.PRECIOUS : %.bin %.elf %.o
all : create

create : flash.bin


flash.bin:main.bin  
    dd if=/dev/zero of=flash.bin bs=4096 count=4096 
    dd if=main.bin of=flash.bin bs=4096 conv=notrunc

%.bin:%.elf
    $(Objcpy) -O binary $< $@   

%.elf:%.o
    $(Linker) $(Link_Options) -o $@ $<

%.o:%.S
    $(Assembler) $(Compile_Options) $< -o $@
    
clean :
    rm -f *.o *.bin *.elf

And this is qemu command:

qemu-system-arm -S -M connex -pflash flash.bin -nographic -serial /dev/null

QEMU emulator version 6.1.0

I check memory by qemu-arm-system and gdbserver and x/16xw 0x4000 command. results is:

0xffffffff 0x00000000 0x00000000 0x00000000

It means .data section is readonly. how could I set it writable?


Solution

  • As mensioned this page: [http://www.bravegnu.org/gnu-eprog/using-ram.html][1]

    The connex board has a 64 MB of RAM starting at address 0xA0000000, in which variables can be stored.

    so I changed ram_address to 0xA0000000 and it worked, and by x/4xw 0xA0000000 I can see changes in RAM.