398
|
1 from ..basetarget import Target
|
|
2 from ...assembler import BaseAssembler
|
|
3 from .registers import rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi
|
|
4 from .registers import r8, r9, r10, r11, r12, r13, r14, r15, regs64
|
|
5 from .instructions import Mov, Inc, Xor, Push, Pop
|
291
|
6
|
|
7
|
398
|
8 class X86Assembler(BaseAssembler):
|
|
9 def __init__(self, target):
|
|
10 super().__init__(target)
|
|
11 self.make_parser()
|
291
|
12
|
|
13
|
398
|
14 class X86Target(Target):
|
|
15 """ x86 target containing assembler, linker"""
|
|
16 def __init__(self):
|
|
17 super().__init__('x86')
|
291
|
18
|
398
|
19 for reg in regs64:
|
|
20 self.add_keyword(reg.name)
|
291
|
21
|
398
|
22 self.add_rule('reg', ['rax'], lambda rhs: rax)
|
|
23 self.add_rule('reg', ['rcx'], lambda rhs: rcx)
|
|
24 self.add_rule('reg', ['rdx'], lambda rhs: rdx)
|
|
25 self.add_rule('reg', ['rbx'], lambda rhs: rbx)
|
|
26 self.add_rule('reg', ['rsp'], lambda rhs: rsp)
|
|
27 self.add_rule('reg', ['rbp'], lambda rhs: rbp)
|
|
28 self.add_rule('reg', ['rsi'], lambda rhs: rsi)
|
|
29 self.add_rule('reg', ['rdi'], lambda rhs: rdi)
|
|
30 self.add_rule('reg', ['r8'], lambda rhs: r8)
|
|
31 self.add_rule('reg', ['r9'], lambda rhs: r9)
|
|
32 self.add_rule('reg', ['r10'], lambda rhs: r10)
|
|
33 self.add_rule('reg', ['r11'], lambda rhs: r11)
|
|
34 self.add_rule('reg', ['r12'], lambda rhs: r12)
|
|
35 self.add_rule('reg', ['r13'], lambda rhs: r13)
|
|
36 self.add_rule('reg', ['r14'], lambda rhs: r14)
|
|
37 self.add_rule('reg', ['r15'], lambda rhs: r15)
|
291
|
38
|
398
|
39 self.add_keyword('mov')
|
|
40 self.add_instruction(['mov', 'reg', ',', 'reg'],
|
|
41 lambda rhs: Mov(rhs[1], rhs[3]))
|
291
|
42
|
398
|
43 self.add_keyword('xor')
|
|
44 self.add_instruction(['xor', 'reg', ',', 'reg'],
|
|
45 lambda rhs: Xor(rhs[1], rhs[3]))
|
|
46
|
|
47 self.add_keyword('inc')
|
|
48 self.add_instruction(['inc', 'reg'],
|
|
49 lambda rhs: Inc(rhs[1]))
|
|
50
|
|
51 self.add_keyword('push')
|
|
52 self.add_instruction(['push', 'reg'],
|
|
53 lambda rhs: Push(rhs[1]))
|
|
54
|
|
55 self.add_keyword('pop')
|
|
56 self.add_instruction(['pop', 'reg'],
|
|
57 lambda rhs: Pop(rhs[1]))
|
|
58
|
|
59 self.assembler = X86Assembler(self)
|