0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, # 56
0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, # 64
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 72
- 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, # 78 p_vaddr: 0x00400000, (virtual address of segment in memory)
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 86
- 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 94 p_filesz: 0x00011E02, (size in bytes of the segment in the file)
- 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00, # 102 p_memsz: 0x7FC00000, (size in bytes of the segment in memory)
+ 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, # 80 p_vaddr: 0x00400000, (virtual address of segment in memory)
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 88
+ 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 96 p_filesz: 0x00011E02, (size in bytes of the segment in the file)
+ 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00, # 104 p_memsz: 0x7FC00000, (size in bytes of the segment in memory)
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 112
]
)
end
-def base_offset()
- unpack64(24)
+def segment_base()
+ unpack64(80)
end
def mov_imm(val, reg)
# allocate value slot
pack64(0)
- offset = base_offset()
+ offset = segment_base()
here = PROG.length
allocation = (2 + ((name.length + 1) / 8.0).ceil) * 8
call('word')
name = pop()
- offset = base_offset()
+ offset = segment_base()
here = PROG.length
allocation = (2 + ((name.length + 1) / 8.0).ceil) * 8
pack8(0x90)
}
+builtin('jmp') {
+ pack8(0xe9)
+ pack32(pop())
+}
+
+builtin('call-word') {
+ here = (PROG.length + 5)
+ call('word')
+ code_addr = unpack64($words[pop()].addr - segment_base)
+
+ pack8(0xe8)
+ pack32(-(here - code_addr))
+}
+
+builtin('tailcall-word') {
+ here = (PROG.length + 5)
+ call('word')
+ code_addr = unpack64($words[pop()].addr - segment_base)
+
+ pack8(0xe9) # jmp
+ pack32(-(here - code_addr))
+}
#------------------------------------------
# Input Interpreter
else
$curr.code << $words[w].code
end
- elsif w =~ /^[0-9A-Fa-f]+$/
+ elsif w =~ /^[0-9A-Fa-f-]+$/
if $state == 0
push w.to_i($base)
else
// movq \reg,(%rbp)
- asm("lea 8(%rbp), %rbp");
- asm("mov %rax, (%rbp)");
+// asm("lea 8(%rbp), %rbp");
+// asm("mov %rax, (%rbp)");
// asm("mov $60, %eax");
- asm("xor %rax,%rax");
- asm("xor %rcx,%rcx");
- asm("xor %rdx,%rdx");
- asm("xor %rbx,%rbx");
- asm("xor %rsp,%rsp");
- asm("xor %rbp,%rbp");
- asm("xor %rsi,%rsi");
- asm("xor %rdi,%rdi");
- asm("xor %r8,%r8");
- asm("xor %r9,%r9");
- asm("xor %r10,%r10");
- asm("xor %r11,%r11");
- asm("xor %r12,%r12");
- asm("xor %r13,%r13");
- asm("xor %r14,%r14");
- asm("xor %r15,%r15");
-
- asm("mov $0x01, %rax");
- asm("mov $0x01, %rcx");
- asm("mov $0x01, %rdx");
- asm("mov $0x01, %rbx");
- asm("mov $0x01, %rsp");
- asm("mov $0x01, %rbp");
- asm("mov $0x01, %rsi");
- asm("mov $0x01, %rdi");
- asm("mov $0x01, %r8");
- asm("mov $0x01, %r9");
- asm("mov $0x01, %r10");
- asm("mov $0x01, %r11");
- asm("mov $0x01, %r12");
- asm("mov $0x01, %r13");
- asm("mov $0x01, %r14");
- asm("mov $0x01, %r15");
+// asm("xor %rax,%rax");
+// asm("xor %rcx,%rcx");
+// asm("xor %rdx,%rdx");
+// asm("xor %rbx,%rbx");
+// asm("xor %rsp,%rsp");
+// asm("xor %rbp,%rbp");
+// asm("xor %rsi,%rsi");
+// asm("xor %rdi,%rdi");
+// asm("xor %r8,%r8");
+// asm("xor %r9,%r9");
+// asm("xor %r10,%r10");
+// asm("xor %r11,%r11");
+// asm("xor %r12,%r12");
+// asm("xor %r13,%r13");
+// asm("xor %r14,%r14");
+// asm("xor %r15,%r15");
+//
+// asm("mov $0x01, %rax");
+// asm("mov $0x01, %rcx");
+// asm("mov $0x01, %rdx");
+// asm("mov $0x01, %rbx");
+// asm("mov $0x01, %rsp");
+// asm("mov $0x01, %rbp");
+// asm("mov $0x01, %rsi");
+// asm("mov $0x01, %rdi");
+// asm("mov $0x01, %r8");
+// asm("mov $0x01, %r9");
+// asm("mov $0x01, %r10");
+// asm("mov $0x01, %r11");
+// asm("mov $0x01, %r12");
+// asm("mov $0x01, %r13");
+// asm("mov $0x01, %r14");
+// asm("mov $0x01, %r15");
+//
+// asm("syscall");
- asm("syscall");
+asm("lea -8192(%rsp), %rsp");
}