/
schedos-1.c
60 lines (48 loc) · 1.3 KB
/
schedos-1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "schedos-app.h"
#include "x86sync.h"
/*****************************************************************************
* schedos-1
*
* This tiny application prints red "1"s to the console.
* It yields the CPU to the kernel after each "1" using the sys_yield()
* system call. This lets the kernel (schedos-kern.c) pick another
* application to run, if it wants.
*
* The other schedos-* processes simply #include this file after defining
* PRINTCHAR appropriately.
*
*****************************************************************************/
#ifndef PRINTCHAR
#define PRINTCHAR ('1' | 0x0C00)
#endif
// UNCOMMENT THE NEXT LINE TO USE EXERCISE 8 CODE INSTEAD OF EXERCISE 6
//#define __EXERCISE_8__
// Use the following structure to choose between them:
#ifndef __EXERCISE_8__
#define __EXERCISE_6__
#endif
void
start(void)
{
int i;
for (i = 0; i < RUNCOUNT; i++) {
// Write characters to the console, yielding after each one.
//*cursorpos++ = PRINTCHAR;
// Atomic syscall version
#ifdef __EXERCISE_6__
sys_print(PRINTCHAR);
#endif
// Atomic lock version
#ifdef __EXERCISE_8__
while (atomic_swap(&lock, 1) != 0)
continue;
*cursorpos++ = PRINTCHAR;
atomic_swap(&lock, 0);
#endif
sys_yield();
}
/*// Yield forever.
while (1)
sys_yield();*/
sys_exit(0);
}