[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luac to create 32bit Lua byte code
- From: bil til <biltil52@...>
- Date: Tue, 24 Oct 2023 16:57:31 +0200
> > On 30 Sep 2023, at 11:11, Roger Leigh <rleigh@codelibre.net> wrote:
> >
> > I know this is anecdotal, but just as a datapoint, I have successfully run Lua code byte-compiled on Windows on an STM32. The versions were matched, of course. There may have been subtle defects, but I didn’t encounter them while testing if there were.
... This week I could continue with this.
Luac for Win32 did not work... somehow this luac also produced 64bit Lua code.
But I then used the lua sourcecode to build my own Luac.Exe (using the
codeinfo.h I use also in my embedded STM32 application). And then it
worked nicely.
Hurray to this... .
Now I tried to keep the function code (lundump.c, function "loadCode")
directly in ROM, so that I would not need to spoil precious RAM code
for the Lua binary program.
When I did debugging there, I recobnized that in this function
"loadCode", I recognized that Lua just copies a longer chunk of bytes
from my Lua Byte Code location in ROM to a new TString object.
So far so fine... .
Just VERY unfortunately: The function start byte of a function in the
Lua byte code file is on an arbitrary BYTE location... so
unfortunately NOT 32bbit aligned, as for 32bit instructions would be
required to load them direclty from ROM without problems... .
(If I try to load 32bit instruction numbers from a String, and these
32bit Instructions do NOT start 32bit aligned, STM32 immediately will
throw a memory align exception... .).
(when Lua creates the TString object for function code, then by this
copy it is guaranteed "automatically", that the function code starts
aligned, as of course the TString memory block starts 32bit aligned,
this is job of my alloc function and no problem... just like this I
have this RAM waste, as I need to copy the complete program code from
ROM to RAM).
... to solve this 32bit ROM align problem I could use two approaches:
- modify the Lua source code such, that instructions are NOT loaded
as 32bit numbers... , but as 4 byte string data... this would work by
memcpy somehow... .
- modify the Luac created Lua byte code such, that the function code
IS aligned on 32bit against the file start... .
The first option sounds very challenging I am frightened? (as I
assume, Lua will read instructions from code at VERY many points?).
The second option would require to tweak luac.exe somehow, and insert
some sort of "NOP codes" in the lua byte code, so that the code of
each function is 32bit aligned against the file start. Is there such a
"Lua NOP code byte" available in Lua byte code? (NOP for "no
operation", that's the typical assembler command coding for such a
"fill byte" in assembler language...).
Anyone who can help here with these 2 questions?