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
8e231276
authored
Dec 30, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
degbug and i dunno maybe i fixed something cr3 is wrong i know that plz help
parent
7907bdb5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
16 deletions
src/PCB.c
src/PCB.h
src/elf.c
src/elf.h
src/kern.c
src/mem.c
src/switch.asm
src/PCB.c
View file @
8e231276
#include "PCB.h"
#include "PCB.h"
#include "serial.h"
#include "serial.h"
#include "term.h"
#include "term.h"
#include "idt.h"
#define NUM_SYSCALLS 256
#define NUM_SYSCALLS 256
#define NUM_PROCS 16
#define NUM_PROCS 16
...
@@ -26,13 +27,19 @@ void settf(trapframe* tf)
...
@@ -26,13 +27,19 @@ void settf(trapframe* tf)
void
schedule
()
void
schedule
()
{
{
int
old
=
curproc
;
int
old
=
curproc
;
curproc
++
;
curproc
=
0
;
//
++;
while
(
procs
[
curproc
]
==
0
||
procs
[
curproc
]
->
state
!=
RUNNABLE
)
/*
while(procs[curproc]==0 || procs[curproc]->state!=RUNNABLE)
{
{
curproc=(curproc<NUM_PROCS-1)?curproc+1:0;
curproc=(curproc<NUM_PROCS-1)?curproc+1:0;
}
}*/
serial_writestring
(
"about to switch
\n
"
);
serial_writestring
(
"about to switch
\n
to ctxt at: "
);
//context_switch(&procs[old]->ctxt, procs[curproc]->ctxt);
serial_hexword
((
uintptr_t
)
procs
[
curproc
]
->
ctxt
);
serial_writestring
(
"
\n
eip: "
);
serial_hexword
(
procs
[
curproc
]
->
ctxt
->
eip
);
serial_writestring
(
"
\n
cr3: "
);
serial_hexword
(
procs
[
curproc
]
->
ctxt
->
cr3
);
serial_writestring
(
"
\n
"
);
context_switch
(
&
procs
[
old
]
->
ctxt
,
procs
[
curproc
]
->
ctxt
);
serial_writestring
(
"switched
\n
"
);
serial_writestring
(
"switched
\n
"
);
//procs[old]->state=RUNNABLE;
//procs[old]->state=RUNNABLE;
procs
[
curproc
]
->
state
=
RUNNING
;
procs
[
curproc
]
->
state
=
RUNNING
;
...
...
src/PCB.h
View file @
8e231276
...
@@ -28,8 +28,8 @@ typedef struct//all regs in proc
...
@@ -28,8 +28,8 @@ typedef struct//all regs in proc
uint32_t
trap
;
uint32_t
trap
;
uint32_t
mmm
;
//
uint32_t mmm;
uint32_t
why
;
//
uint32_t why;
uint32_t
err
;
uint32_t
err
;
...
...
src/elf.c
View file @
8e231276
...
@@ -5,10 +5,14 @@
...
@@ -5,10 +5,14 @@
*/
*/
#include "elf.h"
#include "elf.h"
#include "idt.h"
void
load_elf
(
elf_header
*
elf_start
)
void
load_elf
(
elf_header
*
elf_start
)
{
{
// The elf will get its own memory space.
// The elf will get its own memory space.
serial_writestring
(
"_elf_start entry: "
);
serial_hexword
((
uintptr_t
)
elf_start
->
program_entry_position
);
serial_writestring
(
"
\n
"
);
page_directory_entry
*
pgdir
=
page_new_directory
();
page_directory_entry
*
pgdir
=
page_new_directory
();
void
*
highest_vpage
=
(
void
*
)
0
;
void
*
highest_vpage
=
(
void
*
)
0
;
...
@@ -65,13 +69,16 @@ void load_elf(elf_header* elf_start)
...
@@ -65,13 +69,16 @@ void load_elf(elf_header* elf_start)
page_map
(
pgdir
,
highest_vpage
+
0x2000
);
page_map
(
pgdir
,
highest_vpage
+
0x2000
);
// initial esp = highest_vpage + 0x1000
// initial esp = highest_vpage + 0x1000
process
*
pcb
=
kmalloc
(
sizeof
(
process
)
+
sizeof
(
context
)
+
sizeof
(
trapframe
));
process
*
pcb
=
kmalloc
(
sizeof
(
process
)
);
//
+ sizeof(context) + sizeof(trapframe));
pcb
->
ctxt
=
(
context
*
)((
size_t
)
pcb
+
sizeof
(
process
));
//
pcb->ctxt = (context*)((size_t)pcb + sizeof(process));
pcb
->
tf
=
(
trapframe
*
)((
size_t
)
pcb
+
sizeof
(
process
)
+
sizeof
(
context
));
//
pcb->tf = (trapframe*)((size_t)pcb + sizeof(process) + sizeof(context));
// And of course, a kstack
// And of course, a kstack
pcb
->
kstack
=
(
char
*
)
kmalloc
(
0x1000
);
pcb
->
kstack
=
(
char
*
)
kmalloc
(
0x1000
);
pcb
->
tf
=
(
trapframe
*
)(
pcb
->
kstack
);
// + sizeof(trapframe));
pcb
->
ctxt
=
(
context
*
)(
pcb
->
tf
+
sizeof
(
trapframe
));
//sizeof(context));
pcb
->
mem
=
pgdir
;
pcb
->
mem
=
pgdir
;
pcb
->
pid
=
-
1
;
pcb
->
pid
=
-
1
;
pcb
->
parent
=
0
;
pcb
->
parent
=
0
;
...
@@ -79,13 +86,15 @@ void load_elf(elf_header* elf_start)
...
@@ -79,13 +86,15 @@ void load_elf(elf_header* elf_start)
//pcb->name = "debugstuff";
//pcb->name = "debugstuff";
pcb
->
state
=
RUNNABLE
;
pcb
->
state
=
RUNNABLE
;
pcb
->
ctxt
->
cr3
=
pgdir
;
pcb
->
ctxt
->
cr3
=
(
uintptr_t
)
pgdir
;
pcb
->
ctxt
->
edi
=
0
;
pcb
->
ctxt
->
edi
=
0
;
pcb
->
ctxt
->
esi
=
0
;
pcb
->
ctxt
->
esi
=
0
;
pcb
->
ctxt
->
ebx
=
0
;
pcb
->
ctxt
->
ebx
=
0
;
pcb
->
ctxt
->
ebp
=
(
uint32_t
)
highest_vpage
+
0x1000
;
pcb
->
ctxt
->
ebp
=
(
uint
ptr_t
)
pcb
->
tf
;
//(uint
32_t)highest_vpage + 0x1000;
pcb
->
ctxt
->
eip
=
(
uint32_t
)
elf_start
->
program_entry_position
;
pcb
->
ctxt
->
eip
=
(
uint
ptr_t
)
default_handler
;
//(uint
32_t)elf_start->program_entry_position;
pcb
->
tf
->
eax
=
4
;
pcb
->
tf
->
trap
=
0x80
;
pcb
->
tf
->
ebp
=
(
uint32_t
)
highest_vpage
+
0x1000
;
pcb
->
tf
->
ebp
=
(
uint32_t
)
highest_vpage
+
0x1000
;
pcb
->
tf
->
eip
=
(
uint32_t
)
elf_start
->
program_entry_position
;
pcb
->
tf
->
eip
=
(
uint32_t
)
elf_start
->
program_entry_position
;
...
...
src/elf.h
View file @
8e231276
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
*/
*/
#ifndef _ELF_INC
#ifndef _ELF_INC
#define _ELF_IN
T
#define _ELF_IN
C
#include <stdint.h>
#include <stdint.h>
#include <stddef.h>
#include <stddef.h>
...
...
src/kern.c
View file @
8e231276
...
@@ -86,7 +86,9 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
...
@@ -86,7 +86,9 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
pit_init
();
pit_init
();
pit_start_counter
(
100
,
PIT_OCW_CONT_0
,
PIT_OCW_MODE_SQWVGEN
);
pit_start_counter
(
100
,
PIT_OCW_CONT_0
,
PIT_OCW_MODE_SQWVGEN
);
serial_writestring
(
"enabling interrupts
\n
"
);
serial_writestring
(
"_kernel_end: "
);
serial_hexword
((
uintptr_t
)
&
_kernel_end
);
serial_writestring
(
"
\n
enabling interrupts
\n
"
);
enable_int
();
enable_int
();
...
...
src/mem.c
View file @
8e231276
...
@@ -53,6 +53,10 @@ void* page_allocate()
...
@@ -53,6 +53,10 @@ void* page_allocate()
*
index
=
*
index
|
(
1
<<
i
);
*
index
=
*
index
|
(
1
<<
i
);
uint32_t
page_number
=
((
uint32_t
)(
index
-
(
uint8_t
*
)
_kernel_end
)
*
8
)
+
(
8
-
i
);
uint32_t
page_number
=
((
uint32_t
)(
index
-
(
uint8_t
*
)
_kernel_end
)
*
8
)
+
(
8
-
i
);
//serial_hexword(page_number);
//serial_writestring(" page allocated at address ");
//serial_hexword((uintptr_t)(void*)&_kernel_end + 0x1000 * page_number);
//serial_writestring("\n");
return
(
void
*
)
&
_kernel_end
+
0x1000
*
page_number
;
return
(
void
*
)
&
_kernel_end
+
0x1000
*
page_number
;
}
}
...
...
src/switch.asm
View file @
8e231276
...
@@ -10,6 +10,10 @@ context_switch:
...
@@ -10,6 +10,10 @@ context_switch:
mov
ecx
,
cr3
mov
ecx
,
cr3
push
ecx
push
ecx
; CR3 PROBLEM - STACK CHANGES, CANT ACCESS NEW MEM?
; WHY IS PROCS[CURPROC]->CTXT IN PROCESS MEM, NOT
; IN KERNEL MEM? INTERROGATE FREMMA
mov
[eax],
esp
mov
[eax],
esp
mov
esp
,
edx
mov
esp
,
edx
...
...
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