- add third_party src.
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / service_runtime / arch / arm / nacl_syscall.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 #include "native_client/src/trusted/service_runtime/arch/arm/sel_ldr_arm.h"
8 #include "native_client/src/trusted/service_runtime/arch/arm/sel_rt.h"
9 #include "native_client/src/trusted/service_runtime/nacl_config.h"
10
11 .text
12
13
14 /*
15  * This trusted code is linked into the service runtime. It is executed when a
16  * nacl module performs a system call via a service runtime interface. The nacl
17  * module jumps to the trampoline corresponding to the syscall and then here.
18  * This code switches the execution contexts (registers and stack) from
19  * untrusted to trusted.
20  */
21
22 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSeg):
23   /* Set r0 to the start of the NaClThreadContext struct. */
24   sub r0, r9, #NACL_THREAD_CONTEXT_OFFSET_TLS_VALUE1
25
26   /*
27    * Check that r9 points into a valid NaClThreadContext by checking
28    * that the guard_token field matches nacl_guard_token.
29    */
30   ldr r2, [r0, #NACL_THREAD_CONTEXT_OFFSET_GUARD_TOKEN]
31   ldr r3, .L.offset.nacl_guard_token
32 .LPIC1:
33   ldr r3, [pc, r3]
34   cmp r2, r3
35   bne NaClSyscallThreadCaptureFault
36
37   /* Save address of trampoline for determining which syscall was called. */
38   str lr, [sp, #-0x18]
39
40   /* store thread state to the nacl_user entry */
41   stmia r0, NACL_CALLEE_SAVE_LIST
42   /* if r0 is NULL, we would have faulted here */
43 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSegRegsSaved):
44
45   /*
46    * Store the untrusted fpscr state and load the trusted fpscr into r2.
47    */
48   fmrx ip, fpscr
49   str ip, [r0, #NACL_THREAD_CONTEXT_OFFSET_FPSCR]
50   ldr r2, [r0, #NACL_THREAD_CONTEXT_OFFSET_SYS_FPSCR]
51
52   /* Restore the trusted stack */
53   ldr  sp, [r0, #NACL_THREAD_CONTEXT_OFFSET_TRUSTED_STACK_PTR]
54
55   /* Restore the trusted fpscr. */
56   fmxr fpscr, r2
57
58   bl  NaClSyscallCSegHook
59
60   /*
61    * NaClSyscallCSegHook returned with the NaClThreadContext pointer
62    * back in r0, which is conveniently already where it's needed to
63    * be the argument to NaClSwitch.
64    */
65   b NaClSwitch
66
67 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSegEnd):
68
69 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallThreadCaptureFault):
70   .word NACL_HALT_WORD
71
72 .L.offset.nacl_guard_token:
73   .word nacl_guard_token - (.LPIC1 + 8)