Subversion Repositories Kolibri OS

Rev

Rev 928 | 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.     DBG("%s\n", __FUNCTION__);
  18.  
  19.     thr_slab = slab_cache_create(sizeof(thr_t), 16,
  20.                NULL,NULL,SLAB_CACHE_MAGDEFERRED);
  21. };
  22.  
  23.  
  24. thr_t* __fastcall create_systhread(addr_t entry_ptr)
  25. {
  26.     static count_t  thr_cnt = 0;
  27.     static count_t  slot = 1;
  28.  
  29.     thr_t   *thr;
  30.     addr_t   thr_stack;
  31.  
  32.     DBG("%s\n", __FUNCTION__);
  33.  
  34.     thr = (thr_t*)slab_alloc(thr_slab,0);
  35.     thr_stack = PA2KA(frame_alloc(2));
  36.  
  37.     thr_cnt++;
  38.  
  39.     thr->eax = (thr_cnt<<8)|slot;
  40.     thr->tid = (thr_cnt<<8)|slot;
  41.  
  42.     thr->slot = slot;
  43.  
  44.     slot++;
  45.  
  46.     thr->pdir = KA2PA(&sys_pdbr);
  47.  
  48.     thr->ebx = 0;
  49.  
  50.     thr->edi = 0;
  51.     thr->esi = 0;
  52.     thr->ebp = 0;
  53.     thr->edx = 0;
  54.     thr->ecx = 0;
  55.  
  56.     thr->cs  = sel_srv_code;
  57.     thr->eflags = EFL_IOPL1;
  58.     thr->esp = thr_stack + 8192;
  59.     thr->ss = sel_srv_stack;
  60.  
  61.     thr->thr_flags    = 0;
  62.  
  63.     thr->ticks_left   = 8;
  64.     thr->quantum_size = 8;
  65.  
  66.     thr->eip = entry_ptr;
  67.  
  68.     //lock_enqueue(thr_ptr);       /* add to scheduling queues */
  69.  
  70.     return thr;
  71. };
  72.  
  73.