cpuinfo: first cut at 6502 series info
authorAlan Cox <alan@linux.intel.com>
Fri, 31 Aug 2018 20:21:50 +0000 (21:21 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 31 Aug 2018 20:21:50 +0000 (21:21 +0100)
Applications/util/Makefile.6502
Applications/util/cpuinfo-6502.s [new file with mode: 0644]
Applications/util/cpuinfo.c

index fe5acca..4047d58 100644 (file)
@@ -1,10 +1,10 @@
 PLATFORM = 6502
 CC = cl65
-ASM = ca65
+AS = ca65
 LINKER = cl65
 CFLAGS = -t none -O -D__STDC__ -c -O -I../../Library/include -I../../Library/include/6502
 LINKER_OPT = -L../../Library/libs -C ../../Library/libs/ld65-$(TARGET).cfg
-ASM_OPT = -o
+AS_OPT = -o
 CRT0 = ../../Library/libs/crt0_6502.o
 CRT0NS = ../../Library/libs/crt0nostdio_6502.o
 
@@ -112,18 +112,22 @@ SRCTC = tget.c \
         tchelp.c \
        marksman.c
 
+SRCOTHER = cpuinfo.c \
+          cpuinfo-6502.s
+
 SKIPPED =
 
 
 OBJS = $(SRCS:.c=.o)
 OBJSNS = $(SRCSNS:.c=.o)
 OBJTC = $(SRCTC:.c=.o)
+OBJOTHER = $(SRCOTHER:.c=.o)
 
 APPS = $(OBJS:.o=)
 APPSNS = $(OBJSNS:.o=)
 APPTC = $(OBJTC:.o=)
 
-all: $(APPS) $(APPSNS) $(APPTC) size.report
+all: cpuinfo $(APPS) $(APPSNS) $(APPTC) size.report
 
 $(APPS): %: %.o
        $(LINKER) -o $@ $(LINKER_OPT) $(CRT0) $^ c6502.lib -m $@.map
@@ -134,6 +138,9 @@ $(APPSNS): %: %.o
 $(APPTC): %: %.o
        $(LINKER) -o $@ $(LINKER_OPT) $(CRT0) $^ termcap6502.lib c6502.lib
 
+cpuinfo: cpuinfo.o cpuinfo-6502.o
+       $(LINKER) -o $@ $(LINKER_OPT) $(CRT0) $^ c6502.lib -m $@.map
+
 size.report: $(APPS) $(APPSNS) $(APPTC)
        ls -l $^ > $@
 
diff --git a/Applications/util/cpuinfo-6502.s b/Applications/util/cpuinfo-6502.s
new file mode 100644 (file)
index 0000000..e10351a
--- /dev/null
@@ -0,0 +1,34 @@
+       .include "zeropage.inc"
+
+       .P816
+       .I8
+       .A8
+
+.export _cpu_identify
+.export _cpu_bcdtest
+.export _cpu_rortest
+
+_cpu_identify:
+       lda #0
+       sta tmp1
+       inc
+       cmp #1
+       bmi nmos
+       xba
+       dec
+       xba
+       inc
+nmos:  rts
+
+_cpu_rortest:
+       lda #$01
+       ror a
+       rts
+
+_cpu_bcdtest:
+       sed
+       lda #$09
+       clc
+       adc #$01
+       cld
+       rts
index af5fbe7..d1867d1 100644 (file)
@@ -127,7 +127,6 @@ set_id:
 static const int cpu_vsize = 16;
 static const int cpu_psize = 16;
 static const int cpu_step = -1;
-static const int cpu_mhz = 0;
 static uint8_t cpu_vendor, cpu_id;
 static int cpu_cache = 0;
 static const char cpu_fpu[] = "no";
@@ -193,6 +192,55 @@ static void cpu_ident(void)
         cpu_bugs = "iff";
 }
 
+#elif defined(__CC65__)
+
+extern uint8_t cpu_identify(void);
+extern uint8_t cpu_bcdtest(void);
+extern uint8_t cpu_rortest(void);
+
+static uint8_t cpu_vendor;
+static uint8_t cpu_id;
+static const char *vendor_name[] = { "Unknown", "WDC", "Rockwell/WDC" };
+static const char *cpu_name[3] = { "6502", "65C02", "65C816" };
+static const int8_t cpu_step = -1;
+static const int8_t cpu_MHz = 0;
+static const uint8_t cpu_cache = 0;
+static const char cpu_fpu[]="no";
+static char *cpu_bugs = "";
+static char *cpu_flags = "";
+static const uint8_t cpu_vsize = 16;
+static uint8_t cpu_psize = 16;
+static const char *cpu_pm = NULL;
+
+static void cpu_ident(void)
+{
+    /* NMOS, CMOS or 65C816 ? */
+    cpu_id = cpu_identify();
+    switch(cpu_id) {
+    case 0:
+        if (cpu_rortest() == 0x02)
+            cpu_bugs = "brk ror jmpff invread rmw";
+        else
+            cpu_bugs = "brk jmpff invread rmw";
+        /* Check if BCD mode works - 0A v 10 */
+        /* 2A03: Just in case anyone ever ports Fuzix to a NES */
+        if (cpu_bcdtest() != 0x10)
+            cpu_bugs = "brk jmpff invread rmw nobcd";
+        cpu_flags = "nmos";
+        break;
+    case 1:
+        /* Q : How to safely check for rockwell bit ops ? */
+        /* Could also check here for HuC6820, Renesas 740 I guess ? */
+        cpu_flags = "bcd cmos";
+        break;
+    case 2:
+        cpu_vendor = 1;
+        cpu_flags = "bcd cmos ai16";
+        cpu_psize = 24;
+        break;
+    }
+}
+
 #else
 #error "unsupported CPU"
 #endif
@@ -206,7 +254,7 @@ static void do_identify(void)
     if (cpu_step != -1)
         printf("%-16s: %d\n", "stepping", cpu_step);
     if (cpu_MHz != 0)
-        printf("%-16s: %d\n", "cpu MHz", cpu_mhz);
+        printf("%-16s: %d\n", "cpu MHz", cpu_MHz);
     if (cpu_cache != 0)
         printf("%-16s: %d bytes\n", "cache size", cpu_cache);
     printf("%-16s: %s\n", "fpu", cpu_fpu);
@@ -217,7 +265,8 @@ static void do_identify(void)
     /* TODO bogomips */
     printf("%-16s: %d bits physical, %d bits virtual\n", "address sizes",
         cpu_psize, cpu_vsize);
-    printf("%-16s: %s\n", "power management", cpu_pm);
+    if (cpu_pm)
+        printf("%-16s: %s\n", "power management", cpu_pm);
 }
 
 static void usage(void)