/trunk/uspace/libc/arch/sparc64/_link.ld.in |
---|
7,9 → 7,9 |
} |
SECTIONS { |
. = 0x1000; |
. = 0x2000; |
.init ALIGN(0x1000) : SUBALIGN(0x1000) { |
.init ALIGN(0x2000) : SUBALIGN(0x2000) { |
*(.init); |
} :text |
.text : { |
17,7 → 17,11 |
*(.rodata*); |
} :text |
.data ALIGN(0x1000) : SUBALIGN(0x1000) { |
.got ALIGN(0x2000) : SUBALIGN(0x2000) { |
_gp = .; |
*(.got*); |
} :data |
.data ALIGN(0x2000) : SUBALIGN(0x2000) { |
*(.data); |
*(.sdata); |
} :data |
37,7 → 41,7 |
*(.bss); |
} :data |
. = ALIGN(0x1000); |
. = ALIGN(0x2000); |
_heap = .; |
/DISCARD/ : { |
/trunk/uspace/libc/arch/sparc64/include/context_offset.h |
---|
1,4 → 1,22 |
/* This file is automatically generated by gencontext.c. */ |
/* struct context */ |
#define OFFSET_SP 0x0 |
#define OFFSET_PC 0x8 |
#define OFFSET_I0 0x10 |
#define OFFSET_I1 0x18 |
#define OFFSET_I2 0x20 |
#define OFFSET_I3 0x28 |
#define OFFSET_I4 0x30 |
#define OFFSET_I5 0x38 |
#define OFFSET_FP 0x40 |
#define OFFSET_I7 0x48 |
#define OFFSET_L0 0x50 |
#define OFFSET_L1 0x58 |
#define OFFSET_L2 0x60 |
#define OFFSET_L3 0x68 |
#define OFFSET_L4 0x70 |
#define OFFSET_L5 0x78 |
#define OFFSET_L6 0x80 |
#define OFFSET_L7 0x88 |
#define OFFSET_TP 0x90 |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/psthread.h |
---|
1,5 → 1,5 |
/* |
* Copyright (C) 2006 Martin Decky |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
26,35 → 26,56 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __LIBC__sparc64__PSTHREAD_H__ |
#define __LIBC__sparc64__PSTHREAD_H__ |
#ifndef LIBC_sparc64_PSTHREAD_H_ |
#define LIBC_sparc64_PSTHREAD_H_ |
#include <libarch/stack.h> |
#include <types.h> |
#include <align.h> |
/* We define our own context_set, because we need to set |
* the TLS pointer to the tcb+0x7000 |
* |
* See tls_set in thread.h |
*/ |
#define context_set(c, _pc, stack, size, ptls) \ |
(c)->pc = (sysarg_t) (_pc); \ |
(c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ |
(c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t); |
#define SP_DELTA STACK_WINDOW_SAVE_AREA_SIZE |
#define SP_DELTA 16 |
#ifdef context_set |
#undef context_set |
#endif |
#define context_set(c, _pc, stack, size, ptls) \ |
(c)->pc = ((uintptr_t) _pc) - 8; \ |
(c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ |
(c)->fp = -STACK_BIAS; \ |
(c)->tp = ptls |
/* |
* Only save registers that must be preserved across |
* function calls. |
*/ |
typedef struct { |
uint64_t sp; |
uint64_t pc; |
uint64_t tls; |
} __attribute__ ((packed)) context_t; |
uintptr_t sp; /* %o6 */ |
uintptr_t pc; /* %o7 */ |
uint64_t i0; |
uint64_t i1; |
uint64_t i2; |
uint64_t i3; |
uint64_t i4; |
uint64_t i5; |
uintptr_t fp; /* %i6 */ |
uintptr_t i7; |
uint64_t l0; |
uint64_t l1; |
uint64_t l2; |
uint64_t l3; |
uint64_t l4; |
uint64_t l5; |
uint64_t l6; |
uint64_t l7; |
uint64_t tp; /* %g7 */ |
} context_t; |
#endif |
/trunk/uspace/libc/arch/sparc64/include/syscall.h |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libc |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
/trunk/uspace/libc/arch/sparc64/include/atomic.h |
---|
1,5 → 1,5 |
/* |
* Copyright (C) 2005 Martin Decky |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
26,45 → 26,74 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __sparc64_ATOMIC_H__ |
#define __sparc64_ATOMIC_H__ |
#ifndef LIBC_sparc64_ATOMIC_H_ |
#define LIBC_sparc64_ATOMIC_H_ |
static inline void atomic_inc(atomic_t *val) |
#include <types.h> |
/** Atomic add operation. |
* |
* Use atomic compare and swap operation to atomically add signed value. |
* |
* @param val Atomic variable. |
* @param i Signed value to be added. |
* |
* @return Value of the atomic variable as it existed before addition. |
*/ |
static inline long atomic_add(atomic_t *val, int i) |
{ |
uint64_t a, b; |
volatile uint64_t x = (uint64_t) &val->count; |
__asm__ volatile ( |
"0:\n" |
"ldx %0, %1\n" |
"add %1, %3, %2\n" |
"casx %0, %1, %2\n" |
"cmp %1, %2\n" |
"bne 0b\n" /* The operation failed and must be attempted again if a != b. */ |
"nop\n" |
: "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b) |
: "r" (i) |
); |
return a; |
} |
static inline void atomic_dec(atomic_t *val) |
static inline long atomic_preinc(atomic_t *val) |
{ |
return atomic_add(val, 1) + 1; |
} |
static inline long atomic_postinc(atomic_t *val) |
{ |
atomic_inc(val); |
return val->count - 1; |
return atomic_add(val, 1); |
} |
static inline long atomic_predec(atomic_t *val) |
{ |
return atomic_add(val, -1) - 1; |
} |
static inline long atomic_postdec(atomic_t *val) |
{ |
atomic_dec(val); |
return val->count + 1; |
return atomic_add(val, -1); |
} |
static inline long atomic_preinc(atomic_t *val) |
static inline void atomic_inc(atomic_t *val) |
{ |
atomic_inc(val); |
return val->count; |
(void) atomic_add(val, 1); |
} |
static inline long atomic_predec(atomic_t *val) |
static inline void atomic_dec(atomic_t *val) |
{ |
atomic_dec(val); |
return val->count; |
(void) atomic_add(val, -1); |
} |
#endif |
/trunk/uspace/libc/arch/sparc64/include/endian.h |
---|
26,14 → 26,14 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __sparc64_ENDIAN_H__ |
#define __sparc64_ENDIAN_H__ |
#ifndef LIBC_sparc64_ENDIAN_H_ |
#define LIBC_sparc64_ENDIAN_H_ |
#ifndef __LIBC__ENDIAN_H__ |
# error "Never use <libarch/endian.h> directly - use <endian.h> instead." |
43,6 → 43,5 |
#endif |
/** @} |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/stackarg.h |
---|
32,11 → 32,10 |
/** @file |
*/ |
#ifndef __LIBC__STACKARG_H__ |
#define __LIBC__STACKARG_H__ |
#ifndef LIBC_sparc64_STACKARG_H_ |
#define LIBC_sparc64_STACKARG_H_ |
#endif |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/limits.h |
---|
32,8 → 32,8 |
/** @file |
*/ |
#ifndef __sparc64__LIMITS_H__ |
#define __sparc64__LIMITS_H__ |
#ifndef LIBC_sparc64__LIMITS_H_ |
#define LIBC_sparc64__LIMITS_H_ |
#define LONG_MIN MIN_INT64 |
#define LONG_MAX MAX_INT64 |
/trunk/uspace/libc/arch/sparc64/include/types.h |
---|
35,12 → 35,12 |
#ifndef LIBC_sparc64_TYPES_H_ |
#define LIBC_sparc64_TYPES_H_ |
typedef unsigned int sysarg_t; |
typedef unsigned int size_t; |
typedef signed int ssize_t; |
typedef unsigned long sysarg_t; |
typedef unsigned long size_t; |
typedef signed long ssize_t; |
typedef ssize_t off_t; |
typedef char int8_t; |
typedef signed char int8_t; |
typedef short int int16_t; |
typedef int int32_t; |
typedef long int int64_t; |
/trunk/uspace/libc/arch/sparc64/include/config.h |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
35,7 → 35,7 |
#ifndef LIBC_sparc64_CONFIG_H_ |
#define LIBC_sparc64_CONFIG_H_ |
#define PAGE_WIDTH 12 |
#define PAGE_WIDTH 13 |
#define PAGE_SIZE (1<<PAGE_WIDTH) |
#endif |
/trunk/uspace/libc/arch/sparc64/include/stack.h |
---|
0,0 → 1,56 |
/* |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
*/ |
#ifndef LIBC_sparc64_STACK_H_ |
#define LIBC_sparc64_STACK_H_ |
#define STACK_ITEM_SIZE 8 |
/** According to SPARC Compliance Definition, every stack frame is 16-byte aligned. */ |
#define STACK_ALIGNMENT 16 |
/** |
* 16-extended-word save area for %i[0-7] and %l[0-7] registers. |
*/ |
#define STACK_WINDOW_SAVE_AREA_SIZE (16*STACK_ITEM_SIZE) |
/** |
* By convention, the actual top of the stack is %sp + STACK_BIAS. |
*/ |
#define STACK_BIAS 2047 |
#endif |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/thread.h |
---|
1,5 → 1,6 |
/* |
* Copyright (C) 2006 Martin Decky |
* Copyright (C) 2006 Ondrej Palkovsky |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
26,30 → 27,38 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
/** |
* @file |
* @brief sparc64 TLS functions. |
* |
* The implementation is based on the IA-32 implementation which was also |
* designed by Sun and is virtually the same, except the TCB is stored in |
* %g7 (of the normal set). |
*/ |
#ifndef __LIBC__sparc64__THREAD_H__ |
#define __LIBC__sparc64__THREAD_H__ |
#ifndef LIBC_sparc64_THREAD_H_ |
#define LIBC_sparc64_THREAD_H_ |
#define PPC_TP_OFFSET 0x7000 |
typedef struct { |
void *self; |
void *pst_data; |
} tcb_t; |
static inline void __tcb_set(tcb_t *tcb) |
{ |
void *tp = tcb; |
tp += PPC_TP_OFFSET + sizeof(tcb_t); |
__asm__ volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7"); |
} |
static inline tcb_t *__tcb_get(void) |
static inline tcb_t * __tcb_get(void) |
{ |
return (tcb_t *)(PPC_TP_OFFSET - sizeof(tcb_t)); |
void *retval; |
__asm__ volatile ("mov %%g7, %0\n" : "=r" (retval)); |
return retval; |
} |
#endif |
/trunk/uspace/libc/arch/sparc64/src/entry.s |
---|
37,5 → 37,21 |
# |
# |
__entry: |
sethi %hi(_gp), %l7 |
call __main |
or %l7, %lo(_gp), %l7 |
call __io_init |
nop |
call main |
nop |
call __exit |
nop |
__entry_driver: |
sethi %hi(_gp), %l7 |
call __main |
or %l7, %lo(_gp), %l7 |
call main |
nop |
call __exit |
nop |
/trunk/uspace/libc/arch/sparc64/src/thread.c |
---|
26,10 → 26,12 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 sparc64 |
* @ingroup lc |
* @{ |
*/ |
/** @file |
* |
*/ |
#include <thread.h> |
39,20 → 41,23 |
* |
* @param data Start of data section |
* @return pointer to tcb_t structure |
* |
*/ |
tcb_t * __alloc_tls(void **data, size_t size) |
{ |
tcb_t *result; |
tcb_t *tcb; |
*data = malloc(sizeof(tcb_t) + size); |
result = malloc(sizeof(tcb_t) + size); |
*data = ((void *)result) + sizeof(tcb_t); |
return result; |
tcb = (tcb_t *) (*data + size); |
tcb->self = tcb; |
return tcb; |
} |
void __free_tls_arch(tcb_t *tcb, size_t size) |
{ |
free(tcb); |
void *start = ((void *)tcb) - size; |
free(start); |
} |
/** @} |
/trunk/uspace/libc/arch/sparc64/src/thread_entry.s |
---|
1,5 → 1,5 |
# |
# Copyright (C) 2006 Martin Decky |
# Copyright (C) 2006 Jakub Jermar |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
34,5 → 34,10 |
# |
# |
__thread_entry: |
sethi %hi(_gp), %l7 |
call __thread_main ! %o0 contains address of uarg |
or %l7, %lo(_gp), %l7 |
! not reached |
.end __thread_entry |
/trunk/uspace/libc/arch/sparc64/src/psthread.S |
---|
1,5 → 1,5 |
# |
# Copyright (C) 2006 Martin Decky |
# Copyright (C) 2005 Jakub Jermar |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
26,14 → 26,80 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
# |
.text |
#include <libarch/context_offset.h> |
/** |
* Both context_save_arch() and context_restore_arch() are |
* leaf-optimized procedures. This kind of optimization |
* is very important and prevents any implicit window |
* spill/fill/clean traps in these very core kernel |
* functions. |
*/ |
.text |
.global context_save |
.global context_restore |
#include <libarch/context_offset.h> |
.macro CONTEXT_STORE r |
stx %sp, [\r + OFFSET_SP] |
stx %o7, [\r + OFFSET_PC] |
stx %i0, [\r + OFFSET_I0] |
stx %i1, [\r + OFFSET_I1] |
stx %i2, [\r + OFFSET_I2] |
stx %i3, [\r + OFFSET_I3] |
stx %i4, [\r + OFFSET_I4] |
stx %i5, [\r + OFFSET_I5] |
stx %fp, [\r + OFFSET_FP] |
stx %i7, [\r + OFFSET_I7] |
stx %l0, [\r + OFFSET_L0] |
stx %l1, [\r + OFFSET_L1] |
stx %l2, [\r + OFFSET_L2] |
stx %l3, [\r + OFFSET_L3] |
stx %l4, [\r + OFFSET_L4] |
stx %l5, [\r + OFFSET_L5] |
stx %l6, [\r + OFFSET_L6] |
stx %l7, [\r + OFFSET_L7] |
stx %g7, [\r + OFFSET_TP] |
.endm |
.macro CONTEXT_LOAD r |
ldx [\r + OFFSET_SP], %sp |
ldx [\r + OFFSET_PC], %o7 |
ldx [\r + OFFSET_I0], %i0 |
ldx [\r + OFFSET_I1], %i1 |
ldx [\r + OFFSET_I2], %i2 |
ldx [\r + OFFSET_I3], %i3 |
ldx [\r + OFFSET_I4], %i4 |
ldx [\r + OFFSET_I5], %i5 |
ldx [\r + OFFSET_FP], %fp |
ldx [\r + OFFSET_I7], %i7 |
ldx [\r + OFFSET_L0], %l0 |
ldx [\r + OFFSET_L1], %l1 |
ldx [\r + OFFSET_L2], %l2 |
ldx [\r + OFFSET_L3], %l3 |
ldx [\r + OFFSET_L4], %l4 |
ldx [\r + OFFSET_L5], %l5 |
ldx [\r + OFFSET_L6], %l6 |
ldx [\r + OFFSET_L7], %l7 |
ldx [\r + OFFSET_TP], %g7 |
.endm |
context_save: |
CONTEXT_STORE %o0 |
retl |
mov 1, %o0 ! context_save_arch returns 1 |
context_restore: |
# |
# Flush all active windows. |
# This is essential, because CONTEXT_LOAD overwrites |
# %sp of CWP - 1 with the value written to %fp of CWP. |
# Flushing all active windows mitigates this problem |
# as CWP - 1 becomes the overlap window. |
# |
flushw |
CONTEXT_LOAD %o0 |
retl |
xor %o0, %o0, %o0 ! context_restore_arch returns 0 |