-
Notifications
You must be signed in to change notification settings - Fork 2
/
0013-Primitive-Access.st
1244 lines (1185 loc) · 42.1 KB
/
0013-Primitive-Access.st
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'From Smalltalk 5.5k XM November 24 on 22 November 1980 at 2:57:08 am.'
"BitBlt"
Class new title: 'BitBlt'
subclassof: Object
fields: 'function color destbase destraster destx desty
width height sourcebase sourceraster sourcex sourcey
sstrike dstrike '
declare: 'pageOneCursor ';
asFollows
BitBlt copies bits from one rectangle to another in core. x, y, width and height are in bits, raster is in words, and base is a core address. Mode is storing, oring, xoring or erasing. If source or destination is a Smalltalk object, then you have to lock it, as in copyToString, below. The primitive does no bounds checking, so watch out.
Access to Parts
color [⇑color]
color ← color
destbase [⇑destbase]
destbase ← destbase
destraster [⇑destraster]
destraster ← destraster
destx [⇑destx]
destx ← destx
desty [⇑desty]
desty ← desty
dest ← pt [destx← pt x. desty ← pt y]
dstrike [⇑dstrike]
dstrike ← dstrike
extent ← pt [width ← pt x. height ← pt y]
function [⇑function]
function ← function
height [⇑height]
height ← height
sourcebase [⇑sourcebase]
sourcebase ← sourcebase
sourceraster [⇑sourceraster]
sourceraster ← sourceraster
sourcex [⇑sourcex]
sourcex ← sourcex
sourcey [⇑sourcey]
sourcey ← sourcey
source ← pt [sourcex← pt x. sourcey ← pt y]
sstrike [⇑sstrike]
sstrike ← sstrike
width [⇑width]
width ← width
Setup
classInit
[pageOneCursor ← 0431. "location of hardware cursor"
]
forCursor
[function← color← 0.
destbase← sourcebase← 0431.
width← height← 16. destraster← sourceraster← 1.
destx← desty← sourcex← sourcey← 0. sstrike ← dstrike ← false
]
init
[function ← color ← destbase ← destraster ← destx ← desty ← width ←
height ← sourcebase ← sourceraster ← sourcex ← sourcey ← 0. sstrike ← dstrike ← false
]
Operations
callBLT
[user croak] primitive: 33
checksandcall | destlocked sourcelocked
["checks if either base a string and/or strike and locks accordingly"
function ← function land: 017. "set up function to add XM stuff"
[destbase class ≡ String ⇒
[destbase◦1 ← destbase◦1. "set the dirty bit"
destlocked ← destbase.
destbase ← ([dstrike ⇒ [((destlocked lock) + 9)]
destlocked lock "strike header"])
]
[destbase ≠ pageOneCursor ⇒
[function ← function + 020. "dest not string, then must be in display"]
"unless doing cursor work in page one location"]
].
[sourcebase class ≡ String ⇒
[sourcelocked ← sourcebase.
sourcebase ← ([sstrike ⇒ [((sourcelocked lock) + 9)]
sourcelocked lock "strike header"])
]
[sourcebase ≠ pageOneCursor ⇒
[function ← function + 040. "source not string, then must be in display"]
"unless doing cursor work in page one location"]
].
self callBLT.
[destlocked ≡ nil ⇒ [] destbase ← destlocked unlock].
[sourcelocked ≡ nil ⇒ [] sourcebase ← sourcelocked unlock].
]
copy: mode
[function ← mode land: 3. self checksandcall]
copycomp: mode
[function ← 4 + (mode land: 3). self checksandcall]
fill: mode color: color
[function ← 12 + (mode land: 3). self checksandcall]
paint: mode
[function ← 8 + (mode land: 3). self checksandcall]
stringCopy: deststring from: start to: stop with: replacement from: rstart to: rstop
["copies equal subranges from one string to another.
works for BitBlt parameters up to 4096. maybe too much set up for short strings.
currently, called by String copy:to:with:from:to:"
width ← 1+stop-start.
width = 0⇒ [⇑deststring]
(start > 4096 or⦂ rstart > 4096) or⦂ width ≥ 4096⇒ [⇑false]
(width < 0 or⦂ width ≠ (1+rstop-rstart)) or⦂ (
(start < 1 or⦂ stop > deststring length) or⦂
(rstart < 1 or⦂ rstop > replacement length))⇒ [
user notify: 'illegal range or subscript']
"self init."
function ← color ← destraster ← desty ← sourceraster ← sourcey ← 0.
sstrike ← dstrike ← false.
height ← 1.
width ← width*8.
destbase ← deststring lock.
destx ← (start - 1) * 8.
sourcebase ← replacement lock.
sourcex ← (rstart - 1) * 8.
self callBLT.
replacement unlock.
"mark dirty"
deststring◦1 ← deststring◦1.
deststring unlock.
⇑deststring
]
stringReplace: deststring with: sourcestring from: start to: stop and: replacement from: rstart to: rstop | slock [
"works for BitBlt parameters less than 4096. replaces a subrange of a string.
called only by String replace:to:by:from:to:. concatenates into deststring:
sourcestring◦(1 to: start-1)
replacement◦(rstart to: rstop)
sourcestring◦(stop+1 to: sourcestring length).
assumes String arguments"
deststring length = 0⇒ [⇑deststring]
(replacement is: String)≡false⇒[⇑false]
(stop ≥ 4096 or⦂ sourcestring length - stop ≥ 4096) or⦂
(start+rstop-rstart ≥ 4096 or⦂ rstart > 4096)⇒ [⇑false]
(start < 1 or⦂ stop > sourcestring length) or⦂
(rstart < 1 or⦂ rstop > replacement length)⇒ [user notify: 'illegal subscript']
"self init."
function ← color ← destraster ← desty ← sourceraster ← sourcey ← 0.
sstrike ← dstrike ← false.
height ← 1.
destbase ← deststring lock.
sourcebase ← slock ← sourcestring lock.
width ← (start - 1) * 8.
[width = 0⇒ []
sourcex ← destx ← 0.
self callBLT].
destx ← width.
width ← (1+rstop-rstart)*8.
[width = 0⇒ []
sourcex ← (rstart - 1) * 8.
sourcebase ← replacement lock.
self callBLT.
replacement unlock].
destx ← destx+ width.
width ← (sourcestring length - stop) * 8.
[width = 0⇒ []
sourcebase ← slock.
sourcex ← stop * 8.
self callBLT].
deststring◦1 ← deststring◦1.
sourcestring unlock. deststring unlock.
⇑deststring
]
SystemOrganization classify: ↪BitBlt under: 'Primitive Access'.
BitBlt classInit
"CoreLocs"
Class new title: 'CoreLocs'
subclassof: Array
fields: 'base length'
declare: '';
asFollows
I am an array mapping a section of Alto memory
Initialization
base: base length: length
Reading and Writing
◦ x [x isLarge⇒[⇑self◦(x asSmall)] user croak] primitive: 42
◦ x ← val [x isLarge⇒[⇑self◦(x asSmall) ← val] user croak] primitive: 43
base [⇑base]
length [⇑length]
SystemOrganization classify: ↪CoreLocs under: 'Primitive Access'.
"VirtualMemory"
Class new title: 'VirtualMemory'
subclassof: Object
fields: 'map "Pclass Map"
premap "block before map"
FirstContextOop "oop of FirstContext"
SpecialOopsOop "oop of SpecialOops"
zip "Zone Index of Pages"
prezip "block before zip"
zadd "file info"
vmemfile "file for vmem" '
declare: 'ZHB RCI PIN zfused zfree zjmpt pmint num00 pmend ZN zflen pmatm zlong PCL ZVPN CPT BSC ISC ZJMP zend ';
asFollows
A model of the OOZE virtual memory
Pclass Map
CPT: oop | poma
[poma ← 2*(oop field: PCL) +1.
⇑map◦poma field: CPT]
freelist: object | a
["one-order index into freelists."
object class is: Class ⇒[⇑1]
a ← self ISC: object asOop.
a < 024 ⇒[⇑1+a] ⇑1+ a-013]
freelistOffset: len "offset of freelist for this length in a variable length class"
[⇑Class instsize + [len < 9 ⇒[len] (len-1) log2 + 6]]
highpm0: oop gets: val | poma
[premap◦pmatm ← premap◦pmatm min: (oop field: PIN ← 0).
poma ← 2*(oop field: PCL) +1.
map◦poma ← val]
highPM: oop | pcl a
[pcl ← oop field: PCL.
a ← premap◦pmatm field: PCL.
pcl < a ⇒[⇑false]
⇑map◦(2*pcl +1)]
ISC: oop | poma
[poma ← 2*(oop field: PCL) +1.
⇑map◦poma field: ISC]
lowPM: oop | pcl a
[pcl ← oop field: PCL.
a ← premap◦pmend field: PCL.
pcl ≥ a ⇒[⇑false]
⇑map◦(2*pcl +1)]
newHighPM← pm0 | pcl a
[a ← premap◦pmatm.
premap◦pmatm ← (a ← a-0200).
pcl ← a field: PCL.
map◦(2*pcl +1) ← pm0.
⇑a]
newLowPM← pm0 | poma a
[map◦1 = pm0 ⇒["reserved pclasses for Class"
map◦3 = 0 ⇒[map◦3 ← pm0. ⇑0200]
map◦5 = 0 ⇒[map◦5 ← pm0. ⇑0400] ]
"normal case"
a ← premap◦pmend.
premap◦pmend ← a+0200.
poma ← (a field: PCL) *2 +1.
map◦poma ≠ 0 ⇒["skip over already filled"
⇑self newLowPM← pm0]
map◦poma ← pm0.
⇑a]
newZN: oop
[self ZN: oop gets: self newZone]
pclassesOf: cls | i clsoop n z p "find pclasses of this class (in order of ZHB)"
["ignore small integers and nil"
p ← (Vector new: 1) asStream.
z ← (Vector new: 1) asStream.
clsoop ← cls asOop.
for⦂ i from: (1 to: 2*(0174000 field: PCL) by: 2) do⦂
[map◦i = 0 ⇒[]
(map◦i field: RCI) = clsoop ⇒[p next← i/2. z next← (map◦(i+1) field: ZHB)]].
p ← p contents. z ← z contents.
n ← p copy.
for⦂ i to: z length do⦂
[n◦(z◦i +1) ← p◦i].
⇑n]
pclassesOf: cls length: len | i clsoop n z p isc pm0 "find pclasses of this class and length (in order of ZHB)"
["ignore small integers and nil"
p ← (Vector new: 1) asStream.
z ← (Vector new: 1) asStream.
isc ← [len < 9 ⇒[len] (len-1) log2 + 17].
clsoop ← cls asOop.
for⦂ i from: (1 to: 2*(0174000 field: PCL) by: 2) do⦂
[(pm0 ← map◦i) = 0 ⇒[]
(pm0 field: RCI) ≠ clsoop ⇒[]
(pm0 field: ISC) = isc ⇒[p next← i/2. z next← (map◦(i+1) field: ZHB)]].
p ← p contents. z ← z contents.
n ← p copy.
for⦂ i to: z length do⦂
[n◦(z◦i +1) ← p◦i].
⇑n]
pmatm [⇑premap◦pmatm]
ZHB: oop | poma
[poma ← 2*(oop field: PCL) +1.
⇑map◦(1+poma) field: ZHB]
ZHB: oop gets: val | poma i
[poma ← 2*(oop field: PCL) +1.
i ← map◦(1+poma).
map◦(1+poma) ← (i field: ZHB ← val)]
ZN: oop | poma
[poma ← 2*(oop field: PCL) +1.
⇑map◦(1+poma) field: ZN]
ZN: oop gets: val | poma i
[poma ← 2*(oop field: PCL) +1.
i ← map◦(1+poma).
map◦(1+poma) ← (i field: ZN ← val)]
Writing and Reading
obwiz: oop | poma pm0 pm1 isc bsc i len zz pin zhb
["find (zn, zp, zw, dlen)"
zz ← Vector new: 4.
poma ← (oop field: PCL)*2 +1.
(pm0 ← map◦poma) = 0 ⇒ [user notify: 'bad oop']
pm1 ← map◦(1+poma).
isc ← pm0 field: ISC.
bsc ← pm0 field: BSC.
zhb ← pm1 field: ZHB.
[isc < 024 ⇒[len ← ((isc max: 1)+ 1-bsc) / (2-bsc)]
len ← 8. i ← isc+bsc.
until⦂ 024 = i do⦂ [i ← i-1. len ← len*2]
len ← len+1 "length word" ].
zz◦4 ← len ← len+1. "dlen with refct"
"w ← (dlen*128*zhb) +dlen*pin"
pin ← oop field: PIN.
zz◦2 "zp" ← (zhb/2 *len) +(len/256 *pin).
zz◦3 "zw" ← (zhb\2 *128 *len) +(len\256 *pin).
zhb\2 * len ≥ 512 ⇒[user notify: 'address overflow']
zz◦2 "zp" ← zz◦2 + (zz◦3 field: 136 "highbyte").
zz◦3 "zw" ← zz◦3 field: 128 "lowbyte".
zz◦1 ← pm1 field: ZN.
⇑zz]
readin: oop | zinfo
[zinfo ← self obwiz: oop.
⇑self read: zinfo◦4 at: zinfo]
systemNoHistory [] primitive: 82
writeout: oop with: image | zinfo
[zinfo ← self obwiz: oop.
[zinfo◦4 ≥ (image length /2) ⇒[]
user notify: 'bad image length'].
self write: image at: zinfo
]
Init
AComment
["VirtualMemory models the Pclass Map of Ooze.
Vmem is one with CoreLocs on real system.
(VirtualMemory new) thisvmem.
Pmap is new one we are building.
(VirtualMemory new) fakevmem.
map is 1-order addressing.
In init, set pmatm by searching PM for
highest 0. (No LMAT)
map RCI field is old class oop. only convert to
new with mapPM at end.
Atoms may not cover more than half of the
address space. (highpm0:gets:)
(VirtualMemory new) giveBirth.
Zone Index of Pages. works for both vector zip
and corelocs of real zip.
zip, zadd are one-order.
zfree is 1-order in fake, core addr in this.
zlong = 512.
zend is not used (0 fake, core addr in this)
"]
fakevmem: vmemfile
["this instance is a model of a new vmem, which is built on another file"
self init.
map ← Vector new: 1024.
map all ← 0.
premap ← (0176000, 0174000, 0, 0).
"num00, pmint, pmatm, pmend"
prezip ← (3, 01244, 0). "zfree, zlong, zend"
zip ← Vector new: prezip◦zlong.
zip all ← 0.
zadd ← (1, 1). "zfused, zflen"
vmemfile readwrite.
Smalltalk define: ↪Pmap as: self]
init "common to both real and fake vmem"
["field descriptors and indicies in tables"
num00 ← 1. pmint ← 2. pmatm ← 3. pmend ← 4.
RCI ← 151. CPT ← 22. BSC ← 21. ISC ← 80.
ZHB ← 136. ZN ← 128.
PCL ← 151. PIN ← 112.
ZJMP ← 76. ZVPN ← 16*12.
zfree ← 1. zlong ← 2. zend ← 3.
zfused ← 1. zflen ← 2.
zjmpt ← (603, 570, 471, 410, 353, 300, 253,
210, 169, 132, 101, 72, 49, 30, 13)]
premap [⇑premap] "array of limits in Pclass Map"
thisvmem | c m "create Vmem, a VirtualMemory viewing this very system"
[c ← self specialLocs.
map ← CoreLocs new base: c◦2 -1 length: 1025.
premap ← CoreLocs new base: c◦2 -5 length: 5.
Smalltalk define: ↪Vmem as: self.
self init.
m ← 1023.
until⦂ (map◦m = 0) do⦂ [m ← m-2].
premap◦pmatm ← (0 field: PCL ← m/2 +1).
prezip ← CoreLocs new base: c◦3 -4 length: 4.
zip ← CoreLocs new base: c◦3 -1 length: prezip◦zlong+1.
zadd ← CoreLocs new base: c◦12 -3 length: 3.
(vmemfile ← dp0 oldFile: 'small.boot') readonly.
FirstContext ← Context new sender: nil
receiver: user
method: (m ← UserView md method: ↪restart)
tempframe: (Vector new: (m◦3 max: m◦4)) pc: m◦6
stackptr: m◦5 -1.
SpecialOops◦1 ← Object md method: ↪error.
FirstContextOop ← FirstContext asOop.
SpecialOopsOop ← SpecialOops asOop]
Vmem Writing
afterBirth [MethodKeeperKeeper ← nil]
giveBirth | pm0 vm "initialize map for early pclasses"
[self preBirth.
"small Integer, 16 pclasses, oops 0174000-0177777"
pm0 ← Vmem highPM: 0176000. "size, class info for Integer"
until⦂ (Pmap newHighPM← pm0) = 0174000 do⦂ [].
"first UniqueString"
(vm ← Vmapper new) object: (0173600 asObject); touchoop.
"Class oops 0-0177"
vm object: Class; touchoop.
"more Class oops 0200-0577"
Pmap newLowPM← 0; newLowPM← 0.
"VariableLengthClass oops 0600-0777"
vm object: Vector; touchoop.
"skip over some oops"
until⦂ (Pmap newLowPM← 0) = 01600 do⦂ [].
"Object oops 02000-02177, false=02000"
(vm object: false) map ≠ 02000 ⇒[user notify: 'bad false oop']
"set pointer back to oops skipped over"
Pmap premap ◦ pmend ← 01000
]
giveBirth2 | vm
[vm ← Vmapper new.
vm object: (Smalltalk ref: ↪FirstContext).
FirstContextOop ← (vm readin word: 2). "new oop of FirstContext"
vm reset; object: (Smalltalk ref: ↪SpecialOops).
SpecialOopsOop ← (vm readin word: 2). "new oop of SpecialOops"]
giveBirth3 | vm p ["create a new Small.boot
Write out all objects rooted at Smalltalk.
Do not write the stack (rooted in R76, the current context).
Pmap file close. Pmap ← nil.
*** Below is the commmand to start a Vmem write on a Dorado
(or Alto -- double disk O.S.). edit and recompile the method if you don't
want to use old UniqueStrings, or if newsmall.boot, smalltalk.run,
smalltalk.syms, byterp.mb are not located on dp0i,
i.e. dp1 oldFile: 'small.boot' instead of dp0 oldFile: 'newsmall.boot'.
also delete rename: commands at the end.
user displayoffwhile⦂ [(VirtualMemory new) giveBirth3]. user quit.
***"
user releaseExternalViews.
[E≡nil⇒ [] E kill].
Flushed← false.
(Vmapper new) init; UseOldUniqueStrings: true.
user show: 'init '.
(VirtualMemory new) thisvmem. "define Vmem, Pmap"
(VirtualMemory new) fakevmem: (dp0 oldFile: 'newsmall.boot').
self giveBirth.
vm ← Vmapper new.
user show: 'run '. vm object: Smalltalk; map.
user show: 'USTable '. vm arefsRectify.
user show: 'freelist '. vm writefreelists.
user show: 'mrefs '. vm mrefsRectify.
user show: 'PM '. Pmap mapPM; giveBirth2.
"These work as many times as needed on dp0 or dp1"
user show: 'surgery '.
Pmap surgery: (dp0 oldFile: 'Smalltalk.Run').
user show: 'ram '.
Pmap ramwrite: (dp0 oldFile: 'Byterp.Mb').
"adjust size of new file"
p ← Pmap pagesUsed + 264 "boot & ram" + 250 "extra".
user show: 'pages reclaimed '; print: (Pmap file) file lastPage - p.
(Pmap file) readwriteshorten; settopage: p char: 0; close; readwrite.
"rename files so that new file is small.boot"
(Vmem file) file rename: 'oldsmall.boot'.
(Pmap file) file rename: 'small.boot'.
]
mapPM | c i v rci ctrans "convert to new RCI"
[ctrans ← (Vmapper new) classtrans.
for⦂ c from: (1 to: 1023 by: 2) do⦂
[(i ← map◦c) = 0 ⇒[]
rci ← i field: RCI.
(v ← ctrans lookup: rci) ⇒
[map◦c ← (i field: RCI ← v◦1)]
user notify: 'class not mapped']
]
preBirth | v
[MethodKeeperKeeper ← MessageDict new.
MethodKeeperKeeper init: (v ← MethodKeeper contents) length *2; holdMethods: v]
ramwrite: source | s "write 8 pages of ram image into small.boot" [
s ← source name.
source readonly.
[source directory ≡ dp0 ⇒[]
(dp0 file: s) append: source; close "copy onto dp0"].
source close.
"cleanup vmem file before quit"
vmemfile close.
"go out to OS, packram, and come back"
s ← s◦(1 to: s length-4) concat: '.br.'.
user quitThen: [
(Stream default) append: 'Packmu ';
append: source name; space; append: s;
append: '; Resume '; append: Vmem file name;
contents].
"skip .br stuff and constants"
(s ← dp0 oldFile: s) readonly; skipwords: 0421.
"now write in ram image (8 pages of 512)"
vmemfile settopage: 0400 char: 0; readwrite; next: 4096 from: s.
s close.
self ≡ Vmem ⇒[vmemfile readonly "does flush"]
vmemfile flush]
Surgery
dynaLocs: guide | l locs keys v i "Surgery - add core location and value pairs to guide dictionary to test after flush"
[l ← self specialLocs.
locs ← (premap base +pmend, (l◦11 -1), (l◦12 -2), (l◦4 +1)).
keys ← (↪premaptest, ↪purgetest, ↪zaddtest, ↪loxtest).
for⦂ i from: 1 to: keys length do⦂
[v ← locs◦i, (mem◦(locs◦i)).
guide insert: keys◦i with: v].
(guide lookup: ↪loxtest)◦2 ← ¬1]
runLocs: f | guide i v locs keys offsets "Surgery - create dictionary of locations of key system tables in Smalltalk.run"
[i ← f name.
(v ← f directory oldFile: (i◦(1 to: i length-5) concat: '.syms.')) readonly.
locs ← self symsFind: ('PMBASE', 'ZIP', 'ZADD', 'INITIALIZE', 'OOZIN', 'SAFID') on: v.
v close.
keys ← ↪(maprun ziprun zaddrun initrun zfps safid).
offsets ← ↪(¬1 ¬1 ¬3 ¬3 ¬2 ¬1). "words offset"
guide ← Dictionary new init: 16.
for⦂ i from: 1 to: locs length do⦂
[v ← (locs◦i lshift: ¬8), ((locs◦i land: 0377) -19 *2). "page, byte"
"magic fudge factor of 19 words for .run file"
v◦2 ← v◦2 +(offsets◦i *2). "bytes offset"
guide insert: keys◦i with: v].
v ← (guide lookup: ↪maprun) copy.
v◦2 ← v◦2 +(¬4 *2). "offset ¬5 total"
guide insert: ↪premaprun with: v.
v ← (guide lookup: ↪ziprun) copy.
v◦2 ← v◦2 +(¬3 *2). "offset ¬4 total"
guide insert: ↪preziprun with: v.
⇑guide]
specialLocs [] primitive: 84
"returns a vector containing the core addresses of:
1 ROTBASE (the Resident Object Table)
2 PMBASE (the Pclass Map)
3 ZIP (the Zone Index of Pages)
4 LOX (the table of LOcked objeX)
5 FULL (loc of lowest addr used for resident data)
6 ULIM (loc of highest addr used for resident data)
7 ZFPT (the zone file Page Table)
8 OVTAB (the Table of OVerflow ref counts)
9 PURGE (a code label)
10 DISPGLBS (Table of Display Globals)
11 BACPUR (a code label)
12 ZADD (.-2 has #pages req'd, .-1 has #pages in boot file; add 264 for real file length)
13 SAFID (loc of file id (5-word block) for the .boot file)
"
staticTest: guide on: f | l locs offsets values names i v "Surgery - test known static constants in thisvmem and in smalltalk.run"
[offsets ← (pmint, 2, 0, 0).
values ← (0174000, 01244, 96, 031415).
names ← (↪premaprun, ↪preziprun, ↪zaddrun, ↪initrun).
for⦂ i to: names length do⦂
[v ← guide lookup: names◦i.
f settopage: v◦1 char: v◦2 +(offsets◦i *2).
f nextword ≠ (values◦i)⇒
[user notify: 'bad .run loc']].
self ≡ Vmem ⇒
[l ← self specialLocs.
offsets◦4 ← 0. values◦4 ← 014764.
locs ← (premap base, prezip base, zadd base, (l◦11) "bacpur").
for⦂ i from: 1 to: locs length do⦂
[values◦i ≠ (mem◦(locs◦i +(offsets◦i)))⇒
[user notify: 'bad system loc']]]
]
surgery: f | guide Etemp i v keys [
"write virtual memory tables into Smalltalk.run using Smalltalk.syms.
user displayoffwhile⦂ [Vmem ramwrite: (dp0 oldFile: 'byterp.mb')].
user displayoffwhile⦂ [Vmem surgery: (dp0 oldFile: 'Smalltalk.run')]. "
vmemfile close.
user releaseExternalViews.
[E ≡ nil ⇒[] E kill].
[self ≡ Vmem ⇒[self thisvmem.
Flushed ← true. Etemp ← Events]].
f readwrite.
guide ← self runLocs: f.
self staticTest: guide on: f.
[self ≡ Vmem ⇒[user clearshow: 'Wait for the safe light to flash, then hit any key'.
until⦂ user kbck do⦂ []. user kbd.
self dynaLocs: guide.
user clearshow: 'Dont forget user systemStartup. in the new system to enable interrupts and get the display set up. '.
]].
self tablewrt: guide on: f. "write in Smalltalk.run"
f close.
self ≡ Vmem ⇒
[keys ← (↪premaptest, ↪purgetest, ↪zaddtest, ↪loxtest).
for⦂ i to: keys length do⦂
[v ← guide lookup: keys◦i.
v◦2 ≠ (mem◦(v◦1))⇒[user notify: 'please surgery again']].
Events ← nil. self systemVmemOut.
Events ← Etemp.
vmemfile close.
user quit]
]
symsFind: strs on: f1 | f2 S N L offset val str j i "find initial values of SRELs in smalltalk.syms"
["S is start of string space (words)
N is start of symbol table "
(f2 ← f1 directory oldFile: f1 name) readonly.
f1 wordposition ← 2.
S ← f1 nextword.
N ← f1 nextword.
f1 wordposition ← N.
L ← f1 nextword.
for⦂ i to: L do⦂
[offset ← f1 nextword. "next offset"
f1 skip: 4.
val ← f1 nextword.
f2 wordposition ← S+offset.
str ← f2 next: f2 next.
for⦂ j to: strs length do⦂
[(strs◦j) class ≡ String ⇒
[strs◦j = str ⇒[strs◦j ← val]]].
].
f2 close.
for⦂ j to: strs length do⦂
[(strs◦j) class ≡ String ⇒
[user notify: 'symbol not found']].
⇑strs]
systemVmemOut [] primitive: 83
tablewrt: guide on: f | i v vfile "copy tables from self to .run file"
[v ← guide lookup: ↪premaprun.
f settopage: v◦1 char: v◦2 +(2*pmatm).
f nextword← premap◦pmatm.
f nextword← premap◦pmend.
for⦂ i to: 1024 do⦂ [f nextword← map◦i].
v ← guide lookup: ↪preziprun.
f settopage: v◦1 char: v◦2 +(2*1 "zfree").
i ← [self ≡ Vmem ⇒ [¬1-zip base "relative indexing"]¬1 "make 0-order"] .
f nextword← prezip ◦1 +i. "zfree"
v ← guide lookup: ↪zaddrun.
f settopage: v◦1 char: v◦2 +(2*1 "zfused").
f nextword← zadd ◦1. " zfused "
v ← guide lookup: ↪ziprun.
f settopage: v◦1 char: v◦2 +(2*1).
for⦂ i to: prezip◦zlong do⦂ [f nextword← zip◦i]
v ← guide lookup: ↪initrun.
f settopage: v◦1 char: v◦2 +(2*1 "SpecialOops").
f nextword← SpecialOopsOop.
f nextword← FirstContextOop.
"disk address of start of virtual memory"
vfile ← vmemfile file.
v ← guide lookup: ↪zfps.
f settopage: v◦1 char: v◦2 +(2*1).
f nextword← (vfile read: 0410) address.
"swat file id of vmem file"
v ← guide lookup: ↪safid.
f settopage: v◦1 char: v◦2 + (2*1).
f append: vfile serialNumber; skip: 4; nextword ← (vfile read: 1) address.
]
Zone Pages
cover: zz | pp zrp lpir zjmp vpn olpir
[pp ← zz◦2 + 1. "zp 1-order"
lpir ← 1. olpir ← 0. zrp ← zz◦1 *2 +1.
until⦂ lpir ≥ pp do⦂ [
0 = (zjmp ← zip◦zrp field: ZJMP) ⇒
[self run: [lpir ≥ 32 ⇒[32] lpir +1] after: zrp.
self cover: zz]
zrp ← (zjmpt◦zjmp + zrp -1)\ (prezip◦zlong) +1.
olpir ← lpir.
lpir ← lpir + [lpir ≥ 32 ⇒[32] lpir +1] ].
vpn ← (zip◦zrp field: ZVPN) +pp -(olpir +1).
0 = vpn ⇒[user notify: 'pclass has no zone']
vpn ← vpn + 0407.
vmemfile settopage: vpn char: zz◦3 *2]
file [⇑vmemfile]
getpages: i | vpn
[[zadd◦zflen < (zadd◦zfused + i) ⇒
[zadd◦zflen ← zadd◦zflen + (i max: 20).
vmemfile settopage: zadd◦zflen + 0407 char: 0]].
vpn ← zadd◦zfused.
zadd◦zfused ← vpn+i.
⇑vpn]
newZone | zrp
[zip is: Vector ⇒[
zrp ← prezip◦zfree.
until⦂ zip◦zrp = 0 do⦂ [zrp > (prezip◦zlong) ⇒
[user notify: 'zip overflow']
zrp ← zrp+2].
prezip◦zfree ← 2+zrp.
zip◦zrp ← self getpages: 1.
⇑zrp/2]]
pagesUsed [⇑zadd◦zfused]
read: len at: zz | i str
[i ← 256 - (zz◦3) "zw" min: len.
self cover: zz.
str ← vmemfile next: 2*i.
i=len ⇒[⇑str]
zz◦2 ← zz◦2 +1. "zp"
zz◦3 ← 0. "zw"
⇑str concat: (self read: len-i at: zz)]
run: n after: zrp | i j
[for⦂ i to: 15 do⦂
[j ← zjmpt◦i +zrp -1 \ (prezip◦zlong) +1.
zip◦j = 0 ⇒
[zip◦zrp ← zip◦zrp field: ZJMP ← i.
zip◦j ← self getpages: n. ⇑zrp]
].
user notify: 'new zip is full']
write: str at: zz | i len
[len ← str length /2.
i ← 256 - (zz◦3) "zw" min: len.
i = len ⇒[
self cover: zz.
vmemfile append: str]
self write: str from: 1 at: zz]
write: str from: pos at: zz | i len
[len ← str length +1 -pos. "bytes yet to write"
i ← len min: (256 - (zz◦3) "zw")*2. "bytes in page"
self cover: zz.
vmemfile append: str◦(pos to: i+pos-1).
i=len ⇒[]
zz◦2 ← zz◦2 +1. "zp"
zz◦3 ← 0. "zw"
self write: str from: i+pos at: zz]
SystemOrganization classify: ↪VirtualMemory under: 'Primitive Access'.
"Vmapper"
Class new title: 'Vmapper'
subclassof: Object
fields: 'object oop noop image'
declare: 'classtrans PCL mapqueue clamp stopcount USTableOop mrefs arefs count UseOldUniqueStrings ';
asFollows
This class has not yet been commented
Mapping
map | i
[(i ← mrefs lookup: oop) ⇒[i◦1 ← i◦1 -1. ⇑i◦2]
[user kbck ⇒ [user kbd; ev] self bump].
object class = Integer ⇒[⇑self mapInteger];
= UniqueString ⇒[⇑self mapUniqueString];
= Vector ⇒[⇑self mapVector];
= Float ⇒[⇑self mapFloat];
= MessageDict ⇒[⇑self mapMdict]
object Is: HashSet ⇒[⇑self mapHashSet]
object Is: String ⇒[⇑self mapString]
object class = Class ⇒[⇑self mapClass];
= VariableLengthClass ⇒[⇑self mapClass];
= Vmapper ⇒[⇑¬1]; "avoid recursion in writing"
= VirtualMemory ⇒[⇑self mapVmem]; "avoid recursion in writing"
"put any fixed octave class here"
= Object ⇒[⇑self mapObject]
⇑self mapNormal]
mapClass | nlen oadd i refs vm j
[clamp find: object ⇒[⇑¬1 "don't write this class"]
nlen ← 1 + object class instsize. "refct + normal fields"
i ← [object is: Class ⇒[oadd ← 0. 1] oadd ← 1. 20].
noop ← self newoop.
[(vm ← classtrans lookup: oop) ⇒[vm◦1 ← noop]
vm ← Vector new: i+1. vm◦1 ← noop.
classtrans insert: oop with: vm].
nlen ← nlen + i + oadd.
image ← String new: 2*nlen.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1 ⇒[image word: 2 ← nlen-2]].
for⦂ j from: (2+oadd to: nlen-i) do⦂
[vm ← Vmapper new object: (object instfield: j-1-oadd).
image word: j ← vm map].
self writeout.
⇑noop]
mapFloat | refs i
[image ← String new: 8.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs-2.
for⦂ i to: 3 do⦂ [image word: (i+1) ← object instfield: i].
self writeout.
⇑noop]
mapHashObs | nlen oadd i refs vm trans ob
[nlen ← object length. "in words"
oadd ← [nlen≤8⇒[0]1].
nlen ← oadd +1 +nlen.
image ← String new: 2*nlen.
[(refs ← object refct) = 2 "exactly one ref" ⇒
[noop ← self newoop]
(i ← mrefs lookup: oop) ⇒[i◦1 ← i◦1 -1. noop ← i◦2]
noop ← self newoop.
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1⇒[image word: 2 ← object length]].
ob ← (trans ← self permHashSet) objects. "translation dictionary"
for⦂ i from: (2+oadd to: nlen) do⦂
[vm ← ob◦(i-1-oadd). "integer noops"
vm ≡ nil ⇒[] image word: i ← vm].
self writeout.
⇑noop, trans values]
mapHashSet | nlen i refs vm perm "all subclass on HashSet except Mdict"
[mrefs asOop = oop ⇒[⇑¬1] "do not map"
arefs asOop = oop ⇒[⇑¬1] "do not map"
nlen ← 1 + (object class instsize). "refct + fields"
image ← String new: 2*nlen.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
vm ← Vmapper new object: (object instfield: 1).
i ← vm mapHashObs. "(oop, perm)"
image word: 2 ← i◦1.
perm ← i◦2. "permutation of other parts"
for⦂ i from: (3 to: nlen) do⦂
[vm ← Vmapper new object: (object instfield: i-1).
image word: i ← (vm mapHashVals: perm)].
self writeout.
⇑noop]
mapHashVals: perm | nlen oadd i refs vm "values vec of dictionary"
[oop = ¬1 ⇒[⇑¬1]
nlen ← object length. "in words"
oadd ← [nlen≤8⇒[0]1].
nlen ← oadd +1 +nlen.
image ← String new: 2*nlen.
[(refs ← object refct) = 2 "exactly one ref" ⇒
[noop ← self newoop]
(i ← mrefs lookup: oop) ⇒[i◦1 ← i◦1 -1. noop ← i◦2]
noop ← self newoop.
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1⇒[image word: 2 ← object length]].
object ← object◦perm.
for⦂ i from: (2+oadd to: nlen) do⦂
[(vm ← Vmapper new) object: object◦ (i-1-oadd).
image word: i ← vm map].
self writeout.
⇑noop]
mapInteger | refs
[¬02000 ≤ object and: object < 01777 ⇒
[⇑oop "small integer"]
image ← String new: 4.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs-2.
image word: 2 ← object.
self writeout.
⇑noop]
mapMdict | i refs vm perm " maps MessageDict instance "
[image ← String new: 12.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
(vm ← Vmapper new) object: (object instfield: 1).
i ← vm mapHashObs. "(oop, perm)"
image word: 2 ← i◦1.
perm ← i◦2. "permutation of other parts"
for⦂ i from: (3 to: 6) do⦂
[(vm ← Vmapper new) object: (object instfield: i-1).
i = 3 ⇒[image word: 3 ← (vm mapMethodVec: perm)]
image word: i ← (vm mapHashVals: perm)].
self writeout.
⇑noop]
mapMethod | nlen oadd refs i a vm b
[oop = ¬1 ⇒[⇑¬1]
nlen ← object length. "in bytes!!"
oadd ← [nlen≤8⇒[0]1].
nlen ← 2*oadd +2 +nlen.
image ← String new: nlen+1 |2.
[(refs ← object refct) = 2 "exactly one ref" ⇒
[noop ← self newoop]
(i ← mrefs lookup: oop) ⇒[i◦1 ← i◦1 -1. noop ← i◦2]
noop ← self newoop.
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1⇒[image word: 2 ← object length]].
[nlen ≤ 8 or⦂ object◦6 = 6 ⇒
[image◦(2*oadd +3 to: nlen) ← object]
a ← 2*oadd +3. b ← object◦6.
image◦(a to: a+5) ← object◦(1 to: 6).
for⦂ i from: (4 to: b /2) do⦂
[(vm ← Vmapper new) object: (object word: i) asObject.
image word: (i+1+oadd) ← vm map].
image◦(a+b to: nlen) ← object◦(b+1 to: object length)].
self writeout.
⇑noop]
mapMethodVec: perm | nlen oadd i refs vm
[oop = ¬1 ⇒[⇑¬1]
nlen ← object length. "in words"
oadd ← [nlen≤8⇒[0]1].
nlen ← oadd +1 +nlen.
image ← String new: 2*nlen.
[(refs ← object refct) = 2 "exactly one ref" ⇒
[noop ← self newoop]
(i ← mrefs lookup: oop) ⇒[i◦1 ← i◦1 -1. noop ← i◦2]
noop ← self newoop.
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1⇒[image word: 2 ← object length]].
object ← object◦perm.
for⦂ i from: (2+oadd to: nlen) do⦂
[(vm ← Vmapper new) object: object◦ (i-1-oadd).
image word: i ← vm mapMethod].
self writeout.
⇑noop]
mapNormal | nlen i refs vm oadd "all fixed, pointer type classes"
[clamp find: object class ⇒[⇑¬1 "don't write the instance"]
nlen ← object class instsize.
oadd ← [nlen≤19⇒[0]1].
nlen ← oadd+1 +nlen.
image ← String new: 2*nlen.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs-2.
[oadd=1⇒[image word: 2 ← nlen-oadd-1]].
for⦂ i from: (2+oadd to: nlen) do⦂
[vm ← Vmapper new object: (object instfield: i-oadd-1).
image word: i ← vm map].
self writeout.
⇑noop]
mapObject | refs "nil, false, true"
[object≡nil ⇒
[mrefs insert: ¬1 with: (500, ¬1). "for speed of
catching nil. watch out on cleanup" ⇑¬1]
image ← String new: 4.
noop ← self newoop.
noop\128>1 ⇒
[user notify: 'Unidentified flying Object']
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
self writeout.
⇑noop]
mapString | nlen oadd refs
[nlen ← object length. "in bytes!!"
oadd ← [nlen≤8⇒[0]1].
nlen ← 2*oadd +2 +nlen.
image ← String new: nlen+1 |2.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs -2.
[oadd=1⇒[image word: 2 ← object length]].
image◦((2*oadd +3) to: nlen) ← object.
self writeout.
⇑noop]
mapUniqueString | nlen oadd refs
[[UseOldUniqueStrings ⇒[self UniStroop. noop ← oop]
(refs ← arefs lookup: oop) ⇒[⇑refs]
noop ← self newoop.
arefs insert: oop with: noop].
nlen ← object length. "in bytes!!"
oadd ← [nlen≤8⇒[0]1].
nlen ← 2*oadd +2 +nlen.
image ← String new: nlen+1 |2.
image word: 1 ← 1.
[oadd=1⇒[image word: 2 ← object length]].
image◦((2*oadd +3) to: nlen) ← object.
self writeout.
⇑noop]
mapVector | nlen oadd i refs vm
[[UseOldUniqueStrings ⇒[] USTableOop = oop ⇒[⇑¬1]
"do not map since new atom Oops"].
nlen ← object length. "in words"
oadd ← [nlen≤8⇒[0]1].
nlen ← oadd +1 +nlen.
image ← String new: 2*nlen.
noop ← self newoop.
[(refs ← object refct) = 2 ⇒["exactly one reference"]
mrefs insert: oop with: (refs-2, noop)].
image word: 1 ← refs-2.
[oadd=1⇒[image word: 2 ← object length]].