-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.asm
8134 lines (7743 loc) · 358 KB
/
kernel.asm
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
kernel: file format elf64-littleriscv
Disassembly of section .text:
0000000080000000 <_entry>:
80000000: 00009117 auipc sp,0x9
80000004: d7813103 ld sp,-648(sp) # 80008d78 <_GLOBAL_OFFSET_TABLE_+0x58>
80000008: 00001537 lui a0,0x1
8000000c: f14025f3 csrr a1,mhartid
80000010: 00158593 addi a1,a1,1
80000014: 02b50533 mul a0,a0,a1
80000018: 00a10133 add sp,sp,a0
8000001c: 39d040ef jal ra,80004bb8 <start>
0000000080000020 <spin>:
80000020: 0000006f j 80000020 <spin>
...
0000000080001000 <_ZN5Riscv14supervisorTrapEv>:
.align 4
.global _ZN5Riscv14supervisorTrapEv
.type _ZN5Riscv14supervisorTrapEv, @function
_ZN5Riscv14supervisorTrapEv:
# push all registers to stack
addi sp, sp, -256
80001000: f0010113 addi sp,sp,-256
.irp index, 0,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
sd x\index, \index * 8(sp)
.endr
80001004: 00013023 sd zero,0(sp)
80001008: 00113423 sd ra,8(sp)
8000100c: 00213823 sd sp,16(sp)
80001010: 00313c23 sd gp,24(sp)
80001014: 02413023 sd tp,32(sp)
80001018: 02513423 sd t0,40(sp)
8000101c: 02613823 sd t1,48(sp)
80001020: 02713c23 sd t2,56(sp)
80001024: 04813023 sd s0,64(sp)
80001028: 04913423 sd s1,72(sp)
8000102c: 04a13823 sd a0,80(sp)
80001030: 04b13c23 sd a1,88(sp)
80001034: 06c13023 sd a2,96(sp)
80001038: 06d13423 sd a3,104(sp)
8000103c: 06e13823 sd a4,112(sp)
80001040: 06f13c23 sd a5,120(sp)
80001044: 09013023 sd a6,128(sp)
80001048: 09113423 sd a7,136(sp)
8000104c: 09213823 sd s2,144(sp)
80001050: 09313c23 sd s3,152(sp)
80001054: 0b413023 sd s4,160(sp)
80001058: 0b513423 sd s5,168(sp)
8000105c: 0b613823 sd s6,176(sp)
80001060: 0b713c23 sd s7,184(sp)
80001064: 0d813023 sd s8,192(sp)
80001068: 0d913423 sd s9,200(sp)
8000106c: 0da13823 sd s10,208(sp)
80001070: 0db13c23 sd s11,216(sp)
80001074: 0fc13023 sd t3,224(sp)
80001078: 0fd13423 sd t4,232(sp)
8000107c: 0fe13823 sd t5,240(sp)
80001080: 0ff13c23 sd t6,248(sp)
call _ZN5Riscv20handleSupervisorTrapEv
80001084: 008020ef jal ra,8000308c <_ZN5Riscv20handleSupervisorTrapEv>
csrr t2, scause
80001088: 142023f3 csrr t2,scause
addi t3, x0, 8
8000108c: 00800e13 li t3,8
beq t2, t3, restore
80001090: 01c38863 beq t2,t3,800010a0 <restore>
addi t3, x0, 9
80001094: 00900e13 li t3,9
beq t2, t3, restore
80001098: 01c38463 beq t2,t3,800010a0 <restore>
j skip
8000109c: 0080006f j 800010a4 <skip>
00000000800010a0 <restore>:
restore:
sd x10, 80(sp)
800010a0: 04a13823 sd a0,80(sp)
00000000800010a4 <skip>:
skip:
# pop all registers from stack
.irp index, 0,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
ld x\index, \index * 8(sp)
.endr
800010a4: 00013003 ld zero,0(sp)
800010a8: 00813083 ld ra,8(sp)
800010ac: 01013103 ld sp,16(sp)
800010b0: 01813183 ld gp,24(sp)
800010b4: 02013203 ld tp,32(sp)
800010b8: 02813283 ld t0,40(sp)
800010bc: 03013303 ld t1,48(sp)
800010c0: 03813383 ld t2,56(sp)
800010c4: 04013403 ld s0,64(sp)
800010c8: 04813483 ld s1,72(sp)
800010cc: 05013503 ld a0,80(sp)
800010d0: 05813583 ld a1,88(sp)
800010d4: 06013603 ld a2,96(sp)
800010d8: 06813683 ld a3,104(sp)
800010dc: 07013703 ld a4,112(sp)
800010e0: 07813783 ld a5,120(sp)
800010e4: 08013803 ld a6,128(sp)
800010e8: 08813883 ld a7,136(sp)
800010ec: 09013903 ld s2,144(sp)
800010f0: 09813983 ld s3,152(sp)
800010f4: 0a013a03 ld s4,160(sp)
800010f8: 0a813a83 ld s5,168(sp)
800010fc: 0b013b03 ld s6,176(sp)
80001100: 0b813b83 ld s7,184(sp)
80001104: 0c013c03 ld s8,192(sp)
80001108: 0c813c83 ld s9,200(sp)
8000110c: 0d013d03 ld s10,208(sp)
80001110: 0d813d83 ld s11,216(sp)
80001114: 0e013e03 ld t3,224(sp)
80001118: 0e813e83 ld t4,232(sp)
8000111c: 0f013f03 ld t5,240(sp)
80001120: 0f813f83 ld t6,248(sp)
addi sp, sp, 256
80001124: 10010113 addi sp,sp,256
80001128: 10200073 sret
8000112c: 0000 unimp
...
0000000080001130 <_ZN3TCB13contextSwitchEPNS_7ContextES1_>:
.global _ZN3TCB13contextSwitchEPNS_7ContextES1_
.type _ZN3TCB13contextSwitchEPNS_7ContextES1_, @function
_ZN3TCB13contextSwitchEPNS_7ContextES1_:
sd ra, 0 * 8(a0)
80001130: 00153023 sd ra,0(a0) # 1000 <_entry-0x7ffff000>
sd sp, 1 * 8(a0)
80001134: 00253423 sd sp,8(a0)
ld ra, 0 * 8(a1)
80001138: 0005b083 ld ra,0(a1)
ld sp, 1 * 8(a1)
8000113c: 0085b103 ld sp,8(a1)
80001140: 00008067 ret
0000000080001144 <copy_and_swap>:
# a1 holds expected value
# a2 holds desired value
# a0 holds return value, 0 if successful, !0 otherwise
.global copy_and_swap
copy_and_swap:
lr.w t0, (a0) # Load original value.
80001144: 100522af lr.w t0,(a0)
bne t0, a1, fail # Doesn’t match, so fail.
80001148: 00b29a63 bne t0,a1,8000115c <fail>
sc.w t0, a2, (a0) # Try to update.
8000114c: 18c522af sc.w t0,a2,(a0)
bnez t0, copy_and_swap # Retry if store-conditional failed.
80001150: fe029ae3 bnez t0,80001144 <copy_and_swap>
li a0, 0 # Set return to success.
80001154: 00000513 li a0,0
jr ra # Return.
80001158: 00008067 ret
000000008000115c <fail>:
fail:
li a0, 1 # Set return to failure.
8000115c: 00100513 li a0,1
80001160: 00008067 ret
0000000080001164 <_Z9move_regsv>:
#include "../h/syscall_c.h"
#include "../lib/hw.h"
#include "../h/tcb.hpp"
void move_regs(){
80001164: ff010113 addi sp,sp,-16
80001168: 00813423 sd s0,8(sp)
8000116c: 01010413 addi s0,sp,16
__asm__ volatile ("mv a7, a6");
80001170: 00080893 mv a7,a6
__asm__ volatile ("mv a6, a5");
80001174: 00078813 mv a6,a5
__asm__ volatile ("mv a5, a4");
80001178: 00070793 mv a5,a4
__asm__ volatile ("mv a4, a3");
8000117c: 00068713 mv a4,a3
__asm__ volatile ("mv a3, a2");
80001180: 00060693 mv a3,a2
__asm__ volatile ("mv a2, a1");
80001184: 00058613 mv a2,a1
__asm__ volatile ("mv a1, a0");
80001188: 00050593 mv a1,a0
}
8000118c: 00813403 ld s0,8(sp)
80001190: 01010113 addi sp,sp,16
80001194: 00008067 ret
0000000080001198 <_Z9mem_allocm>:
//==========[MEMORY]=============================================================
void* mem_alloc (size_t size){
80001198: ff010113 addi sp,sp,-16
8000119c: 00813423 sd s0,8(sp)
800011a0: 01010413 addi s0,sp,16
uint64 func_id=0x01;
uint64 result;
if(size<=0) return nullptr;
800011a4: 02050a63 beqz a0,800011d8 <_Z9mem_allocm+0x40>
size_t my_size=size/MEM_BLOCK_SIZE;
800011a8: 00655793 srli a5,a0,0x6
if(size % MEM_BLOCK_SIZE > 0){
800011ac: 03f57513 andi a0,a0,63
800011b0: 00050463 beqz a0,800011b8 <_Z9mem_allocm+0x20>
my_size++;
800011b4: 00178793 addi a5,a5,1
}
__asm__ volatile ("mv a1, %0" : : "r" (my_size));
800011b8: 00078593 mv a1,a5
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800011bc: 00100793 li a5,1
800011c0: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800011c4: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800011c8: 00050513 mv a0,a0
return (void*)result;
}
800011cc: 00813403 ld s0,8(sp)
800011d0: 01010113 addi sp,sp,16
800011d4: 00008067 ret
if(size<=0) return nullptr;
800011d8: 00000513 li a0,0
800011dc: ff1ff06f j 800011cc <_Z9mem_allocm+0x34>
00000000800011e0 <_Z8mem_freePv>:
int mem_free (void* p){
uint64 func_id=0x02;
uint64 result;
if(p==nullptr) return -8;
800011e0: 04050263 beqz a0,80001224 <_Z8mem_freePv+0x44>
int mem_free (void* p){
800011e4: ff010113 addi sp,sp,-16
800011e8: 00113423 sd ra,8(sp)
800011ec: 00813023 sd s0,0(sp)
800011f0: 01010413 addi s0,sp,16
move_regs();
800011f4: 00000097 auipc ra,0x0
800011f8: f70080e7 jalr -144(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800011fc: 00200793 li a5,2
80001200: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001204: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001208: 00050513 mv a0,a0
if(result!=0) return -8;
8000120c: 02051063 bnez a0,8000122c <_Z8mem_freePv+0x4c>
else return result;
80001210: 0005051b sext.w a0,a0
}
80001214: 00813083 ld ra,8(sp)
80001218: 00013403 ld s0,0(sp)
8000121c: 01010113 addi sp,sp,16
80001220: 00008067 ret
if(p==nullptr) return -8;
80001224: ff800513 li a0,-8
}
80001228: 00008067 ret
if(result!=0) return -8;
8000122c: ff800513 li a0,-8
80001230: fe5ff06f j 80001214 <_Z8mem_freePv+0x34>
0000000080001234 <_Z13thread_createPP3TCBPFvPvES2_>:
//==========[THREADS]=============================================================
int thread_create (thread_t* handle, void(*start_routine)(void*),void* arg){
uint64 func_id=0x11;
uint64 result;
if(handle==nullptr) return -4;
80001234: 06050c63 beqz a0,800012ac <_Z13thread_createPP3TCBPFvPvES2_+0x78>
int thread_create (thread_t* handle, void(*start_routine)(void*),void* arg){
80001238: fd010113 addi sp,sp,-48
8000123c: 02113423 sd ra,40(sp)
80001240: 02813023 sd s0,32(sp)
80001244: 00913c23 sd s1,24(sp)
80001248: 01213823 sd s2,16(sp)
8000124c: 01313423 sd s3,8(sp)
80001250: 03010413 addi s0,sp,48
80001254: 00050493 mv s1,a0
80001258: 00058993 mv s3,a1
8000125c: 00060913 mv s2,a2
uint64* stack=(uint64*)mem_alloc((size_t)DEFAULT_STACK_SIZE * sizeof(uint64));
80001260: 00008537 lui a0,0x8
80001264: 00000097 auipc ra,0x0
80001268: f34080e7 jalr -204(ra) # 80001198 <_Z9mem_allocm>
__asm__ volatile ("mv a1, %0" : : "r" (handle));
8000126c: 00048593 mv a1,s1
__asm__ volatile ("mv a2, %0" : : "r" (start_routine));
80001270: 00098613 mv a2,s3
__asm__ volatile ("mv a3, %0" : : "r" (arg));
80001274: 00090693 mv a3,s2
__asm__ volatile ("mv a4, %0" : : "r" (stack));
80001278: 00050713 mv a4,a0
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
8000127c: 01100793 li a5,17
80001280: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001284: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001288: 00050513 mv a0,a0
return result;
8000128c: 0005051b sext.w a0,a0
}
80001290: 02813083 ld ra,40(sp)
80001294: 02013403 ld s0,32(sp)
80001298: 01813483 ld s1,24(sp)
8000129c: 01013903 ld s2,16(sp)
800012a0: 00813983 ld s3,8(sp)
800012a4: 03010113 addi sp,sp,48
800012a8: 00008067 ret
if(handle==nullptr) return -4;
800012ac: ffc00513 li a0,-4
}
800012b0: 00008067 ret
00000000800012b4 <_Z11thread_exitv>:
int thread_exit (){
800012b4: ff010113 addi sp,sp,-16
800012b8: 00813423 sd s0,8(sp)
800012bc: 01010413 addi s0,sp,16
uint64 func_id=0x12;
uint64 result;
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800012c0: 01200793 li a5,18
800012c4: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800012c8: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800012cc: 00050513 mv a0,a0
return result;
}
800012d0: 0005051b sext.w a0,a0
800012d4: 00813403 ld s0,8(sp)
800012d8: 01010113 addi sp,sp,16
800012dc: 00008067 ret
00000000800012e0 <_Z15thread_dispatchv>:
void thread_dispatch (){
800012e0: ff010113 addi sp,sp,-16
800012e4: 00813423 sd s0,8(sp)
800012e8: 01010413 addi s0,sp,16
uint64 func_id=0x13;
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800012ec: 01300793 li a5,19
800012f0: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800012f4: 00000073 ecall
}
800012f8: 00813403 ld s0,8(sp)
800012fc: 01010113 addi sp,sp,16
80001300: 00008067 ret
0000000080001304 <_Z11thread_makePP3TCBPFvPvES2_>:
int thread_make (thread_t* handle, void(*start_routine)(void*),void* arg){
uint64 func_id=0x14;
uint64 result;
if(handle==nullptr) return -4;
80001304: 06050c63 beqz a0,8000137c <_Z11thread_makePP3TCBPFvPvES2_+0x78>
int thread_make (thread_t* handle, void(*start_routine)(void*),void* arg){
80001308: fd010113 addi sp,sp,-48
8000130c: 02113423 sd ra,40(sp)
80001310: 02813023 sd s0,32(sp)
80001314: 00913c23 sd s1,24(sp)
80001318: 01213823 sd s2,16(sp)
8000131c: 01313423 sd s3,8(sp)
80001320: 03010413 addi s0,sp,48
80001324: 00050493 mv s1,a0
80001328: 00058993 mv s3,a1
8000132c: 00060913 mv s2,a2
void* stack=mem_alloc(DEFAULT_STACK_SIZE * sizeof(uint64));
80001330: 00008537 lui a0,0x8
80001334: 00000097 auipc ra,0x0
80001338: e64080e7 jalr -412(ra) # 80001198 <_Z9mem_allocm>
__asm__ volatile ("mv a1, %0" : : "r" (handle));
8000133c: 00048593 mv a1,s1
__asm__ volatile ("mv a2, %0" : : "r" (start_routine));
80001340: 00098613 mv a2,s3
__asm__ volatile ("mv a3, %0" : : "r" (arg));
80001344: 00090693 mv a3,s2
__asm__ volatile ("mv a4, %0" : : "r" (stack));
80001348: 00050713 mv a4,a0
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
8000134c: 01400793 li a5,20
80001350: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001354: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001358: 00050513 mv a0,a0
return result;
8000135c: 0005051b sext.w a0,a0
}
80001360: 02813083 ld ra,40(sp)
80001364: 02013403 ld s0,32(sp)
80001368: 01813483 ld s1,24(sp)
8000136c: 01013903 ld s2,16(sp)
80001370: 00813983 ld s3,8(sp)
80001374: 03010113 addi sp,sp,48
80001378: 00008067 ret
if(handle==nullptr) return -4;
8000137c: ffc00513 li a0,-4
}
80001380: 00008067 ret
0000000080001384 <_Z12thread_startP3TCB>:
int thread_start (thread_t handle){
uint64 func_id=0x15;
uint64 result;
if(handle==nullptr) return -8;
80001384: 04050063 beqz a0,800013c4 <_Z12thread_startP3TCB+0x40>
int thread_start (thread_t handle){
80001388: ff010113 addi sp,sp,-16
8000138c: 00113423 sd ra,8(sp)
80001390: 00813023 sd s0,0(sp)
80001394: 01010413 addi s0,sp,16
move_regs();
80001398: 00000097 auipc ra,0x0
8000139c: dcc080e7 jalr -564(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800013a0: 01500793 li a5,21
800013a4: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800013a8: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800013ac: 00050513 mv a0,a0
return result;
800013b0: 0005051b sext.w a0,a0
}
800013b4: 00813083 ld ra,8(sp)
800013b8: 00013403 ld s0,0(sp)
800013bc: 01010113 addi sp,sp,16
800013c0: 00008067 ret
if(handle==nullptr) return -8;
800013c4: ff800513 li a0,-8
}
800013c8: 00008067 ret
00000000800013cc <_Z8sem_openPP4_semj>:
//==========[SEMS]=============================================================
int sem_open (sem_t* handle, unsigned init){
uint64 func_id=0x21;
uint64 result;
if(!handle) return -2;
800013cc: 04050063 beqz a0,8000140c <_Z8sem_openPP4_semj+0x40>
int sem_open (sem_t* handle, unsigned init){
800013d0: ff010113 addi sp,sp,-16
800013d4: 00113423 sd ra,8(sp)
800013d8: 00813023 sd s0,0(sp)
800013dc: 01010413 addi s0,sp,16
move_regs();
800013e0: 00000097 auipc ra,0x0
800013e4: d84080e7 jalr -636(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800013e8: 02100793 li a5,33
800013ec: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800013f0: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800013f4: 00050513 mv a0,a0
return result;
800013f8: 0005051b sext.w a0,a0
}
800013fc: 00813083 ld ra,8(sp)
80001400: 00013403 ld s0,0(sp)
80001404: 01010113 addi sp,sp,16
80001408: 00008067 ret
if(!handle) return -2;
8000140c: ffe00513 li a0,-2
}
80001410: 00008067 ret
0000000080001414 <_Z9sem_closeP4_sem>:
int sem_close (sem_t handle){
uint64 func_id=0x22;
uint64 result;
if(handle==nullptr) return -16;
80001414: 04050063 beqz a0,80001454 <_Z9sem_closeP4_sem+0x40>
int sem_close (sem_t handle){
80001418: ff010113 addi sp,sp,-16
8000141c: 00113423 sd ra,8(sp)
80001420: 00813023 sd s0,0(sp)
80001424: 01010413 addi s0,sp,16
move_regs();
80001428: 00000097 auipc ra,0x0
8000142c: d3c080e7 jalr -708(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
80001430: 02200793 li a5,34
80001434: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001438: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
8000143c: 00050513 mv a0,a0
return result;
80001440: 0005051b sext.w a0,a0
}
80001444: 00813083 ld ra,8(sp)
80001448: 00013403 ld s0,0(sp)
8000144c: 01010113 addi sp,sp,16
80001450: 00008067 ret
if(handle==nullptr) return -16;
80001454: ff000513 li a0,-16
}
80001458: 00008067 ret
000000008000145c <_Z8sem_waitP4_sem>:
int sem_wait (sem_t id){
uint64 func_id=0x23;
uint64 result;
if(id==nullptr) return -16;
8000145c: 04050063 beqz a0,8000149c <_Z8sem_waitP4_sem+0x40>
int sem_wait (sem_t id){
80001460: ff010113 addi sp,sp,-16
80001464: 00113423 sd ra,8(sp)
80001468: 00813023 sd s0,0(sp)
8000146c: 01010413 addi s0,sp,16
move_regs();
80001470: 00000097 auipc ra,0x0
80001474: cf4080e7 jalr -780(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
80001478: 02300793 li a5,35
8000147c: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001480: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001484: 00050513 mv a0,a0
return result;
80001488: 0005051b sext.w a0,a0
}
8000148c: 00813083 ld ra,8(sp)
80001490: 00013403 ld s0,0(sp)
80001494: 01010113 addi sp,sp,16
80001498: 00008067 ret
if(id==nullptr) return -16;
8000149c: ff000513 li a0,-16
}
800014a0: 00008067 ret
00000000800014a4 <_Z10sem_signalP4_sem>:
int sem_signal (sem_t id) {
uint64 func_id=0x24;
uint64 result;
if(id==nullptr) return -16;
800014a4: 04050063 beqz a0,800014e4 <_Z10sem_signalP4_sem+0x40>
int sem_signal (sem_t id) {
800014a8: ff010113 addi sp,sp,-16
800014ac: 00113423 sd ra,8(sp)
800014b0: 00813023 sd s0,0(sp)
800014b4: 01010413 addi s0,sp,16
move_regs();
800014b8: 00000097 auipc ra,0x0
800014bc: cac080e7 jalr -852(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800014c0: 02400793 li a5,36
800014c4: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800014c8: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800014cc: 00050513 mv a0,a0
return result;
800014d0: 0005051b sext.w a0,a0
}
800014d4: 00813083 ld ra,8(sp)
800014d8: 00013403 ld s0,0(sp)
800014dc: 01010113 addi sp,sp,16
800014e0: 00008067 ret
if(id==nullptr) return -16;
800014e4: ff000513 li a0,-16
}
800014e8: 00008067 ret
00000000800014ec <_Z10time_sleepm>:
//==========[MISC]=============================================================
int time_sleep (time_t t){
800014ec: ff010113 addi sp,sp,-16
800014f0: 00113423 sd ra,8(sp)
800014f4: 00813023 sd s0,0(sp)
800014f8: 01010413 addi s0,sp,16
uint64 func_id=0x31;
uint64 result;
move_regs();
800014fc: 00000097 auipc ra,0x0
80001500: c68080e7 jalr -920(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
80001504: 03100793 li a5,49
80001508: 00078513 mv a0,a5
__asm__ volatile ("ecall");
8000150c: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001510: 00050513 mv a0,a0
return result;
}
80001514: 0005051b sext.w a0,a0
80001518: 00813083 ld ra,8(sp)
8000151c: 00013403 ld s0,0(sp)
80001520: 01010113 addi sp,sp,16
80001524: 00008067 ret
0000000080001528 <_Z4getcv>:
char getc(){
80001528: ff010113 addi sp,sp,-16
8000152c: 00813423 sd s0,8(sp)
80001530: 01010413 addi s0,sp,16
uint64 func_id=0x41;
uint64 result;
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
80001534: 04100793 li a5,65
80001538: 00078513 mv a0,a5
__asm__ volatile ("ecall");
8000153c: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
80001540: 00050513 mv a0,a0
return (char)result;
}
80001544: 0ff57513 andi a0,a0,255
80001548: 00813403 ld s0,8(sp)
8000154c: 01010113 addi sp,sp,16
80001550: 00008067 ret
0000000080001554 <_Z4putcc>:
void putc(char c){
80001554: ff010113 addi sp,sp,-16
80001558: 00113423 sd ra,8(sp)
8000155c: 00813023 sd s0,0(sp)
80001560: 01010413 addi s0,sp,16
uint64 func_id=0x42;
move_regs();
80001564: 00000097 auipc ra,0x0
80001568: c00080e7 jalr -1024(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
8000156c: 04200793 li a5,66
80001570: 00078513 mv a0,a5
__asm__ volatile ("ecall");
80001574: 00000073 ecall
}
80001578: 00813083 ld ra,8(sp)
8000157c: 00013403 ld s0,0(sp)
80001580: 01010113 addi sp,sp,16
80001584: 00008067 ret
0000000080001588 <_Z17test_function_abiii>:
int test_function_abi(int param1, int param2){
80001588: ff010113 addi sp,sp,-16
8000158c: 00113423 sd ra,8(sp)
80001590: 00813023 sd s0,0(sp)
80001594: 01010413 addi s0,sp,16
uint64 func_id=0x69;
uint64 result;
move_regs();
80001598: 00000097 auipc ra,0x0
8000159c: bcc080e7 jalr -1076(ra) # 80001164 <_Z9move_regsv>
__asm__ volatile ("mv a0, %0" : : "r" (func_id));
800015a0: 06900793 li a5,105
800015a4: 00078513 mv a0,a5
__asm__ volatile ("ecall");
800015a8: 00000073 ecall
__asm__ volatile ("mv %0, a0" : "=r" (result));
800015ac: 00050513 mv a0,a0
return result;
800015b0: 0005051b sext.w a0,a0
800015b4: 00813083 ld ra,8(sp)
800015b8: 00013403 ld s0,0(sp)
800015bc: 01010113 addi sp,sp,16
800015c0: 00008067 ret
00000000800015c4 <__mem_alloc>:
// Created by DjordjeS on 8.8.2022.
//
#include "../lib/mem.h"
#include "../h/MemoryAllocator.hpp"
void* __mem_alloc(size_t size){
800015c4: ff010113 addi sp,sp,-16
800015c8: 00113423 sd ra,8(sp)
800015cc: 00813023 sd s0,0(sp)
800015d0: 01010413 addi s0,sp,16
return MemoryAllocator::allocate(size);
800015d4: 00002097 auipc ra,0x2
800015d8: 2c4080e7 jalr 708(ra) # 80003898 <_ZN15MemoryAllocator8allocateEm>
}
800015dc: 00813083 ld ra,8(sp)
800015e0: 00013403 ld s0,0(sp)
800015e4: 01010113 addi sp,sp,16
800015e8: 00008067 ret
00000000800015ec <__mem_free>:
int __mem_free(void *ptr){
800015ec: ff010113 addi sp,sp,-16
800015f0: 00113423 sd ra,8(sp)
800015f4: 00813023 sd s0,0(sp)
800015f8: 01010413 addi s0,sp,16
return MemoryAllocator::free_memory(ptr);
800015fc: 00002097 auipc ra,0x2
80001600: 3e0080e7 jalr 992(ra) # 800039dc <_ZN15MemoryAllocator11free_memoryEPv>
}
80001604: 00813083 ld ra,8(sp)
80001608: 00013403 ld s0,0(sp)
8000160c: 01010113 addi sp,sp,16
80001610: 00008067 ret
0000000080001614 <_ZN9SemaphoreD1Ev>:
Semaphore::Semaphore(unsigned init) {
sem_open(&myHandle, init);
}
Semaphore::~Semaphore() {
80001614: ff010113 addi sp,sp,-16
80001618: 00113423 sd ra,8(sp)
8000161c: 00813023 sd s0,0(sp)
80001620: 01010413 addi s0,sp,16
80001624: 00007797 auipc a5,0x7
80001628: 5fc78793 addi a5,a5,1532 # 80008c20 <_ZTV9Semaphore+0x10>
8000162c: 00f53023 sd a5,0(a0) # 8000 <_entry-0x7fff8000>
sem_close(myHandle);
80001630: 00853503 ld a0,8(a0)
80001634: 00000097 auipc ra,0x0
80001638: de0080e7 jalr -544(ra) # 80001414 <_Z9sem_closeP4_sem>
}
8000163c: 00813083 ld ra,8(sp)
80001640: 00013403 ld s0,0(sp)
80001644: 01010113 addi sp,sp,16
80001648: 00008067 ret
000000008000164c <_ZN9SemaphoreD0Ev>:
Semaphore::~Semaphore() {
8000164c: fe010113 addi sp,sp,-32
80001650: 00113c23 sd ra,24(sp)
80001654: 00813823 sd s0,16(sp)
80001658: 00913423 sd s1,8(sp)
8000165c: 02010413 addi s0,sp,32
80001660: 00050493 mv s1,a0
}
80001664: 00000097 auipc ra,0x0
80001668: fb0080e7 jalr -80(ra) # 80001614 <_ZN9SemaphoreD1Ev>
8000166c: 00048513 mv a0,s1
80001670: 00001097 auipc ra,0x1
80001674: f7c080e7 jalr -132(ra) # 800025ec <_ZdlPv>
80001678: 01813083 ld ra,24(sp)
8000167c: 01013403 ld s0,16(sp)
80001680: 00813483 ld s1,8(sp)
80001684: 02010113 addi sp,sp,32
80001688: 00008067 ret
000000008000168c <_ZN9SemaphoreC1Ej>:
Semaphore::Semaphore(unsigned init) {
8000168c: ff010113 addi sp,sp,-16
80001690: 00113423 sd ra,8(sp)
80001694: 00813023 sd s0,0(sp)
80001698: 01010413 addi s0,sp,16
8000169c: 00007797 auipc a5,0x7
800016a0: 58478793 addi a5,a5,1412 # 80008c20 <_ZTV9Semaphore+0x10>
800016a4: 00f53023 sd a5,0(a0)
sem_open(&myHandle, init);
800016a8: 00850513 addi a0,a0,8
800016ac: 00000097 auipc ra,0x0
800016b0: d20080e7 jalr -736(ra) # 800013cc <_Z8sem_openPP4_semj>
}
800016b4: 00813083 ld ra,8(sp)
800016b8: 00013403 ld s0,0(sp)
800016bc: 01010113 addi sp,sp,16
800016c0: 00008067 ret
00000000800016c4 <_ZN9Semaphore4waitEv>:
int Semaphore::wait() {
800016c4: ff010113 addi sp,sp,-16
800016c8: 00113423 sd ra,8(sp)
800016cc: 00813023 sd s0,0(sp)
800016d0: 01010413 addi s0,sp,16
return sem_wait(myHandle);
800016d4: 00853503 ld a0,8(a0)
800016d8: 00000097 auipc ra,0x0
800016dc: d84080e7 jalr -636(ra) # 8000145c <_Z8sem_waitP4_sem>
}
800016e0: 00813083 ld ra,8(sp)
800016e4: 00013403 ld s0,0(sp)
800016e8: 01010113 addi sp,sp,16
800016ec: 00008067 ret
00000000800016f0 <_ZN9Semaphore6signalEv>:
int Semaphore::signal() {
800016f0: ff010113 addi sp,sp,-16
800016f4: 00113423 sd ra,8(sp)
800016f8: 00813023 sd s0,0(sp)
800016fc: 01010413 addi s0,sp,16
return sem_signal(myHandle);
80001700: 00853503 ld a0,8(a0)
80001704: 00000097 auipc ra,0x0
80001708: da0080e7 jalr -608(ra) # 800014a4 <_Z10sem_signalP4_sem>
}
8000170c: 00813083 ld ra,8(sp)
80001710: 00013403 ld s0,0(sp)
80001714: 01010113 addi sp,sp,16
80001718: 00008067 ret
000000008000171c <_ZN6Thread13threadWrapperEPv>:
int Thread::sleep(time_t t) {
return time_sleep(t);
}
void Thread::threadWrapper(void* t) {
if(t){
8000171c: 02050863 beqz a0,8000174c <_ZN6Thread13threadWrapperEPv+0x30>
void Thread::threadWrapper(void* t) {
80001720: ff010113 addi sp,sp,-16
80001724: 00113423 sd ra,8(sp)
80001728: 00813023 sd s0,0(sp)
8000172c: 01010413 addi s0,sp,16
((Thread*)t)->run();
80001730: 00053783 ld a5,0(a0)
80001734: 0107b783 ld a5,16(a5)
80001738: 000780e7 jalr a5
}
}
8000173c: 00813083 ld ra,8(sp)
80001740: 00013403 ld s0,0(sp)
80001744: 01010113 addi sp,sp,16
80001748: 00008067 ret
8000174c: 00008067 ret
0000000080001750 <_ZN6ThreadD1Ev>:
Thread::~Thread() {
80001750: fe010113 addi sp,sp,-32
80001754: 00113c23 sd ra,24(sp)
80001758: 00813823 sd s0,16(sp)
8000175c: 00913423 sd s1,8(sp)
80001760: 02010413 addi s0,sp,32
80001764: 00007797 auipc a5,0x7
80001768: 4e478793 addi a5,a5,1252 # 80008c48 <_ZTV6Thread+0x10>
8000176c: 00f53023 sd a5,0(a0)
delete myHandle;
80001770: 00853483 ld s1,8(a0)
80001774: 00048e63 beqz s1,80001790 <_ZN6ThreadD1Ev+0x40>
80001778: 00048513 mv a0,s1
8000177c: 00000097 auipc ra,0x0
80001780: 464080e7 jalr 1124(ra) # 80001be0 <_ZN3TCBD1Ev>
class TCB{
public:
//---[NEW i DELETE]--------------------------------------------
void *operator new(size_t n){return __mem_alloc(n);}
void *operator new[](size_t n){return __mem_alloc(n);}
void operator delete(void *p) {__mem_free(p);}
80001784: 00048513 mv a0,s1
80001788: 00000097 auipc ra,0x0
8000178c: e64080e7 jalr -412(ra) # 800015ec <__mem_free>
}
80001790: 01813083 ld ra,24(sp)
80001794: 01013403 ld s0,16(sp)
80001798: 00813483 ld s1,8(sp)
8000179c: 02010113 addi sp,sp,32
800017a0: 00008067 ret
00000000800017a4 <_ZN6ThreadD0Ev>:
Thread::~Thread() {
800017a4: fe010113 addi sp,sp,-32
800017a8: 00113c23 sd ra,24(sp)
800017ac: 00813823 sd s0,16(sp)
800017b0: 00913423 sd s1,8(sp)
800017b4: 02010413 addi s0,sp,32
800017b8: 00050493 mv s1,a0
}
800017bc: 00000097 auipc ra,0x0
800017c0: f94080e7 jalr -108(ra) # 80001750 <_ZN6ThreadD1Ev>
800017c4: 00048513 mv a0,s1
800017c8: 00001097 auipc ra,0x1
800017cc: e24080e7 jalr -476(ra) # 800025ec <_ZdlPv>
800017d0: 01813083 ld ra,24(sp)
800017d4: 01013403 ld s0,16(sp)
800017d8: 00813483 ld s1,8(sp)
800017dc: 02010113 addi sp,sp,32
800017e0: 00008067 ret
00000000800017e4 <_ZN6ThreadC1EPFvPvES0_>:
Thread::Thread(void (*body)(void *), void *arg) {
800017e4: ff010113 addi sp,sp,-16
800017e8: 00113423 sd ra,8(sp)
800017ec: 00813023 sd s0,0(sp)
800017f0: 01010413 addi s0,sp,16
800017f4: 00007797 auipc a5,0x7
800017f8: 45478793 addi a5,a5,1108 # 80008c48 <_ZTV6Thread+0x10>
800017fc: 00f53023 sd a5,0(a0)
thread_make(&myHandle, body, arg);
80001800: 00850513 addi a0,a0,8
80001804: 00000097 auipc ra,0x0
80001808: b00080e7 jalr -1280(ra) # 80001304 <_Z11thread_makePP3TCBPFvPvES2_>
}
8000180c: 00813083 ld ra,8(sp)
80001810: 00013403 ld s0,0(sp)
80001814: 01010113 addi sp,sp,16
80001818: 00008067 ret
000000008000181c <_ZN6Thread5startEv>:
int Thread::start() {
8000181c: ff010113 addi sp,sp,-16
80001820: 00113423 sd ra,8(sp)
80001824: 00813023 sd s0,0(sp)
80001828: 01010413 addi s0,sp,16
return thread_start(myHandle);
8000182c: 00853503 ld a0,8(a0)
80001830: 00000097 auipc ra,0x0
80001834: b54080e7 jalr -1196(ra) # 80001384 <_Z12thread_startP3TCB>
}
80001838: 00813083 ld ra,8(sp)
8000183c: 00013403 ld s0,0(sp)
80001840: 01010113 addi sp,sp,16
80001844: 00008067 ret
0000000080001848 <_ZN6Thread8dispatchEv>:
void Thread::dispatch() {
80001848: ff010113 addi sp,sp,-16
8000184c: 00113423 sd ra,8(sp)
80001850: 00813023 sd s0,0(sp)
80001854: 01010413 addi s0,sp,16
thread_dispatch();
80001858: 00000097 auipc ra,0x0
8000185c: a88080e7 jalr -1400(ra) # 800012e0 <_Z15thread_dispatchv>
}
80001860: 00813083 ld ra,8(sp)
80001864: 00013403 ld s0,0(sp)
80001868: 01010113 addi sp,sp,16
8000186c: 00008067 ret
0000000080001870 <_ZN6Thread5sleepEm>:
int Thread::sleep(time_t t) {
80001870: ff010113 addi sp,sp,-16
80001874: 00113423 sd ra,8(sp)
80001878: 00813023 sd s0,0(sp)
8000187c: 01010413 addi s0,sp,16
return time_sleep(t);
80001880: 00000097 auipc ra,0x0
80001884: c6c080e7 jalr -916(ra) # 800014ec <_Z10time_sleepm>
}
80001888: 00813083 ld ra,8(sp)
8000188c: 00013403 ld s0,0(sp)
80001890: 01010113 addi sp,sp,16
80001894: 00008067 ret
0000000080001898 <_ZN6ThreadC1Ev>:
Thread::Thread() {
80001898: ff010113 addi sp,sp,-16
8000189c: 00113423 sd ra,8(sp)
800018a0: 00813023 sd s0,0(sp)
800018a4: 01010413 addi s0,sp,16
800018a8: 00007797 auipc a5,0x7
800018ac: 3a078793 addi a5,a5,928 # 80008c48 <_ZTV6Thread+0x10>
800018b0: 00f53023 sd a5,0(a0)
thread_make(&myHandle, threadWrapper, this);
800018b4: 00050613 mv a2,a0
800018b8: 00000597 auipc a1,0x0