--- /dev/null
+*.o
+*.bin
+*.elf
+*.hex
\ No newline at end of file
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 *~
+++ /dev/null
-#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);
- }
-}
}
. = 0x1000;
.text : { *(.text) *(.text.*) *(.rodata) *(.rodata.*) }
- . = 0x1800;
+ . = ALIGN(0x80);
.data : { *(.data) *(.data.*) *(.got) *(.toc) }
. = ALIGN(0x80);
__bss_start = .;
--- /dev/null
+#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);
+ }
+}