]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #414 from IrgendwerA8/SED_Fix
authorOliver Schmidt <ol.sc@web.de>
Thu, 30 Mar 2017 10:26:37 +0000 (12:26 +0200)
committerGitHub <noreply@github.com>
Thu, 30 Mar 2017 10:26:37 +0000 (12:26 +0200)
Fixed sim65 SED

12 files changed:
cfg/sim6502.cfg
cfg/sim65c02.cfg
doc/cc65.sgml
src/Makefile
src/cc65/compile.c
src/cc65/symentry.c
src/cc65/symentry.h
src/sim65/6502.c
test/err/bss-name-conflict.c [new file with mode: 0644]
test/val/Makefile
test/val/bss-name-decl.c [new file with mode: 0644]
test/val/bss-name.c [new file with mode: 0644]

index b4f7738f5866ad8ad0432c90b932e55e496ac219..530787489f6679580f409a6306e1771f1fb70a3f 100644 (file)
@@ -3,7 +3,7 @@ SYMBOLS {
     __STACKSIZE__: type = weak, value = $0800; # 2k stack
 }
 MEMORY {
-    ZP:     file = "",               start = $0000, size = $001A;
+    ZP:     file = "",               start = $0000, size = $001B;
     HEADER: file = %O,               start = $0000, size = $0001;
     MAIN:   file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
 }
index b4f7738f5866ad8ad0432c90b932e55e496ac219..530787489f6679580f409a6306e1771f1fb70a3f 100644 (file)
@@ -3,7 +3,7 @@ SYMBOLS {
     __STACKSIZE__: type = weak, value = $0800; # 2k stack
 }
 MEMORY {
-    ZP:     file = "",               start = $0000, size = $001A;
+    ZP:     file = "",               start = $0000, size = $001B;
     HEADER: file = %O,               start = $0000, size = $0001;
     MAIN:   file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
 }
index 6a08cc3c395d118da661c40e653853b5c6707262..2a0fa0260360cecb0a4f7b6b3ed1a33e1efc8eba 100644 (file)
@@ -4,7 +4,7 @@
 <title>cc65 Users Guide
 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
 <url url="mailto:gregdk@users.sf.net" name="Greg King">
-<date>2017-02-27
+<date>2017-03-21
 
 <abstract>
 cc65 is a C compiler for 6502 targets. It supports several 6502 based home
@@ -1276,7 +1276,7 @@ that function).
 As a shortcut, you can put the <tt/volatile/ qualifier in your <tt/asm/
 statements.  It will disable optimization for the functions in which those
 <tt/asm volatile/ statements sit.  The effect is the same as though you put
-</#pragma optimize(push, off)/ above those functions, and </#pragma
+<tt/#pragma optimize(push, off)/ above those functions, and <tt/#pragma
 optimize(pop)/ below those functions.
 
 The string literal may contain format specifiers from the following list. For
index edb6f5aa8a25db449d57ee3350bbed451cd25603..f4f29b949baac9735e92f8ca38c05149230d2f9e 100644 (file)
@@ -65,7 +65,7 @@ endif
 CFLAGS += -MMD -MP -O -I common \
           -Wall -Wextra -Wno-char-subscripts $(USER_CFLAGS) \
           -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) -DCL65_TGT=$(CL65_TGT) \
-          -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG)
+          -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG) \
           -DGIT_SHA=$(GIT_SHA)
 
 LDLIBS += -lm
index 48a5c29d35adca95c566a0adf9f490b041ffbab9..4425b6aad71cd3f52ab3732cd1cdac5ed86c47f1 100644 (file)
@@ -242,16 +242,24 @@ static void Parse (void)
                             Error ("Variable `%s' has unknown size", Decl.Ident);
                         }
                         Entry->Flags &= ~(SC_STORAGE | SC_DEF);
+                    } else {
+                        /* A global (including static) uninitialized variable
+                        ** is only a tentative definition. For example, this is valid:
+                        ** int i;
+                        ** int i;
+                        ** static int j;
+                        ** static int j = 42;
+                        ** Code for these will be generated in FinishCompile.
+                        ** For now, just save the BSS segment name
+                        ** (can be set with #pragma bss-name)
+                        */
+                        const char* bssName = GetSegName (SEG_BSS);
+                        if (Entry->V.BssName && strcmp (Entry->V.BssName, bssName) != 0) {
+                            Error ("Global variable `%s' has already been defined in `%s' segment",
+                                   Entry->Name, Entry->V.BssName);
+                        }
+                        Entry->V.BssName = xstrdup (bssName);
                     }
-
-                    /* A global (including static) uninitialized variable
-                    ** is only a tentative definition. For example, this is valid:
-                    ** int i;
-                    ** int i;
-                    ** static int j;
-                    ** static int j = 42;
-                    ** Code for these will be generated in FinishCompile.
-                    */
                 }
 
             }
@@ -418,6 +426,8 @@ void FinishCompile (void)
         } else if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) {
             /* Tentative definition of uninitialized global variable */
             g_usebss ();
+            SetSegName (SEG_BSS, Entry->V.BssName);
+            g_segname (SEG_BSS); /* TODO: skip if same as before */
             g_defgloblabel (Entry->Name);
             g_res (SizeOf (Entry->Type));
             /* Mark as defined, so that it will be exported not imported */
index 980ee27f2dab87e2c62fcf7f847a7ec5f12e842b..d6e68d1bbbdd291b51d175ba28a600add40acae9 100644 (file)
@@ -71,6 +71,7 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags)
     E->Type     = 0;
     E->Attr     = 0;
     E->AsmName  = 0;
