-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh.asm
5179 lines (4851 loc) · 176 KB
/
sh.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
_sh: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
return 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: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
static char buf[100];
int fd;
// Ensure that three file descriptors are open.
while((fd = open("console", O_RDWR)) >= 0){
11: eb 0e jmp 21 <main+0x21>
13: 90 nop
14: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(fd >= 3){
18: 83 f8 02 cmp $0x2,%eax
1b: 0f 8f c3 00 00 00 jg e4 <main+0xe4>
{
static char buf[100];
int fd;
// Ensure that three file descriptors are open.
while((fd = open("console", O_RDWR)) >= 0){
21: 83 ec 08 sub $0x8,%esp
24: 6a 02 push $0x2
26: 68 1d 1d 00 00 push $0x1d1d
2b: e8 32 0d 00 00 call d62 <open>
30: 83 c4 10 add $0x10,%esp
33: 85 c0 test %eax,%eax
35: 79 e1 jns 18 <main+0x18>
37: eb 2e jmp 67 <main+0x67>
39: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
}
}
// Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
40: 80 3d 02 28 00 00 20 cmpb $0x20,0x2802
47: 74 5d je a6 <main+0xa6>
49: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
int
fork1(void)
{
int pid;
pid = fork();
50: e8 c5 0c 00 00 call d1a <fork>
if(pid == -1)
55: 83 f8 ff cmp $0xffffffff,%eax
58: 74 3f je 99 <main+0x99>
buf[strlen(buf)-1] = 0; // chop \n
if(chdir(buf+3) < 0)
printf(2, "cannot cd %s\n", buf+3);
continue;
}
if(fork1() == 0)
5a: 85 c0 test %eax,%eax
5c: 0f 84 98 00 00 00 je fa <main+0xfa>
runcmd(parsecmd(buf));
wait();
62: e8 c3 0c 00 00 call d2a <wait>
break;
}
}
// Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){
67: 83 ec 08 sub $0x8,%esp
6a: 6a 64 push $0x64
6c: 68 00 28 00 00 push $0x2800
71: e8 9a 00 00 00 call 110 <getcmd>
76: 83 c4 10 add $0x10,%esp
79: 85 c0 test %eax,%eax
7b: 78 78 js f5 <main+0xf5>
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
7d: 80 3d 00 28 00 00 63 cmpb $0x63,0x2800
84: 75 ca jne 50 <main+0x50>
86: 80 3d 01 28 00 00 64 cmpb $0x64,0x2801
8d: 74 b1 je 40 <main+0x40>
int
fork1(void)
{
int pid;
pid = fork();
8f: e8 86 0c 00 00 call d1a <fork>
if(pid == -1)
94: 83 f8 ff cmp $0xffffffff,%eax
97: 75 c1 jne 5a <main+0x5a>
panic("fork");
99: 83 ec 0c sub $0xc,%esp
9c: 68 a6 1c 00 00 push $0x1ca6
a1: e8 ba 00 00 00 call 160 <panic>
// Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
// Chdir must be called by the parent, not the child.
buf[strlen(buf)-1] = 0; // chop \n
a6: 83 ec 0c sub $0xc,%esp
a9: 68 00 28 00 00 push $0x2800
ae: e8 ad 0a 00 00 call b60 <strlen>
if(chdir(buf+3) < 0)
b3: c7 04 24 03 28 00 00 movl $0x2803,(%esp)
// Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
// Chdir must be called by the parent, not the child.
buf[strlen(buf)-1] = 0; // chop \n
ba: c6 80 ff 27 00 00 00 movb $0x0,0x27ff(%eax)
if(chdir(buf+3) < 0)
c1: e8 cc 0c 00 00 call d92 <chdir>
c6: 83 c4 10 add $0x10,%esp
c9: 85 c0 test %eax,%eax
cb: 79 9a jns 67 <main+0x67>
printf(2, "cannot cd %s\n", buf+3);
cd: 50 push %eax
ce: 68 03 28 00 00 push $0x2803
d3: 68 25 1d 00 00 push $0x1d25
d8: 6a 02 push $0x2
da: e8 b1 0d 00 00 call e90 <printf>
df: 83 c4 10 add $0x10,%esp
e2: eb 83 jmp 67 <main+0x67>
int fd;
// Ensure that three file descriptors are open.
while((fd = open("console", O_RDWR)) >= 0){
if(fd >= 3){
close(fd);
e4: 83 ec 0c sub $0xc,%esp
e7: 50 push %eax
e8: e8 5d 0c 00 00 call d4a <close>
break;
ed: 83 c4 10 add $0x10,%esp
f0: e9 72 ff ff ff jmp 67 <main+0x67>
}
if(fork1() == 0)
runcmd(parsecmd(buf));
wait();
}
exit();
f5: e8 28 0c 00 00 call d22 <exit>
if(chdir(buf+3) < 0)
printf(2, "cannot cd %s\n", buf+3);
continue;
}
if(fork1() == 0)
runcmd(parsecmd(buf));
fa: 83 ec 0c sub $0xc,%esp
fd: 68 00 28 00 00 push $0x2800
102: e8 69 09 00 00 call a70 <parsecmd>
107: 89 04 24 mov %eax,(%esp)
10a: e8 71 00 00 00 call 180 <runcmd>
10f: 90 nop
00000110 <getcmd>:
exit();
}
int
getcmd(char *buf, int nbuf)
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 56 push %esi
114: 53 push %ebx
115: 8b 75 0c mov 0xc(%ebp),%esi
118: 8b 5d 08 mov 0x8(%ebp),%ebx
printf(2, "$ ");
11b: 83 ec 08 sub $0x8,%esp
11e: 68 7c 1c 00 00 push $0x1c7c
123: 6a 02 push $0x2
125: e8 66 0d 00 00 call e90 <printf>
memset(buf, 0, nbuf);
12a: 83 c4 0c add $0xc,%esp
12d: 56 push %esi
12e: 6a 00 push $0x0
130: 53 push %ebx
131: e8 5a 0a 00 00 call b90 <memset>
gets(buf, nbuf);
136: 58 pop %eax
137: 5a pop %edx
138: 56 push %esi
139: 53 push %ebx
13a: e8 b1 0a 00 00 call bf0 <gets>
13f: 83 c4 10 add $0x10,%esp
142: 31 c0 xor %eax,%eax
144: 80 3b 00 cmpb $0x0,(%ebx)
147: 0f 94 c0 sete %al
if(buf[0] == 0) // EOF
return -1;
return 0;
}
14a: 8d 65 f8 lea -0x8(%ebp),%esp
14d: f7 d8 neg %eax
14f: 5b pop %ebx
150: 5e pop %esi
151: 5d pop %ebp
152: c3 ret
153: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
159: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000160 <panic>:
exit();
}
void
panic(char *s)
{
160: 55 push %ebp
161: 89 e5 mov %esp,%ebp
163: 83 ec 0c sub $0xc,%esp
printf(2, "%s\n", s);
166: ff 75 08 pushl 0x8(%ebp)
169: 68 19 1d 00 00 push $0x1d19
16e: 6a 02 push $0x2
170: e8 1b 0d 00 00 call e90 <printf>
exit();
175: e8 a8 0b 00 00 call d22 <exit>
17a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000180 <runcmd>:
struct cmd *parsecmd(char*);
// Execute cmd. Never returns.
void
runcmd(struct cmd *cmd)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 53 push %ebx
184: 83 ec 14 sub $0x14,%esp
187: 8b 5d 08 mov 0x8(%ebp),%ebx
struct execcmd *ecmd;
struct listcmd *lcmd;
struct pipecmd *pcmd;
struct redircmd *rcmd;
if(cmd == 0)
18a: 85 db test %ebx,%ebx
18c: 74 76 je 204 <runcmd+0x84>
exit();
switch(cmd->type){
18e: 83 3b 05 cmpl $0x5,(%ebx)
191: 0f 87 f8 00 00 00 ja 28f <runcmd+0x10f>
197: 8b 03 mov (%ebx),%eax
199: ff 24 85 34 1d 00 00 jmp *0x1d34(,%eax,4)
runcmd(lcmd->right);
break;
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
1a0: 8d 45 f0 lea -0x10(%ebp),%eax
1a3: 83 ec 0c sub $0xc,%esp
1a6: 50 push %eax
1a7: e8 86 0b 00 00 call d32 <pipe>
1ac: 83 c4 10 add $0x10,%esp
1af: 85 c0 test %eax,%eax
1b1: 0f 88 07 01 00 00 js 2be <runcmd+0x13e>
int
fork1(void)
{
int pid;
pid = fork();
1b7: e8 5e 0b 00 00 call d1a <fork>
if(pid == -1)
1bc: 83 f8 ff cmp $0xffffffff,%eax
1bf: 0f 84 d7 00 00 00 je 29c <runcmd+0x11c>
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
panic("pipe");
if(fork1() == 0){
1c5: 85 c0 test %eax,%eax
1c7: 0f 84 fe 00 00 00 je 2cb <runcmd+0x14b>
int
fork1(void)
{
int pid;
pid = fork();
1cd: e8 48 0b 00 00 call d1a <fork>
if(pid == -1)
1d2: 83 f8 ff cmp $0xffffffff,%eax
1d5: 0f 84 c1 00 00 00 je 29c <runcmd+0x11c>
dup(p[1]);
close(p[0]);
close(p[1]);
runcmd(pcmd->left);
}
if(fork1() == 0){
1db: 85 c0 test %eax,%eax
1dd: 0f 84 16 01 00 00 je 2f9 <runcmd+0x179>
dup(p[0]);
close(p[0]);
close(p[1]);
runcmd(pcmd->right);
}
close(p[0]);
1e3: 83 ec 0c sub $0xc,%esp
1e6: ff 75 f0 pushl -0x10(%ebp)
1e9: e8 5c 0b 00 00 call d4a <close>
close(p[1]);
1ee: 58 pop %eax
1ef: ff 75 f4 pushl -0xc(%ebp)
1f2: e8 53 0b 00 00 call d4a <close>
wait();
1f7: e8 2e 0b 00 00 call d2a <wait>
wait();
1fc: e8 29 0b 00 00 call d2a <wait>
break;
201: 83 c4 10 add $0x10,%esp
struct listcmd *lcmd;
struct pipecmd *pcmd;
struct redircmd *rcmd;
if(cmd == 0)
exit();
204: e8 19 0b 00 00 call d22 <exit>
int
fork1(void)
{
int pid;
pid = fork();
209: e8 0c 0b 00 00 call d1a <fork>
if(pid == -1)
20e: 83 f8 ff cmp $0xffffffff,%eax
211: 0f 84 85 00 00 00 je 29c <runcmd+0x11c>
wait();
break;
case BACK:
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
217: 85 c0 test %eax,%eax
219: 75 e9 jne 204 <runcmd+0x84>
21b: eb 49 jmp 266 <runcmd+0xe6>
default:
panic("runcmd");
case EXEC:
ecmd = (struct execcmd*)cmd;
if(ecmd->argv[0] == 0)
21d: 8b 43 04 mov 0x4(%ebx),%eax
220: 85 c0 test %eax,%eax
222: 74 e0 je 204 <runcmd+0x84>
exit();
exec(ecmd->argv[0], ecmd->argv);
224: 52 push %edx
225: 52 push %edx
226: 8d 53 04 lea 0x4(%ebx),%edx
229: 52 push %edx
22a: 50 push %eax
22b: e8 2a 0b 00 00 call d5a <exec>
printf(2, "exec %s failed\n", ecmd->argv[0]);
230: 83 c4 0c add $0xc,%esp
233: ff 73 04 pushl 0x4(%ebx)
236: 68 86 1c 00 00 push $0x1c86
23b: 6a 02 push $0x2
23d: e8 4e 0c 00 00 call e90 <printf>
break;
242: 83 c4 10 add $0x10,%esp
245: eb bd jmp 204 <runcmd+0x84>
case REDIR:
rcmd = (struct redircmd*)cmd;
close(rcmd->fd);
247: 83 ec 0c sub $0xc,%esp
24a: ff 73 14 pushl 0x14(%ebx)
24d: e8 f8 0a 00 00 call d4a <close>
if(open(rcmd->file, rcmd->mode) < 0){
252: 59 pop %ecx
253: 58 pop %eax
254: ff 73 10 pushl 0x10(%ebx)
257: ff 73 08 pushl 0x8(%ebx)
25a: e8 03 0b 00 00 call d62 <open>
25f: 83 c4 10 add $0x10,%esp
262: 85 c0 test %eax,%eax
264: 78 43 js 2a9 <runcmd+0x129>
break;
case BACK:
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
runcmd(bcmd->cmd);
266: 83 ec 0c sub $0xc,%esp
269: ff 73 04 pushl 0x4(%ebx)
26c: e8 0f ff ff ff call 180 <runcmd>
int
fork1(void)
{
int pid;
pid = fork();
271: e8 a4 0a 00 00 call d1a <fork>
if(pid == -1)
276: 83 f8 ff cmp $0xffffffff,%eax
279: 74 21 je 29c <runcmd+0x11c>
runcmd(rcmd->cmd);
break;
case LIST:
lcmd = (struct listcmd*)cmd;
if(fork1() == 0)
27b: 85 c0 test %eax,%eax
27d: 74 e7 je 266 <runcmd+0xe6>
runcmd(lcmd->left);
wait();
27f: e8 a6 0a 00 00 call d2a <wait>
runcmd(lcmd->right);
284: 83 ec 0c sub $0xc,%esp
287: ff 73 08 pushl 0x8(%ebx)
28a: e8 f1 fe ff ff call 180 <runcmd>
if(cmd == 0)
exit();
switch(cmd->type){
default:
panic("runcmd");
28f: 83 ec 0c sub $0xc,%esp
292: 68 7f 1c 00 00 push $0x1c7f
297: e8 c4 fe ff ff call 160 <panic>
{
int pid;
pid = fork();
if(pid == -1)
panic("fork");
29c: 83 ec 0c sub $0xc,%esp
29f: 68 a6 1c 00 00 push $0x1ca6
2a4: e8 b7 fe ff ff call 160 <panic>
case REDIR:
rcmd = (struct redircmd*)cmd;
close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){
printf(2, "open %s failed\n", rcmd->file);
2a9: 52 push %edx
2aa: ff 73 08 pushl 0x8(%ebx)
2ad: 68 96 1c 00 00 push $0x1c96
2b2: 6a 02 push $0x2
2b4: e8 d7 0b 00 00 call e90 <printf>
exit();
2b9: e8 64 0a 00 00 call d22 <exit>
break;
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
panic("pipe");
2be: 83 ec 0c sub $0xc,%esp
2c1: 68 ab 1c 00 00 push $0x1cab
2c6: e8 95 fe ff ff call 160 <panic>
if(fork1() == 0){
close(1);
2cb: 83 ec 0c sub $0xc,%esp
2ce: 6a 01 push $0x1
2d0: e8 75 0a 00 00 call d4a <close>
dup(p[1]);
2d5: 58 pop %eax
2d6: ff 75 f4 pushl -0xc(%ebp)
2d9: e8 bc 0a 00 00 call d9a <dup>
close(p[0]);
2de: 58 pop %eax
2df: ff 75 f0 pushl -0x10(%ebp)
2e2: e8 63 0a 00 00 call d4a <close>
close(p[1]);
2e7: 58 pop %eax
2e8: ff 75 f4 pushl -0xc(%ebp)
2eb: e8 5a 0a 00 00 call d4a <close>
runcmd(pcmd->left);
2f0: 58 pop %eax
2f1: ff 73 04 pushl 0x4(%ebx)
2f4: e8 87 fe ff ff call 180 <runcmd>
}
if(fork1() == 0){
close(0);
2f9: 83 ec 0c sub $0xc,%esp
2fc: 6a 00 push $0x0
2fe: e8 47 0a 00 00 call d4a <close>
dup(p[0]);
303: 5a pop %edx
304: ff 75 f0 pushl -0x10(%ebp)
307: e8 8e 0a 00 00 call d9a <dup>
close(p[0]);
30c: 59 pop %ecx
30d: ff 75 f0 pushl -0x10(%ebp)
310: e8 35 0a 00 00 call d4a <close>
close(p[1]);
315: 58 pop %eax
316: ff 75 f4 pushl -0xc(%ebp)
319: e8 2c 0a 00 00 call d4a <close>
runcmd(pcmd->right);
31e: 58 pop %eax
31f: ff 73 08 pushl 0x8(%ebx)
322: e8 59 fe ff ff call 180 <runcmd>
327: 89 f6 mov %esi,%esi
329: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000330 <fork1>:
exit();
}
int
fork1(void)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 83 ec 08 sub $0x8,%esp
int pid;
pid = fork();
336: e8 df 09 00 00 call d1a <fork>
if(pid == -1)
33b: 83 f8 ff cmp $0xffffffff,%eax
33e: 74 02 je 342 <fork1+0x12>
panic("fork");
return pid;
}
340: c9 leave
341: c3 ret
{
int pid;
pid = fork();
if(pid == -1)
panic("fork");
342: 83 ec 0c sub $0xc,%esp
345: 68 a6 1c 00 00 push $0x1ca6
34a: e8 11 fe ff ff call 160 <panic>
34f: 90 nop
00000350 <execcmd>:
//PAGEBREAK!
// Constructors
struct cmd*
execcmd(void)
{
350: 55 push %ebp
351: 89 e5 mov %esp,%ebp
353: 53 push %ebx
354: 83 ec 10 sub $0x10,%esp
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
357: 6a 54 push $0x54
359: e8 62 0d 00 00 call 10c0 <malloc>
memset(cmd, 0, sizeof(*cmd));
35e: 83 c4 0c add $0xc,%esp
struct cmd*
execcmd(void)
{
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
361: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
363: 6a 54 push $0x54
365: 6a 00 push $0x0
367: 50 push %eax
368: e8 23 08 00 00 call b90 <memset>
cmd->type = EXEC;
36d: c7 03 01 00 00 00 movl $0x1,(%ebx)
return (struct cmd*)cmd;
}
373: 89 d8 mov %ebx,%eax
375: 8b 5d fc mov -0x4(%ebp),%ebx
378: c9 leave
379: c3 ret
37a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000380 <redircmd>:
struct cmd*
redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{
380: 55 push %ebp
381: 89 e5 mov %esp,%ebp
383: 53 push %ebx
384: 83 ec 10 sub $0x10,%esp
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
387: 6a 18 push $0x18
389: e8 32 0d 00 00 call 10c0 <malloc>
memset(cmd, 0, sizeof(*cmd));
38e: 83 c4 0c add $0xc,%esp
struct cmd*
redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
391: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
393: 6a 18 push $0x18
395: 6a 00 push $0x0
397: 50 push %eax
398: e8 f3 07 00 00 call b90 <memset>
cmd->type = REDIR;
cmd->cmd = subcmd;
39d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = REDIR;
3a0: c7 03 02 00 00 00 movl $0x2,(%ebx)
cmd->cmd = subcmd;
3a6: 89 43 04 mov %eax,0x4(%ebx)
cmd->file = file;
3a9: 8b 45 0c mov 0xc(%ebp),%eax
3ac: 89 43 08 mov %eax,0x8(%ebx)
cmd->efile = efile;
3af: 8b 45 10 mov 0x10(%ebp),%eax
3b2: 89 43 0c mov %eax,0xc(%ebx)
cmd->mode = mode;
3b5: 8b 45 14 mov 0x14(%ebp),%eax
3b8: 89 43 10 mov %eax,0x10(%ebx)
cmd->fd = fd;
3bb: 8b 45 18 mov 0x18(%ebp),%eax
3be: 89 43 14 mov %eax,0x14(%ebx)
return (struct cmd*)cmd;
}
3c1: 89 d8 mov %ebx,%eax
3c3: 8b 5d fc mov -0x4(%ebp),%ebx
3c6: c9 leave
3c7: c3 ret
3c8: 90 nop
3c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000003d0 <pipecmd>:
struct cmd*
pipecmd(struct cmd *left, struct cmd *right)
{
3d0: 55 push %ebp
3d1: 89 e5 mov %esp,%ebp
3d3: 53 push %ebx
3d4: 83 ec 10 sub $0x10,%esp
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
3d7: 6a 0c push $0xc
3d9: e8 e2 0c 00 00 call 10c0 <malloc>
memset(cmd, 0, sizeof(*cmd));
3de: 83 c4 0c add $0xc,%esp
struct cmd*
pipecmd(struct cmd *left, struct cmd *right)
{
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
3e1: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
3e3: 6a 0c push $0xc
3e5: 6a 00 push $0x0
3e7: 50 push %eax
3e8: e8 a3 07 00 00 call b90 <memset>
cmd->type = PIPE;
cmd->left = left;
3ed: 8b 45 08 mov 0x8(%ebp),%eax
{
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = PIPE;
3f0: c7 03 03 00 00 00 movl $0x3,(%ebx)
cmd->left = left;
3f6: 89 43 04 mov %eax,0x4(%ebx)
cmd->right = right;
3f9: 8b 45 0c mov 0xc(%ebp),%eax
3fc: 89 43 08 mov %eax,0x8(%ebx)
return (struct cmd*)cmd;
}
3ff: 89 d8 mov %ebx,%eax
401: 8b 5d fc mov -0x4(%ebp),%ebx
404: c9 leave
405: c3 ret
406: 8d 76 00 lea 0x0(%esi),%esi
409: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000410 <listcmd>:
struct cmd*
listcmd(struct cmd *left, struct cmd *right)
{
410: 55 push %ebp
411: 89 e5 mov %esp,%ebp
413: 53 push %ebx
414: 83 ec 10 sub $0x10,%esp
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
417: 6a 0c push $0xc
419: e8 a2 0c 00 00 call 10c0 <malloc>
memset(cmd, 0, sizeof(*cmd));
41e: 83 c4 0c add $0xc,%esp
struct cmd*
listcmd(struct cmd *left, struct cmd *right)
{
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
421: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
423: 6a 0c push $0xc
425: 6a 00 push $0x0
427: 50 push %eax
428: e8 63 07 00 00 call b90 <memset>
cmd->type = LIST;
cmd->left = left;
42d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = LIST;
430: c7 03 04 00 00 00 movl $0x4,(%ebx)
cmd->left = left;
436: 89 43 04 mov %eax,0x4(%ebx)
cmd->right = right;
439: 8b 45 0c mov 0xc(%ebp),%eax
43c: 89 43 08 mov %eax,0x8(%ebx)
return (struct cmd*)cmd;
}
43f: 89 d8 mov %ebx,%eax
441: 8b 5d fc mov -0x4(%ebp),%ebx
444: c9 leave
445: c3 ret
446: 8d 76 00 lea 0x0(%esi),%esi
449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000450 <backcmd>:
struct cmd*
backcmd(struct cmd *subcmd)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 53 push %ebx
454: 83 ec 10 sub $0x10,%esp
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
457: 6a 08 push $0x8
459: e8 62 0c 00 00 call 10c0 <malloc>
memset(cmd, 0, sizeof(*cmd));
45e: 83 c4 0c add $0xc,%esp
struct cmd*
backcmd(struct cmd *subcmd)
{
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
461: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
463: 6a 08 push $0x8
465: 6a 00 push $0x0
467: 50 push %eax
468: e8 23 07 00 00 call b90 <memset>
cmd->type = BACK;
cmd->cmd = subcmd;
46d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = BACK;
470: c7 03 05 00 00 00 movl $0x5,(%ebx)
cmd->cmd = subcmd;
476: 89 43 04 mov %eax,0x4(%ebx)
return (struct cmd*)cmd;
}
479: 89 d8 mov %ebx,%eax
47b: 8b 5d fc mov -0x4(%ebp),%ebx
47e: c9 leave
47f: c3 ret
00000480 <gettoken>:
char whitespace[] = " \t\r\n\v";
char symbols[] = "<|>&;()";
int
gettoken(char **ps, char *es, char **q, char **eq)
{
480: 55 push %ebp
481: 89 e5 mov %esp,%ebp
483: 57 push %edi
484: 56 push %esi
485: 53 push %ebx
486: 83 ec 0c sub $0xc,%esp
char *s;
int ret;
s = *ps;
489: 8b 45 08 mov 0x8(%ebp),%eax
char whitespace[] = " \t\r\n\v";
char symbols[] = "<|>&;()";
int
gettoken(char **ps, char *es, char **q, char **eq)
{
48c: 8b 5d 0c mov 0xc(%ebp),%ebx
48f: 8b 75 10 mov 0x10(%ebp),%esi
char *s;
int ret;
s = *ps;
492: 8b 38 mov (%eax),%edi
while(s < es && strchr(whitespace, *s))
494: 39 df cmp %ebx,%edi
496: 72 13 jb 4ab <gettoken+0x2b>
498: eb 29 jmp 4c3 <gettoken+0x43>
49a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
s++;
4a0: 83 c7 01 add $0x1,%edi
{
char *s;
int ret;
s = *ps;
while(s < es && strchr(whitespace, *s))
4a3: 39 fb cmp %edi,%ebx
4a5: 0f 84 ed 00 00 00 je 598 <gettoken+0x118>
4ab: 0f be 07 movsbl (%edi),%eax
4ae: 83 ec 08 sub $0x8,%esp
4b1: 50 push %eax
4b2: 68 e4 27 00 00 push $0x27e4
4b7: e8 f4 06 00 00 call bb0 <strchr>
4bc: 83 c4 10 add $0x10,%esp
4bf: 85 c0 test %eax,%eax
4c1: 75 dd jne 4a0 <gettoken+0x20>
s++;
if(q)
4c3: 85 f6 test %esi,%esi
4c5: 74 02 je 4c9 <gettoken+0x49>
*q = s;
4c7: 89 3e mov %edi,(%esi)
ret = *s;
4c9: 0f be 37 movsbl (%edi),%esi
4cc: 89 f1 mov %esi,%ecx
4ce: 89 f0 mov %esi,%eax
switch(*s){
4d0: 80 f9 29 cmp $0x29,%cl
4d3: 7f 5b jg 530 <gettoken+0xb0>
4d5: 80 f9 28 cmp $0x28,%cl
4d8: 7d 61 jge 53b <gettoken+0xbb>
4da: 84 c9 test %cl,%cl
4dc: 0f 85 de 00 00 00 jne 5c0 <gettoken+0x140>
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
s++;
break;
}
if(eq)
4e2: 8b 55 14 mov 0x14(%ebp),%edx
4e5: 85 d2 test %edx,%edx
4e7: 74 05 je 4ee <gettoken+0x6e>
*eq = s;
4e9: 8b 45 14 mov 0x14(%ebp),%eax
4ec: 89 38 mov %edi,(%eax)
while(s < es && strchr(whitespace, *s))
4ee: 39 fb cmp %edi,%ebx
4f0: 77 0d ja 4ff <gettoken+0x7f>
4f2: eb 23 jmp 517 <gettoken+0x97>
4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
s++;
4f8: 83 c7 01 add $0x1,%edi
break;
}
if(eq)
*eq = s;
while(s < es && strchr(whitespace, *s))
4fb: 39 fb cmp %edi,%ebx
4fd: 74 18 je 517 <gettoken+0x97>
4ff: 0f be 07 movsbl (%edi),%eax
502: 83 ec 08 sub $0x8,%esp
505: 50 push %eax
506: 68 e4 27 00 00 push $0x27e4
50b: e8 a0 06 00 00 call bb0 <strchr>
510: 83 c4 10 add $0x10,%esp
513: 85 c0 test %eax,%eax
515: 75 e1 jne 4f8 <gettoken+0x78>
s++;
*ps = s;
517: 8b 45 08 mov 0x8(%ebp),%eax
51a: 89 38 mov %edi,(%eax)
return ret;
}
51c: 8d 65 f4 lea -0xc(%ebp),%esp
51f: 89 f0 mov %esi,%eax
521: 5b pop %ebx
522: 5e pop %esi
523: 5f pop %edi
524: 5d pop %ebp
525: c3 ret
526: 8d 76 00 lea 0x0(%esi),%esi
529: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
while(s < es && strchr(whitespace, *s))
s++;
if(q)
*q = s;
ret = *s;
switch(*s){
530: 80 f9 3e cmp $0x3e,%cl
533: 75 0b jne 540 <gettoken+0xc0>
case '<':
s++;
break;
case '>':
s++;
if(*s == '>'){
535: 80 7f 01 3e cmpb $0x3e,0x1(%edi)
539: 74 75 je 5b0 <gettoken+0x130>
case '&':
case '<':
s++;
break;
case '>':
s++;
53b: 83 c7 01 add $0x1,%edi
53e: eb a2 jmp 4e2 <gettoken+0x62>
while(s < es && strchr(whitespace, *s))
s++;
if(q)
*q = s;
ret = *s;
switch(*s){
540: 7f 5e jg 5a0 <gettoken+0x120>
542: 83 e9 3b sub $0x3b,%ecx
545: 80 f9 01 cmp $0x1,%cl
548: 76 f1 jbe 53b <gettoken+0xbb>
s++;
}
break;
default:
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
54a: 39 fb cmp %edi,%ebx
54c: 77 24 ja 572 <gettoken+0xf2>
54e: eb 7c jmp 5cc <gettoken+0x14c>
550: 0f be 07 movsbl (%edi),%eax
553: 83 ec 08 sub $0x8,%esp
556: 50 push %eax
557: 68 dc 27 00 00 push $0x27dc
55c: e8 4f 06 00 00 call bb0 <strchr>
561: 83 c4 10 add $0x10,%esp
564: 85 c0 test %eax,%eax
566: 75 1f jne 587 <gettoken+0x107>
s++;
568: 83 c7 01 add $0x1,%edi
s++;
}
break;
default:
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
56b: 39 fb cmp %edi,%ebx
56d: 74 5b je 5ca <gettoken+0x14a>
56f: 0f be 07 movsbl (%edi),%eax
572: 83 ec 08 sub $0x8,%esp
575: 50 push %eax
576: 68 e4 27 00 00 push $0x27e4
57b: e8 30 06 00 00 call bb0 <strchr>
580: 83 c4 10 add $0x10,%esp
583: 85 c0 test %eax,%eax
585: 74 c9 je 550 <gettoken+0xd0>
ret = '+';
s++;
}
break;