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
ffa16ab2
authored
Dec 06, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
horrible hacks and other stuff
parent
b77e65dd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
1 deletions
src/PCB.c
src/PCB.h
src/idt.c
src/switch.asm
src/PCB.c
View file @
ffa16ab2
#include "PCB.h"
#include "PCB.h"
#include "serial.h"
#include "term.h"
#define NUM_SYSCALLS 256
process
*
curproc
;
process
*
otherproc
;
void
setproc
(
process
*
proc
)
{
curproc
=
proc
;
}
void
schedule
()
{
context_switch
(
&
curproc
->
ctxt
,
otherproc
->
ctxt
);
process
*
t
=
curproc
;
curproc
=
otherproc
;
otherproc
=
t
;
}
int
yield
()
{
//lock mutex
curproc
->
state
=
RUNNABLE
;
schedule
();
//unlock mutex
return
1
;
}
int
print1
()
{
terminal_writestring
(
"1"
);
return
1
;
}
int
print2
()
{
terminal_writestring
(
"2"
);
return
2
;
}
int
(
*
syscalls
[
NUM_SYSCALLS
])()
=
{
0
,
0
,
0
,
yield
,
print1
,
print2
};
/*NOPE, exit, fork, yield, test, test*/
void
syscall
()
{
int
num
=
curproc
->
tf
->
eax
;
if
(
num
>
0
&&
num
<
NUM_SYSCALLS
&&
syscalls
[
num
])
{
curproc
->
tf
->
eax
=
syscalls
[
num
]();
}
else
{
serial_writestring
(
"UNKNOWN SYSCALL CALLED
\n
"
);
curproc
->
tf
->
eax
=
-
1
;
}
}
src/PCB.h
View file @
ffa16ab2
...
@@ -49,16 +49,22 @@ typedef struct//regs needed for context
...
@@ -49,16 +49,22 @@ typedef struct//regs needed for context
uint32_t
eip
;
uint32_t
eip
;
}
__attribute__
((
packed
))
context
;
}
__attribute__
((
packed
))
context
;
enum
procstate
{
KILLED
,
RUNNABLE
,
RUNNING
};
typedef
struct
typedef
struct
{
{
page_directory_entry
*
mem
;
page_directory_entry
*
mem
;
volatile
int
pid
;
volatile
int
pid
;
struct
process
*
parent
;
struct
process
*
parent
;
char
*
kstack
;
//apparently we need this. idk why
trapframe
*
tf
;
trapframe
*
tf
;
context
*
ctxt
;
context
*
ctxt
;
char
name
[
32
];
char
name
[
32
];
enum
procstate
state
;
}
__attribute__
((
packed
))
process
;
}
__attribute__
((
packed
))
process
;
extern
void
context_switch
(
context
**
old
,
context
*
new
);
extern
void
context_switch
(
context
**
old
,
context
*
new
);
void
syscall
();
void
setproc
(
process
*
proc
);
#endif
#endif
src/idt.c
View file @
ffa16ab2
...
@@ -105,6 +105,7 @@ int idt_init(uint16_t code_sel)
...
@@ -105,6 +105,7 @@ int idt_init(uint16_t code_sel)
idtsetup
();
idtsetup
();
idt_install
();
idt_install
();
load_error_handlers
();
load_error_handlers
();
handlers
[
0x100
]
=
syscall
;
return
0
;
return
0
;
}
}
#pragma GCC pop_options
#pragma GCC pop_options
src/switch.asm
View file @
ffa16ab2
global
context_switch
global
context_switch
switch
:
context_
switch
:
mov
eax
,
[
esp
+
4
]
mov
eax
,
[
esp
+
4
]
mov
edx
,
[
esp
+
8
]
mov
edx
,
[
esp
+
8
]
...
...
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