Scheduler is now selectable in make menuconfig in kernel hacking.
[projects/modsched/linux.git] / kernel / sched / modsched / framework / os / linux / 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         printk("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         return 0;
32 }
33
34 void os_free(void* ptr)
35 {
36 //      heap_free(&os_heap, ptr);
37 }
38
39 void os_create_task(fw_task_t *task)
40 {
41         (void) task;
42 }
43
44 void os_dispatch(fw_task_t *task)
45 {
46 //      cpu_stack_t *dummy;
47 //
48 //
49 //
50 //      fw_task_t *old_task;
51 //      old_task = current_task;
52 //
53 //
54 //      os_set_current_task(task);
55 //
56 //      os_printf("switching from '%s' (%p) to '%s' (%p)\n", os_task_info(old_task), old_task, os_task_info(current_task), current_task);
57 //      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);
58 //
59 //      /*
60 //       * If there is no old process, we save the old stack pointer into a
61 //       * dummy variable that we ignore.  In fact, this happens only when the
62 //       * old process has just exited.
63 //       */
64 //      asm_switch_context(&((Process*)(current_task->real_task))->stack, old_task ? &((Process*)(old_task->real_task))->stack : &dummy);
65 }
66
67 void os_dispatch_mp(fw_task_t *task, int cpu)
68 {
69 //      (void) cpu;
70 //      os_dispatch(task);
71 }
72
73 fw_task_t *os_current_task(int cpu){
74         (void) cpu;
75
76 //      return proc_current()->fw_task;
77         return 0;
78 }
79
80 int os_init_os(){
81         printk("Initializing for BeRTOS...");
82
83 //      heap_init(&os_heap, os_heap_buf, sizeof(os_heap_buf));
84
85         printk("done!\n");
86         return 0;
87 }
88
89 inline void os_spinlock(fw_spinlock_t *lock)
90 {
91 //      cpu_flags_t __flags;
92 //      IRQ_SAVE_DISABLE(__flags);
93 //      while(*lock){
94 //              IRQ_RESTORE(__flags);
95 //              CPU_IDLE;
96 //              MEMORY_BARRIER;
97 //              IRQ_SAVE_DISABLE(__flags);
98 //      }
99 //      *lock = 1;
100 //      IRQ_RESTORE(__flags);
101 }
102
103 inline void os_spinunlock(fw_spinlock_t *lock)
104 {
105 //      cpu_flags_t __flags;
106 //      IRQ_SAVE_DISABLE(__flags);
107 //      *lock = 0;
108 //      IRQ_RESTORE(__flags);
109 }
110
111 int os_task_name(fw_task_t *task, char *buf, fw_size_t size)
112 {
113         return strlcpy(buf, os_task_info(task), size);
114 }
115
116 const char *os_task_info(fw_task_t *task){
117 //      return task ? (task->real_task ? proc_name(task->real_task) : "Invalid Task") : "<NULL>";
118         return 0;
119 }