1/*
2 ****************************************************************************
3 * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
4 ****************************************************************************
5 *
6 *        File: sched.c
7 *      Author: Grzegorz Milos
8 *     Changes: Robert Kaiser
9 *
10 *        Date: Aug 2005
11 *
12 * Environment: Xen Minimal OS
13 * Description: simple scheduler for Mini-Os
14 *
15 * The scheduler is non-preemptive (cooperative), and schedules according
16 * to Round Robin algorithm.
17 *
18 ****************************************************************************
19 * Permission is hereby granted, free of charge, to any person obtaining a copy
20 * of this software and associated documentation files (the "Software"), to
21 * deal in the Software without restriction, including without limitation the
22 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
23 * sell copies of the Software, and to permit persons to whom the Software is
24 * furnished to do so, subject to the following conditions:
25 *
26 * The above copyright notice and this permission notice shall be included in
27 * all copies or substantial portions of the Software.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 * DEALINGS IN THE SOFTWARE.
36 */
37
38#include <mini-os/os.h>
39#include <mini-os/hypervisor.h>
40#include <mini-os/time.h>
41#include <mini-os/mm.h>
42#include <mini-os/types.h>
43#include <mini-os/lib.h>
44#include <mini-os/semaphore.h>
45
46#include <bmk-core/memalloc.h>
47#include <bmk-core/sched.h>
48
49#if 0
50void dump_stack(struct thread *thread_md)
51{
52    unsigned long *bottom = (unsigned long *)(thread->stack + STACK_SIZE);
53    unsigned long *pointer = (unsigned long *)thread->thr_sp;
54    int count;
55    if(thread == bmk_current)
56    {
57#ifdef __i386__
58        asm("movl %%esp,%0"
59            : "=r"(pointer));
60#else
61        asm("movq %%rsp,%0"
62            : "=r"(pointer));
63#endif
64    }
65    minios_printk("The stack for \"%s\"\n", thread->name);
66    for(count = 0; count < 25 && pointer < bottom; count ++)
67    {
68        minios_printk("[0x%lx] 0x%lx\n", pointer, *pointer);
69        pointer++;
70    }
71
72    if(pointer < bottom) minios_printk(" ... continues.\n");
73}
74#endif
75
76void
77bmk_platform_cpu_sched_settls(struct bmk_tcb *next)
78{
79
80#if defined(__i386__)
81    tlsswitch32(next->btcb_tp);
82#else /* x86_64 */
83    wrmsrl(0xc0000100, next->btcb_tp);
84#endif
85}
86