commit 10b58220536b5085ac9e4ffe294676ad5f2c9d4e
parent 3e9bc8182e08b52ad731789d912340ea7bb87aef
Author: Gabriel G. de Brito <gabrielgbrito@icloud.com>
Date: Sat, 24 Feb 2024 23:38:19 -0300
MIPS is working. Needs testing
Diffstat:
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/main.go b/main.go
@@ -10,12 +10,14 @@ import (
"github.com/gboncoffee/egg/machine"
"github.com/gboncoffee/egg/riscv"
+ "github.com/gboncoffee/egg/mips"
)
// Put new architetures here...
func listArchs() {
fmt.Println(`Currently supported architetures:
-'riscv' - RISC-V IM, 32 bits`)
+'riscv' - RISC-V IM, 32 bits
+'mips' - Subset of MIPS32 (experimental)`)
}
func version() {
@@ -97,6 +99,9 @@ func main() {
case "riscv":
var r riscv.RiscV
m = &r
+ case "mips":
+ var r mips.Mips
+ m = &r
default:
log.Println(fmt.Sprintf("Unknown architeture: %v", architeture))
listArchs()
diff --git a/mips/hello-world.asm b/mips/hello-world.asm
@@ -0,0 +1,13 @@
+;;
+;; MIPS Hello World for the EGG emulator.
+;;
+
+_start:
+ addi v0, zero, 3
+ addi a0, zero, msg
+ addi a1, zero, 14
+ syscall
+ break
+
+msg:
+#Hello, World!%0a
diff --git a/mips/mips.go b/mips/mips.go
@@ -103,8 +103,8 @@ func signExtend64(n uint32) uint64 {
// - rt
// - imm
func parseI(i uint32) (uint8, uint8, uint32) {
- rs := i & 0b11111000000000000000000000
- rt := i & 0b111110000000000000000
+ rs := (i & 0b11111000000000000000000000) >> 21
+ rt := (i & 0b111110000000000000000) >> 16
imm := i & 0xffff
return uint8(rs), uint8(rt), imm
@@ -122,10 +122,10 @@ func parseJ(i uint32) uint32 {
// - shamt
// - funct
func parseR(i uint32) (uint8, uint8, uint8, uint8, uint8) {
- rs := uint8(i & 0b11111000000000000000000000)
- rt := uint8(i & 0b111110000000000000000)
- rd := uint8(i & 0b1111100000000000)
- shamt := uint8(i & 0b11111000000)
+ rs := uint8((i & 0b11111000000000000000000000) >> 21)
+ rt := uint8((i & 0b111110000000000000000) >> 16)
+ rd := uint8((i & 0b1111100000000000) >> 11)
+ shamt := uint8((i & 0b11111000000) >> 6)
funct := uint8(i & 0b111111)
return rs, rt, rd, shamt, funct
@@ -500,7 +500,7 @@ func (m *Mips) executeSw(rs, rt uint8, off uint32) {
}
func (m *Mips) execute(i uint32) (*machine.Call, error) {
- opcode := i & 0b111111
+ opcode := i >> 26
switch opcode {
case 0:
rs, rt, rd, shamt, funct := parseR(i)