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	.globl	make_fcontext[DS]
8	.globl .make_fcontext[PR]
9	.align 2
10	.csect .make_fcontext[PR], 3
11	.globl _make_fcontext
12#._make_fcontext:
13    # save return address into R6
14    mflr  6
15
16    # first arg of make_fcontext() == top address of context-function
17    # shift address in R3 to lower 16 byte boundary
18    clrrwi  3, 3, 4
19
20    # reserve space for context-data on context-stack
21    # including 64 byte of linkage + parameter area (R1 % 16 == 0)
22    subi  3, 3, 248
23
24    # third arg of make_fcontext() == address of context-function
25    stw  5, 176(3)
26
27    # set back-chain to zero
28    li   0, 0
29    std  0, 184(3)
30
31    # compute address of returned transfer_t
32    addi 0, 3, 232
33    mr   4, 0
34    std  4, 152(3)
35
36    # load LR
37    mflr  0
38    # jump to label 1
39    bl  .Label
40.Label:
41    # load LR into R4
42    mflr  4
43    # compute abs address of label .L_finish
44    addi  4, 4, .L_finish - .Label
45    # restore LR
46    mtlr  0
47    # save address of finish as return-address for context-function
48    # will be entered after context-function returns
49    stw  4, 168(3)
50
51    # restore return address from R6
52    mtlr  6
53
54    blr  # return pointer to context-data
55
56.L_finish:
57    # save return address into R0
58    mflr  0
59    # save return address on stack, set up stack frame
60    stw  0, 8(1)
61    # allocate stack space, R1 % 16 == 0
62    stwu  1, -32(1)
63
64    # exit code is zero
65    li  3, 0
66    # exit application
67    bl  ._exit
68    nop
69