/branches/dynload/kernel/generic/src/lib/memstr.c |
---|
34,10 → 34,12 |
* @file |
* @brief Memory string operations. |
* |
* This file provides architecture independent functions to manipulate blocks of |
* memory. These functions are optimized as much as generic functions of this |
* type can be. However, architectures are free to provide even more optimized |
* versions of these functions. |
* This file provides architecture independent functions |
* to manipulate blocks of memory. These functions |
* are optimized as much as generic functions of |
* this type can be. However, architectures are |
* free to provide even more optimized versions of these |
* functions. |
*/ |
#include <memstr.h> |
44,33 → 46,32 |
#include <arch/types.h> |
#include <align.h> |
/** Copy block of memory. |
/** Copy block of memory |
* |
* Copy cnt bytes from src address to dst address. The copying is done |
* word-by-word and then byte-by-byte. The source and destination memory areas |
* cannot overlap. |
* Copy cnt bytes from src address to dst address. |
* The copying is done word-by-word and then byte-by-byte. |
* The source and destination memory areas cannot overlap. |
* |
* @param src Source address to copy from. |
* @param dst Destination address to copy to. |
* @param cnt Number of bytes to copy. |
* @param src Origin address to copy from. |
* @param dst Origin address to copy to. |
* @param cnt Number of bytes to copy. |
* |
* @return Destination address. |
*/ |
void *_memcpy(void *dst, const void *src, size_t cnt) |
void *_memcpy(void * dst, const void *src, size_t cnt) |
{ |
unsigned int i, j; |
if (ALIGN_UP((uintptr_t) src, sizeof(unative_t)) != (uintptr_t) src || |
ALIGN_UP((uintptr_t) dst, sizeof(unative_t)) != (uintptr_t) dst) { |
ALIGN_UP((uintptr_t) dst, sizeof(unative_t)) != (uintptr_t) dst) { |
for (i = 0; i < cnt; i++) |
((uint8_t *) dst)[i] = ((uint8_t *) src)[i]; |
} else { |
for (i = 0; i < cnt / sizeof(unative_t); i++) |
((unative_t *) dst)[i] = ((unative_t *) src)[i]; |
for (j = 0; j < cnt % sizeof(unative_t); j++) |
((uint8_t *)(((unative_t *) dst) + i))[j] = |
((uint8_t *)(((unative_t *) src) + i))[j]; |
((uint8_t *)(((unative_t *) dst) + i))[j] = ((uint8_t *)(((unative_t *) src) + i))[j]; |
} |
return (char *) dst; |
78,12 → 79,12 |
/** Fill block of memory |
* |
* Fill cnt bytes at dst address with the value x. The filling is done |
* byte-by-byte. |
* Fill cnt bytes at dst address with the value x. |
* The filling is done byte-by-byte. |
* |
* @param dst Destination address to fill. |
* @param cnt Number of bytes to fill. |
* @param x Value to fill. |
* @param dst Origin address to fill. |
* @param cnt Number of bytes to fill. |
* @param x Value to fill. |
* |
*/ |
void _memsetb(void *dst, size_t cnt, uint8_t x) |
95,14 → 96,14 |
p[i] = x; |
} |
/** Fill block of memory. |
/** Fill block of memory |
* |
* Fill cnt words at dst address with the value x. The filling is done |
* word-by-word. |
* Fill cnt words at dst address with the value x. |
* The filling is done word-by-word. |
* |
* @param dst Destination address to fill. |
* @param cnt Number of words to fill. |
* @param x Value to fill. |
* @param dst Origin address to fill. |
* @param cnt Number of words to fill. |
* @param x Value to fill. |
* |
*/ |
void _memsetw(void *dst, size_t cnt, uint16_t x) |
114,16 → 115,16 |
p[i] = x; |
} |
/** Copy string. |
/** Copy string |
* |
* Copy string from src address to dst address. The copying is done |
* char-by-char until the null character. The source and destination memory |
* areas cannot overlap. |
* Copy string from src address to dst address. |
* The copying is done char-by-char until the null |
* character. The source and destination memory areas |
* cannot overlap. |
* |
* @param src Source string to copy from. |
* @param dst Destination string to copy to. |
* @param src Origin string to copy from. |
* @param dst Origin string to copy to. |
* |
* @return Address of the destination string. |
*/ |
char *strcpy(char *dest, const char *src) |
{ |
/branches/dynload/kernel/arch/ppc32/include/regutils.h |
---|
File deleted |
/branches/dynload/kernel/arch/ppc32/include/exception.h |
---|
36,7 → 36,6 |
#define KERN_ppc32_EXCEPTION_H_ |
#include <arch/types.h> |
#include <arch/regutils.h> |
typedef struct { |
uint32_t r0; |
85,10 → 84,11 |
} |
/** Return true if exception happened while in userspace */ |
#include <panic.h> |
static inline int istate_from_uspace(istate_t *istate) |
{ |
/* true if privilege level PR (copied from MSR) == 1 */ |
return (istate->srr1 & MSR_PR) != 0; |
panic("istate_from_uspace not yet implemented"); |
return 0; |
} |
static inline unative_t istate_get_pc(istate_t *istate) |
/branches/dynload/kernel/arch/ppc32/include/asm/regname.h |
---|
214,8 → 214,8 |
#define hid0 1008 |
/* MSR bits */ |
#define msr_dr (1 << 4) |
#define msr_ir (1 << 5) |
#define msr_ir (1 << 4) |
#define msr_dr (1 << 5) |
#define msr_pr (1 << 14) |
#define msr_ee (1 << 15) |
/branches/dynload/boot/generic/string.c |
---|
39,9 → 39,9 |
/** Return number of characters in a string. |
* |
* @param str NULL terminated string. |
* @param str NULL terminated string. |
* |
* @return Number of characters in str. |
* @return Number of characters in str. |
*/ |
size_t strlen(const char *str) |
{ |
53,17 → 53,16 |
return i; |
} |
/** Compare two NULL terminated strings. |
/** Compare two NULL terminated strings |
* |
* Do a char-by-char comparison of two NULL terminated strings. |
* The strings are considered equal iff they consist of the same |
* characters on the minimum of their lengths. |
* |
* @param src First string to compare. |
* @param dst Second string to compare. |
* @param src First string to compare. |
* @param dst Second string to compare. |
* |
* @return 0 if the strings are equal, -1 if first is smaller, |
* 1 if second smaller. |
* @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
* |
*/ |
int strcmp(const char *src, const char *dst) |
82,7 → 81,7 |
} |
/** Compare two NULL terminated strings. |
/** Compare two NULL terminated strings |
* |
* Do a char-by-char comparison of two NULL terminated strings. |
* The strings are considered equal iff they consist of the same |
89,12 → 88,11 |
* characters on the minimum of their lengths and specified maximal |
* length. |
* |
* @param src First string to compare. |
* @param dst Second string to compare. |
* @param len Maximal length for comparison. |
* @param src First string to compare. |
* @param dst Second string to compare. |
* @param len Maximal length for comparison. |
* |
* @return 0 if the strings are equal, -1 if first is smaller, |
* 1 if second smaller. |
* @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
* |
*/ |
int strncmp(const char *src, const char *dst, size_t len) |
120,9 → 118,9 |
* If 'src' is shorter than 'len', '\0' is inserted behind the |
* last copied character. |
* |
* @param src Source string. |
* @param dest Destination buffer. |
* @param len Size of destination buffer. |
* @param src Source string. |
* @param dest Destination buffer. |
* @param len Size of destination buffer. |
*/ |
void strncpy(char *dest, const char *src, size_t len) |
{ |
134,13 → 132,13 |
dest[i-1] = '\0'; |
} |
/** Convert ascii representation to unative_t. |
/** Convert ascii representation to unative_t |
* |
* Supports 0x for hexa & 0 for octal notation. |
* Does not check for overflows, does not support negative numbers |
* |
* @param text Textual representation of number. |
* @return Converted number or 0 if no valid number found. |
* @param text Textual representation of number |
* @return Converted number or 0 if no valid number ofund |
*/ |
unative_t atoi(const char *text) |
{ |
154,9 → 152,9 |
base = 8; |
while (*text) { |
if (base != 16 && |
((*text >= 'A' && *text <= 'F') || |
(*text >='a' && *text <='f'))) |
if (base != 16 && \ |
((*text >= 'A' && *text <= 'F' ) |
|| (*text >='a' && *text <='f'))) |
break; |
if (base == 8 && *text >='8') |
break; |
178,28 → 176,5 |
return result; |
} |
/** Move piece of memory to another, possibly overlapping, location. |
* |
* @param dst Destination address. |
* @param src Source address. |
* @param len Number of bytes to move. |
* |
* @return Destination address. |
*/ |
void *memmove(void *dst, const void *src, size_t len) |
{ |
char *d = dst; |
const char *s = src; |
if (s < d) { |
while (len--) |
*(d + len) = *(s + len); |
} else { |
while (len--) |
*d++ = *s++; |
} |
return dst; |
} |
/** @} |
*/ |
/branches/dynload/boot/generic/string.h |
---|
42,7 → 42,6 |
extern int strncmp(const char *src, const char *dst, size_t len); |
extern void strncpy(char *dest, const char *src, size_t len); |
extern unative_t atoi(const char *text); |
extern void *memmove(void *dst, const void *src, size_t len); |
#endif |