Lays groundword for Rv64i extension
Some base files had to be modified to support 64-bit architecture as well as the Makefile to load 64-bit words into memory
This commit is contained in:
25
common/swap_endian.py
Normal file
25
common/swap_endian.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: swap_endian.py <input> <output> [word_size]")
|
||||
sys.exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
word_size = int(sys.argv[3]) if len(sys.argv) > 3 else 4 # par défaut 32 bits
|
||||
|
||||
with open(input_file, "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
# Vérifie que la taille est multiple de la taille de mot
|
||||
if len(data) % word_size != 0:
|
||||
print("⚠️ Attention : la taille du fichier n'est pas multiple de la taille de mot")
|
||||
|
||||
swapped = bytearray()
|
||||
for i in range(0, len(data), word_size):
|
||||
word = data[i:i+word_size]
|
||||
swapped.extend(word[::-1]) # inverse les octets dans chaque mot
|
||||
|
||||
with open(output_file, "wb") as f:
|
||||
f.write(swapped)
|
||||
Reference in New Issue
Block a user