Skip to content
Snippets Groups Projects
Commit cbe008ef authored by Gilles Grimaud's avatar Gilles Grimaud
Browse files

main without mmu

parent 61a58d3a
No related branches found
No related tags found
No related merge requests found
#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 ! */
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment