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
991bcbe0
authored
Dec 07, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Some bugfixes, add debug output
parent
8e6d9b19
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
8 deletions
src/elf.c
src/elf.h
src/kern.c
src/mem.c
src/elf.c
View file @
991bcbe0
...
...
@@ -11,16 +11,31 @@ void load_elf(elf_header* elf_start)
// The elf will get its own memory space.
page_directory_entry
*
pgdir
=
page_new_directory
();
void
*
highest_vpage
=
(
void
*
)
0
;
serial_writestring
(
"Loading elf
\n
"
);
// loop through and copy memory segments
for
(
int
i
=
0
;
i
<
elf_start
->
ph_entry_count
;
i
++
)
{
serial_writestring
(
"Loading memory segment
\n
"
);
// get this section header
elf_program_header
*
ph
;
ph
=
(
elf_program_header
*
)
elf_start
+
(
elf_start
->
ph_table_offset
+
(
i
*
elf_start
->
ph_entry_size
));
ph
=
(
elf_program_header
*
)
((
uint32_t
)
elf_start
+
(
uint32_t
)(
elf_start
->
ph_table_offset
+
(
i
*
elf_start
->
ph_entry_size
)));
serial_hexword
((
uint32_t
)
elf_start
);
serial_writechar
(
'\n'
);
serial_hexword
((
uint32_t
)
ph
);
serial_writechar
(
'\n'
);
serial_hexword
((
uint32_t
)
elf_start
+
(
uint32_t
)(
elf_start
->
ph_table_offset
+
(
i
*
elf_start
->
ph_entry_size
)));
serial_writechar
(
'\n'
);
// map and copy
for
(
void
*
pg
=
(
void
*
)((
uint32_t
)
ph
->
p_vaddr
&
0xfffff000
);
(
uint32_t
)(
pg
-
ph
->
p_vaddr
)
<
ph
->
memory_segment_size
;
pg
+=
0x1000
)
for
(
void
*
pg
=
(
void
*
)((
uint32_t
)
ph
->
p_vaddr
&
0xfffff000
);
(
(
int
)
pg
-
(
int
)
ph
->
p_vaddr
)
<
(
int
)
ph
->
memory_segment_size
;
pg
+=
0x1000
)
{
serial_writestring
(
"Copying in memory segment
\n
"
);
void
*
real_page
=
page_map
(
pgdir
,
pg
);
void
*
start
=
(
pg
>
ph
->
p_vaddr
)
?
pg
:
ph
->
p_vaddr
;
...
...
@@ -30,7 +45,21 @@ void load_elf(elf_header* elf_start)
size_t
offset
=
(
pg
>
ph
->
p_vaddr
)
?
0
:
ph
->
p_vaddr
-
pg
;
// do some memcpy stuff
serial_hexword
((
uint32_t
)
real_page
);
serial_writechar
(
'\n'
);
memcpy
(
real_page
+
offset
,
start
,
size
);
// save the highest start
if
(
pg
>
highest_vpage
)
{
highest_vpage
=
pg
;
}
break
;
}
}
// Allocate two more pages for stack
page_map
(
pgdir
,
highest_vpage
+
0x1000
);
page_map
(
pgdir
,
highest_vpage
+
0x2000
);
// initial esp = highest_vpage + 0x1000
}
src/elf.h
View file @
991bcbe0
...
...
@@ -12,6 +12,7 @@
#include "mem.h"
#include "string.h"
#include "serial.h"
extern
uint8_t
elf_hello
[]
asm
(
"_binary_hello_elf_start"
);
...
...
src/kern.c
View file @
991bcbe0
...
...
@@ -82,6 +82,8 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
serial_hexstring
(
elf_hello
,
4
);
serial_writestring
(
"
\n
"
);
load_elf
((
elf_header
*
)
&
elf_hello
);
test_idt
();
while
(
true
)
{
...
...
src/mem.c
View file @
991bcbe0
...
...
@@ -9,10 +9,6 @@
// later. It must be page aligned for the MMU to read properly
page_directory_entry
page_directory
[
1024
]
__attribute__
((
aligned
(
4096
)));
// page_table_one is the first page table, and at the beginning the
// only page table in the page directory
page_table_entry
page_table_one
[
1024
]
__attribute__
((
aligned
(
4096
)));
// populate_page_table makes a page table at `table` mapping `num`
// pages to bytes after `start + offset*4KB`
// both table and start must be properly aligned
...
...
@@ -149,16 +145,17 @@ page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot
void
*
page_map
(
page_directory_entry
pgdir
[],
void
*
page_start
)
{
void
*
page
=
0
;
if
((
pgdir
[(
uint32_t
)
page_start
>>
22
]
&
0xfffff
)
==
0
)
if
((
pgdir
[(
uint32_t
)
page_start
>>
22
]
&
0xfffff
000
)
==
0
)
{
pgdir
[(
uint32_t
)
page_start
>>
22
]
|=
(
page_directory_entry
)
page_new_table
();
}
page_table_entry
*
page_table
=
(
page_table_entry
*
)
((
uint32_t
)
pgdir
[(
uint32_t
)
page_start
>>
22
]
&
0xfffff000
);
if
((
page_table
[((
uint32_t
)
page_start
>>
12
)
%
1024
]
&
0xfffff
)
==
0
)
if
((
page_table
[((
uint32_t
)
page_start
>>
12
)
%
1024
]
&
0xfffff
000
)
==
0
)
{
page
=
page_allocate
();
page_table
[((
uint32_t
)
page_start
>>
12
)
%
1024
]
|=
(
page_table_entry
)
page
;
}
return
page
;
}
...
...
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