kolibrios/programs/develop/libraries/newlib/reent/getreent.c
Sergey Semyonov (Serge) 2336060a0c newlib: update
git-svn-id: svn://kolibrios.org@1906 a494cfbc-eb01-0410-851d-a64ba20cac60
2011-03-11 18:52:24 +00:00

56 lines
927 B
C

/* default reentrant pointer when multithread enabled */
#include <_ansi.h>
#include <string.h>
#include <reent.h>
static inline
void *user_alloc(int size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=eax"(val)
:"a"(68),"b"(12),"c"(size));
return val;
}
void init_reent()
{
struct _reent *ent;
ent = user_alloc(sizeof(struct _reent));
_REENT_INIT_PTR(ent);
__asm__ __volatile__(
"movl %0, %%fs:12"
::"r"(ent));
__sinit(ent);
}
void __mutex_lock(volatile int *val)
{
int tmp;
__asm__ __volatile__ (
"0:\n\t"
"mov %0, %1\n\t"
"testl %1, %1\n\t"
"jz 1f\n\t"
"movl $68, %%eax\n\t"
"movl $1, %%ebx\n\t"
"int $0x40\n\t"
"jmp 0b\n\t"
"1:\n\t"
"incl %1\n\t"
"xchgl %0, %1\n\t"
"testl %1, %1\n\t"
"jnz 0b\n"
: "+m" (*val), "=&r"(tmp)
::"eax","ebx" );
}