- Timestamp:
- 2006-09-03T23:37:14Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fd85ae5
- Parents:
- 002e613
- Location:
- uspace/libc/arch/sparc64
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/libc/arch/sparc64/_link.ld.in
r002e613 rcfa70add 8 8 9 9 SECTIONS { 10 . = 0x 1000;10 . = 0x2000; 11 11 12 .init ALIGN(0x 1000) : SUBALIGN(0x1000) {12 .init ALIGN(0x2000) : SUBALIGN(0x2000) { 13 13 *(.init); 14 14 } :text … … 18 18 } :text 19 19 20 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 20 .got ALIGN(0x2000) : SUBALIGN(0x2000) { 21 _gp = .; 22 *(.got*); 23 } :data 24 .data ALIGN(0x2000) : SUBALIGN(0x2000) { 21 25 *(.data); 22 26 *(.sdata); … … 38 42 } :data 39 43 40 . = ALIGN(0x 1000);44 . = ALIGN(0x2000); 41 45 _heap = .; 42 46 -
uspace/libc/arch/sparc64/include/atomic.h
r002e613 rcfa70add 1 1 /* 2 * Copyright (C) 2005 Martin Decky2 * Copyright (C) 2005 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libcsparc64 29 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef __sparc64_ATOMIC_H__ 36 #define __sparc64_ATOMIC_H__ 35 #ifndef LIBC_sparc64_ATOMIC_H_ 36 #define LIBC_sparc64_ATOMIC_H_ 37 38 #include <types.h> 39 40 /** Atomic add operation. 41 * 42 * Use atomic compare and swap operation to atomically add signed value. 43 * 44 * @param val Atomic variable. 45 * @param i Signed value to be added. 46 * 47 * @return Value of the atomic variable as it existed before addition. 48 */ 49 static inline long atomic_add(atomic_t *val, int i) 50 { 51 uint64_t a, b; 52 volatile uint64_t x = (uint64_t) &val->count; 53 54 __asm__ volatile ( 55 "0:\n" 56 "ldx %0, %1\n" 57 "add %1, %3, %2\n" 58 "casx %0, %1, %2\n" 59 "cmp %1, %2\n" 60 "bne 0b\n" /* The operation failed and must be attempted again if a != b. */ 61 "nop\n" 62 : "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b) 63 : "r" (i) 64 ); 65 66 return a; 67 } 68 69 static inline long atomic_preinc(atomic_t *val) 70 { 71 return atomic_add(val, 1) + 1; 72 } 73 74 static inline long atomic_postinc(atomic_t *val) 75 { 76 return atomic_add(val, 1); 77 } 78 79 static inline long atomic_predec(atomic_t *val) 80 { 81 return atomic_add(val, -1) - 1; 82 } 83 84 static inline long atomic_postdec(atomic_t *val) 85 { 86 return atomic_add(val, -1); 87 } 37 88 38 89 static inline void atomic_inc(atomic_t *val) 39 90 { 91 (void) atomic_add(val, 1); 40 92 } 41 93 42 94 static inline void atomic_dec(atomic_t *val) 43 95 { 44 } 45 46 static inline long atomic_postinc(atomic_t *val) 47 { 48 atomic_inc(val); 49 return val->count - 1; 50 } 51 52 static inline long atomic_postdec(atomic_t *val) 53 { 54 atomic_dec(val); 55 return val->count + 1; 56 } 57 58 static inline long atomic_preinc(atomic_t *val) 59 { 60 atomic_inc(val); 61 return val->count; 62 } 63 64 static inline long atomic_predec(atomic_t *val) 65 { 66 atomic_dec(val); 67 return val->count; 96 (void) atomic_add(val, -1); 68 97 } 69 98 -
uspace/libc/arch/sparc64/include/config.h
r002e613 rcfa70add 27 27 */ 28 28 29 /** @addtogroup lib sparc6429 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ … … 36 36 #define LIBC_sparc64_CONFIG_H_ 37 37 38 #define PAGE_WIDTH 1 238 #define PAGE_WIDTH 13 39 39 #define PAGE_SIZE (1<<PAGE_WIDTH) 40 40 -
uspace/libc/arch/sparc64/include/context_offset.h
r002e613 rcfa70add 1 /* This file is automatically generated by gencontext.c. */ 1 2 /* struct context */ 3 #define OFFSET_SP 0x0 4 #define OFFSET_PC 0x8 5 #define OFFSET_I0 0x10 6 #define OFFSET_I1 0x18 7 #define OFFSET_I2 0x20 8 #define OFFSET_I3 0x28 9 #define OFFSET_I4 0x30 10 #define OFFSET_I5 0x38 11 #define OFFSET_FP 0x40 12 #define OFFSET_I7 0x48 13 #define OFFSET_L0 0x50 14 #define OFFSET_L1 0x58 15 #define OFFSET_L2 0x60 16 #define OFFSET_L3 0x68 17 #define OFFSET_L4 0x70 18 #define OFFSET_L5 0x78 19 #define OFFSET_L6 0x80 20 #define OFFSET_L7 0x88 21 #define OFFSET_TP 0x90 2 22 3 /** @}4 */ -
uspace/libc/arch/sparc64/include/endian.h
r002e613 rcfa70add 27 27 */ 28 28 29 29 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef __sparc64_ENDIAN_H__36 #define __sparc64_ENDIAN_H__35 #ifndef LIBC_sparc64_ENDIAN_H_ 36 #define LIBC_sparc64_ENDIAN_H_ 37 37 38 38 #ifndef __LIBC__ENDIAN_H__ … … 44 44 #endif 45 45 46 46 /** @} 47 47 */ 48 -
uspace/libc/arch/sparc64/include/limits.h
r002e613 rcfa70add 33 33 */ 34 34 35 #ifndef __sparc64__LIMITS_H__36 #define __sparc64__LIMITS_H__35 #ifndef LIBC_sparc64__LIMITS_H_ 36 #define LIBC_sparc64__LIMITS_H_ 37 37 38 38 #define LONG_MIN MIN_INT64 -
uspace/libc/arch/sparc64/include/psthread.h
r002e613 rcfa70add 1 1 /* 2 * Copyright (C) 200 6 Martin Decky2 * Copyright (C) 2005 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libcsparc64 29 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef __LIBC__sparc64__PSTHREAD_H__36 #define __LIBC__sparc64__PSTHREAD_H__35 #ifndef LIBC_sparc64_PSTHREAD_H_ 36 #define LIBC_sparc64_PSTHREAD_H_ 37 37 38 #include <libarch/stack.h> 38 39 #include <types.h> 40 #include <align.h> 39 41 40 /* We define our own context_set, because we need to set 41 * the TLS pointer to the tcb+0x7000 42 * 43 * See tls_set in thread.h 42 #define SP_DELTA STACK_WINDOW_SAVE_AREA_SIZE 43 44 #ifdef context_set 45 #undef context_set 46 #endif 47 48 #define context_set(c, _pc, stack, size, ptls) \ 49 (c)->pc = ((uintptr_t) _pc) - 8; \ 50 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ 51 (c)->fp = -STACK_BIAS; \ 52 (c)->tp = ptls 53 54 /* 55 * Only save registers that must be preserved across 56 * function calls. 44 57 */ 45 #define context_set(c, _pc, stack, size, ptls) \46 (c)->pc = (sysarg_t) (_pc); \47 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \48 (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);49 50 #define SP_DELTA 1651 52 58 typedef struct { 53 uint64_t sp; 54 uint64_t pc; 55 56 uint64_t tls; 57 } __attribute__ ((packed)) context_t; 59 uintptr_t sp; /* %o6 */ 60 uintptr_t pc; /* %o7 */ 61 uint64_t i0; 62 uint64_t i1; 63 uint64_t i2; 64 uint64_t i3; 65 uint64_t i4; 66 uint64_t i5; 67 uintptr_t fp; /* %i6 */ 68 uintptr_t i7; 69 uint64_t l0; 70 uint64_t l1; 71 uint64_t l2; 72 uint64_t l3; 73 uint64_t l4; 74 uint64_t l5; 75 uint64_t l6; 76 uint64_t l7; 77 uint64_t tp; /* %g7 */ 78 } context_t; 58 79 59 80 #endif -
uspace/libc/arch/sparc64/include/stackarg.h
r002e613 rcfa70add 33 33 */ 34 34 35 #ifndef __LIBC__STACKARG_H__36 #define __LIBC__STACKARG_H__35 #ifndef LIBC_sparc64_STACKARG_H_ 36 #define LIBC_sparc64_STACKARG_H_ 37 37 38 38 #endif 39 39 40 41 40 /** @} 42 41 */ -
uspace/libc/arch/sparc64/include/syscall.h
r002e613 rcfa70add 27 27 */ 28 28 29 /** @addtogroup libc 29 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ -
uspace/libc/arch/sparc64/include/thread.h
r002e613 rcfa70add 1 1 /* 2 * Copyright (C) 2006 Martin Decky 2 * Copyright (C) 2006 Ondrej Palkovsky 3 * Copyright (C) 2006 Jakub Jermar 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 29 /** @addtogroup libcsparc64 30 /** @addtogroup libcsparc64 30 31 * @{ 31 32 */ 32 /** @file 33 /** 34 * @file 35 * @brief sparc64 TLS functions. 36 * 37 * The implementation is based on the IA-32 implementation which was also 38 * designed by Sun and is virtually the same, except the TCB is stored in 39 * %g7 (of the normal set). 33 40 */ 34 41 35 #ifndef __LIBC__sparc64__THREAD_H__ 36 #define __LIBC__sparc64__THREAD_H__ 37 38 #define PPC_TP_OFFSET 0x7000 42 #ifndef LIBC_sparc64_THREAD_H_ 43 #define LIBC_sparc64_THREAD_H_ 39 44 40 45 typedef struct { 46 void *self; 41 47 void *pst_data; 42 48 } tcb_t; … … 44 50 static inline void __tcb_set(tcb_t *tcb) 45 51 { 46 void *tp = tcb; 47 tp += PPC_TP_OFFSET + sizeof(tcb_t); 52 __asm__ volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7"); 48 53 } 49 54 50 static inline tcb_t * __tcb_get(void)55 static inline tcb_t * __tcb_get(void) 51 56 { 52 return (tcb_t *)(PPC_TP_OFFSET - sizeof(tcb_t)); 57 void *retval; 58 59 __asm__ volatile ("mov %%g7, %0\n" : "=r" (retval)); 60 61 return retval; 53 62 } 54 63 -
uspace/libc/arch/sparc64/include/types.h
r002e613 rcfa70add 36 36 #define LIBC_sparc64_TYPES_H_ 37 37 38 typedef unsigned intsysarg_t;39 typedef unsigned intsize_t;40 typedef signed intssize_t;38 typedef unsigned long sysarg_t; 39 typedef unsigned long size_t; 40 typedef signed long ssize_t; 41 41 typedef ssize_t off_t; 42 42 43 typedef char int8_t;43 typedef signed char int8_t; 44 44 typedef short int int16_t; 45 45 typedef int int32_t; -
uspace/libc/arch/sparc64/src/entry.s
r002e613 rcfa70add 38 38 # 39 39 __entry: 40 sethi %hi(_gp), %l7 41 call __main 42 or %l7, %lo(_gp), %l7 43 call __io_init 44 nop 45 call main 46 nop 47 call __exit 48 nop 40 49 41 50 __entry_driver: 51 sethi %hi(_gp), %l7 52 call __main 53 or %l7, %lo(_gp), %l7 54 call main 55 nop 56 call __exit 57 nop -
uspace/libc/arch/sparc64/src/psthread.S
r002e613 rcfa70add 1 1 # 2 # Copyright (C) 200 6 Martin Decky2 # Copyright (C) 2005 Jakub Jermar 3 3 # All rights reserved. 4 4 # … … 27 27 # 28 28 29 .text 29 #include <libarch/context_offset.h> 30 31 /** 32 * Both context_save_arch() and context_restore_arch() are 33 * leaf-optimized procedures. This kind of optimization 34 * is very important and prevents any implicit window 35 * spill/fill/clean traps in these very core kernel 36 * functions. 37 */ 38 39 .text 30 40 31 41 .global context_save 32 42 .global context_restore 33 43 34 #include <libarch/context_offset.h> 44 .macro CONTEXT_STORE r 45 stx %sp, [\r + OFFSET_SP] 46 stx %o7, [\r + OFFSET_PC] 47 stx %i0, [\r + OFFSET_I0] 48 stx %i1, [\r + OFFSET_I1] 49 stx %i2, [\r + OFFSET_I2] 50 stx %i3, [\r + OFFSET_I3] 51 stx %i4, [\r + OFFSET_I4] 52 stx %i5, [\r + OFFSET_I5] 53 stx %fp, [\r + OFFSET_FP] 54 stx %i7, [\r + OFFSET_I7] 55 stx %l0, [\r + OFFSET_L0] 56 stx %l1, [\r + OFFSET_L1] 57 stx %l2, [\r + OFFSET_L2] 58 stx %l3, [\r + OFFSET_L3] 59 stx %l4, [\r + OFFSET_L4] 60 stx %l5, [\r + OFFSET_L5] 61 stx %l6, [\r + OFFSET_L6] 62 stx %l7, [\r + OFFSET_L7] 63 stx %g7, [\r + OFFSET_TP] 64 .endm 65 66 .macro CONTEXT_LOAD r 67 ldx [\r + OFFSET_SP], %sp 68 ldx [\r + OFFSET_PC], %o7 69 ldx [\r + OFFSET_I0], %i0 70 ldx [\r + OFFSET_I1], %i1 71 ldx [\r + OFFSET_I2], %i2 72 ldx [\r + OFFSET_I3], %i3 73 ldx [\r + OFFSET_I4], %i4 74 ldx [\r + OFFSET_I5], %i5 75 ldx [\r + OFFSET_FP], %fp 76 ldx [\r + OFFSET_I7], %i7 77 ldx [\r + OFFSET_L0], %l0 78 ldx [\r + OFFSET_L1], %l1 79 ldx [\r + OFFSET_L2], %l2 80 ldx [\r + OFFSET_L3], %l3 81 ldx [\r + OFFSET_L4], %l4 82 ldx [\r + OFFSET_L5], %l5 83 ldx [\r + OFFSET_L6], %l6 84 ldx [\r + OFFSET_L7], %l7 85 ldx [\r + OFFSET_TP], %g7 86 .endm 35 87 36 88 context_save: 37 89 CONTEXT_STORE %o0 90 retl 91 mov 1, %o0 ! context_save_arch returns 1 38 92 39 93 context_restore: 94 # 95 # Flush all active windows. 96 # This is essential, because CONTEXT_LOAD overwrites 97 # %sp of CWP - 1 with the value written to %fp of CWP. 98 # Flushing all active windows mitigates this problem 99 # as CWP - 1 becomes the overlap window. 100 # 101 flushw 102 103 CONTEXT_LOAD %o0 104 retl 105 xor %o0, %o0, %o0 ! context_restore_arch returns 0 -
uspace/libc/arch/sparc64/src/thread.c
r002e613 rcfa70add 27 27 */ 28 28 29 /** @addtogroup libcsparc64 29 /** @addtogroup libcsparc64 sparc64 30 * @ingroup lc 30 31 * @{ 31 32 */ 32 33 /** @file 34 * 33 35 */ 34 36 … … 40 42 * @param data Start of data section 41 43 * @return pointer to tcb_t structure 42 *43 44 */ 44 45 tcb_t * __alloc_tls(void **data, size_t size) 45 46 { 46 tcb_t *result; 47 tcb_t *tcb; 48 49 *data = malloc(sizeof(tcb_t) + size); 47 50 48 result = malloc(sizeof(tcb_t) + size); 49 *data = ((void *)result) + sizeof(tcb_t); 50 return result; 51 tcb = (tcb_t *) (*data + size); 52 tcb->self = tcb; 53 54 return tcb; 51 55 } 52 56 53 57 void __free_tls_arch(tcb_t *tcb, size_t size) 54 58 { 55 free(tcb); 59 void *start = ((void *)tcb) - size; 60 free(start); 56 61 } 57 62 -
uspace/libc/arch/sparc64/src/thread_entry.s
r002e613 rcfa70add 1 1 # 2 # Copyright (C) 2006 Martin Decky2 # Copyright (C) 2006 Jakub Jermar 3 3 # All rights reserved. 4 4 # … … 35 35 # 36 36 __thread_entry: 37 37 sethi %hi(_gp), %l7 38 call __thread_main ! %o0 contains address of uarg 39 or %l7, %lo(_gp), %l7 40 41 ! not reached 42 38 43 .end __thread_entry
Note:
See TracChangeset
for help on using the changeset viewer.