-
Notifications
You must be signed in to change notification settings - Fork 1
/
fkernel
3360 lines (2834 loc) · 57.5 KB
/
fkernel
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
\
\ ANS Forth kernel for ARM 3 machines Martin Läuter 32bit Mode
\
\ modified for strongarm 2007 Alban Read
\ - works on RPCEmu, Iyonix, TI, misc PI and PI400 in 32bit mode.
\
decimal
here: coldstart 0 , \ branch to cold, will be patched later
here: memtotal 0 , \ total memory available
here: retstack 0 , \ desired return stack size
here: datstack 0 , \ desired data stack size
here: filebuff 0 , \ desired file buffer size
here: commline 0 , \ commandline address
here: thisfile
0 , ," FKERNEL"
vocabulary forth
\ Hash-value for " FORTH" is &10
forth definitions meta
label dovar
stmfd sp !, { tos }
mov tos, link
next c; meta
label docon
stmfd sp !, { tos }
ldr tos, [ link ]
next c;
assembler dovar meta constant dovar
assembler docon meta constant docon
labcreate docol
stmfd rp !, { ip }
mov ip, link
next c;
labcreate dodoes
stmfd sp !, { tos }
mov tos, r0
stmfd rp !, { ip }
mov ip, link
next c;
labcreate dovalue
stmfd sp !, { tos }
ldr tos, [ link ]
next c;
labcreate dovalue!
str tos, [ link, # -8 ]
ldmfd sp !, { tos }
next c;
labcreate dovalue+!
ldr r0, [ link, # -12 ]
add r0, tos, r0
str r0, [ link, # -12 ]
ldmfd sp !, { tos }
next c;
labcreate do2value
stmfd sp !, { tos }
ldr tos, [ link ]
ldmfd tos, { tos, link }
stmfd sp !, { link }
next c; meta
variable lp
labcreate dolocal
stmfd sp !, { tos }
ldr tos, [ link ]
ldr r0, lp
ldr tos, [ r0, tos ]
next c;
labcreate dolocal!
ldr r0, [ link, # -8 ]
ldr r1, lp
str tos, [ r1, r0 ]
ldmfd sp !, { tos }
next c;
labcreate dolocal+!
ldr r0, [ link, # -12 ]
ldr r1, lp
ldr r0, [ r1, r0 ]!
add tos, tos, r0
str tos, [ r1 ]
ldmfd sp !, { tos }
next c;
labcreate docolp
ldr r0, lp
stmfd rp !, { r0, ip }
str rp, lp
mov ip, link
ldr r0, [ ip ], # 4
and r1, r0, # &ff
sub rp, rp, r1, lsl # 2
mov r0, r0, lsr # 8
and s r0, r0, # &ff
0<> if
begin
stmfd rp !, { tos }
ldmfd sp !, { tos }
sub s r0, r0, # 1
0= until
then
next c; meta
variable defer-list
variable loadfile thisfile loadfile !-t
code exitp
ldr rp, lp
ldmfd rp !, { r0, ip }
str r0, lp
next c;
code unnestp
ldr rp, lp
ldmfd rp !, { r0, ip }
str r0, lp
next c;
code exit ( -- )
ldmfd rp !, { ip }
next c;
code unnest ( -- ) \ Same as EXIT
ldmfd rp !, { ip }
next c;
code noop ( -- ) \ Does nothing (No-Operation)
next c;
code lit
stmfd sp !, { tos }
ldmfd ip !, { tos, pc }
c;
\ Execute the word whose CFA is on the stack.
code execute ( cfa -- )
mov r0, tos
ldmfd sp !, { tos }
mov pc, r0 c;
code pause
mov r0, r0
next c;
code branch ( -- ) \ an unconditional branch
ldr ip, [ ip ]
next c;
code ?branch ( f -- ) \ branch if f is zero
teq tos, # 0
ldmfd sp !, { tos }
ldmfd ne ip !, { r0, pc }
ldr ip, [ ip ]
next c;
code _begin
next c;
code _until
teq tos, # 0
ldmfd sp !, { tos }
ldmfd ne ip !, { r0, pc }
ldr ip, [ ip ]
next c;
code _again
ldr ip, [ ip ]
next c;
code _while
teq tos, # 0
ldmfd sp !, { tos }
ldmfd ne ip !, { r0, pc }
ldr ip, [ ip ]
next c;
code _repeat
ldr ip, [ ip ]
next c;
code _then
next c;
code _case
next c;
code _endcase
ldmfd sp !, { tos }
next c;
code _of
mov r0, tos
ldmfd sp !, { tos }
cmp r0, tos
ldr ne ip, [ ip ]
next ne
ldmfd sp !, { tos }
ldmfd ip !, { r0, pc } c;
code _endof ( -- ) \ an unconditional branch
ldr ip, [ ip ]
next
c;
code (do) ( lim sta -- ) \ Primitive form of DO
mov r3, tos
ldmfd sp !, { r1, tos }
ldr r2, [ ip ], # 4
add r1, r1, # &80000000
sub r0, r3, r1
stmfd rp !, { r0, r1, r2 }
next c;
code (?do) ( lim sta -- ) \ Primitive form of ?DO
mov r3, tos
ldmfd sp !, { r1, tos }
cmp r3, r1
ldr ne r2, [ ip ], # 4
add ne r1, r1, # &80000000
sub ne r0, r3, r1
stmfd ne rp !, { r0, r1, r2 }
next ne
ldr ip, [ ip ]
next c;
\ Clean up Return Stack so we can EXIT from DO-loop.
code unloop ( -- )
add rp, rp, # 12
next c;
code (loop) ( -- ) \ Primitive form of LOOP
ldr r0, [ rp ]
add s r0, r0, # 1
str vc r0, [ rp ]
ldr vc ip, [ ip ]
next vc
add rp, rp, # 12
ldmfd ip !, { r0, pc } c;
code (?loop) ( f -- )
orr s tos, tos, tos
ldmfd sp !, { tos }
next eq
ldr r0, [ rp ]
add s r0, r0, # 1
str vc r0, [ rp ]
ldr vc ip, [ ip ]
next vc
add rp, rp, # 12
ldmfd ip !, { r0, pc } c;
code (+loop) ( n -- ) \ Primitive form of +LOOP
ldr r0, [ rp ]
add s r0, r0, tos
ldmfd sp !, { tos }
str vc r0, [ rp ]
ldr vc ip, [ ip ]
next vc
add rp, rp, # 12
ldmfd ip !, { r0, pc } c;
code bounds ( n1 n2 --- n3 n4 ) \ Calculate limits used in DO-loop
mov r0, tos
ldr tos, [ sp ]
add r0, tos, r0
str r0, [ sp ]
next c;
code i ( -- n ) \ get index of the innermost loop
stmfd sp !, { tos }
ldr tos, [ rp ]
ldr r0, [ rp, # 4 ]
add tos, tos, r0
next c;
code j ( -- n ) \ get index of the second most inner loop.
stmfd sp !, { tos }
ldr tos, [ rp, # 12 ]
ldr r0, [ rp, # 16 ]
add tos, tos, r0
next c;
code leave ( -- )
add rp, rp, # 12
ldr ip, [ rp, # -4 ]
next c;
code ?leave ( f -- )
orr s tos, tos, tos
ldmfd sp !, { tos }
next eq
add rp, rp, # 12
ldr ip, [ rp, # -4 ]
next c;
variable sp0
variable rp0
variable hld
variable base
variable handler
variable msg
variable dp
\ sync the last few pages
code syncCode
ldr r0, dp
mov r1, # 0
begin
tst r0, # 3
0<> while
strb r1, [ r0 ], # 1
repeat
mov r2, r0
sub r1, r0, # 8192
mov r0, # 1
swi " OS_SynchroniseCodeAreas"
next c;
code here
stmfd sp !, { tos }
ldr tos, dp
next c;
code allot
ldr r0, dp
add r0, r0, tos
str r0, dp
ldmfd sp !, { tos }
ldr r0, dp
next c;
code compile,
ldr r0, dp
str tos, [ r0 ], # 4
str r0, dp
ldmfd sp !, { tos }
next c;
code ,
ldr r0, dp
str tos, [ r0 ], # 4
str r0, dp
ldmfd sp !, { tos }
next c;
code c,
ldr r0, dp
strb tos, [ r0 ], # 1
str r0, dp
ldmfd sp !, { tos }
next c;
code w,
ldr r0, dp
strb tos, [ r0 ], # 1
mov tos, tos, lsr # 8
strb tos, [ r0 ], # 1
str r0, dp
ldmfd sp !, { tos }
next c;
code compile
ldr r0, dp
ldmfd ip !, { r1, link }
str r1, [ r0 ], # 4
str r0, dp
mov pc, link c;
code align
ldr r0, dp
mov r1, # 0
begin
tst r0, # 3
0<> while
strb r1, [ r0 ], # 1
repeat
str r0, dp
next c;
code aligned
add tos, tos, # 3
bic tos, tos, # 3
next c;
labcreate m0cfa
ldr r0, lp
stmfd rp !, { r0, op, ip }
str rp, lp
mov ip, link
mov op, tos
ldmfd sp !, { tos }
ldr r0, [ ip, # 4 ]!
and r1, r0, # &ff
sub rp, rp, r1, lsl # 2
mov s r0, r0, lsr # 8
0<> if
begin
stmfd rp !, { tos }
ldmfd sp !, { tos }
sub s r0, r0, # 1
0= until
then
add ip, ip, # 4
next c;
labcreate m1cfa
ldr r0, lp
ldr r1, [ ip ], # 4
stmfd rp !, { r0, op, ip }
add op, r1, op
str rp, lp
mov ip, link
ldr r0, [ ip ], # 4
and r1, r0, # &ff
sub rp, rp, r1, lsl # 2
mov s r0, r0, lsr # 8
0<> if
begin
stmfd rp !, { tos }
ldmfd sp !, { tos }
sub s r0, r0, # 1
0= until
then
next c; meta
code exitm
ldr rp, lp
ldmfd rp !, { r0, op, ip }
str r0, lp
next c;
code unnestm
ldr rp, lp
ldmfd rp !, { r0, op, ip }
str r0, lp
next c;
code ^base
stmfd sp !, { tos }
mov tos, op
next c;
labcreate (iv@)
stmfd sp !, { tos }
ldr r0, [ link ]
ldr tos, [ r0, op ]
next c;
labcreate (iv!)
ldr r0, [ link, # -8 ]
str tos, [ r0, op ]
ldmfd sp !, { tos }
next c;
labcreate (iv+!)
ldr r0, [ link, # -12 ]
ldr r1, [ r0, op ]
add tos, tos, r1
str tos, [ r0, op ]
ldmfd sp !, { tos }
next c;
labcreate (iv[]@)
ldr r0, [ link ]
add r0, r0, op
ldr tos, [ r0, tos, lsl # 2 ]
next c;
labcreate (iv[]!)
ldr r0, [ link, # -8 ]
add r0, r0, tos, lsl # 2
ldmfd sp !, { r1, tos }
str r1, [ r0, op ]
next c;
labcreate (iv[]+!)
ldr r0, [ link, # -12 ]
add r0, r0, tos, lsl # 2
ldmfd sp !, { r2, tos }
ldr r1, [ r0, op ]!
add r1, r1, r2
str r1, [ r0 ]
next c;
labcreate doobj
stmfd sp !, { tos }
add tos, link, # 4
next c;
code ((findm))
ldmfd sp !, { r0 }
begin
ldr tos, [ tos ]
teq tos, # 0
next eq
ldr r1, [ tos, # 4 ]
cmp r0, r1
0= until
add tos, tos, # 8
stmfd sp !, { tos }
mvn tos, # 0
next c;
code hash ( ad cnt -- hash )
ldmfd sp !, { r0 }
mov r1, tos
mov tos, # 0
begin
ldrb r2, [ r0 ], # 1
eor tos, r2, tos, lsl # 1
sub s r1, r1, # 1
0= until
next c;
code init-locals
ldr r0, lp
stmfd rp !, { r0 }
str rp, lp
ldr r0, [ ip ], # 4
and r1, r0, # &ff
sub rp, rp, r1, lsl # 2
mov r0, r0, lsr # 8
and s r0, r0, # &ff
0<> if
begin
stmfd rp !, { tos }
ldmfd sp !, { tos }
sub s r0, r0, # 1
0= until
then
next c;
code unparms
ldr rp, lp
ldmfd rp !, { r0 }
str r0, lp
next c;
code _localalloc
sub rp, rp, tos
bic rp, rp, # 3
mov tos, rp
next c;
code drop ( n -- )
ldmfd sp !, { tos }
next c;
code dup ( n -- n n )
stmfd sp !, { tos }
next c;
code swap ( n1 n2 -- n2 n1 )
ldr r0, [ sp ]
str tos, [ sp ]
mov tos, r0
next c;
code over ( n1 n2 -- n1 n2 n1 )
stmfd sp !, { tos }
ldr tos, [ sp, # 4 ]
next c;
code rot ( n1 n2 n3 -- n2 n3 n1 )
mov r0, tos
ldmfd sp !, { r1, tos }
stmfd sp !, { r0, r1 }
next c;
code -rot ( n1 n2 n3 -- n3 n1 n2 )
ldmfd sp !, { r0, r1 }
stmfd sp !, { r1, tos }
mov tos, r0
next c;
code ?dup ( n -- 0 | n n )
orr s tos, tos, tos
stmfd ne sp !, { tos }
next c;
code -dup
orr s tos, tos, tos
stmfd ne sp !, { tos }
next c;
code nip ( n1 n2 -- n2 )
add sp, sp, # 4
next c;
code tuck ( n1 n2 -- n2 n1 n2 )
ldmfd sp !, { r0 }
stmfd sp !, { r0, tos }
next c;
code pick ( nk ... n0 k -- nk ... n0 nk )
ldr tos, [ sp, tos, lsl # 2 ]
next c;
code depth ( -- n )
stmfd sp !, { tos }
adr tos, sp0
ldr tos, [ tos ]
sub tos, tos, sp
mov tos, tos, asr # 2
next c;
\ Push the address of the top element on the stack (prior to push).
code sp@ ( -- n )
stmfd sp !, { tos }
mov tos, sp
next c;
\ Set the parameter stack pointer to specified value.
code sp! ( n -- )
mov sp, tos
ldmfd sp !, { tos }
next c;
\ address of the top element of the return stack
code rp@ ( -- ad )
stmfd sp !, { tos }
mov tos, rp
next c;
\ Set the return stack pointer to ad.
code rp! ( ad -- )
mov rp, tos
ldmfd sp !, { tos }
next c;
code >r ( n -- )
stmfd rp !, { tos }
ldmfd sp !, { tos }
next c;
code r> ( -- n )
stmfd sp !, { tos }
ldmfd rp !, { tos }
next c;
code r@ ( -- n )
stmfd sp !, { tos }
ldr tos, [ rp ]
next c;
code dup>r ( n -- n )
stmfd rp !, { tos }
next c;
code r>drop ( -- )
add rp, rp, # 4
next c;
code 2>r ( d -- )
mov r0, tos
ldmfd sp !, { r1, tos }
stmfd rp !, { r0, r1 }
next c;
code 2r> ( -- d )
ldr r0, [ rp, # 4 ]
stmfd sp !, { r0, tos }
ldr tos, [ rp ], # 8
next c;
code 2r@ ( -- d )
ldr r0, [ rp, # 4 ]
stmfd sp !, { r0, tos }
ldr tos, [ rp ]
next c;
code @ ( ad -- n ) \ Fetch a 32 bit value from addr
ldr tos, [ tos ]
next c;
code ! ( n ad -- ) \ Store value n into the address addr
mov r0, tos
ldmfd sp !, { r1, tos }
str r1, [ r0 ]
next c;
code +! ( n ad -- )
mov r1, tos
ldmfd sp !, { r0, tos }
ldr r2, [ r1 ]
add r2, r2, r0
str r2, [ r1 ]
next c;
code u/ ( n n1 -- n2 )
mov r1, tos
ldmfd sp !, { r0 }
udiv tos, r0, r1
next c;
code s/ ( n n1 -- n2 )
mov r1, tos
ldmfd sp !, { r0 }
sdiv tos, r0, r1
next c;
code c@ ( ad -- c )
ldrb tos, [ tos ]
next c;
code c! ( c ad -- )
mov r0, tos
ldmfd sp !, { r1, tos }
strb r1, [ r0 ]
next c;
code c+! ( c ad -- )
mov r1, tos
ldmfd sp !, { r0, tos }
ldrb r2, [ r1 ]
add r2, r2, r0
strb r2, [ r1 ]
next c;
\ non aligned fetch
code na@ ( ad -- n )
ldrb r0, [ tos ]
ldrb r1, [ tos, # 1 ]
add r0, r0, r1, lsl # 8
ldrb r1, [ tos, # 2 ]
add r0, r0, r1, lsl # 16
ldrb r1, [ tos, # 3 ]
add tos, r0, r1, lsl # 24
next c;
\ non aligned store
code na! ( n ad -- )
mov r0, tos
ldmfd sp !, { r1, tos }
strb r1, [ r0 ], # 1
mov r1, r1, lsr # 8
strb r1, [ r0 ], # 1
mov r1, r1, lsr # 8
strb r1, [ r0 ], # 1
mov r1, r1, lsr # 8
strb r1, [ r0 ], # 1
next c;
code call@ ( ad -- cfa )
ldr r0, [ tos ], # 8
mov r1, r0, lsr # 25
cmp r1, # 117
mov ne tos, r0
next ne
mov r0, r0, lsl # 8
mov r0, r0, asr # 6
add tos, tos, r0
next c;
\ 16 bit (half word) fetch
code w@ ( ad -- n )
ldrb r0, [ tos ]
ldrb r1, [ tos, # 1 ]
add tos, r0, r1, lsl # 8
next c;
\ Fetch a 16 bit value from addr
code sw@ ( ad -- n )
ldrb r0, [ tos ]
ldrb r1, [ tos, # 1 ]
add tos, r0, r1, lsl # 8
mov tos, tos, lsl # 16
mov tos, tos, asr # 16
next c;
\ Store 16 bit value n into the address addr
code w! ( n ad -- )
mov r0, tos
ldmfd sp !, { r1, tos }
strb r1, [ r0 ]
mov r1, r1, lsr # 8
strb r1, [ r0, # 1 ]
next c;
code w+! ( n ad -- )
mov r1, tos
ldmfd sp !, { r0, tos }
ldrb r3, [ r1 ]
ldrb r2, [ r1, # 1 ]
add r2, r3, r2 lsl # 8 ]
add r2, r2, r0
strb r2, [ r1 ]
mov r2, r2, lsr # 8
strb r2, [ r1, # 1 ]
next c;
\ 4 constant cell
code cell
stmfd sp !, { tos }
mov tos, # 4
next c;
code cells ( n1 -- n2 )
mov tos, tos, lsl # 2
next c;
code cells+ ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
add tos, r0, tos, lsl # 2
next c;
code cells- ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
sub tos, r0, tos, lsl # 2
next c;
code cell+ ( n1 -- n2 )
add tos, tos, # 4
next c;
code cell- ( n1 -- n2 )
sub tos, tos, # 4
next c;
code +cells ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
add tos, tos, r0, lsl # 2
next c;
code -cells ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
sub tos, tos, r0, lsl # 2
next c;
code move ( from to count -- )
mov s r3, tos
ldmfd sp !, { r0, r1, tos } \ to from
next eq
sub r2, r0, r1
cmp r2, r3
u>= if
begin
ldrb r2, [ r1 ], # 1
strb r2, [ r0 ], # 1
sub s r3, r3, # 1
0= until
next
else
add r0, r0, r3
add r1, r1, r3
sub r0, r0, # 1
sub r1, r1, # 1
begin
ldrb r2, [ r1 ], # -1
strb r2, [ r0 ], # -1
sub s r3, r3, # 1
0= until
next
then c;
code fill ( ad cnt c -- )
mov r0, tos
ldmfd sp !, { r1, r2, tos }
teq r1, # 0
next eq
begin
strb r0, [ r2 ], # 1
sub s r1, r1, # 1
0= until
next c;
\ 32 constant bl
code bl
stmfd sp !, { tos }
mov tos, # 32
next c;
: erase ( ad cnt -- )
0 fill ;
: blank ( ad cnt -- )
bl fill ;
\ moves block of memory beginning at from !!! traditional !!!
code cmove ( from to count -- )
mov s r3, tos
ldmfd sp !, { r0, r1, tos } \ count, to from
next eq
begin
ldrb r2, [ r1 ], # 1
strb r2, [ r0 ], # 1
sub s r3, r3, # 1
0= until
next c;
\ moves block of memory beginning at from+count-1 !!! traditional !!!
code cmove> ( from to count -- )
mov s r3, tos
ldmfd sp !, { r0, r1, tos } \ count, to from
next eq
add r0, r0, r3
add r1, r1, r3
sub r0, r0, # 1
sub r1, r1, # 1
begin
ldrb r2, [ r1 ], # -1
strb r2, [ r0 ], # -1
sub s r3, r3, # 1
0= until
next c;
code and ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
and tos, tos, r0
next c;
code or ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
orr tos, tos, r0
next c;
code xor ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
eor tos, tos, r0
next c;
code invert ( n1 -- n2 )
mvn tos, tos
next c;
code lshift ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
mov tos, r0, lsl tos
next c;
code rshift ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
mov tos, r0, lsr tos
next c;
-1 constant true
0 constant false
code incr ( ad -- )
ldr r0, [ tos ]
add r0, r0, # 1
str r0, [ tos ]
ldmfd sp !, { tos }
next c;
code decr ( ad -- )
ldr r0, [ tos ]
sub r0, r0, # 1
str r0, [ tos ]
ldmfd sp !, { tos }
next c;
code on ( ad -- )
mvn r0, # 0
str r0, [ tos ]
ldmfd sp !, { tos }
next c;
code off ( ad -- )
mov r0, # 0
str r0, [ tos ]
ldmfd sp !, { tos }
next c;
code toggle ( ad byte -- )
mov r0, tos
ldmfd sp !, { r1, tos }
ldrb r2, [ r1 ]
eor r2, r2, r0
strb r2, [ r1 ]
next c;
code + ( n1 n2 -- n3 )
ldmfd sp !, { r0 }
add tos, tos, r0