-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.asm
1651 lines (1527 loc) · 47.6 KB
/
init.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
_init: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
char *argv[] = { "sh", 0 };
int
main(void)
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 53 push %ebx
e: 51 push %ecx
int pid, wpid;
if(open("console", O_RDWR) < 0){
f: 83 ec 08 sub $0x8,%esp
12: 6a 02 push $0x2
14: 68 c0 07 00 00 push $0x7c0
19: e8 54 03 00 00 call 372 <open>
1e: 83 c4 10 add $0x10,%esp
21: 85 c0 test %eax,%eax
23: 0f 88 9f 00 00 00 js c8 <main+0xc8>
mknod("console", 1, 1);
open("console", O_RDWR);
}
dup(0); // stdout
29: 83 ec 0c sub $0xc,%esp
2c: 6a 00 push $0x0
2e: e8 77 03 00 00 call 3aa <dup>
dup(0); // stderr
33: c7 04 24 00 00 00 00 movl $0x0,(%esp)
3a: e8 6b 03 00 00 call 3aa <dup>
3f: 83 c4 10 add $0x10,%esp
42: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(;;){
printf(1, "init: starting sh\n");
48: 83 ec 08 sub $0x8,%esp
4b: 68 c8 07 00 00 push $0x7c8
50: 6a 01 push $0x1
52: e8 49 04 00 00 call 4a0 <printf>
pid = fork();
57: e8 ce 02 00 00 call 32a <fork>
if(pid < 0){
5c: 83 c4 10 add $0x10,%esp
5f: 85 c0 test %eax,%eax
dup(0); // stdout
dup(0); // stderr
for(;;){
printf(1, "init: starting sh\n");
pid = fork();
61: 89 c3 mov %eax,%ebx
if(pid < 0){
63: 78 2c js 91 <main+0x91>
printf(1, "init: fork failed\n");
exit();
}
if(pid == 0){
65: 74 3d je a4 <main+0xa4>
67: 89 f6 mov %esi,%esi
69: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid)
70: e8 c5 02 00 00 call 33a <wait>
75: 85 c0 test %eax,%eax
77: 78 cf js 48 <main+0x48>
79: 39 c3 cmp %eax,%ebx
7b: 74 cb je 48 <main+0x48>
printf(1, "zombie!\n");
7d: 83 ec 08 sub $0x8,%esp
80: 68 07 08 00 00 push $0x807
85: 6a 01 push $0x1
87: e8 14 04 00 00 call 4a0 <printf>
8c: 83 c4 10 add $0x10,%esp
8f: eb df jmp 70 <main+0x70>
for(;;){
printf(1, "init: starting sh\n");
pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
91: 53 push %ebx
92: 53 push %ebx
93: 68 db 07 00 00 push $0x7db
98: 6a 01 push $0x1
9a: e8 01 04 00 00 call 4a0 <printf>
exit();
9f: e8 8e 02 00 00 call 332 <exit>
}
if(pid == 0){
exec("sh", argv);
a4: 50 push %eax
a5: 50 push %eax
a6: 68 b4 0a 00 00 push $0xab4
ab: 68 ee 07 00 00 push $0x7ee
b0: e8 b5 02 00 00 call 36a <exec>
printf(1, "init: exec sh failed\n");
b5: 5a pop %edx
b6: 59 pop %ecx
b7: 68 f1 07 00 00 push $0x7f1
bc: 6a 01 push $0x1
be: e8 dd 03 00 00 call 4a0 <printf>
exit();
c3: e8 6a 02 00 00 call 332 <exit>
main(void)
{
int pid, wpid;
if(open("console", O_RDWR) < 0){
mknod("console", 1, 1);
c8: 50 push %eax
c9: 6a 01 push $0x1
cb: 6a 01 push $0x1
cd: 68 c0 07 00 00 push $0x7c0
d2: e8 a3 02 00 00 call 37a <mknod>
open("console", O_RDWR);
d7: 58 pop %eax
d8: 5a pop %edx
d9: 6a 02 push $0x2
db: 68 c0 07 00 00 push $0x7c0
e0: e8 8d 02 00 00 call 372 <open>
e5: 83 c4 10 add $0x10,%esp
e8: e9 3c ff ff ff jmp 29 <main+0x29>
ed: 66 90 xchg %ax,%ax
ef: 90 nop
000000f0 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 53 push %ebx
f4: 8b 45 08 mov 0x8(%ebp),%eax
f7: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
fa: 89 c2 mov %eax,%edx
fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
100: 83 c1 01 add $0x1,%ecx
103: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
107: 83 c2 01 add $0x1,%edx
10a: 84 db test %bl,%bl
10c: 88 5a ff mov %bl,-0x1(%edx)
10f: 75 ef jne 100 <strcpy+0x10>
;
return os;
}
111: 5b pop %ebx
112: 5d pop %ebp
113: c3 ret
114: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
11a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000120 <strcmp>:
int
strcmp(const char *p, const char *q)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 56 push %esi
124: 53 push %ebx
125: 8b 55 08 mov 0x8(%ebp),%edx
128: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
12b: 0f b6 02 movzbl (%edx),%eax
12e: 0f b6 19 movzbl (%ecx),%ebx
131: 84 c0 test %al,%al
133: 75 1e jne 153 <strcmp+0x33>
135: eb 29 jmp 160 <strcmp+0x40>
137: 89 f6 mov %esi,%esi
139: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
140: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
143: 0f b6 02 movzbl (%edx),%eax
p++, q++;
146: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
149: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
14d: 84 c0 test %al,%al
14f: 74 0f je 160 <strcmp+0x40>
151: 89 f1 mov %esi,%ecx
153: 38 d8 cmp %bl,%al
155: 74 e9 je 140 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
157: 29 d8 sub %ebx,%eax
}
159: 5b pop %ebx
15a: 5e pop %esi
15b: 5d pop %ebp
15c: c3 ret
15d: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
160: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
162: 29 d8 sub %ebx,%eax
}
164: 5b pop %ebx
165: 5e pop %esi
166: 5d pop %ebp
167: c3 ret
168: 90 nop
169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000170 <strlen>:
uint
strlen(char *s)
{
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
176: 80 39 00 cmpb $0x0,(%ecx)
179: 74 12 je 18d <strlen+0x1d>
17b: 31 d2 xor %edx,%edx
17d: 8d 76 00 lea 0x0(%esi),%esi
180: 83 c2 01 add $0x1,%edx
183: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
187: 89 d0 mov %edx,%eax
189: 75 f5 jne 180 <strlen+0x10>
;
return n;
}
18b: 5d pop %ebp
18c: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
18d: 31 c0 xor %eax,%eax
;
return n;
}
18f: 5d pop %ebp
190: c3 ret
191: eb 0d jmp 1a0 <memset>
193: 90 nop
194: 90 nop
195: 90 nop
196: 90 nop
197: 90 nop
198: 90 nop
199: 90 nop
19a: 90 nop
19b: 90 nop
19c: 90 nop
19d: 90 nop
19e: 90 nop
19f: 90 nop
000001a0 <memset>:
void*
memset(void *dst, int c, uint n)
{
1a0: 55 push %ebp
1a1: 89 e5 mov %esp,%ebp
1a3: 57 push %edi
1a4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1a7: 8b 4d 10 mov 0x10(%ebp),%ecx
1aa: 8b 45 0c mov 0xc(%ebp),%eax
1ad: 89 d7 mov %edx,%edi
1af: fc cld
1b0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1b2: 89 d0 mov %edx,%eax
1b4: 5f pop %edi
1b5: 5d pop %ebp
1b6: c3 ret
1b7: 89 f6 mov %esi,%esi
1b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001c0 <strchr>:
char*
strchr(const char *s, char c)
{
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 53 push %ebx
1c4: 8b 45 08 mov 0x8(%ebp),%eax
1c7: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
1ca: 0f b6 10 movzbl (%eax),%edx
1cd: 84 d2 test %dl,%dl
1cf: 74 1d je 1ee <strchr+0x2e>
if(*s == c)
1d1: 38 d3 cmp %dl,%bl
1d3: 89 d9 mov %ebx,%ecx
1d5: 75 0d jne 1e4 <strchr+0x24>
1d7: eb 17 jmp 1f0 <strchr+0x30>
1d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1e0: 38 ca cmp %cl,%dl
1e2: 74 0c je 1f0 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
1e4: 83 c0 01 add $0x1,%eax
1e7: 0f b6 10 movzbl (%eax),%edx
1ea: 84 d2 test %dl,%dl
1ec: 75 f2 jne 1e0 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
1ee: 31 c0 xor %eax,%eax
}
1f0: 5b pop %ebx
1f1: 5d pop %ebp
1f2: c3 ret
1f3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000200 <gets>:
char*
gets(char *buf, int max)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 57 push %edi
204: 56 push %esi
205: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
206: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
208: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
20b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
20e: eb 29 jmp 239 <gets+0x39>
cc = read(0, &c, 1);
210: 83 ec 04 sub $0x4,%esp
213: 6a 01 push $0x1
215: 57 push %edi
216: 6a 00 push $0x0
218: e8 2d 01 00 00 call 34a <read>
if(cc < 1)
21d: 83 c4 10 add $0x10,%esp
220: 85 c0 test %eax,%eax
222: 7e 1d jle 241 <gets+0x41>
break;
buf[i++] = c;
224: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
228: 8b 55 08 mov 0x8(%ebp),%edx
22b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
22d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
22f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
233: 74 1b je 250 <gets+0x50>
235: 3c 0d cmp $0xd,%al
237: 74 17 je 250 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
239: 8d 5e 01 lea 0x1(%esi),%ebx
23c: 3b 5d 0c cmp 0xc(%ebp),%ebx
23f: 7c cf jl 210 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
241: 8b 45 08 mov 0x8(%ebp),%eax
244: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
248: 8d 65 f4 lea -0xc(%ebp),%esp
24b: 5b pop %ebx
24c: 5e pop %esi
24d: 5f pop %edi
24e: 5d pop %ebp
24f: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
250: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
253: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
255: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
259: 8d 65 f4 lea -0xc(%ebp),%esp
25c: 5b pop %ebx
25d: 5e pop %esi
25e: 5f pop %edi
25f: 5d pop %ebp
260: c3 ret
261: eb 0d jmp 270 <stat>
263: 90 nop
264: 90 nop
265: 90 nop
266: 90 nop
267: 90 nop
268: 90 nop
269: 90 nop
26a: 90 nop
26b: 90 nop
26c: 90 nop
26d: 90 nop
26e: 90 nop
26f: 90 nop
00000270 <stat>:
int
stat(char *n, struct stat *st)
{
270: 55 push %ebp
271: 89 e5 mov %esp,%ebp
273: 56 push %esi
274: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
275: 83 ec 08 sub $0x8,%esp
278: 6a 00 push $0x0
27a: ff 75 08 pushl 0x8(%ebp)
27d: e8 f0 00 00 00 call 372 <open>
if(fd < 0)
282: 83 c4 10 add $0x10,%esp
285: 85 c0 test %eax,%eax
287: 78 27 js 2b0 <stat+0x40>
return -1;
r = fstat(fd, st);
289: 83 ec 08 sub $0x8,%esp
28c: ff 75 0c pushl 0xc(%ebp)
28f: 89 c3 mov %eax,%ebx
291: 50 push %eax
292: e8 f3 00 00 00 call 38a <fstat>
close(fd);
297: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
29a: 89 c6 mov %eax,%esi
close(fd);
29c: e8 b9 00 00 00 call 35a <close>
return r;
2a1: 83 c4 10 add $0x10,%esp
}
2a4: 8d 65 f8 lea -0x8(%ebp),%esp
2a7: 89 f0 mov %esi,%eax
2a9: 5b pop %ebx
2aa: 5e pop %esi
2ab: 5d pop %ebp
2ac: c3 ret
2ad: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
2b0: be ff ff ff ff mov $0xffffffff,%esi
2b5: eb ed jmp 2a4 <stat+0x34>
2b7: 89 f6 mov %esi,%esi
2b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002c0 <atoi>:
return r;
}
int
atoi(const char *s)
{
2c0: 55 push %ebp
2c1: 89 e5 mov %esp,%ebp
2c3: 53 push %ebx
2c4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2c7: 0f be 11 movsbl (%ecx),%edx
2ca: 8d 42 d0 lea -0x30(%edx),%eax
2cd: 3c 09 cmp $0x9,%al
2cf: b8 00 00 00 00 mov $0x0,%eax
2d4: 77 1f ja 2f5 <atoi+0x35>
2d6: 8d 76 00 lea 0x0(%esi),%esi
2d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
2e0: 8d 04 80 lea (%eax,%eax,4),%eax
2e3: 83 c1 01 add $0x1,%ecx
2e6: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
2ea: 0f be 11 movsbl (%ecx),%edx
2ed: 8d 5a d0 lea -0x30(%edx),%ebx
2f0: 80 fb 09 cmp $0x9,%bl
2f3: 76 eb jbe 2e0 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
2f5: 5b pop %ebx
2f6: 5d pop %ebp
2f7: c3 ret
2f8: 90 nop
2f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000300 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 56 push %esi
304: 53 push %ebx
305: 8b 5d 10 mov 0x10(%ebp),%ebx
308: 8b 45 08 mov 0x8(%ebp),%eax
30b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
30e: 85 db test %ebx,%ebx
310: 7e 14 jle 326 <memmove+0x26>
312: 31 d2 xor %edx,%edx
314: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
318: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
31c: 88 0c 10 mov %cl,(%eax,%edx,1)
31f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
322: 39 da cmp %ebx,%edx
324: 75 f2 jne 318 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
326: 5b pop %ebx
327: 5e pop %esi
328: 5d pop %ebp
329: c3 ret
0000032a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
32a: b8 01 00 00 00 mov $0x1,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <exit>:
SYSCALL(exit)
332: b8 02 00 00 00 mov $0x2,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <wait>:
SYSCALL(wait)
33a: b8 03 00 00 00 mov $0x3,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <pipe>:
SYSCALL(pipe)
342: b8 04 00 00 00 mov $0x4,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <read>:
SYSCALL(read)
34a: b8 05 00 00 00 mov $0x5,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <write>:
SYSCALL(write)
352: b8 10 00 00 00 mov $0x10,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <close>:
SYSCALL(close)
35a: b8 15 00 00 00 mov $0x15,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <kill>:
SYSCALL(kill)
362: b8 06 00 00 00 mov $0x6,%eax
367: cd 40 int $0x40
369: c3 ret
0000036a <exec>:
SYSCALL(exec)
36a: b8 07 00 00 00 mov $0x7,%eax
36f: cd 40 int $0x40
371: c3 ret
00000372 <open>:
SYSCALL(open)
372: b8 0f 00 00 00 mov $0xf,%eax
377: cd 40 int $0x40
379: c3 ret
0000037a <mknod>:
SYSCALL(mknod)
37a: b8 11 00 00 00 mov $0x11,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <unlink>:
SYSCALL(unlink)
382: b8 12 00 00 00 mov $0x12,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <fstat>:
SYSCALL(fstat)
38a: b8 08 00 00 00 mov $0x8,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <link>:
SYSCALL(link)
392: b8 13 00 00 00 mov $0x13,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <mkdir>:
SYSCALL(mkdir)
39a: b8 14 00 00 00 mov $0x14,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <chdir>:
SYSCALL(chdir)
3a2: b8 09 00 00 00 mov $0x9,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <dup>:
SYSCALL(dup)
3aa: b8 0a 00 00 00 mov $0xa,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <getpid>:
SYSCALL(getpid)
3b2: b8 0b 00 00 00 mov $0xb,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <getppid>:
SYSCALL(getppid)
3ba: b8 19 00 00 00 mov $0x19,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <getAllPids>:
SYSCALL(getAllPids)
3c2: b8 17 00 00 00 mov $0x17,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <shutdown>:
SYSCALL(shutdown)
3ca: b8 18 00 00 00 mov $0x18,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <sbrk>:
SYSCALL(sbrk)
3d2: b8 0c 00 00 00 mov $0xc,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <sleep>:
SYSCALL(sleep)
3da: b8 0d 00 00 00 mov $0xd,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <uptime>:
SYSCALL(uptime)
3e2: b8 0e 00 00 00 mov $0xe,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <cps>:
SYSCALL(cps)
3ea: b8 16 00 00 00 mov $0x16,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
3f2: 66 90 xchg %ax,%ax
3f4: 66 90 xchg %ax,%ax
3f6: 66 90 xchg %ax,%ax
3f8: 66 90 xchg %ax,%ax
3fa: 66 90 xchg %ax,%ax
3fc: 66 90 xchg %ax,%ax
3fe: 66 90 xchg %ax,%ax
00000400 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 57 push %edi
404: 56 push %esi
405: 53 push %ebx
406: 89 c6 mov %eax,%esi
408: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
40b: 8b 5d 08 mov 0x8(%ebp),%ebx
40e: 85 db test %ebx,%ebx
410: 74 7e je 490 <printint+0x90>
412: 89 d0 mov %edx,%eax
414: c1 e8 1f shr $0x1f,%eax
417: 84 c0 test %al,%al
419: 74 75 je 490 <printint+0x90>
neg = 1;
x = -xx;
41b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
41d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
424: f7 d8 neg %eax
426: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
429: 31 ff xor %edi,%edi
42b: 8d 5d d7 lea -0x29(%ebp),%ebx
42e: 89 ce mov %ecx,%esi
430: eb 08 jmp 43a <printint+0x3a>
432: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
438: 89 cf mov %ecx,%edi
43a: 31 d2 xor %edx,%edx
43c: 8d 4f 01 lea 0x1(%edi),%ecx
43f: f7 f6 div %esi
441: 0f b6 92 18 08 00 00 movzbl 0x818(%edx),%edx
}while((x /= base) != 0);
448: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
44a: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
44d: 75 e9 jne 438 <printint+0x38>
if(neg)
44f: 8b 45 c4 mov -0x3c(%ebp),%eax
452: 8b 75 c0 mov -0x40(%ebp),%esi
455: 85 c0 test %eax,%eax
457: 74 08 je 461 <printint+0x61>
buf[i++] = '-';
459: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
45e: 8d 4f 02 lea 0x2(%edi),%ecx
while(--i >= 0)
461: 8d 79 ff lea -0x1(%ecx),%edi
464: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
468: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
46d: 83 ec 04 sub $0x4,%esp
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
470: 83 ef 01 sub $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
473: 6a 01 push $0x1
475: 53 push %ebx
476: 56 push %esi
477: 88 45 d7 mov %al,-0x29(%ebp)
47a: e8 d3 fe ff ff call 352 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
47f: 83 c4 10 add $0x10,%esp
482: 83 ff ff cmp $0xffffffff,%edi
485: 75 e1 jne 468 <printint+0x68>
putc(fd, buf[i]);
}
487: 8d 65 f4 lea -0xc(%ebp),%esp
48a: 5b pop %ebx
48b: 5e pop %esi
48c: 5f pop %edi
48d: 5d pop %ebp
48e: c3 ret
48f: 90 nop
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
490: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
492: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
499: eb 8b jmp 426 <printint+0x26>
49b: 90 nop
49c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000004a0 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
4a0: 55 push %ebp
4a1: 89 e5 mov %esp,%ebp
4a3: 57 push %edi
4a4: 56 push %esi
4a5: 53 push %ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4a6: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
4a9: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4ac: 8b 75 0c mov 0xc(%ebp),%esi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
4af: 8b 7d 08 mov 0x8(%ebp),%edi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4b2: 89 45 d0 mov %eax,-0x30(%ebp)
4b5: 0f b6 1e movzbl (%esi),%ebx
4b8: 83 c6 01 add $0x1,%esi
4bb: 84 db test %bl,%bl
4bd: 0f 84 b0 00 00 00 je 573 <printf+0xd3>
4c3: 31 d2 xor %edx,%edx
4c5: eb 39 jmp 500 <printf+0x60>
4c7: 89 f6 mov %esi,%esi
4c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
4d0: 83 f8 25 cmp $0x25,%eax
4d3: 89 55 d4 mov %edx,-0x2c(%ebp)