-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache-control.lisp
66 lines (62 loc) · 2.31 KB
/
cache-control.lisp
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
(defpackage #:psx-cache-control
(:nicknames #:cache-control)
(:use :cl)
(:export #:cache-control #:make-cache-control #:write-cache-control
#:read-cache-control #:cache-control-code-cache-enabled
#:cache-control-scratchpad-enable-1))
(in-package :psx-cache-control)
(declaim (optimize (speed 3) (safety 1)))
(defstruct cache-control
(0-2-unknown 0 :type (unsigned-byte 3))
(scratchpad-enable-1 nil :type boolean)
(4-5-unknown 0 :type (unsigned-byte 2))
(scratchpad-enable-2 nil :type boolean)
(8-unknown 0 :type (unsigned-byte 1))
(crash-if-code-cache-enabled nil :type boolean)
(code-cache-enabled nil :type boolean))
(declaim (ftype (function (cache-control (unsigned-byte 32)))
write-cache-control))
(defun write-cache-control (cache-control value)
(setf (cache-control-0-2-unknown cache-control)
(ldb (byte 3 0) value))
(setf (cache-control-scratchpad-enable-1 cache-control)
(ldb-test (byte 1 3) value))
(setf (cache-control-4-5-unknown cache-control)
(ldb (byte 2 4) value))
(setf (cache-control-scratchpad-enable-2 cache-control)
(ldb-test (byte 1 7) value))
(setf (cache-control-8-unknown cache-control)
(ldb (byte 1 8) value))
(setf (cache-control-crash-if-code-cache-enabled cache-control)
(ldb-test (byte 1 9) value))
(setf (cache-control-code-cache-enabled cache-control)
(ldb-test (byte 1 11) value))
(when (and (ldb-test (byte 1 11) value)
(ldb-test (byte 1 9) value))
(error "Cache control has set both code cache and the crash bit!~%"))
(values))
(declaim (ftype (function (cache-control)
(unsigned-byte 32))
read-cache-control))
(defun read-cache-control (cache-control)
(logior
(ash (cache-control-0-2-unknown cache-control) 0)
(ash (if (cache-control-scratchpad-enable-1 cache-control)
1
0)
3)
(ash (cache-control-4-5-unknown cache-control) 4)
(ash (if (cache-control-scratchpad-enable-2 cache-control)
1
0)
7)
(ash (cache-control-8-unknown cache-control) 8)
(ash (if (cache-control-crash-if-code-cache-enabled cache-control)
1
0)
9)
(ash 0 10)
(ash (if (cache-control-code-cache-enabled cache-control)
1
0)
11)))