2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-12-22 22:08:47 +01:00

apply some fixes

This commit is contained in:
Abdur-Rahman Mansoor 2024-07-12 13:55:44 -04:00
parent 87fa0e0e3f
commit e9de569036

View File

@ -477,11 +477,6 @@ proc build_prp_list stdcall, nprps:dword, buf_physical:dword, prp_list_ptr:dword
; its important to cache the value
mov dword [esp + 12], 0
; the pointer to our PRP list (virtual), needed so
; that the caller can free the PRP list afterwards
mov ebx, [prp_list_ptr]
mov dword [ebx], 0
xor edi, edi
xor esi, esi
mov ecx, [nprps]
@ -494,7 +489,8 @@ proc build_prp_list stdcall, nprps:dword, buf_physical:dword, prp_list_ptr:dword
jz .err
mov dword [esp + 12], eax
mov edi, eax
mov dword [ebx], eax
mov eax, [prp_list_ptr]
mov dword [eax], edi
; note we assume buf_physical is page-aligned
mov esi, [buf_physical]
@ -549,12 +545,18 @@ proc build_prp_list stdcall, nprps:dword, buf_physical:dword, prp_list_ptr:dword
endp
proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, nprps_ptr:dword, buf:dword
proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, prp_list_ptr:dword, buf:dword
push esi edi
mov edi, [prps_ptr]
mov dword [edi], 0 ; PRP1 default value
mov dword [edi + 4], 0 ; PRP2 default value
; the pointer to our PRP list (virtual), needed so
; that the caller can free the PRP list afterwards
mov edi, [prp_list_ptr]
mov dword [edi], 0
mov dword [edi + 4], 0
mov eax, [buf]
invoke GetPhysAddr
mov dword [edi], eax
@ -606,13 +608,10 @@ proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, nprps_ptr:d
inc eax
@@:
mov esi, [nprps_ptr]
dec eax
mov dword [esi], eax
mov edx, dword [edi]
and edx, PAGE_SIZE - 1
add edx, PAGE_SIZE
stdcall build_prp_list, eax, edx
stdcall build_prp_list, eax, edx, [prp_list_ptr]
test eax, eax
jz .err
DEBUGF DBG_INFO, "Successfully allocated PRP list at: %x\n", eax
@ -643,13 +642,19 @@ proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors
push ebx esi edi
sub esp, 20
; stack:
; [esp] - PRP1
; [esp + 4] - PRP2
; [esp + 8] - command type (read or write)
; [esp + 12] - original numsectors value
; [esp + 16] - virtual pointer to PRP2 PRP list (if allocated, 0 if not)
mov ebx, esp
mov eax, [numsectors_ptr]
mov eax, dword [eax]
DEBUGF DBG_INFO, "buf: %x, start_sector: %x%x\n, numsectors: %u", [buf], [start_sector + 4], [start_sector], eax
DEBUGF DBG_INFO, "buf: %x, start_sector: %x%x, numsectors: %u", [buf], [start_sector + 4], [start_sector], eax
mov dword [ebx + 8], edx ; command type (read or write)
mov dword [ebx + 12], eax ; save original numsectors value
mov dword [ebx + 16], 0 ; nPRPs for PRP list
mov esi, [ns]
mov edi, [buf]
@ -657,12 +662,15 @@ proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors
mov edx, [edx]
mov ecx, ebx
add ecx, 16
; Note that [esp] will contain the value of PRP1 and [esp + 4] will
; contain the value of PRP2 (after this call, if it completes successfully)
; contain the value of PRP2. If PRP2 is a PRP list, then [esp + 16] will point
; to the allocated PRP list (after this call, only if it completes successfully)
stdcall alloc_dptr, esi, ebx, edx, ecx, [buf]
test eax, eax
jz .dptr_fail
DEBUGF DBG_INFO, "PRP1: %x, PRP2: %x, nPRPs for PRP list: %u\n", [ebx], [ebx + 4], [ebx + 16]
DEBUGF DBG_INFO, "PRP1: %x, PRP2: %x\n", [ebx], [ebx + 4]
stdcall nvme_io_rw, [esi + NSINFO.pci], \
1, \
[esi + NSINFO.nsid], \
@ -674,6 +682,7 @@ proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors
dword [ebx + 8]
; assume command completes successfully for now
jmp .end
.dptr_fail:
mov ebx, [numsectors_ptr]