gm2
[Top][All Lists]
Advanced

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

Re: Partial success building the trunk on MSYS2/Windows platform


From: Runar Tenfjord
Subject: Re: Partial success building the trunk on MSYS2/Windows platform
Date: Fri, 4 Nov 2022 11:02:35 +0100

Thanks,

Indeed I found your project with R-pi4, but did not find
the article, only the Github repo. This inspired me to look
into m2 for bare metal programming. There is not a lot of
information how to setup these complete build environment,
because it is common to just use commercial offerings here.

So, thank for this effort.

I will probably target a STM32F4 or similar micro controller.
It should not be to difficult I believe.

The STM programmer is a native windows application,
therfore I wanted to get gm2 compiler to run under
Windows, so the complete toolchain is on one platform.

I want to try to use the 'semi hosting' setup, as this allows
for easy debug printing without any setup.
Just printing directly through a debugging probe with
the BKPT CPU instruction.
You can even debug the startup code with this solution.

I will post information if I find anything which could be of
general interest.

Best regards
Runar Tenfjord

On Wed, Nov 2, 2022 at 12:16 PM Gaius Mulley <gaiusmod2@gmail.com> wrote:
Runar Tenfjord <runar.tenfjord@gmail.com> writes:

> Hi,
>
> Thank you for your detailed explanation. My knowledge of the C language
> is limited and I missed a bit the distinction between the various types.
>
> I was trying to port the 'strlen' function from newlib and looked
> into the examples in the testsuite for inspiration as suggested
> and came up with:
>
>  (* Adapted from GNU NewLib *)
>  (* gm2 -g  -fcpp -Wall String.mod *)
>  MODULE String ;
>
>  FROM SYSTEM IMPORT ADR, BITSET32, WORD, TSIZE ;
>  FROM ASCII IMPORT nul;
>
>  TYPE
>  (* defined(__x86_64) || (defined(__alpha__) && defined(__arch64__)) || defined(__LP64__) *)
>  #if defined(HAS_BITSET64)
>     BITS = BITSET64 ;
>     WRD = LONGCARD ;
>  #else
>     BITS = BITSET32 ;
>     WRD = CARDINAL ;
>  #endif
>
>  CONST
>     BLOCK_SIZE = TSIZE(WRD) ;
>  (* defined(__x86_64) || (defined(__alpha__) && defined(__arch64__)) || defined(__LP64__) *)
>  #if defined(HAS_BITSET64)
>     NULLMASK1 = 0101010101010101H ;
>     NULLMASK2 = 8080808080808080H ;
>  #else
>     NULLMASK1 = 01010101H ;
>     NULLMASK2 = 80808080H ;
>  #endif
>
>  #define DETECTNULL(X) (BITSET(VAL(WRD,X^) - VAL(WRD,NULLMASK1)) * (-VAL(BITSET,X^)) * VAL(BITSET,NULLMASK2))
>
>  (* Find length of string *)
>  PROCEDURE Length (VAR a: ARRAY OF CHAR) : CARDINAL ;
>  VAR
>     Len, High: CARDINAL ;
>     PWord: POINTER TO WRD ;
>  BEGIN
>     Len := 0;
>     High := HIGH(a) ;
>  #if !(defined LIBRARY_OPTIMIZE_SIZE)
>     (* Check block by block *)
>     (* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord *)
>     PWord := ADR(a[Len]);
>     LOOP
>        IF DETECTNULL(PWord) # 0 THEN
>           EXIT;
>        END;
>        INC(PWord, BLOCK_SIZE);
>        INC(Len, BLOCK_SIZE);
>        IF (Len > (High - BLOCK_SIZE)) THEN
>           EXIT;
>        END;
>     END;
>     (* Find position in last block *)
>  #endif
>     WHILE (Len <= High) AND (a[Len] # nul) DO
>        INC(Len);
>     END;
>     RETURN(Len);
>  END Length ;
>
>  VAR   
>     str : ARRAY[0..256] OF CHAR;
>     i, len : CARDINAL;
>
>  BEGIN
>     str := '123';
>     len := Length(str);
>  END String.
>
> This works fine and look readable still.
> Except for when I use the flag -fsoft-check-all.
> It then failed with a segmentation fault.

Hi,

thanks for the report - I'll explore the sigsegv.

> For now this is a fun exercise in porting Newlib
> functions in order to learn/evaluate the language.
>
> I think this could work perfectly for bare-metal embedded
> development and potential much safer than C/C++.
> It is for a reason the IEC 61131-3 PLC structured text
> language is based on Modula-2 and not C/C++.

yes indeed - low level systems programming in m2 is a great match.  I
think the gcc analyser working with m2 would also be extremely effective
for small bare metal programs.  I had a minor detour on the R-pi4 a year
ago:

  https://splendidisolation.ddns.net/Southwales/gaius/web/bare-metal-m2.html

regards,
Gaius

reply via email to

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