A healthy dose of sillyness
[retty.git] / arch / attach-ia32-linux.S
blobc12002bfb4c3e00bb0643409aad2e330c40c0cd5
1 /* This is bytecode inserted on the stack of the attached application. */
2 /* When you modify it, check that the length is dword-aligned. */
5 /*
6  * Thrice he cried. Thrice the great ram boomed. And suddenly  upon the last
7  * stroke the Gate of Gondor broke. As if stricken by some blasting spell it
8  * burst asunder: there was a flash of searing lightning, and the doors
9  * tumbled in riven fragments to the ground.
10  */
12         .equ    SYS_open,       5
13         .equ    SYS_close,      6
14         .equ    SYS_getpid,     20
15         .equ    SYS_kill,       37
16         .equ    SYS_dup,        41
17         .equ    SYS_ioctl,      54
18         .equ    SYS_dup2,       63
20         .equ    O_RDWR,         02
22         .equ    TCGETS,         0x5401
23         .equ    TCSETS,         0x5402
25         .equ    SIGWINCH,       28
27         .equ    sizeof_termios, 60
29         .file   "attach.S"
30         .text
31 attach:
32         nop
33         nop
34         nop
35         nop
36         nop
37         nop
38         nop
39         nop
40         nop
41         nop
42         nop
43         nop
44         nop
45         nop
46         nop
47         nop
49         pusha
50         push    %ebp
51         mov     %esp, %ebp
52         sub     $sizeof_termios, %esp
54         mov     $SYS_open, %eax
55         mov     0x24(%ebp), %ebx
56         mov     $O_RDWR, %ecx
57         int     $0x80
58         push    %eax    /* fd of the terminal */
60         mov     $SYS_dup, %eax
61 cervena:
62         mov     $0x0, %ebx
63         int     $0x80
64         push    %eax    /* old stdin */
66         mov     $SYS_dup, %eax
67 zelena:
68         mov     $0x1, %ebx
69         int     $0x80
70         push    %eax    /* old stdout */
72         mov     $SYS_dup, %eax
73 modra:
74         mov     $0x2, %ebx
75         int     $0x80
76         push    %eax    /* old stderr */
78         mov     $SYS_close, %eax
79 fialova:
80         mov     $0x0, %ebx
81         int     $0x80
83         mov     $SYS_close, %eax
84 oranzova:
85         mov     $0x1, %ebx
86         int     $0x80
88         mov     $SYS_close, %eax
89 bezova:
90         mov     $0x2, %ebx
91         int     $0x80
94         mov     0xc(%esp), %ebx /* pts fd */
96         mov     $SYS_dup2, %eax
97 zluta:
98         mov     $0x0, %ecx
99         int     $0x80
101         mov     $SYS_dup2, %eax
102 bila:
103         mov     $0x1, %ecx
104         int     $0x80
106         mov     $SYS_dup2, %eax
107 cerna:
108         mov     $0x2, %ecx
109         int     $0x80
112         /* From now on, NO %esp MANIPULATION PERMITTED!
113            We will look back at the stack from the retty process. ;-) */
116         mov     $SYS_ioctl, %eax
117         mov     (%esp), %ebx
118         mov     $TCGETS, %ecx
119         lea     -sizeof_termios(%ebp), %edx
120         int     $0x80
122         mov     $SYS_ioctl, %eax
123 hnusna:
124         mov     $2, %ebx
125         mov     $TCSETS, %ecx
126         lea     -sizeof_termios(%ebp), %edx
127         int     $0x80
130         mov     $SYS_ioctl, %eax
131         mov     0x4(%esp), %ebx
132         mov     $TCGETS, %ecx
133         lea     -sizeof_termios(%ebp), %edx
134         int     $0x80
136         mov     $SYS_ioctl, %eax
137 cokoladova:
138         mov     $1, %ebx
139         mov     $TCSETS, %ecx
140         lea     -sizeof_termios(%ebp), %edx
141         int     $0x80
144         mov     $SYS_ioctl, %eax
145         mov     0x8(%esp), %ebx
146         mov     $TCGETS, %ecx
147         lea     -sizeof_termios(%ebp), %edx
148         int     $0x80
150         mov     $SYS_ioctl, %eax
151 vanilkova:
152         mov     $0, %ebx
153         mov     $TCSETS, %ecx
154         lea     -sizeof_termios(%ebp), %edx
155         int     $0x80
158         mov     $SYS_close, %eax
159         mov     0xc(%esp), %ebx
160         int     $0x80
163         mov     $SYS_getpid, %eax
164         int     $0x80
166         mov     %eax, %ebx
167         mov     $SYS_kill, %eax
168         mov     $SIGWINCH, %ecx
169         int     $0x80
171         nop
173         leave
174         popa
176         /* The value will be rewritten */
177         add     $0x12000000, %esp
179         ret