section .text
struc cptr
-.sector: resd 1 ; Sector number
-.prev: resw 1 ; LRU pointer to previous (less recent)
-.next: resw 1 ; LRU pointer to next (more recent)
+.sector: resd 1 ; Sector number
+.prev: resw 1 ; LRU pointer to previous (less recent)
+.next: resw 1 ; LRU pointer to next (more recent)
endstruc
cptr_size_lg2 equ 3
ret
;
-; cache_remove_lru:
-; Remove a cache block from the expiry list. Can be used to
-; lock down a cache block for future use.
-;
-; SI = cache block offset (any offset inside the block is OK)
-; Assumes CS == DS
-;
-cache_remove_lru:
- pusha
-
- ; Get metadata pointer
- shr si,SECTOR_SHIFT-cptr_size_lg2
- add si,CachePtrs+cptr_size
-
- mov bx,[si+cptr.prev]
- mov di,[si+cptr.next]
- mov [bx+cptr.next],di
- mov [di+cptr.prev],bx
-
- popa
- ret
-
-;
-; cache_add_lru:
-; Add back a cache block to the expiry chain that was removed.
-;
-; SI = cache block offset (any offset inside the block is OK)
-; Assumes CS == DS
-;
-cache_add_lru:
- pusha
-
- ; Get metadata pointer
- shr si,SECTOR_SHIFT-cptr_size_lg2
- add si,CachePtrs+cptr_size
-
- mov bx,[CachePtrs+cptr.prev]
- mov [si+cptr.prev],bx
- mov [bx+cptr.next],si
- mov [CachePtrs+cptr.prev],si
- mov word [si+cptr.next],CachePtrs
-
- popa
- ret
-
-;
; getcachesector: Check for a particular sector (EAX) in the sector cache,
; and if it is already there, return a pointer in GS:SI
; otherwise load it and return said pointer.
; Update LRU, then compute buffer address
TRACER 'H'
- sub si,CachePtrs+cptr_size
- shl si,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address
-
; Remove from current position in the list
- call cache_remove_lru
+ mov bx,[si+cptr.prev]
+ mov di,[si+cptr.next]
+ mov [bx+cptr.next],di
+ mov [di+cptr.prev],bx
; Add to just before head node
- call cache_add_lru
+ mov bx,[CachePtrs+cptr.prev]
+ mov [si+cptr.prev],bx
+ mov [bx+cptr.next],si
+ mov [CachePtrs+cptr.prev],si
+ mov word [si+cptr.next],CachePtrs
+
+ sub si,CachePtrs+cptr_size
+ shl si,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address
pop di
pop bx