haxor 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +0,0 @@
1
- module Haxor
2
- module Compiler
3
- module Component
4
- class Transfer < Base
5
- def register
6
- bind_cmd 'mov', :cmd_mov
7
- bind_cmd 'push', :cmd_push
8
- bind_cmd 'pop', :cmd_pop
9
- end
10
-
11
- def cmd_push(a)
12
- add_cmd Vm::Cpu::Unit::Transfer::OP_PUSH, a
13
- end
14
-
15
- def cmd_pop(a)
16
- add_cmd Vm::Cpu::Unit::Transfer::OP_POP, a
17
- end
18
-
19
- def cmd_mov(a, b)
20
- add_cmd Vm::Cpu::Unit::Transfer::OP_MOV, a, b
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,30 +0,0 @@
1
- module Haxor
2
- module Compiler
3
- module Component
4
- class Various < Base
5
- def register
6
- bind_cmd 'nop', :cmd_nop
7
- bind_cmd 'lea', :cmd_lea
8
- bind_cmd 'int', :cmd_int
9
- bind_cmd 'syscall', :cmd_syscall
10
- end
11
-
12
- def cmd_nop(*_args)
13
- add_cmd Vm::Cpu::Unit::Various::OP_NOP
14
- end
15
-
16
- def cmd_lea(a, b)
17
- add_cmd Vm::Cpu::Unit::Various::OP_LEA, a, b
18
- end
19
-
20
- def cmd_int(a)
21
- add_cmd Vm::Cpu::Unit::Various::OP_INT, a
22
- end
23
-
24
- def cmd_syscall
25
- add_cmd Vm::Cpu::Unit::Various::OP_SYSCALL
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,78 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Arithmetic < Base
6
- # 0x00 (not used)
7
- OP_ADD = 0x01 # add a, b
8
- OP_SUB = 0x02 # sub a, b
9
- OP_DIV = 0x03 # div a
10
- OP_MUL = 0x04 # mul a
11
- OP_INC = 0x05 # inc a
12
- OP_DEC = 0x06 # dec a
13
- OP_CMP = 0x07 # cmp a, b
14
- # 0x1f
15
-
16
- def register
17
- bind_opcode OP_ADD, :op_add
18
- bind_opcode OP_SUB, :op_sub
19
- bind_opcode OP_DIV, :op_div
20
- bind_opcode OP_MUL, :op_mul
21
- bind_opcode OP_INC, :op_inc
22
- bind_opcode OP_DEC, :op_dec
23
- bind_opcode OP_CMP, :op_cmp
24
- end
25
-
26
- def op_add
27
- a, b = operands
28
- c = @vm.subsystem(:mem).read(a) + @vm.subsystem(:mem).read(b)
29
- @vm.subsystem(:mem).write a, c
30
- end
31
-
32
- def op_sub
33
- a, b = operands
34
- c = @vm.subsystem(:mem).read(a) - @vm.subsystem(:mem).read(b)
35
- @vm.subsystem(:mem).write a, c
36
- end
37
-
38
- def op_div
39
- a = operand
40
- av = @vm.subsystem(:mem).read a
41
- arv = @vm.subsystem(:registers).read 'ar'
42
- @vm.subsystem(:registers).write 'ar', (arv / av)
43
- @vm.subsystem(:registers).write 'dr', (arv % av)
44
- end
45
-
46
- def op_mul
47
- a = operand
48
- av = @vm.subsystem(:mem).read a
49
- arv = @vm.subsystem(:registers).read 'ar'
50
- @vm.subsystem(:registers).write 'ar', (arv * av)
51
- end
52
-
53
- def op_inc
54
- a = operand
55
- av = @vm.subsystem(:mem).read a
56
- @vm.subsystem(:mem).write a, (av + 1)
57
- end
58
-
59
- def op_dec
60
- a = operand
61
- av = @vm.subsystem(:mem).read a
62
- @vm.subsystem(:mem).write a, (av - 1)
63
- end
64
-
65
- def op_cmp
66
- a, b = operands
67
- av = @vm.subsystem(:mem).read a
68
- bv = @vm.subsystem(:mem).read b
69
- v = av - bv
70
-
71
- @vm.subsystem(:registers).flag Consts::FR_ZERO, v == 0
72
- @vm.subsystem(:registers).flag Consts::FR_SIGN, v < 0
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,46 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Base
6
- attr_accessor :vm
7
-
8
- def register
9
- fail 'this method must be implemented.'
10
- end
11
-
12
- def bind_opcode(opcode, method)
13
- @vm.bind_opcode opcode, self, method
14
- end
15
-
16
- # TODO: BC
17
- def next_cell
18
- @vm.subsystem(:mem).next_word
19
- end
20
-
21
- # TODO: BC
22
- def fetch_cell(addr)
23
- @vm.subsystem(:mem).read addr
24
- end
25
-
26
- def dereference(addr)
27
- @vm.subsystem(:mem).read addr
28
- end
29
-
30
- # TODO: BC
31
- def replace_cell(addr, value)
32
- @vm.subsystem(:mem).write addr, value
33
- end
34
-
35
- def operand
36
- @vm.operand
37
- end
38
-
39
- def operands
40
- @vm.operands
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,118 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Jumps < Base
6
- # 0x20
7
- OP_CALL = 0x20 # call a
8
- OP_JMP = 0x21 # jmp a
9
- OP_JE = 0x22 # je a
10
- OP_JG = 0x23 # jg a
11
- OP_JGE = 0x24 # jge a
12
- OP_JL = 0x25 # jl a
13
- OP_JLE = 0x26 # jle a
14
- OP_JNE = 0x27 # jne a
15
- OP_JNG = 0x28 # jng a
16
- OP_JNGE = 0x29 # jnge a
17
- OP_JNL = 0x2a # jnl a
18
- OP_JNLE = 0x2b # jnle a
19
- OP_RET = 0x2c # ret
20
- OP_IRET = 0x2d # iret
21
- # 0x3f
22
-
23
- def register
24
- bind_opcode OP_CALL, :op_call
25
- bind_opcode OP_JMP, :op_jmp
26
- bind_opcode OP_JE, :op_je
27
- bind_opcode OP_JG, :op_jg
28
- bind_opcode OP_JGE, :op_jge
29
- bind_opcode OP_JL, :op_jl
30
- bind_opcode OP_JLE, :op_jle
31
- bind_opcode OP_JNE, :op_jne
32
- bind_opcode OP_JNG, :op_jng
33
- bind_opcode OP_JNGE, :op_jnge
34
- bind_opcode OP_JNL, :op_jnl
35
- bind_opcode OP_JNLE, :op_jnle
36
- bind_opcode OP_RET, :op_ret
37
- bind_opcode OP_IRET, :op_iret
38
- end
39
-
40
- def op_call
41
- a = operand
42
- @vm.subsystem(:stack).push 'ip'
43
- jmp a
44
- end
45
-
46
- def op_jmp
47
- a = operand
48
- jmp a
49
- end
50
-
51
- def op_je
52
- a = operand
53
- jmp a if @vm.subsystem(:registers).check_flag Consts::FR_ZERO
54
- end
55
-
56
- def op_jg
57
- a = operand
58
- jmp a if !@vm.subsystem(:registers).check_flag(Consts::FR_ZERO) && !@vm.subsystem(:registers).check_flag(Consts::FR_SIGN)
59
- end
60
-
61
- def op_jge
62
- a = operand
63
- jmp a if !@vm.subsystem(:registers).check_flag(Consts::FR_SIGN) || @vm.subsystem(:registers).check_flag(Consts::FR_ZERO)
64
- end
65
-
66
- def op_jl
67
- a = operand
68
- jmp a if !@vm.subsystem(:registers).check_flag(Consts::FR_ZERO) && @vm.subsystem(:registers).check_flag(Consts::FR_SIGN)
69
- end
70
-
71
- def op_jle
72
- a = operand
73
- jmp a if @vm.subsystem(:registers).check_flag(Consts::FR_SIGN) || @vm.subsystem(:registers).check_flag(Consts::FR_ZERO)
74
- end
75
-
76
- def op_jne
77
- a = operand
78
- jmp a unless @vm.subsystem(:registers).check_flag Consts::FR_ZERO
79
- end
80
-
81
- def op_jng
82
- a = operand
83
- jmp a unless !@vm.subsystem(:registers).check_flag(Consts::FR_ZERO) && !@vm.subsystem(:registers).check_flag(Consts::FR_SIGN)
84
- end
85
-
86
- def op_jnge
87
- a = operand
88
- jmp a unless !@vm.subsystem(:registers).check_flag(Consts::FR_SIGN) || @vm.subsystem(:registers).check_flag(Consts::FR_ZERO)
89
- end
90
-
91
- def op_jnl
92
- a = operand
93
- jmp a unless !@vm.subsystem(:registers).check_flag(Consts::FR_ZERO) && @vm.subsystem(:registers).check_flag(Consts::FR_SIGN)
94
- end
95
-
96
- def op_jnle
97
- a = operand
98
- jmp a unless @vm.subsystem(:registers).check_flag(Consts::FR_SIGN) || @vm.subsystem(:registers).check_flag(Consts::FR_ZERO)
99
- end
100
-
101
- def op_ret
102
- @vm.subsystem(:stack).pop 'ip'
103
- end
104
-
105
- def op_iret
106
- @vm.subsystem(:stack).pop 'ip'
107
- end
108
-
109
- private
110
-
111
- def jmp(addr)
112
- @vm.subsystem(:registers).write 'ip', addr
113
- end
114
- end
115
- end
116
- end
117
- end
118
- end
@@ -1,59 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Logical < Base
6
- # 0x40
7
- OP_AND = 0x40 # and a, b
8
- OP_NEG = 0x41 # neg a
9
- OP_NOT = 0x42 # not a
10
- OP_OR = 0x43 # or a, b
11
- OP_XOR = 0x44 # xor a, b
12
- # 0x5f
13
-
14
- def register
15
- bind_opcode OP_AND, :op_and
16
- bind_opcode OP_NEG, :op_neg
17
- bind_opcode OP_NOT, :op_not
18
- bind_opcode OP_OR, :op_or
19
- bind_opcode OP_XOR, :op_xor
20
- end
21
-
22
- def op_and
23
- a, b = operands
24
- av = @vm.subsystem(:mem).read a
25
- bv = @vm.subsystem(:mem).read b
26
- v = av & bv
27
- @vm.subsystem(:mem).write a, v
28
- end
29
-
30
- def op_neg
31
- a = operand
32
- av = @vm.subsystem(:mem).read a
33
- @vm.subsystem(:mem).write a, -av
34
- end
35
-
36
- def op_not
37
- a = operand
38
- av = @vm.subsystem(:mem).read a
39
- @vm.subsystem(:mem).write a, ~av
40
- end
41
-
42
- def op_or
43
- a, b = operands
44
- av = @vm.subsystem(:mem).read a
45
- bv = @vm.subsystem(:mem).read b
46
- @vm.subsystem(:mem).write a, (av | bv)
47
- end
48
-
49
- def op_xor
50
- a, b = operands
51
- av = @vm.subsystem(:mem).read a
52
- bv = @vm.subsystem(:mem).read b
53
- @vm.subsystem(:mem).write a, (av ^ bv)
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,37 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Transfer < Base
6
- # 0x60
7
- OP_MOV = 0x60 # mov a, b
8
- OP_PUSH = 0x61 # push a
9
- OP_POP = 0x62 # pop a
10
- # 0x7f
11
-
12
- def register
13
- bind_opcode OP_MOV, :op_mov
14
- bind_opcode OP_PUSH, :op_push
15
- bind_opcode OP_POP, :op_pop
16
- end
17
-
18
- def op_mov
19
- a, b = operands
20
- v = @vm.subsystem(:mem).read b
21
- @vm.subsystem(:mem).write a, v
22
- end
23
-
24
- def op_push
25
- a = operand
26
- @vm.subsystem(:stack).push a
27
- end
28
-
29
- def op_pop
30
- a = operand
31
- @vm.subsystem(:stack).pop a
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,47 +0,0 @@
1
- module Haxor
2
- module Vm
3
- module Cpu
4
- module Unit
5
- class Various < Base
6
- # = 0x80
7
- OP_LEA = 0x80 # lea a
8
- OP_NOP = 0x81 # nop
9
- OP_INT = 0x85 # int a
10
- OP_SYSCALL = 0x86 # syscall
11
- # 0x9f
12
-
13
- def register
14
- bind_opcode OP_LEA, :op_lea
15
- bind_opcode OP_NOP, :op_nop
16
- bind_opcode OP_INT, :op_int
17
- bind_opcode OP_SYSCALL, :op_syscall
18
- end
19
-
20
- def op_lea
21
- a, b = operands
22
- @vm.subsystem(:mem).write a, b
23
- end
24
-
25
- def op_nop
26
- # intentionally nothing here
27
- end
28
-
29
- def op_int
30
- a = operand
31
-
32
- @vm.subsystem(:stack).push 'ip'
33
-
34
- av = @vm.subsystem(:mem).read a
35
- ivt = Consts::IVT_ADDR + (av * 8)
36
- handler = @vm.subsystem(:mem).read ivt
37
- @vm.subsystem(:mem).write 'ip', handler
38
- end
39
-
40
- def op_syscall
41
- @vm.subsystem(:os).syscall
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end