+#endif
+
+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", i);
+
+ // 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", i);
+}
+
+static int
+emitIfNew(struct dbuf_s *oBuf, set **emitted, const char *fmt,
+ const char *name)
+{
+ int wasPresent = pic14_stringInSet(name, emitted, 1);
+
+ if (!wasPresent) {
+ dbuf_printf (oBuf, fmt, name);
+ } // if
+ return (!wasPresent);
+}