Example #1
0
static void
emitPseudoStack(struct dbuf_s *oBuf, struct dbuf_s *oBufExt)
{
    int shared, low, high, size, i;
    PIC_device *pic;

    /* also emit STK symbols
     * XXX: This is ugly and fails as soon as devices start to get
     *      differently sized sharebanks, since STK12 will be
     *      required by larger devices but only up to STK03 might
     *      be defined using smaller devices. */
    shared = pic14_getSharedStack(&low, &high, &size);
    if (!pic14_options.isLibrarySource)
    {
        pic = pic14_getPIC();

        dbuf_printf (oBuf, "\n");
        dbuf_printf (oBuf, "\tglobal PSAVE\n");
        dbuf_printf (oBuf, "\tglobal SSAVE\n");
        dbuf_printf (oBuf, "\tglobal WSAVE\n");
        for (i = size - 4; i >= 0; i--) {
            dbuf_printf (oBuf, "\tglobal STK%02d\n", i);
        } // for i
        dbuf_printf (oBuf, "\n");

        // 16f84 has no SHAREBANK (in linkerscript) but memory aliased in two
        // banks, sigh...
        if (1 || !shared) {
            // for single banked devices: use normal, "banked" RAM
            dbuf_printf (oBuf, "sharebank udata_ovr 0x%04X\n", low);
        } else {
            // for devices with at least two banks, require a sharebank section
            dbuf_printf (oBuf, "sharebank udata_shr\n");
        }
        dbuf_printf (oBuf, "PSAVE\tres 1\n");
        dbuf_printf (oBuf, "SSAVE\tres 1\n");
        dbuf_printf (oBuf, "WSAVE\tres 1\n"); // WSAVE *must* be in sharebank (IRQ handlers)
        /* fill rest of sharebank with stack STKxx .. STK00 */
        for (i = size - 4; i >= 0; i--) {
            dbuf_printf (oBuf, "STK%02d\tres 1\n", i);
        } // for i
    } else {
        /* declare STKxx as extern for all files
         * except the one containing main() */
        dbuf_printf (oBufExt, "\n");
        dbuf_printf (oBufExt, "\textern PSAVE\n");
        dbuf_printf (oBufExt, "\textern SSAVE\n");
        dbuf_printf (oBufExt, "\textern WSAVE\n");
        for (i = size - 4; i >= 0; i--) {
            char buffer[128];
            SNPRINTF(&buffer[0], 127, "STK%02d", i);
            dbuf_printf (oBufExt, "\textern %s\n", &buffer[0]);
            pic14_stringInSet(&buffer[0], &emitted, 1);
        } // for i
    }
    dbuf_printf (oBuf, "\n");
}
Example #2
0
static void
_pic14_do_link (void)
{
  /*
   * link command format:
   * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
   *
   */
#define LFRM  "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}"
  hTab *linkValues = NULL;
  char *lcmd;
  set *tSet = NULL;
  int ret;
  char * procName;

  shash_add (&linkValues, "linker", "gplink");

  /* LIBRARY SEARCH DIRS */
  mergeSets (&tSet, libPathsSet);
  mergeSets (&tSet, libDirsSet);
  shash_add (&linkValues, "incdirs", joinStrSet (processStrSet (tSet, "-I", NULL, shell_escape)));

  joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape));
  shash_add (&linkValues, "sysincdirs", joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape)));

  shash_add (&linkValues, "lflags", joinStrSet (linkOptionsSet));

  {
    char *s = shell_escape (fullDstFileName ? fullDstFileName : dstFileName);

    shash_add (&linkValues, "outfile", s);
    Safe_free (s);
  }

  if (fullSrcFileName)
    {
      struct dbuf_s dbuf;
      char *s;

      dbuf_init (&dbuf, 128);

      dbuf_append_str (&dbuf, fullDstFileName ? fullDstFileName : dstFileName);
      dbuf_append (&dbuf, ".o", 2);
      s = shell_escape (dbuf_c_str (&dbuf));
      dbuf_destroy (&dbuf);
      shash_add (&linkValues, "user_ofile", s);
      Safe_free (s);
    }

  shash_add (&linkValues, "ofiles", joinStrSet (processStrSet (relFilesSet, NULL, NULL, shell_escape)));

  /* LIBRARIES */
  procName = processor_base_name ();
  if (!procName)
    procName = "16f877";

  addSet (&libFilesSet, Safe_strdup (pic14_getPIC()->isEnhancedCore ?
          "libsdcce.lib" : "libsdcc.lib"));

    {
      struct dbuf_s dbuf;

      dbuf_init (&dbuf, 128);
      dbuf_append (&dbuf, "pic", sizeof ("pic") - 1);
      dbuf_append_str (&dbuf, procName);
      dbuf_append (&dbuf, ".lib", sizeof (".lib") - 1);
      addSet (&libFilesSet, dbuf_detach_c_str (&dbuf));
    }

  shash_add (&linkValues, "libs", joinStrSet (processStrSet (libFilesSet, NULL, NULL, shell_escape)));

  lcmd = msprintf(linkValues, LFRM);
  ret = sdcc_system (lcmd);
  Safe_free (lcmd);

  if (ret)
    exit (1);
}