-
Notifications
You must be signed in to change notification settings - Fork 2
/
align.inc
97 lines (86 loc) · 2.13 KB
/
align.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
; Universal implementation of ALIGN.
; Basic use:
; align 4
; Ensure specific offset relative to an aligned address:
; align 4 | 1
; Provide information for the alignment of relocatable symbols:
; align.assume rbp, 16
; element RELOCATABLE_BASE
; org RELOCATABLE_BASE
; align.assume RELOCATABLE_BASE, 10000h
; Pad with value:
; align 16, 90h
; Use a custom command to pad:
; align 16, db # dup ($ and 0FFh)
define align? align
align?.count = 0
calminstruction align?.assume? address*, alignment*
local index, symbol
compute address, address
compute alignment, alignment
check address relativeto 0
jyes absolute
compute index, 0
find:
check index = align.count
jyes update
arrange symbol, align.=address#index
check address relativeto symbol
jyes update
compute index, index + 1
jump find
update:
arrange symbol, align.=address#index
publish symbol, address
arrange symbol, align.=alignment#index
publish symbol, alignment
compute align.count, align.count + 1
exit
absolute:
check address mod alignment = 0
jyes ok
err 'false assumption about absolute address'
ok:
end calminstruction
calminstruction align? alignment*, filler:rb #
local index, address, offset
compute offset, 0
match alignment | offset, alignment
compute alignment, alignment
check alignment >= 0
jyes alignment_ok
err 'invalid alignment value'
exit
alignment_ok:
compute address, $
check address relativeto 0
jyes align
compute index, 0
find:
check index = align.count
jyes fail
arrange symbol, align.=address#index
check address relativeto symbol
jyes found
compute index, index + 1
jump find
found:
compute address, address - symbol
arrange symbol, align.=alignment#index
check symbol > 0 & symbol mod alignment = 0
jyes align
fail:
err 'variable portion of the address is not aligned enough'
exit
align:
compute alignment, (alignment-1) - (address-offset+alignment-1) mod alignment
local prefix, suffix
match prefix? # suffix?, filler
jyes custom
arrange alignment, =db alignment =dup (filler)
assemble alignment
exit
custom:
arrange alignment, prefix alignment suffix
assemble alignment
end calminstruction