+    E->V.BssName = 0;
     memcpy (E->Name, Name, Len+1);
 
     /* Return the new entry */
index 4fa84255b4b4d8d1e07349dba19c49dce4a9f403..ff136702f6cfd9849918988ed84aee204e6ec2d2 100644 (file)
@@ -153,6 +153,8 @@ struct SymEntry {
             struct LiteralPool* LitPool;  /* Literal pool for this function */
         } F;
 
+        /* Segment name for tentantive global definitions */
+        const char*             BssName;
     } V;
     char                       Name[1]; /* Name, dynamically allocated */
 };
index 87cef2db6acb423ddbb856922b8c033bb41075b8..81caff4da6c833c97d5c5cce83bb0295c80392d0 100644 (file)
@@ -472,7 +472,7 @@ static void OPC_65SC02_0C (void)
     unsigned Addr;
     unsigned char Val;
     Cycles = 6;
-    Addr = MemReadByte (Regs.PC+1);
+    Addr = MemReadWord (Regs.PC+1);
     Val = MemReadByte (Addr);
     SET_ZF ((Val & Regs.AC) == 0);
     MemWriteByte (Addr, (unsigned char) (Val | Regs.AC));    
@@ -606,7 +606,7 @@ static void OPC_65SC02_1C (void)
     unsigned Addr;
     unsigned char Val;
     Cycles = 6;
-    Addr = MemReadByte (Regs.PC+1);
+    Addr = MemReadWord (Regs.PC+1);
     Val = MemReadByte (Addr);
     SET_ZF ((Val & Regs.AC) == 0);
     MemWriteByte (Addr, (unsigned char) (Val & ~Regs.AC));    
diff --git a/test/err/bss-name-conflict.c b/test/err/bss-name-conflict.c
new file mode 100644 (file)
index 0000000..1d6cd50
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+  !!DESCRIPTION!! conflicting bss-name pragmas
+  !!ORIGIN!!      cc65 regression tests
+  !!LICENCE!!     Public Domain
+  !!AUTHOR!!      Piotr Fusik
+*/
+
+/*
+  see: https://github.com/cc65/cc65/issues/409
+*/
+
+char oam_off;
+#pragma bss-name (push,"ZEROPAGE")
+char oam_off;
+#pragma bss-name (pop)
+
+int main(void)
+{
+    return 0;
+}
index 1981b36fe3fef0c0c21297afd35bd744b971c05d..c7539c81b6d74a9cea52b02deebd3419d6117b17 100644 (file)
@@ -36,16 +36,9 @@ OPTIONS = g O Os Osi Osir Oi Oir Or
 .PHONY: all clean
 
 SOURCES := $(wildcard *.c)
-TESTS := $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
+TESTS  = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
 TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg))
 
-# FIXME: These tests fail when built with optimizations for the 65c02
-TESTS := $(filter-out $(WORKDIR)/compare7.O%.65c02.prg,$(TESTS))
-TESTS := $(filter-out $(WORKDIR)/compare8.O%.65c02.prg,$(TESTS))
-TESTS := $(filter-out $(WORKDIR)/compare9.O%.65c02.prg,$(TESTS))
-TESTS := $(filter-out $(WORKDIR)/compare10.O%.65c02.prg,$(TESTS))
-TESTS := $(filter-out $(WORKDIR)/or1.O%.65c02.prg,$(TESTS))
-
 all: $(TESTS)
 
 $(WORKDIR):
diff --git a/test/val/bss-name-decl.c b/test/val/bss-name-decl.c
new file mode 100644 (file)
index 0000000..9a53584
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+  !!DESCRIPTION!! bss-name pragma not affecting declarations
+  !!ORIGIN!!      cc65 regression tests
+  !!LICENCE!!     Public Domain
+  !!AUTHOR!!      Piotr Fusik
+*/
+
+/*
+  see: https://github.com/cc65/cc65/issues/409
+*/
+
+#pragma bss-name (push,"ZEROPAGE")
+
+char n; /* only a declaration because followed by definition */
+char n = 1; /* not BSS */
+
+#pragma bss-name (pop)
+
+int main(void)
+{
+    return (unsigned) &n >= 0x100 ? 0 : 1;
+}
diff --git a/test/val/bss-name.c b/test/val/bss-name.c
new file mode 100644 (file)
index 0000000..f0ad711
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+  !!DESCRIPTION!! bss-name pragma
+  !!ORIGIN!!      cc65 regression tests
+  !!LICENCE!!     Public Domain
+  !!AUTHOR!!      Piotr Fusik
+*/
+
+/*
+  see: https://github.com/cc65/cc65/issues/409
+*/
+
+#pragma bss-name (push,"ZEROPAGE")
+
+char zp_var;
+
+#pragma bss-name (pop)
+
+int main(void)
+{
+    return (unsigned) &zp_var < 0x100 ? 0 : 1;
+}