Skip to content

Commit b1e1097

Browse files
committed
support syscall in assembler, and compiler
1 parent a67af3a commit b1e1097

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/vaporware/compiler/assembler/elf.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(type:, input:, output:, debug:)
1010
@header = Header.new(type:)
1111
@sections = Sections.new
1212
end
13-
13+
1414
def build(input: @input, output: @output, debug: false)
1515
program_size = 0
1616
read!(input:)
@@ -60,6 +60,7 @@ def build(input: @input, output: @output, debug: false)
6060

6161
private
6262
def init_assemble! = (note!; symtab!)
63+
6364
def read!(input: @input, text: @sections.text.body)
6465
read = { main: false }
6566
File.open(input, "r") do |r|

lib/vaporware/compiler/assembler/elf/section/text.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def opecode(op, *operands)
4949
sete(op, *operands)
5050
when "je", "jmp"
5151
jump(op, *operands)
52+
when "syscall"
53+
[0x0f, 0x05]
5254
when "ret"
5355
[0xc3]
5456
else

lib/vaporware/compiler/generator.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def already_build_methods? = @defined_methods.sort == @doned.to_a.sort
5757
def epilogue(output)
5858
output.puts " mov rsp, rbp"
5959
output.puts " pop rbp"
60+
output.puts " mov rdi, rax"
61+
output.puts " mov rax, 60"
62+
output.puts " syscall"
6063
output.puts " ret"
6164
end
6265

0 commit comments

Comments
 (0)