From 5c5456ef20448a09f661bfe70420f7d3f683a8dc Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 8 Nov 2023 18:04:39 -0800 Subject: [PATCH] check sc 1 and sc 2 too --- sc_test/.gitignore | 4 ++ sc_test/Makefile | 14 +++--- sc_test/hello_world.c | 107 ------------------------------------------ sc_test/powerpc.lds | 2 +- sc_test/sc_test.c | 92 ++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 115 deletions(-) create mode 100644 sc_test/.gitignore delete mode 100644 sc_test/hello_world.c create mode 100644 sc_test/sc_test.c diff --git a/sc_test/.gitignore b/sc_test/.gitignore new file mode 100644 index 0000000..5c1376c --- /dev/null +++ b/sc_test/.gitignore @@ -0,0 +1,4 @@ +*.o +*.bin +*.elf +*.hex \ No newline at end of file diff --git a/sc_test/Makefile b/sc_test/Makefile index 159cb86..7f5637a 100644 --- a/sc_test/Makefile +++ b/sc_test/Makefile @@ -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 index 6a92414..0000000 --- a/sc_test/hello_world.c +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include - -#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); - } -} diff --git a/sc_test/powerpc.lds b/sc_test/powerpc.lds index 1e218c7..4967a46 100644 --- a/sc_test/powerpc.lds +++ b/sc_test/powerpc.lds @@ -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 index 0000000..e89f7f1 --- /dev/null +++ b/sc_test/sc_test.c @@ -0,0 +1,92 @@ +#include +#include + +#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); + } +} -- 2.30.2