gm2
[Top][All Lists]
Advanced

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

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


From: JD
Subject: [Gm2] A success with a stand-alone application on the Raspberry PI - after modifying the assembler
Date: Thu, 6 Nov 2014 14:24:28 +0000
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

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




reply via email to

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