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

refactor: let FASM calculate LOG2(x) for us at compile time

This commit is contained in:
Abdur-Rahman Mansoor 2024-08-26 12:12:33 -04:00
parent e78be21c18
commit bd93b426c0
Signed by: ramenu
GPG Key ID: 8D15FCF6795779C8
2 changed files with 10 additions and 23 deletions

View File

@ -1032,9 +1032,8 @@ proc get_new_cid stdcall, pci:dword, y:dword
mov eax, [pci] mov eax, [pci]
mov eax, dword [eax + pcidev.queue_entries] mov eax, dword [eax + pcidev.queue_entries]
mov ecx, [y] mov ecx, [y]
shl ecx, SIZEOF_NVM_QUEUE_ENTRY shl ecx, LOG2 sizeof.NVM_QUEUE_ENTRY
movzx eax, word [eax + ecx + NVM_QUEUE_ENTRY.head] movzx eax, word [eax + ecx + NVM_QUEUE_ENTRY.head]
;DEBUGF DBG_INFO, "get_new_cid: %u\n", eax
ret ret
endp endp
@ -1129,7 +1128,7 @@ proc cqyhdbl_write stdcall, pci:dword, y:dword, cqh:dword
imul dx, ax imul dx, ax
add dx, 0x1000 add dx, 0x1000
mov ecx, [y] mov ecx, [y]
shl ecx, SIZEOF_NVM_QUEUE_ENTRY shl ecx, LOG2 sizeof.NVM_QUEUE_ENTRY
mov edi, dword [esi + pcidev.queue_entries] mov edi, dword [esi + pcidev.queue_entries]
lea edi, dword [edi + ecx] lea edi, dword [edi + ecx]
mov eax, [cqh] mov eax, [cqh]
@ -1164,7 +1163,7 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
mov edi, [pci] mov edi, [pci]
mov edi, dword [edi + pcidev.queue_entries] mov edi, dword [edi + pcidev.queue_entries]
movzx ebx, [y] movzx ebx, [y]
shl ebx, SIZEOF_NVM_QUEUE_ENTRY shl ebx, LOG2 sizeof.NVM_QUEUE_ENTRY
lea edi, [edi + ebx] lea edi, [edi + ebx]
;mov eax, dword [edi + NVM_QUEUE_ENTRY.cmd_ptr] ;mov eax, dword [edi + NVM_QUEUE_ENTRY.cmd_ptr]
mov edx, dword [edi + NVM_QUEUE_ENTRY.sq_ptr] mov edx, dword [edi + NVM_QUEUE_ENTRY.sq_ptr]
@ -1172,9 +1171,9 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
mov ecx, dword [esi + SQ_ENTRY.cdw0] mov ecx, dword [esi + SQ_ENTRY.cdw0]
shr ecx, 16 ; Get CID shr ecx, 16 ; Get CID
mov ebx, ecx mov ebx, ecx
shl ebx, SIZEOF_NVM_QUEUE_ENTRY shl ebx, LOG2 sizeof.NVM_QUEUE_ENTRY
add ebx, eax add ebx, eax
shl ecx, SIZEOF_SQ_ENTRY shl ecx, LOG2 sizeof.SQ_ENTRY
lea edx, [edx + ecx] lea edx, [edx + ecx]
stdcall memcpyd, edx, esi, sizeof.SQ_ENTRY / 4 stdcall memcpyd, edx, esi, sizeof.SQ_ENTRY / 4
;mov ecx, dword [ebx + NVMQCMD.mutex_ptr] ;mov ecx, dword [ebx + NVMQCMD.mutex_ptr]
@ -1245,7 +1244,7 @@ proc consume_cq_entries stdcall, pci:dword, queue:dword
push esi edi push esi edi
mov esi, [pci] mov esi, [pci]
mov ecx, [queue] mov ecx, [queue]
shl ecx, SIZEOF_NVM_QUEUE_ENTRY shl ecx, LOG2 sizeof.NVM_QUEUE_ENTRY
mov esi, dword [esi + pcidev.queue_entries] mov esi, dword [esi + pcidev.queue_entries]
lea esi, [esi + ecx] lea esi, [esi + ecx]
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head] movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]

