SpinalHDL / openocd_riscv

Spen's Official OpenOCD Mirror
Other
47 stars 34 forks source link

Compilation on macOS results in alignment errors #20

Closed tomverbeure closed 2 years ago

tomverbeure commented 2 years ago

When compiling with macOS, I get the following errors:

src/target/vexriscv.c:290:6: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                        *((uint32_t*)reg->value) = 0xDEADBEEF;
                          ^~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:330:45: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                vexriscv_write_regfile(target, false, 1, *(uint32_t *)reg->value);
                                                          ^~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:736:42: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                vexriscv_cpu_write_pc(target, false, *((uint32_t*)vexriscv->regs->pc.value));
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:744:46: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                        vexriscv_write_regfile(target, false, i,*((uint32_t*)reg->value));
                                                                  ^~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:831:12: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
    pc = *((uint32_t*) vexriscv->core_cache->reg_list[32].value);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:876:16: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
        r0 = *((uint32_t*) vexriscv->core_cache->reg_list[10].value);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:879:16: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
        r1 = *((uint32_t*) vexriscv->core_cache->reg_list[11].value);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:1664:5: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                *((uint32_t*)vexriscv->regs->pc.value) = address;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:1674:42: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                breakpoint = breakpoint_find(target, *((uint32_t*)vexriscv->regs->pc.value));
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/vexriscv.c:1709:49: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                LOG_DEBUG("Target resumed at 0x%08" PRIx32, *((uint32_t*)vexriscv->regs->pc.value));
                                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/helper/log.h:125:5: note: expanded from macro 'LOG_DEBUG'
                                expr); \
                                ^~~~
src/target/vexriscv.c:1713:55: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                LOG_DEBUG("Target debug resumed at 0x%08" PRIx32, *((uint32_t*)vexriscv->regs->pc.value));
                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/helper/log.h:125:5: note: expanded from macro 'LOG_DEBUG'
                                expr); \

These errors look valid to me.

The can be fixed by using the buf_set_u32 and buf_get_u32 functions. I'm working on a patch.

Tom

Dolu1990 commented 2 years ago

<3