-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRAND.ASM
More file actions
executable file
·188 lines (144 loc) · 6.15 KB
/
RAND.ASM
File metadata and controls
executable file
·188 lines (144 loc) · 6.15 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
model tiny
codeseg
org 0
start:
dw 0ffffh,0ffffh
dw 8000h ; character device
dw entry_strategy
dw entry_interrupt
db 'RAND$ '
request_off dw 0
request_seg dw 0
commands:
dw command_0 ; 0 initialization [both]
dw command_unknown ; 1 media check [block]
dw command_unknown ; 2 build bfb [block]
dw command_unknown ; 3 ioctl input [both]
dw command_4 ; 4 input (read) [both]
dw command_unknown ; 5 nondestructive input no wait [character]
dw command_unknown ; 6 input status [character]
dw command_unknown ; 7 input flush [character]
dw command_unknown ; 8 output (write) [both]
dw command_unknown ; 9 output (write with verify) [block]
dw command_unknown ; 10 output status [character]
dw command_unknown ; 11 output flush [character]
dw command_unknown ; 12 ioctl output [both]
dw command_unknown ; 13 device open [both]
dw command_unknown ; 14 device close [both]
dw command_unknown ; 15 removable media [block]
dw command_unknown ; 16
dw command_unknown ; 17
dw command_unknown ; 18
dw command_unknown ; 19 generic ioctl request [both]
dw command_unknown ; 20
dw command_unknown ; 21
dw command_unknown ; 22
dw command_unknown ; 23 get logical device [block]
dw command_unknown ; 24 set logical device [block]
entry_strategy:
mov word ptr cs:[request_off], bx ; save request pointer
mov word ptr cs:[request_seg], es ; for use in entry_interrupt
retf
entry_interrupt:
pushf ; save state
push ax ; "
push bx ; "
push dx ; "
push di ; "
push ds ; "
lds bx, dword ptr cs:[request_off] ; load request pointer into DS:BX
mov di, word ptr [bx + 2] ; read command code
cmp di, 24 ; is it greater than 24?
ja _command_unknown ; yes, jump forward
shl di, 1 ; convert to table offset
call word ptr cs:[di + commands] ; execute command handler
jmp short _done ; jump forward
_command_unknown:
call command_unknown ; handle command as unknown
_done:
pop ds ; revert state
pop di ; "
pop dx ; "
pop bx ; "
pop ax ; "
popf ; "
retf
command_unknown:
mov word ptr [bx + 3], 8103h ; set status:
; error: 8000h
; done: 0100h
; unknown command: 0003h
ret
command_0:
mov word ptr [bx + 14], offset end_addr ; set ending address of
mov word ptr [bx + 16], cs ; program resident code
mov word ptr [bx + 3], 0100h ; set status done
ret
command_4:
push di ; clobbers DI
push ds ; clobbers DS
lds di, dword ptr [bx + 14] ; load output buffer into DS:DI
push ax ; clobbers AX
call next_rand ; get next random number
mov byte ptr [di], al ; write to output buffer
pop ax
pop ds
mov word ptr [bx + 18], 1 ; set byte count to 1
pop di
mov word ptr [bx + 3], 0100h ; set status done
ret
bits0 dw 0fffeh
bits1 db 0ffh
next_rand:
push bx
push cx
push dx
mov bx, word ptr cs:[bits0] ; tap bit 0
and bx, 1 ; "
mov al, bl ; "
mov bx, word ptr cs:[bits0] ; tap bit 2
shr bx, 1 ; "
and bl, 2 ; "
or al, bl ; "
mov bx, word ptr cs:[bits0] ; tap bit 5
shr bx, 3 ; "
and bl, 4 ; "
or al, bl ; "
mov bx, word ptr cs:[bits0] ; tap bit 9
shr bx, 6 ; "
and bl, 8 ; "
or al, bl ; "
mov bx, word ptr cs:[bits0] ; tap bit 11
shr bx, 7 ; "
and bl, 16 ; "
or al, bl ; "
mov bx, word ptr cs:[bits0] ; tap bit 14
shr bx, 9 ; "
and bl, 32 ; "
or al, bl ; "
mov bl, byte ptr cs:[bits1] ; tap bit 18
shl bl, 4 ; "
and bl, 64 ; "
or al, bl ; "
mov bl, byte ptr cs:[bits1] ; tap bit 20
shl bl, 3 ; "
and bl, 128 ; "
or al, bl ; "
mov bl, byte ptr cs:[bits1] ; xor bit 17
shr bl, 1 ; "
and bl, 1 ; "
mov cl, bl ; "
mov bl, byte ptr cs:[bits1] ; xor bit 22
shr bl, 6 ; "
and bl, 1 ; "
xor cl, bl ; "
clc ; rotate left 1 bit
rcl word ptr cs:[bits0], 1 ; "
rcl byte ptr cs:[bits1], 1 ; "
or byte ptr cs:[bits0], cl ; feed in xor result
pop dx
pop cx
pop bx
ret
end_addr:
end start