_sh: file format elf32-i386 Disassembly of section .text: 00000000
: return -1; } 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 push -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 13: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 17: 90 nop if (fd >= 3) { 18: 83 f8 02 cmp $0x2,%eax 1b: 0f 8f 01 01 00 00 jg 122 while ((fd = open("console", O_RDWR)) >= 0) { 21: 83 ec 08 sub $0x8,%esp 24: 6a 02 push $0x2 26: 68 99 13 00 00 push $0x1399 2b: e8 8b 0e 00 00 call ebb 30: 83 c4 10 add $0x10,%esp 33: 85 c0 test %eax,%eax 35: 79 e1 jns 18 37: eb 33 jmp 6c 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] == 'e' && buf[1] == 'x' && buf[2] == 'i' && buf[3] == 't') { exit(); } if (buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' ') { 40: 3c 63 cmp $0x63,%al 42: 75 0d jne 51 44: 80 3d 41 1a 00 00 64 cmpb $0x64,0x1a41 4b: 0f 84 7f 00 00 00 je d0 } int fork1(void) { int pid; pid = fork(); 51: e8 f5 0d 00 00 call e4b if (pid == -1) { 56: 83 f8 ff cmp $0xffffffff,%eax 59: 0f 84 e9 00 00 00 je 148 if (fork1() == 0) { 5f: 85 c0 test %eax,%eax 61: 0f 84 cc 00 00 00 je 133 wait(); 67: e8 ef 0d 00 00 call e5b printf(2, "$ "); 6c: 83 ec 08 sub $0x8,%esp 6f: 68 f8 12 00 00 push $0x12f8 74: 6a 02 push $0x2 76: e8 55 0f 00 00 call fd0 memset(buf, 0, nbuf); 7b: 83 c4 0c add $0xc,%esp 7e: 6a 64 push $0x64 80: 6a 00 push $0x0 82: 68 40 1a 00 00 push $0x1a40 87: e8 34 0c 00 00 call cc0 gets(buf, nbuf); 8c: 58 pop %eax 8d: 5a pop %edx 8e: 6a 64 push $0x64 90: 68 40 1a 00 00 push $0x1a40 95: e8 86 0c 00 00 call d20 if (buf[0] == 0) { // EOF 9a: 0f b6 05 40 1a 00 00 movzbl 0x1a40,%eax a1: 83 c4 10 add $0x10,%esp a4: 84 c0 test %al,%al a6: 74 1f je c7 if (buf[0] == 'e' && buf[1] == 'x' && buf[2] == 'i' && buf[3] == 't') { a8: 3c 65 cmp $0x65,%al aa: 75 94 jne 40 ac: 80 3d 41 1a 00 00 78 cmpb $0x78,0x1a41 b3: 75 9c jne 51 b5: 80 3d 42 1a 00 00 69 cmpb $0x69,0x1a42 bc: 75 93 jne 51 be: 80 3d 43 1a 00 00 74 cmpb $0x74,0x1a43 c5: 75 8a jne 51 exit(); c7: e8 87 0d 00 00 call e53 cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if (buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' ') { d0: 80 3d 42 1a 00 00 20 cmpb $0x20,0x1a42 d7: 0f 85 74 ff ff ff jne 51 buf[strlen(buf) - 1] = 0; // chop \n dd: 83 ec 0c sub $0xc,%esp e0: 68 40 1a 00 00 push $0x1a40 e5: e8 a6 0b 00 00 call c90 if (chdir(buf + 3) < 0) { ea: c7 04 24 43 1a 00 00 movl $0x1a43,(%esp) buf[strlen(buf) - 1] = 0; // chop \n f1: c6 80 3f 1a 00 00 00 movb $0x0,0x1a3f(%eax) if (chdir(buf + 3) < 0) { f8: e8 8e 0d 00 00 call e8b fd: 83 c4 10 add $0x10,%esp 100: 85 c0 test %eax,%eax 102: 0f 89 64 ff ff ff jns 6c printf(2, "cannot cd %s\n", buf + 3); 108: 51 push %ecx 109: 68 43 1a 00 00 push $0x1a43 10e: 68 a1 13 00 00 push $0x13a1 113: 6a 02 push $0x2 115: e8 b6 0e 00 00 call fd0 11a: 83 c4 10 add $0x10,%esp 11d: e9 4a ff ff ff jmp 6c close(fd); 122: 83 ec 0c sub $0xc,%esp 125: 50 push %eax 126: e8 c0 0d 00 00 call eeb break; 12b: 83 c4 10 add $0x10,%esp 12e: e9 39 ff ff ff jmp 6c runcmd(parsecmd(buf)); 133: 83 ec 0c sub $0xc,%esp 136: 68 40 1a 00 00 push $0x1a40 13b: e8 50 0a 00 00 call b90 140: 89 04 24 mov %eax,(%esp) 143: e8 98 00 00 00 call 1e0 panic("fork"); 148: 83 ec 0c sub $0xc,%esp 14b: 68 fb 12 00 00 push $0x12fb 150: e8 4b 00 00 00 call 1a0 155: 66 90 xchg %ax,%ax 157: 66 90 xchg %ax,%ax 159: 66 90 xchg %ax,%ax 15b: 66 90 xchg %ax,%ax 15d: 66 90 xchg %ax,%ax 15f: 90 nop 00000160 : int getcmd(char *buf, int nbuf) { 160: 55 push %ebp 161: 89 e5 mov %esp,%ebp 163: 56 push %esi 164: 53 push %ebx 165: 8b 75 0c mov 0xc(%ebp),%esi 168: 8b 5d 08 mov 0x8(%ebp),%ebx printf(2, "$ "); 16b: 83 ec 08 sub $0x8,%esp 16e: 68 f8 12 00 00 push $0x12f8 173: 6a 02 push $0x2 175: e8 56 0e 00 00 call fd0 memset(buf, 0, nbuf); 17a: 83 c4 0c add $0xc,%esp 17d: 56 push %esi 17e: 6a 00 push $0x0 180: 53 push %ebx 181: e8 3a 0b 00 00 call cc0 gets(buf, nbuf); 186: 58 pop %eax 187: 5a pop %edx 188: 56 push %esi 189: 53 push %ebx 18a: e8 91 0b 00 00 call d20 if (buf[0] == 0) { // EOF 18f: 83 c4 10 add $0x10,%esp 192: 80 3b 01 cmpb $0x1,(%ebx) 195: 19 c0 sbb %eax,%eax } 197: 8d 65 f8 lea -0x8(%ebp),%esp 19a: 5b pop %ebx 19b: 5e pop %esi 19c: 5d pop %ebp 19d: c3 ret 19e: 66 90 xchg %ax,%ax 000001a0 : void panic(char *s) { 1a0: 55 push %ebp 1a1: 89 e5 mov %esp,%ebp 1a3: 83 ec 0c sub $0xc,%esp printf(2, "%s\n", s); 1a6: ff 75 08 push 0x8(%ebp) 1a9: 68 95 13 00 00 push $0x1395 1ae: 6a 02 push $0x2 1b0: e8 1b 0e 00 00 call fd0 exit(); 1b5: e8 99 0c 00 00 call e53 1ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 000001c0 : int fork1(void) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 83 ec 08 sub $0x8,%esp pid = fork(); 1c6: e8 80 0c 00 00 call e4b if (pid == -1) { 1cb: 83 f8 ff cmp $0xffffffff,%eax 1ce: 74 02 je 1d2 } return pid; } 1d0: c9 leave 1d1: c3 ret panic("fork"); 1d2: 83 ec 0c sub $0xc,%esp 1d5: 68 fb 12 00 00 push $0x12fb 1da: e8 c1 ff ff ff call 1a0 1df: 90 nop 000001e0 : void runcmd(struct cmd *cmd) { 1e0: 55 push %ebp 1e1: 89 e5 mov %esp,%ebp 1e3: 53 push %ebx 1e4: 83 ec 14 sub $0x14,%esp 1e7: 8b 5d 08 mov 0x8(%ebp),%ebx if (cmd == 0) { 1ea: 85 db test %ebx,%ebx 1ec: 74 42 je 230 switch (cmd->type) { 1ee: 83 3b 05 cmpl $0x5,(%ebx) 1f1: 0f 87 e3 00 00 00 ja 2da 1f7: 8b 03 mov (%ebx),%eax 1f9: ff 24 85 b0 13 00 00 jmp *0x13b0(,%eax,4) if (ecmd->argv[0] == 0) { 200: 8b 43 04 mov 0x4(%ebx),%eax 203: 85 c0 test %eax,%eax 205: 74 29 je 230 exec(ecmd->argv[0], ecmd->argv); 207: 8d 53 04 lea 0x4(%ebx),%edx 20a: 51 push %ecx 20b: 51 push %ecx 20c: 52 push %edx 20d: 50 push %eax 20e: e8 68 0c 00 00 call e7b printf(2, "exec %s failed\n", ecmd->argv[0]); 213: 83 c4 0c add $0xc,%esp 216: ff 73 04 push 0x4(%ebx) 219: 68 07 13 00 00 push $0x1307 21e: 6a 02 push $0x2 220: e8 ab 0d 00 00 call fd0 break; 225: 83 c4 10 add $0x10,%esp 228: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 22f: 90 nop exit(); 230: e8 1e 0c 00 00 call e53 if (fork1() == 0) { 235: e8 86 ff ff ff call 1c0 23a: 85 c0 test %eax,%eax 23c: 75 f2 jne 230 23e: e9 8c 00 00 00 jmp 2cf if (pipe(p) < 0) { 243: 83 ec 0c sub $0xc,%esp 246: 8d 45 f0 lea -0x10(%ebp),%eax 249: 50 push %eax 24a: e8 14 0c 00 00 call e63 24f: 83 c4 10 add $0x10,%esp 252: 85 c0 test %eax,%eax 254: 0f 88 a2 00 00 00 js 2fc if (fork1() == 0) { 25a: e8 61 ff ff ff call 1c0 25f: 85 c0 test %eax,%eax 261: 0f 84 a2 00 00 00 je 309 if (fork1() == 0) { 267: e8 54 ff ff ff call 1c0 26c: 85 c0 test %eax,%eax 26e: 0f 84 c3 00 00 00 je 337 close(p[0]); 274: 83 ec 0c sub $0xc,%esp 277: ff 75 f0 push -0x10(%ebp) 27a: e8 6c 0c 00 00 call eeb close(p[1]); 27f: 58 pop %eax 280: ff 75 f4 push -0xc(%ebp) 283: e8 63 0c 00 00 call eeb wait(); 288: e8 ce 0b 00 00 call e5b wait(); 28d: e8 c9 0b 00 00 call e5b break; 292: 83 c4 10 add $0x10,%esp 295: eb 99 jmp 230 if (fork1() == 0) { 297: e8 24 ff ff ff call 1c0 29c: 85 c0 test %eax,%eax 29e: 74 2f je 2cf wait(); 2a0: e8 b6 0b 00 00 call e5b runcmd(lcmd->right); 2a5: 83 ec 0c sub $0xc,%esp 2a8: ff 73 08 push 0x8(%ebx) 2ab: e8 30 ff ff ff call 1e0 close(rcmd->fd); 2b0: 83 ec 0c sub $0xc,%esp 2b3: ff 73 14 push 0x14(%ebx) 2b6: e8 30 0c 00 00 call eeb if (open(rcmd->file, rcmd->mode) < 0) { 2bb: 58 pop %eax 2bc: 5a pop %edx 2bd: ff 73 10 push 0x10(%ebx) 2c0: ff 73 08 push 0x8(%ebx) 2c3: e8 f3 0b 00 00 call ebb 2c8: 83 c4 10 add $0x10,%esp 2cb: 85 c0 test %eax,%eax 2cd: 78 18 js 2e7 runcmd(bcmd->cmd); 2cf: 83 ec 0c sub $0xc,%esp 2d2: ff 73 04 push 0x4(%ebx) 2d5: e8 06 ff ff ff call 1e0 panic("runcmd"); 2da: 83 ec 0c sub $0xc,%esp 2dd: 68 00 13 00 00 push $0x1300 2e2: e8 b9 fe ff ff call 1a0 printf(2, "open %s failed\n", rcmd->file); 2e7: 51 push %ecx 2e8: ff 73 08 push 0x8(%ebx) 2eb: 68 17 13 00 00 push $0x1317 2f0: 6a 02 push $0x2 2f2: e8 d9 0c 00 00 call fd0 exit(); 2f7: e8 57 0b 00 00 call e53 panic("pipe"); 2fc: 83 ec 0c sub $0xc,%esp 2ff: 68 27 13 00 00 push $0x1327 304: e8 97 fe ff ff call 1a0 close(1); 309: 83 ec 0c sub $0xc,%esp 30c: 6a 01 push $0x1 30e: e8 d8 0b 00 00 call eeb dup(p[1]); 313: 58 pop %eax 314: ff 75 f4 push -0xc(%ebp) 317: e8 77 0b 00 00 call e93 close(p[0]); 31c: 58 pop %eax 31d: ff 75 f0 push -0x10(%ebp) 320: e8 c6 0b 00 00 call eeb close(p[1]); 325: 58 pop %eax 326: ff 75 f4 push -0xc(%ebp) 329: e8 bd 0b 00 00 call eeb runcmd(pcmd->left); 32e: 5a pop %edx 32f: ff 73 04 push 0x4(%ebx) 332: e8 a9 fe ff ff call 1e0 close(0); 337: 83 ec 0c sub $0xc,%esp 33a: 6a 00 push $0x0 33c: e8 aa 0b 00 00 call eeb dup(p[0]); 341: 5a pop %edx 342: ff 75 f0 push -0x10(%ebp) 345: e8 49 0b 00 00 call e93 close(p[0]); 34a: 59 pop %ecx 34b: ff 75 f0 push -0x10(%ebp) 34e: e8 98 0b 00 00 call eeb close(p[1]); 353: 58 pop %eax 354: ff 75 f4 push -0xc(%ebp) 357: e8 8f 0b 00 00 call eeb runcmd(pcmd->right); 35c: 58 pop %eax 35d: ff 73 08 push 0x8(%ebx) 360: e8 7b fe ff ff call 1e0 365: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 36c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000370 : // Constructors struct cmd* execcmd(void) { 370: 55 push %ebp 371: 89 e5 mov %esp,%ebp 373: 53 push %ebx 374: 83 ec 10 sub $0x10,%esp struct execcmd *cmd; cmd = malloc(sizeof(*cmd)); 377: 6a 54 push $0x54 379: e8 82 0e 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 37e: 83 c4 0c add $0xc,%esp 381: 6a 54 push $0x54 cmd = malloc(sizeof(*cmd)); 383: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 385: 6a 00 push $0x0 387: 50 push %eax 388: e8 33 09 00 00 call cc0 cmd->type = EXEC; 38d: c7 03 01 00 00 00 movl $0x1,(%ebx) return (struct cmd*)cmd; } 393: 89 d8 mov %ebx,%eax 395: 8b 5d fc mov -0x4(%ebp),%ebx 398: c9 leave 399: c3 ret 39a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 000003a0 : struct cmd* redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd) { 3a0: 55 push %ebp 3a1: 89 e5 mov %esp,%ebp 3a3: 53 push %ebx 3a4: 83 ec 10 sub $0x10,%esp struct redircmd *cmd; cmd = malloc(sizeof(*cmd)); 3a7: 6a 18 push $0x18 3a9: e8 52 0e 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 3ae: 83 c4 0c add $0xc,%esp 3b1: 6a 18 push $0x18 cmd = malloc(sizeof(*cmd)); 3b3: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 3b5: 6a 00 push $0x0 3b7: 50 push %eax 3b8: e8 03 09 00 00 call cc0 cmd->type = REDIR; cmd->cmd = subcmd; 3bd: 8b 45 08 mov 0x8(%ebp),%eax cmd->type = REDIR; 3c0: c7 03 02 00 00 00 movl $0x2,(%ebx) cmd->cmd = subcmd; 3c6: 89 43 04 mov %eax,0x4(%ebx) cmd->file = file; 3c9: 8b 45 0c mov 0xc(%ebp),%eax 3cc: 89 43 08 mov %eax,0x8(%ebx) cmd->efile = efile; 3cf: 8b 45 10 mov 0x10(%ebp),%eax 3d2: 89 43 0c mov %eax,0xc(%ebx) cmd->mode = mode; 3d5: 8b 45 14 mov 0x14(%ebp),%eax 3d8: 89 43 10 mov %eax,0x10(%ebx) cmd->fd = fd; 3db: 8b 45 18 mov 0x18(%ebp),%eax 3de: 89 43 14 mov %eax,0x14(%ebx) return (struct cmd*)cmd; } 3e1: 89 d8 mov %ebx,%eax 3e3: 8b 5d fc mov -0x4(%ebp),%ebx 3e6: c9 leave 3e7: c3 ret 3e8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3ef: 90 nop 000003f0 : struct cmd* pipecmd(struct cmd *left, struct cmd *right) { 3f0: 55 push %ebp 3f1: 89 e5 mov %esp,%ebp 3f3: 53 push %ebx 3f4: 83 ec 10 sub $0x10,%esp struct pipecmd *cmd; cmd = malloc(sizeof(*cmd)); 3f7: 6a 0c push $0xc 3f9: e8 02 0e 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 3fe: 83 c4 0c add $0xc,%esp 401: 6a 0c push $0xc cmd = malloc(sizeof(*cmd)); 403: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 405: 6a 00 push $0x0 407: 50 push %eax 408: e8 b3 08 00 00 call cc0 cmd->type = PIPE; cmd->left = left; 40d: 8b 45 08 mov 0x8(%ebp),%eax cmd->type = PIPE; 410: c7 03 03 00 00 00 movl $0x3,(%ebx) cmd->left = left; 416: 89 43 04 mov %eax,0x4(%ebx) cmd->right = right; 419: 8b 45 0c mov 0xc(%ebp),%eax 41c: 89 43 08 mov %eax,0x8(%ebx) return (struct cmd*)cmd; } 41f: 89 d8 mov %ebx,%eax 421: 8b 5d fc mov -0x4(%ebp),%ebx 424: c9 leave 425: c3 ret 426: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 42d: 8d 76 00 lea 0x0(%esi),%esi 00000430 : struct cmd* listcmd(struct cmd *left, struct cmd *right) { 430: 55 push %ebp 431: 89 e5 mov %esp,%ebp 433: 53 push %ebx 434: 83 ec 10 sub $0x10,%esp struct listcmd *cmd; cmd = malloc(sizeof(*cmd)); 437: 6a 0c push $0xc 439: e8 c2 0d 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 43e: 83 c4 0c add $0xc,%esp 441: 6a 0c push $0xc cmd = malloc(sizeof(*cmd)); 443: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 445: 6a 00 push $0x0 447: 50 push %eax 448: e8 73 08 00 00 call cc0 cmd->type = LIST; cmd->left = left; 44d: 8b 45 08 mov 0x8(%ebp),%eax cmd->type = LIST; 450: c7 03 04 00 00 00 movl $0x4,(%ebx) cmd->left = left; 456: 89 43 04 mov %eax,0x4(%ebx) cmd->right = right; 459: 8b 45 0c mov 0xc(%ebp),%eax 45c: 89 43 08 mov %eax,0x8(%ebx) return (struct cmd*)cmd; } 45f: 89 d8 mov %ebx,%eax 461: 8b 5d fc mov -0x4(%ebp),%ebx 464: c9 leave 465: c3 ret 466: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 46d: 8d 76 00 lea 0x0(%esi),%esi 00000470 : struct cmd* backcmd(struct cmd *subcmd) { 470: 55 push %ebp 471: 89 e5 mov %esp,%ebp 473: 53 push %ebx 474: 83 ec 10 sub $0x10,%esp struct backcmd *cmd; cmd = malloc(sizeof(*cmd)); 477: 6a 08 push $0x8 479: e8 82 0d 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 47e: 83 c4 0c add $0xc,%esp 481: 6a 08 push $0x8 cmd = malloc(sizeof(*cmd)); 483: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 485: 6a 00 push $0x0 487: 50 push %eax 488: e8 33 08 00 00 call cc0 cmd->type = BACK; cmd->cmd = subcmd; 48d: 8b 45 08 mov 0x8(%ebp),%eax cmd->type = BACK; 490: c7 03 05 00 00 00 movl $0x5,(%ebx) cmd->cmd = subcmd; 496: 89 43 04 mov %eax,0x4(%ebx) return (struct cmd*)cmd; } 499: 89 d8 mov %ebx,%eax 49b: 8b 5d fc mov -0x4(%ebp),%ebx 49e: c9 leave 49f: c3 ret 000004a0 : // Parsing char whitespace[] = " \t\r\n\v"; char symbols[] = "<|>&;()"; int gettoken(char **ps, char *es, char **q, char **eq) { 4a0: 55 push %ebp 4a1: 89 e5 mov %esp,%ebp 4a3: 57 push %edi 4a4: 56 push %esi 4a5: 53 push %ebx 4a6: 83 ec 0c sub $0xc,%esp char *s; int ret; s = *ps; 4a9: 8b 45 08 mov 0x8(%ebp),%eax int gettoken(char **ps, char *es, char **q, char **eq) { 4ac: 8b 5d 0c mov 0xc(%ebp),%ebx 4af: 8b 75 10 mov 0x10(%ebp),%esi s = *ps; 4b2: 8b 38 mov (%eax),%edi while (s < es && strchr(whitespace, *s)) { 4b4: 39 df cmp %ebx,%edi 4b6: 72 0f jb 4c7 4b8: eb 25 jmp 4df 4ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi s++; 4c0: 83 c7 01 add $0x1,%edi while (s < es && strchr(whitespace, *s)) { 4c3: 39 fb cmp %edi,%ebx 4c5: 74 18 je 4df 4c7: 0f be 07 movsbl (%edi),%eax 4ca: 83 ec 08 sub $0x8,%esp 4cd: 50 push %eax 4ce: 68 1c 1a 00 00 push $0x1a1c 4d3: e8 08 08 00 00 call ce0 4d8: 83 c4 10 add $0x10,%esp 4db: 85 c0 test %eax,%eax 4dd: 75 e1 jne 4c0 } if (q) { 4df: 85 f6 test %esi,%esi 4e1: 74 02 je 4e5 *q = s; 4e3: 89 3e mov %edi,(%esi) } ret = *s; 4e5: 0f b6 07 movzbl (%edi),%eax switch (*s) { 4e8: 3c 3c cmp $0x3c,%al 4ea: 0f 8f d0 00 00 00 jg 5c0 4f0: 3c 3a cmp $0x3a,%al 4f2: 0f 8f b4 00 00 00 jg 5ac 4f8: 84 c0 test %al,%al 4fa: 75 44 jne 540 4fc: 31 f6 xor %esi,%esi while (s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) { s++; } break; } if (eq) { 4fe: 8b 55 14 mov 0x14(%ebp),%edx 501: 85 d2 test %edx,%edx 503: 74 05 je 50a *eq = s; 505: 8b 45 14 mov 0x14(%ebp),%eax 508: 89 38 mov %edi,(%eax) } while (s < es && strchr(whitespace, *s)) { 50a: 39 df cmp %ebx,%edi 50c: 72 09 jb 517 50e: eb 1f jmp 52f s++; 510: 83 c7 01 add $0x1,%edi while (s < es && strchr(whitespace, *s)) { 513: 39 fb cmp %edi,%ebx 515: 74 18 je 52f 517: 0f be 07 movsbl (%edi),%eax 51a: 83 ec 08 sub $0x8,%esp 51d: 50 push %eax 51e: 68 1c 1a 00 00 push $0x1a1c 523: e8 b8 07 00 00 call ce0 528: 83 c4 10 add $0x10,%esp 52b: 85 c0 test %eax,%eax 52d: 75 e1 jne 510 } *ps = s; 52f: 8b 45 08 mov 0x8(%ebp),%eax 532: 89 38 mov %edi,(%eax) return ret; } 534: 8d 65 f4 lea -0xc(%ebp),%esp 537: 89 f0 mov %esi,%eax 539: 5b pop %ebx 53a: 5e pop %esi 53b: 5f pop %edi 53c: 5d pop %ebp 53d: c3 ret 53e: 66 90 xchg %ax,%ax switch (*s) { 540: 79 5e jns 5a0 while (s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) { 542: 39 fb cmp %edi,%ebx 544: 77 34 ja 57a if (eq) { 546: 8b 45 14 mov 0x14(%ebp),%eax 549: be 61 00 00 00 mov $0x61,%esi 54e: 85 c0 test %eax,%eax 550: 75 b3 jne 505 552: eb db jmp 52f 554: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while (s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) { 558: 0f be 07 movsbl (%edi),%eax 55b: 83 ec 08 sub $0x8,%esp 55e: 50 push %eax 55f: 68 14 1a 00 00 push $0x1a14 564: e8 77 07 00 00 call ce0 569: 83 c4 10 add $0x10,%esp 56c: 85 c0 test %eax,%eax 56e: 75 22 jne 592 s++; 570: 83 c7 01 add $0x1,%edi while (s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) { 573: 39 fb cmp %edi,%ebx 575: 74 cf je 546 577: 0f b6 07 movzbl (%edi),%eax 57a: 83 ec 08 sub $0x8,%esp 57d: 0f be f0 movsbl %al,%esi 580: 56 push %esi 581: 68 1c 1a 00 00 push $0x1a1c 586: e8 55 07 00 00 call ce0 58b: 83 c4 10 add $0x10,%esp 58e: 85 c0 test %eax,%eax 590: 74 c6 je 558 ret = 'a'; 592: be 61 00 00 00 mov $0x61,%esi 597: e9 62 ff ff ff jmp 4fe 59c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi switch (*s) { 5a0: 3c 26 cmp $0x26,%al 5a2: 74 08 je 5ac 5a4: 8d 48 d8 lea -0x28(%eax),%ecx 5a7: 80 f9 01 cmp $0x1,%cl 5aa: 77 96 ja 542 ret = *s; 5ac: 0f be f0 movsbl %al,%esi s++; 5af: 83 c7 01 add $0x1,%edi break; 5b2: e9 47 ff ff ff jmp 4fe 5b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5be: 66 90 xchg %ax,%ax switch (*s) { 5c0: 3c 3e cmp $0x3e,%al 5c2: 75 1c jne 5e0 if (*s == '>') { 5c4: 80 7f 01 3e cmpb $0x3e,0x1(%edi) s++; 5c8: 8d 47 01 lea 0x1(%edi),%eax if (*s == '>') { 5cb: 74 1c je 5e9 s++; 5cd: 89 c7 mov %eax,%edi 5cf: be 3e 00 00 00 mov $0x3e,%esi 5d4: e9 25 ff ff ff jmp 4fe 5d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi switch (*s) { 5e0: 3c 7c cmp $0x7c,%al 5e2: 74 c8 je 5ac 5e4: e9 59 ff ff ff jmp 542 s++; 5e9: 83 c7 02 add $0x2,%edi ret = '+'; 5ec: be 2b 00 00 00 mov $0x2b,%esi 5f1: e9 08 ff ff ff jmp 4fe 5f6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5fd: 8d 76 00 lea 0x0(%esi),%esi 00000600 : int peek(char **ps, char *es, char *toks) { 600: 55 push %ebp 601: 89 e5 mov %esp,%ebp 603: 57 push %edi 604: 56 push %esi 605: 53 push %ebx 606: 83 ec 0c sub $0xc,%esp 609: 8b 7d 08 mov 0x8(%ebp),%edi 60c: 8b 75 0c mov 0xc(%ebp),%esi char *s; s = *ps; 60f: 8b 1f mov (%edi),%ebx while (s < es && strchr(whitespace, *s)) { 611: 39 f3 cmp %esi,%ebx 613: 72 12 jb 627 615: eb 28 jmp 63f 617: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 61e: 66 90 xchg %ax,%ax s++; 620: 83 c3 01 add $0x1,%ebx while (s < es && strchr(whitespace, *s)) { 623: 39 de cmp %ebx,%esi 625: 74 18 je 63f 627: 0f be 03 movsbl (%ebx),%eax 62a: 83 ec 08 sub $0x8,%esp 62d: 50 push %eax 62e: 68 1c 1a 00 00 push $0x1a1c 633: e8 a8 06 00 00 call ce0 638: 83 c4 10 add $0x10,%esp 63b: 85 c0 test %eax,%eax 63d: 75 e1 jne 620 } *ps = s; 63f: 89 1f mov %ebx,(%edi) return *s && strchr(toks, *s); 641: 0f be 03 movsbl (%ebx),%eax 644: 31 d2 xor %edx,%edx 646: 84 c0 test %al,%al 648: 75 0e jne 658 } 64a: 8d 65 f4 lea -0xc(%ebp),%esp 64d: 89 d0 mov %edx,%eax 64f: 5b pop %ebx 650: 5e pop %esi 651: 5f pop %edi 652: 5d pop %ebp 653: c3 ret 654: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi return *s && strchr(toks, *s); 658: 83 ec 08 sub $0x8,%esp 65b: 50 push %eax 65c: ff 75 10 push 0x10(%ebp) 65f: e8 7c 06 00 00 call ce0 664: 83 c4 10 add $0x10,%esp 667: 31 d2 xor %edx,%edx 669: 85 c0 test %eax,%eax 66b: 0f 95 c2 setne %dl } 66e: 8d 65 f4 lea -0xc(%ebp),%esp 671: 5b pop %ebx 672: 89 d0 mov %edx,%eax 674: 5e pop %esi 675: 5f pop %edi 676: 5d pop %ebp 677: c3 ret 678: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 67f: 90 nop 00000680 : cmd = pipecmd(cmd, parsepipe(ps, es)); } return cmd; } struct cmd* parseredirs(struct cmd *cmd, char **ps, char *es) { 680: 55 push %ebp 681: 89 e5 mov %esp,%ebp 683: 57 push %edi 684: 56 push %esi 685: 53 push %ebx 686: 83 ec 2c sub $0x2c,%esp 689: 8b 75 0c mov 0xc(%ebp),%esi 68c: 8b 5d 10 mov 0x10(%ebp),%ebx int tok; char *q, *eq; while (peek(ps, es, "<>")) { 68f: 90 nop 690: 83 ec 04 sub $0x4,%esp 693: 68 49 13 00 00 push $0x1349 698: 53 push %ebx 699: 56 push %esi 69a: e8 61 ff ff ff call 600 69f: 83 c4 10 add $0x10,%esp 6a2: 85 c0 test %eax,%eax 6a4: 0f 84 f6 00 00 00 je 7a0 tok = gettoken(ps, es, 0, 0); 6aa: 6a 00 push $0x0 6ac: 6a 00 push $0x0 6ae: 53 push %ebx 6af: 56 push %esi 6b0: e8 eb fd ff ff call 4a0 6b5: 89 c7 mov %eax,%edi if (gettoken(ps, es, &q, &eq) != 'a') { 6b7: 8d 45 e4 lea -0x1c(%ebp),%eax 6ba: 50 push %eax 6bb: 8d 45 e0 lea -0x20(%ebp),%eax 6be: 50 push %eax 6bf: 53 push %ebx 6c0: 56 push %esi 6c1: e8 da fd ff ff call 4a0 6c6: 83 c4 20 add $0x20,%esp 6c9: 83 f8 61 cmp $0x61,%eax 6cc: 0f 85 d9 00 00 00 jne 7ab panic("missing file for redirection"); } switch (tok) { 6d2: 83 ff 3c cmp $0x3c,%edi 6d5: 74 69 je 740 6d7: 83 ff 3e cmp $0x3e,%edi 6da: 74 05 je 6e1 6dc: 83 ff 2b cmp $0x2b,%edi 6df: 75 af jne 690 cmd = malloc(sizeof(*cmd)); 6e1: 83 ec 0c sub $0xc,%esp break; case '>': cmd = redircmd(cmd, q, eq, O_WRONLY | O_CREATE, 1); break; case '+': // >> cmd = redircmd(cmd, q, eq, O_WRONLY | O_CREATE, 1); 6e4: 8b 55 e4 mov -0x1c(%ebp),%edx 6e7: 8b 4d e0 mov -0x20(%ebp),%ecx cmd = malloc(sizeof(*cmd)); 6ea: 6a 18 push $0x18 cmd = redircmd(cmd, q, eq, O_WRONLY | O_CREATE, 1); 6ec: 89 55 d0 mov %edx,-0x30(%ebp) 6ef: 89 4d d4 mov %ecx,-0x2c(%ebp) cmd = malloc(sizeof(*cmd)); 6f2: e8 09 0b 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 6f7: 83 c4 0c add $0xc,%esp 6fa: 6a 18 push $0x18 cmd = malloc(sizeof(*cmd)); 6fc: 89 c7 mov %eax,%edi memset(cmd, 0, sizeof(*cmd)); 6fe: 6a 00 push $0x0 700: 50 push %eax 701: e8 ba 05 00 00 call cc0 cmd->type = REDIR; 706: c7 07 02 00 00 00 movl $0x2,(%edi) cmd->cmd = subcmd; 70c: 8b 45 08 mov 0x8(%ebp),%eax break; 70f: 83 c4 10 add $0x10,%esp cmd->cmd = subcmd; 712: 89 47 04 mov %eax,0x4(%edi) cmd->file = file; 715: 8b 4d d4 mov -0x2c(%ebp),%ecx 718: 89 4f 08 mov %ecx,0x8(%edi) cmd->efile = efile; 71b: 8b 55 d0 mov -0x30(%ebp),%edx cmd->mode = mode; 71e: c7 47 10 01 02 00 00 movl $0x201,0x10(%edi) cmd->efile = efile; 725: 89 57 0c mov %edx,0xc(%edi) cmd->fd = fd; 728: c7 47 14 01 00 00 00 movl $0x1,0x14(%edi) break; 72f: 89 7d 08 mov %edi,0x8(%ebp) 732: e9 59 ff ff ff jmp 690 737: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 73e: 66 90 xchg %ax,%ax cmd = malloc(sizeof(*cmd)); 740: 83 ec 0c sub $0xc,%esp cmd = redircmd(cmd, q, eq, O_RDONLY, 0); 743: 8b 55 e4 mov -0x1c(%ebp),%edx 746: 8b 4d e0 mov -0x20(%ebp),%ecx cmd = malloc(sizeof(*cmd)); 749: 6a 18 push $0x18 cmd = redircmd(cmd, q, eq, O_RDONLY, 0); 74b: 89 55 d0 mov %edx,-0x30(%ebp) 74e: 89 4d d4 mov %ecx,-0x2c(%ebp) cmd = malloc(sizeof(*cmd)); 751: e8 aa 0a 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 756: 83 c4 0c add $0xc,%esp 759: 6a 18 push $0x18 cmd = malloc(sizeof(*cmd)); 75b: 89 c7 mov %eax,%edi memset(cmd, 0, sizeof(*cmd)); 75d: 6a 00 push $0x0 75f: 50 push %eax 760: e8 5b 05 00 00 call cc0 cmd->cmd = subcmd; 765: 8b 45 08 mov 0x8(%ebp),%eax cmd->file = file; 768: 8b 4d d4 mov -0x2c(%ebp),%ecx break; 76b: 89 7d 08 mov %edi,0x8(%ebp) cmd->efile = efile; 76e: 8b 55 d0 mov -0x30(%ebp),%edx cmd->type = REDIR; 771: c7 07 02 00 00 00 movl $0x2,(%edi) break; 777: 83 c4 10 add $0x10,%esp cmd->cmd = subcmd; 77a: 89 47 04 mov %eax,0x4(%edi) cmd->file = file; 77d: 89 4f 08 mov %ecx,0x8(%edi) cmd->efile = efile; 780: 89 57 0c mov %edx,0xc(%edi) cmd->mode = mode; 783: c7 47 10 00 00 00 00 movl $0x0,0x10(%edi) cmd->fd = fd; 78a: c7 47 14 00 00 00 00 movl $0x0,0x14(%edi) break; 791: e9 fa fe ff ff jmp 690 796: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 79d: 8d 76 00 lea 0x0(%esi),%esi } } return cmd; } 7a0: 8b 45 08 mov 0x8(%ebp),%eax 7a3: 8d 65 f4 lea -0xc(%ebp),%esp 7a6: 5b pop %ebx 7a7: 5e pop %esi 7a8: 5f pop %edi 7a9: 5d pop %ebp 7aa: c3 ret panic("missing file for redirection"); 7ab: 83 ec 0c sub $0xc,%esp 7ae: 68 2c 13 00 00 push $0x132c 7b3: e8 e8 f9 ff ff call 1a0 7b8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 7bf: 90 nop 000007c0 : gettoken(ps, es, 0, 0); cmd = parseredirs(cmd, ps, es); return cmd; } struct cmd* parseexec(char **ps, char *es) { 7c0: 55 push %ebp 7c1: 89 e5 mov %esp,%ebp 7c3: 57 push %edi 7c4: 56 push %esi 7c5: 53 push %ebx 7c6: 83 ec 30 sub $0x30,%esp 7c9: 8b 75 08 mov 0x8(%ebp),%esi 7cc: 8b 7d 0c mov 0xc(%ebp),%edi char *q, *eq; int tok, argc; struct execcmd *cmd; struct cmd *ret; if (peek(ps, es, "(")) { 7cf: 68 4c 13 00 00 push $0x134c 7d4: 57 push %edi 7d5: 56 push %esi 7d6: e8 25 fe ff ff call 600 7db: 83 c4 10 add $0x10,%esp 7de: 85 c0 test %eax,%eax 7e0: 0f 85 aa 00 00 00 jne 890 cmd = malloc(sizeof(*cmd)); 7e6: 83 ec 0c sub $0xc,%esp 7e9: 89 c3 mov %eax,%ebx 7eb: 6a 54 push $0x54 7ed: e8 0e 0a 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 7f2: 83 c4 0c add $0xc,%esp 7f5: 6a 54 push $0x54 7f7: 6a 00 push $0x0 7f9: 50 push %eax 7fa: 89 45 d0 mov %eax,-0x30(%ebp) 7fd: e8 be 04 00 00 call cc0 cmd->type = EXEC; 802: 8b 45 d0 mov -0x30(%ebp),%eax ret = execcmd(); cmd = (struct execcmd*)ret; argc = 0; ret = parseredirs(ret, ps, es); 805: 83 c4 0c add $0xc,%esp cmd->type = EXEC; 808: c7 00 01 00 00 00 movl $0x1,(%eax) ret = parseredirs(ret, ps, es); 80e: 57 push %edi 80f: 56 push %esi 810: 50 push %eax 811: e8 6a fe ff ff call 680 while (!peek(ps, es, "|)&;")) { 816: 83 c4 10 add $0x10,%esp ret = parseredirs(ret, ps, es); 819: 89 45 d4 mov %eax,-0x2c(%ebp) while (!peek(ps, es, "|)&;")) { 81c: eb 15 jmp 833 81e: 66 90 xchg %ax,%ax cmd->eargv[argc] = eq; argc++; if (argc >= MAXARGS) { panic("too many args"); } ret = parseredirs(ret, ps, es); 820: 83 ec 04 sub $0x4,%esp 823: 57 push %edi 824: 56 push %esi 825: ff 75 d4 push -0x2c(%ebp) 828: e8 53 fe ff ff call 680 82d: 83 c4 10 add $0x10,%esp 830: 89 45 d4 mov %eax,-0x2c(%ebp) while (!peek(ps, es, "|)&;")) { 833: 83 ec 04 sub $0x4,%esp 836: 68 63 13 00 00 push $0x1363 83b: 57 push %edi 83c: 56 push %esi 83d: e8 be fd ff ff call 600 842: 83 c4 10 add $0x10,%esp 845: 85 c0 test %eax,%eax 847: 75 5f jne 8a8 if ((tok = gettoken(ps, es, &q, &eq)) == 0) { 849: 8d 45 e4 lea -0x1c(%ebp),%eax 84c: 50 push %eax 84d: 8d 45 e0 lea -0x20(%ebp),%eax 850: 50 push %eax 851: 57 push %edi 852: 56 push %esi 853: e8 48 fc ff ff call 4a0 858: 83 c4 10 add $0x10,%esp 85b: 85 c0 test %eax,%eax 85d: 74 49 je 8a8 if (tok != 'a') { 85f: 83 f8 61 cmp $0x61,%eax 862: 75 62 jne 8c6 cmd->argv[argc] = q; 864: 8b 45 e0 mov -0x20(%ebp),%eax 867: 8b 55 d0 mov -0x30(%ebp),%edx 86a: 89 44 9a 04 mov %eax,0x4(%edx,%ebx,4) cmd->eargv[argc] = eq; 86e: 8b 45 e4 mov -0x1c(%ebp),%eax 871: 89 44 9a 2c mov %eax,0x2c(%edx,%ebx,4) argc++; 875: 83 c3 01 add $0x1,%ebx if (argc >= MAXARGS) { 878: 83 fb 0a cmp $0xa,%ebx 87b: 75 a3 jne 820 panic("too many args"); 87d: 83 ec 0c sub $0xc,%esp 880: 68 55 13 00 00 push $0x1355 885: e8 16 f9 ff ff call 1a0 88a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi return parseblock(ps, es); 890: 89 7d 0c mov %edi,0xc(%ebp) 893: 89 75 08 mov %esi,0x8(%ebp) } cmd->argv[argc] = 0; cmd->eargv[argc] = 0; return ret; } 896: 8d 65 f4 lea -0xc(%ebp),%esp 899: 5b pop %ebx 89a: 5e pop %esi 89b: 5f pop %edi 89c: 5d pop %ebp return parseblock(ps, es); 89d: e9 ae 01 00 00 jmp a50 8a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cmd->argv[argc] = 0; 8a8: 8b 45 d0 mov -0x30(%ebp),%eax 8ab: c7 44 98 04 00 00 00 movl $0x0,0x4(%eax,%ebx,4) 8b2: 00 cmd->eargv[argc] = 0; 8b3: c7 44 98 2c 00 00 00 movl $0x0,0x2c(%eax,%ebx,4) 8ba: 00 } 8bb: 8b 45 d4 mov -0x2c(%ebp),%eax 8be: 8d 65 f4 lea -0xc(%ebp),%esp 8c1: 5b pop %ebx 8c2: 5e pop %esi 8c3: 5f pop %edi 8c4: 5d pop %ebp 8c5: c3 ret panic("syntax"); 8c6: 83 ec 0c sub $0xc,%esp 8c9: 68 4e 13 00 00 push $0x134e 8ce: e8 cd f8 ff ff call 1a0 8d3: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 8da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 000008e0 : struct cmd* parsepipe(char **ps, char *es) { 8e0: 55 push %ebp 8e1: 89 e5 mov %esp,%ebp 8e3: 57 push %edi 8e4: 56 push %esi 8e5: 53 push %ebx 8e6: 83 ec 14 sub $0x14,%esp 8e9: 8b 75 08 mov 0x8(%ebp),%esi 8ec: 8b 7d 0c mov 0xc(%ebp),%edi cmd = parseexec(ps, es); 8ef: 57 push %edi 8f0: 56 push %esi 8f1: e8 ca fe ff ff call 7c0 if (peek(ps, es, "|")) { 8f6: 83 c4 0c add $0xc,%esp 8f9: 68 68 13 00 00 push $0x1368 cmd = parseexec(ps, es); 8fe: 89 c3 mov %eax,%ebx if (peek(ps, es, "|")) { 900: 57 push %edi 901: 56 push %esi 902: e8 f9 fc ff ff call 600 907: 83 c4 10 add $0x10,%esp 90a: 85 c0 test %eax,%eax 90c: 75 12 jne 920 } 90e: 8d 65 f4 lea -0xc(%ebp),%esp 911: 89 d8 mov %ebx,%eax 913: 5b pop %ebx 914: 5e pop %esi 915: 5f pop %edi 916: 5d pop %ebp 917: c3 ret 918: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 91f: 90 nop gettoken(ps, es, 0, 0); 920: 6a 00 push $0x0 922: 6a 00 push $0x0 924: 57 push %edi 925: 56 push %esi 926: e8 75 fb ff ff call 4a0 cmd = pipecmd(cmd, parsepipe(ps, es)); 92b: 58 pop %eax 92c: 5a pop %edx 92d: 57 push %edi 92e: 56 push %esi 92f: e8 ac ff ff ff call 8e0 cmd = malloc(sizeof(*cmd)); 934: c7 04 24 0c 00 00 00 movl $0xc,(%esp) cmd = pipecmd(cmd, parsepipe(ps, es)); 93b: 89 c7 mov %eax,%edi cmd = malloc(sizeof(*cmd)); 93d: e8 be 08 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 942: 83 c4 0c add $0xc,%esp 945: 6a 0c push $0xc cmd = malloc(sizeof(*cmd)); 947: 89 c6 mov %eax,%esi memset(cmd, 0, sizeof(*cmd)); 949: 6a 00 push $0x0 94b: 50 push %eax 94c: e8 6f 03 00 00 call cc0 cmd->left = left; 951: 89 5e 04 mov %ebx,0x4(%esi) cmd->right = right; 954: 83 c4 10 add $0x10,%esp 957: 89 f3 mov %esi,%ebx cmd->type = PIPE; 959: c7 06 03 00 00 00 movl $0x3,(%esi) } 95f: 89 d8 mov %ebx,%eax cmd->right = right; 961: 89 7e 08 mov %edi,0x8(%esi) } 964: 8d 65 f4 lea -0xc(%ebp),%esp 967: 5b pop %ebx 968: 5e pop %esi 969: 5f pop %edi 96a: 5d pop %ebp 96b: c3 ret 96c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000970 : struct cmd* parseline(char **ps, char *es) { 970: 55 push %ebp 971: 89 e5 mov %esp,%ebp 973: 57 push %edi 974: 56 push %esi 975: 53 push %ebx 976: 83 ec 24 sub $0x24,%esp 979: 8b 75 08 mov 0x8(%ebp),%esi 97c: 8b 7d 0c mov 0xc(%ebp),%edi cmd = parsepipe(ps, es); 97f: 57 push %edi 980: 56 push %esi 981: e8 5a ff ff ff call 8e0 while (peek(ps, es, "&")) { 986: 83 c4 10 add $0x10,%esp cmd = parsepipe(ps, es); 989: 89 c3 mov %eax,%ebx while (peek(ps, es, "&")) { 98b: eb 3b jmp 9c8 98d: 8d 76 00 lea 0x0(%esi),%esi gettoken(ps, es, 0, 0); 990: 6a 00 push $0x0 992: 6a 00 push $0x0 994: 57 push %edi 995: 56 push %esi 996: e8 05 fb ff ff call 4a0 cmd = malloc(sizeof(*cmd)); 99b: c7 04 24 08 00 00 00 movl $0x8,(%esp) 9a2: e8 59 08 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); 9a7: 83 c4 0c add $0xc,%esp 9aa: 6a 08 push $0x8 9ac: 6a 00 push $0x0 9ae: 50 push %eax 9af: 89 45 e4 mov %eax,-0x1c(%ebp) 9b2: e8 09 03 00 00 call cc0 cmd->type = BACK; 9b7: 8b 55 e4 mov -0x1c(%ebp),%edx cmd->cmd = subcmd; 9ba: 83 c4 10 add $0x10,%esp cmd->type = BACK; 9bd: c7 02 05 00 00 00 movl $0x5,(%edx) cmd->cmd = subcmd; 9c3: 89 5a 04 mov %ebx,0x4(%edx) 9c6: 89 d3 mov %edx,%ebx while (peek(ps, es, "&")) { 9c8: 83 ec 04 sub $0x4,%esp 9cb: 68 6a 13 00 00 push $0x136a 9d0: 57 push %edi 9d1: 56 push %esi 9d2: e8 29 fc ff ff call 600 9d7: 83 c4 10 add $0x10,%esp 9da: 85 c0 test %eax,%eax 9dc: 75 b2 jne 990 if (peek(ps, es, ";")) { 9de: 83 ec 04 sub $0x4,%esp 9e1: 68 66 13 00 00 push $0x1366 9e6: 57 push %edi 9e7: 56 push %esi 9e8: e8 13 fc ff ff call 600 9ed: 83 c4 10 add $0x10,%esp 9f0: 85 c0 test %eax,%eax 9f2: 75 0c jne a00 } 9f4: 8d 65 f4 lea -0xc(%ebp),%esp 9f7: 89 d8 mov %ebx,%eax 9f9: 5b pop %ebx 9fa: 5e pop %esi 9fb: 5f pop %edi 9fc: 5d pop %ebp 9fd: c3 ret 9fe: 66 90 xchg %ax,%ax gettoken(ps, es, 0, 0); a00: 6a 00 push $0x0 a02: 6a 00 push $0x0 a04: 57 push %edi a05: 56 push %esi a06: e8 95 fa ff ff call 4a0 cmd = listcmd(cmd, parseline(ps, es)); a0b: 58 pop %eax a0c: 5a pop %edx a0d: 57 push %edi a0e: 56 push %esi a0f: e8 5c ff ff ff call 970 cmd = malloc(sizeof(*cmd)); a14: c7 04 24 0c 00 00 00 movl $0xc,(%esp) cmd = listcmd(cmd, parseline(ps, es)); a1b: 89 c7 mov %eax,%edi cmd = malloc(sizeof(*cmd)); a1d: e8 de 07 00 00 call 1200 memset(cmd, 0, sizeof(*cmd)); a22: 83 c4 0c add $0xc,%esp a25: 6a 0c push $0xc cmd = malloc(sizeof(*cmd)); a27: 89 c6 mov %eax,%esi memset(cmd, 0, sizeof(*cmd)); a29: 6a 00 push $0x0 a2b: 50 push %eax a2c: e8 8f 02 00 00 call cc0 cmd->left = left; a31: 89 5e 04 mov %ebx,0x4(%esi) cmd->right = right; a34: 83 c4 10 add $0x10,%esp a37: 89 f3 mov %esi,%ebx cmd->type = LIST; a39: c7 06 04 00 00 00 movl $0x4,(%esi) } a3f: 89 d8 mov %ebx,%eax cmd->right = right; a41: 89 7e 08 mov %edi,0x8(%esi) } a44: 8d 65 f4 lea -0xc(%ebp),%esp a47: 5b pop %ebx a48: 5e pop %esi a49: 5f pop %edi a4a: 5d pop %ebp a4b: c3 ret a4c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000a50 : struct cmd* parseblock(char **ps, char *es) { a50: 55 push %ebp a51: 89 e5 mov %esp,%ebp a53: 57 push %edi a54: 56 push %esi a55: 53 push %ebx a56: 83 ec 10 sub $0x10,%esp a59: 8b 5d 08 mov 0x8(%ebp),%ebx a5c: 8b 75 0c mov 0xc(%ebp),%esi if (!peek(ps, es, "(")) { a5f: 68 4c 13 00 00 push $0x134c a64: 56 push %esi a65: 53 push %ebx a66: e8 95 fb ff ff call 600 a6b: 83 c4 10 add $0x10,%esp a6e: 85 c0 test %eax,%eax a70: 74 4a je abc gettoken(ps, es, 0, 0); a72: 6a 00 push $0x0 a74: 6a 00 push $0x0 a76: 56 push %esi a77: 53 push %ebx a78: e8 23 fa ff ff call 4a0 cmd = parseline(ps, es); a7d: 58 pop %eax a7e: 5a pop %edx a7f: 56 push %esi a80: 53 push %ebx a81: e8 ea fe ff ff call 970 if (!peek(ps, es, ")")) { a86: 83 c4 0c add $0xc,%esp a89: 68 88 13 00 00 push $0x1388 cmd = parseline(ps, es); a8e: 89 c7 mov %eax,%edi if (!peek(ps, es, ")")) { a90: 56 push %esi a91: 53 push %ebx a92: e8 69 fb ff ff call 600 a97: 83 c4 10 add $0x10,%esp a9a: 85 c0 test %eax,%eax a9c: 74 2b je ac9 gettoken(ps, es, 0, 0); a9e: 6a 00 push $0x0 aa0: 6a 00 push $0x0 aa2: 56 push %esi aa3: 53 push %ebx aa4: e8 f7 f9 ff ff call 4a0 cmd = parseredirs(cmd, ps, es); aa9: 83 c4 0c add $0xc,%esp aac: 56 push %esi aad: 53 push %ebx aae: 57 push %edi aaf: e8 cc fb ff ff call 680 } ab4: 8d 65 f4 lea -0xc(%ebp),%esp ab7: 5b pop %ebx ab8: 5e pop %esi ab9: 5f pop %edi aba: 5d pop %ebp abb: c3 ret panic("parseblock"); abc: 83 ec 0c sub $0xc,%esp abf: 68 6c 13 00 00 push $0x136c ac4: e8 d7 f6 ff ff call 1a0 panic("syntax - missing )"); ac9: 83 ec 0c sub $0xc,%esp acc: 68 77 13 00 00 push $0x1377 ad1: e8 ca f6 ff ff call 1a0 ad6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi add: 8d 76 00 lea 0x0(%esi),%esi 00000ae0 : // NUL-terminate all the counted strings. struct cmd* nulterminate(struct cmd *cmd) { ae0: 55 push %ebp ae1: 89 e5 mov %esp,%ebp ae3: 53 push %ebx ae4: 83 ec 04 sub $0x4,%esp ae7: 8b 5d 08 mov 0x8(%ebp),%ebx struct execcmd *ecmd; struct listcmd *lcmd; struct pipecmd *pcmd; struct redircmd *rcmd; if (cmd == 0) { aea: 85 db test %ebx,%ebx aec: 0f 84 8e 00 00 00 je b80 return 0; } switch (cmd->type) { af2: 83 3b 05 cmpl $0x5,(%ebx) af5: 77 61 ja b58 af7: 8b 03 mov (%ebx),%eax af9: ff 24 85 c8 13 00 00 jmp *0x13c8(,%eax,4) nulterminate(pcmd->right); break; case LIST: lcmd = (struct listcmd*)cmd; nulterminate(lcmd->left); b00: 83 ec 0c sub $0xc,%esp b03: ff 73 04 push 0x4(%ebx) b06: e8 d5 ff ff ff call ae0 nulterminate(lcmd->right); b0b: 58 pop %eax b0c: ff 73 08 push 0x8(%ebx) b0f: e8 cc ff ff ff call ae0 break; b14: 83 c4 10 add $0x10,%esp b17: 89 d8 mov %ebx,%eax bcmd = (struct backcmd*)cmd; nulterminate(bcmd->cmd); break; } return cmd; } b19: 8b 5d fc mov -0x4(%ebp),%ebx b1c: c9 leave b1d: c3 ret b1e: 66 90 xchg %ax,%ax nulterminate(bcmd->cmd); b20: 83 ec 0c sub $0xc,%esp b23: ff 73 04 push 0x4(%ebx) b26: e8 b5 ff ff ff call ae0 break; b2b: 89 d8 mov %ebx,%eax b2d: 83 c4 10 add $0x10,%esp } b30: 8b 5d fc mov -0x4(%ebp),%ebx b33: c9 leave b34: c3 ret b35: 8d 76 00 lea 0x0(%esi),%esi for (i = 0; ecmd->argv[i]; i++) { b38: 8b 4b 04 mov 0x4(%ebx),%ecx b3b: 8d 43 08 lea 0x8(%ebx),%eax b3e: 85 c9 test %ecx,%ecx b40: 74 16 je b58 b42: 8d b6 00 00 00 00 lea 0x0(%esi),%esi *ecmd->eargv[i] = 0; b48: 8b 50 24 mov 0x24(%eax),%edx for (i = 0; ecmd->argv[i]; i++) { b4b: 83 c0 04 add $0x4,%eax *ecmd->eargv[i] = 0; b4e: c6 02 00 movb $0x0,(%edx) for (i = 0; ecmd->argv[i]; i++) { b51: 8b 50 fc mov -0x4(%eax),%edx b54: 85 d2 test %edx,%edx b56: 75 f0 jne b48 switch (cmd->type) { b58: 89 d8 mov %ebx,%eax } b5a: 8b 5d fc mov -0x4(%ebp),%ebx b5d: c9 leave b5e: c3 ret b5f: 90 nop nulterminate(rcmd->cmd); b60: 83 ec 0c sub $0xc,%esp b63: ff 73 04 push 0x4(%ebx) b66: e8 75 ff ff ff call ae0 *rcmd->efile = 0; b6b: 8b 43 0c mov 0xc(%ebx),%eax break; b6e: 83 c4 10 add $0x10,%esp *rcmd->efile = 0; b71: c6 00 00 movb $0x0,(%eax) break; b74: 89 d8 mov %ebx,%eax } b76: 8b 5d fc mov -0x4(%ebp),%ebx b79: c9 leave b7a: c3 ret b7b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi b7f: 90 nop return 0; b80: 31 c0 xor %eax,%eax b82: eb 95 jmp b19 b84: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi b8b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi b8f: 90 nop 00000b90 : struct cmd* parsecmd(char *s) { b90: 55 push %ebp b91: 89 e5 mov %esp,%ebp b93: 57 push %edi b94: 56 push %esi cmd = parseline(&s, es); b95: 8d 7d 08 lea 0x8(%ebp),%edi struct cmd* parsecmd(char *s) { b98: 53 push %ebx b99: 83 ec 18 sub $0x18,%esp es = s + strlen(s); b9c: 8b 5d 08 mov 0x8(%ebp),%ebx b9f: 53 push %ebx ba0: e8 eb 00 00 00 call c90 cmd = parseline(&s, es); ba5: 59 pop %ecx ba6: 5e pop %esi es = s + strlen(s); ba7: 01 c3 add %eax,%ebx cmd = parseline(&s, es); ba9: 53 push %ebx baa: 57 push %edi bab: e8 c0 fd ff ff call 970 peek(&s, es, ""); bb0: 83 c4 0c add $0xc,%esp bb3: 68 16 13 00 00 push $0x1316 cmd = parseline(&s, es); bb8: 89 c6 mov %eax,%esi peek(&s, es, ""); bba: 53 push %ebx bbb: 57 push %edi bbc: e8 3f fa ff ff call 600 if (s != es) { bc1: 8b 45 08 mov 0x8(%ebp),%eax bc4: 83 c4 10 add $0x10,%esp bc7: 39 d8 cmp %ebx,%eax bc9: 75 13 jne bde nulterminate(cmd); bcb: 83 ec 0c sub $0xc,%esp bce: 56 push %esi bcf: e8 0c ff ff ff call ae0 } bd4: 8d 65 f4 lea -0xc(%ebp),%esp bd7: 89 f0 mov %esi,%eax bd9: 5b pop %ebx bda: 5e pop %esi bdb: 5f pop %edi bdc: 5d pop %ebp bdd: c3 ret printf(2, "leftovers: %s\n", s); bde: 52 push %edx bdf: 50 push %eax be0: 68 8a 13 00 00 push $0x138a be5: 6a 02 push $0x2 be7: e8 e4 03 00 00 call fd0 panic("syntax"); bec: c7 04 24 4e 13 00 00 movl $0x134e,(%esp) bf3: e8 a8 f5 ff ff call 1a0 bf8: 66 90 xchg %ax,%ax bfa: 66 90 xchg %ax,%ax bfc: 66 90 xchg %ax,%ax bfe: 66 90 xchg %ax,%ax 00000c00 : #include "stat.h" #include "fcntl.h" #include "user.h" #include "x86.h" char*strcpy(char *s, const char *t) { c00: 55 push %ebp char *os; os = s; while ((*s++ = *t++) != 0) { c01: 31 c0 xor %eax,%eax char*strcpy(char *s, const char *t) { c03: 89 e5 mov %esp,%ebp c05: 53 push %ebx c06: 8b 4d 08 mov 0x8(%ebp),%ecx c09: 8b 5d 0c mov 0xc(%ebp),%ebx c0c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while ((*s++ = *t++) != 0) { c10: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx c14: 88 14 01 mov %dl,(%ecx,%eax,1) c17: 83 c0 01 add $0x1,%eax c1a: 84 d2 test %dl,%dl c1c: 75 f2 jne c10 ; } return os; } c1e: 8b 5d fc mov -0x4(%ebp),%ebx c21: 89 c8 mov %ecx,%eax c23: c9 leave c24: c3 ret c25: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi c2c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000c30 : int strcmp(const char *p, const char *q) { c30: 55 push %ebp c31: 89 e5 mov %esp,%ebp c33: 53 push %ebx c34: 8b 55 08 mov 0x8(%ebp),%edx c37: 8b 4d 0c mov 0xc(%ebp),%ecx while (*p && *p == *q) { c3a: 0f b6 02 movzbl (%edx),%eax c3d: 84 c0 test %al,%al c3f: 75 17 jne c58 c41: eb 3a jmp c7d c43: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c47: 90 nop c48: 0f b6 42 01 movzbl 0x1(%edx),%eax p++, q++; c4c: 83 c2 01 add $0x1,%edx c4f: 8d 59 01 lea 0x1(%ecx),%ebx while (*p && *p == *q) { c52: 84 c0 test %al,%al c54: 74 1a je c70 p++, q++; c56: 89 d9 mov %ebx,%ecx while (*p && *p == *q) { c58: 0f b6 19 movzbl (%ecx),%ebx c5b: 38 c3 cmp %al,%bl c5d: 74 e9 je c48 } return (uchar) * p - (uchar) * q; c5f: 29 d8 sub %ebx,%eax } c61: 8b 5d fc mov -0x4(%ebp),%ebx c64: c9 leave c65: c3 ret c66: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi c6d: 8d 76 00 lea 0x0(%esi),%esi return (uchar) * p - (uchar) * q; c70: 0f b6 59 01 movzbl 0x1(%ecx),%ebx c74: 31 c0 xor %eax,%eax c76: 29 d8 sub %ebx,%eax } c78: 8b 5d fc mov -0x4(%ebp),%ebx c7b: c9 leave c7c: c3 ret return (uchar) * p - (uchar) * q; c7d: 0f b6 19 movzbl (%ecx),%ebx c80: 31 c0 xor %eax,%eax c82: eb db jmp c5f c84: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi c8b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c8f: 90 nop 00000c90 : uint strlen(const char *s) { c90: 55 push %ebp c91: 89 e5 mov %esp,%ebp c93: 8b 55 08 mov 0x8(%ebp),%edx int n; for (n = 0; s[n]; n++) { c96: 80 3a 00 cmpb $0x0,(%edx) c99: 74 15 je cb0 c9b: 31 c0 xor %eax,%eax c9d: 8d 76 00 lea 0x0(%esi),%esi ca0: 83 c0 01 add $0x1,%eax ca3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) ca7: 89 c1 mov %eax,%ecx ca9: 75 f5 jne ca0 ; } return n; } cab: 89 c8 mov %ecx,%eax cad: 5d pop %ebp cae: c3 ret caf: 90 nop for (n = 0; s[n]; n++) { cb0: 31 c9 xor %ecx,%ecx } cb2: 5d pop %ebp cb3: 89 c8 mov %ecx,%eax cb5: c3 ret cb6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi cbd: 8d 76 00 lea 0x0(%esi),%esi 00000cc0 : void* memset(void *dst, int c, uint n) { cc0: 55 push %ebp cc1: 89 e5 mov %esp,%ebp cc3: 57 push %edi cc4: 8b 55 08 mov 0x8(%ebp),%edx "d" (port), "0" (addr), "1" (cnt) : "cc"); } static inline void stosb(void *addr, int data, int cnt) { asm volatile ("cld; rep stosb" : cc7: 8b 4d 10 mov 0x10(%ebp),%ecx cca: 8b 45 0c mov 0xc(%ebp),%eax ccd: 89 d7 mov %edx,%edi ccf: fc cld cd0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } cd2: 8b 7d fc mov -0x4(%ebp),%edi cd5: 89 d0 mov %edx,%eax cd7: c9 leave cd8: c3 ret cd9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000ce0 : char* strchr(const char *s, char c) { ce0: 55 push %ebp ce1: 89 e5 mov %esp,%ebp ce3: 8b 45 08 mov 0x8(%ebp),%eax ce6: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for (; *s; s++) { cea: 0f b6 10 movzbl (%eax),%edx ced: 84 d2 test %dl,%dl cef: 75 12 jne d03 cf1: eb 1d jmp d10 cf3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi cf7: 90 nop cf8: 0f b6 50 01 movzbl 0x1(%eax),%edx cfc: 83 c0 01 add $0x1,%eax cff: 84 d2 test %dl,%dl d01: 74 0d je d10 if (*s == c) { d03: 38 d1 cmp %dl,%cl d05: 75 f1 jne cf8 return (char*)s; } } return 0; } d07: 5d pop %ebp d08: c3 ret d09: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; d10: 31 c0 xor %eax,%eax } d12: 5d pop %ebp d13: c3 ret d14: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi d1b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi d1f: 90 nop 00000d20 : char* gets(char *buf, int max) { d20: 55 push %ebp d21: 89 e5 mov %esp,%ebp d23: 57 push %edi d24: 56 push %esi int i, cc; char c; for (i = 0; i + 1 < max;) { cc = read(0, &c, 1); d25: 8d 7d e7 lea -0x19(%ebp),%edi char* gets(char *buf, int max) { d28: 53 push %ebx for (i = 0; i + 1 < max;) { d29: 31 db xor %ebx,%ebx char* gets(char *buf, int max) { d2b: 83 ec 1c sub $0x1c,%esp for (i = 0; i + 1 < max;) { d2e: eb 27 jmp d57 cc = read(0, &c, 1); d30: 83 ec 04 sub $0x4,%esp d33: 6a 01 push $0x1 d35: 57 push %edi d36: 6a 00 push $0x0 d38: e8 2e 01 00 00 call e6b if (cc < 1) { d3d: 83 c4 10 add $0x10,%esp d40: 85 c0 test %eax,%eax d42: 7e 1d jle d61 break; } buf[i++] = c; d44: 0f b6 45 e7 movzbl -0x19(%ebp),%eax d48: 8b 55 08 mov 0x8(%ebp),%edx d4b: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if (c == '\n' || c == '\r') { d4f: 3c 0a cmp $0xa,%al d51: 74 1d je d70 d53: 3c 0d cmp $0xd,%al d55: 74 19 je d70 for (i = 0; i + 1 < max;) { d57: 89 de mov %ebx,%esi d59: 83 c3 01 add $0x1,%ebx d5c: 3b 5d 0c cmp 0xc(%ebp),%ebx d5f: 7c cf jl d30 break; } } buf[i] = '\0'; d61: 8b 45 08 mov 0x8(%ebp),%eax d64: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } d68: 8d 65 f4 lea -0xc(%ebp),%esp d6b: 5b pop %ebx d6c: 5e pop %esi d6d: 5f pop %edi d6e: 5d pop %ebp d6f: c3 ret buf[i] = '\0'; d70: 8b 45 08 mov 0x8(%ebp),%eax d73: 89 de mov %ebx,%esi d75: c6 04 30 00 movb $0x0,(%eax,%esi,1) } d79: 8d 65 f4 lea -0xc(%ebp),%esp d7c: 5b pop %ebx d7d: 5e pop %esi d7e: 5f pop %edi d7f: 5d pop %ebp d80: c3 ret d81: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi d88: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi d8f: 90 nop 00000d90 : int stat(const char *n, struct stat *st) { d90: 55 push %ebp d91: 89 e5 mov %esp,%ebp d93: 56 push %esi d94: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); d95: 83 ec 08 sub $0x8,%esp d98: 6a 00 push $0x0 d9a: ff 75 08 push 0x8(%ebp) d9d: e8 19 01 00 00 call ebb if (fd < 0) { da2: 83 c4 10 add $0x10,%esp da5: 85 c0 test %eax,%eax da7: 78 27 js dd0 return -1; } r = fstat(fd, st); da9: 83 ec 08 sub $0x8,%esp dac: ff 75 0c push 0xc(%ebp) daf: 89 c3 mov %eax,%ebx db1: 50 push %eax db2: e8 cc 00 00 00 call e83 close(fd); db7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); dba: 89 c6 mov %eax,%esi close(fd); dbc: e8 2a 01 00 00 call eeb return r; dc1: 83 c4 10 add $0x10,%esp } dc4: 8d 65 f8 lea -0x8(%ebp),%esp dc7: 89 f0 mov %esi,%eax dc9: 5b pop %ebx dca: 5e pop %esi dcb: 5d pop %ebp dcc: c3 ret dcd: 8d 76 00 lea 0x0(%esi),%esi return -1; dd0: be ff ff ff ff mov $0xffffffff,%esi dd5: eb ed jmp dc4 dd7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi dde: 66 90 xchg %ax,%ax 00000de0 : int atoi(const char *s) { de0: 55 push %ebp de1: 89 e5 mov %esp,%ebp de3: 53 push %ebx de4: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while ('0' <= *s && *s <= '9') { de7: 0f be 02 movsbl (%edx),%eax dea: 8d 48 d0 lea -0x30(%eax),%ecx ded: 80 f9 09 cmp $0x9,%cl n = 0; df0: b9 00 00 00 00 mov $0x0,%ecx while ('0' <= *s && *s <= '9') { df5: 77 1e ja e15 df7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi dfe: 66 90 xchg %ax,%ax n = n * 10 + *s++ - '0'; e00: 83 c2 01 add $0x1,%edx e03: 8d 0c 89 lea (%ecx,%ecx,4),%ecx e06: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while ('0' <= *s && *s <= '9') { e0a: 0f be 02 movsbl (%edx),%eax e0d: 8d 58 d0 lea -0x30(%eax),%ebx e10: 80 fb 09 cmp $0x9,%bl e13: 76 eb jbe e00 } return n; } e15: 8b 5d fc mov -0x4(%ebp),%ebx e18: 89 c8 mov %ecx,%eax e1a: c9 leave e1b: c3 ret e1c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000e20 : void* memmove(void *vdst, const void *vsrc, int n) { e20: 55 push %ebp e21: 89 e5 mov %esp,%ebp e23: 57 push %edi e24: 8b 45 10 mov 0x10(%ebp),%eax e27: 8b 55 08 mov 0x8(%ebp),%edx e2a: 56 push %esi e2b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while (n-- > 0) { e2e: 85 c0 test %eax,%eax e30: 7e 13 jle e45 e32: 01 d0 add %edx,%eax dst = vdst; e34: 89 d7 mov %edx,%edi e36: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi e3d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; e40: a4 movsb %ds:(%esi),%es:(%edi) while (n-- > 0) { e41: 39 f8 cmp %edi,%eax e43: 75 fb jne e40 } return vdst; } e45: 5e pop %esi e46: 89 d0 mov %edx,%eax e48: 5f pop %edi e49: 5d pop %ebp e4a: c3 ret 00000e4b : name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) e4b: b8 01 00 00 00 mov $0x1,%eax e50: cd 40 int $0x40 e52: c3 ret 00000e53 : SYSCALL(exit) e53: b8 02 00 00 00 mov $0x2,%eax e58: cd 40 int $0x40 e5a: c3 ret 00000e5b : SYSCALL(wait) e5b: b8 03 00 00 00 mov $0x3,%eax e60: cd 40 int $0x40 e62: c3 ret 00000e63 : SYSCALL(pipe) e63: b8 04 00 00 00 mov $0x4,%eax e68: cd 40 int $0x40 e6a: c3 ret 00000e6b : SYSCALL(read) e6b: b8 05 00 00 00 mov $0x5,%eax e70: cd 40 int $0x40 e72: c3 ret 00000e73 : SYSCALL(kill) e73: b8 06 00 00 00 mov $0x6,%eax e78: cd 40 int $0x40 e7a: c3 ret 00000e7b : SYSCALL(exec) e7b: b8 07 00 00 00 mov $0x7,%eax e80: cd 40 int $0x40 e82: c3 ret 00000e83 : SYSCALL(fstat) e83: b8 08 00 00 00 mov $0x8,%eax e88: cd 40 int $0x40 e8a: c3 ret 00000e8b : SYSCALL(chdir) e8b: b8 09 00 00 00 mov $0x9,%eax e90: cd 40 int $0x40 e92: c3 ret 00000e93 : SYSCALL(dup) e93: b8 0a 00 00 00 mov $0xa,%eax e98: cd 40 int $0x40 e9a: c3 ret 00000e9b : SYSCALL(getpid) e9b: b8 0b 00 00 00 mov $0xb,%eax ea0: cd 40 int $0x40 ea2: c3 ret 00000ea3 : SYSCALL(sbrk) ea3: b8 0c 00 00 00 mov $0xc,%eax ea8: cd 40 int $0x40 eaa: c3 ret 00000eab : SYSCALL(sleep) eab: b8 0d 00 00 00 mov $0xd,%eax eb0: cd 40 int $0x40 eb2: c3 ret 00000eb3 : SYSCALL(uptime) eb3: b8 0e 00 00 00 mov $0xe,%eax eb8: cd 40 int $0x40 eba: c3 ret 00000ebb : SYSCALL(open) ebb: b8 0f 00 00 00 mov $0xf,%eax ec0: cd 40 int $0x40 ec2: c3 ret 00000ec3 : SYSCALL(write) ec3: b8 10 00 00 00 mov $0x10,%eax ec8: cd 40 int $0x40 eca: c3 ret 00000ecb : SYSCALL(mknod) ecb: b8 11 00 00 00 mov $0x11,%eax ed0: cd 40 int $0x40 ed2: c3 ret 00000ed3 : SYSCALL(unlink) ed3: b8 12 00 00 00 mov $0x12,%eax ed8: cd 40 int $0x40 eda: c3 ret 00000edb : SYSCALL(link) edb: b8 13 00 00 00 mov $0x13,%eax ee0: cd 40 int $0x40 ee2: c3 ret 00000ee3 : SYSCALL(mkdir) ee3: b8 14 00 00 00 mov $0x14,%eax ee8: cd 40 int $0x40 eea: c3 ret 00000eeb : SYSCALL(close) eeb: b8 15 00 00 00 mov $0x15,%eax ef0: cd 40 int $0x40 ef2: c3 ret 00000ef3 : SYSCALL(getch) ef3: b8 16 00 00 00 mov $0x16,%eax ef8: cd 40 int $0x40 efa: c3 ret 00000efb : SYSCALL(greeting) efb: b8 17 00 00 00 mov $0x17,%eax f00: cd 40 int $0x40 f02: c3 ret 00000f03 : SYSCALL(shutdown) f03: b8 18 00 00 00 mov $0x18,%eax f08: cd 40 int $0x40 f0a: c3 ret 00000f0b : SYSCALL(screen) f0b: b8 19 00 00 00 mov $0x19,%eax f10: cd 40 int $0x40 f12: c3 ret 00000f13 : SYSCALL(cls) f13: b8 1a 00 00 00 mov $0x1a,%eax f18: cd 40 int $0x40 f1a: c3 ret f1b: 66 90 xchg %ax,%ax f1d: 66 90 xchg %ax,%ax f1f: 90 nop 00000f20 : static void putc(int fd, char c) { write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { f20: 55 push %ebp f21: 89 e5 mov %esp,%ebp f23: 57 push %edi f24: 56 push %esi f25: 53 push %ebx f26: 83 ec 3c sub $0x3c,%esp f29: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if (sgn && xx < 0) { neg = 1; x = -xx; f2c: 89 d1 mov %edx,%ecx static void printint(int fd, int xx, int base, int sgn) { f2e: 89 45 b8 mov %eax,-0x48(%ebp) if (sgn && xx < 0) { f31: 85 d2 test %edx,%edx f33: 0f 89 7f 00 00 00 jns fb8 f39: f6 45 08 01 testb $0x1,0x8(%ebp) f3d: 74 79 je fb8 neg = 1; f3f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; f46: f7 d9 neg %ecx } else { x = xx; } i = 0; f48: 31 db xor %ebx,%ebx f4a: 8d 75 d7 lea -0x29(%ebp),%esi f4d: 8d 76 00 lea 0x0(%esi),%esi do { buf[i++] = digits[x % base]; f50: 89 c8 mov %ecx,%eax f52: 31 d2 xor %edx,%edx f54: 89 cf mov %ecx,%edi f56: f7 75 c4 divl -0x3c(%ebp) f59: 0f b6 92 40 14 00 00 movzbl 0x1440(%edx),%edx f60: 89 45 c0 mov %eax,-0x40(%ebp) f63: 89 d8 mov %ebx,%eax f65: 8d 5b 01 lea 0x1(%ebx),%ebx } while ((x /= base) != 0); f68: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; f6b: 88 14 1e mov %dl,(%esi,%ebx,1) while ((x /= base) != 0); f6e: 39 7d c4 cmp %edi,-0x3c(%ebp) f71: 76 dd jbe f50 if (neg) { f73: 8b 4d bc mov -0x44(%ebp),%ecx f76: 85 c9 test %ecx,%ecx f78: 74 0c je f86 buf[i++] = '-'; f7a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; f7f: 89 d8 mov %ebx,%eax buf[i++] = '-'; f81: ba 2d 00 00 00 mov $0x2d,%edx } while (--i >= 0) { f86: 8b 7d b8 mov -0x48(%ebp),%edi f89: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx f8d: eb 07 jmp f96 f8f: 90 nop putc(fd, buf[i]); f90: 0f b6 13 movzbl (%ebx),%edx f93: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); f96: 83 ec 04 sub $0x4,%esp f99: 88 55 d7 mov %dl,-0x29(%ebp) f9c: 6a 01 push $0x1 f9e: 56 push %esi f9f: 57 push %edi fa0: e8 1e ff ff ff call ec3 while (--i >= 0) { fa5: 83 c4 10 add $0x10,%esp fa8: 39 de cmp %ebx,%esi faa: 75 e4 jne f90 } } fac: 8d 65 f4 lea -0xc(%ebp),%esp faf: 5b pop %ebx fb0: 5e pop %esi fb1: 5f pop %edi fb2: 5d pop %ebp fb3: c3 ret fb4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; fb8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) fbf: eb 87 jmp f48 fc1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi fc8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi fcf: 90 nop 00000fd0 : // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { fd0: 55 push %ebp fd1: 89 e5 mov %esp,%ebp fd3: 57 push %edi fd4: 56 push %esi fd5: 53 push %ebx fd6: 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++) { fd9: 8b 5d 0c mov 0xc(%ebp),%ebx void printf(int fd, const char *fmt, ...) { fdc: 8b 75 08 mov 0x8(%ebp),%esi for (i = 0; fmt[i]; i++) { fdf: 0f b6 13 movzbl (%ebx),%edx fe2: 84 d2 test %dl,%dl fe4: 74 6a je 1050 ap = (uint*)(void*)&fmt + 1; fe6: 8d 45 10 lea 0x10(%ebp),%eax fe9: 83 c3 01 add $0x1,%ebx write(fd, &c, 1); fec: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; fef: 31 c9 xor %ecx,%ecx ap = (uint*)(void*)&fmt + 1; ff1: 89 45 d0 mov %eax,-0x30(%ebp) ff4: eb 36 jmp 102c ff6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi ffd: 8d 76 00 lea 0x0(%esi),%esi 1000: 89 4d d4 mov %ecx,-0x2c(%ebp) c = fmt[i] & 0xff; if (state == 0) { if (c == '%') { state = '%'; 1003: b9 25 00 00 00 mov $0x25,%ecx if (c == '%') { 1008: 83 f8 25 cmp $0x25,%eax 100b: 74 15 je 1022 write(fd, &c, 1); 100d: 83 ec 04 sub $0x4,%esp 1010: 88 55 e7 mov %dl,-0x19(%ebp) 1013: 6a 01 push $0x1 1015: 57 push %edi 1016: 56 push %esi 1017: e8 a7 fe ff ff call ec3 101c: 8b 4d d4 mov -0x2c(%ebp),%ecx } else { putc(fd, c); 101f: 83 c4 10 add $0x10,%esp for (i = 0; fmt[i]; i++) { 1022: 0f b6 13 movzbl (%ebx),%edx 1025: 83 c3 01 add $0x1,%ebx 1028: 84 d2 test %dl,%dl 102a: 74 24 je 1050 c = fmt[i] & 0xff; 102c: 0f b6 c2 movzbl %dl,%eax if (state == 0) { 102f: 85 c9 test %ecx,%ecx 1031: 74 cd je 1000 } } else if (state == '%') { 1033: 83 f9 25 cmp $0x25,%ecx 1036: 75 ea jne 1022 if (c == 'd') { 1038: 83 f8 25 cmp $0x25,%eax 103b: 0f 84 07 01 00 00 je 1148 1041: 83 e8 63 sub $0x63,%eax 1044: 83 f8 15 cmp $0x15,%eax 1047: 77 17 ja 1060 1049: ff 24 85 e8 13 00 00 jmp *0x13e8(,%eax,4) putc(fd, c); } state = 0; } } } 1050: 8d 65 f4 lea -0xc(%ebp),%esp 1053: 5b pop %ebx 1054: 5e pop %esi 1055: 5f pop %edi 1056: 5d pop %ebp 1057: c3 ret 1058: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 105f: 90 nop write(fd, &c, 1); 1060: 83 ec 04 sub $0x4,%esp 1063: 88 55 d4 mov %dl,-0x2c(%ebp) 1066: 6a 01 push $0x1 1068: 57 push %edi 1069: 56 push %esi 106a: c6 45 e7 25 movb $0x25,-0x19(%ebp) 106e: e8 50 fe ff ff call ec3 putc(fd, c); 1073: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx write(fd, &c, 1); 1077: 83 c4 0c add $0xc,%esp 107a: 88 55 e7 mov %dl,-0x19(%ebp) 107d: 6a 01 push $0x1 107f: 57 push %edi 1080: 56 push %esi 1081: e8 3d fe ff ff call ec3 putc(fd, c); 1086: 83 c4 10 add $0x10,%esp state = 0; 1089: 31 c9 xor %ecx,%ecx 108b: eb 95 jmp 1022 108d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 1090: 83 ec 0c sub $0xc,%esp 1093: b9 10 00 00 00 mov $0x10,%ecx 1098: 6a 00 push $0x0 109a: 8b 45 d0 mov -0x30(%ebp),%eax 109d: 8b 10 mov (%eax),%edx 109f: 89 f0 mov %esi,%eax 10a1: e8 7a fe ff ff call f20 ap++; 10a6: 83 45 d0 04 addl $0x4,-0x30(%ebp) 10aa: 83 c4 10 add $0x10,%esp state = 0; 10ad: 31 c9 xor %ecx,%ecx 10af: e9 6e ff ff ff jmp 1022 10b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 10b8: 8b 45 d0 mov -0x30(%ebp),%eax 10bb: 8b 10 mov (%eax),%edx ap++; 10bd: 83 c0 04 add $0x4,%eax 10c0: 89 45 d0 mov %eax,-0x30(%ebp) if (s == 0) { 10c3: 85 d2 test %edx,%edx 10c5: 0f 84 8d 00 00 00 je 1158 while (*s != 0) { 10cb: 0f b6 02 movzbl (%edx),%eax state = 0; 10ce: 31 c9 xor %ecx,%ecx while (*s != 0) { 10d0: 84 c0 test %al,%al 10d2: 0f 84 4a ff ff ff je 1022 10d8: 89 5d d4 mov %ebx,-0x2c(%ebp) 10db: 89 d3 mov %edx,%ebx 10dd: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 10e0: 83 ec 04 sub $0x4,%esp s++; 10e3: 83 c3 01 add $0x1,%ebx 10e6: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 10e9: 6a 01 push $0x1 10eb: 57 push %edi 10ec: 56 push %esi 10ed: e8 d1 fd ff ff call ec3 while (*s != 0) { 10f2: 0f b6 03 movzbl (%ebx),%eax 10f5: 83 c4 10 add $0x10,%esp 10f8: 84 c0 test %al,%al 10fa: 75 e4 jne 10e0 state = 0; 10fc: 8b 5d d4 mov -0x2c(%ebp),%ebx 10ff: 31 c9 xor %ecx,%ecx 1101: e9 1c ff ff ff jmp 1022 1106: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 110d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 1110: 83 ec 0c sub $0xc,%esp 1113: b9 0a 00 00 00 mov $0xa,%ecx 1118: 6a 01 push $0x1 111a: e9 7b ff ff ff jmp 109a 111f: 90 nop putc(fd, *ap); 1120: 8b 45 d0 mov -0x30(%ebp),%eax write(fd, &c, 1); 1123: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 1126: 8b 00 mov (%eax),%eax write(fd, &c, 1); 1128: 6a 01 push $0x1 112a: 57 push %edi 112b: 56 push %esi putc(fd, *ap); 112c: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 112f: e8 8f fd ff ff call ec3 ap++; 1134: 83 45 d0 04 addl $0x4,-0x30(%ebp) 1138: 83 c4 10 add $0x10,%esp state = 0; 113b: 31 c9 xor %ecx,%ecx 113d: e9 e0 fe ff ff jmp 1022 1142: 8d b6 00 00 00 00 lea 0x0(%esi),%esi putc(fd, c); 1148: 88 55 e7 mov %dl,-0x19(%ebp) write(fd, &c, 1); 114b: 83 ec 04 sub $0x4,%esp 114e: e9 2a ff ff ff jmp 107d 1153: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1157: 90 nop s = "(null)"; 1158: ba e0 13 00 00 mov $0x13e0,%edx while (*s != 0) { 115d: 89 5d d4 mov %ebx,-0x2c(%ebp) 1160: b8 28 00 00 00 mov $0x28,%eax 1165: 89 d3 mov %edx,%ebx 1167: e9 74 ff ff ff jmp 10e0 116c: 66 90 xchg %ax,%ax 116e: 66 90 xchg %ax,%ax 00001170 : typedef union header Header; static Header base; static Header *freep; void free(void *ap) { 1170: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 1171: a1 a4 1a 00 00 mov 0x1aa4,%eax void free(void *ap) { 1176: 89 e5 mov %esp,%ebp 1178: 57 push %edi 1179: 56 push %esi 117a: 53 push %ebx 117b: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 117e: 8d 4b f8 lea -0x8(%ebx),%ecx for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 1181: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1188: 89 c2 mov %eax,%edx 118a: 8b 00 mov (%eax),%eax 118c: 39 ca cmp %ecx,%edx 118e: 73 30 jae 11c0 1190: 39 c1 cmp %eax,%ecx 1192: 72 04 jb 1198 if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 1194: 39 c2 cmp %eax,%edx 1196: 72 f0 jb 1188 break; } } if (bp + bp->s.size == p->s.ptr) { 1198: 8b 73 fc mov -0x4(%ebx),%esi 119b: 8d 3c f1 lea (%ecx,%esi,8),%edi 119e: 39 f8 cmp %edi,%eax 11a0: 74 30 je 11d2 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; 11a2: 89 43 f8 mov %eax,-0x8(%ebx) } else { bp->s.ptr = p->s.ptr; } if (p + p->s.size == bp) { 11a5: 8b 42 04 mov 0x4(%edx),%eax 11a8: 8d 34 c2 lea (%edx,%eax,8),%esi 11ab: 39 f1 cmp %esi,%ecx 11ad: 74 3a je 11e9 p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; 11af: 89 0a mov %ecx,(%edx) } else { p->s.ptr = bp; } freep = p; } 11b1: 5b pop %ebx freep = p; 11b2: 89 15 a4 1a 00 00 mov %edx,0x1aa4 } 11b8: 5e pop %esi 11b9: 5f pop %edi 11ba: 5d pop %ebp 11bb: c3 ret 11bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 11c0: 39 c2 cmp %eax,%edx 11c2: 72 c4 jb 1188 11c4: 39 c1 cmp %eax,%ecx 11c6: 73 c0 jae 1188 if (bp + bp->s.size == p->s.ptr) { 11c8: 8b 73 fc mov -0x4(%ebx),%esi 11cb: 8d 3c f1 lea (%ecx,%esi,8),%edi 11ce: 39 f8 cmp %edi,%eax 11d0: 75 d0 jne 11a2 bp->s.size += p->s.ptr->s.size; 11d2: 03 70 04 add 0x4(%eax),%esi 11d5: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 11d8: 8b 02 mov (%edx),%eax 11da: 8b 00 mov (%eax),%eax 11dc: 89 43 f8 mov %eax,-0x8(%ebx) if (p + p->s.size == bp) { 11df: 8b 42 04 mov 0x4(%edx),%eax 11e2: 8d 34 c2 lea (%edx,%eax,8),%esi 11e5: 39 f1 cmp %esi,%ecx 11e7: 75 c6 jne 11af p->s.size += bp->s.size; 11e9: 03 43 fc add -0x4(%ebx),%eax freep = p; 11ec: 89 15 a4 1a 00 00 mov %edx,0x1aa4 p->s.size += bp->s.size; 11f2: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 11f5: 8b 4b f8 mov -0x8(%ebx),%ecx 11f8: 89 0a mov %ecx,(%edx) } 11fa: 5b pop %ebx 11fb: 5e pop %esi 11fc: 5f pop %edi 11fd: 5d pop %ebp 11fe: c3 ret 11ff: 90 nop 00001200 : hp->s.size = nu; free((void*)(hp + 1)); return freep; } void* malloc(uint nbytes) { 1200: 55 push %ebp 1201: 89 e5 mov %esp,%ebp 1203: 57 push %edi 1204: 56 push %esi 1205: 53 push %ebx 1206: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 1209: 8b 45 08 mov 0x8(%ebp),%eax if ((prevp = freep) == 0) { 120c: 8b 3d a4 1a 00 00 mov 0x1aa4,%edi nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 1212: 8d 70 07 lea 0x7(%eax),%esi 1215: c1 ee 03 shr $0x3,%esi 1218: 83 c6 01 add $0x1,%esi if ((prevp = freep) == 0) { 121b: 85 ff test %edi,%edi 121d: 0f 84 9d 00 00 00 je 12c0 base.s.ptr = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 1223: 8b 17 mov (%edi),%edx if (p->s.size >= nunits) { 1225: 8b 4a 04 mov 0x4(%edx),%ecx 1228: 39 f1 cmp %esi,%ecx 122a: 73 6a jae 1296 122c: bb 00 10 00 00 mov $0x1000,%ebx 1231: 39 de cmp %ebx,%esi 1233: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 1236: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax 123d: 89 45 e4 mov %eax,-0x1c(%ebp) 1240: eb 17 jmp 1259 1242: 8d b6 00 00 00 00 lea 0x0(%esi),%esi for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 1248: 8b 02 mov (%edx),%eax if (p->s.size >= nunits) { 124a: 8b 48 04 mov 0x4(%eax),%ecx 124d: 39 f1 cmp %esi,%ecx 124f: 73 4f jae 12a0 p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if (p == freep) { 1251: 8b 3d a4 1a 00 00 mov 0x1aa4,%edi 1257: 89 c2 mov %eax,%edx 1259: 39 d7 cmp %edx,%edi 125b: 75 eb jne 1248 p = sbrk(nu * sizeof(Header)); 125d: 83 ec 0c sub $0xc,%esp 1260: ff 75 e4 push -0x1c(%ebp) 1263: e8 3b fc ff ff call ea3 if (p == (char*)-1) { 1268: 83 c4 10 add $0x10,%esp 126b: 83 f8 ff cmp $0xffffffff,%eax 126e: 74 1c je 128c hp->s.size = nu; 1270: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 1273: 83 ec 0c sub $0xc,%esp 1276: 83 c0 08 add $0x8,%eax 1279: 50 push %eax 127a: e8 f1 fe ff ff call 1170 return freep; 127f: 8b 15 a4 1a 00 00 mov 0x1aa4,%edx if ((p = morecore(nunits)) == 0) { 1285: 83 c4 10 add $0x10,%esp 1288: 85 d2 test %edx,%edx 128a: 75 bc jne 1248 return 0; } } } } 128c: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 128f: 31 c0 xor %eax,%eax } 1291: 5b pop %ebx 1292: 5e pop %esi 1293: 5f pop %edi 1294: 5d pop %ebp 1295: c3 ret if (p->s.size >= nunits) { 1296: 89 d0 mov %edx,%eax 1298: 89 fa mov %edi,%edx 129a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (p->s.size == nunits) { 12a0: 39 ce cmp %ecx,%esi 12a2: 74 4c je 12f0 p->s.size -= nunits; 12a4: 29 f1 sub %esi,%ecx 12a6: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 12a9: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 12ac: 89 70 04 mov %esi,0x4(%eax) freep = prevp; 12af: 89 15 a4 1a 00 00 mov %edx,0x1aa4 } 12b5: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 12b8: 83 c0 08 add $0x8,%eax } 12bb: 5b pop %ebx 12bc: 5e pop %esi 12bd: 5f pop %edi 12be: 5d pop %ebp 12bf: c3 ret base.s.ptr = freep = prevp = &base; 12c0: c7 05 a4 1a 00 00 a8 movl $0x1aa8,0x1aa4 12c7: 1a 00 00 base.s.size = 0; 12ca: bf a8 1a 00 00 mov $0x1aa8,%edi base.s.ptr = freep = prevp = &base; 12cf: c7 05 a8 1a 00 00 a8 movl $0x1aa8,0x1aa8 12d6: 1a 00 00 for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 12d9: 89 fa mov %edi,%edx base.s.size = 0; 12db: c7 05 ac 1a 00 00 00 movl $0x0,0x1aac 12e2: 00 00 00 if (p->s.size >= nunits) { 12e5: e9 42 ff ff ff jmp 122c 12ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 12f0: 8b 08 mov (%eax),%ecx 12f2: 89 0a mov %ecx,(%edx) 12f4: eb b9 jmp 12af