task.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* kernel/task.c
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <kernel/init.h>
  19. #include <kernel/kernel.h>
  20. #include <kernel/module.h>
  21. #include <kernel/mm.h>
  22. #include <kernel/task.h>
  23. #include <kernel/kmlog.h>
  24. #include <arch/archinfo.h>
  25. #include <sys/types.h>
  26. struct task init_task = {
  27. .state = TASK_RUNNING,
  28. .pid = 0,
  29. .parent = NULL,
  30. .arch_descr = ARCH_TASK_DESCR_INIT,
  31. .nice = 0
  32. };
  33. struct task *current = &init_task;
  34. int next_pid = 1;
  35. int task_init(void) {
  36. struct task *new = dup_task();
  37. kmlog("New task: %p\n", new);
  38. kmlog("task initialization finished. \n");
  39. switch_to(new);
  40. return 0;
  41. }
  42. struct task *dup_task(void) {
  43. struct task *tsk;
  44. if (unlikely(!(tsk = kmalloc(sizeof(struct task)))))
  45. panic("dup_task: Out of memory");
  46. tsk->state = TASK_WAIT;
  47. tsk->pid = next_pid++;
  48. tsk->parent = current;
  49. tsk->nice = 0;
  50. arch_task_descr_init(&tsk->arch_descr);
  51. arch_stack_init(&tsk->arch_descr);
  52. tsk->state = TASK_READY;
  53. return tsk;
  54. }
  55. kernel_init(task_init);