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
|
; -*- fundamental -*- ---------------------------------------------------
;
; Copyright 2004 H. Peter Anvin - All Rights Reserved
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
; Boston MA 02111-1307, USA; either version 2 of the License, or
; (at your option) any later version; incorporated herein by reference.
;
; -----------------------------------------------------------------------
section .text
;
; initcache: Initialize the cache data structures
;
initcache:
xor eax,eax ; We don't care about sector 0
mov di,CachePtrs
mov cx,65536/SECTOR_SIZE
rep stosd
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.
;
; Assumes CS == DS.
;
getcachesector:
push cx
mov si,cache_seg
mov gs,si
mov si,CachePtrs ; Sector cache pointers
mov cx,65536/SECTOR_SIZE
.search:
cmp eax,[si]
jz .hit
add si,4
loop .search
.miss:
TRACER 'M'
; Need to load it. Highly inefficient cache replacement
; algorithm: Least Recently Written (LRW)
push bx
push es
push gs
pop es
mov bx,[NextCacheSlot]
inc bx
and bx,(1 << (16-SECTOR_SHIFT))-1
mov [NextCacheSlot],bx
shl bx,2
mov [CachePtrs+bx],eax
shl bx,SECTOR_SHIFT-2
mov si,bx
pushad
%if IS_EXTLINUX
call getonesec_ext
%else
call getonesec
%endif
popad
pop es
pop bx
pop cx
ret
.hit: ; We have it; get the pointer
TRACER 'H'
sub si,CachePtrs
shl si,SECTOR_SHIFT-2
pop cx
ret
section .latebss
alignb 4
CachePtrs resd 65536/SECTOR_SIZE ; Cached sector pointers
NextCacheSlot resw 1 ; Next cache slot to occupy
|