From f013d0b7c98ef0de999741936f0d8e71b40cb122 Mon Sep 17 00:00:00 2001 From: Pavel Pisa <pisa@cmp.felk.cvut.cz> Date: Tue, 5 May 2020 12:32:16 +0200 Subject: [PATCH] seminaries/qtmips/fb-simple: example to draw on QtMips LCD display. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz> --- seminaries/qtmips/fb-simple/.gitignore | 4 ++ seminaries/qtmips/fb-simple/Makefile | 71 +++++++++++++++++++++++++ seminaries/qtmips/fb-simple/crt0local.S | 69 ++++++++++++++++++++++++ seminaries/qtmips/fb-simple/fb-simple.c | 53 ++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 seminaries/qtmips/fb-simple/.gitignore create mode 100644 seminaries/qtmips/fb-simple/Makefile create mode 100644 seminaries/qtmips/fb-simple/crt0local.S create mode 100644 seminaries/qtmips/fb-simple/fb-simple.c diff --git a/seminaries/qtmips/fb-simple/.gitignore b/seminaries/qtmips/fb-simple/.gitignore new file mode 100644 index 0000000..4cc3a92 --- /dev/null +++ b/seminaries/qtmips/fb-simple/.gitignore @@ -0,0 +1,4 @@ +*.o +fb-simple +*~ + diff --git a/seminaries/qtmips/fb-simple/Makefile b/seminaries/qtmips/fb-simple/Makefile new file mode 100644 index 0000000..c54c639 --- /dev/null +++ b/seminaries/qtmips/fb-simple/Makefile @@ -0,0 +1,71 @@ +ARCH=mips-elf + +SOURCES = fb-simple.c crt0local.S +TARGET_EXE = fb-simple + +CC=$(ARCH)-gcc +CXX=$(ARCH)-g++ +AS=$(ARCH)-as +LD=$(ARCH)-ld +OBJCOPY=$(ARCH)-objcopy + +#ARCHFLAGS += -march=mips3 +ARCHFLAGS += -fno-lto +#ARCHFLAGS += -mno-shared + +CFLAGS += -ggdb -O3 -Wall +CXXFLAGS+= -ggdb -O3 -Wall +AFLAGS += -ggdb +LDFLAGS += -ggdb +LDFLAGS += -nostartfiles +LDFLAGS += -static + +CFLAGS += $(ARCHFLAGS) +CXXFLAGS+= $(ARCHFLAGS) +AFLAGS += $(ARCHFLAGS) +LDFLAGS += $(ARCHFLAGS) + +OBJECTS += $(filter %.o,$(SOURCES:%.c=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.cpp=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.S=%.o)) + +all : default + +.PHONY : default clean dep all + +%.o:%.S + $(CC) -D__ASSEMBLY__ $(AFLAGS) -c $< -o $@ + +%.o:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + +%.o:%.cpp + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< + +%.s:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ + +default : $(TARGET_EXE) + +$(TARGET_EXE) : $(OBJECTS) + $(CC) $(LDFLAGS) $^ -o $@ + +dep: depend + +depend: $(SOURCES) *.h + echo '# autogenerated dependencies' > depend +ifneq ($(filter %.c,$(SOURCES)),) + $(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M $(filter %.c,$(SOURCES)) \ + >> depend +endif +ifneq ($(filter %.cpp,$(SOURCES)),) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -w -E -M $(filter %.cpp,$(SOURCES)) \ + >> depend +endif + +clean: + rm -f *.o *.a $(OBJECTS) $(TARGET_EXE) depend + +#mips-elf-objdump --source -M no-aliases,reg-names=numeric exam1-asm + +-include depend diff --git a/seminaries/qtmips/fb-simple/crt0local.S b/seminaries/qtmips/fb-simple/crt0local.S new file mode 100644 index 0000000..0565712 --- /dev/null +++ b/seminaries/qtmips/fb-simple/crt0local.S @@ -0,0 +1,69 @@ +/* minimal replacement of crt0.o provided by C library */ + +#define zero $0 +#define AT $1 +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 + +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define t5 $13 +#define t6 $14 +#define t7 $15 +#define t8 $24 +#define t9 $25 +#define k0 $26 +#define k1 $27 + +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 + +#define gp $28 +#define sp $29 +#define fp $30 +#define ra $31 + +.globl main +.globl __start +.globl _start +.set noat +.set noreorder +.ent __start + +.text + +__start: +_start: + bal next + nop +next: .set noreorder + .cpload $31 + .set reorder + + addi a0, zero, 0 + addi a1, zero, 0 + jal main +quit: + addi a0, zero, 0 + addi v0, zero, 4001 /* SYS_exit */ + + syscall + +loop: break + beq zero, zero, loop + nop + +.end __start diff --git a/seminaries/qtmips/fb-simple/fb-simple.c b/seminaries/qtmips/fb-simple/fb-simple.c new file mode 100644 index 0000000..02c0ee0 --- /dev/null +++ b/seminaries/qtmips/fb-simple/fb-simple.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdint.h> + +int main(void) +{ + + volatile uint16_t *fb = (volatile uint16_t *)0xffe00000; + int x, y, i; + int width = 480; + int height = 320; + + for (i = 0; i < width; i++) { + x = i; + y = 0; + fb[y * width + x] = 0xf800; + y = height - 1; + fb[y * width + x] = 0xf800; + } + + for (i = 1; i < height -1; i++) { + x = 0; + y = i; + fb[y * width + x] = 0xf800; + x = width - 1; + fb[y * width + x] = 0xf800; + } + + + while (1) { + for (y = 1; y < height - 1; y++) { + for (i = 0; i < 200; i++) { + x = (y & 0xff) + i; + fb[y * width + x] = 0xffff; + } + for (i = 0; i < 10; i++) { + x = (y & 0xff) + i + 200; + fb[y * width + x] = 0xf800; + } + for (i = 0; i < 10; i++) { + x = (y & 0xff) + i + 210; + fb[y * width + x] = 0x07e0; + } + for (i = 0; i < 10; i++) { + x = (y & 0xff) + i + 220; + fb[y * width + x] = 0x001f; + } + } + // no reorder or combine memory accesses over this sequesntial point + //__asm__ __volatile__ ("" : : : "memory"); + __asm__ __volatile__ ("break\n" : : : "memory"); + } + return 0; +} -- GitLab