Questions regarding ARM Thumb code generation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Questions regarding ARM Thumb code generation

Erlend Sveen
Hi all!

I have been trying to get a compiler running on a Cortex-M7. I've had success
with some of the GNU binutils (linker, assembler, objdump, ...), but getting
GCC to run seemed to be a bit too ambitious. I went looking around and found
TCC. Sadly it does not support thumb instructions, but I did find that someone
has attempted to get going with it:

  https://github.com/gfwilliams/tinycc

While it barely compiles an empty function, I decided to spend a couple of
weekends trying to understand it and figure out if I could get it working.
Those weekends have now turned into month(s). Using the tests in the
tests/tests2 directory, I'm having a success rate of about 88% (I'm ignoring
those that are intended to not compile). The ones that fail are 4 due to
floating point support, 1 because of array copying, 1 due to C library issues
and 1 due to an immediate being out of range (still working on these). Note that
I'm running the tests manually since I can't run the test system on my MCU
(yet), so take the numbers with a grain of salt. I've also been using an older
version of TCC (from the link above), so I'll have to migrate my changes and
run all the newer tests too.

While I'm still hacking away on the original arm-gen.c it is starting to look
rather serious. So I figured I should ask a few questions on the mailing list
to ensure that I'm on the right track and that my contributions are welcome.

 * Is anyone else working on something like this? I've searched the mailing
   list but could not find any.
 * The repository I found mentions a licensing issue. I've searched the
   mailing list and found that the author of the original ARM codegen does not
   want to re-license it. Personally, I don't mind leaving the license as is.
   There is no way I will be able to write the thumb code gen from scratch,
   so my code will be based on the ARM one and subject to the same issue. Do I
   need to worry about this? It would really suck if my code gets dropped due
   to relicensing in the future.
 * Generally speaking, information to new contributors seems to be a bit
   scarce. I'm guessing that I'll have to make a new target to the build system
   at the very least, and new files for the thumb code gen. Is there anything I
   should read up on before I attemt to do this?
 * Code style: It is of course best to follow the existing code, but if I
   contribute a new file, am I allowed to use my own style for it? I've read
   the CodingStyle text file but it does not say much on this.
 * If I do substantial modifications to a function, may I reformat it? I see
   that some functions have a mix of spaces and tab indentation, I'd love to
   make this consistent.
 * C99: I could not find anything about mixed code and declarations. Am I
   allowed to use this? I personally find this to be a really important
   feature, since it improves readability by a lot. It also helps avoiding
   uninitialized variables (RAII and all).

I will probably have more questions for later, but these are the most important
ones. If there are no major roadblocks I may even have a diff ready some time
in the next few months! Also if there is something special I should know
regarding adding a new codegen I'd love to know.

Regards,
Erlend Sveen

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Questions regarding ARM Thumb code generation

Daniel Glöckner-2
Hi,

On Sun, Mar 22, 2020 at 11:26:30AM +0000, Erlend Sveen wrote:
> * The repository I found mentions a licensing issue. I've searched the
>   mailing list and found that the author of the original ARM codegen does not
>   want to re-license it. Personally, I don't mind leaving the license as is.
>   There is no way I will be able to write the thumb code gen from scratch,
>   so my code will be based on the ARM one and subject to the same issue. Do I
>   need to worry about this? It would really suck if my code gets dropped due
>   to relicensing in the future.

since I am the one who does not want to relicense the ARM32 backend, I give
you and everyone else permission to use my ARM backend code as a template
for a backend for another instruction set as long as you release it as open
source software under the license found in the RELICENSING file in TinyCC
(or the LGPL). To me ARM Thumb is a different instruction set.

My intention is not to hinder development of TinyCC. What I want to prevent
is that TinyCC gets hidden in closed source products. The LGPL does allow
commercial use. People just have to read and follow the license.

Best regards,

  Daniel

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Questions regarding ARM Thumb code generation

Christian Jullien-3
In reply to this post by Erlend Sveen

Hi, here is my personal opinion about CodingStyle:

If you do substantial modifications to a function, I prefer you don’t reformat it except:

-          to change tabs to spaces

-          to adopt a “common” style, for example if you see in this function “if ( n == 0 )” while the general style is “if (n == 0)”. I recognize that the term “common” means nothing at all :o)

 

In any cases, please resist to reformat anything else for your convenience because it is hard to see real modifications with diff.

 

Even I’m not sure to use Cortex-M7 one day, I’m quite impatient to see a new backend in TCC. Congrat Erlend

 

C

 

 

From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Erlend Sveen
Sent: Sunday, March 22, 2020 12:27
To: [hidden email]
Subject: [Tinycc-devel] Questions regarding ARM Thumb code generation

 

Hi all!

 

I have been trying to get a compiler running on a Cortex-M7. I've had success

