Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
af2a722f
authored
Dec 06, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
updated stuff to use an array for now
parent
ffa16ab2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
13 deletions
src/PCB.c
src/PCB.h
src/kern.c
src/PCB.c
View file @
af2a722f
...
@@ -2,27 +2,43 @@
...
@@ -2,27 +2,43 @@
#include "serial.h"
#include "serial.h"
#include "term.h"
#include "term.h"
#define NUM_SYSCALLS 256
#define NUM_SYSCALLS 256
#define NUM_PROCS 16
process
*
curproc
;
process
*
procs
[
NUM_PROCS
];
process
*
otherproc
;
int
curproc
=-
1
;
int
firstfree
=
0
;
void
setproc
(
process
*
proc
)
//process* curproc;
//process* otherproc;
void
addproc
(
process
*
proc
)
{
{
curproc
=
proc
;
procs
[
firstfree
]
=
proc
;
firstfree
++
;
//curproc=proc;
}
}
void
schedule
()
void
schedule
()
{
{
context_switch
(
&
curproc
->
ctxt
,
otherproc
->
ctxt
);
int
old
=
curproc
;
process
*
t
=
curproc
;
curproc
++
;
curproc
=
otherproc
;
while
(
procs
[
curproc
]
==
0
||
procs
[
curproc
]
->
state
!=
RUNNABLE
)
otherproc
=
t
;
{
curproc
=
(
curproc
<
NUM_PROCS
-
1
)
?
curproc
+
1
:
0
;
}
context_switch
(
&
procs
[
old
]
->
ctxt
,
procs
[
curproc
]
->
ctxt
);
//procs[old]->state=RUNNABLE;
procs
[
curproc
]
->
state
=
RUNNING
;
//process* t = curproc;
//curproc = otherproc;
//otherproc = t;
}
}
int
yield
()
int
yield
()
{
{
//lock mutex
//lock mutex
curproc
->
state
=
RUNNABLE
;
procs
[
curproc
]
->
state
=
RUNNABLE
;
schedule
();
schedule
();
//unlock mutex
//unlock mutex
return
1
;
return
1
;
...
@@ -45,15 +61,23 @@ int(*syscalls[NUM_SYSCALLS])()={0,0,0, yield, print1, print2};
...
@@ -45,15 +61,23 @@ int(*syscalls[NUM_SYSCALLS])()={0,0,0, yield, print1, print2};
void
syscall
()
void
syscall
()
{
{
int
num
=
curproc
->
tf
->
eax
;
int
num
=
procs
[
curproc
]
->
tf
->
eax
;
if
(
num
>
0
&&
num
<
NUM_SYSCALLS
&&
syscalls
[
num
])
if
(
num
>
0
&&
num
<
NUM_SYSCALLS
&&
syscalls
[
num
])
{
{
curproc
->
tf
->
eax
=
syscalls
[
num
]();
procs
[
curproc
]
->
tf
->
eax
=
syscalls
[
num
]();
}
}
else
else
{
{
serial_writestring
(
"UNKNOWN SYSCALL CALLED
\n
"
);
serial_writestring
(
"UNKNOWN SYSCALL CALLED
\n
"
);
curproc
->
tf
->
eax
=
-
1
;
procs
[
curproc
]
->
tf
->
eax
=
-
1
;
}
}
void
proc_setup
()
{
for
(
int
i
=
0
;
i
<
NUM_PROCS
;
i
++
)
{
procs
[
i
]
=
NULL
;
}
}
}
}
src/PCB.h
View file @
af2a722f
...
@@ -65,6 +65,7 @@ typedef struct
...
@@ -65,6 +65,7 @@ typedef struct
extern
void
context_switch
(
context
**
old
,
context
*
new
);
extern
void
context_switch
(
context
**
old
,
context
*
new
);
void
syscall
();
void
syscall
();
void
setproc
(
process
*
proc
);
void
addproc
(
process
*
proc
);
void
proc_setup
();
#endif
#endif
src/kern.c
View file @
af2a722f
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "pit.h"
#include "pit.h"
#include "io.h"
#include "io.h"
#include "elf.h"
#include "elf.h"
#include "PCB.h"
// The parameters passed here ultimately come through the bootloader
// The parameters passed here ultimately come through the bootloader
void
kernel_main
(
multiboot_info
*
mbt
,
uint32_t
magic
)
void
kernel_main
(
multiboot_info
*
mbt
,
uint32_t
magic
)
...
@@ -39,6 +40,7 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
...
@@ -39,6 +40,7 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
pic_init
(
0x20
,
0x28
);
pic_init
(
0x20
,
0x28
);
pit_init
();
pit_init
();
io_init
();
io_init
();
proc_setup
();
pit_start_counter
(
100
,
PIT_OCW_CONT_0
,
PIT_OCW_MODE_SQWVGEN
);
pit_start_counter
(
100
,
PIT_OCW_CONT_0
,
PIT_OCW_MODE_SQWVGEN
);
enable_int
();
enable_int
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment