-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
437 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM --platform=linux/amd64 ubuntu:22.04 | ||
|
||
ENV SHELL=/bin/bash | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ | ||
ca-certificates \ | ||
build-essential \ | ||
curl \ | ||
g++-mips-linux-gnu \ | ||
libc6-dev-mips-cross \ | ||
binutils-mips-linux-gnu \ | ||
llvm \ | ||
clang \ | ||
python3 \ | ||
python3-pip \ | ||
xxd | ||
|
||
RUN python3 -m pip install capstone pyelftools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
set positional-arguments := true | ||
|
||
help: | ||
just --list | ||
|
||
# Build the MIPS64 test case assembler image | ||
build-image: | ||
#!/bin/bash | ||
docker build -f builder.dockerfile -t mips-test-builder:local . | ||
|
||
# Assemble the test cases | ||
make-tests *args='': | ||
#!/bin/bash | ||
if [ ! "$(docker images -q mips-test-builder:local 2> /dev/null)" ]; then | ||
just build-image | ||
fi | ||
|
||
docker run \ | ||
--rm \ | ||
--platform linux/amd64 \ | ||
-v `pwd`/:/workdir \ | ||
-w="/workdir" \ | ||
mips-test-builder:local bash make_tests.sh {{args}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
function maketest() { | ||
local src="$1" | ||
local out="$2" | ||
|
||
printf "building %s -> %s" "$src" "$out" | ||
|
||
# Create a temporary file | ||
full_bin=$(mktemp) | ||
|
||
# Assemble the full test vector | ||
mips-linux-gnu-as -defsym big_endian=1 -march=mips64 -o "$full_bin" "$src" | ||
|
||
# Copy the `.test` section data to a temporary file | ||
section_data=$(mktemp) | ||
mips-linux-gnu-objcopy --dump-section .test="$section_data" "$full_bin" | ||
|
||
# Write the .test section data to the output file | ||
cp "$section_data" "$out" | ||
|
||
# Clean up the temporary files | ||
rm "$full_bin" "$section_data" | ||
|
||
printf " ✅\n" | ||
} | ||
|
||
mkdir -p /tmp/mips | ||
|
||
if [ "$#" -gt 0 ]; then | ||
maketest "$1" "test/bin/$(basename "$1" .asm).bin" | ||
else | ||
for d in test/*.asm; | ||
do | ||
[ -e "$d" ] || continue | ||
maketest "$d" "test/bin/$(basename "$d" .asm).bin" | ||
done | ||
|
||
echo "[🧙] All tests built successfully. God speed, space cowboy." | ||
fi |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
############################################################################### | ||
# File : dadd.asm | ||
# Author: : clabby (github.com/clabby) | ||
# | ||
# Standards/Formatting: | ||
# MIPS gas, soft tab, 80 column | ||
# | ||
# Description: | ||
# Test the functionality of the 'dadd' instruction. | ||
# | ||
############################################################################### | ||
|
||
|
||
.section .test, "x" | ||
.balign 4 | ||
.set noreorder | ||
.global test | ||
.ent test | ||
test: | ||
lui $s0, 0xbfff # Load the base address 0xbffffff0 | ||
ori $s0, 0xfff0 | ||
ori $s1, $0, 1 # Prepare the 'done' status | ||
|
||
#### Test code start #### | ||
|
||
# Check that overflow is detected | ||
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD) | ||
ori $t1, $0, 0x3 # B = 0x3 | ||
dadd $t2, $t0, $t1 # C = A + B = 0 | ||
bne $t2, $0, $finish # If C != 0, fail | ||
nop | ||
|
||
# Add standard unsigned 64-bit numbers, no overflow | ||
lui $t3, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t3, $t3, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003) | ||
|
||
dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF) | ||
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000) | ||
ori $t1, $0, 0x3 # B = 0x3 | ||
dadd $t2, $t0, $t1 # C = A + B = 0xFFFF_FFFF_FFFF_0003 | ||
bne $t2, $t3, $finish # If C != 0xFFFF_FFFF_FFFF_0003, fail | ||
nop | ||
|
||
# Set success flag | ||
ori $v0, $0, 1 # Set test result to success | ||
|
||
#### Test code end #### | ||
|
||
$finish: | ||
sw $v0, 8($s0) # Set the test result | ||
sw $s1, 4($s0) # Set 'done' | ||
|
||
$done: | ||
jr $ra | ||
nop | ||
|
||
.end test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
############################################################################### | ||
# File : daddi.asm | ||
# Author: : clabby (github.com/clabby) | ||
# | ||
# Standards/Formatting: | ||
# MIPS gas, soft tab, 80 column | ||
# | ||
# Description: | ||
# Test the functionality of the 'daddi' instruction. | ||
# | ||
############################################################################### | ||
|
||
|
||
.section .test, "x" | ||
.balign 4 | ||
.set noreorder | ||
.global test | ||
.ent test | ||
test: | ||
lui $s0, 0xbfff # Load the base address 0xbffffff0 | ||
ori $s0, 0xfff0 | ||
ori $s1, $0, 1 # Prepare the 'done' status | ||
|
||
#### Test code start #### | ||
|
||
# Check that overflow is detected | ||
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD) | ||
daddi $t1, $t0, 0x3 # B = A + 3 = 0 | ||
bne $t1, $0, $finish # If B != 0, fail | ||
nop | ||
|
||
# Add standard unsigned 64-bit numbers, no overflow | ||
lui $t2, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t2, $t2, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003) | ||
|
||
dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF) | ||
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000) | ||
daddi $t1, $t0, 0x3 # B = A + 3 = 0xFFFF_FFFF_FFFF_0003 | ||
bne $t1, $t2, $finish # If B != 0xFFFF_FFFF_FFFF_0003, fail | ||
nop | ||
|
||
# Set success flag | ||
ori $v0, $0, 1 # Set test result to success | ||
|
||
#### Test code end #### | ||
|
||
$finish: | ||
sw $v0, 8($s0) # Set the test result | ||
sw $s1, 4($s0) # Set 'done' | ||
|
||
$done: | ||
jr $ra | ||
nop | ||
|
||
.end test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
############################################################################### | ||
# File : daddiu.asm | ||
# Author: : clabby (github.com/clabby) | ||
# | ||
# Standards/Formatting: | ||
# MIPS gas, soft tab, 80 column | ||
# | ||
# Description: | ||
# Test the functionality of the 'daddiu' instruction. | ||
# | ||
############################################################################### | ||
|
||
|
||
.section .test, "x" | ||
.balign 4 | ||
.set noreorder | ||
.global test | ||
.ent test | ||
test: | ||
lui $s0, 0xbfff # Load the base address 0xbffffff0 | ||
ori $s0, 0xfff0 | ||
ori $s1, $0, 1 # Prepare the 'done' status | ||
|
||
#### Test code start #### | ||
|
||
# Check that overflow is detected | ||
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD) | ||
daddiu $t1, $t0, 0x3 # B = A + 3 = 0 | ||
bne $t1, $0, $finish # If B != 0, fail | ||
nop | ||
|
||
# Add standard unsigned 64-bit numbers, no overflow | ||
lui $t2, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t2, $t2, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003) | ||
|
||
dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF) | ||
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000) | ||
daddiu $t1, $t0, 0x3 # B = A + 3 = 0xFFFF_FFFF_FFFF_0003 | ||
bne $t1, $t2, $finish # If B != 0xFFFF_FFFF_FFFF_0003, fail | ||
nop | ||
|
||
# Set success flag | ||
ori $v0, $0, 1 # Set test result to success | ||
|
||
#### Test code end #### | ||
|
||
$finish: | ||
sw $v0, 8($s0) # Set the test result | ||
sw $s1, 4($s0) # Set 'done' | ||
|
||
$done: | ||
jr $ra | ||
nop | ||
|
||
.end test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
############################################################################### | ||
# File : daddu.asm | ||
# Author: : clabby (github.com/clabby) | ||
# | ||
# Standards/Formatting: | ||
# MIPS gas, soft tab, 80 column | ||
# | ||
# Description: | ||
# Test the functionality of the 'daddu' instruction. | ||
# | ||
############################################################################### | ||
|
||
|
||
.section .test, "x" | ||
.balign 4 | ||
.set noreorder | ||
.global test | ||
.ent test | ||
test: | ||
lui $s0, 0xbfff # Load the base address 0xbffffff0 | ||
ori $s0, 0xfff0 | ||
ori $s1, $0, 1 # Prepare the 'done' status | ||
|
||
#### Test code start #### | ||
|
||
# Check that overflow is detected | ||
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD) | ||
ori $t1, $0, 0x3 # B = 0x3 | ||
daddu $t2, $t0, $t1 # C = A + B = 0 | ||
bne $t2, $0, $finish # If C != 0, fail | ||
nop | ||
|
||
# Add standard unsigned 64-bit numbers, no overflow | ||
lui $t3, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended) | ||
ori $t3, $t3, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003) | ||
|
||
dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF) | ||
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000) | ||
ori $t1, $0, 0x3 # B = 0x3 | ||
daddu $t2, $t0, $t1 # C = A + B = 0xFFFF_FFFF_FFFF_0003 | ||
bne $t2, $t3, $finish # If C != 0xFFFF_FFFF_FFFF_0003, fail | ||
nop | ||
|
||
# Set success flag | ||
ori $v0, $0, 1 # Set test result to success | ||
|
||
#### Test code end #### | ||
|
||
$finish: | ||
sw $v0, 8($s0) # Set the test result | ||
sw $s1, 4($s0) # Set 'done' | ||
|
||
$done: | ||
jr $ra | ||
nop | ||
|
||
.end test |
Oops, something went wrong.