nuclear@51: #define ASM nuclear@51: #include nuclear@44: nuclear@44: .text nuclear@44: .globl test_proc nuclear@44: test_proc: nuclear@57: /* fork another process */ nuclear@57: movl $SYS_FORK, %eax nuclear@57: int $SYSCALL_INT nuclear@57: nuclear@71: /* test copy-on-write by pushing the pid to the stack nuclear@71: * then use this value from the stack times 2 as a sleep nuclear@71: * interval in the loop. nuclear@71: */ nuclear@71: movl $SYS_GETPID, %eax nuclear@71: int $SYSCALL_INT nuclear@69: push %eax nuclear@69: nuclear@75: /* this will count the iterations */ nuclear@75: xor %ecx, %ecx nuclear@75: nuclear@57: infloop: nuclear@44: /* --- print a message --- */ nuclear@44: movl $SYS_HELLO, %eax nuclear@44: int $SYSCALL_INT nuclear@44: nuclear@57: nuclear@60: /* --- sleep for (pid * 2) seconds --- nuclear@71: * grab the pid from the stack and shift it left to nuclear@71: * multiply the pid by 2. Then use that as a sleep interval nuclear@71: * in seconds. nuclear@60: */ nuclear@71: movl (%esp), %ebx nuclear@71: shl $1, %ebx nuclear@44: movl $SYS_SLEEP, %eax nuclear@44: int $SYSCALL_INT nuclear@44: nuclear@75: inc %ecx nuclear@75: nuclear@75: /* let process 2 quit after 2 iterations */ nuclear@75: cmpl $2, (%esp) nuclear@75: jne 1f nuclear@75: cmpl $2, %ecx nuclear@75: je exit_proc nuclear@75: nuclear@75: 1: nuclear@57: jmp infloop nuclear@44: nuclear@75: exit_proc: nuclear@75: movl $SYS_EXIT, %eax nuclear@75: movl $0, %ebx nuclear@75: int $SYSCALL_INT nuclear@75: nuclear@75: /* shouldn't reach this, trap otherwise */ nuclear@75: int $3 nuclear@75: nuclear@44: .globl test_proc_end nuclear@44: test_proc_end: