-
Notifications
You must be signed in to change notification settings - Fork 0
/
ata.asm
137 lines (108 loc) · 2.54 KB
/
ata.asm
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
[bits 32]
extern _blockAddr
extern _At
global _read
global _write
_read:
pushfd
and eax , 0x0FFFFFFF
push eax
push ebx
push ecx
push edx
push edi
mov eax , [_blockAddr]
mov cl , 1
mov edi , _At
mov ebx , eax
mov edx , 0x01F6
shr eax , 24
or al , 11100000b ; Sets bit 6 in al for LBA mode
out dx , al
mov edx , 0x01F2 ; Port to send number of sectors
mov al , cl ; Get number of sectors from CL
out dx , al
mov edx , 0x1F3 ; Port to send bit 0 - 7 of LBA
mov eax , ebx ; Get LBA from EBX
out dx , al
mov edx , 0x1F4 ; Port to send bit 8 - 15 of LBA
mov eax , ebx ; Get LBA from EBX
shr eax , 8 ; Get bit 8 - 15 in AL
out dx , al
mov edx , 0x1F5 ; Port to send bit 16 - 23 of LBA
mov eax , ebx ; Get LBA from EBX
shr eax , 16 ; Get bit 16 - 23 in AL
out dx , al
mov edx , 0x1F7 ; Command port
mov al , 0x20 ; Read with retry.
out dx , al
.loop1:
in al , dx
test al , 8
jz .loop1
mov eax , 256 ; Read 256 words , 1 sector
xor bx , bx
mov bl , cl ; read CL sectors
mul bx
mov ecx , eax
mov edx , 0x1F0
rep insw ; copy to [RDI]
pop edi
pop edx
pop ecx
pop ebx
pop eax
popfd
ret
_write:
pushfd
and eax , 0x0FFFFFFF
push eax
push ebx
push ecx
push edx
push edi
mov eax , [_blockAddr]
mov cl , 1
mov edi , _At
mov ebx , eax
mov edx , 0x01F6
shr eax , 24
or al , 11100000b ; Set bit 6 in al for LBA mode
out dx , al
mov edx , 0x01F2 ; Port to send number of sectors
mov al , cl ; Get number of sectors from CL
out dx , al
mov edx , 0x1F3 ; Port to send bit 0 - 7 of LBA
mov eax , ebx ; Get LBA from EBX
out dx , al
mov edx , 0x1F4 ; Port to send bit 8 - 15 of LBA
mov eax , ebx ; Get LBA from EBX
shr eax , 8 ; Get bit 8 - 15 in AL
out dx , al
mov edx , 0x1F5 ; Port to send bit 16 - 23 of LBA
mov eax , ebx ; Get LBA from EBX
shr eax , 16 ; Get bit 16 - 23 in AL
out dx , al
mov edx , 0x1F7 ; Command port
mov al , 0x30 ; Write with retry.
out dx , al
.loop2:
in al , dx
test al , 8
jz .loop2
mov eax , 256 ; Read 256 words , 1 sector
xor bx , bx
mov bl , cl ; write CL sectors
mul bx
mov ecx , eax
mov edx , 0x1F0
mov esi , edi
rep outsw ; go out
pop edi
pop edx
pop ecx
pop ebx
pop eax
popfd
ret