check sc 1 and sc 2 too sc-test
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 9 Nov 2023 02:04:39 +0000 (18:04 -0800)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 9 Nov 2023 02:04:39 +0000 (18:04 -0800)
sc_test/.gitignore [new file with mode: 0644]
sc_test/Makefile
sc_test/hello_world.c [deleted file]
sc_test/powerpc.lds
sc_test/sc_test.c [new file with mode: 0644]

diff --git a/sc_test/.gitignore b/sc_test/.gitignore
new file mode 100644 (file)
index 0000000..5c1376c
--- /dev/null
@@ -0,0 +1,4 @@
+*.o
+*.bin
+*.elf
+*.hex
\ No newline at end of file
index 159cb86a24f454df00385b565b56d7e636063bec..7f5637a1731e7cdc5e9d99550f098d525e4e6d32 100644 (file)
@@ -13,23 +13,23 @@ CFLAGS = -Os -g -Wall -std=c99 -msoft-float -mno-string -mno-multiple -mno-vsx -
 ASFLAGS = $(CFLAGS)
 LDFLAGS = -T powerpc.lds
 
-all: hello_world.hex
+all: sc_test.hex
 
 console.o: ../lib/console.c
        $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
 
-hello_world.elf: hello_world.o head.o console.o
+sc_test.elf: sc_test.o head.o console.o
        $(LD) $(LDFLAGS) -o $@ $^
 
-hello_world.bin: hello_world.elf
+sc_test.bin: sc_test.elf
        $(OBJCOPY) -O binary $^ $@
 
-hello_world.hex: hello_world.bin
-       ../scripts/bin2hex.py $^ > hello_world.hex.tmp
-       mv -f hello_world.hex.tmp hello_world.hex
+sc_test.hex: sc_test.bin
+       ../scripts/bin2hex.py $^ > sc_test.hex.tmp
+       mv -f sc_test.hex.tmp sc_test.hex
 
 clean:
-       @rm -f *.o hello_world.elf hello_world.bin hello_world.hex
+       @rm -f *.o sc_test.elf sc_test.bin sc_test.hex
 distclean: clean
        rm -f *~
 
diff --git a/sc_test/hello_world.c b/sc_test/hello_world.c
deleted file mode 100644 (file)
index 6a92414..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "console.h"
-#include "io.h"
-#include "microwatt_soc.h"
-
-static char mw_logo1[] =
-"\n"
-"   .oOOo.     \n"
-" .\"      \". \n"
-" ;  .mw.  ;   Microwatt, it works.\n"
-"  . '  ' .    \n"
-"   \\ || /     HDL Git SHA1: ";
-
-static char mw_logo2[] =
-"\n"
-"    ;..;      \n"
-"    ;..;      \n"
-"    `ww'      \n\n";
-
-void write_hex(uint64_t v)
-{
-    puts("0x");
-    for(int i = 15; i >= 0; i--)
-    {
-        uint8_t digit = (v >> 4 * i) & 0xF;
-        if(digit >= 10)
-        {
-            putchar('A' + (digit - 10));
-        }
-        else
-        {
-            putchar('0' + digit);
-        }
-    }
-}
-
-void test_sc(uint64_t srr0, uint64_t srr1, uint64_t msr)
-{
-    puts("before sc:\n");
-    puts("SRR0 = ");
-    write_hex(srr0);
-    puts(" SRR1 = ");
-    write_hex(srr1);
-    puts(" MSR = ");
-    write_hex(msr);
-    puts("\nsc");
-    register uint64_t srr0_ __asm("r3");
-    register uint64_t srr1_ __asm("r4");
-    register uint64_t msr_ __asm("r5");
-    srr0_ = srr0;
-    srr1_ = srr1;
-    msr_ = msr;
-    __asm(
-        "mtsrr0 3\n\t"
-        "mtsrr1 4\n\t"
-        "mtmsrd 5\n\t"
-        "sc"
-        : "+r"(srr0_), "+r"(srr1_), "+r"(msr_));
-    srr0 = srr0_;
-    srr1 = srr1_;
-    msr = msr_;
-    puts("\nafter sc:\n");
-    puts("SRR0 = ");
-    write_hex(srr0);
-    puts(" SRR1 = ");
-    write_hex(srr1);
-    puts(" MSR = ");
-    write_hex(msr);
-    puts("\n");
-}
-
-int main(void)
-{
-       uint64_t gitinfo;
-       uint8_t c;
-        bool dirty;
-
-       console_init();
-
-        test_sc(0x12345678, 0x5678, 0x90000000783f2903ULL);
-        test_sc(0x12345678, 0x5678, 0x9000000000000003ULL);
-
-        puts(mw_logo1);
-
-        gitinfo = readq(SYSCON_BASE + SYS_REG_GIT_INFO);
-        dirty = gitinfo >> 63;
-       for (int i = 0; i < 14; i++) {
-               c = (gitinfo >> 52) & 0xf;
-               if (c >= 10)
-                        putchar(0x61 + c - 10); // a-f
-                else
-                        putchar(0x30 + c); // 0-9
-               gitinfo <<= 4;
-       }
-        if (dirty)
-                puts("-dirty");
-       puts(mw_logo2);
-
-       while (1) {
-               unsigned char c = getchar();
-               putchar(c);
-               if (c == 13) // if CR send LF
-                       putchar(10);
-       }
-}
index 1e218c7a431debd3cbd4f1f8bed6392ce288e882..4967a46feecf89a8648459edca6fa955bbf653d1 100644 (file)
@@ -7,7 +7,7 @@ SECTIONS
        }
        . = 0x1000;
        .text : { *(.text) *(.text.*) *(.rodata) *(.rodata.*) }
