Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* default reentrant pointer when multithread enabled */
  2.  
  3. #include <_ansi.h>
  4. #include <string.h>
  5. #include <reent.h>
  6.  
  7. #ifdef __getreent
  8. #undef __getreent
  9. #endif
  10.  
  11. static inline
  12. void *user_alloc(int size)
  13. {
  14.     void  *val;
  15.     __asm__ __volatile__(
  16.     "int $0x40"
  17.     :"=eax"(val)
  18.     :"a"(68),"b"(12),"c"(size));
  19.     return val;
  20. }
  21.  
  22. void init_reent()
  23. {
  24.     struct _reent *ent;
  25.  
  26.     ent = user_alloc(sizeof(struct _reent));
  27.  
  28.     _REENT_INIT_PTR(ent);
  29.  
  30.     __asm__ __volatile__(
  31.     "movl %0, %%fs:0"
  32.     ::"r"(ent));
  33.     __sinit(ent);
  34. }
  35.  
  36. struct _reent *
  37. _DEFUN_VOID(__getreent)
  38. {
  39.     struct _reent *ent;
  40.  
  41.     __asm__ __volatile__(
  42.     "movl %%fs:0, %0"
  43.     :"=r"(ent));
  44.     return ent;
  45. }
  46.  
  47. void __mutex_lock(volatile int *val)
  48. {
  49.     int tmp;
  50.  
  51.     __asm__ __volatile__ (
  52. "0:\n\t"
  53.     "mov %0, %1\n\t"
  54.     "testl %1, %1\n\t"
  55.     "jz 1f\n\t"
  56.  
  57.     "movl $68, %%eax\n\t"
  58.     "movl $1,  %%ebx\n\t"
  59.     "int  $0x40\n\t"
  60.     "jmp 0b\n\t"
  61. "1:\n\t"
  62.     "incl %1\n\t"
  63.     "xchgl %0, %1\n\t"
  64.     "testl %1, %1\n\t"
  65.         "jnz 0b\n"
  66.     : "+m" (*val), "=&r"(tmp)
  67.     ::"eax","ebx" );
  68. }
  69.