Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include <types.h>
  3. #include <core.h>
  4. #include <spinlock.h>
  5. #include <link.h>
  6. #include <mm.h>
  7. #include <slab.h>
  8.  
  9. addr_t thr_ptr;
  10.  
  11. slab_cache_t *thr_slab;
  12.  
  13. extern addr_t sys_pdbr;
  14.  
  15. void init_threads()
  16. {
  17.     thr_slab = slab_cache_create(sizeof(thr_t), 16,
  18.                NULL,NULL,SLAB_CACHE_MAGDEFERRED);
  19. };
  20.  
  21.  
  22. thr_t* __fastcall create_systhread(addr_t entry_ptr)
  23. {
  24.     static count_t  thr_cnt = 0;
  25.     static count_t  slot = 1;
  26.  
  27.     thr_t   *thr;
  28.     addr_t   thr_stack;
  29.  
  30.     thr = (thr_t*)slab_alloc(thr_slab,0);
  31.     thr_stack = PA2KA(core_alloc(1));
  32.  
  33.     thr_cnt++;
  34.  
  35.     thr->eax = (thr_cnt<<8)|slot;
  36.     thr->tid = (thr_cnt<<8)|slot;
  37.  
  38.     thr->slot = slot;
  39.  
  40.     slot++;
  41.  
  42.     thr->pdir = KA2PA(&sys_pdbr);
  43.  
  44.     thr->ebx = 0;
  45.  
  46.     thr->edi = 0;
  47.     thr->esi = 0;
  48.     thr->ebp = 0;
  49.     thr->edx = 0;
  50.     thr->ecx = 0;
  51.  
  52.     thr->cs  = sel_srv_code;
  53.     thr->eflags = EFL_IOPL1;
  54.     thr->esp = thr_stack + 8192;
  55.     thr->ss = sel_srv_stack;
  56.  
  57.     thr->thr_flags    = 0;
  58.  
  59.     thr->ticks_left   = 8;
  60.     thr->quantum_size = 8;
  61.  
  62.     thr->eip = entry_ptr;
  63.  
  64.     //lock_enqueue(thr_ptr);       /* add to scheduling queues */
  65.  
  66.     return thr;
  67. };
  68.  
  69.