finished init routine

and better implemented sys calls
This commit is contained in:
Torsten Ruger
2015-06-25 16:31:09 +03:00
parent cedc6e1b61
commit 32e1903884
10 changed files with 57 additions and 26 deletions

View File

@ -14,6 +14,7 @@ module Arm
def initialize(first, attributes)
super(attributes)
raise "no target" if first.nil?
@first = first
opcode = @attributes[:opcode].to_s
if opcode.length == 3 and opcode[0] == "b"
@ -32,7 +33,7 @@ module Arm
case @attributes[:opcode]
when :b, :call
arg = @first
#puts "BLAB #{arg.inspect}"
puts "BLAB #{arg.class}"
if arg.is_a?(Virtual::Block) or arg.is_a?(Parfait::Method)
#relative addressing for jumps/calls
# but because of the arm "theoretical" 3- stage pipeline,

View File

@ -4,7 +4,7 @@ module Arm
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::LoadConstant
load = ArmMachine.ldr( code.value , code.constant )
load = ArmMachine.ldr( code.register , code.constant )
block.replace(code , load )
#puts "replaced #{load.inspect.to_s[0..1000]}"
end

View File

@ -1,17 +1,37 @@
module Arm
class SyscallImplementation
CALLS_CODES = { :putstring => 4 , :exit => 0 }
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::Syscall
raise "uups" unless code.name == :putstring
new_codes = [ ArmMachine.mov( :r1 , 20 ) ]
new_codes << ArmMachine.ldr( :r0 , Virtual::Slot::MESSAGE_REGISTER, Virtual::SELF_INDEX)
new_codes << ArmMachine.mov( :r7 , 4 )
new_codes << ArmMachine.swi( 0 )
new_codes = []
int_code = CALLS_CODES[code.name]
raise "Not implemented syscall, #{code.name}" unless int_code
send( code.name , int_code , new_codes )
block.replace(code , new_codes )
end
end
def putstring int_code , codes
codes << ArmMachine.mov( :r1 , 20 ) # String length, obvious TODO
codes << ArmMachine.ldr( :r0 , Virtual::Slot::MESSAGE_REGISTER, Virtual::SELF_INDEX)
syscall(int_code , codes )
end
def exit int_code , codes
syscall int_code , codes
end
private
# syscall is always triggered by swi(0)
# The actual code (ie the index of the kernel function) is in r7
def syscall int_code , codes
codes << ArmMachine.mov( :r7 , int_code )
codes << ArmMachine.swi( 0 )
end
end
Virtual.machine.add_pass "Arm::SyscallImplementation"
end