-
Notifications
You must be signed in to change notification settings - Fork 1
/
ls.asm
1077 lines (1001 loc) · 35.3 KB
/
ls.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
_ls: file format elf32-i386
Disassembly of section .text:
00000000 <fmtname>:
#include "user.h"
#include "fs.h"
char*
fmtname(char *path)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 56 push %esi
4: 53 push %ebx
5: 8b 5d 08 mov 0x8(%ebp),%ebx
static char buf[DIRSIZ+1];
char *p;
// Find first character after last slash.
for(p=path+strlen(path); p >= path && *p != '/'; p--)
8: 83 ec 0c sub $0xc,%esp
b: 53 push %ebx
c: e8 1f 03 00 00 call 330 <strlen>
11: 01 d8 add %ebx,%eax
13: 83 c4 10 add $0x10,%esp
16: eb 03 jmp 1b <fmtname+0x1b>
18: 83 e8 01 sub $0x1,%eax
1b: 39 d8 cmp %ebx,%eax
1d: 72 05 jb 24 <fmtname+0x24>
1f: 80 38 2f cmpb $0x2f,(%eax)
22: 75 f4 jne 18 <fmtname+0x18>
;
p++;
24: 8d 58 01 lea 0x1(%eax),%ebx
// Return blank-padded name.
if(strlen(p) >= DIRSIZ)
27: 83 ec 0c sub $0xc,%esp
2a: 53 push %ebx
2b: e8 00 03 00 00 call 330 <strlen>
30: 83 c4 10 add $0x10,%esp
33: 83 f8 0d cmp $0xd,%eax
36: 76 09 jbe 41 <fmtname+0x41>
return p;
memmove(buf, p, strlen(p));
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
return buf;
}
38: 89 d8 mov %ebx,%eax
3a: 8d 65 f8 lea -0x8(%ebp),%esp
3d: 5b pop %ebx
3e: 5e pop %esi
3f: 5d pop %ebp
40: c3 ret
memmove(buf, p, strlen(p));
41: 83 ec 0c sub $0xc,%esp
44: 53 push %ebx
45: e8 e6 02 00 00 call 330 <strlen>
4a: 83 c4 0c add $0xc,%esp
4d: 50 push %eax
4e: 53 push %ebx
4f: 68 10 08 00 00 push $0x810
54: e8 f6 03 00 00 call 44f <memmove>
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
59: 89 1c 24 mov %ebx,(%esp)
5c: e8 cf 02 00 00 call 330 <strlen>
61: 89 c6 mov %eax,%esi
63: 89 1c 24 mov %ebx,(%esp)
66: e8 c5 02 00 00 call 330 <strlen>
6b: 83 c4 0c add $0xc,%esp
6e: ba 0e 00 00 00 mov $0xe,%edx
73: 29 f2 sub %esi,%edx
75: 52 push %edx
76: 6a 20 push $0x20
78: 05 10 08 00 00 add $0x810,%eax
7d: 50 push %eax
7e: e8 c5 02 00 00 call 348 <memset>
return buf;
83: 83 c4 10 add $0x10,%esp
86: bb 10 08 00 00 mov $0x810,%ebx
8b: eb ab jmp 38 <fmtname+0x38>
0000008d <ls>:
void
ls(char *path)
{
8d: 55 push %ebp
8e: 89 e5 mov %esp,%ebp
90: 57 push %edi
91: 56 push %esi
92: 53 push %ebx
93: 81 ec 54 02 00 00 sub $0x254,%esp
99: 8b 5d 08 mov 0x8(%ebp),%ebx
char buf[512], *p;
int fd;
struct dirent de;
struct stat st;
if((fd = open(path, 0)) < 0){
9c: 6a 00 push $0x0
9e: 53 push %ebx
9f: e8 1f 04 00 00 call 4c3 <open>
a4: 83 c4 10 add $0x10,%esp
a7: 85 c0 test %eax,%eax
a9: 0f 88 8c 00 00 00 js 13b <ls+0xae>
af: 89 c7 mov %eax,%edi
printf(2, "ls: cannot open %s\n", path);
return;
}
if(fstat(fd, &st) < 0){
b1: 83 ec 08 sub $0x8,%esp
b4: 8d 85 c4 fd ff ff lea -0x23c(%ebp),%eax
ba: 50 push %eax
bb: 57 push %edi
bc: e8 1a 04 00 00 call 4db <fstat>
c1: 83 c4 10 add $0x10,%esp
c4: 85 c0 test %eax,%eax
c6: 0f 88 84 00 00 00 js 150 <ls+0xc3>
printf(2, "ls: cannot stat %s\n", path);
close(fd);
return;
}
switch(st.type){
cc: 0f b7 85 c4 fd ff ff movzwl -0x23c(%ebp),%eax
d3: 0f bf f0 movswl %ax,%esi
d6: 66 83 f8 01 cmp $0x1,%ax
da: 0f 84 8d 00 00 00 je 16d <ls+0xe0>
e0: 66 83 f8 02 cmp $0x2,%ax
e4: 75 41 jne 127 <ls+0x9a>
case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
e6: 8b 85 d4 fd ff ff mov -0x22c(%ebp),%eax
ec: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp)
f2: 8b 95 cc fd ff ff mov -0x234(%ebp),%edx
f8: 89 95 b0 fd ff ff mov %edx,-0x250(%ebp)
fe: 83 ec 0c sub $0xc,%esp
101: 53 push %ebx
102: e8 f9 fe ff ff call 0 <fmtname>
107: 83 c4 08 add $0x8,%esp
10a: ff b5 b4 fd ff ff push -0x24c(%ebp)
110: ff b5 b0 fd ff ff push -0x250(%ebp)
116: 56 push %esi
117: 50 push %eax
118: 68 78 07 00 00 push $0x778
11d: 6a 01 push $0x1
11f: e8 c4 04 00 00 call 5e8 <printf>
break;
124: 83 c4 20 add $0x20,%esp
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
}
break;
}
close(fd);
127: 83 ec 0c sub $0xc,%esp
12a: 57 push %edi
12b: e8 7b 03 00 00 call 4ab <close>
130: 83 c4 10 add $0x10,%esp
}
133: 8d 65 f4 lea -0xc(%ebp),%esp
136: 5b pop %ebx
137: 5e pop %esi
138: 5f pop %edi
139: 5d pop %ebp
13a: c3 ret
printf(2, "ls: cannot open %s\n", path);
13b: 83 ec 04 sub $0x4,%esp
13e: 53 push %ebx
13f: 68 50 07 00 00 push $0x750
144: 6a 02 push $0x2
146: e8 9d 04 00 00 call 5e8 <printf>
return;
14b: 83 c4 10 add $0x10,%esp
14e: eb e3 jmp 133 <ls+0xa6>
printf(2, "ls: cannot stat %s\n", path);
150: 83 ec 04 sub $0x4,%esp
153: 53 push %ebx
154: 68 64 07 00 00 push $0x764
159: 6a 02 push $0x2
15b: e8 88 04 00 00 call 5e8 <printf>
close(fd);
160: 89 3c 24 mov %edi,(%esp)
163: e8 43 03 00 00 call 4ab <close>
return;
168: 83 c4 10 add $0x10,%esp
16b: eb c6 jmp 133 <ls+0xa6>
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
16d: 83 ec 0c sub $0xc,%esp
170: 53 push %ebx
171: e8 ba 01 00 00 call 330 <strlen>
176: 83 c0 10 add $0x10,%eax
179: 83 c4 10 add $0x10,%esp
17c: 3d 00 02 00 00 cmp $0x200,%eax
181: 76 14 jbe 197 <ls+0x10a>
printf(1, "ls: path too long\n");
183: 83 ec 08 sub $0x8,%esp
186: 68 85 07 00 00 push $0x785
18b: 6a 01 push $0x1
18d: e8 56 04 00 00 call 5e8 <printf>
break;
192: 83 c4 10 add $0x10,%esp
195: eb 90 jmp 127 <ls+0x9a>
strcpy(buf, path);
197: 83 ec 08 sub $0x8,%esp
19a: 53 push %ebx
19b: 8d b5 e8 fd ff ff lea -0x218(%ebp),%esi
1a1: 56 push %esi
1a2: e8 3d 01 00 00 call 2e4 <strcpy>
p = buf+strlen(buf);
1a7: 89 34 24 mov %esi,(%esp)
1aa: e8 81 01 00 00 call 330 <strlen>
1af: 01 c6 add %eax,%esi
*p++ = '/';
1b1: 8d 46 01 lea 0x1(%esi),%eax
1b4: 89 85 ac fd ff ff mov %eax,-0x254(%ebp)
1ba: c6 06 2f movb $0x2f,(%esi)
while(read(fd, &de, sizeof(de)) == sizeof(de)){
1bd: 83 c4 10 add $0x10,%esp
1c0: eb 19 jmp 1db <ls+0x14e>
printf(1, "ls: cannot stat %s\n", buf);
1c2: 83 ec 04 sub $0x4,%esp
1c5: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
1cb: 50 push %eax
1cc: 68 64 07 00 00 push $0x764
1d1: 6a 01 push $0x1
1d3: e8 10 04 00 00 call 5e8 <printf>
continue;
1d8: 83 c4 10 add $0x10,%esp
while(read(fd, &de, sizeof(de)) == sizeof(de)){
1db: 83 ec 04 sub $0x4,%esp
1de: 6a 10 push $0x10
1e0: 8d 85 d8 fd ff ff lea -0x228(%ebp),%eax
1e6: 50 push %eax
1e7: 57 push %edi
1e8: e8 ae 02 00 00 call 49b <read>
1ed: 83 c4 10 add $0x10,%esp
1f0: 83 f8 10 cmp $0x10,%eax
1f3: 0f 85 2e ff ff ff jne 127 <ls+0x9a>
if(de.inum == 0)
1f9: 66 83 bd d8 fd ff ff cmpw $0x0,-0x228(%ebp)
200: 00
201: 74 d8 je 1db <ls+0x14e>
memmove(p, de.name, DIRSIZ);
203: 83 ec 04 sub $0x4,%esp
206: 6a 0e push $0xe
208: 8d 85 da fd ff ff lea -0x226(%ebp),%eax
20e: 50 push %eax
20f: ff b5 ac fd ff ff push -0x254(%ebp)
215: e8 35 02 00 00 call 44f <memmove>
p[DIRSIZ] = 0;
21a: c6 46 0f 00 movb $0x0,0xf(%esi)
if(stat(buf, &st) < 0){
21e: 83 c4 08 add $0x8,%esp
221: 8d 85 c4 fd ff ff lea -0x23c(%ebp),%eax
227: 50 push %eax
228: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
22e: 50 push %eax
22f: e8 a7 01 00 00 call 3db <stat>
234: 83 c4 10 add $0x10,%esp
237: 85 c0 test %eax,%eax
239: 78 87 js 1c2 <ls+0x135>
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
23b: 8b 9d d4 fd ff ff mov -0x22c(%ebp),%ebx
241: 8b 85 cc fd ff ff mov -0x234(%ebp),%eax
247: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp)
24d: 0f b7 8d c4 fd ff ff movzwl -0x23c(%ebp),%ecx
254: 66 89 8d b0 fd ff ff mov %cx,-0x250(%ebp)
25b: 83 ec 0c sub $0xc,%esp
25e: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
264: 50 push %eax
265: e8 96 fd ff ff call 0 <fmtname>
26a: 89 c2 mov %eax,%edx
26c: 83 c4 08 add $0x8,%esp
26f: 53 push %ebx
270: ff b5 b4 fd ff ff push -0x24c(%ebp)
276: 0f bf 85 b0 fd ff ff movswl -0x250(%ebp),%eax
27d: 50 push %eax
27e: 52 push %edx
27f: 68 78 07 00 00 push $0x778
284: 6a 01 push $0x1
286: e8 5d 03 00 00 call 5e8 <printf>
28b: 83 c4 20 add $0x20,%esp
28e: e9 48 ff ff ff jmp 1db <ls+0x14e>
00000293 <main>:
int
main(int argc, char *argv[])
{
293: 8d 4c 24 04 lea 0x4(%esp),%ecx
297: 83 e4 f0 and $0xfffffff0,%esp
29a: ff 71 fc push -0x4(%ecx)
29d: 55 push %ebp
29e: 89 e5 mov %esp,%ebp
2a0: 57 push %edi
2a1: 56 push %esi
2a2: 53 push %ebx
2a3: 51 push %ecx
2a4: 83 ec 08 sub $0x8,%esp
2a7: 8b 31 mov (%ecx),%esi
2a9: 8b 79 04 mov 0x4(%ecx),%edi
int i;
if(argc < 2){
2ac: 83 fe 01 cmp $0x1,%esi
2af: 7e 07 jle 2b8 <main+0x25>
ls(".");
exit();
}
for(i=1; i<argc; i++)
2b1: bb 01 00 00 00 mov $0x1,%ebx
2b6: eb 23 jmp 2db <main+0x48>
ls(".");
2b8: 83 ec 0c sub $0xc,%esp
2bb: 68 98 07 00 00 push $0x798
2c0: e8 c8 fd ff ff call 8d <ls>
exit();
2c5: e8 b9 01 00 00 call 483 <exit>
ls(argv[i]);
2ca: 83 ec 0c sub $0xc,%esp
2cd: ff 34 9f push (%edi,%ebx,4)
2d0: e8 b8 fd ff ff call 8d <ls>
for(i=1; i<argc; i++)
2d5: 83 c3 01 add $0x1,%ebx
2d8: 83 c4 10 add $0x10,%esp
2db: 39 f3 cmp %esi,%ebx
2dd: 7c eb jl 2ca <main+0x37>
exit();
2df: e8 9f 01 00 00 call 483 <exit>
000002e4 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
2e4: 55 push %ebp
2e5: 89 e5 mov %esp,%ebp
2e7: 56 push %esi
2e8: 53 push %ebx
2e9: 8b 75 08 mov 0x8(%ebp),%esi
2ec: 8b 55 0c mov 0xc(%ebp),%edx
char *os;
os = s;
while((*s++ = *t++) != 0)
2ef: 89 f0 mov %esi,%eax
2f1: 89 d1 mov %edx,%ecx
2f3: 83 c2 01 add $0x1,%edx
2f6: 89 c3 mov %eax,%ebx
2f8: 83 c0 01 add $0x1,%eax
2fb: 0f b6 09 movzbl (%ecx),%ecx
2fe: 88 0b mov %cl,(%ebx)
300: 84 c9 test %cl,%cl
302: 75 ed jne 2f1 <strcpy+0xd>
;
return os;
}
304: 89 f0 mov %esi,%eax
306: 5b pop %ebx
307: 5e pop %esi
308: 5d pop %ebp
309: c3 ret
0000030a <strcmp>:
int
strcmp(const char *p, const char *q)
{
30a: 55 push %ebp
30b: 89 e5 mov %esp,%ebp
30d: 8b 4d 08 mov 0x8(%ebp),%ecx
310: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
313: eb 06 jmp 31b <strcmp+0x11>
p++, q++;
315: 83 c1 01 add $0x1,%ecx
318: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
31b: 0f b6 01 movzbl (%ecx),%eax
31e: 84 c0 test %al,%al
320: 74 04 je 326 <strcmp+0x1c>
322: 3a 02 cmp (%edx),%al
324: 74 ef je 315 <strcmp+0xb>
return (uchar)*p - (uchar)*q;
326: 0f b6 c0 movzbl %al,%eax
329: 0f b6 12 movzbl (%edx),%edx
32c: 29 d0 sub %edx,%eax
}
32e: 5d pop %ebp
32f: c3 ret
00000330 <strlen>:
uint
strlen(const char *s)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
336: b8 00 00 00 00 mov $0x0,%eax
33b: eb 03 jmp 340 <strlen+0x10>
33d: 83 c0 01 add $0x1,%eax
340: 80 3c 01 00 cmpb $0x0,(%ecx,%eax,1)
344: 75 f7 jne 33d <strlen+0xd>
;
return n;
}
346: 5d pop %ebp
347: c3 ret
00000348 <memset>:
void*
memset(void *dst, int c, uint n)
{
348: 55 push %ebp
349: 89 e5 mov %esp,%ebp
34b: 57 push %edi
34c: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
34f: 89 d7 mov %edx,%edi
351: 8b 4d 10 mov 0x10(%ebp),%ecx
354: 8b 45 0c mov 0xc(%ebp),%eax
357: fc cld
358: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
35a: 89 d0 mov %edx,%eax
35c: 8b 7d fc mov -0x4(%ebp),%edi
35f: c9 leave
360: c3 ret
00000361 <strchr>:
char*
strchr(const char *s, char c)
{
361: 55 push %ebp
362: 89 e5 mov %esp,%ebp
364: 8b 45 08 mov 0x8(%ebp),%eax
367: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
36b: eb 03 jmp 370 <strchr+0xf>
36d: 83 c0 01 add $0x1,%eax
370: 0f b6 10 movzbl (%eax),%edx
373: 84 d2 test %dl,%dl
375: 74 06 je 37d <strchr+0x1c>
if(*s == c)
377: 38 ca cmp %cl,%dl
379: 75 f2 jne 36d <strchr+0xc>
37b: eb 05 jmp 382 <strchr+0x21>
return (char*)s;
return 0;
37d: b8 00 00 00 00 mov $0x0,%eax
}
382: 5d pop %ebp
383: c3 ret
00000384 <gets>:
char*
gets(char *buf, int max)
{
384: 55 push %ebp
385: 89 e5 mov %esp,%ebp
387: 57 push %edi
388: 56 push %esi
389: 53 push %ebx
38a: 83 ec 1c sub $0x1c,%esp
38d: 8b 7d 08 mov 0x8(%ebp),%edi
int i, cc;
char c;
for(i=0; i+1 < max; ){
390: bb 00 00 00 00 mov $0x0,%ebx
395: 89 de mov %ebx,%esi
397: 83 c3 01 add $0x1,%ebx
39a: 3b 5d 0c cmp 0xc(%ebp),%ebx
39d: 7d 2e jge 3cd <gets+0x49>
cc = read(0, &c, 1);
39f: 83 ec 04 sub $0x4,%esp
3a2: 6a 01 push $0x1
3a4: 8d 45 e7 lea -0x19(%ebp),%eax
3a7: 50 push %eax
3a8: 6a 00 push $0x0
3aa: e8 ec 00 00 00 call 49b <read>
if(cc < 1)
3af: 83 c4 10 add $0x10,%esp
3b2: 85 c0 test %eax,%eax
3b4: 7e 17 jle 3cd <gets+0x49>
break;
buf[i++] = c;
3b6: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
3ba: 88 04 37 mov %al,(%edi,%esi,1)
if(c == '\n' || c == '\r')
3bd: 3c 0a cmp $0xa,%al
3bf: 0f 94 c2 sete %dl
3c2: 3c 0d cmp $0xd,%al
3c4: 0f 94 c0 sete %al
3c7: 08 c2 or %al,%dl
3c9: 74 ca je 395 <gets+0x11>
buf[i++] = c;
3cb: 89 de mov %ebx,%esi
break;
}
buf[i] = '\0';
3cd: c6 04 37 00 movb $0x0,(%edi,%esi,1)
return buf;
}
3d1: 89 f8 mov %edi,%eax
3d3: 8d 65 f4 lea -0xc(%ebp),%esp
3d6: 5b pop %ebx
3d7: 5e pop %esi
3d8: 5f pop %edi
3d9: 5d pop %ebp
3da: c3 ret
000003db <stat>:
int
stat(const char *n, struct stat *st)
{
3db: 55 push %ebp
3dc: 89 e5 mov %esp,%ebp
3de: 56 push %esi
3df: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
3e0: 83 ec 08 sub $0x8,%esp
3e3: 6a 00 push $0x0
3e5: ff 75 08 push 0x8(%ebp)
3e8: e8 d6 00 00 00 call 4c3 <open>
if(fd < 0)
3ed: 83 c4 10 add $0x10,%esp
3f0: 85 c0 test %eax,%eax
3f2: 78 24 js 418 <stat+0x3d>
3f4: 89 c3 mov %eax,%ebx
return -1;
r = fstat(fd, st);
3f6: 83 ec 08 sub $0x8,%esp
3f9: ff 75 0c push 0xc(%ebp)
3fc: 50 push %eax
3fd: e8 d9 00 00 00 call 4db <fstat>
402: 89 c6 mov %eax,%esi
close(fd);
404: 89 1c 24 mov %ebx,(%esp)
407: e8 9f 00 00 00 call 4ab <close>
return r;
40c: 83 c4 10 add $0x10,%esp
}
40f: 89 f0 mov %esi,%eax
411: 8d 65 f8 lea -0x8(%ebp),%esp
414: 5b pop %ebx
415: 5e pop %esi
416: 5d pop %ebp
417: c3 ret
return -1;
418: be ff ff ff ff mov $0xffffffff,%esi
41d: eb f0 jmp 40f <stat+0x34>
0000041f <atoi>:
int
atoi(const char *s)
{
41f: 55 push %ebp
420: 89 e5 mov %esp,%ebp
422: 53 push %ebx
423: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
426: ba 00 00 00 00 mov $0x0,%edx
while('0' <= *s && *s <= '9')
42b: eb 10 jmp 43d <atoi+0x1e>
n = n*10 + *s++ - '0';
42d: 8d 1c 92 lea (%edx,%edx,4),%ebx
430: 8d 14 1b lea (%ebx,%ebx,1),%edx
433: 83 c1 01 add $0x1,%ecx
436: 0f be c0 movsbl %al,%eax
439: 8d 54 10 d0 lea -0x30(%eax,%edx,1),%edx
while('0' <= *s && *s <= '9')
43d: 0f b6 01 movzbl (%ecx),%eax
440: 8d 58 d0 lea -0x30(%eax),%ebx
443: 80 fb 09 cmp $0x9,%bl
446: 76 e5 jbe 42d <atoi+0xe>
return n;
}
448: 89 d0 mov %edx,%eax
44a: 8b 5d fc mov -0x4(%ebp),%ebx
44d: c9 leave
44e: c3 ret
0000044f <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
44f: 55 push %ebp
450: 89 e5 mov %esp,%ebp
452: 56 push %esi
453: 53 push %ebx
454: 8b 75 08 mov 0x8(%ebp),%esi
457: 8b 4d 0c mov 0xc(%ebp),%ecx
45a: 8b 45 10 mov 0x10(%ebp),%eax
char *dst;
const char *src;
dst = vdst;
45d: 89 f2 mov %esi,%edx
src = vsrc;
while(n-- > 0)
45f: eb 0d jmp 46e <memmove+0x1f>
*dst++ = *src++;
461: 0f b6 01 movzbl (%ecx),%eax
464: 88 02 mov %al,(%edx)
466: 8d 49 01 lea 0x1(%ecx),%ecx
469: 8d 52 01 lea 0x1(%edx),%edx
while(n-- > 0)
46c: 89 d8 mov %ebx,%eax
46e: 8d 58 ff lea -0x1(%eax),%ebx
471: 85 c0 test %eax,%eax
473: 7f ec jg 461 <memmove+0x12>
return vdst;
}
475: 89 f0 mov %esi,%eax
477: 5b pop %ebx
478: 5e pop %esi
479: 5d pop %ebp
47a: c3 ret
0000047b <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
47b: b8 01 00 00 00 mov $0x1,%eax
480: cd 40 int $0x40
482: c3 ret
00000483 <exit>:
SYSCALL(exit)
483: b8 02 00 00 00 mov $0x2,%eax
488: cd 40 int $0x40
48a: c3 ret
0000048b <wait>:
SYSCALL(wait)
48b: b8 03 00 00 00 mov $0x3,%eax
490: cd 40 int $0x40
492: c3 ret
00000493 <pipe>:
SYSCALL(pipe)
493: b8 04 00 00 00 mov $0x4,%eax
498: cd 40 int $0x40
49a: c3 ret
0000049b <read>:
SYSCALL(read)
49b: b8 05 00 00 00 mov $0x5,%eax
4a0: cd 40 int $0x40
4a2: c3 ret
000004a3 <write>:
SYSCALL(write)
4a3: b8 10 00 00 00 mov $0x10,%eax
4a8: cd 40 int $0x40
4aa: c3 ret
000004ab <close>:
SYSCALL(close)
4ab: b8 15 00 00 00 mov $0x15,%eax
4b0: cd 40 int $0x40
4b2: c3 ret
000004b3 <kill>:
SYSCALL(kill)
4b3: b8 06 00 00 00 mov $0x6,%eax
4b8: cd 40 int $0x40
4ba: c3 ret
000004bb <exec>:
SYSCALL(exec)
4bb: b8 07 00 00 00 mov $0x7,%eax
4c0: cd 40 int $0x40
4c2: c3 ret
000004c3 <open>:
SYSCALL(open)
4c3: b8 0f 00 00 00 mov $0xf,%eax
4c8: cd 40 int $0x40
4ca: c3 ret
000004cb <mknod>:
SYSCALL(mknod)
4cb: b8 11 00 00 00 mov $0x11,%eax
4d0: cd 40 int $0x40
4d2: c3 ret
000004d3 <unlink>:
SYSCALL(unlink)
4d3: b8 12 00 00 00 mov $0x12,%eax
4d8: cd 40 int $0x40
4da: c3 ret
000004db <fstat>:
SYSCALL(fstat)
4db: b8 08 00 00 00 mov $0x8,%eax
4e0: cd 40 int $0x40
4e2: c3 ret
000004e3 <link>:
SYSCALL(link)
4e3: b8 13 00 00 00 mov $0x13,%eax
4e8: cd 40 int $0x40
4ea: c3 ret
000004eb <mkdir>:
SYSCALL(mkdir)
4eb: b8 14 00 00 00 mov $0x14,%eax
4f0: cd 40 int $0x40
4f2: c3 ret
000004f3 <chdir>:
SYSCALL(chdir)
4f3: b8 09 00 00 00 mov $0x9,%eax
4f8: cd 40 int $0x40
4fa: c3 ret
000004fb <dup>:
SYSCALL(dup)
4fb: b8 0a 00 00 00 mov $0xa,%eax
500: cd 40 int $0x40
502: c3 ret
00000503 <getpid>:
SYSCALL(getpid)
503: b8 0b 00 00 00 mov $0xb,%eax
508: cd 40 int $0x40
50a: c3 ret
0000050b <sbrk>:
SYSCALL(sbrk)
50b: b8 0c 00 00 00 mov $0xc,%eax
510: cd 40 int $0x40
512: c3 ret
00000513 <sleep>:
SYSCALL(sleep)
513: b8 0d 00 00 00 mov $0xd,%eax
518: cd 40 int $0x40
51a: c3 ret
0000051b <uptime>:
SYSCALL(uptime)
51b: b8 0e 00 00 00 mov $0xe,%eax
520: cd 40 int $0x40
522: c3 ret
00000523 <yield>:
SYSCALL(yield)
523: b8 16 00 00 00 mov $0x16,%eax
528: cd 40 int $0x40
52a: c3 ret
0000052b <shutdown>:
SYSCALL(shutdown)
52b: b8 17 00 00 00 mov $0x17,%eax
530: cd 40 int $0x40
532: c3 ret
00000533 <schedlog>:
SYSCALL(schedlog)
533: b8 18 00 00 00 mov $0x18,%eax
538: cd 40 int $0x40
53a: c3 ret
0000053b <priofork>:
SYSCALL(priofork)
53b: b8 19 00 00 00 mov $0x19,%eax
540: cd 40 int $0x40
542: c3 ret
00000543 <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
543: 55 push %ebp
544: 89 e5 mov %esp,%ebp
546: 83 ec 1c sub $0x1c,%esp
549: 88 55 f4 mov %dl,-0xc(%ebp)
write(fd, &c, 1);
54c: 6a 01 push $0x1
54e: 8d 55 f4 lea -0xc(%ebp),%edx
551: 52 push %edx
552: 50 push %eax
553: e8 4b ff ff ff call 4a3 <write>
}
558: 83 c4 10 add $0x10,%esp
55b: c9 leave
55c: c3 ret
0000055d <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
55d: 55 push %ebp
55e: 89 e5 mov %esp,%ebp
560: 57 push %edi
561: 56 push %esi
562: 53 push %ebx
563: 83 ec 2c sub $0x2c,%esp
566: 89 45 d0 mov %eax,-0x30(%ebp)
569: 89 d0 mov %edx,%eax
56b: 89 ce mov %ecx,%esi
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
56d: 83 7d 08 00 cmpl $0x0,0x8(%ebp)
571: 0f 95 c1 setne %cl
574: c1 ea 1f shr $0x1f,%edx
577: 84 d1 test %dl,%cl
579: 74 44 je 5bf <printint+0x62>
neg = 1;
x = -xx;
57b: f7 d8 neg %eax
57d: 89 c1 mov %eax,%ecx
neg = 1;
57f: c7 45 d4 01 00 00 00 movl $0x1,-0x2c(%ebp)
} else {
x = xx;
}
i = 0;
586: bb 00 00 00 00 mov $0x0,%ebx
do{
buf[i++] = digits[x % base];
58b: 89 c8 mov %ecx,%eax
58d: ba 00 00 00 00 mov $0x0,%edx
592: f7 f6 div %esi
594: 89 df mov %ebx,%edi
596: 83 c3 01 add $0x1,%ebx
599: 0f b6 92 fc 07 00 00 movzbl 0x7fc(%edx),%edx
5a0: 88 54 3d d8 mov %dl,-0x28(%ebp,%edi,1)
}while((x /= base) != 0);
5a4: 89 ca mov %ecx,%edx
5a6: 89 c1 mov %eax,%ecx
5a8: 39 d6 cmp %edx,%esi
5aa: 76 df jbe 58b <printint+0x2e>
if(neg)
5ac: 83 7d d4 00 cmpl $0x0,-0x2c(%ebp)
5b0: 74 31 je 5e3 <printint+0x86>
buf[i++] = '-';
5b2: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
5b7: 8d 5f 02 lea 0x2(%edi),%ebx
5ba: 8b 75 d0 mov -0x30(%ebp),%esi
5bd: eb 17 jmp 5d6 <printint+0x79>
x = xx;
5bf: 89 c1 mov %eax,%ecx
neg = 0;
5c1: c7 45 d4 00 00 00 00 movl $0x0,-0x2c(%ebp)
5c8: eb bc jmp 586 <printint+0x29>
while(--i >= 0)
putc(fd, buf[i]);
5ca: 0f be 54 1d d8 movsbl -0x28(%ebp,%ebx,1),%edx
5cf: 89 f0 mov %esi,%eax
5d1: e8 6d ff ff ff call 543 <putc>
while(--i >= 0)
5d6: 83 eb 01 sub $0x1,%ebx
5d9: 79 ef jns 5ca <printint+0x6d>
}
5db: 83 c4 2c add $0x2c,%esp
5de: 5b pop %ebx
5df: 5e pop %esi
5e0: 5f pop %edi
5e1: 5d pop %ebp
5e2: c3 ret
5e3: 8b 75 d0 mov -0x30(%ebp),%esi
5e6: eb ee jmp 5d6 <printint+0x79>
000005e8 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
5e8: 55 push %ebp
5e9: 89 e5 mov %esp,%ebp
5eb: 57 push %edi
5ec: 56 push %esi
5ed: 53 push %ebx
5ee: 83 ec 1c sub $0x1c,%esp
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
5f1: 8d 45 10 lea 0x10(%ebp),%eax
5f4: 89 45 e4 mov %eax,-0x1c(%ebp)
state = 0;
5f7: be 00 00 00 00 mov $0x0,%esi
for(i = 0; fmt[i]; i++){
5fc: bb 00 00 00 00 mov $0x0,%ebx
601: eb 14 jmp 617 <printf+0x2f>
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
} else {
putc(fd, c);
603: 89 fa mov %edi,%edx
605: 8b 45 08 mov 0x8(%ebp),%eax
608: e8 36 ff ff ff call 543 <putc>
60d: eb 05 jmp 614 <printf+0x2c>
}
} else if(state == '%'){
60f: 83 fe 25 cmp $0x25,%esi
612: 74 25 je 639 <printf+0x51>
for(i = 0; fmt[i]; i++){
614: 83 c3 01 add $0x1,%ebx
617: 8b 45 0c mov 0xc(%ebp),%eax
61a: 0f b6 04 18 movzbl (%eax,%ebx,1),%eax
61e: 84 c0 test %al,%al
620: 0f 84 20 01 00 00 je 746 <printf+0x15e>
c = fmt[i] & 0xff;
626: 0f be f8 movsbl %al,%edi
629: 0f b6 c0 movzbl %al,%eax
if(state == 0){
62c: 85 f6 test %esi,%esi
62e: 75 df jne 60f <printf+0x27>
if(c == '%'){
630: 83 f8 25 cmp $0x25,%eax
633: 75 ce jne 603 <printf+0x1b>
state = '%';
635: 89 c6 mov %eax,%esi
637: eb db jmp 614 <printf+0x2c>
if(c == 'd'){
639: 83 f8 25 cmp $0x25,%eax
63c: 0f 84 cf 00 00 00 je 711 <printf+0x129>
642: 0f 8c dd 00 00 00 jl 725 <printf+0x13d>
648: 83 f8 78 cmp $0x78,%eax
64b: 0f 8f d4 00 00 00 jg 725 <printf+0x13d>
651: 83 f8 63 cmp $0x63,%eax
654: 0f 8c cb 00 00 00 jl 725 <printf+0x13d>
65a: 83 e8 63 sub $0x63,%eax
65d: 83 f8 15 cmp $0x15,%eax
660: 0f 87 bf 00 00 00 ja 725 <printf+0x13d>
666: ff 24 85 a4 07 00 00 jmp *0x7a4(,%eax,4)
printint(fd, *ap, 10, 1);
66d: 8b 7d e4 mov -0x1c(%ebp),%edi
670: 8b 17 mov (%edi),%edx
672: 83 ec 0c sub $0xc,%esp
675: 6a 01 push $0x1
677: b9 0a 00 00 00 mov $0xa,%ecx
67c: 8b 45 08 mov 0x8(%ebp),%eax
67f: e8 d9 fe ff ff call 55d <printint>
ap++;
684: 83 c7 04 add $0x4,%edi
687: 89 7d e4 mov %edi,-0x1c(%ebp)
68a: 83 c4 10 add $0x10,%esp
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
68d: be 00 00 00 00 mov $0x0,%esi
692: eb 80 jmp 614 <printf+0x2c>
printint(fd, *ap, 16, 0);