OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 * | 5 * |
6 * This is a standalone program that loads and runs the dynamic linker. | 6 * This is a standalone program that loads and runs the dynamic linker. |
7 * This program itself must be linked statically. To keep it small, it's | 7 * This program itself must be linked statically. To keep it small, it's |
8 * written to avoid all dependencies on libc and standard startup code. | 8 * written to avoid all dependencies on libc and standard startup code. |
9 * Hence, this should be linked using -nostartfiles. It must be compiled | 9 * Hence, this should be linked using -nostartfiles. It must be compiled |
10 * with -fno-stack-protector to ensure the compiler won't emit code that | 10 * with -fno-stack-protector to ensure the compiler won't emit code that |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 ehdr.e_phentsize != sizeof(ElfW(Phdr))) | 257 ehdr.e_phentsize != sizeof(ElfW(Phdr))) |
258 fail(filename, "File has no valid ELF header!", NULL, 0, NULL, 0); | 258 fail(filename, "File has no valid ELF header!", NULL, 0, NULL, 0); |
259 | 259 |
260 switch (ehdr.e_machine) { | 260 switch (ehdr.e_machine) { |
261 #if defined(__i386__) | 261 #if defined(__i386__) |
262 case EM_386: | 262 case EM_386: |
263 #elif defined(__x86_64__) | 263 #elif defined(__x86_64__) |
264 case EM_X86_64: | 264 case EM_X86_64: |
265 #elif defined(__arm__) | 265 #elif defined(__arm__) |
266 case EM_ARM: | 266 case EM_ARM: |
267 #elif defined(__mips__) | |
268 case EM_MIPS: | |
267 #else | 269 #else |
268 # error "Don't know the e_machine value for this architecture!" | 270 # error "Don't know the e_machine value for this architecture!" |
269 #endif | 271 #endif |
270 break; | 272 break; |
271 default: | 273 default: |
272 fail(filename, "ELF file has wrong architecture! ", | 274 fail(filename, "ELF file has wrong architecture! ", |
273 "e_machine", ehdr.e_machine, NULL, 0); | 275 "e_machine", ehdr.e_machine, NULL, 0); |
274 break; | 276 break; |
275 } | 277 } |
276 | 278 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 #endif | 662 #endif |
661 "mov fp, #0\n" | 663 "mov fp, #0\n" |
662 "mov lr, #0\n" | 664 "mov lr, #0\n" |
663 "mov r4, sp\n" /* Save starting SP in r4. */ | 665 "mov r4, sp\n" /* Save starting SP in r4. */ |
664 "mov r0, sp\n" /* Argument: stack block. */ | 666 "mov r0, sp\n" /* Argument: stack block. */ |
665 "bl do_load\n" | 667 "bl do_load\n" |
666 "mov sp, r4\n" /* Restore the saved SP. */ | 668 "mov sp, r4\n" /* Restore the saved SP. */ |
667 "blx r0\n" /* Jump to the entry point. */ | 669 "blx r0\n" /* Jump to the entry point. */ |
668 ".popsection" | 670 ".popsection" |
669 ); | 671 ); |
672 #elif defined(__mips__) | |
673 asm(".pushsection \".text\",\"ax\",%progbits\n" | |
Mark Seaborn
2012/09/18 03:24:34
Nit: don't indent this line, because it's a top-le
petarj
2012/09/19 17:27:51
Done.
| |
674 ".globl _start\n" | |
675 ".type _start,@function\n" | |
676 "_start:\n" | |
677 ".set noreorder\n" | |
678 "addiu $fp, $zero, 0\n" | |
679 "addiu $ra, $zero, 0\n" | |
680 "addiu $s8, $sp, 0\n" /* Save starting SP in s8. */ | |
681 "addiu $a0, $sp, 0\n" | |
682 "addiu $sp, $sp, -16\n" | |
683 "jal do_load\n" | |
684 "nop\n" | |
685 "addiu $sp, $s8, 0\n" /* Restore the saved SP. */ | |
686 "jr $v0\n" /* Jump to the entry point. */ | |
687 "nop\n" | |
688 ".popsection" | |
689 ); | |
670 #else | 690 #else |
671 # error "Need stack-preserving _start code for this architecture!" | 691 # error "Need stack-preserving _start code for this architecture!" |
672 #endif | 692 #endif |
673 | 693 |
674 #if defined(__arm__) | 694 #if defined(__arm__) |
675 /* | 695 /* |
676 * We may bring in __aeabi_* functions from libgcc that in turn | 696 * We may bring in __aeabi_* functions from libgcc that in turn |
677 * want to call raise. | 697 * want to call raise. |
678 */ | 698 */ |
679 int raise(int sig) { | 699 int raise(int sig) { |
680 return sys_kill(sys_getpid(), sig); | 700 return sys_kill(sys_getpid(), sig); |
681 } | 701 } |
682 #endif | 702 #endif |
OLD | NEW |