ericb59 / Fusion-C-v1.2

MSX C Library for SDCC compiler
Other
71 stars 7 forks source link

crt0_msxdos_advanced.rel does not initialise static variables #7

Closed S0urceror closed 3 years ago

S0urceror commented 3 years ago

Noticed today something strange. When I compile my code with the supplied .rel my static variables don't initialise. When I compile the rel with the .s file all is well. My guess is that the .rel in your include folder is old and based on the initial version of Konamiman.

My code to check things:

#include "stdio.h"
#include "stdint.h"
#include "string.h"

uint8_t query[255];

void dosomething ()
{
  static unsigned char endquery[] = {0,0,1,0,1};  
  memcpy(query, endquery, 5);
}

/*---------------------------------------------------------------------------*/
int main(char *argv[], int argc)
{
  // check arguments
  if (argc==0)
    printf ("No arguments\r\n");
  else
    printf ("Arguments\r\n");

  dosomething ();
  printf ("%d,%d,%d,%d,%d",query[0],query[1],query[2],query[3],query[4]);
  return 0;
}

With the wrong crt0 it displays 255,255,255,255,255. With the right one it displays: 0,0,1,0,1

I patched the original Konamiman version by doing this:

        ;.area   _GSINIT      WAS HERE MOVED DOWN TO gsinext
gsinit::
        ld  bc,#l__INITIALIZER
        ld  a,b
        or  a,c
        jp  z,gsinext
        ld  de,#s__INITIALIZED
        ld  hl,#s__INITIALIZER
        ldir
gsinext:
        .area   _GSINIT
        .area   _GSFINAL

Problem was that the application calls gsinit at start. When area _GSINIT is before that it will be skipped. I moved it to gsinext. The crt0_msxdos_advanced.s of FusionLib when compiled also gives a good result. Only it does not include code for INITIALIZER. Don't know if this is still necessary though.

ericb59 commented 3 years ago

Hello,

Yes you are right the CRT0_msxdos_advanced was not updated with latests modifications. I've just made an update the .rel and the .s files

Thanks for reporting this issue :-)