with some of the GNU binutils (linker, assembler, objdump, ...), but getting

GCC to run seemed to be a bit too ambitious. I went looking around and found

TCC. Sadly it does not support thumb instructions, but I did find that someone

has attempted to get going with it:

 

  https://github.com/gfwilliams/tinycc

 

While it barely compiles an empty function, I decided to spend a couple of

weekends trying to understand it and figure out if I could get it working.

Those weekends have now turned into month(s). Using the tests in the

tests/tests2 directory, I'm having a success rate of about 88% (I'm ignoring

those that are intended to not compile). The ones that fail are 4 due to

floating point support, 1 because of array copying, 1 due to C library issues

and 1 due to an immediate being out of range (still working on these). Note that

I'm running the tests manually since I can't run the test system on my MCU

(yet), so take the numbers with a grain of salt. I've also been using an older

version of TCC (from the link above), so I'll have to migrate my changes and

run all the newer tests too.

 

While I'm still hacking away on the original arm-gen.c it is starting to look

rather serious. So I figured I should ask a few questions on the mailing list

to ensure that I'm on the right track and that my contributions are welcome.

 

 * Is anyone else working on something like this? I've searched the mailing

   list but could not find any.

 * The repository I found mentions a licensing issue. I've searched the

   mailing list and found that the author of the original ARM codegen does not

   want to re-license it. Personally, I don't mind leaving the license as is.

   There is no way I will be able to write the thumb code gen from scratch,

   so my code will be based on the ARM one and subject to the same issue. Do I

   need to worry about this? It would really suck if my code gets dropped due

   to relicensing in the future.

 * Generally speaking, information to new contributors seems to be a bit

   scarce. I'm guessing that I'll have to make a new target to the build system

   at the very least, and new files for the thumb code gen. Is there anything I

   should read up on before I attemt to do this?

 * Code style: It is of course best to follow the existing code, but if I

   contribute a new file, am I allowed to use my own style for it? I've read

   the CodingStyle text file but it does not say much on this.

 * If I do substantial modifications to a function, may I reformat it? I see

   that some functions have a mix of spaces and tab indentation, I'd love to

   make this consistent.

 * C99: I could not find anything about mixed code and declarations. Am I

   allowed to use this? I personally find this to be a really important

   feature, since it improves readability by a lot. It also helps avoiding

   uninitialized variables (RAII and all).

 

I will probably have more questions for later, but these are the most important

ones. If there are no major roadblocks I may even have a diff ready some time

in the next few months! Also if there is something special I should know

regarding adding a new codegen I'd love to know.

 

Regards,

Erlend Sveen


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Questions regarding ARM Thumb code generation

Erlend Sveen
In reply to this post by Daniel Glöckner-2
Thanks!

I am working on a copy of the arm-gen file, and not making any changes to
the original. However, while the modifications are substantial there are some
components that will probably remain mostly unchanged such as the register
allocation and parameter copying. I think it is best that I keep the license as
is for now and add a note or something, and not consider changing it until I
have something working that you can look at.

This may change if I find the time to figure out how these components work,
but I need to keep this project manageable with the limited time I have, so I
mostly focus on program correctness and keep the things I can. I am also
delaying float support for now, I hope this is okay.

While I personally prefer GPL style licenses I consider this to be a derivative
work, and I think it is not up to me to make these decisions, but the
contributors that came before me.

Regards,
Erlend


Fra: Tinycc-devel <tinycc-devel-bounces+erlend.sveen=[hidden email]> på vegne av Daniel Glöckner <[hidden email]>
Sendt: søndag 22. mars 2020 13:16
Til: [hidden email] <[hidden email]>
Emne: Re: [Tinycc-devel] Questions regarding ARM Thumb code generation
 
Hi,

On Sun, Mar 22, 2020 at 11:26:30AM +0000, Erlend Sveen wrote:
> * The repository I found mentions a licensing issue. I've searched the
>   mailing list and found that the author of the original ARM codegen does not
>   want to re-license it. Personally, I don't mind leaving the license as is.
>   There is no way I will be able to write the thumb code gen from scratch,
>   so my code will be based on the ARM one and subject to the same issue. Do I
>   need to worry about this? It would really suck if my code gets dropped due
>   to relicensing in the future.

since I am the one who does not want to relicense the ARM32 backend, I give
you and everyone else permission to use my ARM backend code as a template
for a backend for another instruction set as long as you release it as open
source software under the license found in the RELICENSING file in TinyCC
(or the LGPL). To me ARM Thumb is a different instruction set.

My intention is not to hinder development of TinyCC. What I want to prevent
is that TinyCC gets hidden in closed source products. The LGPL does allow
commercial use. People just have to read and follow the license.

Best regards,

  Daniel

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel