1 ; -*- fundamental -*- ---------------------------------------------------
3 ; Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 ; This program is free software; you can redistribute it and/or modify
6 ; it under the terms of the GNU General Public License as published by
7 ; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ; (at your option) any later version; incorporated herein by reference.
11 ; -----------------------------------------------------------------------
16 .sector: resd 1 ; Sector number
17 .prev: resw 1 ; LRU pointer to previous (less recent)
18 .next: resw 1 ; LRU pointer to next (more recent)
22 NCacheEntries equ 65536/SECTOR_SIZE
25 ; initcache: Initialize the cache data structures
28 xor eax,eax ; We don't care about sector 0
30 mov cx,NCacheEntries+1
31 mov bx,CachePtrs+NCacheEntries*cptr_size ; "prev" pointer
33 mov [di+cptr.sector],eax ; Zero sector number
34 mov [di+cptr.prev],bx ; Previous pointer
35 mov [bx+cptr.next],di ; Previous entry's next pointer
42 ; getcachesector: Check for a particular sector (EAX) in the sector cache,
43 ; and if it is already there, return a pointer in GS:SI
44 ; otherwise load it and return said pointer.
54 mov si,CachePtrs+cptr_size ; Real sector cache pointers
68 mov bx,[CachePtrs+cptr.next] ; "Next most recent than head node"
69 mov [bx+cptr.sector],eax
71 sub bx,CachePtrs+cptr_size
72 shl bx,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address
82 ; Update LRU, then compute buffer address
85 ; Remove from current position in the list
91 ; Add to just before head node
92 mov bx,[CachePtrs+cptr.prev]
95 mov [CachePtrs+cptr.prev],si
96 mov word [si+cptr.next],CachePtrs
98 sub si,CachePtrs+cptr_size
99 shl si,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address
108 ; Each CachePtr contains:
110 ; - LRU previous pointer
112 ; The first entry is the head node of the list
114 CachePtrs resb (NCacheEntries+1)*cptr_size