writing and reading from the same memory address from two different QEMU instances

44 Views Asked by At

I have a code to write "Hello" at the memory address 0x10000000, and another code to read the value from this memory address and print it out. I have defined 0x10000000 as a shared memory in the linker scripts of both the codes. I am running both these codes (reading and writing) on two different instances of QEMU. The processor that I am emulating is Arm cortex M7, and the target machine is lm3s811evb. Both the codes are running. But there are no outputs on the console.

Following is my code to write "Hello" at the memory address 0x10000000:

// Memory address where the value will be written
#define MEMORY_ADDRESS 0x10000000

// Function to write a string to a memory address
void write_string_to_memory(char* address, const char* str) {
    while (*str != '\0') {
        *address = *str;
        address++;
        str++;
    }
    // Null-terminate the string at the end
    *address = '\0';
}

// Entry point
void main() {
    // Cast the memory address to a character pointer
    char* memory_address = (char*)MEMORY_ADDRESS;

    // Write the string "hello" to the specified memory address
    write_string_to_memory(memory_address, "hello");

    // Infinite loop (halt the program)
    while (1);
}

And following is the corresponding linker script:

MEMORY
{
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
    SHARED_MEMORY (rwx) : ORIGIN = 0x10000000, LENGTH = 0x00001000
    SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00002000
}

SECTIONS
{
    .text :
    {
        _text = .;
        KEEP(*(.isr_vector))
        *(.text*)
        *(.rodata*)
        _etext = .;
    } > FLASH

    .data : AT(ADDR(.text) + SIZEOF(.text))
    {
        _sdata = .;
        *(vtable)
        *(.data*)
        _edata = .;
    } > SRAM

    .bss :
    {
        _sbss = .;
        *(.bss*)
        *(COMMON)
        _ebss = .;
    } > SRAM

    .shared_memory :
    {
        /* Define the shared memory section */
        _shared_memory_start = .;
        *(.shared_memory*)
        _shared_memory_end = .;
    } > SHARED_MEMORY
}

I am using the following commands to link and run the file:

arm-none-eabi-ld -T linker_lm3s811.ld main1-string.o startup1.o -o main1-string.elf
./qemu-system-arm -M lm3s811evb -kernel main1-string.elf -nographic

While debugging using gdb, i am getting the following:

Breakpoint 1, main () at main1-string.c:18
18          char* memory_address = (char*)MEMORY_ADDRESS;
(gdb)  x/s 0x10000000
0x10000000:     <error: Cannot access memory at address 0x10000000>
0

There are 0 best solutions below