define and use syscall_XX registers

rather than use hardcoded r0 etc use syscall_X
change the syscalls and interpreter to use them
later use platform to map from syscall_X to actually used register (like r0 in arm)
This commit is contained in:
Torsten 2020-03-16 17:31:14 +02:00
parent 3b50fee158
commit 17a7f29b0c
5 changed files with 19 additions and 9 deletions

View File

@ -19,6 +19,13 @@ module Risc
def to_s
class_source name
end
end
# return the nth register that a sycall needs
# these map to different physical registers in the Platform
# first arg is (running 1..) integer, second (optional) type
def self.syscall_reg( number , type = nil)
type = :Integer unless type
RegisterValue.new("syscall_#{number}".to_sym , type)
end
end

View File

@ -257,12 +257,12 @@ module Risc
else
raise "un-implemented syscall #{name}"
end
set_register( :r0 , ret_value ) # syscalls return into r0 , usually some int
set_register( :syscall_1 , ret_value ) # syscalls return into syscall_1
true
end
def handle_putstring
str = get_register( :r1 ) # should test length, ie r2
str = get_register( :"syscall_1" ) # should test length, ie r2
case str
when Symbol
@stdout << str.to_s

View File

@ -20,10 +20,9 @@ module SlotMachine
# Assumes int return value and extracts the fixnum for process exit code
def self.exit_sequence(builder)
save_message( builder )
unix_return = Risc.syscall_reg(1)
builder.build do
message << message[:return_value]
int = message.reduce_int(false) #hack, noo type check
message << int
unix_return << message[:return_value].reduce_int(false) #hack, noo type check
add_code Risc::Syscall.new("emit_syscall(exit)", :exit )
end
end
@ -46,7 +45,7 @@ module SlotMachine
r8 = Risc::RegisterValue.new( :saved_message , :Message).set_compiler(builder.compiler)
tmp = Risc::RegisterValue.new( :integer_tmp , :Integer).set_compiler(builder.compiler)
builder.build do
tmp << message
tmp << Risc.syscall_reg(1)
message << r8
message[:return_value][Parfait::Integer.integer_index] << tmp
end

View File

@ -3,9 +3,13 @@ module SlotMachine
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer = builder.prepare_int_return # makes integer_tmp variable as return
word = Risc.syscall_reg(1).set_compiler(compiler)
length = Risc.syscall_reg(2).set_compiler(compiler)
builder.build do
word = message[:receiver].to_reg.known_type(:Word)
integer << word[:char_length]
string = message[:receiver].to_reg.known_type(:Word)
integer << string[:char_length]
word << string # into right
length << integer # registers
end
SlotMachine::Macro.emit_syscall( builder , :putstring )
compiler

View File

@ -49,7 +49,7 @@ module Risc
def get_return
assert_equal Parfait::Message , @interpreter.get_register(:saved_message).class
@interpreter.get_register(:message)
@interpreter.get_register(:syscall_1)
end
# do as many as given ticks in the main, ie main_at more