View Single Post
Old 01 May 2019, 12:17   #13
bebbo
botcher

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 439
To get back to that: In my opinion, the simplest and most convenient way to get a tiny executable is the following:
  • use -fbaserel
  • use library auto opening
  • use an own simple startup code
  • optional switch to the standard startup code if your project grows...

The startup code
Code:
#include <proto/exec.h>

extern int main(void);
extern void __initlibraries();
extern void __exitlibraries();

APTR __sp;
register APTR __stkptr __asm("sp");
struct ExecBase * SysBase;

__entrypoint int __startup(void) {
  asm("lea ___a4_init,a4");
  __sp = __stkptr;
  SysBase = (*((struct ExecBase **) 4));
  __initlibraries();
  	
  return main();
}

static __attribute__((noinline)) void ___exit(int rc __asm("d0")) {
  __stkptr = __sp;
}
void exit(int rc) {
  __exitlibraries();
  ___exit(rc);
}
and the real program:
Code:
#include <proto/dos.h>
#include <string.h>

extern void exit(int);

BPTR   Stdout;
int N = 100;

STATIC const ULONG tricky=0x16c04e75; /* move.b d0,(a3)+ ; rts */
VOID myprintf(char *fmt,...) {
  unsigned char buf[256];
  STRPTR *arg = (STRPTR *)(&fmt+1);
  RawDoFmt((STRPTR) fmt, arg, (void (*)())&tricky, buf);
  Write(Stdout, buf, strlen((char *)buf));
}

void main() {
  Stdout = Output();

  float x = 1.623 * (float) N;
  myprintf("Just a hello world. if you cast x to integer is: %ld\n", (int)x);

  exit(0);
}
Use
Code:
CFLAGS=-Os -noixemul -fomit-frame-pointer -fbaserel -msmall-code
LDFLAGS=-nostartfiles  -noixemul -fbaserel
plus specify startup.o as first file to the linker.
Code:
m68k-amigaos-gcc -nostartfiles -s -noixemul -fbaserel -o nshello startup.o nshello.o
?
bebbo is offline  
 
Page generated in 0.04190 seconds with 11 queries