On 4/3/24 08:15, Gautam Bhat wrote:
On Tue, Apr 2, 2024 at 2:01 AM Richard Henderson
<richard.hender...@linaro.org> wrote:

The boot process must cooperate somehow.

When using loader, you must link the image such that it loads at the pc reset 
address
defined by the architecture manual.


r~

I changed my loading options to the following now to have better control:

./qemu-system-msp430 -machine msp430-launchpad -device
loader,file=simple_test.bin,addr=0xFFFE,cpu-num=0,force
-raw=on -d in_asm,out_asm

Here simple_test.bin is the raw binary file converted using objcopy.
addr=0xFFFE is the vector location where the PC will load with the
starting address.

Now how do I load the address in that reset vector location and set my
PC? Is there some example code that I can look at?

Hmm. I can't find an example. I see a TODO for m68k which *should* be loading the pc from the reset vector on reset.

What I think should work is something like

void msp430_cpu_reset_hold(Object *obj)
{
    standard stuff, mostly zeroing registers.
}

void msp430_cpu_reset_exit(Object *obj)
{
    MSP430CPUClass *mcc = MSP430_CPU_GET_CLASS(obj);
    CPUState *cs = CPU(obj);
    CPUMSP430State *env = cpu_env(cs);
    MemTxResult res;

    if (mcc->parent_phases.exit) {
        mvv->parent_phases.exit(obj);
    }

    /* Load PC from the Hard Reset interrupt vector. */
    env->pc = address_space_lduw(cs->as, 0xfffe, MEMTXATTRS_UNSPECIFIED, &res);
    assert(res == MEMTX_OK);
}

void msp430_cpu_class_init(ObjectClass *c, void *data)
{
    MSP430CPUClass *mcc = MSP430_CPU_CLASS(c);
    ResettableClass *rc = RESETTABLE_CLASS(c);

    resettable_class_set_parent_phases(rc, NULL,
                                       msp430_cpu_reset_hold,
                                       msp430_cpu_reset_exit,
                                       &mcc->parent_phases);
}

The loader device populates ram during the reset hold phase, so I believe you need to wait until after that is complete to perform the load, thus the reset_exit hook.


r~

Reply via email to