Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
my kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Barbara Joyez
my kernel
Commits
cbe008ef
Commit
cbe008ef
authored
2 years ago
by
Gilles Grimaud
Browse files
Options
Downloads
Patches
Plain Diff
main without mmu
parent
61a58d3a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+7
-69
7 additions, 69 deletions
src/main.c
with
7 additions
and
69 deletions
src/main.c
+
7
−
69
View file @
cbe008ef
#include
"ioport.h"
#include
"gdt.h"
#include
"idt.h"
#include
"minilib.h"
#include
"mmu.h"
#include
"ioport.h"
#include
"syscalls.h"
extern
void
user
(
void
);
extern
void
app_main
(
void
);
void
empty_irq
(
int_regs_t
*
r
)
{
}
void
syscall_handler
(
int_regs_t
*
r
)
{
switch
(
r
->
eax
)
{
case
SYSCALL_PUTC
:
putc
(
r
->
edi
);
break
;
default:
puts
(
"unhandled syscall
\n
"
);
break
;
};
}
static
struct
pte_s
my_page_table
[
PT_SIZE
]
__attribute__
((
aligned
(
PAGE_SIZE
)));
void
fault_handler
(
int_regs_t
*
r
)
{
puts
(
"page fault! fault address="
);
puthex
(
get_fault_address
());
puts
(
"
\n
"
);
/* Example: allow access to 0x800000 */
int
fault_page
=
get_fault_address
()
>>
12
;
if
(
fault_page
==
0x800
)
{
puts
(
"Add page mapping...
\n
"
);
memset
(
my_page_table
,
0
,
sizeof
(
my_page_table
));
my_page_table
[
0
].
g
=
0
;
/* page locale */
my_page_table
[
0
].
pat
=
0
;
my_page_table
[
0
].
d
=
0
;
my_page_table
[
0
].
a
=
0
;
my_page_table
[
0
].
pcd
=
0
;
/* cache activé */
my_page_table
[
0
].
pwt
=
0
;
/* cache write back */
my_page_table
[
0
].
us
=
1
;
/* page user */
my_page_table
[
0
].
rw
=
1
;
/* page read write */
my_page_table
[
0
].
p
=
1
;
/* entrée présente */
my_page_table
[
0
].
address
=
0x800
;
/* map to physical page 0x800 */
my_page_table
[
0
].
unused1
=
0
;
setup_page_table
(
2
/* our page table will map vpages starting at 2*0x400 == 0x800 to 0xBFF */
,
my_page_table
);
/* so my_page_table[0] represents vpage 0x800, which will be mapped to ppage 0x800 */
flush_tlb
();
return
;
}
for
(;;);
}
/* multiboot entry-point with datastructure as arg. */
void
main
(
unsigned
int
*
mboot_info
)
{
/* clear the screen */
clear_screen
();
puts
(
"Early boot.
\n
"
);
/* Initialize the memory */
puts
(
"
\t
-> Setting up the GDT... "
);
gdt_init_default
();
puts
(
"OK
\n
"
);
/* Initializa the Interrupt Descriptor Table */
puts
(
"
\t
-> Setting up the IDT... "
);
setup_idt
();
puts
(
"OK
\n
"
);
puts
(
"
\t
-> Setting up the MMU... "
);
setup_mmu
();
puts
(
"OK
\n
"
);
puts
(
"
\n\n
"
);
/* Installs two empty handlers for the timer (0) and the keyboard (1) */
idt_setup_irq_handler
(
0
,
empty_irq
);
idt_setup_irq_handler
(
1
,
empty_irq
);
idt_setup_int_handler
(
87
,
syscall_handler
);
idt_setup_int_handler
(
14
,
fault_handler
);
idt_setup_int_handler
(
0
,
empty_irq
);
idt_setup_int_handler
(
1
,
empty_irq
);
/* Enables interrupts */
__asm
volatile
(
"sti"
);
/* minimal setup done ! */
app_main
();
puts
(
"
\t
-> Switching to user-mode... "
);
user
();
/* switch to user-mode and calls user_entry() in user.c */
}
puts
(
"Going idle
\n
"
);
for
(;;)
;
/* nothing more to do... really nothing ! */
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment