-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkill.asm
3271 lines (3062 loc) · 113 KB
/
kill.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
_kill: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char **argv)
{
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: 57 push %edi
e: 56 push %esi
f: 53 push %ebx
10: 51 push %ecx
11: bb 01 00 00 00 mov $0x1,%ebx
16: 83 ec 08 sub $0x8,%esp
19: 8b 31 mov (%ecx),%esi
1b: 8b 79 04 mov 0x4(%ecx),%edi
int i;
if(argc < 2){
1e: 83 fe 01 cmp $0x1,%esi
21: 7e 27 jle 4a <main+0x4a>
23: 90 nop
24: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));
28: 83 ec 0c sub $0xc,%esp
2b: ff 34 9f pushl (%edi,%ebx,4)
if(argc < 2){
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
2e: 83 c3 01 add $0x1,%ebx
kill(atoi(argv[i]));
31: e8 fa 01 00 00 call 230 <atoi>
36: 89 04 24 mov %eax,(%esp)
39: e8 94 02 00 00 call 2d2 <kill>
if(argc < 2){
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
3e: 83 c4 10 add $0x10,%esp
41: 39 de cmp %ebx,%esi
43: 75 e3 jne 28 <main+0x28>
kill(atoi(argv[i]));
exit();
45: e8 58 02 00 00 call 2a2 <exit>
main(int argc, char **argv)
{
int i;
if(argc < 2){
printf(2, "usage: kill pid...\n");
4a: 50 push %eax
4b: 50 push %eax
4c: 68 fc 11 00 00 push $0x11fc
51: 6a 02 push $0x2
53: e8 b8 03 00 00 call 410 <printf>
exit();
58: e8 45 02 00 00 call 2a2 <exit>
5d: 66 90 xchg %ax,%ax
5f: 90 nop
00000060 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 53 push %ebx
64: 8b 45 08 mov 0x8(%ebp),%eax
67: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
6a: 89 c2 mov %eax,%edx
6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
70: 83 c1 01 add $0x1,%ecx
73: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
77: 83 c2 01 add $0x1,%edx
7a: 84 db test %bl,%bl
7c: 88 5a ff mov %bl,-0x1(%edx)
7f: 75 ef jne 70 <strcpy+0x10>
;
return os;
}
81: 5b pop %ebx
82: 5d pop %ebp
83: c3 ret
84: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
8a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000090 <strcmp>:
int
strcmp(const char *p, const char *q)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 56 push %esi
94: 53 push %ebx
95: 8b 55 08 mov 0x8(%ebp),%edx
98: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
9b: 0f b6 02 movzbl (%edx),%eax
9e: 0f b6 19 movzbl (%ecx),%ebx
a1: 84 c0 test %al,%al
a3: 75 1e jne c3 <strcmp+0x33>
a5: eb 29 jmp d0 <strcmp+0x40>
a7: 89 f6 mov %esi,%esi
a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
b0: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
b3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
b6: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
b9: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
bd: 84 c0 test %al,%al
bf: 74 0f je d0 <strcmp+0x40>
c1: 89 f1 mov %esi,%ecx
c3: 38 d8 cmp %bl,%al
c5: 74 e9 je b0 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
c7: 29 d8 sub %ebx,%eax
}
c9: 5b pop %ebx
ca: 5e pop %esi
cb: 5d pop %ebp
cc: c3 ret
cd: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
d0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
d2: 29 d8 sub %ebx,%eax
}
d4: 5b pop %ebx
d5: 5e pop %esi
d6: 5d pop %ebp
d7: c3 ret
d8: 90 nop
d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000000e0 <strlen>:
uint
strlen(char *s)
{
e0: 55 push %ebp
e1: 89 e5 mov %esp,%ebp
e3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
e6: 80 39 00 cmpb $0x0,(%ecx)
e9: 74 12 je fd <strlen+0x1d>
eb: 31 d2 xor %edx,%edx
ed: 8d 76 00 lea 0x0(%esi),%esi
f0: 83 c2 01 add $0x1,%edx
f3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
f7: 89 d0 mov %edx,%eax
f9: 75 f5 jne f0 <strlen+0x10>
;
return n;
}
fb: 5d pop %ebp
fc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
fd: 31 c0 xor %eax,%eax
;
return n;
}
ff: 5d pop %ebp
100: c3 ret
101: eb 0d jmp 110 <memset>
103: 90 nop
104: 90 nop
105: 90 nop
106: 90 nop
107: 90 nop
108: 90 nop
109: 90 nop
10a: 90 nop
10b: 90 nop
10c: 90 nop
10d: 90 nop
10e: 90 nop
10f: 90 nop
00000110 <memset>:
void*
memset(void *dst, int c, uint n)
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 57 push %edi
114: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
117: 8b 4d 10 mov 0x10(%ebp),%ecx
11a: 8b 45 0c mov 0xc(%ebp),%eax
11d: 89 d7 mov %edx,%edi
11f: fc cld
120: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
122: 89 d0 mov %edx,%eax
124: 5f pop %edi
125: 5d pop %ebp
126: c3 ret
127: 89 f6 mov %esi,%esi
129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000130 <strchr>:
char*
strchr(const char *s, char c)
{
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 53 push %ebx
134: 8b 45 08 mov 0x8(%ebp),%eax
137: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
13a: 0f b6 10 movzbl (%eax),%edx
13d: 84 d2 test %dl,%dl
13f: 74 1d je 15e <strchr+0x2e>
if(*s == c)
141: 38 d3 cmp %dl,%bl
143: 89 d9 mov %ebx,%ecx
145: 75 0d jne 154 <strchr+0x24>
147: eb 17 jmp 160 <strchr+0x30>
149: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
150: 38 ca cmp %cl,%dl
152: 74 0c je 160 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
154: 83 c0 01 add $0x1,%eax
157: 0f b6 10 movzbl (%eax),%edx
15a: 84 d2 test %dl,%dl
15c: 75 f2 jne 150 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
15e: 31 c0 xor %eax,%eax
}
160: 5b pop %ebx
161: 5d pop %ebp
162: c3 ret
163: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000170 <gets>:
char*
gets(char *buf, int max)
{
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 57 push %edi
174: 56 push %esi
175: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
176: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
178: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
17b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
17e: eb 29 jmp 1a9 <gets+0x39>
cc = read(0, &c, 1);
180: 83 ec 04 sub $0x4,%esp
183: 6a 01 push $0x1
185: 57 push %edi
186: 6a 00 push $0x0
188: e8 2d 01 00 00 call 2ba <read>
if(cc < 1)
18d: 83 c4 10 add $0x10,%esp
190: 85 c0 test %eax,%eax
192: 7e 1d jle 1b1 <gets+0x41>
break;
buf[i++] = c;
194: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
198: 8b 55 08 mov 0x8(%ebp),%edx
19b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
19d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
19f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1a3: 74 1b je 1c0 <gets+0x50>
1a5: 3c 0d cmp $0xd,%al
1a7: 74 17 je 1c0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1a9: 8d 5e 01 lea 0x1(%esi),%ebx
1ac: 3b 5d 0c cmp 0xc(%ebp),%ebx
1af: 7c cf jl 180 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1b1: 8b 45 08 mov 0x8(%ebp),%eax
1b4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1b8: 8d 65 f4 lea -0xc(%ebp),%esp
1bb: 5b pop %ebx
1bc: 5e pop %esi
1bd: 5f pop %edi
1be: 5d pop %ebp
1bf: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1c0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1c3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1c5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1c9: 8d 65 f4 lea -0xc(%ebp),%esp
1cc: 5b pop %ebx
1cd: 5e pop %esi
1ce: 5f pop %edi
1cf: 5d pop %ebp
1d0: c3 ret
1d1: eb 0d jmp 1e0 <stat>
1d3: 90 nop
1d4: 90 nop
1d5: 90 nop
1d6: 90 nop
1d7: 90 nop
1d8: 90 nop
1d9: 90 nop
1da: 90 nop
1db: 90 nop
1dc: 90 nop
1dd: 90 nop
1de: 90 nop
1df: 90 nop
000001e0 <stat>:
int
stat(char *n, struct stat *st)
{
1e0: 55 push %ebp
1e1: 89 e5 mov %esp,%ebp
1e3: 56 push %esi
1e4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1e5: 83 ec 08 sub $0x8,%esp
1e8: 6a 00 push $0x0
1ea: ff 75 08 pushl 0x8(%ebp)
1ed: e8 f0 00 00 00 call 2e2 <open>
if(fd < 0)
1f2: 83 c4 10 add $0x10,%esp
1f5: 85 c0 test %eax,%eax
1f7: 78 27 js 220 <stat+0x40>
return -1;
r = fstat(fd, st);
1f9: 83 ec 08 sub $0x8,%esp
1fc: ff 75 0c pushl 0xc(%ebp)
1ff: 89 c3 mov %eax,%ebx
201: 50 push %eax
202: e8 f3 00 00 00 call 2fa <fstat>
207: 89 c6 mov %eax,%esi
close(fd);
209: 89 1c 24 mov %ebx,(%esp)
20c: e8 b9 00 00 00 call 2ca <close>
return r;
211: 83 c4 10 add $0x10,%esp
214: 89 f0 mov %esi,%eax
}
216: 8d 65 f8 lea -0x8(%ebp),%esp
219: 5b pop %ebx
21a: 5e pop %esi
21b: 5d pop %ebp
21c: c3 ret
21d: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
220: b8 ff ff ff ff mov $0xffffffff,%eax
225: eb ef jmp 216 <stat+0x36>
227: 89 f6 mov %esi,%esi
229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000230 <atoi>:
return r;
}
int
atoi(const char *s)
{
230: 55 push %ebp
231: 89 e5 mov %esp,%ebp
233: 53 push %ebx
234: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
237: 0f be 11 movsbl (%ecx),%edx
23a: 8d 42 d0 lea -0x30(%edx),%eax
23d: 3c 09 cmp $0x9,%al
23f: b8 00 00 00 00 mov $0x0,%eax
244: 77 1f ja 265 <atoi+0x35>
246: 8d 76 00 lea 0x0(%esi),%esi
249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
250: 8d 04 80 lea (%eax,%eax,4),%eax
253: 83 c1 01 add $0x1,%ecx
256: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
25a: 0f be 11 movsbl (%ecx),%edx
25d: 8d 5a d0 lea -0x30(%edx),%ebx
260: 80 fb 09 cmp $0x9,%bl
263: 76 eb jbe 250 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
265: 5b pop %ebx
266: 5d pop %ebp
267: c3 ret
268: 90 nop
269: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000270 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
270: 55 push %ebp
271: 89 e5 mov %esp,%ebp
273: 56 push %esi
274: 53 push %ebx
275: 8b 5d 10 mov 0x10(%ebp),%ebx
278: 8b 45 08 mov 0x8(%ebp),%eax
27b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
27e: 85 db test %ebx,%ebx
280: 7e 14 jle 296 <memmove+0x26>
282: 31 d2 xor %edx,%edx
284: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
288: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
28c: 88 0c 10 mov %cl,(%eax,%edx,1)
28f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
292: 39 da cmp %ebx,%edx
294: 75 f2 jne 288 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
296: 5b pop %ebx
297: 5e pop %esi
298: 5d pop %ebp
299: c3 ret
0000029a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
29a: b8 01 00 00 00 mov $0x1,%eax
29f: cd 40 int $0x40
2a1: c3 ret
000002a2 <exit>:
SYSCALL(exit)
2a2: b8 02 00 00 00 mov $0x2,%eax
2a7: cd 40 int $0x40
2a9: c3 ret
000002aa <wait>:
SYSCALL(wait)
2aa: b8 03 00 00 00 mov $0x3,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <pipe>:
SYSCALL(pipe)
2b2: b8 04 00 00 00 mov $0x4,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <read>:
SYSCALL(read)
2ba: b8 05 00 00 00 mov $0x5,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <write>:
SYSCALL(write)
2c2: b8 10 00 00 00 mov $0x10,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <close>:
SYSCALL(close)
2ca: b8 15 00 00 00 mov $0x15,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <kill>:
SYSCALL(kill)
2d2: b8 06 00 00 00 mov $0x6,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <exec>:
SYSCALL(exec)
2da: b8 07 00 00 00 mov $0x7,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <open>:
SYSCALL(open)
2e2: b8 0f 00 00 00 mov $0xf,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <mknod>:
SYSCALL(mknod)
2ea: b8 11 00 00 00 mov $0x11,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <unlink>:
SYSCALL(unlink)
2f2: b8 12 00 00 00 mov $0x12,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <fstat>:
SYSCALL(fstat)
2fa: b8 08 00 00 00 mov $0x8,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <link>:
SYSCALL(link)
302: b8 13 00 00 00 mov $0x13,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <mkdir>:
SYSCALL(mkdir)
30a: b8 14 00 00 00 mov $0x14,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <chdir>:
SYSCALL(chdir)
312: b8 09 00 00 00 mov $0x9,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <dup>:
SYSCALL(dup)
31a: b8 0a 00 00 00 mov $0xa,%eax
31f: cd 40 int $0x40
321: c3 ret
00000322 <getpid>:
SYSCALL(getpid)
322: b8 0b 00 00 00 mov $0xb,%eax
327: cd 40 int $0x40
329: c3 ret
0000032a <sbrk>:
SYSCALL(sbrk)
32a: b8 0c 00 00 00 mov $0xc,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <sleep>:
SYSCALL(sleep)
332: b8 0d 00 00 00 mov $0xd,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <uptime>:
SYSCALL(uptime)
33a: b8 0e 00 00 00 mov $0xe,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <signal>:
/* assignment 2 adding code */
SYSCALL(signal)
342: b8 16 00 00 00 mov $0x16,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <sigsend>:
SYSCALL(sigsend)
34a: b8 17 00 00 00 mov $0x17,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <sigreturn>:
SYSCALL(sigreturn)
352: b8 18 00 00 00 mov $0x18,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <alarm>:
SYSCALL(alarm)
35a: b8 19 00 00 00 mov $0x19,%eax
35f: cd 40 int $0x40
361: c3 ret
362: 66 90 xchg %ax,%ax
364: 66 90 xchg %ax,%ax
366: 66 90 xchg %ax,%ax
368: 66 90 xchg %ax,%ax
36a: 66 90 xchg %ax,%ax
36c: 66 90 xchg %ax,%ax
36e: 66 90 xchg %ax,%ax
00000370 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 57 push %edi
374: 56 push %esi
375: 53 push %ebx
376: 89 c6 mov %eax,%esi
378: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
37b: 8b 5d 08 mov 0x8(%ebp),%ebx
37e: 85 db test %ebx,%ebx
380: 74 7e je 400 <printint+0x90>
382: 89 d0 mov %edx,%eax
384: c1 e8 1f shr $0x1f,%eax
387: 84 c0 test %al,%al
389: 74 75 je 400 <printint+0x90>
neg = 1;
x = -xx;
38b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
38d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
394: f7 d8 neg %eax
396: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
399: 31 ff xor %edi,%edi
39b: 8d 5d d7 lea -0x29(%ebp),%ebx
39e: 89 ce mov %ecx,%esi
3a0: eb 08 jmp 3aa <printint+0x3a>
3a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3a8: 89 cf mov %ecx,%edi
3aa: 31 d2 xor %edx,%edx
3ac: 8d 4f 01 lea 0x1(%edi),%ecx
3af: f7 f6 div %esi
3b1: 0f b6 92 18 12 00 00 movzbl 0x1218(%edx),%edx
}while((x /= base) != 0);
3b8: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
3ba: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
3bd: 75 e9 jne 3a8 <printint+0x38>
if(neg)
3bf: 8b 45 c4 mov -0x3c(%ebp),%eax
3c2: 8b 75 c0 mov -0x40(%ebp),%esi
3c5: 85 c0 test %eax,%eax
3c7: 74 08 je 3d1 <printint+0x61>
buf[i++] = '-';
3c9: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
3ce: 8d 4f 02 lea 0x2(%edi),%ecx
3d1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi
3d5: 8d 76 00 lea 0x0(%esi),%esi
3d8: 0f b6 07 movzbl (%edi),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
3db: 83 ec 04 sub $0x4,%esp
3de: 83 ef 01 sub $0x1,%edi
3e1: 6a 01 push $0x1
3e3: 53 push %ebx
3e4: 56 push %esi
3e5: 88 45 d7 mov %al,-0x29(%ebp)
3e8: e8 d5 fe ff ff call 2c2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
3ed: 83 c4 10 add $0x10,%esp
3f0: 39 df cmp %ebx,%edi
3f2: 75 e4 jne 3d8 <printint+0x68>
putc(fd, buf[i]);
}
3f4: 8d 65 f4 lea -0xc(%ebp),%esp
3f7: 5b pop %ebx
3f8: 5e pop %esi
3f9: 5f pop %edi
3fa: 5d pop %ebp
3fb: c3 ret
3fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
400: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
402: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
409: eb 8b jmp 396 <printint+0x26>
40b: 90 nop
40c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000410 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
410: 55 push %ebp
411: 89 e5 mov %esp,%ebp
413: 57 push %edi
414: 56 push %esi
415: 53 push %ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
416: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
419: 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++){
41c: 8b 75 0c mov 0xc(%ebp),%esi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
41f: 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++){
422: 89 45 d0 mov %eax,-0x30(%ebp)
425: 0f b6 1e movzbl (%esi),%ebx
428: 83 c6 01 add $0x1,%esi
42b: 84 db test %bl,%bl
42d: 0f 84 b0 00 00 00 je 4e3 <printf+0xd3>
433: 31 d2 xor %edx,%edx
435: eb 39 jmp 470 <printf+0x60>
437: 89 f6 mov %esi,%esi
439: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
440: 83 f8 25 cmp $0x25,%eax
443: 89 55 d4 mov %edx,-0x2c(%ebp)
state = '%';
446: ba 25 00 00 00 mov $0x25,%edx
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
44b: 74 18 je 465 <printf+0x55>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
44d: 8d 45 e2 lea -0x1e(%ebp),%eax
450: 83 ec 04 sub $0x4,%esp
453: 88 5d e2 mov %bl,-0x1e(%ebp)
456: 6a 01 push $0x1
458: 50 push %eax
459: 57 push %edi
45a: e8 63 fe ff ff call 2c2 <write>
45f: 8b 55 d4 mov -0x2c(%ebp),%edx
462: 83 c4 10 add $0x10,%esp
465: 83 c6 01 add $0x1,%esi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
468: 0f b6 5e ff movzbl -0x1(%esi),%ebx
46c: 84 db test %bl,%bl
46e: 74 73 je 4e3 <printf+0xd3>
c = fmt[i] & 0xff;
if(state == 0){
470: 85 d2 test %edx,%edx
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
472: 0f be cb movsbl %bl,%ecx
475: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
478: 74 c6 je 440 <printf+0x30>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
47a: 83 fa 25 cmp $0x25,%edx
47d: 75 e6 jne 465 <printf+0x55>
if(c == 'd'){
47f: 83 f8 64 cmp $0x64,%eax
482: 0f 84 f8 00 00 00 je 580 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
488: 81 e1 f7 00 00 00 and $0xf7,%ecx
48e: 83 f9 70 cmp $0x70,%ecx
491: 74 5d je 4f0 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
493: 83 f8 73 cmp $0x73,%eax
496: 0f 84 84 00 00 00 je 520 <printf+0x110>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
49c: 83 f8 63 cmp $0x63,%eax
49f: 0f 84 ea 00 00 00 je 58f <printf+0x17f>
putc(fd, *ap);
ap++;