/
sh.asm
3451 lines (3225 loc) · 109 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 <getcmd>:
exit();
}
int
getcmd(char *buf, int nbuf)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 18 sub $0x18,%esp
6: 89 5d f8 mov %ebx,-0x8(%ebp)
9: 8b 5d 08 mov 0x8(%ebp),%ebx
c: 89 75 fc mov %esi,-0x4(%ebp)
f: 8b 75 0c mov 0xc(%ebp),%esi
printf(2, "$ ");
12: c7 44 24 04 10 13 00 movl $0x1310,0x4(%esp)
19: 00
1a: c7 04 24 02 00 00 00 movl $0x2,(%esp)
21: e8 ca 0f 00 00 call ff0 <printf>
memset(buf, 0, nbuf);
26: 89 74 24 08 mov %esi,0x8(%esp)
2a: 89 1c 24 mov %ebx,(%esp)
2d: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
34: 00
35: e8 c6 0c 00 00 call d00 <memset>
gets(buf, nbuf);
3a: 89 74 24 04 mov %esi,0x4(%esp)
3e: 89 1c 24 mov %ebx,(%esp)
41: e8 2a 0d 00 00 call d70 <gets>
if(buf[0] == 0) // EOF
return -1;
return 0;
}
46: 8b 75 fc mov -0x4(%ebp),%esi
{
printf(2, "$ ");
memset(buf, 0, nbuf);
gets(buf, nbuf);
if(buf[0] == 0) // EOF
return -1;
49: 80 3b 01 cmpb $0x1,(%ebx)
return 0;
}
4c: 8b 5d f8 mov -0x8(%ebp),%ebx
{
printf(2, "$ ");
memset(buf, 0, nbuf);
gets(buf, nbuf);
if(buf[0] == 0) // EOF
return -1;
4f: 19 c0 sbb %eax,%eax
return 0;
}
51: 89 ec mov %ebp,%esp
53: 5d pop %ebp
54: c3 ret
55: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
59: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000060 <panic>:
exit();
}
void
panic(char *s)
{
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 83 ec 18 sub $0x18,%esp
printf(2, "%s\n", s);
66: 8b 45 08 mov 0x8(%ebp),%eax
69: c7 44 24 04 ad 13 00 movl $0x13ad,0x4(%esp)
70: 00
71: c7 04 24 02 00 00 00 movl $0x2,(%esp)
78: 89 44 24 08 mov %eax,0x8(%esp)
7c: e8 6f 0f 00 00 call ff0 <printf>
exit();
81: e8 1e 0e 00 00 call ea4 <exit>
86: 8d 76 00 lea 0x0(%esi),%esi
89: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000090 <fork1>:
}
int
fork1(void)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 83 ec 28 sub $0x28,%esp
int pid;
pid = fork();
96: e8 01 0e 00 00 call e9c <fork>
if(pid == -1)
9b: 83 f8 ff cmp $0xffffffff,%eax
9e: 74 08 je a8 <fork1+0x18>
panic("fork");
return pid;
}
a0: c9 leave
a1: c3 ret
a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
{
int pid;
pid = fork();
if(pid == -1)
panic("fork");
a8: 89 45 f4 mov %eax,-0xc(%ebp)
ab: c7 04 24 13 13 00 00 movl $0x1313,(%esp)
b2: e8 a9 ff ff ff call 60 <panic>
b7: 8b 45 f4 mov -0xc(%ebp),%eax
return pid;
}
ba: c9 leave
bb: c3 ret
bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000000c0 <runcmd>:
struct cmd *parsecmd(char*);
// Execute cmd. Never returns.
void
runcmd(struct cmd *cmd)
{
c0: 55 push %ebp
c1: 89 e5 mov %esp,%ebp
c3: 53 push %ebx
c4: 83 ec 24 sub $0x24,%esp
c7: 8b 5d 08 mov 0x8(%ebp),%ebx
struct execcmd *ecmd;
struct listcmd *lcmd;
struct pipecmd *pcmd;
struct redircmd *rcmd;
if(cmd == 0)
ca: 85 db test %ebx,%ebx
cc: 74 42 je 110 <runcmd+0x50>
exit();
switch(cmd->type){
ce: 83 3b 05 cmpl $0x5,(%ebx)
d1: 76 45 jbe 118 <runcmd+0x58>
default:
panic("runcmd");
d3: c7 04 24 18 13 00 00 movl $0x1318,(%esp)
da: e8 81 ff ff ff call 60 <panic>
case EXEC:
ecmd = (struct execcmd*)cmd;
if(ecmd->argv[0] == 0)
df: 8b 43 04 mov 0x4(%ebx),%eax
e2: 85 c0 test %eax,%eax
e4: 74 2a je 110 <runcmd+0x50>
exit();
exec(ecmd->argv[0], ecmd->argv);
e6: 8d 53 04 lea 0x4(%ebx),%edx
e9: 89 54 24 04 mov %edx,0x4(%esp)
ed: 89 04 24 mov %eax,(%esp)
f0: e8 e7 0d 00 00 call edc <exec>
printf(2, "exec %s failed\n", ecmd->argv[0]);
f5: 8b 43 04 mov 0x4(%ebx),%eax
f8: c7 44 24 04 1f 13 00 movl $0x131f,0x4(%esp)
ff: 00
100: c7 04 24 02 00 00 00 movl $0x2,(%esp)
107: 89 44 24 08 mov %eax,0x8(%esp)
10b: e8 e0 0e 00 00 call ff0 <printf>
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
runcmd(bcmd->cmd);
break;
}
exit();
110: e8 8f 0d 00 00 call ea4 <exit>
115: 8d 76 00 lea 0x0(%esi),%esi
struct redircmd *rcmd;
if(cmd == 0)
exit();
switch(cmd->type){
118: 8b 03 mov (%ebx),%eax
11a: ff 24 85 c8 13 00 00 jmp *0x13c8(,%eax,4)
121: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
wait();
break;
case BACK:
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
128: e8 63 ff ff ff call 90 <fork1>
12d: 85 c0 test %eax,%eax
12f: 90 nop
130: 0f 84 a7 00 00 00 je 1dd <runcmd+0x11d>
runcmd(bcmd->cmd);
break;
}
exit();
136: e8 69 0d 00 00 call ea4 <exit>
13b: 90 nop
13c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
runcmd(rcmd->cmd);
break;
case LIST:
lcmd = (struct listcmd*)cmd;
if(fork1() == 0)
140: e8 4b ff ff ff call 90 <fork1>
145: 85 c0 test %eax,%eax
147: 0f 84 a3 00 00 00 je 1f0 <runcmd+0x130>
14d: 8d 76 00 lea 0x0(%esi),%esi
runcmd(lcmd->left);
wait();
150: e8 57 0d 00 00 call eac <wait>
runcmd(lcmd->right);
155: 8b 43 08 mov 0x8(%ebx),%eax
158: 89 04 24 mov %eax,(%esp)
15b: e8 60 ff ff ff call c0 <runcmd>
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
runcmd(bcmd->cmd);
break;
}
exit();
160: e8 3f 0d 00 00 call ea4 <exit>
165: 8d 76 00 lea 0x0(%esi),%esi
runcmd(lcmd->right);
break;
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
168: 8d 45 f0 lea -0x10(%ebp),%eax
16b: 89 04 24 mov %eax,(%esp)
16e: e8 41 0d 00 00 call eb4 <pipe>
173: 85 c0 test %eax,%eax
175: 0f 88 25 01 00 00 js 2a0 <runcmd+0x1e0>
panic("pipe");
if(fork1() == 0){
17b: e8 10 ff ff ff call 90 <fork1>
180: 85 c0 test %eax,%eax
182: 0f 84 b8 00 00 00 je 240 <runcmd+0x180>
dup(p[1]);
close(p[0]);
close(p[1]);
runcmd(pcmd->left);
}
if(fork1() == 0){
188: e8 03 ff ff ff call 90 <fork1>
18d: 85 c0 test %eax,%eax
18f: 90 nop
190: 74 6e je 200 <runcmd+0x140>
dup(p[0]);
close(p[0]);
close(p[1]);
runcmd(pcmd->right);
}
close(p[0]);
192: 8b 45 f0 mov -0x10(%ebp),%eax
195: 89 04 24 mov %eax,(%esp)
198: e8 2f 0d 00 00 call ecc <close>
close(p[1]);
19d: 8b 45 f4 mov -0xc(%ebp),%eax
1a0: 89 04 24 mov %eax,(%esp)
1a3: e8 24 0d 00 00 call ecc <close>
wait();
1a8: e8 ff 0c 00 00 call eac <wait>
wait();
1ad: e8 fa 0c 00 00 call eac <wait>
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
runcmd(bcmd->cmd);
break;
}
exit();
1b2: e8 ed 0c 00 00 call ea4 <exit>
1b7: 90 nop
printf(2, "exec %s failed\n", ecmd->argv[0]);
break;
case REDIR:
rcmd = (struct redircmd*)cmd;
close(rcmd->fd);
1b8: 8b 43 14 mov 0x14(%ebx),%eax
1bb: 89 04 24 mov %eax,(%esp)
1be: e8 09 0d 00 00 call ecc <close>
if(open(rcmd->file, rcmd->mode) < 0){
1c3: 8b 43 10 mov 0x10(%ebx),%eax
1c6: 89 44 24 04 mov %eax,0x4(%esp)
1ca: 8b 43 08 mov 0x8(%ebx),%eax
1cd: 89 04 24 mov %eax,(%esp)
1d0: e8 0f 0d 00 00 call ee4 <open>
1d5: 85 c0 test %eax,%eax
1d7: 0f 88 a3 00 00 00 js 280 <runcmd+0x1c0>
break;
case BACK:
bcmd = (struct backcmd*)cmd;
if(fork1() == 0)
runcmd(bcmd->cmd);
1dd: 8b 43 04 mov 0x4(%ebx),%eax
1e0: 89 04 24 mov %eax,(%esp)
1e3: e8 d8 fe ff ff call c0 <runcmd>
break;
}
exit();
1e8: e8 b7 0c 00 00 call ea4 <exit>
1ed: 8d 76 00 lea 0x0(%esi),%esi
break;
case LIST:
lcmd = (struct listcmd*)cmd;
if(fork1() == 0)
runcmd(lcmd->left);
1f0: 8b 43 04 mov 0x4(%ebx),%eax
1f3: 89 04 24 mov %eax,(%esp)
1f6: e8 c5 fe ff ff call c0 <runcmd>
1fb: e9 4d ff ff ff jmp 14d <runcmd+0x8d>
close(p[0]);
close(p[1]);
runcmd(pcmd->left);
}
if(fork1() == 0){
close(0);
200: c7 04 24 00 00 00 00 movl $0x0,(%esp)
207: e8 c0 0c 00 00 call ecc <close>
dup(p[0]);
20c: 8b 45 f0 mov -0x10(%ebp),%eax
20f: 89 04 24 mov %eax,(%esp)
212: e8 05 0d 00 00 call f1c <dup>
close(p[0]);
217: 8b 45 f0 mov -0x10(%ebp),%eax
21a: 89 04 24 mov %eax,(%esp)
21d: e8 aa 0c 00 00 call ecc <close>
close(p[1]);
222: 8b 45 f4 mov -0xc(%ebp),%eax
225: 89 04 24 mov %eax,(%esp)
228: e8 9f 0c 00 00 call ecc <close>
runcmd(pcmd->right);
22d: 8b 43 08 mov 0x8(%ebx),%eax
230: 89 04 24 mov %eax,(%esp)
233: e8 88 fe ff ff call c0 <runcmd>
238: e9 55 ff ff ff jmp 192 <runcmd+0xd2>
23d: 8d 76 00 lea 0x0(%esi),%esi
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
panic("pipe");
if(fork1() == 0){
close(1);
240: c7 04 24 01 00 00 00 movl $0x1,(%esp)
247: e8 80 0c 00 00 call ecc <close>
dup(p[1]);
24c: 8b 45 f4 mov -0xc(%ebp),%eax
24f: 89 04 24 mov %eax,(%esp)
252: e8 c5 0c 00 00 call f1c <dup>
close(p[0]);
257: 8b 45 f0 mov -0x10(%ebp),%eax
25a: 89 04 24 mov %eax,(%esp)
25d: e8 6a 0c 00 00 call ecc <close>
close(p[1]);
262: 8b 45 f4 mov -0xc(%ebp),%eax
265: 89 04 24 mov %eax,(%esp)
268: e8 5f 0c 00 00 call ecc <close>
runcmd(pcmd->left);
26d: 8b 43 04 mov 0x4(%ebx),%eax
270: 89 04 24 mov %eax,(%esp)
273: e8 48 fe ff ff call c0 <runcmd>
278: e9 0b ff ff ff jmp 188 <runcmd+0xc8>
27d: 8d 76 00 lea 0x0(%esi),%esi
case REDIR:
rcmd = (struct redircmd*)cmd;
close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){
printf(2, "open %s failed\n", rcmd->file);
280: 8b 43 08 mov 0x8(%ebx),%eax
283: c7 44 24 04 2f 13 00 movl $0x132f,0x4(%esp)
28a: 00
28b: c7 04 24 02 00 00 00 movl $0x2,(%esp)
292: 89 44 24 08 mov %eax,0x8(%esp)
296: e8 55 0d 00 00 call ff0 <printf>
exit();
29b: e8 04 0c 00 00 call ea4 <exit>
break;
case PIPE:
pcmd = (struct pipecmd*)cmd;
if(pipe(p) < 0)
panic("pipe");
2a0: c7 04 24 3f 13 00 00 movl $0x133f,(%esp)
2a7: e8 b4 fd ff ff call 60 <panic>
2ac: e9 ca fe ff ff jmp 17b <runcmd+0xbb>
2b1: eb 0d jmp 2c0 <execcmd>
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 <execcmd>:
// Constructors
struct cmd*
execcmd(void)
{
2c0: 55 push %ebp
2c1: 89 e5 mov %esp,%ebp
2c3: 53 push %ebx
2c4: 83 ec 14 sub $0x14,%esp
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
2c7: c7 04 24 54 00 00 00 movl $0x54,(%esp)
2ce: e8 3d 0f 00 00 call 1210 <malloc>
memset(cmd, 0, sizeof(*cmd));
2d3: c7 44 24 08 54 00 00 movl $0x54,0x8(%esp)
2da: 00
2db: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
2e2: 00
struct cmd*
execcmd(void)
{
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
2e3: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
2e5: 89 04 24 mov %eax,(%esp)
2e8: e8 13 0a 00 00 call d00 <memset>
cmd->type = EXEC;
return (struct cmd*)cmd;
}
2ed: 89 d8 mov %ebx,%eax
{
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = EXEC;
2ef: c7 03 01 00 00 00 movl $0x1,(%ebx)
return (struct cmd*)cmd;
}
2f5: 83 c4 14 add $0x14,%esp
2f8: 5b pop %ebx
2f9: 5d pop %ebp
2fa: c3 ret
2fb: 90 nop
2fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000300 <redircmd>:
struct cmd*
redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 53 push %ebx
304: 83 ec 14 sub $0x14,%esp
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
307: c7 04 24 18 00 00 00 movl $0x18,(%esp)
30e: e8 fd 0e 00 00 call 1210 <malloc>
memset(cmd, 0, sizeof(*cmd));
313: c7 44 24 08 18 00 00 movl $0x18,0x8(%esp)
31a: 00
31b: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
322: 00
struct cmd*
redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
323: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
325: 89 04 24 mov %eax,(%esp)
328: e8 d3 09 00 00 call d00 <memset>
cmd->type = REDIR;
cmd->cmd = subcmd;
32d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = REDIR;
330: c7 03 02 00 00 00 movl $0x2,(%ebx)
cmd->cmd = subcmd;
336: 89 43 04 mov %eax,0x4(%ebx)
cmd->file = file;
339: 8b 45 0c mov 0xc(%ebp),%eax
33c: 89 43 08 mov %eax,0x8(%ebx)
cmd->efile = efile;
33f: 8b 45 10 mov 0x10(%ebp),%eax
342: 89 43 0c mov %eax,0xc(%ebx)
cmd->mode = mode;
345: 8b 45 14 mov 0x14(%ebp),%eax
348: 89 43 10 mov %eax,0x10(%ebx)
cmd->fd = fd;
34b: 8b 45 18 mov 0x18(%ebp),%eax
34e: 89 43 14 mov %eax,0x14(%ebx)
return (struct cmd*)cmd;
}
351: 89 d8 mov %ebx,%eax
353: 83 c4 14 add $0x14,%esp
356: 5b pop %ebx
357: 5d pop %ebp
358: c3 ret
359: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000360 <pipecmd>:
struct cmd*
pipecmd(struct cmd *left, struct cmd *right)
{
360: 55 push %ebp
361: 89 e5 mov %esp,%ebp
363: 53 push %ebx
364: 83 ec 14 sub $0x14,%esp
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
367: c7 04 24 0c 00 00 00 movl $0xc,(%esp)
36e: e8 9d 0e 00 00 call 1210 <malloc>
memset(cmd, 0, sizeof(*cmd));
373: c7 44 24 08 0c 00 00 movl $0xc,0x8(%esp)
37a: 00
37b: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
382: 00
struct cmd*
pipecmd(struct cmd *left, struct cmd *right)
{
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
383: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
385: 89 04 24 mov %eax,(%esp)
388: e8 73 09 00 00 call d00 <memset>
cmd->type = PIPE;
cmd->left = left;
38d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = PIPE;
390: c7 03 03 00 00 00 movl $0x3,(%ebx)
cmd->left = left;
396: 89 43 04 mov %eax,0x4(%ebx)
cmd->right = right;
399: 8b 45 0c mov 0xc(%ebp),%eax
39c: 89 43 08 mov %eax,0x8(%ebx)
return (struct cmd*)cmd;
}
39f: 89 d8 mov %ebx,%eax
3a1: 83 c4 14 add $0x14,%esp
3a4: 5b pop %ebx
3a5: 5d pop %ebp
3a6: c3 ret
3a7: 89 f6 mov %esi,%esi
3a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000003b0 <listcmd>:
struct cmd*
listcmd(struct cmd *left, struct cmd *right)
{
3b0: 55 push %ebp
3b1: 89 e5 mov %esp,%ebp
3b3: 53 push %ebx
3b4: 83 ec 14 sub $0x14,%esp
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
3b7: c7 04 24 0c 00 00 00 movl $0xc,(%esp)
3be: e8 4d 0e 00 00 call 1210 <malloc>
memset(cmd, 0, sizeof(*cmd));
3c3: c7 44 24 08 0c 00 00 movl $0xc,0x8(%esp)
3ca: 00
3cb: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
3d2: 00
struct cmd*
listcmd(struct cmd *left, struct cmd *right)
{
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
3d3: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
3d5: 89 04 24 mov %eax,(%esp)
3d8: e8 23 09 00 00 call d00 <memset>
cmd->type = LIST;
cmd->left = left;
3dd: 8b 45 08 mov 0x8(%ebp),%eax
{
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = LIST;
3e0: c7 03 04 00 00 00 movl $0x4,(%ebx)
cmd->left = left;
3e6: 89 43 04 mov %eax,0x4(%ebx)
cmd->right = right;
3e9: 8b 45 0c mov 0xc(%ebp),%eax
3ec: 89 43 08 mov %eax,0x8(%ebx)
return (struct cmd*)cmd;
}
3ef: 89 d8 mov %ebx,%eax
3f1: 83 c4 14 add $0x14,%esp
3f4: 5b pop %ebx
3f5: 5d pop %ebp
3f6: c3 ret
3f7: 89 f6 mov %esi,%esi
3f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000400 <backcmd>:
struct cmd*
backcmd(struct cmd *subcmd)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 53 push %ebx
404: 83 ec 14 sub $0x14,%esp
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
407: c7 04 24 08 00 00 00 movl $0x8,(%esp)
40e: e8 fd 0d 00 00 call 1210 <malloc>
memset(cmd, 0, sizeof(*cmd));
413: c7 44 24 08 08 00 00 movl $0x8,0x8(%esp)
41a: 00
41b: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
422: 00
struct cmd*
backcmd(struct cmd *subcmd)
{
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
423: 89 c3 mov %eax,%ebx
memset(cmd, 0, sizeof(*cmd));
425: 89 04 24 mov %eax,(%esp)
428: e8 d3 08 00 00 call d00 <memset>
cmd->type = BACK;
cmd->cmd = subcmd;
42d: 8b 45 08 mov 0x8(%ebp),%eax
{
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = BACK;
430: c7 03 05 00 00 00 movl $0x5,(%ebx)
cmd->cmd = subcmd;
436: 89 43 04 mov %eax,0x4(%ebx)
return (struct cmd*)cmd;
}
439: 89 d8 mov %ebx,%eax
43b: 83 c4 14 add $0x14,%esp
43e: 5b pop %ebx
43f: 5d pop %ebp
440: c3 ret
441: eb 0d jmp 450 <gettoken>
443: 90 nop
444: 90 nop
445: 90 nop
446: 90 nop
447: 90 nop
448: 90 nop
449: 90 nop
44a: 90 nop
44b: 90 nop
44c: 90 nop
44d: 90 nop
44e: 90 nop
44f: 90 nop
00000450 <gettoken>:
char whitespace[] = " \t\r\n\v";
char symbols[] = "<|>&;()";
int
gettoken(char **ps, char *es, char **q, char **eq)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 57 push %edi
454: 56 push %esi
455: 53 push %ebx
456: 83 ec 1c sub $0x1c,%esp
char *s;
int ret;
s = *ps;
459: 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)
{
45c: 8b 75 0c mov 0xc(%ebp),%esi
45f: 8b 7d 10 mov 0x10(%ebp),%edi
char *s;
int ret;
s = *ps;
462: 8b 18 mov (%eax),%ebx
while(s < es && strchr(whitespace, *s))
464: 39 f3 cmp %esi,%ebx
466: 72 0f jb 477 <gettoken+0x27>
468: eb 24 jmp 48e <gettoken+0x3e>
46a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
s++;
470: 83 c3 01 add $0x1,%ebx
{
char *s;
int ret;
s = *ps;
while(s < es && strchr(whitespace, *s))
473: 39 de cmp %ebx,%esi
475: 76 17 jbe 48e <gettoken+0x3e>
477: 0f be 03 movsbl (%ebx),%eax
47a: c7 04 24 10 14 00 00 movl $0x1410,(%esp)
481: 89 44 24 04 mov %eax,0x4(%esp)
485: e8 a6 08 00 00 call d30 <strchr>
48a: 85 c0 test %eax,%eax
48c: 75 e2 jne 470 <gettoken+0x20>
s++;
if(q)
48e: 85 ff test %edi,%edi
490: 74 02 je 494 <gettoken+0x44>
*q = s;
492: 89 1f mov %ebx,(%edi)
ret = *s;
494: 0f b6 13 movzbl (%ebx),%edx
497: 0f be fa movsbl %dl,%edi
switch(*s){
49a: 80 fa 3c cmp $0x3c,%dl
s = *ps;
while(s < es && strchr(whitespace, *s))
s++;
if(q)
*q = s;
ret = *s;
49d: 89 f8 mov %edi,%eax
switch(*s){
49f: 7f 4f jg 4f0 <gettoken+0xa0>
4a1: 80 fa 3b cmp $0x3b,%dl
4a4: 0f 8c 9e 00 00 00 jl 548 <gettoken+0xf8>
case '(':
case ')':
case ';':
case '&':
case '<':
s++;
4aa: 83 c3 01 add $0x1,%ebx
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
s++;
break;
}
if(eq)
4ad: 8b 45 14 mov 0x14(%ebp),%eax
4b0: 85 c0 test %eax,%eax
4b2: 74 05 je 4b9 <gettoken+0x69>
*eq = s;
4b4: 8b 45 14 mov 0x14(%ebp),%eax
4b7: 89 18 mov %ebx,(%eax)
while(s < es && strchr(whitespace, *s))
4b9: 39 f3 cmp %esi,%ebx
4bb: 72 0a jb 4c7 <gettoken+0x77>
4bd: eb 1f jmp 4de <gettoken+0x8e>
4bf: 90 nop
s++;
4c0: 83 c3 01 add $0x1,%ebx
break;
}
if(eq)
*eq = s;
while(s < es && strchr(whitespace, *s))
4c3: 39 de cmp %ebx,%esi
4c5: 76 17 jbe 4de <gettoken+0x8e>
4c7: 0f be 03 movsbl (%ebx),%eax
4ca: c7 04 24 10 14 00 00 movl $0x1410,(%esp)
4d1: 89 44 24 04 mov %eax,0x4(%esp)
4d5: e8 56 08 00 00 call d30 <strchr>
4da: 85 c0 test %eax,%eax
4dc: 75 e2 jne 4c0 <gettoken+0x70>
s++;
*ps = s;
4de: 8b 45 08 mov 0x8(%ebp),%eax
4e1: 89 18 mov %ebx,(%eax)
return ret;
}
4e3: 83 c4 1c add $0x1c,%esp
4e6: 89 f8 mov %edi,%eax
4e8: 5b pop %ebx
4e9: 5e pop %esi
4ea: 5f pop %edi
4eb: 5d pop %ebp
4ec: c3 ret
4ed: 8d 76 00 lea 0x0(%esi),%esi
while(s < es && strchr(whitespace, *s))
s++;
if(q)
*q = s;
ret = *s;
switch(*s){
4f0: 80 fa 3e cmp $0x3e,%dl
4f3: 74 73 je 568 <gettoken+0x118>
4f5: 80 fa 7c cmp $0x7c,%dl
4f8: 74 b0 je 4aa <gettoken+0x5a>
s++;
}
break;
default:
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
4fa: 39 de cmp %ebx,%esi
ret = '+';
s++;
}
break;
default:
ret = 'a';
4fc: bf 61 00 00 00 mov $0x61,%edi
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
501: 77 26 ja 529 <gettoken+0xd9>
503: eb a8 jmp 4ad <gettoken+0x5d>
505: 8d 76 00 lea 0x0(%esi),%esi
508: 0f be 03 movsbl (%ebx),%eax
50b: c7 04 24 16 14 00 00 movl $0x1416,(%esp)
512: 89 44 24 04 mov %eax,0x4(%esp)
516: e8 15 08 00 00 call d30 <strchr>
51b: 85 c0 test %eax,%eax
51d: 75 1e jne 53d <gettoken+0xed>
s++;
51f: 83 c3 01 add $0x1,%ebx
s++;
}
break;
default:
ret = 'a';
while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s))
522: 39 de cmp %ebx,%esi
524: 76 17 jbe 53d <gettoken+0xed>
526: 0f be 03 movsbl (%ebx),%eax
529: 89 44 24 04 mov %eax,0x4(%esp)
52d: c7 04 24 10 14 00 00 movl $0x1410,(%esp)
534: e8 f7 07 00 00 call d30 <strchr>
539: 85 c0 test %eax,%eax
53b: 74 cb je 508 <gettoken+0xb8>
ret = '+';
s++;
}
break;
default:
ret = 'a';
53d: bf 61 00 00 00 mov $0x61,%edi
542: e9 66 ff ff ff jmp 4ad <gettoken+0x5d>
547: 90 nop
while(s < es && strchr(whitespace, *s))
s++;
if(q)
*q = s;
ret = *s;
switch(*s){
548: 80 fa 29 cmp $0x29,%dl
54b: 7f ad jg 4fa <gettoken+0xaa>
54d: 80 fa 28 cmp $0x28,%dl
550: 0f 8d 54 ff ff ff jge 4aa <gettoken+0x5a>
556: 84 d2 test %dl,%dl
558: 0f 84 4f ff ff ff je 4ad <gettoken+0x5d>
55e: 80 fa 26 cmp $0x26,%dl
561: 75 97 jne 4fa <gettoken+0xaa>
563: e9 42 ff ff ff jmp 4aa <gettoken+0x5a>
case '&':
case '<':
s++;
break;
case '>':
s++;
568: 83 c3 01 add $0x1,%ebx
if(*s == '>'){
56b: 80 3b 3e cmpb $0x3e,(%ebx)
56e: 66 90 xchg %ax,%ax
570: 0f 85 37 ff ff ff jne 4ad <gettoken+0x5d>
ret = '+';
s++;
576: 83 c3 01 add $0x1,%ebx
s++;
break;
case '>':
s++;
if(*s == '>'){
ret = '+';
579: bf 2b 00 00 00 mov $0x2b,%edi
57e: e9 2a ff ff ff jmp 4ad <gettoken+0x5d>
583: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
589: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000590 <peek>:
return ret;
}
int
peek(char **ps, char *es, char *toks)
{
590: 55 push %ebp
591: 89 e5 mov %esp,%ebp
593: 57 push %edi
594: 56 push %esi
595: 53 push %ebx
596: 83 ec 1c sub $0x1c,%esp
599: 8b 7d 08 mov 0x8(%ebp),%edi
59c: 8b 75 0c mov 0xc(%ebp),%esi
char *s;
s = *ps;
59f: 8b 1f mov (%edi),%ebx
while(s < es && strchr(whitespace, *s))
5a1: 39 f3 cmp %esi,%ebx
5a3: 72 0a jb 5af <peek+0x1f>
5a5: eb 1f jmp 5c6 <peek+0x36>
5a7: 90 nop
s++;
5a8: 83 c3 01 add $0x1,%ebx
peek(char **ps, char *es, char *toks)
{
char *s;
s = *ps;
while(s < es && strchr(whitespace, *s))
5ab: 39 de cmp %ebx,%esi
5ad: 76 17 jbe 5c6 <peek+0x36>
5af: 0f be 03 movsbl (%ebx),%eax
5b2: c7 04 24 10 14 00 00 movl $0x1410,(%esp)
5b9: 89 44 24 04 mov %eax,0x4(%esp)
5bd: e8 6e 07 00 00 call d30 <strchr>
5c2: 85 c0 test %eax,%eax
5c4: 75 e2 jne 5a8 <peek+0x18>
s++;
*ps = s;
5c6: 89 1f mov %ebx,(%edi)
return *s && strchr(toks, *s);
5c8: 0f b6 13 movzbl (%ebx),%edx
5cb: 31 c0 xor %eax,%eax
5cd: 84 d2 test %dl,%dl
5cf: 75 0f jne 5e0 <peek+0x50>
}
5d1: 83 c4 1c add $0x1c,%esp
5d4: 5b pop %ebx
5d5: 5e pop %esi
5d6: 5f pop %edi
5d7: 5d pop %ebp
5d8: c3 ret
5d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = *ps;
while(s < es && strchr(whitespace, *s))
s++;
*ps = s;
return *s && strchr(toks, *s);
5e0: 8b 45 10 mov 0x10(%ebp),%eax
5e3: 0f be d2 movsbl %dl,%edx
5e6: 89 54 24 04 mov %edx,0x4(%esp)
5ea: 89 04 24 mov %eax,(%esp)
5ed: e8 3e 07 00 00 call d30 <strchr>
*ps = s;
return ret;
}
int
peek(char **ps, char *es, char *toks)