-
Notifications
You must be signed in to change notification settings - Fork 0
/
nachos-gcc.diff
2177 lines (2145 loc) · 56.3 KB
/
nachos-gcc.diff
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
diff -Naur n/code/build.linux/Makefile NachOS-4.0/code/build.linux/Makefile
--- n/code/build.linux/Makefile 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/build.linux/Makefile 2021-06-10 17:24:22.660288606 +0700
@@ -200,8 +200,9 @@
# break the thread system. You might want to use -fno-inline if
# you need to call some inline functions from the debugger.
-CFLAGS = -g -Wall -fwritable-strings $(INCPATH) $(DEFINES) $(HOSTCFLAGS) -DCHANGED
-LDFLAGS =
+CFLAGS = -g -Wall $(INCPATH) $(DEFINES) $(HOSTCFLAGS) -DCHANGED -m32
+LDFLAGS = -m32
+CPP_AS_FLAGS= -m32
#####################################################################
CPP=/lib/cpp
@@ -210,7 +211,7 @@
AS = as
RM = /bin/rm
-INCPATH = -I../network -I../filesys -I../userprog -I../threads -I../machine -I../lib
+INCPATH = -I../network -I../filesys -I../userprog -I../threads -I../machine -I../lib -I-
PROGRAM = nachos
@@ -336,13 +337,12 @@
$(C_OFILES): %.o:
$(CC) $(CFLAGS) -c $<
-switch.o: ../threads/switch.s
- $(CPP) $(CPP_AS_FLAGS) -P $(INCPATH) $(HOSTCFLAGS) ../threads/switch.s > swtch.s
- $(AS) -o switch.o swtch.s
+switch.o: ../threads/switch.S
+ $(CC) $(CPP_AS_FLAGS) -P $(INCPATH) $(HOSTCFLAGS) -c ../threads/switch.S
depend: $(CFILES) $(HFILES)
$(CC) $(INCPATH) $(DEFINES) $(HOSTCFLAGS) -DCHANGED -M $(CFILES) > makedep
- @echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
+ @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
@echo '$$r makedep' >>eddep
@echo 'w' >>eddep
@echo 'q' >>eddep
@@ -354,12 +354,19 @@
clean:
$(RM) -f $(OFILES)
- $(RM) -f swtch.s
distclean: clean
$(RM) -f $(PROGRAM)
$(RM) -f DISK_?
$(RM) -f core
$(RM) -f SOCKET_?
+ @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
+ @echo 'w' >>eddep
+ @echo 'q' >>eddep
+ ed - Makefile.dep < eddep
+ rm eddep
+ @echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.dep
+ @echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.dep
+ @echo '# see make depend above' >> Makefile.dep
include Makefile.dep
diff -Naur n/code/lib/list.cc NachOS-4.0/code/lib/list.cc
--- n/code/lib/list.cc 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/lib/list.cc 2021-06-10 17:26:44.712933321 +0700
@@ -236,27 +236,27 @@
ListElement<T> *element = new ListElement<T>(item);
ListElement<T> *ptr; // keep track
- ASSERT(!IsInList(item));
- if (IsEmpty()) { // if list is empty, put at front
- first = element;
- last = element;
- } else if (compare(item, first->item) < 0) { // item goes at front
- element->next = first;
- first = element;
+ ASSERT(!this->IsInList(item));
+ if (this->IsEmpty()) { // if list is empty, put at front
+ this->first = element;
+ this->last = element;
+ } else if (compare(item, this->first->item) < 0) { // item goes at front
+ element->next = this->first;
+ this->first = element;
} else { // look for first elt in list bigger than item
- for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
+ for (ptr = this->first; ptr->next != NULL; ptr = ptr->next) {
if (compare(item, ptr->next->item) < 0) {
element->next = ptr->next;
ptr->next = element;
- numInList++;
+ this->numInList++;
return;
}
}
- last->next = element; // item goes at end of list
- last = element;
+ this->last->next = element; // item goes at end of list
+ this->last = element;
}
- numInList++;
- ASSERT(IsInList(item));
+ this->numInList++;
+ ASSERT(this->IsInList(item));
}
//----------------------------------------------------------------------
@@ -338,8 +338,8 @@
ListElement<T> *prev, *ptr;
List<T>::SanityCheck();
- if (first != last) {
- for (prev = first, ptr = first->next; ptr != NULL;
+ if (this->first != this->last) {
+ for (prev = this->first, ptr = this->first->next; ptr != NULL;
prev = ptr, ptr = ptr->next) {
ASSERT(compare(prev->item, ptr->item) <= 0);
}
@@ -362,16 +362,16 @@
for (i = 0; i < numEntries; i++) {
Insert(p[i]);
- ASSERT(IsInList(p[i]));
+ ASSERT(this->IsInList(p[i]));
}
SanityCheck();
// should be able to get out everything we put in
for (i = 0; i < numEntries; i++) {
- q[i] = RemoveFront();
- ASSERT(!IsInList(q[i]));
+ q[i] = this->RemoveFront();
+ ASSERT(!this->IsInList(q[i]));
}
- ASSERT(IsEmpty());
+ ASSERT(this->IsEmpty());
// make sure everything came out in the right order
for (i = 0; i < (numEntries - 1); i++) {
diff -Naur n/code/lib/sysdep.cc NachOS-4.0/code/lib/sysdep.cc
--- n/code/lib/sysdep.cc 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/lib/sysdep.cc 2021-06-10 17:24:22.660288606 +0700
@@ -26,12 +26,13 @@
#include "copyright.h"
#include "debug.h"
#include "sysdep.h"
-#include "stdlib.h"
-#include "unistd.h"
-#include "sys/time.h"
-#include "sys/file.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/file.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <cerrno>
#ifdef SOLARIS
// KMS
@@ -509,9 +510,6 @@
ReadFromSocket(int sockID, char *buffer, int packetSize)
{
int retVal;
-#if defined(__GNUC__) && __GNUC__ < 3
- extern int errno;
-#endif
struct sockaddr_un uName;
#ifdef LINUX
socklen_t size = sizeof(uName);
diff -Naur n/code/lib/sysdep.h NachOS-4.0/code/lib/sysdep.h
--- n/code/lib/sysdep.h 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/lib/sysdep.h 2021-06-10 17:24:22.660288606 +0700
@@ -12,10 +12,12 @@
#define SYSDEP_H
#include "copyright.h"
-#include "iostream.h"
-#include "stdlib.h"
-#include "stdio.h"
-#include "string.h"
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+using namespace std;
// Process control: abort, exit, and sleep
extern void Abort();
diff -Naur n/code/test/Makefile NachOS-4.0/code/test/Makefile
--- n/code/test/Makefile 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/test/Makefile 2021-06-10 17:24:22.660288606 +0700
@@ -106,7 +106,7 @@
LD = $(GCCDIR)ld
INCDIR =-I../userprog -I../lib
-CFLAGS = -G 0 -c $(INCDIR)
+CFLAGS = -G 0 -c $(INCDIR) -B../../../usr/local/nachos/lib/gcc-lib/decstation-ultrix/2.95.2/ -B../../../usr/local/nachos/decstation-ultrix/bin/
ifeq ($(hosttype),unknown)
PROGRAMS = unknownhost
@@ -117,10 +117,8 @@
all: $(PROGRAMS)
-start.o: start.s ../userprog/syscall.h
- $(CPP) $(CPPFLAGS) start.s > strt.s
- $(AS) $(ASFLAGS) -o start.o strt.s
- rm strt.s
+start.o: start.S ../userprog/syscall.h
+ $(CC) $(CFLAGS) $(ASFLAGS) -c start.S
halt.o: halt.c
$(CC) $(CFLAGS) -c halt.c
diff -Naur n/code/test/Makefile.dep NachOS-4.0/code/test/Makefile.dep
--- n/code/test/Makefile.dep 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/test/Makefile.dep 2021-06-10 17:24:22.660288606 +0700
@@ -21,9 +21,9 @@
ifeq ($(osname),Linux)
# full path name of your cpp program i.e.:
-CPP = /usr/local/nachos/lib/gcc-lib/decstation-ultrix/2.95.2/cpp
+CPP = ../../../usr/local/nachos/lib/gcc-lib/decstation-ultrix/2.95.2/cpp
# directory in which your gcc cross-compiler lives i.e.:
-GCCDIR = /usr/local/nachos/bin/decstation-ultrix-
+GCCDIR = ../../../usr/local/nachos/bin/decstation-ultrix-
LDFLAGS = -T script -N
ASFLAGS = -mips2
CPPFLAGS = $(INCDIR)
diff -Naur n/code/test/start.s NachOS-4.0/code/test/start.s
--- n/code/test/start.s 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/test/start.s 1970-01-01 08:00:00.000000000 +0800
@@ -1,187 +0,0 @@
-/* Start.s
- * Assembly language assist for user programs running on top of Nachos.
- *
- * Since we don't want to pull in the entire C library, we define
- * what we need for a user program here, namely Start and the system
- * calls.
- */
-
-#define IN_ASM
-#include "syscall.h"
-
- .text
- .align 2
-
-/* -------------------------------------------------------------
- * __start
- * Initialize running a C program, by calling "main".
- *
- * NOTE: This has to be first, so that it gets loaded at location 0.
- * The Nachos kernel always starts a program by jumping to location 0.
- * -------------------------------------------------------------
- */
-
- .globl __start
- .ent __start
-__start:
- jal main
- move $4,$0
- jal Exit /* if we return from main, exit(0) */
- .end __start
-
-/* -------------------------------------------------------------
- * System call stubs:
- * Assembly language assist to make system calls to the Nachos kernel.
- * There is one stub per system call, that places the code for the
- * system call into register r2, and leaves the arguments to the
- * system call alone (in other words, arg1 is in r4, arg2 is
- * in r5, arg3 is in r6, arg4 is in r7)
- *
- * The return value is in r2. This follows the standard C calling
- * convention on the MIPS.
- * -------------------------------------------------------------
- */
-
- .globl Halt
- .ent Halt
-Halt:
- addiu $2,$0,SC_Halt
- syscall
- j $31
- .end Halt
-
- .globl Add
- .ent Add
-Add:
- addiu $2,$0,SC_Add
- syscall
- j $31
- .end Add
-
- .globl Exit
- .ent Exit
-Exit:
- addiu $2,$0,SC_Exit
- syscall
- j $31
- .end Exit
-
- .globl Exec
- .ent Exec
-Exec:
- addiu $2,$0,SC_Exec
- syscall
- j $31
- .end Exec
-
- .globl ExecV
- .ent ExecV
-ExecV:
- addiu $2,$0,SC_ExecV
- syscall
- j $31
- .end ExecV
-
- .globl Join
- .ent Join
-Join:
- addiu $2,$0,SC_Join
- syscall
- j $31
- .end Join
-
- .globl Create
- .ent Create
-Create:
- addiu $2,$0,SC_Create
- syscall
- j $31
- .end Create
-
- .globl Remove
- .ent Remove
-Remove:
- addiu $2,$0,SC_Remove
- syscall
- j $31
- .end Remove
-
- .globl Open
- .ent Open
-Open:
- addiu $2,$0,SC_Open
- syscall
- j $31
- .end Open
-
- .globl Read
- .ent Read
-Read:
- addiu $2,$0,SC_Read
- syscall
- j $31
- .end Read
-
- .globl Write
- .ent Write
-Write:
- addiu $2,$0,SC_Write
- syscall
- j $31
- .end Write
-
- .globl Close
- .ent Close
-Close:
- addiu $2,$0,SC_Close
- syscall
- j $31
- .end Close
-
- .globl Seek
- .ent Seek
-Seek:
- addiu $2,$0,SC_Seek
- syscall
- j $31
- .end Seek
-
- .globl ThreadFork
- .ent ThreadFork
-ThreadFork:
- addiu $2,$0,SC_ThreadFork
- syscall
- j $31
- .end ThreadFork
-
- .globl ThreadYield
- .ent ThreadYield
-ThreadYield:
- addiu $2,$0,SC_ThreadYield
- syscall
- j $31
- .end ThreadYield
-
- .globl ThreadExit
- .ent ThreadExit
-ThreadExit:
- addiu $2, $0, SC_ThreadExit
- syscall
- j $31
- .end ThreadExit
-
- .globl ThreadJoin
- .ent ThreadJoin
-ThreadJoin:
- addiu $2, $0, SC_ThreadJoin
- syscall
- j $31
- .end ThreadJoin
-
-/* dummy function to keep gcc happy */
- .globl __main
- .ent __main
-__main:
- j $31
- .end __main
-
diff -Naur n/code/test/start.S NachOS-4.0/code/test/start.S
--- n/code/test/start.S 1970-01-01 08:00:00.000000000 +0800
+++ NachOS-4.0/code/test/start.S 2021-06-10 17:24:22.660288606 +0700
@@ -0,0 +1,187 @@
+/* Start.s
+ * Assembly language assist for user programs running on top of Nachos.
+ *
+ * Since we don't want to pull in the entire C library, we define
+ * what we need for a user program here, namely Start and the system
+ * calls.
+ */
+
+#define IN_ASM
+#include "syscall.h"
+
+ .text
+ .align 2
+
+/* -------------------------------------------------------------
+ * __start
+ * Initialize running a C program, by calling "main".
+ *
+ * NOTE: This has to be first, so that it gets loaded at location 0.
+ * The Nachos kernel always starts a program by jumping to location 0.
+ * -------------------------------------------------------------
+ */
+
+ .globl __start
+ .ent __start
+__start:
+ jal main
+ move $4,$0
+ jal Exit /* if we return from main, exit(0) */
+ .end __start
+
+/* -------------------------------------------------------------
+ * System call stubs:
+ * Assembly language assist to make system calls to the Nachos kernel.
+ * There is one stub per system call, that places the code for the
+ * system call into register r2, and leaves the arguments to the
+ * system call alone (in other words, arg1 is in r4, arg2 is
+ * in r5, arg3 is in r6, arg4 is in r7)
+ *
+ * The return value is in r2. This follows the standard C calling
+ * convention on the MIPS.
+ * -------------------------------------------------------------
+ */
+
+ .globl Halt
+ .ent Halt
+Halt:
+ addiu $2,$0,SC_Halt
+ syscall
+ j $31
+ .end Halt
+
+ .globl Add
+ .ent Add
+Add:
+ addiu $2,$0,SC_Add
+ syscall
+ j $31
+ .end Add
+
+ .globl Exit
+ .ent Exit
+Exit:
+ addiu $2,$0,SC_Exit
+ syscall
+ j $31
+ .end Exit
+
+ .globl Exec
+ .ent Exec
+Exec:
+ addiu $2,$0,SC_Exec
+ syscall
+ j $31
+ .end Exec
+
+ .globl ExecV
+ .ent ExecV
+ExecV:
+ addiu $2,$0,SC_ExecV
+ syscall
+ j $31
+ .end ExecV
+
+ .globl Join
+ .ent Join
+Join:
+ addiu $2,$0,SC_Join
+ syscall
+ j $31
+ .end Join
+
+ .globl Create
+ .ent Create
+Create:
+ addiu $2,$0,SC_Create
+ syscall
+ j $31
+ .end Create
+
+ .globl Remove
+ .ent Remove
+Remove:
+ addiu $2,$0,SC_Remove
+ syscall
+ j $31
+ .end Remove
+
+ .globl Open
+ .ent Open
+Open:
+ addiu $2,$0,SC_Open
+ syscall
+ j $31
+ .end Open
+
+ .globl Read
+ .ent Read
+Read:
+ addiu $2,$0,SC_Read
+ syscall
+ j $31
+ .end Read
+
+ .globl Write
+ .ent Write
+Write:
+ addiu $2,$0,SC_Write
+ syscall
+ j $31
+ .end Write
+
+ .globl Close
+ .ent Close
+Close:
+ addiu $2,$0,SC_Close
+ syscall
+ j $31
+ .end Close
+
+ .globl Seek
+ .ent Seek
+Seek:
+ addiu $2,$0,SC_Seek
+ syscall
+ j $31
+ .end Seek
+
+ .globl ThreadFork
+ .ent ThreadFork
+ThreadFork:
+ addiu $2,$0,SC_ThreadFork
+ syscall
+ j $31
+ .end ThreadFork
+
+ .globl ThreadYield
+ .ent ThreadYield
+ThreadYield:
+ addiu $2,$0,SC_ThreadYield
+ syscall
+ j $31
+ .end ThreadYield
+
+ .globl ThreadExit
+ .ent ThreadExit
+ThreadExit:
+ addiu $2, $0, SC_ThreadExit
+ syscall
+ j $31
+ .end ThreadExit
+
+ .globl ThreadJoin
+ .ent ThreadJoin
+ThreadJoin:
+ addiu $2, $0, SC_ThreadJoin
+ syscall
+ j $31
+ .end ThreadJoin
+
+/* dummy function to keep gcc happy */
+ .globl __main
+ .ent __main
+__main:
+ j $31
+ .end __main
+
diff -Naur n/code/threads/switch.s NachOS-4.0/code/threads/switch.s
--- n/code/threads/switch.s 2002-12-16 17:57:00.000000000 +0700
+++ NachOS-4.0/code/threads/switch.s 1970-01-01 08:00:00.000000000 +0800
@@ -1,750 +0,0 @@
-/* switch.s
- * Machine dependent context switch routines. DO NOT MODIFY THESE!
- *
- * Context switching is inherently machine dependent, since
- * the registers to be saved, how to set up an initial
- * call frame, etc, are all specific to a processor architecture.
- *
- * This file currently supports the following architectures:
- * DEC MIPS (DECMIPS)
- * DEC Alpha (ALPHA)
- * SUN SPARC (SPARC)
- * HP PA-RISC (PARISC)
- * Intel 386 (x86)
- * IBM RS6000 (PowerPC) -- I hope it will also work for Mac PowerPC
- *
- * We define two routines for each architecture:
- *
- * ThreadRoot(InitialPC, InitialArg, WhenDonePC, StartupPC)
- * InitialPC - The program counter of the procedure to run
- * in this thread.
- * InitialArg - The single argument to the thread.
- * WhenDonePC - The routine to call when the thread returns.
- * StartupPC - Routine to call when the thread is started.
- *
- * ThreadRoot is called from the SWITCH() routine to start
- * a thread for the first time.
- *
- * SWITCH(oldThread, newThread)
- * oldThread - The current thread that was running, where the
- * CPU register state is to be saved.
- * newThread - The new thread to be run, where the CPU register
- * state is to be loaded from.
- */
-
-/*
- Copyright (c) 1992-1996 The Regents of the University of California.
- All rights reserved. See copyright.h for copyright notice and limitation
- of liability and disclaimer of warranty provisions.
- */
-
-#include "copyright.h"
-#include "switch.h"
-
-
-#ifdef DECMIPS
-
-/* Symbolic register names */
-#define z $0 /* zero register */
-#define a0 $4 /* argument registers */
-#define a1 $5
-#define s0 $16 /* callee saved */
-#define s1 $17
-#define s2 $18
-#define s3 $19
-#define s4 $20
-#define s5 $21
-#define s6 $22
-#define s7 $23
-#define sp $29 /* stack pointer */
-#define fp $30 /* frame pointer */
-#define ra $31 /* return address */
-
- .text
- .align 2
-
- .globl ThreadRoot
- .ent ThreadRoot,0
-ThreadRoot:
- or fp,z,z # Clearing the frame pointer here
- # makes gdb backtraces of thread stacks
- # end here (I hope!)
-
- jal StartupPC # call startup procedure
- move a0, InitialArg
- jal InitialPC # call main procedure
- jal WhenDonePC # when done, call clean up procedure
-
- # NEVER REACHED
- .end ThreadRoot
-
- # a0 -- pointer to old Thread
- # a1 -- pointer to new Thread
- .globl SWITCH
- .ent SWITCH,0
-SWITCH:
- sw sp, SP(a0) # save new stack pointer
- sw s0, S0(a0) # save all the callee-save registers
- sw s1, S1(a0)
- sw s2, S2(a0)
- sw s3, S3(a0)
- sw s4, S4(a0)
- sw s5, S5(a0)
- sw s6, S6(a0)
- sw s7, S7(a0)
- sw fp, FP(a0) # save frame pointer
- sw ra, PC(a0) # save return address
-
- lw sp, SP(a1) # load the new stack pointer
- lw s0, S0(a1) # load the callee-save registers
- lw s1, S1(a1)
- lw s2, S2(a1)
- lw s3, S3(a1)
- lw s4, S4(a1)
- lw s5, S5(a1)
- lw s6, S6(a1)
- lw s7, S7(a1)
- lw fp, FP(a1)
- lw ra, PC(a1) # load the return address
-
- j ra
- .end SWITCH
-
-#endif // DECMIPS
-
-
-
-#ifdef SPARC
-
-/* NOTE! These files appear not to exist on Solaris --
- * you need to find where (the SPARC-specific) MINFRAME, ST_FLUSH_WINDOWS, ...
- * are defined. (I don't have a Solaris machine, so I have no way to tell.)
- */
-#ifdef SOLARIS
-#include <sys/trap.h>
-#include <sys/asm_linkage.h>
-#else
-#include <sun4/trap.h>
-#include <sun4/asm_linkage.h>
-#endif
-.seg "text"
-
-/* SPECIAL to the SPARC:
- * The first two instruction of ThreadRoot are skipped because
- * the address of ThreadRoot is made the return address of SWITCH()
- * by the routine Thread::StackAllocate. SWITCH() jumps here on the
- * "ret" instruction which is really at "jmp %o7+8". The 8 skips the
- * two nops at the beginning of the routine.
- */
-
-#ifdef SOLARIS
-.globl ThreadRoot
-ThreadRoot:
-#else
-.globl _ThreadRoot
-_ThreadRoot:
-#endif
- nop ; nop /* These 2 nops are skipped because we are called
- * with a jmp+8 instruction. */
- clr %fp /* Clearing the frame pointer makes gdb backtraces
- * of thread stacks end here. */
- /* Currently the arguments are in out registers we
- * save them into local registers so they won't be
- * trashed during the calls we make. */
- mov InitialPC, %l0
- mov InitialArg, %l1
- mov WhenDonePC, %l2
- /* Execute the code:
- * call StartupPC();
- * call InitialPC(InitialArg);
- * call WhenDonePC();
- */
- call StartupPC,0
- nop
- call %l0, 1
- mov %l1, %o0 /* Using delay slot to setup argument to InitialPC */
- call %l2, 0
- nop
- /* WhenDonePC call should never return. If it does
- * we execute a trap into the debugger. */
- ta ST_BREAKPOINT
-
-
-#ifdef SOLARIS
-.globl SWITCH
-SWITCH:
-#else
-.globl _SWITCH
-_SWITCH:
-#endif
- save %sp, -SA(MINFRAME), %sp
- st %fp, [%i0]
- st %i0, [%i0+I0]
- st %i1, [%i0+I1]
- st %i2, [%i0+I2]
- st %i3, [%i0+I3]
- st %i4, [%i0+I4]
- st %i5, [%i0+I5]
- st %i7, [%i0+I7]
- ta ST_FLUSH_WINDOWS
- nop
- mov %i1, %l0
- ld [%l0+I0], %i0
- ld [%l0+I1], %i1
- ld [%l0+I2], %i2
- ld [%l0+I3], %i3
- ld [%l0+I4], %i4
- ld [%l0+I5], %i5
- ld [%l0+I7], %i7
- ld [%l0], %i6
- ret
- restore
-
-#endif // SPARC
-
-
-
-#ifdef PARISC
-
- ;rp = r2, sp = r30
- ;arg0 = r26, arg1 = r25, arg2 = r24, arg3 = r23
-
- .SPACE $TEXT$
- .SUBSPA $CODE$
-ThreadRoot
- .PROC
- .CALLINFO CALLER,FRAME=0
- .ENTER
-
- .CALL
- ble 0(%r6) ;call StartupPC
- stw %r31, -24(%sp) ;put return address in proper stack
- ;location for StartupPC export stub.
-
- or %r4, 0, %arg0 ;load InitialArg
- .CALL ;in=26
- ble 0(%r3) ;call InitialPC
- stw %r31, -24(%sp) ;put return address in proper stack
- ;location for InitialPC export stub.
-
- .CALL
- ble 0(%r5) ;call WhenDonePC
- stw %r31, -24(%sp) ;put return address in proper stack
- ;location for StartupPC export stub.
- .LEAVE
-
- .PROCEND
-
-
-SWITCH
- .PROC
- .CALLINFO CALLER,FRAME=0
- .ENTRY
-
- ; save process state of oldThread
- stw %sp, SP(%arg0) ;save stack pointer
- stw %r3, S0(%arg0) ;save callee-save registers
- stw %r4, S1(%arg0)
- stw %r5, S2(%arg0)
- stw %r6, S3(%arg0)
- stw %r7, S4(%arg0)
- stw %r8, S5(%arg0)
- stw %r9, S6(%arg0)
- stw %r10, S7(%arg0)
- stw %r11, S8(%arg0)
- stw %r12, S9(%arg0)
- stw %r13, S10(%arg0)
- stw %r14, S11(%arg0)
- stw %r15, S12(%arg0)
- stw %r16, S13(%arg0)
- stw %r17, S14(%arg0)
- stw %r18, S15(%arg0)
- stw %rp, PC(%arg0) ;save program counter
-
- ; restore process state of nextThread
- ldw SP(%arg1), %sp ;restore stack pointer
- ldw S0(%arg1), %r3 ;restore callee-save registers
- ldw S1(%arg1), %r4
- ldw S2(%arg1), %r5
- ldw S3(%arg1), %r6
- ldw S4(%arg1), %r7
- ldw S5(%arg1), %r8
- ldw S6(%arg1), %r9
- ldw S7(%arg1), %r10
- ldw S8(%arg1), %r11
- ldw S9(%arg1), %r12
- ldw S10(%arg1), %r13
- ldw S11(%arg1), %r14
- ldw S12(%arg1), %r15
- ldw S13(%arg1), %r16
- ldw S14(%arg1), %r17
- ldw PC(%arg1), %rp ;save program counter
- bv 0(%rp)
- .EXIT
- ldw S15(%arg1), %r18
-
- .PROCEND
-
- .EXPORT SWITCH,ENTRY,PRIV_LEV=3,RTNVAL=GR
- .EXPORT ThreadRoot,ENTRY,PRIV_LEV=3,RTNVAL=GR
-
-#endif // PARISC
-
-
-
-#ifdef x86
-
- .text
- .align 2
-
- .globl ThreadRoot
- .globl _ThreadRoot
-
-/* void ThreadRoot( void )
-**
-** expects the following registers to be initialized:
-** eax points to startup function (interrupt enable)
-** edx contains inital argument to thread function
-** esi points to thread function
-** edi point to Thread::Finish()
-*/
-_ThreadRoot:
-ThreadRoot:
- pushl %ebp
- movl %esp,%ebp
- pushl InitialArg
- call *StartupPC
- call *InitialPC
- call *WhenDonePC
-
- # NOT REACHED
- movl %ebp,%esp
- popl %ebp
- ret
-
-
-
-/* void SWITCH( thread *t1, thread *t2 )
-**
-** on entry, stack looks like this:
-** 8(esp) -> thread *t2
-** 4(esp) -> thread *t1
-** (esp) -> return address
-**
-** we push the current eax on the stack so that we can use it as
-** a pointer to t1, this decrements esp by 4, so when we use it
-** to reference stuff on the stack, we add 4 to the offset.
-*/
- .comm _eax_save,4
-
- .globl SWITCH
- .globl _SWITCH
-_SWITCH:
-SWITCH:
- movl %eax,_eax_save # save the value of eax
- movl 4(%esp),%eax # move pointer to t1 into eax
- movl %ebx,_EBX(%eax) # save registers
- movl %ecx,_ECX(%eax)
- movl %edx,_EDX(%eax)
- movl %esi,_ESI(%eax)
- movl %edi,_EDI(%eax)
- movl %ebp,_EBP(%eax)
- movl %esp,_ESP(%eax) # save stack pointer
- movl _eax_save,%ebx # get the saved value of eax
- movl %ebx,_EAX(%eax) # store it
- movl 0(%esp),%ebx # get return address from stack into ebx
- movl %ebx,_PC(%eax) # save it into the pc storage
-
- movl 8(%esp),%eax # move pointer to t2 into eax
-
- movl _EAX(%eax),%ebx # get new value for eax into ebx
- movl %ebx,_eax_save # save it
- movl _EBX(%eax),%ebx # retore old registers
- movl _ECX(%eax),%ecx
- movl _EDX(%eax),%edx
- movl _ESI(%eax),%esi
- movl _EDI(%eax),%edi
- movl _EBP(%eax),%ebp
- movl _ESP(%eax),%esp # restore stack pointer
- movl _PC(%eax),%eax # restore return address into eax
- movl %eax,4(%esp) # copy over the ret address on the stack
- movl _eax_save,%eax
-
- ret
-
-#endif // x86
-
-
-#if defined(ApplePowerPC)
-
- /* The AIX PowerPC code is incompatible with the assembler on MacOS X
- * and Linux. So the SWITCH code was adapted for IBM 750 compatible
- * processors, and ThreadRoot is modeled after the more reasonable
- * looking ThreadRoot's in this file.
- *
- * Joshua LeVasseur <[email protected]>