Re: [cc65] The Contiki Desktop OS for cc65

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-03-16 12:41:34


Hi!

On Sun, Mar 16, 2003 at 08:12:57AM +0100, Adam Dunkels wrote:
> This sounds very, very interesting, and not too complicated either!

Yes. As soon as I had described it, I thought this could be useful for others,
too. Having this automated in some way would allow to create program overlays.
The only drawback is that these overlays cannot call each other.

> Would it be possible to make library file out of the compiled assmebler
> file created in step 2, together with a small crt0.s which just calls
> _main, and then compile Contiki programs as regular programs, but by
> linking to the special Contiki library? Could the resulting binary be
> turned into a o65 module?

I'm not sure what you want to do. Of course you can write a crt0.s file and of
course a function could be named _main, but I can't see and advantages when
doing so, because the binary is not able to run without Contiki because of the
absolute memory references.

> This way, Contiki programs could be written with a main() function
> similar to ordinary programs.

Ahh, ok. Since modules don't really need a setup (they don't have their own
stack, and the hardware setup is done in the main program), there's nothing
that a crt0.s module could do besides jumping to main(). So it would in fact
be a jump table with just one entry. Here is such a crt0.s module:

----------------------------------------------------------------------------
.segment        "JUMPTABLE"

        .import _main
        jmp     _main
----------------------------------------------------------------------------

The jump vector is then located at the start of the code segment of the
module, which is identical to the start address of the module when loaded into
memory. Loading the module and calling it's main function would look like
that:

----------------------------------------------------------------------------
void install_contiki_module (const char* name, int argc, char* argv[])
/* Load a contiki module from disk and call it's main function */
{
    typedef int (*mainfunc) (int argc, char* argv[], ...);

    static struct mod_ctrl ctrl = {
        read            /* Read from disk */
    };
    unsigned char Res;

    /* Now open the file */
    ctrl.callerdata = open (name, O_RDONLY);
    if (ctrl.callerdata >= 0) {

        /* Load the module */
        Res = mod_load (&ctrl);

        /* Close the input file */
        close (ctrl.callerdata);

        /* Check the return code */
        if (Res == MLOAD_OK) {
            /* Wrong module, out of memory or whatever. Print an error
             * message and return.
             */
            /* ### */
            return;
        }

        /* We've successfully loaded the module. Call its main function. We
         * could also evaluate the function result code if necessary.
         */
        ((mainfunc) ctrl.module) (argc, argv);

    } else {

        /* Could not open the file, display an error and return */
        /* ### */

    }
}
----------------------------------------------------------------------------

Beware: All this code is untested!

> Am I totally "out there", or is there some sense in my thinking? :-)

Sounds very reasonable, as usual:-)

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-03-16 12:41:52 CET