gicking / STM8_headers

Device headers and examples for STM8 microcontrollers
MIT License
40 stars 10 forks source link

Pre-compiled examples? #11

Closed brainstorm closed 4 days ago

brainstorm commented 5 days ago

Would it be possible to have the examples pre-compiled for all SDCC/Cosmic/IAR (binaries and/or ihex)? I'm interested in how those compilers generate the assembly since I'm working on a STM8 reverse engineering project:

https://github.com/brainstorm/treadmill-re

In particular I'm interested in seeing different compiler's approaches to calling conventions, for instance.

/cc @trufae

gicking commented 5 days ago

Hi brainstorm,

when I started this project, I had access to Cosmic and IAR licenses from work. Unfortunately this is no longer the case. Nowadays I only use SDCC if/when I program STM8 - which has become pretty rare...

I understand that you want the binaries to analyze the parameter passing, stack handling, etc..? If this is the case, any binary+source should do, correct? For SDCC I please find the serial_printf binaries here. However, for Cosmic and IAR I'm at a loss due to lack of license. Sorry for the negative feedback!

Georg

PS: nice project :-) Actually I know someone who might be able to support you in reverse engineering. I'll send him a link to this issue. If he's interested, I'm sure he'll contact you.

brainstorm commented 4 days ago

Excellent, thank you so much!

Yes I do have SDCC binaries already (easy to compile locally), I just wanted to compare w/ Cosmic/IAR as you are pointing out. Thanks for pointing to somebody that can help too! I'm at brainstorm at nopcode dot org over email if that's more convenient for your someone.

prosper00 commented 4 days ago

you might be able to reach out to Philip Krause, he maintains a comparo of stm8 compilers here: http://www.colecovision.eu/stm8/

SDCC especially has been evolving a lot over the past few years. There's an active mailing list archived on sourceforge

basilhussain commented 4 days ago

In particular I'm interested in seeing different compiler's approaches to calling conventions, for instance.

The calling conventions of the various commercial compilers that support STM8 are actually documented in the SDCC manual, because recent versions of SDCC allow the calling convention to be specified for interoperability with pre-compiled code from other compilers like Raisonance, IAR, and Cosmic. See section 4.5.1 of the SDCC manual.

For convenience, here are excerpts of this information in the SDCC manual:

Raisonance: If the first parameter is 8 or 16 bits, it is passed in a or x. If the first parameter is 8 bits, and the second 16 bits, the second is passed in x. If the first parameter is 16 bits, and the second is 8 bits, the second is passed in a. All other parameters are passed on the stack. If the return value is 8 bits, it is passed in a. If it is 16 bits, it is passed in x. Raisonance passes larger return values in pseudoregisters, which is not supported by SDCC.

IAR: The first 8-bit parameter is passed in a, the first 16-bit parameter in x, the second 16-bit parameter in y. Further parameters of up to 32 bits are passed in pseudoregisters, which is not supported by SDCC. All other parameters are passed on the stack. If the return value is 8 bits, it is passed in a. If it is 16 bits, it is passed in x. IAR passes larger return values in pseudoregisters, which is not supported by SDCC.

Cosmic: If the first parameter is 8 or 16 bits, it is passed in a or x. If the return value is 8 bits, it is passed in a. If it is 16 bits, it is passed in x. Cosmic passes larger return values in pseudoregisters, which is not supported by SDCC. Even for the medium memory model, __cosmic functions use a 24-bit return address in their stack frame, and are called using callf.

I suspect the use of the mentioned "pseudoregisters" involves the 'zero-page', which takes advantage of 'short' addressing mode single-cycle instructions that can only address 0x0-0xFF (i.e. the first 256 bytes of RAM). But I've never looked into it, so don't quote me on that. 😄

gicking commented 4 days ago

you might be able to reach out to Philip Krause, he maintains a comparo of stm8 compilers here: http://www.colecovision.eu/stm8/

SDCC especially has been evolving a lot over the past few years. There's an active mailing list archived on sourceforge

That's a great idea! The contact given on http://www.colecovision.eu is philipp@colecovision.eu

gicking commented 4 days ago

... Thanks for pointing to somebody that can help too! I'm at brainstorm at nopcode dot org over email if that's more convenient for your someone.

Basil was the one I was referring to :-)