Pawn on 20-bit MSP430

99 views
Skip to first unread message

Martin Samuelsson

unread,
Oct 14, 2015, 4:53:19 PM10/14/15
to Pawn Scripting Language
I'm trying to make something out of the Kreyos Meteor firmware ( https://github.com/KreyosMeteorite/KreyosFirmware-gcc-elf ), and it makes some use of Pawn. When I ported it over to TI's gcc for MSP430, I began getting warnings:

watch/host.c: In function ‘script_process’:
watch/host.c:211:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         amx_Push(amx, (cell)rparam);

with "(cell)rparam" indicated as the culprit, and rparam being a void *:

uint8_t script_process(uint8_t event, uint16_t lparam, void* rparam) {
...
    amx_Push(amx, (cell)rparam);
...
}

https://github.com/KreyosMeteorite/KreyosFirmware-gcc-elf/blob/master/Watch/watch/host.c#L211

The code specifies a cell size of 16, which obviously is smaller than the CPU address space of 20 bits. Should I go through the code and make sure it assumes a cell size of 32 bits to get rid of this warning, or are there other, perhaps better and more space efficient ways to do it?

Petteri Aimonen

unread,
Oct 15, 2015, 12:02:46 AM10/15/15
to pawns...@googlegroups.com
Hi,

> The code specifies a cell size of 16, which obviously is smaller than the
> CPU address space of 20 bits. Should I go through the code and make sure it
> assumes a cell size of 32 bits to get rid of this warning, or are there
> other, perhaps better and more space efficient ways to do it?

Defining PAWN_CELL_SIZE as 32 would be the easiest way to fix this.

If you don't need more than 64kB of address space for Pawn, you can also
use 16 bit cells and make sure the amx_Address macro gets defined in
amx.h.

--
Petteri

Thiadmer Riemersma

unread,
Oct 15, 2015, 4:45:15 AM10/15/15
to pawns...@googlegroups.com
Disclamier: I have no experience with the newer MSP430 controllers.So caveat, I may not known what I am talking about. That said...

You may get away with ignoring the warnings. Pawn requires addresses to data (other variables in its sandbox) to fit in a cell. Pawn also pushes the instruction addresses in its abstract machine to a stack, and each stack item is again a cell. So basically, an address must fit in a cell.

But... a Pawn script is typically loaded in RAM and runs from RAM. This is something that you have to check on the Kreyos Meteor firmware. If running from RAM, all addresses are actually in the first 64K, so on a 20-bit pointer, the top 4 bits are guaranteed to be zero.

Best of luck,
Thiadmer

--
You received this message because you are subscribed to the Google Groups "Pawn Scripting Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pawnscript+...@googlegroups.com.
To post to this group, send email to pawns...@googlegroups.com.
Visit this group at http://groups.google.com/group/pawnscript.
For more options, visit https://groups.google.com/d/optout.

Martin Samuelsson

unread,
Oct 16, 2015, 10:31:48 AM10/16/15
to Pawn Scripting Language
This is an MSP430F5438A, which should be even safer, with its 16K RAM. Good point there, that's probably why it manages to run. I'll poke around and make sure it stays in RAM.

Regards,
/Martin

Martin Samuelsson

unread,
Oct 16, 2015, 10:39:22 AM10/16/15
to Pawn Scripting Language
I did a quick test with PAWN_CELL_SIZE set to 32, and while it took care of some warnings, others popped up in their place.

amx_Address is defined, but as
 #define amx_Address(amx,addr) ((void)(amx),(cell*)(addr))
because __32BIT__ isn't. I'll do some more experimenting with this.

Thanks for your help,
/Martin
Reply all
Reply to author
Forward
0 new messages