This commit is contained in:
2025-08-02 12:10:59 -04:00
parent 0a4dd81318
commit 5bb19672a7
11 changed files with 1227 additions and 32 deletions
+1
View File
@@ -1,2 +1,3 @@
toolchain/pcsx-redux toolchain/pcsx-redux
# toolchain/armips
build build
+56
View File
@@ -0,0 +1,56 @@
.psx
.create "exercise1.bin", 0x80010000
; Entry Point of Code
.org 0x80010000
; Constant declaration
BASE_ADDR equ 0x0000
; Symbol Alias Table
; Instructions
load_imm equ li
; Registers
rtemp_0 equ $t0
rtemp_1 equ $t1
rtemp_2 equ $t2
.macro test,dst_reg,value
li dst_reg,value
.endmacro
.macro test2,reg
li reg,0xA000
.endmacro
.macro myli,dest,value
.if value & ~0xFFFF
ori dest,r0,value
.elseif (value & 0xFFFF8000) == 0xFFFF8000
addiu dest,r0,value & 0xFFFF
.elseif (value & 0xFFFF) == 0
lui dest,value >> 16
.else
lui dest,value >> 16 + (value & 0x8000 != 0)
addiu dest,dest,value & 0xFFFF
.endif
.endmacro
.macro store_word, src_reg, dst_address
sw src_reg, dst_address
.endmacro
Main:
myli $t0, 0xA000
li rtemp_1, 0xA100 ; $t1 = 0xA100
li rtemp_2, 0x11111111 ; $t2 = 0x11111111
Loop:
sw $t2, BASE_ADDR($t0) ; Store byte at 0x0000 + t0
addi $t0, $t0, 4 ; ++ t0
blt $t0, $t1, Loop ; while (t0 < t1) keep looping
.close
Binary file not shown.
+14 -15
View File
@@ -20,12 +20,12 @@ function main(args)
os.exit(1) os.exit(1)
end end
print(string.format("Input file: %s", args[1])) -- print(string.format("Input file: %s", args[1]))
print(string.format("Output file: %s", args[2])) -- print(string.format("Output file: %s", args[2]))
-- PS1 executables have a maximum size limit of 2MB -- PS1 executables have a maximum size limit of 2MB
local max_size = 0x200000 local max_size = 0x200000
print(string.format("\nChecking input file size (max: %d bytes)...", max_size)) -- print(string.format("\nChecking input file size (max: %d bytes)...", max_size))
local infile_size = file_size(args[1]) local infile_size = file_size(args[1])
if not infile_size then if not infile_size then
@@ -33,14 +33,14 @@ function main(args)
os.exit(1) os.exit(1)
end end
print(string.format("Input file size: %d bytes", infile_size)) -- print(string.format("Input file size: %d bytes", infile_size))
if infile_size > max_size then if infile_size > max_size then
io.stderr:write(string.format("Error: Input file %s longer than %d bytes\n", args[1], max_size)) io.stderr:write(string.format("Error: Input file %s longer than %d bytes\n", args[1], max_size))
os.exit(1) os.exit(1)
end end
print("\nOpening files...") -- print("\nOpening files...")
local ofile = io.open(args[2], "wb") local ofile = io.open(args[2], "wb")
if not ofile then if not ofile then
io.stderr:write("Error: Cannot open output file " .. args[2] .. "\n") io.stderr:write("Error: Cannot open output file " .. args[2] .. "\n")
@@ -53,16 +53,15 @@ function main(args)
os.exit(1) os.exit(1)
end end
print("Writing PS-X executable header...")
-- PS1 executables start with "PS-X EXE" magic string -- PS1 executables start with "PS-X EXE" magic string
-- print("Writing PS-X executable header...")
ofile:write("PS-X EXE") ofile:write("PS-X EXE")
-- Write entry point address (where the PS1 will jump to start execution) -- Write entry point address (where the PS1 will jump to start execution)
-- 0x80010000 is a standard entry point in PS1 RAM -- 0x80010000 is a standard entry point in PS1 RAM
ofile:seek("set", 0x10) ofile:seek("set", 0x10)
ofile:write(string.pack("<I4", 0x80010000)) ofile:write(string.pack("<I4", 0x80010000))
print(" Entry point: 0x80010000") -- print(" Entry point: 0x80010000")
-- Initial GP/R28 register value (Global Pointer for data addressing) -- Initial GP/R28 register value (Global Pointer for data addressing)
-- 0xFFFFFFFF means it will be set by crt0.S startup code -- 0xFFFFFFFF means it will be set by crt0.S startup code
@@ -70,21 +69,21 @@ function main(args)
-- Destination address in RAM where the executable will be loaded -- Destination address in RAM where the executable will be loaded
ofile:write(string.pack("<I4", 0x80010000)) ofile:write(string.pack("<I4", 0x80010000))
print(" Load address: 0x80010000") -- print(" Load address: 0x80010000")
-- Initial stack pointer (SP/R29) and frame pointer (FP/R30) -- Initial stack pointer (SP/R29) and frame pointer (FP/R30)
-- 0x801FFF00 points near the top of the 2MB main RAM -- 0x801FFF00 points near the top of the 2MB main RAM
ofile:seek("set", 0x30) ofile:seek("set", 0x30)
ofile:write(string.pack("<I4", 0x801FFF00)) ofile:write(string.pack("<I4", 0x801FFF00))
print(" Stack pointer: 0x801FFF00") -- print(" Stack pointer: 0x801FFF00")
-- PS1 executables have an 0x800 (2048) byte header -- PS1 executables have an 0x800 (2048) byte header
-- Zero fill the rest of the header -- Zero fill the rest of the header
ofile:seek("set", 0x800) ofile:seek("set", 0x800)
print(" Header padding complete (2048 bytes)") -- print(" Header padding complete (2048 bytes)")
-- Copy the actual program binary data after the header -- Copy the actual program binary data after the header
print("\nCopying program data...") -- print("\nCopying program data...")
local buffer_size = 0x2000 -- 8KB chunks for efficient copying local buffer_size = 0x2000 -- 8KB chunks for efficient copying
local bytes_copied = 0 local bytes_copied = 0
@@ -118,13 +117,13 @@ function main(args)
-- This goes at offset 0x1C in the header -- This goes at offset 0x1C in the header
ofile:seek("set", 0x1C) ofile:seek("set", 0x1C)
ofile:write(string.pack("<I4", exe_size - 0x800)) ofile:write(string.pack("<I4", exe_size - 0x800))
print(string.format("\nProgram size field set to: %d bytes", exe_size - 0x800)) -- print(string.format("\nProgram size field set to: %d bytes", exe_size - 0x800))
ifile:close() ifile:close()
ofile:close() ofile:close()
print(string.format("\nSuccess! PS1 executable created: %s", args[2])) -- print(string.format("\nSuccess! PS1 executable created: %s", args[2]))
print(string.format("Total file size: %d bytes", exe_size)) print(string.format("Total file size: %d bytes\n", exe_size))
end end
-- Run main with command line arguments -- Run main with command line arguments
+21 -13
View File
@@ -2,27 +2,35 @@ $path_root = split-path -Path $PSScriptRoot -Parent
$path_build = join-path $path_root 'build' $path_build = join-path $path_root 'build'
$path_code = join-path $path_root 'code' $path_code = join-path $path_root 'code'
$path_scripts = join-path $path_root 'scripts' $path_scripts = join-path $path_root 'scripts'
$path_toolchain = join-path $path_root 'toolchain'
if ((test-path $path_build) -eq $false) { if ((test-path $path_build) -eq $false) {
new-item -itemtype directory -path $path_build new-item -itemtype directory -path $path_build
} }
$armips = 'armips' $armips = join-path $path_toolchain 'armips/armips.exe'
$bin2exe_lua = join-path $path_scripts 'bin2exe.lua' $bin2exe_lua = join-path $path_scripts 'bin2exe.lua'
$bin2exe_py = join-path $path_scripts 'bin2exe.py' $bin2exe_py = join-path $path_scripts 'bin2exe.py'
$path_fillmem = join-path $path_code 'fillmem' function build-program { param(
$src_fillmem = join-path $path_fillmem 'fillmem.s' [string]$module,
$bin_fillmem = join-path $path_build 'fillmem.bin' [string]$unit
$exe_fillmem = join-path $path_build 'fillmem.exe' )
$path_module = join-path $path_code $module
$src = join-path $path_module "$unit.s"
$bin = join-path $path_build "$unit.bin"
$exe = join-path $path_build "$unit.exe"
push-location $path_build push-location $path_build
write-host "Assembling: $src_fillmem`n" write-host "Assembling: $src`n"
& $armips $src_fillmem & $armips $src
write-host 'Generating executable..' write-host 'Generating executable..'
& lua $bin2exe_lua $bin_fillmem $exe_fillmem & lua $bin2exe_lua $bin $exe
# & py $bin2exe_py $bin_fillmem $exe_fillmem # & py $bin2exe_py $bin $exe
write-host 'Done!' write-host 'Done!'
pop-location pop-location
}
# build-program 'fillmem' 'fillmem'
build-program 'warmup' 'exercise1'
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.