1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
; Copyright reserved by SRC
4
; Author Jun Sawada, University of Texas at Austin
5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;; This file includes various underlying definition for ISA and
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
(include-book "../../../../../data-structures/array1")
14
(include-book "../../../../../data-structures/deflist")
15
(include-book "../../../../../data-structures/list-defthms")
16
(include-book "../../../../../data-structures/structures")
19
(include-book "trivia")
20
(include-book "b-ops-aux")
22
(deflabel begin-basic-def)
24
(defconst *addr-size* 16)
25
(defconst *page-offset-size* 10)
27
(defconst *rname-size* 4)
28
(defconst *immediate-size* 8)
29
(defconst *opcode-size* 4)
30
(defconst *word-size* 16)
31
(defconst *max-word-value* (expt 2 *word-size*))
32
(defconst *num-regs* (expt 2 *rname-size*))
33
(defconst *num-mem-words* (expt 2 *addr-size*))
34
(defconst *num-page-words* (expt 2 *page-offset-size*))
35
(defconst *num-pages* (expt 2 (- *addr-size* *page-offset-size*)))
36
(defbytetype word *word-size* :unsigned)
37
(defbytetype addr *addr-size* :unsigned)
38
(defbytetype rname *rname-size* :unsigned)
39
(defbytetype immediate *immediate-size* :unsigned)
40
(defbytetype opcd *opcode-size* :unsigned)
43
(implies (word-p word)
46
(< word *max-word-value*)))
47
:hints (("Goal" :in-theory (enable word-p)))
48
:rule-classes :forward-chaining)
51
(implies (rname-p rname)
54
(< rname *num-regs*)))
55
:hints (("Goal" :in-theory (enable rname-p)))
56
:rule-classes :forward-chaining)
62
(< ad *num-mem-words*)))
63
:hints (("Goal" :in-theory (enable addr-p)))
64
:rule-classes :forward-chaining)
66
(defthm addr-word-double-casting
67
(equal (addr (word i)) (addr i))
68
:hints (("goal" :in-theory (enable addr word))))
70
(defthm word-addr-double-casting
71
(equal (word (addr i)) (word i))
72
:hints (("goal" :in-theory (enable addr word))))
76
(implies (addr-p x) (equal (word x) x))
77
:hints (("goal" :in-theory (enable addr-p word))))
80
(implies (word-p x) (equal (addr x) x))
81
:hints (("goal" :in-theory (enable addr word-p))))
83
(in-theory (disable word-addr-p addr-word-p))
86
(implies (and (word-p val1) (word-p val2))
87
(word-p (logand val1 val2)))
88
:hints (("Goal" :in-theory (enable word-p))))
91
(implies (and (word-p val1) (word-p val2))
92
(word-p (logxor val1 val2)))
93
:hints (("Goal" :in-theory (enable word-p))))
96
(implies (and (word-p val1) (word-p val2))
97
(word-p (logior val1 val2)))
98
:hints (("Goal" :in-theory (enable word-p))))
100
(defthm word-p-bv-eqv-iff-equal
101
(implies (and (word-p wd0) (word-p wd1))
102
(equal (b1p (bv-eqv *word-size* wd0 wd1)) (equal wd0 wd1)))
103
:hints (("Goal" :in-theory (enable word-p))))
105
(defthm addr-p-bv-eqv-iff-equal
106
(implies (and (addr-p wd0) (addr-p wd1))
107
(equal (b1p (bv-eqv *addr-size* wd0 wd1)) (equal wd0 wd1)))
108
:hints (("Goal" :in-theory (enable addr-p))))
110
(defthm rname-p-bv-eqv-iff-equal
111
(implies (and (rname-p wd0) (rname-p wd1))
112
(equal (b1p (bv-eqv *rname-size* wd0 wd1)) (equal wd0 wd1)))
113
:hints (("Goal" :in-theory (enable rname-p))))
115
(defthm immediate-p-bv-eqv-iff-equal
116
(implies (and (immediate-p wd0) (immediate-p wd1))
117
(equal (b1p (bv-eqv *immediate-size* wd0 wd1)) (equal wd0 wd1)))
118
:hints (("Goal" :in-theory (enable immediate-p))))
120
(defthm opcd-p-bv-eqv-iff-equal
121
(implies (and (opcd-p wd0) (opcd-p wd1))
122
(equal (b1p (bv-eqv *opcode-size* wd0 wd1)) (equal wd0 wd1)))
123
:hints (("Goal" :in-theory (enable opcd-p))))
126
(deflist word-listp (l)
127
(declare (xargs :guard t))
130
(defun fixlen-word-listp (n lst)
131
"test if list is a array of n words."
132
(declare (xargs :guard (and (integerp n) (<= 0 n))))
133
(and (word-listp lst) (equal (len lst) n)))
135
(defthm fixlen-word-true-listp
136
(implies (fixlen-word-listp n x)
138
:rule-classes :forward-chaining)
140
(in-theory (disable fixlen-word-listp))
142
; Register file is a fixed lenghth true list of words.
144
(declare (xargs :guard t))
145
(fixlen-word-listp *num-regs* regs))
147
(defthm regs-p-true-listp
150
:rule-classes :forward-chaining)
153
(defun read-reg (num regs)
154
(declare (xargs :guard (and (rname-p num) (regs-p regs))))
157
(defun write-reg (val num regs)
158
(declare (xargs :guard (and (word-p val) (rname-p num) (regs-p regs))))
159
(update-nth num val regs))
161
(defthm regs-p-write-reg
162
(implies (and (word-p word)
165
(regs-p (write-reg word rname regs)))
166
:hints (("Goal" :in-theory (enable regs-p fixlen-word-listp
167
rname-p UNSIGNED-BYTE-P
171
(defthm nth-content-word-listp
172
(implies (and (integerp n)
176
(and (integerp (nth n lst))
177
(acl2-numberp (nth n lst))))
178
:hints (("Goal" :use ((:instance word-listp-nth (n0 n) (l lst)))
179
:in-theory (disable word-listp-nth)))))
182
(defthm numberp-read-reg
183
(implies (and (regs-p regs)
185
(and (integerp (read-reg rname regs))
186
(acl2-numberp (read-reg rname regs))))
187
:hints (("Goal" :in-theory (enable rname-p regs-p fixlen-word-listp)))
189
((:type-prescription) (:rewrite)))
191
(defthm word-p-read-reg
192
(implies (and (regs-p regs)
194
(word-p (read-reg rname regs)))
195
:hints (("Goal" :in-theory (enable rname-p regs-p fixlen-word-listp)))
198
(:type-prescription :corollary
199
(implies (and (regs-p regs) (rname-p rname))
200
(integerp (read-reg rname regs)))
201
:hints (("goal" :in-theory (enable word-p unsigned-byte-p))))))
203
(defthm read-reg-write-reg
204
(implies (and (rname-p rn1)
207
(equal (read-reg rn1 (write-reg val rn2 regs))
208
(if (equal rn1 rn2) val (read-reg rn1 regs))))
209
:hints (("Goal" :in-theory (enable read-reg write-reg regs-p
212
(in-theory (disable regs-p write-reg read-reg))
214
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
215
;; Here we define the memory system.
216
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
217
(defconst *no-access* 0)
218
(defconst *read-only* 1)
219
(defconst *read-write* 2)
221
;; Definition of Address Transformer
222
;; page-num Address --> Page number
223
;; page-offset Address --> Page Offset
224
(defun page-num (addr)
225
(declare (xargs :guard (addr-p addr)))
226
(floor addr *num-page-words*))
228
(defun page-offset (addr)
229
(declare (xargs :guard (addr-p addr)))
230
(mod addr *num-page-words*))
232
(defthm page-num-type
233
(implies (addr-p addr)
234
(and (integerp (page-num addr))
235
(<= 0 (page-num addr))))
236
:rule-classes :type-prescription)
238
(defthm page-num-bound
239
(implies (addr-p addr)
240
(< (page-num addr) *num-pages*))
241
:hints (("Goal" :in-theory (enable addr-p unsigned-byte-p)))
242
:rule-classes :linear)
244
(defthm page-offset-type
245
(implies (addr-p addr)
246
(and (integerp (page-offset addr))
247
(<= 0 (page-offset addr))))
248
:rule-classes :type-prescription)
250
(defthm page-offset-bound
251
(implies (addr-p addr)
252
(< (page-offset addr) *num-page-words*))
253
:rule-classes :linear)
255
(in-theory (disable page-num page-offset))
256
;; End of Address Transformer
259
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260
; Definition of Memory Object
261
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262
; Check if page is an array representing a page.
263
; Addr does not affect the value, but if the correct page tag is given,
264
; execution is faster.
265
(defun word-array-p (array)
266
(declare (xargs :guard (alistp array)
268
(cond ((endp array) t)
269
((equal (caar array) ':header) (word-array-p (cdr array)))
270
(t (and (word-p (cdar array))
271
(word-array-p (cdr array))))))
273
(verify-guards word-array-p
274
:hints (("Goal" :in-theory (enable alistp))))
276
(defun page-array-p (tag page-array)
277
(declare (xargs :guard t))
278
(and (array1p tag page-array)
279
(equal (car (dimensions tag page-array)) *num-page-words*)
280
(word-p (default tag page-array))
281
(word-array-p page-array)))
284
(tag (:assert (symbolp tag) :rewrite))
285
(mode (:assert (integerp mode) :rewrite))
286
(array (:assert (page-array-p tag array) :rewrite))
289
(defun mem-array-p (array)
290
(declare (xargs :guard (alistp array)
292
(cond ((endp array) t)
293
((equal (caar array) ':header) (mem-array-p (cdr array)))
294
(t (and (let ((page (cdar array)))
296
(or (equal page *no-access*) (equal page *read-only*)
297
(equal page *read-write*))
299
(mem-array-p (cdr array))))))
301
(verify-guards mem-array-p :hints (("Goal" :in-theory (enable alistp))))
304
(declare (xargs :guard t))
305
(and (array1p 'mem mem)
306
(equal (car (dimensions 'mem mem)) *num-pages*)
307
(equal (default 'mem mem) *no-access*)
310
(in-theory (disable word-array-p page-array-p mem-array-p mem-p))
315
:hints (("Goal" :in-theory (enable page-p)))
316
:rule-classes :compound-recognizer)
319
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
320
; Definition of Read-mem
321
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322
(defmacro get-page (n mem)
323
`(aref1 'mem ,mem ,n))
325
(defmacro set-page (page n mem)
326
`(aset1 'mem ,mem ,n ,page))
328
(defun read-page (offset page)
329
(declare (xargs :guard (and (page-p page)
330
(integerp offset) (<= 0 offset)
331
(< offset *num-page-words*))
333
(aref1 (page-tag page) (page-array page) offset))
336
(defun read-mem (addr mem)
337
(declare (xargs :guard (and (addr-p addr) (mem-p mem))
339
(let ((page (get-page (page-num addr) mem)))
342
(read-page (page-offset addr) page))))
344
;(verify-guards get-page
345
; :hints (("Goal" :in-theory (enable mem-p))))
347
(verify-guards read-page
348
:hints (("Goal" :in-theory (enable page-p page-array-p))))
352
(defthm page-p-assoc-mem-array
353
(implies (and (mem-array-p mem)
356
(not (integerp (cdr (assoc pn mem)))))
357
(page-p (cdr (assoc pn mem))))
358
:hints (("Goal" :in-theory (enable assoc mem-array-p)))))
361
(defthm integerp-default-in-mem-array
363
(integerp (default 'mem mem)))
364
:hints (("Goal" :in-theory (enable mem-p)))))
366
(defthm page-p-get-page
367
(implies (and (mem-p mem)
369
(not (integerp (get-page pn mem))))
370
(page-p (get-page pn mem)))
371
:hints (("Goal" :in-theory (enable aref1 mem-p))))
375
(defthm word-p-assoc-word-array
376
(implies (and (word-array-p wa)
379
(word-p (cdr (assoc pn wa))))
380
:hints (("Goal" :in-theory (enable word-array-p assoc)))))
383
(defthm word-p-read-page
384
(implies (and (page-p page)
386
(word-p (read-page offset page)))
387
:hints (("Goal" :in-theory (enable page-p aref1 page-array-p))))
390
(in-theory (disable read-page read-mem))
391
(verify-guards read-mem
392
:hints (("goal" :in-theory (enable mem-p))))
394
(defthm word-p-read-mem
395
(implies (and (mem-p mem)
397
(word-p (read-mem addr mem)))
398
:hints (("Goal" :in-theory (enable read-mem)))
401
(:type-prescription :corollary
402
(implies (and (mem-p mem) (addr-p addr))
403
(and (integerp (read-mem addr mem))
404
(>= (read-mem addr mem) 0))))
406
(implies (and (mem-p mem) (addr-p addr))
407
(acl2-numberp (read-mem addr mem))))))
411
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412
; Definition of Write-Mem
413
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414
; Page tag is calculated for fast array access.
415
; The tag for the <n>'th page is given by page<n>.
416
(defun gen-page-tag (page-num)
417
(declare (xargs :guard (and (integerp page-num)
421
(coerce (append (coerce (symbol-name 'page) 'list)
422
(explode-nonnegative-integer page-num 10 nil))
427
(defthm character-listp-explode-nonnegative-integer-help
428
(implies (and (integerp n) (>= n 0)
430
(character-listp (explode-nonnegative-integer n print-base x)))
431
:hints (("goal" :in-theory (enable explode-nonnegative-integer
435
(defthm character-listp-explode-nonnegative-integer
436
(implies (and (integerp n) (>= n 0))
437
(character-listp (explode-nonnegative-integer n print-base nil)))))
439
; Renamed by Matt K. after Version 4.3, since a similar :type-prescription
440
; lemma is now provided by the ACL2 system. Perhaps it could be deleted now.
442
(defthm true-listp-explode-nonnegative-integer-rewrite
443
(implies (true-listp x)
444
(true-listp (explode-nonnegative-integer n print-base x)))))
446
(verify-guards gen-page-tag
447
:hints (("goal" :in-theory (enable U::coerce-string-designator-list
448
U::STRING-DESIGNATOR-LISTP
453
(defun init-page (page-num mode)
454
(declare (xargs :guard (and (integerp page-num) (<= 0 page-num)
457
(let ((name (gen-page-tag page-num)))
460
(compress1 name `((:header :name ,name
461
:dimensions (,*num-page-words*)
463
:maximum-length 4096))))))
465
(verify-guards init-page
466
:hints (("Goal" :in-theory (enable array1p alistp
470
bounded-integer-alistp))))
472
(defun write-page (val offset page)
473
(declare (xargs :guard (and (word-p val)
474
(integerp offset) (<= 0 offset)
475
(< offset *num-page-words*)
479
:array (aset1 (page-tag page) (page-array page) offset val)))
481
(defun write-mem (val addr mem)
482
(declare (xargs :guard (and (word-p val) (addr-p addr) (mem-p mem))
484
(let ((page (get-page (page-num addr) mem)))
486
(let ((p (init-page (page-num addr) page)))
487
(set-page (write-page val (page-offset addr) p)
490
(set-page (write-page val (page-offset addr) page)
494
(verify-guards write-page
495
:hints (("Goal" :in-theory (enable page-p page-array-p))))
497
(in-theory (disable write-mem init-page gen-page-tag write-page))
500
(defthm page-p-init-page
501
(implies (integerp mode)
502
(page-p (init-page pn mode)))
503
:hints (("goal" :in-theory (enable page-p init-page page-array-p
505
header array1p word-array-p))))
507
(verify-guards write-mem
508
:hints (("Goal" :in-theory (enable mem-p ))))
511
(defthm word-array-p-compress11
512
(implies (and (array1p tag array)
515
(word-array-p (compress11 tag array i dim default)))
516
:hints (("Goal" :in-theory (enable word-array-p)))))
519
; Added by Matt K. for Version 3.1, 7/1/06, to support proof of
520
; compress1-assoc-property-0 in light of addition of reverse-sorted and
521
; unsorted ACL2 arrays:
523
(defthm word-array-p-revappend
524
(equal (word-array-p (revappend x y))
525
(and (word-array-p x)
527
:hints (("Goal" :in-theory (enable word-array-p)
528
:induct (revappend x y)))))
530
(defthm word-array-p-compress1
531
(implies (and (array1p tag array)
532
(word-array-p array))
533
(word-array-p (compress1 tag array)))
534
:hints (("Goal" :in-theory (enable compress1 word-array-p))))
536
(defthm word-array-p-aset1
537
(implies (and (array1p tag page-array)
538
(word-array-p page-array)
541
(> (car (dimensions tag page-array)) index)
543
(word-array-p (aset1 tag page-array index val)))
544
:hints (("goal" :in-theory (enable aset1 word-array-p ARRAY1P-CONS))))
546
(defthm page-array-p-aref1
547
(implies (and (page-array-p tag page-array)
551
(> *num-page-words* offset))
552
(page-array-p tag (aset1 tag page-array offset val)))
553
:hints (("Goal" :in-theory (enable page-array-p))))
556
(defthm page-p-write-page
557
(implies (and (word-p val)
560
(> *num-page-words* offset)
562
(page-p (write-page val offset page)))
563
:hints (("Goal" :in-theory (enable write-page))))
566
(defthm valid-integer-assoc-mem-array
567
(implies (and (mem-array-p ma)
570
(integerp (cdr (assoc pn ma)))
571
(not (equal (cdr (assoc pn ma)) 0))
572
(not (equal (cdr (assoc pn ma)) 1)))
573
(equal (cdr (assoc pn ma)) 2))
574
:hints (("Goal" :in-theory (enable mem-array-p assoc)))))
577
(defthm page-p-assoc-mem-array
578
(implies (and (mem-array-p ma)
581
(not (integerp (cdr (assoc pn ma)))))
582
(page-p (cdr (assoc pn ma))))
583
:hints (("Goal" :in-theory (enable mem-array-p assoc)))))
587
(defthm mem-array-p-compress11
588
(implies (and (array1p tag array)
591
(mem-array-p (compress11 tag array i dim default)))
592
:hints (("Goal" :in-theory (enable mem-array-p compress1)))))
594
; Added by Matt K. for Version 3.1, 7/1/06, to support proof of
595
; compress1-assoc-property-0 in light of addition of reverse-sorted and
596
; unsorted ACL2 arrays:
598
(defthm mem-array-p-revappend
599
(equal (mem-array-p (revappend x y))
602
:hints (("Goal" :in-theory (enable mem-array-p)
603
:induct (revappend x y)))))
605
(defthm mem-array-p-compress1
606
(implies (and (array1p tag array)
608
(mem-array-p (compress1 tag array)))
609
:hints (("Goal" :in-theory (enable mem-array-p compress1))))
613
(defthm mem-array-p-aset1
614
(implies (and (array1p tag mem-array)
615
(mem-array-p mem-array)
617
(equal page *no-access*)
618
(equal page *read-only*)
619
(equal page *read-write*))
622
(> (car (dimensions tag mem-array)) pn))
623
(mem-array-p (aset1 tag mem-array pn page)))
624
:hints (("Goal" :in-theory (enable mem-array-p aset1))))
627
(defthm mem-p-write-mem
628
(implies (and (word-p val)
631
(mem-p (write-mem val addr mem)))
632
:hints (("goal" :in-theory (enable mem-p write-mem))))
634
(defthm page-num-offset-extionsionality
635
(implies (and (addr-p addr1)
637
(equal (page-num addr1) (page-num addr2))
638
(equal (page-offset addr1) (page-offset addr2)))
640
:hints (("Goal" :in-theory (enable addr-p page-num page-offset)))
642
((:rewrite :corollary
643
(implies (and (addr-p addr1)
645
(equal (page-num addr1) (page-num addr2))
646
(not (equal addr1 addr2)))
647
(equal (equal (page-offset addr1) (page-offset addr2))
650
(defthm read-page-init-page
651
(implies (integerp offset)
652
(equal (read-page offset (init-page pn mode)) 0))
653
:hints (("Goal" :in-theory (enable init-page read-page aref1
657
(defthm read-page-write-page
658
(implies (and (page-p page)
661
(> *num-page-words* offset1)
664
(> *num-page-words* offset2))
665
(equal (read-page offset1 (write-page val offset2 page))
666
(if (equal offset1 offset2)
668
(read-page offset1 page))))
669
:hints (("Goal" :in-theory (enable page-p read-page write-page
673
(defthm read-mem-write-mem
674
(implies (and (addr-p ad1)
677
(equal (read-mem ad1 (write-mem val ad2 mem))
678
(if (equal ad1 ad2) val (read-mem ad1 mem))))
679
:hints (("Goal" :in-theory (enable read-mem write-mem
683
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
684
; Definition of Protection Check.
685
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
686
(defun readable-addr-p (ad mem)
687
(declare (xargs :guard (and (addr-p ad) (mem-p mem))
689
(let ((page (get-page (page-num ad) mem)))
691
(or (equal page *read-only*)
692
(equal page *read-write*))
693
(or (equal (page-mode page) *read-only*)
694
(equal (page-mode page) *read-write*)))))
696
(verify-guards readable-addr-p
697
:hints (("Goal" :in-theory (enable mem-p))))
699
(defun readable-addr? (ad mem)
700
(declare (xargs :guard (and (addr-p ad) (mem-p mem))))
701
(if (readable-addr-p ad mem) 1 0))
703
(defthm bitp-readable-addr (bitp (readable-addr? ad mem)))
705
(defun writable-addr-p (ad mem)
706
(declare (xargs :guard (and (addr-p ad) (mem-p mem))
708
(let ((page (get-page (page-num ad) mem)))
710
(equal page *read-write*)
711
(equal (page-mode page) *read-write*))))
713
(verify-guards writable-addr-p
714
:hints (("Goal" :in-theory (enable mem-p))))
716
(defun writable-addr? (ad mem)
717
(declare (xargs :guard (and (addr-p ad) (mem-p mem))))
718
(if (writable-addr-p ad mem) 1 0))
720
(defthm bitp-writable-addr (bitp (writable-addr? ad mem)))
722
(defun set-page-mode (mode pn mem)
723
(declare (xargs :guard (and (integerp mode)
724
(integerp pn) (<= 0 pn) (< pn *num-pages*)
727
(let ((page (get-page pn mem)))
729
(set-page mode pn mem)
730
(set-page (update-page page :mode mode) pn mem))))
732
(verify-guards set-page-mode
733
:hints (("Goal" :in-theory (enable mem-p))))
735
(defthm mem-p-set-page-mode
736
(implies (and (mem-p mem)
738
(or (equal mode *no-access*)
739
(equal mode *read-only*)
740
(equal mode *read-write*))
741
(integerp pn) (<= 0 pn) (< pn *num-pages*))
742
(mem-p (set-page-mode mode pn mem)))
743
:hints (("Goal" :in-theory (enable mem-p))))
745
(defthm page-mode-init-page
746
(equal (page-mode (init-page page-num mode)) mode)
747
:hints (("Goal" :in-theory (enable init-page))))
749
(defthm page-mode-write-page
750
(equal (page-mode (write-page val offset page))
752
:hints (("Goal" :in-theory (enable write-page))))
754
(defthm readable-addr-p-set-page-mode
755
(implies (and (integerp mode)
757
(integerp pn1) (<= 0 pn1) (< pn1 *num-pages*)
759
(equal (readable-addr-p addr (set-page-mode mode pn1 mem))
760
(if (equal (page-num addr) pn1)
761
(or (equal mode *read-only*) (equal mode *read-write*))
762
(readable-addr-p addr mem))))
763
:hints (("Goal" :in-theory (enable set-page-mode mem-p
767
(defthm readable-addr-set-page-mode
768
(implies (and (integerp mode)
770
(integerp pn1) (<= 0 pn1) (< pn1 *num-pages*)
772
(equal (readable-addr? addr (set-page-mode mode pn1 mem))
773
(if (equal (page-num addr) pn1)
774
(if (or (equal mode *read-only*)
775
(equal mode *read-write*))
777
(readable-addr? addr mem))))
778
:hints (("Goal" :in-theory (e/d (readable-addr?) (readable-addr-p
781
(defthm writable-addr-p-set-page-mode
782
(implies (and (integerp mode)
784
(integerp pn1) (<= 0 pn1) (< pn1 *num-pages*)
786
(equal (writable-addr-p addr (set-page-mode mode pn1 mem))
787
(if (equal (page-num addr) pn1)
788
(equal mode *read-write*)
789
(writable-addr-p addr mem))))
790
:hints (("Goal" :in-theory (enable set-page-mode mem-p
793
(defthm writable-addr-set-page-mode
794
(implies (and (integerp mode)
796
(integerp pn1) (<= 0 pn1) (< pn1 *num-pages*)
798
(equal (writable-addr? addr (set-page-mode mode pn1 mem))
799
(if (equal (page-num addr) pn1)
800
(if (equal mode *read-write*) 1 0)
801
(writable-addr? addr mem))))
802
:hints (("Goal" :in-theory (e/d (writable-addr?)
803
(writable-addr-p SET-PAGE-MODE)))))
805
(defthm readable-addr-p-write-mem
806
(implies (and (addr-p addr) (addr-p addr2) (word-p val) (mem-p mem))
807
(equal (readable-addr-p addr (write-mem val addr2 mem))
808
(readable-addr-p addr mem)))
809
:hints (("Goal" :in-theory (enable readable-addr-p write-mem mem-p))))
811
(defthm readable-addr-write-mem
812
(implies (and (addr-p addr) (addr-p addr2) (word-p val) (mem-p mem))
813
(equal (readable-addr? addr (write-mem val addr2 mem))
814
(readable-addr? addr mem)))
815
:hints (("Goal" :in-theory (enable readable-addr?))))
817
(defthm writable-addr-p-write-mem
818
(implies (and (addr-p addr) (addr-p addr2) (word-p val) (mem-p mem))
819
(equal (writable-addr-p addr (write-mem val addr2 mem))
820
(writable-addr-p addr mem)))
821
:hints (("Goal" :in-theory (enable writable-addr-p write-mem mem-p))))
823
(defthm writable-addr-write-mem
824
(implies (and (addr-p addr) (addr-p addr2) (word-p val) (mem-p mem))
825
(equal (writable-addr? addr (write-mem val addr2 mem))
826
(writable-addr? addr mem)))
827
:hints (("Goal" :in-theory (enable writable-addr?))))
829
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
833
(compress1 'mem (list `(:header :name mem
834
:dimensions (,*num-pages*)
835
:default ,*no-access*
836
:maximum-length 2048))))
838
(defthm mem-p-init-mem
841
(deflist mem-alist-p (l)
842
(declare (xargs :guard t))
843
(lambda (l) (and (consp l) (addr-p (car l)) (word-p (cdr l)))))
845
(defun load-mem-alist (alist mem)
846
(declare (xargs :guard (and (mem-alist-p alist) (mem-p mem))))
849
(load-mem-alist (cdr alist) (write-mem (cdar alist) (caar alist) mem))))
851
(defthm mem-p-load-mem-alist
852
(implies (and (mem-alist-p alist)
854
(mem-p (load-mem-alist alist mem))))
856
(in-theory (disable page-p page-array-p word-array-p mem-p))
857
(in-theory (disable read-reg))
858
(in-theory (disable write-reg))
859
(in-theory (disable read-mem))
860
(in-theory (disable write-mem))
861
(in-theory (disable writable-addr-p readable-addr-p
862
writable-addr? readable-addr? set-page-mode))
864
(defword* word-layout ((op-field 4 12)
865
(rc-field *rname-size* 8)
866
(ra-field *rname-size* 4)
867
(rb-field *rname-size* 0)
868
(im-field *immediate-size* 0))
872
(defthm opcd-p-opcode
873
(opcd-p (op-field inst))
874
:hints (("Goal" :in-theory (enable opcd-p))))
876
(defthm rname-p-rc-field
877
(rname-p (rc-field inst))
878
:hints (("Goal" :in-theory (enable rname-p))))
880
(defthm rname-p-ra-field
881
(rname-p (ra-field inst))
882
:hints (("Goal" :in-theory (enable rname-p))))
884
(defthm rname-p-rb-field
885
(rname-p (rb-field inst))
886
:hints (("Goal" :in-theory (enable rname-p))))
889
(defthm immediate-p-immediate-field
890
(immediate-p (im-field inst))
891
:hints (("Goal" :in-theory (enable immediate-p))))
894
(defthm word-p-immediate-field
895
(word-p (im-field inst))
896
:hints (("Goal" :in-theory (enable word-p))))
898
(defthm word-IM-field
899
(equal (word (IM-field i)) (IM-field i))
900
:hints (("goal" :in-theory (enable word))))
902
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
903
; Definition of Special registers
904
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
905
(defconst *num-sregs* 2)
908
(su (:assert (bitp su) :rewrite ))
909
(sr0 (:assert (word-p sr0) :rewrite))
910
(sr1 (:assert (word-p sr1) :rewrite))
913
(defun srname-p (rname)
914
(declare (xargs :guard t))
915
(and (rname-p rname) (< rname *num-sregs*)))
917
(defthm srname-p-type
918
(implies (srname-p rname)
919
(and (integerp rname)
921
(< rname *num-sregs*)))
922
:hints (("Goal" :in-theory (enable rname-p srname-p)))
923
:rule-classes :forward-chaining)
925
(defun read-sreg (id sregs)
926
(declare (xargs :guard (and (rname-p id) (sregs-p sregs))))
927
(if (equal id 0) (sregs-sr0 sregs)
928
(if (equal id 1) (sregs-sr1 sregs)
931
(defun write-sreg (val id sregs)
932
(declare (xargs :guard (and (word-p val) (rname-p id) (sregs-p sregs))))
933
(if (equal id 0) (sregs (sregs-su sregs) val (sregs-sr1 sregs))
934
(if (equal id 1) (sregs (sregs-su sregs) (sregs-sr0 sregs) val)
937
(defthm word-p-read-sreg
938
(implies (and (rname-p id) (sregs-p sregs))
939
(word-p (read-sreg id sregs))))
941
(defthm numberp-read-sreg
942
(implies (and (sregs-p sregs)
944
(and (integerp (read-sreg rname sregs))
945
(acl2-numberp (read-sreg rname sregs))))
946
:hints (("Goal" :in-theory (enable rname-p sregs-p fixlen-word-listp)))
948
((:type-prescription) (:rewrite)))
950
(defthm sregs-p-write-sreg
951
(implies (and (word-p val) (rname-p id) (sregs-p sregs))
952
(sregs-p (write-sreg val id sregs))))
954
(defthm read-sreg-write-sreg
955
(implies (and (srname-p rn1)
958
(equal (read-sreg rn1 (write-sreg val rn2 sregs))
959
(if (equal rn1 rn2) val (read-sreg rn1 sregs))))
960
:hints (("Goal" :in-theory (enable read-sreg write-sreg sregs-p
963
(in-theory (disable read-sreg write-sreg srname-p))