OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. |
| 5 */ |
| 6 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h
" |
| 7 #include "native_client/src/trusted/service_runtime/nacl_config.h" |
| 8 |
| 9 .text |
| 10 start_of_text: |
| 11 |
| 12 .p2align NACLENTRYALIGN |
| 13 write_num_10: |
| 14 movl 8(%esp), %eax /* number to be printed */ |
| 15 pushl %ebp |
| 16 pushl %ebx /* callee saved */ |
| 17 pushl %edi /* callee saved */ |
| 18 movl %esp, %ebp |
| 19 subl $0x10, %esp /* buffer[0x10] */ |
| 20 movl %ebp, %ebx /* %ebx = &buffer[0x10] (off the end) */ |
| 21 xorl %ecx, %ecx /* %ecx = 0; (byte count) */ |
| 22 |
| 23 movl $10, %edi |
| 24 do_digit_10: |
| 25 xorl %edx, %edx |
| 26 divl %edi /* %edx:%eax div_mod 10 */ |
| 27 addl $'0', %edx /* *--%ebx = remainder + '0' */ |
| 28 subl $1, %ebx |
| 29 movb %dl, (%ebx) |
| 30 addl $1, %ecx /* ++byte_count */ |
| 31 andl %eax, %eax |
| 32 jnz do_digit_10 |
| 33 |
| 34 pushl %ecx |
| 35 pushl %ebx |
| 36 movl 0x10(%ebp), %eax |
| 37 pushl %eax |
| 38 call NACL_SYSCALL_ADDR(NACL_sys_write) |
| 39 addl $12, %esp |
| 40 |
| 41 movl %ebp, %esp |
| 42 popl %edi |
| 43 popl %ebx |
| 44 popl %ebp |
| 45 |
| 46 popl %ecx |
| 47 nacljmp %ecx |
| 48 |
| 49 write_num_16: |
| 50 movl 8(%esp), %eax /* number to be printed */ |
| 51 pushl %ebp |
| 52 pushl %ebx |
| 53 movl %esp, %ebp |
| 54 subl $0x10, %esp |
| 55 movl %ebp, %ebx |
| 56 xorl %ecx, %ecx |
| 57 |
| 58 do_digit_16: |
| 59 movl %eax, %edx |
| 60 andl $0xf, %edx |
| 61 addl $'0', %edx |
| 62 cmpl $(10 + '0'), %edx |
| 63 jl do_digit_not_upper |
| 64 addl $('a'-'0'-10), %edx |
| 65 do_digit_not_upper: |
| 66 subl $1, %ebx |
| 67 movb %dl, (%ebx) |
| 68 addl $1, %ecx |
| 69 shrl $4, %eax |
| 70 jnz do_digit_16 |
| 71 |
| 72 pushl %ecx |
| 73 pushl %ebx |
| 74 movl 0xc(%ebp), %eax |
| 75 pushl %eax |
| 76 call NACL_SYSCALL_ADDR(NACL_sys_write) |
| 77 addl $12, %esp |
| 78 |
| 79 movl %ebp, %esp |
| 80 popl %ebx |
| 81 popl %ebp |
| 82 |
| 83 popl %ecx |
| 84 nacljmp %ecx |
| 85 |
| 86 .p2align NACLENTRYALIGN |
| 87 write_char: |
| 88 movl 4(%esp), %eax |
| 89 movl 8(%esp), %edx |
| 90 push %ebp |
| 91 movl %esp, %ebp |
| 92 subl $4, %esp |
| 93 lea -4(%ebp), %ecx |
| 94 movb %dl, (%ecx) |
| 95 pushl $1 |
| 96 pushl %ecx |
| 97 pushl %eax |
| 98 call NACL_SYSCALL_ADDR(NACL_sys_write) |
| 99 addl $12, %esp |
| 100 movl %ebp, %esp |
| 101 popl %ebp |
| 102 popl %ecx |
| 103 nacljmp %ecx |
| 104 |
| 105 .p2align NACLENTRYALIGN |
| 106 .globl _start |
| 107 _start: |
| 108 pushl $1234567 |
| 109 pushl $1 |
| 110 call write_num_10 |
| 111 addl $8, %esp |
| 112 |
| 113 pushl $'\n' |
| 114 pushl $1 |
| 115 call write_char |
| 116 addl $8, %esp |
| 117 |
| 118 pushl $0xdeadbeef |
| 119 pushl $1 |
| 120 call write_num_16 |
| 121 addl $8, %esp |
| 122 |
| 123 pushl $'\n' |
| 124 pushl $1 |
| 125 call write_char |
| 126 addl $8, %esp |
| 127 |
| 128 pushl $end_of_text |
| 129 pushl $1 |
| 130 call write_num_16 |
| 131 addl $8, %esp |
| 132 pushl $'\n' |
| 133 pushl $1 |
| 134 call write_char |
| 135 addl $8, %esp |
| 136 |
| 137 pushl $0 |
| 138 call NACL_SYSCALL_ADDR(NACL_sys_sysbrk) |
| 139 addl $4, %esp |
| 140 |
| 141 xorl %edi, %edi /* edi holds our eventual exit status */ |
| 142 cmpl $EXPECTED_BREAK, %eax |
| 143 je brk_sane |
| 144 movl $1, %edi |
| 145 brk_sane: |
| 146 |
| 147 pushl %eax |
| 148 pushl $1 |
| 149 call write_num_16 |
| 150 addl $8, %esp |
| 151 |
| 152 pushl $'\n' |
| 153 pushl $1 |
| 154 call write_char |
| 155 addl $8, %esp |
| 156 |
| 157 pushl $EXPECTED_BREAK |
| 158 pushl $1 |
| 159 call write_num_16 |
| 160 addl $8, %esp |
| 161 |
| 162 pushl $'\n' |
| 163 pushl $1 |
| 164 call write_char |
| 165 addl $8, %esp |
| 166 |
| 167 #if EXPECTED_RODATA != 0 |
| 168 pushl $12 |
| 169 pushl $ro_str |
| 170 pushl $1 |
| 171 call NACL_SYSCALL_ADDR(NACL_sys_write) |
| 172 addl $12, %esp |
| 173 |
| 174 pushl $ro_str |
| 175 pushl $1 |
| 176 call write_num_16 |
| 177 addl $8, %esp |
| 178 |
| 179 pushl $'\n' |
| 180 pushl $1 |
| 181 call write_char |
| 182 addl $8, %esp |
| 183 |
| 184 leal ro_str, %eax |
| 185 cmpl $EXPECTED_RODATA, %eax |
| 186 je ro_sane |
| 187 movl $1, %edi |
| 188 ro_sane: |
| 189 |
| 190 pushl $EXPECTED_RODATA |
| 191 pushl $1 |
| 192 call write_num_16 |
| 193 addl $8, %esp |
| 194 |
| 195 pushl $'\n' |
| 196 pushl $1 |
| 197 call write_char |
| 198 addl $8, %esp |
| 199 #endif |
| 200 |
| 201 pushl %edi |
| 202 call NACL_SYSCALL_ADDR(NACL_sys_exit) |
| 203 |
| 204 .skip TEXT_EXTEND - (. - start_of_text), 0xf4 |
| 205 end_of_text: |
| 206 |
| 207 #if EXPECTED_RODATA != 0 |
| 208 .section .rodata |
| 209 ro_str: .ascii "Hello world\n" |
| 210 /* 123456789012 */ |
| 211 #endif |
OLD | NEW |