Files
xv6-custom-os/init.asm
2022-12-06 11:49:47 +00:00

1227 lines
42 KiB
NASM

_init: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "user.h"
#include "fcntl.h"
char *argv[] = { "sh", 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: 53 push %ebx
e: 51 push %ecx
int pid, wpid;
if (open("console", O_RDWR) < 0) {
f: 83 ec 08 sub $0x8,%esp
12: 6a 02 push $0x2
14: 68 c8 07 00 00 push $0x7c8
19: e8 7d 03 00 00 call 39b <open>
1e: 83 c4 10 add $0x10,%esp
21: 85 c0 test %eax,%eax
23: 0f 88 8d 00 00 00 js b6 <main+0xb6>
mknod("console", 1, 1);
open("console", O_RDWR);
}
dup(0); // stdout
29: 83 ec 0c sub $0xc,%esp
2c: 6a 00 push $0x0
2e: e8 40 03 00 00 call 373 <dup>
dup(0); // stderr
33: c7 04 24 00 00 00 00 movl $0x0,(%esp)
3a: e8 34 03 00 00 call 373 <dup>
3f: 83 c4 10 add $0x10,%esp
42: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for (;;) {
printf(1, "init: starting sh\n");
48: 83 ec 08 sub $0x8,%esp
4b: 68 d0 07 00 00 push $0x7d0
50: 6a 01 push $0x1
52: e8 49 04 00 00 call 4a0 <printf>
pid = fork();
57: e8 cf 02 00 00 call 32b <fork>
if (pid < 0) {
5c: 83 c4 10 add $0x10,%esp
pid = fork();
5f: 89 c3 mov %eax,%ebx
if (pid < 0) {
61: 85 c0 test %eax,%eax
63: 78 1a js 7f <main+0x7f>
printf(1, "init: fork failed\n");
exit();
}
if (pid == 0) {
65: 74 2b je 92 <main+0x92>
67: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
6e: 66 90 xchg %ax,%ax
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
while ((wpid = wait()) >= 0 && wpid != pid) {
70: e8 c6 02 00 00 call 33b <wait>
75: 85 c0 test %eax,%eax
77: 78 cf js 48 <main+0x48>
79: 39 c3 cmp %eax,%ebx
7b: 75 f3 jne 70 <main+0x70>
7d: eb c9 jmp 48 <main+0x48>
printf(1, "init: fork failed\n");
7f: 53 push %ebx
80: 53 push %ebx
81: 68 e3 07 00 00 push $0x7e3
86: 6a 01 push $0x1
88: e8 13 04 00 00 call 4a0 <printf>
exit();
8d: e8 a1 02 00 00 call 333 <exit>
exec("sh", argv);
92: 50 push %eax
93: 50 push %eax
94: 68 1c 0b 00 00 push $0xb1c
99: 68 f6 07 00 00 push $0x7f6
9e: e8 b8 02 00 00 call 35b <exec>
printf(1, "init: exec sh failed\n");
a3: 5a pop %edx
a4: 59 pop %ecx
a5: 68 f9 07 00 00 push $0x7f9
aa: 6a 01 push $0x1
ac: e8 ef 03 00 00 call 4a0 <printf>
exit();
b1: e8 7d 02 00 00 call 333 <exit>
mknod("console", 1, 1);
b6: 50 push %eax
b7: 6a 01 push $0x1
b9: 6a 01 push $0x1
bb: 68 c8 07 00 00 push $0x7c8
c0: e8 e6 02 00 00 call 3ab <mknod>
open("console", O_RDWR);
c5: 58 pop %eax
c6: 5a pop %edx
c7: 6a 02 push $0x2
c9: 68 c8 07 00 00 push $0x7c8
ce: e8 c8 02 00 00 call 39b <open>
d3: 83 c4 10 add $0x10,%esp
d6: e9 4e ff ff ff jmp 29 <main+0x29>
db: 66 90 xchg %ax,%ax
dd: 66 90 xchg %ax,%ax
df: 90 nop
000000e0 <strcpy>:
#include "stat.h"
#include "fcntl.h"
#include "user.h"
#include "x86.h"
char*strcpy(char *s, const char *t) {
e0: 55 push %ebp
char *os;
os = s;
while ((*s++ = *t++) != 0) {
e1: 31 c0 xor %eax,%eax
char*strcpy(char *s, const char *t) {
e3: 89 e5 mov %esp,%ebp
e5: 53 push %ebx
e6: 8b 4d 08 mov 0x8(%ebp),%ecx
e9: 8b 5d 0c mov 0xc(%ebp),%ebx
ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while ((*s++ = *t++) != 0) {
f0: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
f4: 88 14 01 mov %dl,(%ecx,%eax,1)
f7: 83 c0 01 add $0x1,%eax
fa: 84 d2 test %dl,%dl
fc: 75 f2 jne f0 <strcpy+0x10>
;
}
return os;
}
fe: 8b 5d fc mov -0x4(%ebp),%ebx
101: 89 c8 mov %ecx,%eax
103: c9 leave
104: c3 ret
105: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
10c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000110 <strcmp>:
int strcmp(const char *p, const char *q) {
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 53 push %ebx
114: 8b 55 08 mov 0x8(%ebp),%edx
117: 8b 4d 0c mov 0xc(%ebp),%ecx
while (*p && *p == *q) {
11a: 0f b6 02 movzbl (%edx),%eax
11d: 84 c0 test %al,%al
11f: 75 17 jne 138 <strcmp+0x28>
121: eb 3a jmp 15d <strcmp+0x4d>
123: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
127: 90 nop
128: 0f b6 42 01 movzbl 0x1(%edx),%eax
p++, q++;
12c: 83 c2 01 add $0x1,%edx
12f: 8d 59 01 lea 0x1(%ecx),%ebx
while (*p && *p == *q) {
132: 84 c0 test %al,%al
134: 74 1a je 150 <strcmp+0x40>
p++, q++;
136: 89 d9 mov %ebx,%ecx
while (*p && *p == *q) {
138: 0f b6 19 movzbl (%ecx),%ebx
13b: 38 c3 cmp %al,%bl
13d: 74 e9 je 128 <strcmp+0x18>
}
return (uchar) * p - (uchar) * q;
13f: 29 d8 sub %ebx,%eax
}
141: 8b 5d fc mov -0x4(%ebp),%ebx
144: c9 leave
145: c3 ret
146: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
14d: 8d 76 00 lea 0x0(%esi),%esi
return (uchar) * p - (uchar) * q;
150: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
154: 31 c0 xor %eax,%eax
156: 29 d8 sub %ebx,%eax
}
158: 8b 5d fc mov -0x4(%ebp),%ebx
15b: c9 leave
15c: c3 ret
return (uchar) * p - (uchar) * q;
15d: 0f b6 19 movzbl (%ecx),%ebx
160: 31 c0 xor %eax,%eax
162: eb db jmp 13f <strcmp+0x2f>
164: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
16b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
16f: 90 nop
00000170 <strlen>:
uint strlen(const char *s) {
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for (n = 0; s[n]; n++) {
176: 80 3a 00 cmpb $0x0,(%edx)
179: 74 15 je 190 <strlen+0x20>
17b: 31 c0 xor %eax,%eax
17d: 8d 76 00 lea 0x0(%esi),%esi
180: 83 c0 01 add $0x1,%eax
183: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
187: 89 c1 mov %eax,%ecx
189: 75 f5 jne 180 <strlen+0x10>
;
}
return n;
}
18b: 89 c8 mov %ecx,%eax
18d: 5d pop %ebp
18e: c3 ret
18f: 90 nop
for (n = 0; s[n]; n++) {
190: 31 c9 xor %ecx,%ecx
}
192: 5d pop %ebp
193: 89 c8 mov %ecx,%eax
195: c3 ret
196: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
19d: 8d 76 00 lea 0x0(%esi),%esi
000001a0 <memset>:
void* memset(void *dst, int c, uint n) {
1a0: 55 push %ebp
1a1: 89 e5 mov %esp,%ebp
1a3: 57 push %edi
1a4: 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" :
1a7: 8b 4d 10 mov 0x10(%ebp),%ecx
1aa: 8b 45 0c mov 0xc(%ebp),%eax
1ad: 89 d7 mov %edx,%edi
1af: fc cld
1b0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1b2: 8b 7d fc mov -0x4(%ebp),%edi
1b5: 89 d0 mov %edx,%eax
1b7: c9 leave
1b8: c3 ret
1b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000001c0 <strchr>:
char* strchr(const char *s, char c) {
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 8b 45 08 mov 0x8(%ebp),%eax
1c6: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for (; *s; s++) {
1ca: 0f b6 10 movzbl (%eax),%edx
1cd: 84 d2 test %dl,%dl
1cf: 75 12 jne 1e3 <strchr+0x23>
1d1: eb 1d jmp 1f0 <strchr+0x30>
1d3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1d7: 90 nop
1d8: 0f b6 50 01 movzbl 0x1(%eax),%edx
1dc: 83 c0 01 add $0x1,%eax
1df: 84 d2 test %dl,%dl
1e1: 74 0d je 1f0 <strchr+0x30>
if (*s == c) {
1e3: 38 d1 cmp %dl,%cl
1e5: 75 f1 jne 1d8 <strchr+0x18>
return (char*)s;
}
}
return 0;
}
1e7: 5d pop %ebp
1e8: c3 ret
1e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
1f0: 31 c0 xor %eax,%eax
}
1f2: 5d pop %ebp
1f3: c3 ret
1f4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1fb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1ff: 90 nop
00000200 <gets>:
char* gets(char *buf, int max) {
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 57 push %edi
204: 56 push %esi
int i, cc;
char c;
for (i = 0; i + 1 < max;) {
cc = read(0, &c, 1);
205: 8d 7d e7 lea -0x19(%ebp),%edi
char* gets(char *buf, int max) {
208: 53 push %ebx
for (i = 0; i + 1 < max;) {
209: 31 db xor %ebx,%ebx
char* gets(char *buf, int max) {
20b: 83 ec 1c sub $0x1c,%esp
for (i = 0; i + 1 < max;) {
20e: eb 27 jmp 237 <gets+0x37>
cc = read(0, &c, 1);
210: 83 ec 04 sub $0x4,%esp
213: 6a 01 push $0x1
215: 57 push %edi
216: 6a 00 push $0x0
218: e8 2e 01 00 00 call 34b <read>
if (cc < 1) {
21d: 83 c4 10 add $0x10,%esp
220: 85 c0 test %eax,%eax
222: 7e 1d jle 241 <gets+0x41>
break;
}
buf[i++] = c;
224: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
228: 8b 55 08 mov 0x8(%ebp),%edx
22b: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if (c == '\n' || c == '\r') {
22f: 3c 0a cmp $0xa,%al
231: 74 1d je 250 <gets+0x50>
233: 3c 0d cmp $0xd,%al
235: 74 19 je 250 <gets+0x50>
for (i = 0; i + 1 < max;) {
237: 89 de mov %ebx,%esi
239: 83 c3 01 add $0x1,%ebx
23c: 3b 5d 0c cmp 0xc(%ebp),%ebx
23f: 7c cf jl 210 <gets+0x10>
break;
}
}
buf[i] = '\0';
241: 8b 45 08 mov 0x8(%ebp),%eax
244: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
248: 8d 65 f4 lea -0xc(%ebp),%esp
24b: 5b pop %ebx
24c: 5e pop %esi
24d: 5f pop %edi
24e: 5d pop %ebp
24f: c3 ret
buf[i] = '\0';
250: 8b 45 08 mov 0x8(%ebp),%eax
253: 89 de mov %ebx,%esi
255: c6 04 30 00 movb $0x0,(%eax,%esi,1)
}
259: 8d 65 f4 lea -0xc(%ebp),%esp
25c: 5b pop %ebx
25d: 5e pop %esi
25e: 5f pop %edi
25f: 5d pop %ebp
260: c3 ret
261: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
268: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
26f: 90 nop
00000270 <stat>:
int stat(const char *n, struct stat *st) {
270: 55 push %ebp
271: 89 e5 mov %esp,%ebp
273: 56 push %esi
274: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
275: 83 ec 08 sub $0x8,%esp
278: 6a 00 push $0x0
27a: ff 75 08 push 0x8(%ebp)
27d: e8 19 01 00 00 call 39b <open>
if (fd < 0) {
282: 83 c4 10 add $0x10,%esp
285: 85 c0 test %eax,%eax
287: 78 27 js 2b0 <stat+0x40>
return -1;
}
r = fstat(fd, st);
289: 83 ec 08 sub $0x8,%esp
28c: ff 75 0c push 0xc(%ebp)
28f: 89 c3 mov %eax,%ebx
291: 50 push %eax
292: e8 cc 00 00 00 call 363 <fstat>
close(fd);
297: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
29a: 89 c6 mov %eax,%esi
close(fd);
29c: e8 2a 01 00 00 call 3cb <close>
return r;
2a1: 83 c4 10 add $0x10,%esp
}
2a4: 8d 65 f8 lea -0x8(%ebp),%esp
2a7: 89 f0 mov %esi,%eax
2a9: 5b pop %ebx
2aa: 5e pop %esi
2ab: 5d pop %ebp
2ac: c3 ret
2ad: 8d 76 00 lea 0x0(%esi),%esi
return -1;
2b0: be ff ff ff ff mov $0xffffffff,%esi
2b5: eb ed jmp 2a4 <stat+0x34>
2b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2be: 66 90 xchg %ax,%ax
000002c0 <atoi>:
int atoi(const char *s) {
2c0: 55 push %ebp
2c1: 89 e5 mov %esp,%ebp
2c3: 53 push %ebx
2c4: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while ('0' <= *s && *s <= '9') {
2c7: 0f be 02 movsbl (%edx),%eax
2ca: 8d 48 d0 lea -0x30(%eax),%ecx
2cd: 80 f9 09 cmp $0x9,%cl
n = 0;
2d0: b9 00 00 00 00 mov $0x0,%ecx
while ('0' <= *s && *s <= '9') {
2d5: 77 1e ja 2f5 <atoi+0x35>
2d7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2de: 66 90 xchg %ax,%ax
n = n * 10 + *s++ - '0';
2e0: 83 c2 01 add $0x1,%edx
2e3: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
2e6: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while ('0' <= *s && *s <= '9') {
2ea: 0f be 02 movsbl (%edx),%eax
2ed: 8d 58 d0 lea -0x30(%eax),%ebx
2f0: 80 fb 09 cmp $0x9,%bl
2f3: 76 eb jbe 2e0 <atoi+0x20>
}
return n;
}
2f5: 8b 5d fc mov -0x4(%ebp),%ebx
2f8: 89 c8 mov %ecx,%eax
2fa: c9 leave
2fb: c3 ret
2fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000300 <memmove>:
void* memmove(void *vdst, const void *vsrc, int n) {
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 57 push %edi
304: 8b 45 10 mov 0x10(%ebp),%eax
307: 8b 55 08 mov 0x8(%ebp),%edx
30a: 56 push %esi
30b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while (n-- > 0) {
30e: 85 c0 test %eax,%eax
310: 7e 13 jle 325 <memmove+0x25>
312: 01 d0 add %edx,%eax
dst = vdst;
314: 89 d7 mov %edx,%edi
316: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
31d: 8d 76 00 lea 0x0(%esi),%esi
*dst++ = *src++;
320: a4 movsb %ds:(%esi),%es:(%edi)
while (n-- > 0) {
321: 39 f8 cmp %edi,%eax
323: 75 fb jne 320 <memmove+0x20>
}
return vdst;
}
325: 5e pop %esi
326: 89 d0 mov %edx,%eax
328: 5f pop %edi
329: 5d pop %ebp
32a: c3 ret
0000032b <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
32b: b8 01 00 00 00 mov $0x1,%eax
330: cd 40 int $0x40
332: c3 ret
00000333 <exit>:
SYSCALL(exit)
333: b8 02 00 00 00 mov $0x2,%eax
338: cd 40 int $0x40
33a: c3 ret
0000033b <wait>:
SYSCALL(wait)
33b: b8 03 00 00 00 mov $0x3,%eax
340: cd 40 int $0x40
342: c3 ret
00000343 <pipe>:
SYSCALL(pipe)
343: b8 04 00 00 00 mov $0x4,%eax
348: cd 40 int $0x40
34a: c3 ret
0000034b <read>:
SYSCALL(read)
34b: b8 05 00 00 00 mov $0x5,%eax
350: cd 40 int $0x40
352: c3 ret
00000353 <kill>:
SYSCALL(kill)
353: b8 06 00 00 00 mov $0x6,%eax
358: cd 40 int $0x40
35a: c3 ret
0000035b <exec>:
SYSCALL(exec)
35b: b8 07 00 00 00 mov $0x7,%eax
360: cd 40 int $0x40
362: c3 ret
00000363 <fstat>:
SYSCALL(fstat)
363: b8 08 00 00 00 mov $0x8,%eax
368: cd 40 int $0x40
36a: c3 ret
0000036b <chdir>:
SYSCALL(chdir)
36b: b8 09 00 00 00 mov $0x9,%eax
370: cd 40 int $0x40
372: c3 ret
00000373 <dup>:
SYSCALL(dup)
373: b8 0a 00 00 00 mov $0xa,%eax
378: cd 40 int $0x40
37a: c3 ret
0000037b <getpid>:
SYSCALL(getpid)
37b: b8 0b 00 00 00 mov $0xb,%eax
380: cd 40 int $0x40
382: c3 ret
00000383 <sbrk>:
SYSCALL(sbrk)
383: b8 0c 00 00 00 mov $0xc,%eax
388: cd 40 int $0x40
38a: c3 ret
0000038b <sleep>:
SYSCALL(sleep)
38b: b8 0d 00 00 00 mov $0xd,%eax
390: cd 40 int $0x40
392: c3 ret
00000393 <uptime>:
SYSCALL(uptime)
393: b8 0e 00 00 00 mov $0xe,%eax
398: cd 40 int $0x40
39a: c3 ret
0000039b <open>:
SYSCALL(open)
39b: b8 0f 00 00 00 mov $0xf,%eax
3a0: cd 40 int $0x40
3a2: c3 ret
000003a3 <write>:
SYSCALL(write)
3a3: b8 10 00 00 00 mov $0x10,%eax
3a8: cd 40 int $0x40
3aa: c3 ret
000003ab <mknod>:
SYSCALL(mknod)
3ab: b8 11 00 00 00 mov $0x11,%eax
3b0: cd 40 int $0x40
3b2: c3 ret
000003b3 <unlink>:
SYSCALL(unlink)
3b3: b8 12 00 00 00 mov $0x12,%eax
3b8: cd 40 int $0x40
3ba: c3 ret
000003bb <link>:
SYSCALL(link)
3bb: b8 13 00 00 00 mov $0x13,%eax
3c0: cd 40 int $0x40
3c2: c3 ret
000003c3 <mkdir>:
SYSCALL(mkdir)
3c3: b8 14 00 00 00 mov $0x14,%eax
3c8: cd 40 int $0x40
3ca: c3 ret
000003cb <close>:
SYSCALL(close)
3cb: b8 15 00 00 00 mov $0x15,%eax
3d0: cd 40 int $0x40
3d2: c3 ret
000003d3 <getch>:
SYSCALL(getch)
3d3: b8 16 00 00 00 mov $0x16,%eax
3d8: cd 40 int $0x40
3da: c3 ret
000003db <greeting>:
SYSCALL(greeting)
3db: b8 17 00 00 00 mov $0x17,%eax
3e0: cd 40 int $0x40
3e2: c3 ret
000003e3 <shutdown>:
SYSCALL(shutdown)
3e3: b8 18 00 00 00 mov $0x18,%eax
3e8: cd 40 int $0x40
3ea: c3 ret
3eb: 66 90 xchg %ax,%ax
3ed: 66 90 xchg %ax,%ax
3ef: 90 nop
000003f0 <printint>:
static void putc(int fd, char c) {
write(fd, &c, 1);
}
static void printint(int fd, int xx, int base, int sgn) {
3f0: 55 push %ebp
3f1: 89 e5 mov %esp,%ebp
3f3: 57 push %edi
3f4: 56 push %esi
3f5: 53 push %ebx
3f6: 83 ec 3c sub $0x3c,%esp
3f9: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if (sgn && xx < 0) {
neg = 1;
x = -xx;
3fc: 89 d1 mov %edx,%ecx
static void printint(int fd, int xx, int base, int sgn) {
3fe: 89 45 b8 mov %eax,-0x48(%ebp)
if (sgn && xx < 0) {
401: 85 d2 test %edx,%edx
403: 0f 89 7f 00 00 00 jns 488 <printint+0x98>
409: f6 45 08 01 testb $0x1,0x8(%ebp)
40d: 74 79 je 488 <printint+0x98>
neg = 1;
40f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
416: f7 d9 neg %ecx
}
else {
x = xx;
}
i = 0;
418: 31 db xor %ebx,%ebx
41a: 8d 75 d7 lea -0x29(%ebp),%esi
41d: 8d 76 00 lea 0x0(%esi),%esi
do {
buf[i++] = digits[x % base];
420: 89 c8 mov %ecx,%eax
422: 31 d2 xor %edx,%edx
424: 89 cf mov %ecx,%edi
426: f7 75 c4 divl -0x3c(%ebp)
429: 0f b6 92 70 08 00 00 movzbl 0x870(%edx),%edx
430: 89 45 c0 mov %eax,-0x40(%ebp)
433: 89 d8 mov %ebx,%eax
435: 8d 5b 01 lea 0x1(%ebx),%ebx
}
while ((x /= base) != 0);
438: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
43b: 88 14 1e mov %dl,(%esi,%ebx,1)
while ((x /= base) != 0);
43e: 39 7d c4 cmp %edi,-0x3c(%ebp)
441: 76 dd jbe 420 <printint+0x30>
if (neg) {
443: 8b 4d bc mov -0x44(%ebp),%ecx
446: 85 c9 test %ecx,%ecx
448: 74 0c je 456 <printint+0x66>
buf[i++] = '-';
44a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
44f: 89 d8 mov %ebx,%eax
buf[i++] = '-';
451: ba 2d 00 00 00 mov $0x2d,%edx
}
while (--i >= 0) {
456: 8b 7d b8 mov -0x48(%ebp),%edi
459: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
45d: eb 07 jmp 466 <printint+0x76>
45f: 90 nop
putc(fd, buf[i]);
460: 0f b6 13 movzbl (%ebx),%edx
463: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
466: 83 ec 04 sub $0x4,%esp
469: 88 55 d7 mov %dl,-0x29(%ebp)
46c: 6a 01 push $0x1
46e: 56 push %esi
46f: 57 push %edi
470: e8 2e ff ff ff call 3a3 <write>
while (--i >= 0) {
475: 83 c4 10 add $0x10,%esp
478: 39 de cmp %ebx,%esi
47a: 75 e4 jne 460 <printint+0x70>
}
}
47c: 8d 65 f4 lea -0xc(%ebp),%esp
47f: 5b pop %ebx
480: 5e pop %esi
481: 5f pop %edi
482: 5d pop %ebp
483: c3 ret
484: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
488: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
48f: eb 87 jmp 418 <printint+0x28>
491: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
498: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
49f: 90 nop
000004a0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void printf(int fd, const char *fmt, ...) {
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 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for (i = 0; fmt[i]; i++) {
4a9: 8b 5d 0c mov 0xc(%ebp),%ebx
void printf(int fd, const char *fmt, ...) {
4ac: 8b 75 08 mov 0x8(%ebp),%esi
for (i = 0; fmt[i]; i++) {
4af: 0f b6 13 movzbl (%ebx),%edx
4b2: 84 d2 test %dl,%dl
4b4: 74 6a je 520 <printf+0x80>
ap = (uint*)(void*)&fmt + 1;
4b6: 8d 45 10 lea 0x10(%ebp),%eax
4b9: 83 c3 01 add $0x1,%ebx
write(fd, &c, 1);
4bc: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
4bf: 31 c9 xor %ecx,%ecx
ap = (uint*)(void*)&fmt + 1;
4c1: 89 45 d0 mov %eax,-0x30(%ebp)
4c4: eb 36 jmp 4fc <printf+0x5c>
4c6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4cd: 8d 76 00 lea 0x0(%esi),%esi
4d0: 89 4d d4 mov %ecx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if (state == 0) {
if (c == '%') {
state = '%';
4d3: b9 25 00 00 00 mov $0x25,%ecx
if (c == '%') {
4d8: 83 f8 25 cmp $0x25,%eax
4db: 74 15 je 4f2 <printf+0x52>
write(fd, &c, 1);
4dd: 83 ec 04 sub $0x4,%esp
4e0: 88 55 e7 mov %dl,-0x19(%ebp)
4e3: 6a 01 push $0x1
4e5: 57 push %edi
4e6: 56 push %esi
4e7: e8 b7 fe ff ff call 3a3 <write>
4ec: 8b 4d d4 mov -0x2c(%ebp),%ecx
}
else {
putc(fd, c);
4ef: 83 c4 10 add $0x10,%esp
for (i = 0; fmt[i]; i++) {
4f2: 0f b6 13 movzbl (%ebx),%edx
4f5: 83 c3 01 add $0x1,%ebx
4f8: 84 d2 test %dl,%dl
4fa: 74 24 je 520 <printf+0x80>
c = fmt[i] & 0xff;
4fc: 0f b6 c2 movzbl %dl,%eax
if (state == 0) {
4ff: 85 c9 test %ecx,%ecx
501: 74 cd je 4d0 <printf+0x30>
}
}
else if (state == '%') {
503: 83 f9 25 cmp $0x25,%ecx
506: 75 ea jne 4f2 <printf+0x52>
if (c == 'd') {
508: 83 f8 25 cmp $0x25,%eax
50b: 0f 84 07 01 00 00 je 618 <printf+0x178>
511: 83 e8 63 sub $0x63,%eax
514: 83 f8 15 cmp $0x15,%eax
517: 77 17 ja 530 <printf+0x90>
519: ff 24 85 18 08 00 00 jmp *0x818(,%eax,4)
putc(fd, c);
}
state = 0;
}
}
}
520: 8d 65 f4 lea -0xc(%ebp),%esp
523: 5b pop %ebx
524: 5e pop %esi
525: 5f pop %edi
526: 5d pop %ebp
527: c3 ret
528: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
52f: 90 nop
write(fd, &c, 1);
530: 83 ec 04 sub $0x4,%esp
533: 88 55 d4 mov %dl,-0x2c(%ebp)
536: 6a 01 push $0x1
538: 57 push %edi
539: 56 push %esi
53a: c6 45 e7 25 movb $0x25,-0x19(%ebp)
53e: e8 60 fe ff ff call 3a3 <write>
putc(fd, c);
543: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx
write(fd, &c, 1);
547: 83 c4 0c add $0xc,%esp
54a: 88 55 e7 mov %dl,-0x19(%ebp)
54d: 6a 01 push $0x1
54f: 57 push %edi
550: 56 push %esi
551: e8 4d fe ff ff call 3a3 <write>
putc(fd, c);
556: 83 c4 10 add $0x10,%esp
state = 0;
559: 31 c9 xor %ecx,%ecx
55b: eb 95 jmp 4f2 <printf+0x52>
55d: 8d 76 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
560: 83 ec 0c sub $0xc,%esp
563: b9 10 00 00 00 mov $0x10,%ecx
568: 6a 00 push $0x0
56a: 8b 45 d0 mov -0x30(%ebp),%eax
56d: 8b 10 mov (%eax),%edx
56f: 89 f0 mov %esi,%eax
571: e8 7a fe ff ff call 3f0 <printint>
ap++;
576: 83 45 d0 04 addl $0x4,-0x30(%ebp)
57a: 83 c4 10 add $0x10,%esp
state = 0;
57d: 31 c9 xor %ecx,%ecx
57f: e9 6e ff ff ff jmp 4f2 <printf+0x52>
584: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
588: 8b 45 d0 mov -0x30(%ebp),%eax
58b: 8b 10 mov (%eax),%edx
ap++;
58d: 83 c0 04 add $0x4,%eax
590: 89 45 d0 mov %eax,-0x30(%ebp)
if (s == 0) {
593: 85 d2 test %edx,%edx
595: 0f 84 8d 00 00 00 je 628 <printf+0x188>
while (*s != 0) {
59b: 0f b6 02 movzbl (%edx),%eax
state = 0;
59e: 31 c9 xor %ecx,%ecx
while (*s != 0) {
5a0: 84 c0 test %al,%al
5a2: 0f 84 4a ff ff ff je 4f2 <printf+0x52>
5a8: 89 5d d4 mov %ebx,-0x2c(%ebp)
5ab: 89 d3 mov %edx,%ebx
5ad: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
5b0: 83 ec 04 sub $0x4,%esp
s++;
5b3: 83 c3 01 add $0x1,%ebx
5b6: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
5b9: 6a 01 push $0x1
5bb: 57 push %edi
5bc: 56 push %esi
5bd: e8 e1 fd ff ff call 3a3 <write>
while (*s != 0) {
5c2: 0f b6 03 movzbl (%ebx),%eax
5c5: 83 c4 10 add $0x10,%esp
5c8: 84 c0 test %al,%al
5ca: 75 e4 jne 5b0 <printf+0x110>
state = 0;
5cc: 8b 5d d4 mov -0x2c(%ebp),%ebx
5cf: 31 c9 xor %ecx,%ecx
5d1: e9 1c ff ff ff jmp 4f2 <printf+0x52>
5d6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5dd: 8d 76 00 lea 0x0(%esi),%esi
printint(fd, *ap, 10, 1);
5e0: 83 ec 0c sub $0xc,%esp
5e3: b9 0a 00 00 00 mov $0xa,%ecx
5e8: 6a 01 push $0x1
5ea: e9 7b ff ff ff jmp 56a <printf+0xca>
5ef: 90 nop
putc(fd, *ap);
5f0: 8b 45 d0 mov -0x30(%ebp),%eax
write(fd, &c, 1);
5f3: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
5f6: 8b 00 mov (%eax),%eax
write(fd, &c, 1);
5f8: 6a 01 push $0x1
5fa: 57 push %edi
5fb: 56 push %esi
putc(fd, *ap);
5fc: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
5ff: e8 9f fd ff ff call 3a3 <write>
ap++;
604: 83 45 d0 04 addl $0x4,-0x30(%ebp)
608: 83 c4 10 add $0x10,%esp
state = 0;
60b: 31 c9 xor %ecx,%ecx
60d: e9 e0 fe ff ff jmp 4f2 <printf+0x52>
612: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
putc(fd, c);
618: 88 55 e7 mov %dl,-0x19(%ebp)
write(fd, &c, 1);
61b: 83 ec 04 sub $0x4,%esp
61e: e9 2a ff ff ff jmp 54d <printf+0xad>
623: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
627: 90 nop
s = "(null)";
628: ba 0f 08 00 00 mov $0x80f,%edx
while (*s != 0) {
62d: 89 5d d4 mov %ebx,-0x2c(%ebp)
630: b8 28 00 00 00 mov $0x28,%eax
635: 89 d3 mov %edx,%ebx
637: e9 74 ff ff ff jmp 5b0 <printf+0x110>
63c: 66 90 xchg %ax,%ax
63e: 66 90 xchg %ax,%ax
00000640 <free>:
typedef union header Header;
static Header base;
static Header *freep;
void free(void *ap) {
640: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) {
641: a1 24 0b 00 00 mov 0xb24,%eax
void free(void *ap) {
646: 89 e5 mov %esp,%ebp
648: 57 push %edi
649: 56 push %esi
64a: 53 push %ebx
64b: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
64e: 8d 4b f8 lea -0x8(%ebx),%ecx
for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) {
651: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
658: 89 c2 mov %eax,%edx
65a: 8b 00 mov (%eax),%eax
65c: 39 ca cmp %ecx,%edx
65e: 73 30 jae 690 <free+0x50>
660: 39 c1 cmp %eax,%ecx
662: 72 04 jb 668 <free+0x28>
if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) {
664: 39 c2 cmp %eax,%edx
666: 72 f0 jb 658 <free+0x18>
break;
}
}
if (bp + bp->s.size == p->s.ptr) {
668: 8b 73 fc mov -0x4(%ebx),%esi
66b: 8d 3c f1 lea (%ecx,%esi,8),%edi
66e: 39 f8 cmp %edi,%eax
670: 74 30 je 6a2 <free+0x62>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
672: 89 43 f8 mov %eax,-0x8(%ebx)
}
else {
bp->s.ptr = p->s.ptr;
}
if (p + p->s.size == bp) {
675: 8b 42 04 mov 0x4(%edx),%eax
678: 8d 34 c2 lea (%edx,%eax,8),%esi
67b: 39 f1 cmp %esi,%ecx
67d: 74 3a je 6b9 <free+0x79>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
67f: 89 0a mov %ecx,(%edx)
}
else {
p->s.ptr = bp;
}
freep = p;
}
681: 5b pop %ebx
freep = p;
682: 89 15 24 0b 00 00 mov %edx,0xb24
}
688: 5e pop %esi
689: 5f pop %edi
68a: 5d pop %ebp
68b: c3 ret
68c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) {
690: 39 c2 cmp %eax,%edx
692: 72 c4 jb 658 <free+0x18>
694: 39 c1 cmp %eax,%ecx
696: 73 c0 jae 658 <free+0x18>
if (bp + bp->s.size == p->s.ptr) {
698: 8b 73 fc mov -0x4(%ebx),%esi
69b: 8d 3c f1 lea (%ecx,%esi,8),%edi
69e: 39 f8 cmp %edi,%eax
6a0: 75 d0 jne 672 <free+0x32>
bp->s.size += p->s.ptr->s.size;
6a2: 03 70 04 add 0x4(%eax),%esi
6a5: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
6a8: 8b 02 mov (%edx),%eax
6aa: 8b 00 mov (%eax),%eax
6ac: 89 43 f8 mov %eax,-0x8(%ebx)
if (p + p->s.size == bp) {
6af: 8b 42 04 mov 0x4(%edx),%eax
6b2: 8d 34 c2 lea (%edx,%eax,8),%esi
6b5: 39 f1 cmp %esi,%ecx
6b7: 75 c6 jne 67f <free+0x3f>
p->s.size += bp->s.size;
6b9: 03 43 fc add -0x4(%ebx),%eax
freep = p;
6bc: 89 15 24 0b 00 00 mov %edx,0xb24
p->s.size += bp->s.size;
6c2: 89 42 04 mov %eax,0x4(%edx)
p->s.ptr = bp->s.ptr;
6c5: 8b 4b f8 mov -0x8(%ebx),%ecx
6c8: 89 0a mov %ecx,(%edx)
}
6ca: 5b pop %ebx
6cb: 5e pop %esi
6cc: 5f pop %edi
6cd: 5d pop %ebp
6ce: c3 ret
6cf: 90 nop
000006d0 <malloc>:
hp->s.size = nu;
free((void*)(hp + 1));
return freep;
}
void* malloc(uint nbytes) {
6d0: 55 push %ebp
6d1: 89 e5 mov %esp,%ebp
6d3: 57 push %edi
6d4: 56 push %esi
6d5: 53 push %ebx
6d6: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
6d9: 8b 45 08 mov 0x8(%ebp),%eax
if ((prevp = freep) == 0) {
6dc: 8b 3d 24 0b 00 00 mov 0xb24,%edi
nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
6e2: 8d 70 07 lea 0x7(%eax),%esi
6e5: c1 ee 03 shr $0x3,%esi
6e8: 83 c6 01 add $0x1,%esi
if ((prevp = freep) == 0) {
6eb: 85 ff test %edi,%edi
6ed: 0f 84 9d 00 00 00 je 790 <malloc+0xc0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) {
6f3: 8b 17 mov (%edi),%edx
if (p->s.size >= nunits) {
6f5: 8b 4a 04 mov 0x4(%edx),%ecx
6f8: 39 f1 cmp %esi,%ecx
6fa: 73 6a jae 766 <malloc+0x96>
6fc: bb 00 10 00 00 mov $0x1000,%ebx
701: 39 de cmp %ebx,%esi
703: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
706: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax
70d: 89 45 e4 mov %eax,-0x1c(%ebp)
710: eb 17 jmp 729 <malloc+0x59>
712: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) {
718: 8b 02 mov (%edx),%eax
if (p->s.size >= nunits) {
71a: 8b 48 04 mov 0x4(%eax),%ecx
71d: 39 f1 cmp %esi,%ecx
71f: 73 4f jae 770 <malloc+0xa0>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if (p == freep) {
721: 8b 3d 24 0b 00 00 mov 0xb24,%edi
727: 89 c2 mov %eax,%edx
729: 39 d7 cmp %edx,%edi
72b: 75 eb jne 718 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
72d: 83 ec 0c sub $0xc,%esp
730: ff 75 e4 push -0x1c(%ebp)
733: e8 4b fc ff ff call 383 <sbrk>
if (p == (char*)-1) {
738: 83 c4 10 add $0x10,%esp
73b: 83 f8 ff cmp $0xffffffff,%eax
73e: 74 1c je 75c <malloc+0x8c>
hp->s.size = nu;
740: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
743: 83 ec 0c sub $0xc,%esp
746: 83 c0 08 add $0x8,%eax
749: 50 push %eax
74a: e8 f1 fe ff ff call 640 <free>
return freep;
74f: 8b 15 24 0b 00 00 mov 0xb24,%edx
if ((p = morecore(nunits)) == 0) {
755: 83 c4 10 add $0x10,%esp
758: 85 d2 test %edx,%edx
75a: 75 bc jne 718 <malloc+0x48>
return 0;
}
}
}
}
75c: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
75f: 31 c0 xor %eax,%eax
}
761: 5b pop %ebx
762: 5e pop %esi
763: 5f pop %edi
764: 5d pop %ebp
765: c3 ret
if (p->s.size >= nunits) {
766: 89 d0 mov %edx,%eax
768: 89 fa mov %edi,%edx
76a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if (p->s.size == nunits) {
770: 39 ce cmp %ecx,%esi
772: 74 4c je 7c0 <malloc+0xf0>
p->s.size -= nunits;
774: 29 f1 sub %esi,%ecx
776: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
779: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
77c: 89 70 04 mov %esi,0x4(%eax)
freep = prevp;
77f: 89 15 24 0b 00 00 mov %edx,0xb24
}
785: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
788: 83 c0 08 add $0x8,%eax
}
78b: 5b pop %ebx
78c: 5e pop %esi
78d: 5f pop %edi
78e: 5d pop %ebp
78f: c3 ret
base.s.ptr = freep = prevp = &base;
790: c7 05 24 0b 00 00 28 movl $0xb28,0xb24
797: 0b 00 00
base.s.size = 0;
79a: bf 28 0b 00 00 mov $0xb28,%edi
base.s.ptr = freep = prevp = &base;
79f: c7 05 28 0b 00 00 28 movl $0xb28,0xb28
7a6: 0b 00 00
for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) {
7a9: 89 fa mov %edi,%edx
base.s.size = 0;
7ab: c7 05 2c 0b 00 00 00 movl $0x0,0xb2c
7b2: 00 00 00
if (p->s.size >= nunits) {
7b5: e9 42 ff ff ff jmp 6fc <malloc+0x2c>
7ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
7c0: 8b 08 mov (%eax),%ecx
7c2: 89 0a mov %ecx,(%edx)
7c4: eb b9 jmp 77f <malloc+0xaf>