View File

@ -8,6 +8,8 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
define LOG2 bsr
; NVMe Controller Versions ; NVMe Controller Versions
VS100 = 0x00010000 ; (v1.0.0) VS100 = 0x00010000 ; (v1.0.0)
VS110 = 0x00010100 ; (v1.1.0) VS110 = 0x00010100 ; (v1.1.0)
@ -27,10 +29,6 @@ SUPPORTED_LBADS = 9 ; KolibriOS only supports LBADS of 512, later on w
SQ_ALLOC_SIZE = 0x1000 SQ_ALLOC_SIZE = 0x1000
CQ_ALLOC_SIZE = 0x1000 CQ_ALLOC_SIZE = 0x1000
QUEUE_ALLOC_SIZE = SQ_ALLOC_SIZE + CQ_ALLOC_SIZE QUEUE_ALLOC_SIZE = SQ_ALLOC_SIZE + CQ_ALLOC_SIZE
SIZEOF_SQ_ENTRY = 6 ; log2(sizeof.SQ_ENTRY)
SIZEOF_CQ_ENTRY = 4 ; log2(sizeof.CQ_ENTRY)
SIZEOF_NVM_QUEUE_ENTRY = 4 ; log2(sizeof.NVM_QUEUE_ENTRY)
SIZEOF_NVMQCMD = 4 ; log2(sizeof.NVMQCMD)
MSIXCAP_CID = 0x11 MSIXCAP_CID = 0x11
MSIXCAP_MXE = 1 shl 15 ; MSI-X Enable bit MSIXCAP_MXE = 1 shl 15 ; MSI-X Enable bit
@ -146,8 +144,8 @@ CC_CRIME = 1 shl 24
CC_SHN_NORMAL_SHUTDOWN = 1 shl 14 CC_SHN_NORMAL_SHUTDOWN = 1 shl 14
CC_SHN_ABRUPT_SHUTDOWN = 1 shl 15 CC_SHN_ABRUPT_SHUTDOWN = 1 shl 15
CC_DEFAULT_IOSQES = SIZEOF_SQ_ENTRY shl 16 CC_DEFAULT_IOSQES = LOG2 sizeof.SQ_ENTRY shl 16
CC_DEFAULT_IOCQES = SIZEOF_CQ_ENTRY shl 20 CC_DEFAULT_IOCQES = LOG2 sizeof.CQ_ENTRY shl 20
; Completion Queue Entry Status Field Values ; Completion Queue Entry Status Field Values
CQ_PHASE_TAG = 1 shl 0 CQ_PHASE_TAG = 1 shl 0
@ -577,15 +575,5 @@ assert sizeof.IDENTC = 4096
assert sizeof.IDENTN = 4096 assert sizeof.IDENTN = 4096
assert sizeof.NSGRANLS = 288 assert sizeof.NSGRANLS = 288
assert sizeof.NVMQCMD = 16 assert sizeof.NVMQCMD = 16
assert SIZEOF_SQ_ENTRY = 6
assert SIZEOF_CQ_ENTRY = 4
assert SIZEOF_SQ_ENTRY = CC_DEFAULT_IOSQES shr 16
assert SIZEOF_CQ_ENTRY = CC_DEFAULT_IOCQES shr 20
; NOTE: DO NOT CHANGE THIS ASSERTION!
; If you do decide to change it, you'll have
; to modify the source code manually since it
; uses bit shifts to multiply by the struct size
assert sizeof.NVM_QUEUE_ENTRY = 16
assert SIZEOF_NVM_QUEUE_ENTRY = 4
; vim: syntax=fasm ; vim: syntax=fasm