Compare commits
No commits in common. "e15b705eda11b2742c724a2973bee33211f499bb" and "c38a0cbf41ed2550295657892b053695a854930c" have entirely different histories.
e15b705eda
...
c38a0cbf41
3 changed files with 54 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef ENDIAN_KERNEL_H
|
#ifndef ENDIAN_KERNEL_H
|
||||||
#define ENDIAN_KERNEL_H
|
#define ENDIAN_KERNEL_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <types.h>
|
||||||
|
|
||||||
/** Swap byte order of 16-bit value */
|
/** Swap byte order of 16-bit value */
|
||||||
static inline u16 swap16(u16 x) {
|
static inline u16 swap16(u16 x) {
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ uint32_t pop_off(void) {
|
||||||
PANIC("pop_off - interruptible");
|
PANIC("pop_off - interruptible");
|
||||||
|
|
||||||
if (cpu->noff < 1)
|
if (cpu->noff < 1)
|
||||||
PANIC("pop_off when cpu->noff < 1");
|
PANIC("pop_off");
|
||||||
|
|
||||||
cpu->noff -= 1;
|
cpu->noff -= 1;
|
||||||
|
|
||||||
|
|
@ -89,8 +89,8 @@ __attribute__((warn_unused_result)) bool spin_trylock(spinlock_t *l) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void spin_unlock(spinlock_t *l) {
|
void spin_unlock(spinlock_t *l) {
|
||||||
if (!spin_is_holding(l))
|
// if (!spin_is_holding(l))
|
||||||
PANIC("Unlocking a spinlock that is not held by the locking cpu!");
|
// panic("spin_unlock");
|
||||||
|
|
||||||
l->cpu = 0;
|
l->cpu = 0;
|
||||||
|
|
||||||
|
|
@ -98,10 +98,10 @@ void spin_unlock(spinlock_t *l) {
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
__asm__ volatile("amoswap.w.rl %0, %2, (%1)\n" : "=&r"(dummy) : "r"(&l->v), "r"(0u) : "memory");
|
__asm__ volatile("amoswap.w.rl %0, %2, (%1)\n" : "=&r"(dummy) : "r"(&l->v), "r"(0u) : "memory");
|
||||||
|
|
||||||
__sync_synchronize(); // No loads/stores after this point
|
// __sync_synchronize(); // No loads/stores after this point
|
||||||
// __sync_lock_release(&lk->locked); // Essentially lk->locked = 0
|
// __sync_lock_release(&lk->locked); // Essentially lk->locked = 0
|
||||||
|
|
||||||
pop_off();
|
// pop_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,11 +110,8 @@ void spin_unlock(spinlock_t *l) {
|
||||||
void spin_lock(spinlock_t *l) {
|
void spin_lock(spinlock_t *l) {
|
||||||
uint32_t backoff = 1;
|
uint32_t backoff = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (spin_trylock(l)) {
|
if (spin_trylock(l))
|
||||||
l->cpu = mycpu();
|
|
||||||
push_off();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
while (__atomic_load_n(&l->v, __ATOMIC_RELAXED) != 0) {
|
while (__atomic_load_n(&l->v, __ATOMIC_RELAXED) != 0) {
|
||||||
for (uint32_t i = 0; i < backoff; ++i)
|
for (uint32_t i = 0; i < backoff; ++i)
|
||||||
|
|
@ -123,6 +120,8 @@ void spin_lock(spinlock_t *l) {
|
||||||
backoff <<= 1;
|
backoff <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l->cpu = mycpu();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,18 @@ void *memset(void *dest, int c, size_t n) {
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int memcmp(const void *s1, const void *s2, size_t n) {
|
||||||
|
// if (n != 0) {
|
||||||
|
// const unsigned char *p1 = s1, *p2 = s2;
|
||||||
|
//
|
||||||
|
// do {
|
||||||
|
// if (*p1++ != *p2++)
|
||||||
|
// return (*--p1 - *--p2);
|
||||||
|
// } while (--n != 0);
|
||||||
|
// }
|
||||||
|
// return (0);
|
||||||
|
// }
|
||||||
|
|
||||||
char *itoa(int value, char *str, int base) {
|
char *itoa(int value, char *str, int base) {
|
||||||
char *p = str;
|
char *p = str;
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
|
|
@ -154,6 +166,39 @@ char *itoa(int value, char *str, int base) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void *memset(void *dst, int c, size_t length) {
|
||||||
|
// u8 *ptr = (u8 *)dst;
|
||||||
|
// const u8 value = (u8)c;
|
||||||
|
//
|
||||||
|
// while (length--) *(ptr++) = value;
|
||||||
|
//
|
||||||
|
// return dst;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void *memcpy(void *dst, const void *src, size_t len) {
|
||||||
|
// u8 *d = (u8 *)dst;
|
||||||
|
// const u8 *s = (const u8 *)src;
|
||||||
|
// for (size_t i = 0; i < len; i++) {
|
||||||
|
// d[i] = s[i];
|
||||||
|
// }
|
||||||
|
// return dst;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void *memmove(void *dst, const void *src, size_t len) {
|
||||||
|
// u8 *d = (u8 *)dst;
|
||||||
|
// const u8 *s = (const u8 *)src;
|
||||||
|
// if (d < s) {
|
||||||
|
// for (size_t i = 0; i < len; i++) {
|
||||||
|
// d[i] = s[i];
|
||||||
|
// }
|
||||||
|
// } else if (d > s) {
|
||||||
|
// for (size_t i = len; i > 0; i--) {
|
||||||
|
// d[i - 1] = s[i - 1];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return dst;
|
||||||
|
// }
|
||||||
|
|
||||||
int memcmp(const void *s1, const void *s2, size_t len) {
|
int memcmp(const void *s1, const void *s2, size_t len) {
|
||||||
const u8 *a = (const u8 *)s1;
|
const u8 *a = (const u8 *)s1;
|
||||||
const u8 *b = (const u8 *)s2;
|
const u8 *b = (const u8 *)s2;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue