08 February 2022, 14:38 | #1 |
Tinkerer
Join Date: Jan 2020
Location: Sweden
Posts: 104
|
VBCC - Relative pointer to string?
I'm trying to write this simple device in a fashion that it is position independent so it may be loaded into an expansion rom for example
I'm running into a problem where a couple of pointers to some strings end up requiring relocation which I can work around with some inline assembly but I'm wondering if there is a more correct way to do this? I'm a noob when it comes to programming especially C so I'm sorry if this is a really stupid question! I am using both the small code and small data options with vbcc. i.e the example code would be here where devname uses some inline assembly but devid doesn't - to illustrate the problem Code:
const char devname[] = "example.device"; const char devid[] = "example.device - 1.23 - (Feb 2022)"; struct testres *Init(__reg("d0") struct testres *me, __reg("a6") struct ExecBase *SysBase) { APTR PCRelDevName() = "\tlea _devname(PC),a1\n\tmove.l a1,d0"; struct CurrentBinding *cb = NULL; me->SysBase = SysBase; me->lib.lib_Node.ln_Name = PCRelDevName(); me->lib.lib_Node.ln_Type = NT_RESOURCE; me->lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED; me->lib.lib_Version = 69; me->lib.lib_Revision = 0; me->lib.lib_IdString = (APTR)devid; return me; } Code:
_Init movem.l l3,-(a7) move.l a6,a3 move.l d0,a2 move.l #0,a5 move.l a3,(34,a2) lea _devname(PC),a1 move.l a1,d0 move.l d0,(10,a2) move.b #8,(8,a2) move.b #6,(14,a2) move.w #69,(20,a2) move.w #0,(22,a2) move.l #_devid,(24,a2) move.l a2,d0 |
08 February 2022, 15:12 | #2 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
As you already noticed, the small-code mode doesn't really help you to generate position independant code. It just makes all function calls PC-relative.
There is no PIC option for the m68k backend yet (a few other backends have that), so there is also no real solution now. I doubt such an option will make it into the upcoming V0.9h release, but it certainly would be a good thing to have. A workaround to avoid assembler inlines could be to call a normal function with your constant string pointer, which writes it to the target structure. That makes sure vbccm68k generates a LEA (for register arguments) or PEA (for stack arguments), which is optimized to PC-relative by vasm. You can also add the -picoption to vasmm68k_mot in your config file, so any non-position-independant access is immediately reported by the assembler. |
09 February 2022, 08:34 | #3 |
Tinkerer
Join Date: Jan 2020
Location: Sweden
Posts: 104
|
Ok I'll do that then thanks for your help!
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBCC and pointer dereferencing | PR77 | Coders. C/C++ | 7 | 30 May 2019 20:29 |
Vbcc on Win: Flag <-o> needs string | guy lateur | Coders. C/C++ | 15 | 19 July 2017 20:31 |
Trying to have portable configuration, relative paths relative to C:\Public\... ? | Turrican | support.WinUAE | 3 | 24 June 2011 16:33 |
32bit PC-relative LEA ?? | Nut | Coders. General | 22 | 18 March 2010 10:56 |
Relative paths | Toni Wilen | request.UAE Wishlist | 0 | 16 August 2009 16:06 |
|
|