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 |     |  *
26 *  -------------------------------------------------  *
27 *  |  64 |  68 |  72 |  76 |  80 |  84 |  88 |     |  *
28 *  -------------------------------------------------  *
29 *  |  S4 |  S5 |  S6 |  S7 |  FP |  RA |  PC |     |  *
30 *  -------------------------------------------------  *
31 *                                                     *
32 * *****************************************************/
33
34.text
35.globl make_fcontext
36.align 2
37.type make_fcontext,@function
38.ent make_fcontext
39make_fcontext:
40#ifdef __PIC__
41.set    noreorder
42.cpload $t9
43.set    reorder
44#endif
45    # first arg of make_fcontext() == top address of context-stack
46    move $v0, $a0
47
48    # shift address in A0 to lower 16 byte boundary
49    move $v1, $v0
50    li $v0, -16 # 0xfffffffffffffff0
51    and $v0, $v1, $v0
52
53    # reserve space for context-data on context-stack
54    # including 48 byte of shadow space (sp % 16 == 0)
55    addiu $v0, $v0, -140
56
57    # third arg of make_fcontext() == address of context-function
58    sw  $a2, 88($v0)
59    # save global pointer in context-data
60    # S0 will contain address of global pointer
61    sw  $gp, 48($v0)
62
63    # compute abs address of label finish
64    la  $t9, finish
65    # save address of finish as return-address for context-function
66    # will be entered after context-function returns
67    sw  $t9, 84($v0)
68
69    jr  $ra # return pointer to context-data
70
71finish:
72    # allocate stack space (contains shadow space for subroutines)
73    addiu  $sp, $sp, -32
74    # save return address
75    sw  $ra, 28($sp)
76
77    # restore GP (global pointer)
78    move  $gp, $s0
79    # exit code is zero
80    move  $a0, $zero
81    # address of exit
82    lw  $t9, %call16(_exit)($gp)
83    # exit application
84    jalr  $t9
85.end make_fcontext
86.size make_fcontext, .-make_fcontext
87
88/* Mark that we don't need executable stack.  */
89.section .note.GNU-stack,"",%progbits
90