Disable the Cache(s)Assembler/80486

This gem disables cache(s) on a 486 or Pentium processor. It may disable the Pentium Pro caches also but it is not certain. Since I do not know who wrote this gem I do not know if it works on a Pentium Pro or Intel clones.
Please note that due to the protection schemes incorporated into the 486 and Pentium processors, it will NOT work in virtual 8086 mode. The gem was found in Tenie Remmel's Assembly Snippets. Also note that I (John Eckerdal) am not the author.

;
; Disable the Cache(s)
;
; input:
;   none
;
; output:
;   none
;
; destroys:
;   noting - (except switching flags)
;

CR0_CD  EQU     040000000h      ; Cache Disable bit of CR0
CR0_NW  EQU     020000000h      ; Not Write-through bit of CR0

        pushf                   ; save the flags
        push    eax             ; save eax
        cli                     ; disable interrupts while we do this
        mov     eax,cr0         ; read CR0
        or      eax,CR0_CD      ; set CD but not NW bit of CR0
        mov     cr0,eax         ; cache is now disabled
        wbinvd                  ; flush and invalidate cache

        ; the cache is effectively disabled at this point, but memory
        ; consistency will be maintained. To completely disable cache,
        ; the following two lines may used as well:

        or      eax,CR0_NW      ; now set the NW bit
        mov     cr0,eax         ; turn off the cache entirely
        pop     eax             ; restore eax
        popf                    ; restore the flags
        ret                     ; return to caller
Gem writer: John Eckerdal
last updated: 1998-03-16