/trunk/uspace/libc/arch/sparc64/include/stack.h |
---|
File deleted |
/trunk/uspace/libc/arch/sparc64/include/syscall.h |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libc |
* @{ |
*/ |
/** @file |
/trunk/uspace/libc/arch/sparc64/include/context_offset.h |
---|
1,22 → 1,4 |
/* 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) 2005 Jakub Jermar |
* Copyright (C) 2006 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
26,56 → 26,35 |
* 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> |
#define SP_DELTA STACK_WINDOW_SAVE_AREA_SIZE |
/* 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); |
#ifdef context_set |
#undef context_set |
#endif |
#define SP_DELTA 16 |
#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 |
typedef struct { |
uint64_t sp; |
uint64_t pc; |
/* |
* Only save registers that must be preserved across |
* function calls. |
*/ |
typedef struct { |
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; |
uint64_t tls; |
} __attribute__ ((packed)) context_t; |
#endif |
/trunk/uspace/libc/arch/sparc64/include/atomic.h |
---|
1,5 → 1,5 |
/* |
* Copyright (C) 2005 Jakub Jermar |
* Copyright (C) 2005 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
26,74 → 26,45 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
*/ |
#ifndef LIBC_sparc64_ATOMIC_H_ |
#define LIBC_sparc64_ATOMIC_H_ |
#ifndef __sparc64_ATOMIC_H__ |
#define __sparc64_ATOMIC_H__ |
#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) |
static inline void atomic_inc(atomic_t *val) |
{ |
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 long atomic_preinc(atomic_t *val) |
static inline void atomic_dec(atomic_t *val) |
{ |
return atomic_add(val, 1) + 1; |
} |
static inline long atomic_postinc(atomic_t *val) |
{ |
return atomic_add(val, 1); |
atomic_inc(val); |
return val->count - 1; |
} |
static inline long atomic_predec(atomic_t *val) |
{ |
return atomic_add(val, -1) - 1; |
} |
static inline long atomic_postdec(atomic_t *val) |
{ |
return atomic_add(val, -1); |
atomic_dec(val); |
return val->count + 1; |
} |
static inline void atomic_inc(atomic_t *val) |
static inline long atomic_preinc(atomic_t *val) |
{ |
(void) atomic_add(val, 1); |
atomic_inc(val); |
return val->count; |
} |
static inline void atomic_dec(atomic_t *val) |
static inline long atomic_predec(atomic_t *val) |
{ |
(void) atomic_add(val, -1); |
atomic_dec(val); |
return val->count; |
} |
#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 LIBC_sparc64_ENDIAN_H_ |
#define LIBC_sparc64_ENDIAN_H_ |
#ifndef __sparc64_ENDIAN_H__ |
#define __sparc64_ENDIAN_H__ |
#ifndef __LIBC__ENDIAN_H__ |
# error "Never use <libarch/endian.h> directly - use <endian.h> instead." |
43,5 → 43,6 |
#endif |
/** @} |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/stackarg.h |
---|
32,10 → 32,11 |
/** @file |
*/ |
#ifndef LIBC_sparc64_STACKARG_H_ |
#define LIBC_sparc64_STACKARG_H_ |
#ifndef __LIBC__STACKARG_H__ |
#define __LIBC__STACKARG_H__ |
#endif |
/** @} |
*/ |
/trunk/uspace/libc/arch/sparc64/include/limits.h |
---|
32,8 → 32,8 |
/** @file |
*/ |
#ifndef LIBC_sparc64__LIMITS_H_ |
#define LIBC_sparc64__LIMITS_H_ |
#ifndef __sparc64__LIMITS_H__ |
#define __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 long sysarg_t; |
typedef unsigned long size_t; |
typedef signed long ssize_t; |
typedef unsigned int sysarg_t; |
typedef unsigned int size_t; |
typedef signed int ssize_t; |
typedef ssize_t off_t; |
typedef signed char int8_t; |
typedef 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 libcsparc64 |
/** @addtogroup libsparc64 |
* @{ |
*/ |
/** @file |
35,7 → 35,7 |
#ifndef LIBC_sparc64_CONFIG_H_ |
#define LIBC_sparc64_CONFIG_H_ |
#define PAGE_WIDTH 13 |
#define PAGE_WIDTH 12 |
#define PAGE_SIZE (1<<PAGE_WIDTH) |
#endif |
/trunk/uspace/libc/arch/sparc64/include/thread.h |
---|
1,6 → 1,5 |
/* |
* Copyright (C) 2006 Ondrej Palkovsky |
* Copyright (C) 2006 Jakub Jermar |
* Copyright (C) 2006 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
27,38 → 26,30 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** |
* @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). |
/** @file |
*/ |
#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) |
{ |
__asm__ volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7"); |
void *tp = tcb; |
tp += PPC_TP_OFFSET + sizeof(tcb_t); |
} |
static inline tcb_t * __tcb_get(void) |
static inline tcb_t *__tcb_get(void) |
{ |
void *retval; |
__asm__ volatile ("mov %%g7, %0\n" : "=r" (retval)); |
return retval; |
return (tcb_t *)(PPC_TP_OFFSET - sizeof(tcb_t)); |
} |
#endif |
/trunk/uspace/libc/arch/sparc64/src/entry.s |
---|
37,21 → 37,5 |
# |
# |
__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,12 → 26,10 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcsparc64 sparc64 |
* @ingroup lc |
/** @addtogroup libcsparc64 |
* @{ |
*/ |
/** @file |
* |
*/ |
#include <thread.h> |
41,23 → 39,20 |
* |
* @param data Start of data section |
* @return pointer to tcb_t structure |
* |
*/ |
tcb_t * __alloc_tls(void **data, size_t size) |
{ |
tcb_t *tcb; |
*data = malloc(sizeof(tcb_t) + size); |
tcb_t *result; |
tcb = (tcb_t *) (*data + size); |
tcb->self = tcb; |
return tcb; |
result = malloc(sizeof(tcb_t) + size); |
*data = ((void *)result) + sizeof(tcb_t); |
return result; |
} |
void __free_tls_arch(tcb_t *tcb, size_t size) |
{ |
void *start = ((void *)tcb) - size; |
free(start); |
free(tcb); |
} |
/** @} |
/trunk/uspace/libc/arch/sparc64/src/thread_entry.s |
---|
1,5 → 1,5 |
# |
# Copyright (C) 2006 Jakub Jermar |
# Copyright (C) 2006 Martin Decky |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
34,10 → 34,5 |
# |
# |
__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) 2005 Jakub Jermar |
# Copyright (C) 2006 Martin Decky |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
26,80 → 26,14 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
# |
#include <libarch/context_offset.h> |
.text |
/** |
* 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 |
.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 |
#include <libarch/context_offset.h> |
.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 |
/trunk/uspace/libc/arch/sparc64/_link.ld.in |
---|
7,9 → 7,9 |
} |
SECTIONS { |
. = 0x2000; |
. = 0x1000; |
.init ALIGN(0x2000) : SUBALIGN(0x2000) { |
.init ALIGN(0x1000) : SUBALIGN(0x1000) { |
*(.init); |
} :text |
.text : { |
17,11 → 17,7 |
*(.rodata*); |
} :text |
.got ALIGN(0x2000) : SUBALIGN(0x2000) { |
_gp = .; |
*(.got*); |
} :data |
.data ALIGN(0x2000) : SUBALIGN(0x2000) { |
.data ALIGN(0x1000) : SUBALIGN(0x1000) { |
*(.data); |
*(.sdata); |
} :data |
41,7 → 37,7 |
*(.bss); |
} :data |
. = ALIGN(0x2000); |
. = ALIGN(0x1000); |
_heap = .; |
/DISCARD/ : { |