kern

view src/test_proc.S @ 75:8b21fe04ba2c

testing of the exit syscall
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Oct 2011 08:07:09 +0300
parents c7bd6ec7b946
children
line source
1 #define ASM
2 #include <syscall.h>
4 .text
5 .globl test_proc
6 test_proc:
7 /* fork another process */
8 movl $SYS_FORK, %eax
9 int $SYSCALL_INT
11 /* test copy-on-write by pushing the pid to the stack
12 * then use this value from the stack times 2 as a sleep
13 * interval in the loop.
14 */
15 movl $SYS_GETPID, %eax
16 int $SYSCALL_INT
17 push %eax
19 /* this will count the iterations */
20 xor %ecx, %ecx
22 infloop:
23 /* --- print a message --- */
24 movl $SYS_HELLO, %eax
25 int $SYSCALL_INT
28 /* --- sleep for (pid * 2) seconds ---
29 * grab the pid from the stack and shift it left to
30 * multiply the pid by 2. Then use that as a sleep interval
31 * in seconds.
32 */
33 movl (%esp), %ebx
34 shl $1, %ebx
35 movl $SYS_SLEEP, %eax
36 int $SYSCALL_INT
38 inc %ecx
40 /* let process 2 quit after 2 iterations */
41 cmpl $2, (%esp)
42 jne 1f
43 cmpl $2, %ecx
44 je exit_proc
46 1:
47 jmp infloop
49 exit_proc:
50 movl $SYS_EXIT, %eax
51 movl $0, %ebx
52 int $SYSCALL_INT
54 /* shouldn't reach this, trap otherwise */
55 int $3
57 .globl test_proc_end
58 test_proc_end: