gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] A success with a stand-alone application on the Raspberry PI -


From: Gaius Mulley
Subject: Re: [Gm2] A success with a stand-alone application on the Raspberry PI - after modifying the assembler
Date: Mon, 10 Nov 2014 12:44:52 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

JD <address@hidden> writes:

> Gaius,
> My main interest in using gm2 is to create stand-alone applications
> ("bare metal programming") on the RPi. So here is my first, trivial,
> attempt:
>
>     MODULE BakingPi2;
>     
>     VAR GPIOcontrol[20200000H]: ARRAY [0..5] OF BITSET;
>     GPIOon[2020001CH]: ARRAY [0..1] OF BITSET;
>     GPIOoff[20200028H]: ARRAY [0..1] OF BITSET;
>     
>     VAR i: CARDINAL;
>     
>     BEGIN
>     GPIOcontrol[1]:= {18};
>     
>     LOOP (* forever *)
>     
>     GPIOon[0]:= {16};
>     FOR i :=1 TO 100000000 DO (* nothing *)END;
>     
>     GPIOoff[0]:= {16};
>     FOR i :=1 TO 100000000 DO (* nothing *)END;
>     END; (* loop *)
>     END BakingPi2.
> (This simple functionality comes from
> http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/). This
> module compiles and produces a binary with no problem but,
> unfortunately, nothing seems to happen when the RPi is booted with
> just this binary. Of course, there isn't much that the RPi could
> display to show what happened.
>
> So I looked at the assembler and noticed that it uses the stack
> pointer before assigning anything to it:
>
>     _M2_BakingPi2_init:
>     .fnstart
>     .LFB0:
>     @ args = 0, pretend = 0, frame = 0
>     @ frame_needed = 1, uses_anonymous_args = 0
>     @ link register save eliminated.
>     stmfd sp!, {r4, fp} @,
>     .save {r4, fp}
>     .setfp fp, sp, #4
> The stmfd instruction saves the list of registers in {} on the stack
> using the register sp.
>
> So I augmented the assembler using a crib from the web:
>
>     _M2_BakingPi2_init:
>     .fnstart
>     .LFB0:
>     LDR sp, =stack_top
>     @ args = 0, pretend = 0, frame = 0
>     @ frame_needed = 1, uses_anonymous_args = 0
>     @ link register save eliminated.
>     stmfd sp!, {r4, fp} @,
>     .save {r4, fp}
>     .setfp fp, sp, #4
> and right at the end:
>
>     STACK: . = . + 0x1000 /* 4kB of stack memory */
>     stack_top = .
> And then it all works!
>
> So, is there a way around this "feature"? Is there a gcc option? (I
> tried -nostdlib, but no change) Or is this a problem with binutls that
> neither you nor a user can alter? I tried compiling the above module
> on my x86 and the assembler looks very similar. It starts off with a
> pushl instruction.
>
> I look forward to hearing from you.
>
> Regards,
> John
>
>
> _______________________________________________
> gm2 mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/gm2

Hi John,

thanks for the email - very interesting!  I think you might be able to
achieve this by adding inline assembler into the Modula-2 source code.
So for example:

    MODULE BakingPi2;
    
    VAR GPIOcontrol[20200000H]: ARRAY [0..5] OF BITSET;
    GPIOon[2020001CH]: ARRAY [0..1] OF BITSET;
    GPIOoff[20200028H]: ARRAY [0..1] OF BITSET;
    
    VAR i: CARDINAL;
    
    BEGIN
       ASM VOLATILE ("LDR sp, =stack_top") ;

       GPIOcontrol[1]:= {18};
    
       LOOP (* forever *)
    
       GPIOon[0]:= {16};
       FOR i :=1 TO 100000000 DO (* nothing *)END;
    
       GPIOoff[0]:= {16};
       FOR i :=1 TO 100000000 DO (* nothing *)END;
       END; (* loop *)

       ASM VOLATILE ("STACK: . = . + 0x1000")  (* 4kB of stack memory *)
       ASM VOLATILE ("stack_top = .")

    END BakingPi2.

hope this helps,

regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]