Author Topic: Starting compiler plugin for gcc m6811 (Freescale hc12 family)  (Read 7937 times)

Offline LouisBertrand

  • Single posting newcomer
  • *
  • Posts: 6
Hello,

I am starting a  gcc compiler plugin for the Freescale m6811/m68hc11/hc12/hcs12 (CPU12 arch). It was ported a while ago by Stephane Carrez based on Gcc 3.3.6, Gdb 6.4, Binutils 2.15, Newlib 1.12.0.
http://www.gnu-m68hc11.org/wiki/index.php/Main_Page

So far, I have used the examples of GNUAVR and GNUARM to create my own compilerGNUm6811.cpp and .h files, and added them into src/plugins/compilergcc. I also added my compiler to compilergcc.cpp.

I am using a slightly older nightly 7932 to build. I am up to date on the SVN repository, currently at 8201.

I am running into trouble building from source since I made my changes. I will post separately with details.

Any help is appreciated. Thanks
 --Louis


Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Starting compiler plugin for gcc m6811 (Freescale hc12 family)
« Reply #1 on: June 01, 2012, 06:56:42 am »
Nice, just go ahead!!!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline LouisBertrand

  • Single posting newcomer
  • *
  • Posts: 6
Re: Starting compiler plugin for gcc m6811 (Freescale hc12 family)
« Reply #2 on: July 05, 2012, 10:28:10 pm »
[Edited to make my question clearer - HTH  :) ]

Hi,

I started on the m6811 gcc compiler and created new files in plugins\compilergcc and edited compilergcc.h accordingly, created a little wizard script. Amazingly enough, it builds and runs! I can start a project but I run into problems with the options.

What I am trying to do is make sure that the option -mshort (16 bit int) is selected by default when I select a particular architecture in the project wizard (new file: <C::B>\src\plugins\scriptedwizard\resources\m6811\wizard.script). Initially, I had it in the script as well as in compiler options and the "-mshort" appeared twice in the gcc command line.

In void CompilerGNUm6811::Reset() , for the defaults, I have option -mshort (16 bit int by default):
Code
    m_Options.AddOption(_("Type int is 16 bits wide, like short int"), _T("-mshort"), category);

How do I get the option to come up checked by default in my project, in the Project > Build Options > Compiler settings?

Thanks
 --Louis


« Last Edit: July 08, 2012, 03:54:41 am by LouisBertrand »

Offline LouisBertrand

  • Single posting newcomer
  • *
  • Posts: 6
Re: Starting compiler plugin for gcc m6811 (Freescale hc12 family)
« Reply #3 on: July 08, 2012, 06:49:49 pm »
[Edit to add bug ID]

Hi again,

I just checked the behaviour of the GNU AVR compiler plugin and project script. It seems it's the same as what I have observed in my m6811 plugin so far.
  • Start a project and pick a CPU in the project wizard. I chose ATmega16 [-mmcu=atmega16].
  • In the project, go to Project > Build Options... > Compiler and, in the Compiler settings / Compiler flags, select the AVR CPU specific options. You will see that ATmega16 [-mmcu=atmega16] is NOT checked.
Furthermore, if you check a different MCU, for example ATmega32 [-mmcu=atmega32], the ATmega16 option stays even though it is not shown.

The resulting .CBP file looks like this:
Build options:
Code
			<Target title="Debug">
<Option output="bin\Debug\blahblahavr.elf" prefix_auto="1" extension_auto="0" />
<Option working_dir="" />
<Option object_output="obj\Debug\" />
<Option type="5" />
<Option compiler="avrgcc" />
<Compiler>
<Add option="-mmcu=atmega16" />
<Add option="-g" />
</Compiler>
</Target>
Compiler options:
Code
		<Compiler>
<Add option="-mmcu=atmega32" />
<Add option="-Wall" />
<Add option="-DF_CPU=16000000UL" />
</Compiler>
Linker options:
Code
		<Linker>
<Add option="-mmcu=atmega16" />
<Add option="-Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map,--cref" />
</Linker>

And the gcc command line uses both CPU settings:
Code
avr-gcc.exe -mmcu=atmega32 -mmcu=atmega16 -Wall -DF_CPU=16000000UL  -Os     -c main.c -o obj\Release\main.o

What's even more confusing is that if you close and re-open the project, the build options seem to be ignored (atmega16) and only the compiler options are used (atmega32 comes up checked, and the command line uses atmega32 only).

Being able to unknowingly set conflicting CPU types seems a bit dangerous to me. I created bug report 018659 (Conflicting compiler options for CPU type) against application::interface for this.

Thanks
 --Louis
« Last Edit: July 08, 2012, 07:30:33 pm by LouisBertrand »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Starting compiler plugin for gcc m6811 (Freescale hc12 family)
« Reply #4 on: July 16, 2012, 03:29:18 pm »
Afaik only the options designated to compilers in the 'common_functions.script' under the folder 'src\plugins\scriptedwizard\resources' get checked when added to the project by the wizard. Others are not. At least that's what I observed when modifying the mcs51 wizard. Although they are not checked, they are added as command line options. Hope this helps...