00001 /* 00002 * Copyright (c) 2005 Jakub Jermar 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00035 #ifndef LIBC_ia64_FIBRIL_H_ 00036 #define LIBC_ia64_FIBRIL_H_ 00037 00038 #include <sys/types.h> 00039 #include <align.h> 00040 #include <libarch/stack.h> 00041 #include <libarch/types.h> 00042 00043 /* 00044 * context_save() and context_restore() are both leaf procedures. 00045 * No need to allocate scratch area. 00046 */ 00047 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 00048 00049 #define PFM_MASK (~0x3fffffffff) 00050 00051 #define PSTHREAD_INITIAL_STACK_PAGES_NO 2 00052 /* Stack is divided into two equal parts (for memory stack and register stack). */ 00053 #define PSTHREAD_INITIAL_STACK_DIVISION 2 00054 00055 #define context_set(c, _pc, stack, size, tls) \ 00056 do { \ 00057 (c)->pc = (uint64_t) _pc; \ 00058 (c)->bsp = ((uint64_t) stack) + size / PSTHREAD_INITIAL_STACK_DIVISION; \ 00059 (c)->ar_pfs &= PFM_MASK; \ 00060 (c)->sp = ((uint64_t) stack) + ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - SP_DELTA; \ 00061 (c)->tp = (uint64_t) tls; \ 00062 } while (0); 00063 00064 00065 /* 00066 * Only save registers that must be preserved across 00067 * function calls. 00068 */ 00069 typedef struct context { 00070 00071 /* 00072 * Application registers 00073 */ 00074 uint64_t ar_pfs; 00075 uint64_t ar_unat_caller; 00076 uint64_t ar_unat_callee; 00077 uint64_t ar_rsc; 00078 uint64_t bsp; /* ar_bsp */ 00079 uint64_t ar_rnat; 00080 uint64_t ar_lc; 00081 00082 /* 00083 * General registers 00084 */ 00085 uint64_t r1; 00086 uint64_t r4; 00087 uint64_t r5; 00088 uint64_t r6; 00089 uint64_t r7; 00090 uint64_t sp; /* r12 */ 00091 uint64_t tp; /* r13 */ 00092 00093 /* 00094 * Branch registers 00095 */ 00096 uint64_t pc; /* b0 */ 00097 uint64_t b1; 00098 uint64_t b2; 00099 uint64_t b3; 00100 uint64_t b4; 00101 uint64_t b5; 00102 00103 /* 00104 * Predicate registers 00105 */ 00106 uint64_t pr; 00107 00108 uint128_t f2 __attribute__ ((aligned(16))); 00109 uint128_t f3; 00110 uint128_t f4; 00111 uint128_t f5; 00112 00113 uint128_t f16; 00114 uint128_t f17; 00115 uint128_t f18; 00116 uint128_t f19; 00117 uint128_t f20; 00118 uint128_t f21; 00119 uint128_t f22; 00120 uint128_t f23; 00121 uint128_t f24; 00122 uint128_t f25; 00123 uint128_t f26; 00124 uint128_t f27; 00125 uint128_t f28; 00126 uint128_t f29; 00127 uint128_t f30; 00128 uint128_t f31; 00129 00130 } context_t; 00131 00132 static inline uintptr_t context_get_fp(context_t *ctx) 00133 { 00134 return 0; /* FIXME */ 00135 } 00136 00137 #endif 00138