Subversion Repositories shark

Rev

Rev 961 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
961 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
23
 CVS :        $Id: dummy.c,v 1.1 2005-02-25 10:55:09 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1 $
27
 Last update: $Date: 2005-02-25 10:55:09 $
28
 ------------
29
 
30
 This file contains the Dummy scheduling module
31
 
32
 Read dummy.h for further details.
33
 
34
**/
35
 
36
/*
37
 * Copyright (C) 2000 Paolo Gai
38
 *
39
 * This program is free software; you can redistribute it and/or modify
40
 * it under the terms of the GNU General Public License as published by
41
 * the Free Software Foundation; either version 2 of the License, or
42
 * (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
52
 *
53
 */
54
 
55
#include <dummy/dummy/dummy.h>
56
#include <ll/ll.h>
1689 fabio 57
#include <arch/stdio.h>
58
#include <arch/string.h>
961 pj 59
#include <kernel/config.h>
60
#include <sys/types.h>
61
#include <kernel/model.h>
62
#include <kernel/descr.h>
63
#include <kernel/var.h>
64
#include <kernel/func.h>
65
 
66
 
67
 
68
/*+ the level redefinition for the Dummy level +*/
69
typedef struct {
70
  level_des l;     /*+ the standard level descriptor          +*/
71
 
72
  PID dummy;       /*+ the dummy task...                      +*/
73
} dummy_level_des;
74
 
75
 
76
static PID dummy_public_scheduler(LEVEL l)
77
{
78
  dummy_level_des *lev = (dummy_level_des *)(level_table[l]);
79
  //kern_printf("DUMMYsched!!! %d", lev->dummy);
80
  return lev->dummy;
81
}
82
 
83
static int dummy_public_create(LEVEL l, PID p, TASK_MODEL *m)
84
{
85
  dummy_level_des *lev = (dummy_level_des *)(level_table[l]);
86
 
87
  if (m->pclass != DUMMY_PCLASS) return -1;
88
  if (m->level != 0 && m->level != l) return -1;
89
  if (lev->dummy != -1) return -1;
90
 
91
  /* the dummy level doesn't introduce any new field in the TASK_MODEL
92
     so, all initialization stuffs are done by the task_create.
93
     the task state is set at SLEEP by the general task_create */
94
  return 0; /* OK */
95
}
96
 
97
static void dummy_public_dispatch(LEVEL l, PID p, int nostop)
98
{
99
  /* nothing... the dummy hangs the cpu waiting for interrupts... */
100
}
101
 
102
static void dummy_public_epilogue(LEVEL l, PID p)
103
{
104
  proc_table[p].status = SLEEP; /* Paranoia */
105
}
106
 
107
/*+ Dummy task must be present & cannot be killed; +*/
108
static TASK dummy()
109
{
110
    /*
111
    It is possible to Halt the CPU & avoid consumption if idle
112
    cycle are intercepted with hlt instructions!
113
    It seems that some CPU have buggy hlt instruction or they
114
    have not it at all! So, if available, use the hlt facility!!
115
    */
116
    #ifdef __HLT_WORKS__
117
    for(;;) {
118
//       kern_printf("?");
119
        hlt();
120
    }
121
    #else
122
    for(;;);// kern_printf("?");
123
    #endif
124
}
125
 
126
/* Registration functions */
127
 
128
/*+ This init function install the dummy task +*/
129
static void dummy_create(void *l)
130
{
131
  LEVEL lev;
132
  PID p;
133
  DUMMY_TASK_MODEL m;
134
 
135
  lev = (LEVEL)l;
136
 
137
  dummy_task_default_model(m);
138
  dummy_task_def_level(m,lev);
139
  dummy_task_def_system(m);
140
  dummy_task_def_nokill(m);
141
  dummy_task_def_ctrl_jet(m);
142
 
143
  ((dummy_level_des *)level_table[lev])->dummy = p =
144
    task_create("Dummy", dummy, &m, NULL);
145
 
146
  if (p == NIL)
147
    printk("\nPanic!!! can't create dummy task...\n");
148
 
149
  /* dummy must block all signals... */
150
  proc_table[p].sigmask = 0xFFFFFFFF;
151
}
152
 
153
 
154
/*+ Registration function:
155
    TIME slice                the slice for the Round Robin queue
156
    int createmain            1 if the level creates the main task 0 otherwise
157
    struct multiboot_info *mb used if createmain specified   +*/
158
LEVEL dummy_register_level()
159
{
160
  LEVEL l;            /* the level that we register */
161
  dummy_level_des *lev;  /* for readableness only */
162
 
163
  printk("dummy_register_level\n");
164
 
165
  /* request an entry in the level_table */
166
  l = level_alloc_descriptor(sizeof(dummy_level_des));
167
 
168
  lev = (dummy_level_des *)level_table[l];
169
 
170
  /* fill the standard descriptor */
171
  lev->l.public_scheduler = dummy_public_scheduler;
172
  lev->l.public_guarantee = NULL;
173
  lev->l.public_create    = dummy_public_create;
174
  lev->l.public_dispatch  = dummy_public_dispatch;
175
  lev->l.public_epilogue  = dummy_public_epilogue;
176
 
177
  /* the dummy process will be created at init_time.
178
     see also dummy_level_accept_model,dummy_create   */
179
  lev->dummy = -1;
180
 
181
  sys_atrunlevel(dummy_create,(void *) l, RUNLEVEL_INIT);
182
 
183
  return l;
184
}