Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Struct interface for IO doesn't work

I was trying to convert a large code base written for the NIOS I processor to NIOS II. My clever idea was to simply include the excalibur.h and compile for NIOS II. However, every time I read from a memory address through the old struct interface of NIOS I, the compiler uses a ldw assembly instruction. If I do the same memory-mapped read using the macros supplied with NIOS II, the compiler uses a ldwio. What gives? Did Altera hack their compiler to explicitly not support a struct-based interface for memory-mapped IO?

--Jordan

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Jordan,

    > However, every time I read from a memory address through the old struct interface of NIOS I,

    > the compiler uses a ldw assembly instruction.

    This is correct behavior.

    > If I do the same memory-mapped read using the macros supplied with NIOS II, the compiler

    > uses a ldwio.

    If you're referring to the IORD/WR macros, this is correct.

    > What gives?

    The compiler doesn't know anything about your data cache. If you don't implement a data

    cache, then ldw/ldwio behave identically. However, if you do implement a data cache you

    need to do one of two things:

    1. Use the IO macros, which will explicitly use ldxio, or,

    2. Make your structs (describing registers) volatile, and use -mno-cache-volatile.

    The volatile keyword in no sufficient -- it only tells the compiler that it must perform

    memory read/write on each object reference (rather than storing it in a register). But it

    doesn't tell the compiler anything about _how_ to access the object -- that's where the

    compiler flag comes in :-)

    Hope this helps.

    Regards,

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ah, I didn't know about the compiler flag.

    Thanks, that does help.

    --Jordan