1/*
2            Copyright Oliver Kowalke 2009.
3   Distributed under the Boost Software License, Version 1.0.
4      (See accompanying file LICENSE_1_0.txt or copy at
5          http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8/*******************************************************
9 *                                                     *
10 *  -------------------------------------------------  *
11 *  |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  *
12 *  -------------------------------------------------  *
13 *  |  0  |  4  |  8  |  12 |  16 |  20 |  24 |  28 |  *
14 *  -------------------------------------------------  *
15 *  |    F20    |    F22    |    F24    |    F26    |  *
16 *  -------------------------------------------------  *
17 *  -------------------------------------------------  *
18 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
19 *  -------------------------------------------------  *
20 *  |  32 |  36 |  40 |  44 |  48 |  52 |  56 |  60 |  *
21 *  -------------------------------------------------  *
22 *  |    F28    |    F30    |  S0 |  S1 |  S2 |  S3 |  *
23 *  -------------------------------------------------  *
24 *  -------------------------------------------------  *
25 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
26 *  -------------------------------------------------  *
27 *  |  64 |  68 |  72 |  76 |  80 |  84 |  88 |  92 |  *
28 *  -------------------------------------------------  *
29 *  |  S4 |  S5 |  S6 |  S7 |  FP |hiddn|  RA |  PC |  *
30 *  -------------------------------------------------  *
31 *  -------------------------------------------------  *
32 *  |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  *
33 *  -------------------------------------------------  *
34 *  |  96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 |  *
35 *  -------------------------------------------------  *
36 *  |       ABI ARGS        |  GP | FCTX| DATA|     |  *
37 *  -------------------------------------------------  *
38 *                                                     *
39 * *****************************************************/
40
41.file "make_mips32_o32_elf_gas.S"
42.text
43.globl make_fcontext
44.align 2
45.type make_fcontext,@function
46.ent make_fcontext
47make_fcontext:
48#ifdef __PIC__
49.set    noreorder
50.cpload $t9
51.set    reorder
52#endif
53    # shift address in A0 to lower 16 byte boundary
54    li $v1, -16 # 0xfffffffffffffff0
55    and $v0, $v1, $a0
56
57    # reserve space for context-data on context-stack
58    #  includes an extra 32 bytes for:
59    #  - 16-byte incoming argument area required by mips ABI used when
60    #    jump_context calls the initial function
61    #  - 4 bytes to save our GP register used in finish
62    #  - 8 bytes to as space for transfer_t returned to finish
63    #  - 4 bytes for alignment
64    addiu $v0, $v0, -128
65
66    # third arg of make_fcontext() == address of context-function
67    sw  $a2, 92($v0)
68    # save global pointer in context-data
69    sw  $gp, 112($v0)
70
71    # compute address of returned transfer_t
72    addiu $t0, $v0, 116
73    sw  $t0, 84($v0)
74
75    # compute abs address of label finish
76    la  $t9, finish
77    # save address of finish as return-address for context-function
78    # will be entered after context-function returns
79    sw  $t9, 88($v0)
80
81    jr  $ra # return pointer to context-data
82
83finish:
84    # reload our gp register (needed for la)
85    lw $gp, 16($sp)
86
87    # call _exit(0)
88    #  the previous function should have left the 16 bytes incoming argument
89    #  area on the stack which we reuse for calling _exit
90    la $t9, _exit
91    move $a0, $zero
92    jr $t9
93.end make_fcontext
94.size make_fcontext, .-make_fcontext
95
96/* Mark that we don't need executable stack.  */
97.section .note.GNU-stack,"",%progbits
98