From 3d2058b6cd9216f3e1dcb4b2374c62500678eab7 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 25 Jul 2020 11:50:04 +0300 Subject: [PATCH 1/1] first commit: hello world --- .gitignore | 6 +++ Makefile | 31 +++++++++++++ README | 4 ++ o2.ld | 28 ++++++++++++ regdefs.h | 43 ++++++++++++++++++ test.S | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README create mode 100644 o2.ld create mode 100644 regdefs.h create mode 100644 test.S diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a14c92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.d +*.swp +*.elf +*.ecoff +disasm diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..811fe64 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +obj = test.o +elf = test.elf +bin = test.ecoff + +TC = mips-none-elf- +CC = $(TC)gcc +AS = $(TC)as +LD = $(TC)ld + +ASFLAGS = -mips3 -mabi=32 -mno-abicalls -G 0 -fno-pic +LDFLAGS = -T o2.ld + +$(bin): $(elf) + wreckoff $< $@ + +$(elf): $(obj) + $(LD) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(elf) $(bin) + +.PHONY: install +install: $(elf) + cp $(elf) $(bin) /srv/tftp/ + +#disasm: $(bin) +# mips-ecoff-objdump -D $< >$@ +# +disasm: $(elf) + $(TC)objdump -D $< >$@ diff --git a/README b/README new file mode 100644 index 0000000..6a91b7a --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +To run: + - on boot enter maintenance mode + - go to the command monitor + - type: bootp():test.elf diff --git a/o2.ld b/o2.ld new file mode 100644 index 0000000..6e3256f --- /dev/null +++ b/o2.ld @@ -0,0 +1,28 @@ +OUTPUT_FORMAT("elf32-bigmips") +OUTPUT_ARCH(mips) +ENTRY(_start) + +SECTIONS { + . = 0x81404000; + + .text : { + * (.text); + * (.rel.text); + } + + .rodata ALIGN(4): { + * (.rodata); + } + + .data ALIGN(4): { + * (.data); + } + + .bss ALIGN(4): { + _bss_start = .; + * (.bss); + . = ALIGN(4); + _bss_end = .; + } + _bss_size = SIZEOF(.bss); +} diff --git a/regdefs.h b/regdefs.h new file mode 100644 index 0000000..cc85cb7 --- /dev/null +++ b/regdefs.h @@ -0,0 +1,43 @@ +#ifndef REGDEFS_H_ +#define REGDEFS_H_ + +#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 ta0 $12 +#define t5 $13 +#define ta1 $13 +#define t6 $14 +#define ta2 $14 +#define t7 $15 +#define ta3 $15 +#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 t8 $24 +#define t9 $25 +#define jp $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define fp $30 +#define s8 $30 +#define ra $31 + +#endif diff --git a/test.S b/test.S new file mode 100644 index 0000000..e1d85a3 --- /dev/null +++ b/test.S @@ -0,0 +1,147 @@ +#include "regdefs.h" + + .set noreorder + .text + + .equ SPB_FWVEC_ADDR, 0x80001020 + + .equ FW_HALT_OFFS, 0x0c + .equ FW_RST_INTERACT_OFFS, 0x1c + .equ FW_WRITE_OFFS, 0x6c + + .globl _start +_start: + jal print_pc + nop + + li a0, 0xbaadf00d + jal print_hex + nop + la t0, buffer + li t1, '\n' + sb t1, 0(t0) + sb zero, 1(t0) + la a0, buffer + jal printstr + nop + + + la a0, hellostr + jal printstr + nop + la a0, foobar + jal printstr + nop +0: b 0b + nop + +print_pc: + addiu sp, sp, -20 + sw ra, 16(sp) + + la a0, buffer + li t1, 'P' + sb t1, 0(a0) + li t1, 'C' + sb t1, 1(a0) + li t1, ':' + sb t1, 2(a0) + sb zero, 3(a0) + jal printstr + nop + + lw a0, 16(sp) + jal print_hex + addiu a0, a0, -8 # bd: address of the jal instruction to arg0 + + la t0, buffer + li t1, '\n' + sb t1, 0(t0) + sb zero, 1(t0) + la a0, buffer + jal printstr + nop + + lw ra, 16(sp) + jr ra + addiu sp, sp, 20 # bd + + +print_hex: + addiu sp, sp, -20 + sw ra, 16(sp) + + la t0, buffer + li t3, 8 # 8 nibbles to format +.Ltop: + addiu t3, t3, -1 + sll t1, t3, 2 + srl t1, a0, t1 # shift to low nibble + andi t1, t1, 0xf # and mask off everything above + li t2, 9 + bgt t1, t2, .Lover9 + nop + b .Lstore + addiu t1, t1, '0' # bd +.Lover9: + addiu t1, t1, 'A'-10 + +.Lstore: + sb t1, (t0) + bne t3, zero, .Ltop + addiu t0, t0, 1 # bd + + sb zero, (t0) # zero-terminate + la a0, buffer + jal printstr + nop + + lw ra, 16(sp) + jr ra + addiu sp, sp, 20 # bd + +buffer: .space 64 + +printstr: + addiu sp, sp, -20 + sw ra, 16(sp) + + # compute string length -> a2 + move t0, a0 +0: lb t1, (t0) + bne t1, zero, 0b + addiu t0, t0, 1 + addiu t0, t0, -1 + subu a2, t0, a0 + + move a1, a0 # buffer pointer + li a0, 1 # fd + move a3, sp # count pointer + + lw t0, SPB_FWVEC_ADDR + addiu t0, t0, FW_WRITE_OFFS + lw t0, (t0) # grab the write entry point in t0 + jal t0 + nop + + lw ra, 16(sp) + jr ra + addiu sp, sp, 20 # bd + +halt: + addiu sp, sp, -20 + sw ra, 16(sp) + + lw t0, SPB_FWVEC_ADDR + addiu t0, t0, FW_HALT_OFFS + lw t0, (t0) + jal t0 + nop + + lw ra, 16(sp) + jr ra + addiu sp, sp, 20 + + .data +hellostr: .asciiz "Hello SGI!\n" +foobar: .asciiz "This is a test!\n" -- 1.7.10.4