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
574fd64b
authored
Dec 06, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Elf segment copying
parent
ef50401d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletions
src/elf.c
src/mem.c
src/elf.c
0 → 100644
View file @
574fd64b
/*
elf.c
Mainly, contains the elf loading code
*/
#include "mem.h"
void
load_elf
(
elf_header
*
elf_start
)
{
// The elf will get its own memory space.
page_directory_entry
*
pgdir
=
page_new_directory
();
// loop through and copy memory segments
for
(
int
i
=
0
;
i
<
elf_start
->
ph_entry_count
;
i
++
)
{
// get this section header
elf_program_header
*
ph
;
ph
=
elf_start
+
elf_start
->
ph_table_offset
+
(
i
*
elf_start
->
ph_entry_size
);
// map and copy
for
(
pg
=
ph
->
p_vaddr
&
0xfffff000
;
pg
-
ph
->
p_vaddr
<
ph
->
memory_segment_size
;
pg
+=
0x1000
)
{
real_page
=
page_allocate
(
pg
);
start
=
(
pg
>
ph
->
p_vaddr
)
?
pg
:
ph
->
p_vaddr
;
end
=
(
pg
+
0x1000
<
ph
->
p_vaddr
+
ph
->
file_segment_size
)
?
pg
+
0x1000
:
ph
->
p_vaddr
+
ph
->
file_segment_size
;
size
=
end
-
start
;
offset
=
(
pg
>
ph
->
p_vaddr
)
?
0
:
ph
->
p_vaddr
-
pg
;
// do some memcpy stuff
memcpy
(
real_page
+
offset
,
start
,
size
);
elf_start
+
p
->
ph_offset
}
}
}
src/mem.c
View file @
574fd64b
...
...
@@ -148,14 +148,17 @@ page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot
// that that address points to valid memory
void
page_map
(
page_directory_entry
[]
pgdir
,
void
*
page_start
)
{
void
*
page
=
0
;
if
(
pgdir
[
page_start
>>
22
]
&
0xfffff
==
0
)
{
pgdir
[
page_start
>>
22
]
|=
page_new_table
();
}
if
(
pgdir
[
page_start
>>
22
][(
page_start
>>
12
)
%
1024
]
&
0xfffff
==
0
)
{
pgdir
[
page_start
>>
22
][(
page_start
>>
12
)
%
1024
]
|=
page_allocate
();
page
=
page_allocate
();
pgdir
[
page_start
>>
22
][(
page_start
>>
12
)
%
1024
]
|=
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