More sophisticated alpha blending; comment out background call ATM
[syslinux.git] / cache.inc
blobe2595a211b65a5470fa47cb781ca4583b4dad401
1 ; -*- fundamental -*- ---------------------------------------------------
3 ;   Copyright 2004 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 ; -----------------------------------------------------------------------
13                 section .text
15 ; initcache: Initialize the cache data structures
17 initcache:
18                 xor eax,eax                     ; We don't care about sector 0
19                 mov di,CachePtrs
20                 mov cx,65536/SECTOR_SIZE
21                 rep stosd
22                 ret
26 ; getcachesector: Check for a particular sector (EAX) in the sector cache,
27 ;                 and if it is already there, return a pointer in GS:SI
28 ;                 otherwise load it and return said pointer.
30 ;               Assumes CS == DS.
32 getcachesector:
33                 push cx
34                 mov si,cache_seg
35                 mov gs,si
36                 mov si,CachePtrs        ; Sector cache pointers
37                 mov cx,65536/SECTOR_SIZE
38 .search:
39                 cmp eax,[si]
40                 jz .hit
41                 add si,4
42                 loop .search
44 .miss:
45                 TRACER 'M'
46                 ; Need to load it.  Highly inefficient cache replacement
47                 ; algorithm: Least Recently Written (LRW)
48                 push bx
49                 push es
50                 push gs
51                 pop es
52                 mov bx,[NextCacheSlot]
53                 inc bx
54                 and bx,(1 << (16-SECTOR_SHIFT))-1
55                 mov [NextCacheSlot],bx
56                 shl bx,2
57                 mov [CachePtrs+bx],eax
58                 shl bx,SECTOR_SHIFT-2
59                 mov si,bx
60                 pushad
61 %if IS_EXTLINUX
62                 call getonesec_ext
63 %else
64                 call getonesec
65 %endif
66                 popad
67                 pop es
68                 pop bx
69                 pop cx
70                 ret
72 .hit:           ; We have it; get the pointer
73                 TRACER 'H'
74                 sub si,CachePtrs
75                 shl si,SECTOR_SHIFT-2
76                 pop cx
77                 ret
79                 section .latebss
80                 alignb 4
81 CachePtrs       resd 65536/SECTOR_SIZE  ; Cached sector pointers
82 NextCacheSlot   resw 1                  ; Next cache slot to occupy