-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstressfs.asm
3399 lines (3171 loc) · 117 KB
/
stressfs.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
_stressfs: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "fs.h"
#include "fcntl.h"
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
int fd, i;
char path[] = "stressfs0";
7: b8 30 00 00 00 mov $0x30,%eax
#include "fs.h"
#include "fcntl.h"
int
main(int argc, char *argv[])
{
c: ff 71 fc pushl -0x4(%ecx)
f: 55 push %ebp
10: 89 e5 mov %esp,%ebp
12: 57 push %edi
13: 56 push %esi
14: 53 push %ebx
15: 51 push %ecx
int fd, i;
char path[] = "stressfs0";
char data[512];
printf(1, "stressfs starting\n");
memset(data, 'a', sizeof(data));
16: 8d b5 e8 fd ff ff lea -0x218(%ebp),%esi
for(i = 0; i < 4; i++)
1c: 31 db xor %ebx,%ebx
#include "fs.h"
#include "fcntl.h"
int
main(int argc, char *argv[])
{
1e: 81 ec 20 02 00 00 sub $0x220,%esp
int fd, i;
char path[] = "stressfs0";
24: 66 89 85 e6 fd ff ff mov %ax,-0x21a(%ebp)
2b: c7 85 de fd ff ff 73 movl $0x65727473,-0x222(%ebp)
32: 74 72 65
char data[512];
printf(1, "stressfs starting\n");
35: 68 dc 12 00 00 push $0x12dc
3a: 6a 01 push $0x1
int
main(int argc, char *argv[])
{
int fd, i;
char path[] = "stressfs0";
3c: c7 85 e2 fd ff ff 73 movl $0x73667373,-0x21e(%ebp)
43: 73 66 73
char data[512];
printf(1, "stressfs starting\n");
46: e8 a5 04 00 00 call 4f0 <printf>
memset(data, 'a', sizeof(data));
4b: 83 c4 0c add $0xc,%esp
4e: 68 00 02 00 00 push $0x200
53: 6a 61 push $0x61
55: 56 push %esi
56: e8 95 01 00 00 call 1f0 <memset>
5b: 83 c4 10 add $0x10,%esp
for(i = 0; i < 4; i++)
if(fork() > 0)
5e: e8 17 03 00 00 call 37a <fork>
63: 85 c0 test %eax,%eax
65: 0f 8f bf 00 00 00 jg 12a <main+0x12a>
char data[512];
printf(1, "stressfs starting\n");
memset(data, 'a', sizeof(data));
for(i = 0; i < 4; i++)
6b: 83 c3 01 add $0x1,%ebx
6e: 83 fb 04 cmp $0x4,%ebx
71: 75 eb jne 5e <main+0x5e>
73: bf 04 00 00 00 mov $0x4,%edi
if(fork() > 0)
break;
printf(1, "write %d\n", i);
78: 83 ec 04 sub $0x4,%esp
7b: 53 push %ebx
7c: 68 ef 12 00 00 push $0x12ef
path[8] += i;
fd = open(path, O_CREATE | O_RDWR);
81: bb 14 00 00 00 mov $0x14,%ebx
for(i = 0; i < 4; i++)
if(fork() > 0)
break;
printf(1, "write %d\n", i);
86: 6a 01 push $0x1
88: e8 63 04 00 00 call 4f0 <printf>
path[8] += i;
8d: 89 f8 mov %edi,%eax
8f: 00 85 e6 fd ff ff add %al,-0x21a(%ebp)
fd = open(path, O_CREATE | O_RDWR);
95: 5f pop %edi
96: 58 pop %eax
97: 8d 85 de fd ff ff lea -0x222(%ebp),%eax
9d: 68 02 02 00 00 push $0x202
a2: 50 push %eax
a3: e8 1a 03 00 00 call 3c2 <open>
a8: 83 c4 10 add $0x10,%esp
ab: 89 c7 mov %eax,%edi
ad: 8d 76 00 lea 0x0(%esi),%esi
for(i = 0; i < 20; i++)
// printf(fd, "%d\n", i);
write(fd, data, sizeof(data));
b0: 83 ec 04 sub $0x4,%esp
b3: 68 00 02 00 00 push $0x200
b8: 56 push %esi
b9: 57 push %edi
ba: e8 e3 02 00 00 call 3a2 <write>
printf(1, "write %d\n", i);
path[8] += i;
fd = open(path, O_CREATE | O_RDWR);
for(i = 0; i < 20; i++)
bf: 83 c4 10 add $0x10,%esp
c2: 83 eb 01 sub $0x1,%ebx
c5: 75 e9 jne b0 <main+0xb0>
// printf(fd, "%d\n", i);
write(fd, data, sizeof(data));
close(fd);
c7: 83 ec 0c sub $0xc,%esp
ca: 57 push %edi
cb: e8 da 02 00 00 call 3aa <close>
printf(1, "read\n");
d0: 58 pop %eax
d1: 5a pop %edx
d2: 68 ba 14 00 00 push $0x14ba
d7: 6a 01 push $0x1
d9: e8 12 04 00 00 call 4f0 <printf>
fd = open(path, O_RDONLY);
de: 59 pop %ecx
df: 8d 85 de fd ff ff lea -0x222(%ebp),%eax
e5: 5b pop %ebx
e6: 6a 00 push $0x0
e8: 50 push %eax
e9: bb 14 00 00 00 mov $0x14,%ebx
ee: e8 cf 02 00 00 call 3c2 <open>
f3: 83 c4 10 add $0x10,%esp
f6: 89 c7 mov %eax,%edi
f8: 90 nop
f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for (i = 0; i < 20; i++)
read(fd, data, sizeof(data));
100: 83 ec 04 sub $0x4,%esp
103: 68 00 02 00 00 push $0x200
108: 56 push %esi
109: 57 push %edi
10a: e8 8b 02 00 00 call 39a <read>
close(fd);
printf(1, "read\n");
fd = open(path, O_RDONLY);
for (i = 0; i < 20; i++)
10f: 83 c4 10 add $0x10,%esp
112: 83 eb 01 sub $0x1,%ebx
115: 75 e9 jne 100 <main+0x100>
read(fd, data, sizeof(data));
close(fd);
117: 83 ec 0c sub $0xc,%esp
11a: 57 push %edi
11b: e8 8a 02 00 00 call 3aa <close>
wait();
120: e8 65 02 00 00 call 38a <wait>
exit();
125: e8 58 02 00 00 call 382 <exit>
12a: 89 df mov %ebx,%edi
12c: e9 47 ff ff ff jmp 78 <main+0x78>
131: 66 90 xchg %ax,%ax
133: 66 90 xchg %ax,%ax
135: 66 90 xchg %ax,%ax
137: 66 90 xchg %ax,%ax
139: 66 90 xchg %ax,%ax
13b: 66 90 xchg %ax,%ax
13d: 66 90 xchg %ax,%ax
13f: 90 nop
00000140 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 53 push %ebx
144: 8b 45 08 mov 0x8(%ebp),%eax
147: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
14a: 89 c2 mov %eax,%edx
14c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
150: 83 c1 01 add $0x1,%ecx
153: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
157: 83 c2 01 add $0x1,%edx
15a: 84 db test %bl,%bl
15c: 88 5a ff mov %bl,-0x1(%edx)
15f: 75 ef jne 150 <strcpy+0x10>
;
return os;
}
161: 5b pop %ebx
162: 5d pop %ebp
163: c3 ret
164: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
16a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000170 <strcmp>:
int
strcmp(const char *p, const char *q)
{
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 56 push %esi
174: 53 push %ebx
175: 8b 55 08 mov 0x8(%ebp),%edx
178: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
17b: 0f b6 02 movzbl (%edx),%eax
17e: 0f b6 19 movzbl (%ecx),%ebx
181: 84 c0 test %al,%al
183: 75 1e jne 1a3 <strcmp+0x33>
185: eb 29 jmp 1b0 <strcmp+0x40>
187: 89 f6 mov %esi,%esi
189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
190: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
193: 0f b6 02 movzbl (%edx),%eax
p++, q++;
196: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
199: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
19d: 84 c0 test %al,%al
19f: 74 0f je 1b0 <strcmp+0x40>
1a1: 89 f1 mov %esi,%ecx
1a3: 38 d8 cmp %bl,%al
1a5: 74 e9 je 190 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
1a7: 29 d8 sub %ebx,%eax
}
1a9: 5b pop %ebx
1aa: 5e pop %esi
1ab: 5d pop %ebp
1ac: c3 ret
1ad: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
1b0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
1b2: 29 d8 sub %ebx,%eax
}
1b4: 5b pop %ebx
1b5: 5e pop %esi
1b6: 5d pop %ebp
1b7: c3 ret
1b8: 90 nop
1b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000001c0 <strlen>:
uint
strlen(char *s)
{
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
1c6: 80 39 00 cmpb $0x0,(%ecx)
1c9: 74 12 je 1dd <strlen+0x1d>
1cb: 31 d2 xor %edx,%edx
1cd: 8d 76 00 lea 0x0(%esi),%esi
1d0: 83 c2 01 add $0x1,%edx
1d3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1d7: 89 d0 mov %edx,%eax
1d9: 75 f5 jne 1d0 <strlen+0x10>
;
return n;
}
1db: 5d pop %ebp
1dc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
1dd: 31 c0 xor %eax,%eax
;
return n;
}
1df: 5d pop %ebp
1e0: c3 ret
1e1: eb 0d jmp 1f0 <memset>
1e3: 90 nop
1e4: 90 nop
1e5: 90 nop
1e6: 90 nop
1e7: 90 nop
1e8: 90 nop
1e9: 90 nop
1ea: 90 nop
1eb: 90 nop
1ec: 90 nop
1ed: 90 nop
1ee: 90 nop
1ef: 90 nop
000001f0 <memset>:
void*
memset(void *dst, int c, uint n)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 57 push %edi
1f4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1f7: 8b 4d 10 mov 0x10(%ebp),%ecx
1fa: 8b 45 0c mov 0xc(%ebp),%eax
1fd: 89 d7 mov %edx,%edi
1ff: fc cld
200: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
202: 89 d0 mov %edx,%eax
204: 5f pop %edi
205: 5d pop %ebp
206: c3 ret
207: 89 f6 mov %esi,%esi
209: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000210 <strchr>:
char*
strchr(const char *s, char c)
{
210: 55 push %ebp
211: 89 e5 mov %esp,%ebp
213: 53 push %ebx
214: 8b 45 08 mov 0x8(%ebp),%eax
217: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
21a: 0f b6 10 movzbl (%eax),%edx
21d: 84 d2 test %dl,%dl
21f: 74 1d je 23e <strchr+0x2e>
if(*s == c)
221: 38 d3 cmp %dl,%bl
223: 89 d9 mov %ebx,%ecx
225: 75 0d jne 234 <strchr+0x24>
227: eb 17 jmp 240 <strchr+0x30>
229: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
230: 38 ca cmp %cl,%dl
232: 74 0c je 240 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
234: 83 c0 01 add $0x1,%eax
237: 0f b6 10 movzbl (%eax),%edx
23a: 84 d2 test %dl,%dl
23c: 75 f2 jne 230 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
23e: 31 c0 xor %eax,%eax
}
240: 5b pop %ebx
241: 5d pop %ebp
242: c3 ret
243: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000250 <gets>:
char*
gets(char *buf, int max)
{
250: 55 push %ebp
251: 89 e5 mov %esp,%ebp
253: 57 push %edi
254: 56 push %esi
255: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
256: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
258: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
25b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
25e: eb 29 jmp 289 <gets+0x39>
cc = read(0, &c, 1);
260: 83 ec 04 sub $0x4,%esp
263: 6a 01 push $0x1
265: 57 push %edi
266: 6a 00 push $0x0
268: e8 2d 01 00 00 call 39a <read>
if(cc < 1)
26d: 83 c4 10 add $0x10,%esp
270: 85 c0 test %eax,%eax
272: 7e 1d jle 291 <gets+0x41>
break;
buf[i++] = c;
274: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
278: 8b 55 08 mov 0x8(%ebp),%edx
27b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
27d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
27f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
283: 74 1b je 2a0 <gets+0x50>
285: 3c 0d cmp $0xd,%al
287: 74 17 je 2a0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
289: 8d 5e 01 lea 0x1(%esi),%ebx
28c: 3b 5d 0c cmp 0xc(%ebp),%ebx
28f: 7c cf jl 260 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
291: 8b 45 08 mov 0x8(%ebp),%eax
294: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
298: 8d 65 f4 lea -0xc(%ebp),%esp
29b: 5b pop %ebx
29c: 5e pop %esi
29d: 5f pop %edi
29e: 5d pop %ebp
29f: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
2a0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
2a3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
2a5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
2a9: 8d 65 f4 lea -0xc(%ebp),%esp
2ac: 5b pop %ebx
2ad: 5e pop %esi
2ae: 5f pop %edi
2af: 5d pop %ebp
2b0: c3 ret
2b1: eb 0d jmp 2c0 <stat>
2b3: 90 nop
2b4: 90 nop
2b5: 90 nop
2b6: 90 nop
2b7: 90 nop
2b8: 90 nop
2b9: 90 nop
2ba: 90 nop
2bb: 90 nop
2bc: 90 nop
2bd: 90 nop
2be: 90 nop
2bf: 90 nop
000002c0 <stat>:
int
stat(char *n, struct stat *st)
{
2c0: 55 push %ebp
2c1: 89 e5 mov %esp,%ebp
2c3: 56 push %esi
2c4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
2c5: 83 ec 08 sub $0x8,%esp
2c8: 6a 00 push $0x0
2ca: ff 75 08 pushl 0x8(%ebp)
2cd: e8 f0 00 00 00 call 3c2 <open>
if(fd < 0)
2d2: 83 c4 10 add $0x10,%esp
2d5: 85 c0 test %eax,%eax
2d7: 78 27 js 300 <stat+0x40>
return -1;
r = fstat(fd, st);
2d9: 83 ec 08 sub $0x8,%esp
2dc: ff 75 0c pushl 0xc(%ebp)
2df: 89 c3 mov %eax,%ebx
2e1: 50 push %eax
2e2: e8 f3 00 00 00 call 3da <fstat>
2e7: 89 c6 mov %eax,%esi
close(fd);
2e9: 89 1c 24 mov %ebx,(%esp)
2ec: e8 b9 00 00 00 call 3aa <close>
return r;
2f1: 83 c4 10 add $0x10,%esp
2f4: 89 f0 mov %esi,%eax
}
2f6: 8d 65 f8 lea -0x8(%ebp),%esp
2f9: 5b pop %ebx
2fa: 5e pop %esi
2fb: 5d pop %ebp
2fc: c3 ret
2fd: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
300: b8 ff ff ff ff mov $0xffffffff,%eax
305: eb ef jmp 2f6 <stat+0x36>
307: 89 f6 mov %esi,%esi
309: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000310 <atoi>:
return r;
}
int
atoi(const char *s)
{
310: 55 push %ebp
311: 89 e5 mov %esp,%ebp
313: 53 push %ebx
314: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
317: 0f be 11 movsbl (%ecx),%edx
31a: 8d 42 d0 lea -0x30(%edx),%eax
31d: 3c 09 cmp $0x9,%al
31f: b8 00 00 00 00 mov $0x0,%eax
324: 77 1f ja 345 <atoi+0x35>
326: 8d 76 00 lea 0x0(%esi),%esi
329: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
330: 8d 04 80 lea (%eax,%eax,4),%eax
333: 83 c1 01 add $0x1,%ecx
336: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
33a: 0f be 11 movsbl (%ecx),%edx
33d: 8d 5a d0 lea -0x30(%edx),%ebx
340: 80 fb 09 cmp $0x9,%bl
343: 76 eb jbe 330 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
345: 5b pop %ebx
346: 5d pop %ebp
347: c3 ret
348: 90 nop
349: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000350 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
350: 55 push %ebp
351: 89 e5 mov %esp,%ebp
353: 56 push %esi
354: 53 push %ebx
355: 8b 5d 10 mov 0x10(%ebp),%ebx
358: 8b 45 08 mov 0x8(%ebp),%eax
35b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
35e: 85 db test %ebx,%ebx
360: 7e 14 jle 376 <memmove+0x26>
362: 31 d2 xor %edx,%edx
364: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
368: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
36c: 88 0c 10 mov %cl,(%eax,%edx,1)
36f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
372: 39 da cmp %ebx,%edx
374: 75 f2 jne 368 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
376: 5b pop %ebx
377: 5e pop %esi
378: 5d pop %ebp
379: c3 ret
0000037a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
37a: b8 01 00 00 00 mov $0x1,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <exit>:
SYSCALL(exit)
382: b8 02 00 00 00 mov $0x2,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <wait>:
SYSCALL(wait)
38a: b8 03 00 00 00 mov $0x3,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <pipe>:
SYSCALL(pipe)
392: b8 04 00 00 00 mov $0x4,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <read>:
SYSCALL(read)
39a: b8 05 00 00 00 mov $0x5,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <write>:
SYSCALL(write)
3a2: b8 10 00 00 00 mov $0x10,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <close>:
SYSCALL(close)
3aa: b8 15 00 00 00 mov $0x15,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <kill>:
SYSCALL(kill)
3b2: b8 06 00 00 00 mov $0x6,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <exec>:
SYSCALL(exec)
3ba: b8 07 00 00 00 mov $0x7,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <open>:
SYSCALL(open)
3c2: b8 0f 00 00 00 mov $0xf,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <mknod>:
SYSCALL(mknod)
3ca: b8 11 00 00 00 mov $0x11,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <unlink>:
SYSCALL(unlink)
3d2: b8 12 00 00 00 mov $0x12,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <fstat>:
SYSCALL(fstat)
3da: b8 08 00 00 00 mov $0x8,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <link>:
SYSCALL(link)
3e2: b8 13 00 00 00 mov $0x13,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <mkdir>:
SYSCALL(mkdir)
3ea: b8 14 00 00 00 mov $0x14,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <chdir>:
SYSCALL(chdir)
3f2: b8 09 00 00 00 mov $0x9,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <dup>:
SYSCALL(dup)
3fa: b8 0a 00 00 00 mov $0xa,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <getpid>:
SYSCALL(getpid)
402: b8 0b 00 00 00 mov $0xb,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <sbrk>:
SYSCALL(sbrk)
40a: b8 0c 00 00 00 mov $0xc,%eax
40f: cd 40 int $0x40
411: c3 ret
00000412 <sleep>:
SYSCALL(sleep)
412: b8 0d 00 00 00 mov $0xd,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <uptime>:
SYSCALL(uptime)
41a: b8 0e 00 00 00 mov $0xe,%eax
41f: cd 40 int $0x40
421: c3 ret
00000422 <signal>:
/* assignment 2 adding code */
SYSCALL(signal)
422: b8 16 00 00 00 mov $0x16,%eax
427: cd 40 int $0x40
429: c3 ret
0000042a <sigsend>:
SYSCALL(sigsend)
42a: b8 17 00 00 00 mov $0x17,%eax
42f: cd 40 int $0x40
431: c3 ret
00000432 <sigreturn>:
SYSCALL(sigreturn)
432: b8 18 00 00 00 mov $0x18,%eax
437: cd 40 int $0x40
439: c3 ret
0000043a <alarm>:
SYSCALL(alarm)
43a: b8 19 00 00 00 mov $0x19,%eax
43f: cd 40 int $0x40
441: c3 ret
442: 66 90 xchg %ax,%ax
444: 66 90 xchg %ax,%ax
446: 66 90 xchg %ax,%ax
448: 66 90 xchg %ax,%ax
44a: 66 90 xchg %ax,%ax
44c: 66 90 xchg %ax,%ax
44e: 66 90 xchg %ax,%ax
00000450 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 57 push %edi
454: 56 push %esi
455: 53 push %ebx
456: 89 c6 mov %eax,%esi
458: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
45b: 8b 5d 08 mov 0x8(%ebp),%ebx
45e: 85 db test %ebx,%ebx
460: 74 7e je 4e0 <printint+0x90>
462: 89 d0 mov %edx,%eax
464: c1 e8 1f shr $0x1f,%eax
467: 84 c0 test %al,%al
469: 74 75 je 4e0 <printint+0x90>
neg = 1;
x = -xx;
46b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
46d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
474: f7 d8 neg %eax
476: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
479: 31 ff xor %edi,%edi
47b: 8d 5d d7 lea -0x29(%ebp),%ebx
47e: 89 ce mov %ecx,%esi
480: eb 08 jmp 48a <printint+0x3a>
482: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
488: 89 cf mov %ecx,%edi
48a: 31 d2 xor %edx,%edx
48c: 8d 4f 01 lea 0x1(%edi),%ecx
48f: f7 f6 div %esi
491: 0f b6 92 00 13 00 00 movzbl 0x1300(%edx),%edx
}while((x /= base) != 0);
498: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
49a: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
49d: 75 e9 jne 488 <printint+0x38>
if(neg)
49f: 8b 45 c4 mov -0x3c(%ebp),%eax
4a2: 8b 75 c0 mov -0x40(%ebp),%esi
4a5: 85 c0 test %eax,%eax
4a7: 74 08 je 4b1 <printint+0x61>
buf[i++] = '-';
4a9: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
4ae: 8d 4f 02 lea 0x2(%edi),%ecx
4b1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi
4b5: 8d 76 00 lea 0x0(%esi),%esi
4b8: 0f b6 07 movzbl (%edi),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4bb: 83 ec 04 sub $0x4,%esp
4be: 83 ef 01 sub $0x1,%edi
4c1: 6a 01 push $0x1
4c3: 53 push %ebx
4c4: 56 push %esi
4c5: 88 45 d7 mov %al,-0x29(%ebp)
4c8: e8 d5 fe ff ff call 3a2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
4cd: 83 c4 10 add $0x10,%esp
4d0: 39 df cmp %ebx,%edi
4d2: 75 e4 jne 4b8 <printint+0x68>
putc(fd, buf[i]);
}
4d4: 8d 65 f4 lea -0xc(%ebp),%esp
4d7: 5b pop %ebx
4d8: 5e pop %esi
4d9: 5f pop %edi
4da: 5d pop %ebp
4db: c3 ret
4dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
4e0: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
4e2: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
4e9: eb 8b jmp 476 <printint+0x26>
4eb: 90 nop
4ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000004f0 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
4f0: 55 push %ebp
4f1: 89 e5 mov %esp,%ebp
4f3: 57 push %edi
4f4: 56 push %esi