-       . = 0x1800;
+       . = ALIGN(0x80);
        .data : { *(.data) *(.data.*) *(.got) *(.toc) }
        . = ALIGN(0x80);
        __bss_start = .;
diff --git a/sc_test/sc_test.c b/sc_test/sc_test.c
new file mode 100644 (file)
index 0000000..e89f7f1
--- /dev/null
@@ -0,0 +1,92 @@
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "console.h"
+
+void write_hex(uint64_t v)
+{
+    puts("0x");
+    for(int i = 15; i >= 0; i--)
+    {
+        uint8_t digit = (v >> 4 * i) & 0xF;
+        if(digit >= 10)
+        {
+            putchar('A' + (digit - 10));
+        }
+        else
+        {
+            putchar('0' + digit);
+        }
+    }
+}
+
+typedef struct sc_io
+{
+    uint64_t srr0, srr1, msr;
+} sc_io;
+
+#define DO_SC(LEV)                                \
+    void do_sc##LEV(sc_io *io)                    \
+    {                                             \
+        register uint64_t srr0 __asm("r3");       \
+        register uint64_t srr1 __asm("r4");       \
+        register uint64_t msr __asm("r5");        \
+        srr0 = io->srr0;                          \
+        srr1 = io->srr1;                          \
+        msr = io->msr;                            \
+        __asm(                                    \
+            "mtsrr0 3\n\t"                        \
+            "mtsrr1 4\n\t"                        \
+            "mtmsrd 5\n\t"                        \
+            "sc " #LEV                            \
+            : "+r"(srr0), "+r"(srr1), "+r"(msr)); \
+        io->srr0 = srr0;                          \
+        io->srr1 = srr1;                          \
+        io->msr = msr;                            \
+    }
+
+DO_SC(0)
+DO_SC(1)
+DO_SC(2)
+
+static void (*const do_sc_fns[])(sc_io *) = {do_sc0, do_sc1, do_sc2};
+
+void test_sc(sc_io io, int LEV)
+{
+    puts("before sc:\n");
+    puts("SRR0 = ");
+    write_hex(io.srr0);
+    puts(" SRR1 = ");
+    write_hex(io.srr1);
+    puts(" MSR = ");
+    write_hex(io.msr);
+    puts("\nsc ");
+    putchar('0' + LEV);
+    do_sc_fns[LEV](&io);
+    puts("\nafter sc:\n");
+    puts("SRR0 = ");
+    write_hex(io.srr0);
+    puts(" SRR1 = ");
+    write_hex(io.srr1);
+    puts(" MSR = ");
+    write_hex(io.msr);
+    puts("\n");
+}
+
+int main(void)
+{
+    console_init();
+
+    test_sc((sc_io){0x12345678, 0x5678, 0x90000000783f2903ULL}, 0);
+    test_sc((sc_io){0x12345678, 0x5678, 0x9000000000000003ULL}, 0);
+    test_sc((sc_io){0x12345678, 0x5678, 0x9000000000000003ULL}, 1);
+    test_sc((sc_io){0x12345678, 0x5678, 0x9000000000000003ULL}, 2);
+
+    while(1)
+    {
+        unsigned char c = getchar();
+        putchar(c);
+        if(c == 13) // if CR send LF
+            putchar(10);
+    }
+}