001b7841792ff37ef22e5bfa3a5fbc8a867ebcb9
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / service_runtime / arch / x86_32 / springboard.S
1 /*
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
4  * found in the LICENSE file.
5  */
6
7 /*
8  * NaCl Simple/secure ELF loader (NaCl SEL).
9  */
10 #include "native_client/src/trusted/service_runtime/nacl_config.h"
11 #include "native_client/src/trusted/service_runtime/arch/x86_32/sel_rt_32.h"
12
13 /*
14  * Assembly code template.  This is linked into the service runtime
15  * but is unused as code -- it is used as data to be patched into
16  * a NaCl app's address space as a "hidden" part of its trampoline
17  * region.
18  */
19
20         /*
21          * This is code, but it is not code that is actually part of the
22          * program/library being linked.  Marking it as read-only data
23          * instead ensures that nothing like linker code-rewriting will
24          * be applied to this code.
25          */
26         NACL_RODATA
27
28 /*
29  * NaCl_springboard is used for syscall return and any time we want
30  * to do an upcall into NaCl application.
31  */
32
33 DEFINE_GLOBAL_HIDDEN_LOCATION(NaCl_springboard):
34         hlt  /* one byte */
35         /* Restore state from struct NaClThreadContext. */
36         /* syscall return value, if any, from trusted stack */
37         mov     NACL_THREAD_CONTEXT_OFFSET_SYSRET(%ecx), %eax
38         lss     NACL_THREAD_CONTEXT_OFFSET_STACK_PTR(%ecx), %esp
39         movw    NACL_THREAD_CONTEXT_OFFSET_DS(%ecx), %ds
40         /* Set %ecx to zero to avoid leaking the NaClThreadContext address. */
41         xorl    %ecx, %ecx
42         jmp     *%edx
43 DEFINE_GLOBAL_HIDDEN_LOCATION(NaCl_springboard_end):
44
45
46 DEFINE_GLOBAL_HIDDEN_LOCATION(NaCl_springboard_all_regs):
47         hlt  /* one byte */
48         /* Restore state from struct NaClSwitchRemainingRegsState. */
49         lss     0(%ecx), %esp /* stack_ptr */
50         movw    0x10(%ecx), %ds /* ds */
51         movl    %gs:0xc, %ecx /* new_ecx from NaClGsSegment */
52         jmp     *%gs:8 /* new_prog_ctr from NaClGsSegment */
53 DEFINE_GLOBAL_HIDDEN_LOCATION(NaCl_springboard_all_regs_end):