Scheduler is now selectable in make menuconfig in kernel hacking.
[projects/modsched/linux.git] / kernel / sched / modsched / framework / os / freebsd / os.c
1 /*
2  * os.c
3  *
4  *  Created on: 04.12.2013
5  *      Author: jkrieg
6  */
7
8 #include "os.h"
9
10
11 /**
12  * CPU dependent context switching routines.
13  *
14  * Saving and restoring the context on the stack is done by a CPU-dependent
15  * support routine which usually needs to be written in assembly.
16  */
17 //EXTERN_C void asm_switch_context(cpu_stack_t **new_sp, cpu_stack_t **save_sp);
18
19 //HEAP_DEFINE_BUF(os_heap_buf, 1024);
20 //Heap os_heap;
21
22 fw_task_t *current_task = NULL;
23
24 void os_set_current_task(fw_task_t *task){
25         current_task = task;
26         printf("current_task set to %p\n", task);
27 }
28
29 void *os_malloc(fw_size_t size){
30 //      return heap_malloc(&os_heap, (size_t) size);
31 }
32
33 void os_free(void* ptr)
34 {
35 //      heap_free(&os_heap, ptr);
36 }
37
38 void os_create_task(fw_task_t *task)
39 {
40         (void) task;
41 }
42
43 void os_dispatch(fw_task_t *task)
44 {
45 //      cpu_stack_t *dummy;
46 //
47 //
48 //
49 //      fw_task_t *old_task;
50 //      old_task = current_task;
51 //
52 //
53 //      os_set_current_task(task);
54 //
55 //      os_printf("switching from '%s' (%p) to '%s' (%p)\n", os_task_info(old_task), old_task, os_task_info(current_task), current_task);
56 //      os_printf("switching stack from %x (%p) &(%p) to %x (%p) &(%p)\n", *((Process*)(old_task->real_task))->stack, ((Process*)(old_task->real_task))->stack, &((Process*)(old_task->real_task))->stack, *((Process*)(current_task->real_task))->stack, ((Process*)(current_task->real_task))->stack, &((Process*)(current_task->real_task))->stack);
57 //
58 //      /*
59 //       * If there is no old process, we save the old stack pointer into a
60 //       * dummy variable that we ignore.  In fact, this happens only when the
61 //       * old process has just exited.
62 //       */
63 //      asm_switch_context(&((Process*)(current_task->real_task))->stack, old_task ? &((Process*)(old_task->real_task))->stack : &dummy);
64 }
65
66 void os_dispatch_mp(fw_task_t *task, int cpu)
67 {
68 //      (void) cpu;
69 //      os_dispatch(task);
70 }
71
72 fw_task_t *os_current_task(int cpu){
73         (void) cpu;
74
75 //      return proc_current()->fw_task;
76         return 0;
77 }
78
79 int os_init_os(){
80         printf("Initializing for BeRTOS...");
81
82 //      heap_init(&os_heap, os_heap_buf, sizeof(os_heap_buf));
83
84         printf("done!\n");
85         return 0;
86 }
87
88 inline void os_spinlock(fw_spinlock_t *lock)
89 {
90 //      cpu_flags_t __flags; \
91 //      IRQ_SAVE_DISABLE(__flags); \
92 //      while(*lock){
93 //              IRQ_RESTORE(__flags);
94 //              CPU_IDLE;
95 //              MEMORY_BARRIER;
96 //              IRQ_SAVE_DISABLE(__flags);
97 //      }
98 //      *lock = 1;
99 //      IRQ_RESTORE(__flags);
100 }
101
102 inline void os_spinunlock(fw_spinlock_t *lock)
103 {
104 //      cpu_flags_t __flags; \
105 //      IRQ_SAVE_DISABLE(__flags); \
106 //      *lock = 0;
107 //      IRQ_RESTORE(__flags);
108 }
109
110 int os_task_name(fw_task_t *task, char *buf, fw_size_t size)
111 {
112         return strlcpy(buf, os_task_info(task), size);
113 }
114
115 const char *os_task_info(fw_task_t *task){
116 //      return task ? (task->real_task ? proc_name(task->real_task) : "Invalid Task") : "<NULL>";
117         return 0;
118 }