From 758af92799656991c5e5b8d8a72381fb5cd6170f Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 20 Aug 2019 18:59:56 +0200 Subject: Add embedded examples menu and resources. Signed-off-by: Pavel Pisa --- qtmips_gui/samples/cop0-test-ia.S | 74 +++++++++++++++++++++++ qtmips_gui/samples/simple-lw-sw-ia.S | 26 ++++++++ qtmips_gui/samples/template-os.S | 114 +++++++++++++++++++++++++++++++++++ qtmips_gui/samples/template.S | 109 +++++++++++++++++++++++++++++++++ 4 files changed, 323 insertions(+) create mode 100644 qtmips_gui/samples/cop0-test-ia.S create mode 100644 qtmips_gui/samples/simple-lw-sw-ia.S create mode 100644 qtmips_gui/samples/template-os.S create mode 100644 qtmips_gui/samples/template.S (limited to 'qtmips_gui/samples') diff --git a/qtmips_gui/samples/cop0-test-ia.S b/qtmips_gui/samples/cop0-test-ia.S new file mode 100644 index 0000000..3bfe586 --- /dev/null +++ b/qtmips_gui/samples/cop0-test-ia.S @@ -0,0 +1,74 @@ +.set SERIAL_PORT_BASE, 0xffffc000 + +.set SERP_RX_ST_REG_o, 0x00 +.set SERP_RX_ST_REG_READY_m, 0x1 +.set SERP_RX_ST_REG_IE_m, 0x2 + +.set SERP_RX_DATA_REG_o, 0x04 + +.set SERP_TX_ST_REG_o, 0x08 +.set SERP_TX_ST_REG_READY_m, 0x1 +.set SERP_TX_ST_REG_IE_m, 0x2 + +.set SERP_TX_DATA_REG_o, 0x0c + + +.globl _start +.set noat +.set noreorder +.ent _start + +.text + +_start: + addi $1, $0, 0x101 + addi $2, $0, 0x102 + synci 0($zero) + addi $3, $0, 0x103 + addi $4, $0, 0x104 + la $20, skip + mtc0 $20, $14, 0 // EPC + eret + addi $5, $0, 0x105 + addi $6, $0, 0x106 +skip: + addi $7, $0, 0x107 + addi $8, $0, 0x108 + mfc0 $9, $14, 0 // EPC + + break + mfc0 $10, $14, 0 // EPC + + la $20, irq_entry - 0x180 + mtc0 $20, $15, 1 // EBase + + li $21, SERIAL_PORT_BASE + li $20, SERP_RX_ST_REG_IE_m + sw $20, SERP_RX_ST_REG_o($21) + li $20, 0x00000801 + mtc0 $20, $12, 0 // Status + +loop: mfc0 $10, $14, 0 // EPC + beq $zero, $zero, loop + nop + + +irq_entry: + mfc0 $26, $13, 0 // Cause + andi $27, $26, 0x00000800 + bne $27, $0, rx_irq + nop + mfc0 $27, $12, 0 // Status + nor $26, $26, $0 + andi $26, $26, 0x0000ff00 + and $27, $27, $26 + mtc0 $27, $12, 0 // Status + eret + +rx_irq: + li $26, SERIAL_PORT_BASE + lw $27, SERP_RX_DATA_REG_o($26) + sw $27, SERP_TX_DATA_REG_o($26) + eret + +.end _start diff --git a/qtmips_gui/samples/simple-lw-sw-ia.S b/qtmips_gui/samples/simple-lw-sw-ia.S new file mode 100644 index 0000000..d2c3f2c --- /dev/null +++ b/qtmips_gui/samples/simple-lw-sw-ia.S @@ -0,0 +1,26 @@ +.globl _start +.set noat +.set noreorder + +.text + +_start: +loop: + // load the word from absolute address + lw $2, 0x2000($0) + // store the word to absolute address + sw $2, 0x2004($0) + + // stop execution wait for debugger/user + //break + // ensure that continuation does not + // interpret random data + beq $0, $0, loop + nop + +.data + +src_val: + .word 0x12345678 +dst_val: + .word 0 diff --git a/qtmips_gui/samples/template-os.S b/qtmips_gui/samples/template-os.S new file mode 100644 index 0000000..6c2264f --- /dev/null +++ b/qtmips_gui/samples/template-os.S @@ -0,0 +1,114 @@ +// Template file with defines of peripheral registers +// QtMips simulator https://github.com/cvut/QtMips/ +// developed by Karel Koci and Pavel Pisa. +// +// template.S - example file +// +// (C) 2019 by Pavel Pisa +// e-mail: pisa@cmp.felk.cvut.cz +// homepage: http://cmp.felk.cvut.cz/~pisa +// work: http://www.pikron.com/ +// license: public domain + +.globl _start +.globl __start +.set noreorder +.ent _start + +// Serial port/terminal registers +// There is mirror of this region at address 0xffff0000 +// to match QtSpim and Mars emulators + +.equ SERIAL_PORT_BASE, 0xffffc000 // base address of serial port region + +.equ SERP_RX_ST_REG, 0xffffc000 // Receiver status register +.equ SERP_RX_ST_REG_o, 0x0000 // Offset of RX_ST_REG +.equ SERP_RX_ST_REG_READY_m, 0x1 // Data byte is ready to be read +.equ SERP_RX_ST_REG_IE_m, 0x2 // Enable Rx ready interrupt + +.equ SERP_RX_DATA_REG, 0xffffc004 // Received data byte in 8 LSB bits +.equ SERP_RX_DATA_REG_o, 0x0004 // Offset of RX_DATA_REG + +.equ SERP_TX_ST_REG, 0xffffc008 // Transmitter status register +.equ SERP_TX_ST_REG_o, 0x0008 // Offset of TX_ST_REG +.equ SERP_TX_ST_REG_READY_m, 0x1 // Transmitter can accept next byte +.equ SERP_TX_ST_REG_IE_m, 0x2 // Enable Tx ready interrupt + +.equ SERP_TX_DATA_REG, 0xffffc00c // Write word to send 8 LSB bits to terminal +.equ SERP_TX_DATA_REG_o, 0x000c // Offset of TX_DATA_REG + + +// Memory mapped peripheral for dial knobs input, +// LED and RGB LEDs output designed to match +// MZ_APO education Zynq based board developed +// by Petr Porazil and Pavel Pisa at PiKRON.com company + +.equ SPILED_REG_BASE 0xffffc100 // base of SPILED port region + +.equ SPILED_REG_LED_LINE, 0xffffc104 // 32 bit word mapped as output +.equ SPILED_REG_LED_LINE_o, 0x0004 // Offset of the LED_LINE +.equ SPILED_REG_LED_RGB1, 0xffffc110 // RGB LED 1 color components +.equ SPILED_REG_LED_RGB1_o, 0x0010 // Offset of LED_RGB1 +.equ SPILED_REG_LED_RGB2, 0xffffc114 // RGB LED 2 color components +.equ SPILED_REG_LED_RGB2_o, 0x0014 // Offset of LED_RGB2 +.equ SPILED_REG_KNOBS_8BIT, 0xffffc124 // Three 8 bit knob values +.equ SPILED_REG_KNOBS_8BIT_o, 0x0024 // Offset of KNOBS_8BIT + +// The simple 16-bit per pixel (RGB565) frame-buffer +// display size is 480 x 320 pixel +// Pixel format RGB565 expect +// bits 11 .. 15 red component +// bits 5 .. 10 green component +// bits 0 .. 4 blue component +.equ LCD_FB_START, 0xffe00000 +.equ LCD_FB_END, 0xffe4afff + +// Mapping of interrupts +// Irq number Cause/Status Bit Source +// 2 / HW0 10 Serial port ready to accept character to Tx +// 3 / HW1 11 There is received character ready to be read +// 7 / HW5 15 Counter reached value in Compare register + + +// Linux kernel compatible system calls subset + +.equ __NR_exit, 4001 // void exit(int status) +.equ __NR_read, 4003 // ssize_t read(int fd, void *buf, size_t count) +.equ __NR_write, 4004 // ssize_t write(int fd, const void *buf, size_t count) +.equ __NR_close, 4006 // int close(int fd) +.equ __NR_open, 4005 // int open(const char *pathname, int flags, mode_t mode) +.equ __NR_brk, 4045 // void * brk(void *addr) +.equ __NR_truncate, 4092 // int ftruncate(int fd, off_t length) +.equ __NR_readv, 4145 // ssize_t readv(int fd, const struct iovec *iov, int iovcnt) +.equ __NR_writev, 4146 // ssize_t writev(int fd, const struct iovec *iov, int iovcnt) +.equ __NR_set_thread_area, 4283 // int set_thread_area(unsigned long addr) + +// Original MIPS start address after reset +.org 0x80020000 + +.text + +__start: +_start: + + addi $v0, $zero, __NR_write + addi $a0, $zero, 1 + la $a1, text_1 + addi $a2, $zero, text_1_e - text_1 + syscall + + addi $v0, $zero, __NR_exit + addi $a0, $zero, 0 + +final: break + beq $zero, $zero, final + nop + +.end _start + +.data + +data_1: .word 1, 2, 3, 4 + +text_1: .ascii "Hello word.\n" // store ASCII text, no termination +text_1_e: diff --git a/qtmips_gui/samples/template.S b/qtmips_gui/samples/template.S new file mode 100644 index 0000000..58de4a3 --- /dev/null +++ b/qtmips_gui/samples/template.S @@ -0,0 +1,109 @@ +// Template file with defines of peripheral registers +// QtMips simulator https://github.com/cvut/QtMips/ +// developed by Karel Koci and Pavel Pisa. +// +// template.S - example file +// +// (C) 2019 by Pavel Pisa +// e-mail: pisa@cmp.felk.cvut.cz +// homepage: http://cmp.felk.cvut.cz/~pisa +// work: http://www.pikron.com/ +// license: public domain + +.globl _start +.globl __start +.set noreorder +.ent _start + +// Serial port/terminal registers +// There is mirror of this region at address 0xffff0000 +// to match QtSpim and Mars emulators + +.equ SERIAL_PORT_BASE, 0xffffc000 // base address of serial port region + +.equ SERP_RX_ST_REG, 0xffffc000 // Receiver status register +.equ SERP_RX_ST_REG_o, 0x0000 // Offset of RX_ST_REG +.equ SERP_RX_ST_REG_READY_m, 0x1 // Data byte is ready to be read +.equ SERP_RX_ST_REG_IE_m, 0x2 // Enable Rx ready interrupt + +.equ SERP_RX_DATA_REG, 0xffffc004 // Received data byte in 8 LSB bits +.equ SERP_RX_DATA_REG_o, 0x0004 // Offset of RX_DATA_REG + +.equ SERP_TX_ST_REG, 0xffffc008 // Transmitter status register +.equ SERP_TX_ST_REG_o, 0x0008 // Offset of TX_ST_REG +.equ SERP_TX_ST_REG_READY_m, 0x1 // Transmitter can accept next byte +.equ SERP_TX_ST_REG_IE_m, 0x2 // Enable Tx ready interrupt + +.equ SERP_TX_DATA_REG, 0xffffc00c // Write word to send 8 LSB bits to terminal +.equ SERP_TX_DATA_REG_o, 0x000c // Offset of TX_DATA_REG + + +// Memory mapped peripheral for dial knobs input, +// LED and RGB LEDs output designed to match +// MZ_APO education Zynq based board developed +// by Petr Porazil and Pavel Pisa at PiKRON.com company + +.equ SPILED_REG_BASE 0xffffc100 // base of SPILED port region + +.equ SPILED_REG_LED_LINE, 0xffffc104 // 32 bit word mapped as output +.equ SPILED_REG_LED_LINE_o, 0x0004 // Offset of the LED_LINE +.equ SPILED_REG_LED_RGB1, 0xffffc110 // RGB LED 1 color components +.equ SPILED_REG_LED_RGB1_o, 0x0010 // Offset of LED_RGB1 +.equ SPILED_REG_LED_RGB2, 0xffffc114 // RGB LED 2 color components +.equ SPILED_REG_LED_RGB2_o, 0x0014 // Offset of LED_RGB2 +.equ SPILED_REG_KNOBS_8BIT, 0xffffc124 // Three 8 bit knob values +.equ SPILED_REG_KNOBS_8BIT_o, 0x0024 // Offset of KNOBS_8BIT + +// The simple 16-bit per pixel (RGB565) frame-buffer +// display size is 480 x 320 pixel +// Pixel format RGB565 expect +// bits 11 .. 15 red component +// bits 5 .. 10 green component +// bits 0 .. 4 blue component +.equ LCD_FB_START, 0xffe00000 +.equ LCD_FB_END, 0xffe4afff + +// Mapping of interrupts +// Irq number Cause/Status Bit Source +// 2 / HW0 10 Serial port ready to accept character to Tx +// 3 / HW1 11 There is received character ready to be read +// 7 / HW5 15 Counter reached value in Compare register + +// Original MIPS start address after reset +.org 0x80020000 + +.text + +__start: +_start: + +loop: la $a0, SERIAL_PORT_BASE // load base address of serial port + // it is pseodooperation lui $a0, 0xffff ; ori $a0, $a0, 0xc000 + // can be optimized as addi $a0, $zero, 0xffffc000-0x100000000 + // in this particular case + + la $a1, text_1 // load address of text + +next_char:lb $t1, 0($a1) // load one byte after another + beq $t1, $zero, end_char // is this the terminal zero byte + addi $a1, $a1, 1 // move pointer to next text byte +tx_busy: lw $t0, SERP_TX_ST_REG_o($a0) // read status of transmitter + andi $t0, $t0, SERP_TX_ST_REG_READY_m // mask ready bit + beq $t0, $zero, tx_busy // if not ready wait for ready condition + nop // fill branch instruction delay slot + sw $t1,SERP_TX_DATA_REG_o($a0) // write byte to Tx data register + beq $zero, $zero, next_char // unconditional branch to process next byte + nop // fill delay slot + +end_char: break // stop continuous execution + // request developer interaction + beq $zero, $zero, loop + nop // fill delay slot + +.end _start + +.data + +data_1: .word 1, 2, 3, 4 // example how to fill data words + +text_1: .asciz "Hello word.\n" // store zero terminated ASCII text -- cgit v1.2.3