Skip to content

Commit 6e4eadf

Browse files
committed
VMM in progress.
Added documentation Added Bochsrc Modified PMM and added a single page allocation function. Added skeleton files to iso and base. Removed some extraneous messages from kernel log.
1 parent 222928e commit 6e4eadf

File tree

16 files changed

+211
-33
lines changed

16 files changed

+211
-33
lines changed

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CPP := g++
1616
CFLAGS := -ffreestanding -std=gnu99 -nostartfiles -Wall -Wextra -DARCH${ARCH} -O2 ${DEBUGFG} -lgcc
1717
CPFLAGS := -ffreestanding -nostartfiles -fno-rtti -fno-exceptions -Wall -Wextra -DARCH${ARCH} -O2 ${DEBUGFG} -lgcc
1818
LD := ${CPP}
19-
LD_FLAGS:= -ffreestanding -nostdlib -lgcc -Wall -Wextra -O2 ${DEBUGFG}
19+
LD_FLAGS:= -ffreestanding -nostdlib -lgcc -Wall -Wextra -O2 ${DEBUGFG} -lgcc
2020

2121
GENISO := genisoimage
2222
GENISOF := -R -b boot/grub/stage2_eltorito -quiet -no-emul-boot -boot-load-size 4 -boot-info-table
@@ -65,7 +65,6 @@ clean:
6565
sysroot:
6666
@-mkdir sysroot 2>/dev/null
6767
clean-sysroot: sysroot
68-
6968
-@rm -r sysroot/*
7069

7170
sysroot-base:

arch/x86/i386/early_main.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@
44

55
#include <arch/x86/gdt.h>
66
#include <arch/x86/idt.h>
7+
#include <arch/x86/paging.h>
8+
9+
#include <pmm.h>
10+
711
void kmain();
12+
813
#ifdef GRUB_BOOT
9-
extern "C" void early_kernel_main(int magic, void* bootinfo) {
14+
extern "C" void early_kernel_main(int magic, void* bootinfo)
1015
#else
11-
extern "C" void early_kernel_main() {
16+
extern "C" void early_kernel_main()
1217
#endif
18+
{
1319
TextConsole::Init();
1420
Kernel::Version::printKernelVersion();
1521
printk(LOG_NOTICE,"\n");
16-
printk(LOG_NOTICE,"========== Started Kernel Arch Init ==========\n");
1722
//Start to initialise the hardware
1823
ArchX86::GDT::Init();
1924
ArchX86::IDT::Init();
20-
printk(LOG_NOTICE,"========== Finished Kernel Arch Init =========\n");
25+
2126
kmain();
2227
}

arch/x86/interrupts.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <arch/x86/ports.h>
66
#include <arch/x86/irq.h>
77
#include <log/printk.h>
8-
8+
#include <panic.h>
99
const char *exception_messages[] =
1010
{
1111
"Division By Zero",
@@ -61,6 +61,7 @@ extern "C" void fault_handler(struct regs *r)
6161
printk(LOG_CRIT,"eax: 0x%x ebx: 0x%x ecx: 0x%x edx: 0x%x\n",r->eax,r->ebx,r->ecx,r->edx);
6262
printk(LOG_CRIT,"esi: 0x%x edi: 0x%x eip: 0x%x eflags: 0x%x \n",r->esi,r->edi,r->eip,r->eflags);
6363
printk(LOG_CRIT,"========== Ended Kernel Fault Handler ========\n");
64+
panic("Fault!");
6465
return;
6566
}
6667
if(r->int_no < 32)
@@ -72,6 +73,7 @@ extern "C" void fault_handler(struct regs *r)
7273
printk(LOG_CRIT,"eax: 0x%x ebx:0x%x ecx:0x%x edx:0x%x\n",r->eax,r->ebx,r->ecx,r->edx);
7374
printk(LOG_CRIT,"esi: 0x%x edi:0x%x eip:0x%x eflags:0x%x\n",r->esi,r->edi,r->eip,r->eflags);
7475
printk(LOG_CRIT,"========== Ended Kernel Fault Handler ========\n");
76+
panic("Fault!");
7577
}
7678
}
7779

arch/x86/memregions.cpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22
#include <memory.h>
33
#include <pmm.h>
44

5-
memory_section_t mem_regions[3];
5+
memory_section_t pre_static_mem_regions[3];
66

77
extern "C" uintptr_t kernel_start;
88
extern "C" uintptr_t kernel_end;
99
void init_static_memregions() {
10-
mem_regions[0].type = RESERVED;
11-
mem_regions[0].start_address = 0x00000000;
12-
mem_regions[0].end_address = 0x00100000;
13-
mem_regions[0].read_only = true;
14-
mem_regions[0].vmm_mapped = 0;
10+
pre_static_mem_regions[0].type = RESERVED;
11+
pre_static_mem_regions[0].start_address = 0x00000000;
12+
pre_static_mem_regions[0].end_address = 0x00100000;
13+
pre_static_mem_regions[0].read_only = true;
14+
pre_static_mem_regions[0].vmm_mapped = 0;
1515

16-
mem_regions[1].type = KERNEL_CODE;
17-
mem_regions[1].start_address = (uintptr_t)&kernel_start;
18-
mem_regions[1].end_address = (uintptr_t)&kernel_end;
19-
mem_regions[1].read_only = true;
20-
mem_regions[1].vmm_mapped = 0;
21-
Kernel::PMM::register_memoryRegion((memory_section_t*)&mem_regions[0]);
22-
Kernel::PMM::register_memoryRegion((memory_section_t*)&mem_regions[1]);
16+
pre_static_mem_regions[1].type = KERNEL_CODE;
17+
pre_static_mem_regions[1].start_address = (uintptr_t)&kernel_start;
18+
pre_static_mem_regions[1].end_address = (uintptr_t)&kernel_end;
19+
pre_static_mem_regions[1].read_only = true;
20+
pre_static_mem_regions[1].vmm_mapped = 0;
21+
22+
pre_static_mem_regions[2].type = KERNEL_HEAP;
23+
pre_static_mem_regions[2].start_address = (uintptr_t)&kernel_end;
24+
pre_static_mem_regions[2].end_address = (uintptr_t)&kernel_end + 0x100000;
25+
pre_static_mem_regions[2].read_only = false;
26+
pre_static_mem_regions[2].vmm_mapped = 0;
27+
28+
Kernel::PMM::register_memoryRegion((memory_section_t*)&pre_static_mem_regions[0]);
29+
Kernel::PMM::register_memoryRegion((memory_section_t*)&pre_static_mem_regions[1]);
30+
//Kernel::PMM::register_memoryRegion((memory_section_t*)&pre_static_mem_regions[2]);
2331
}

arch/x86/paging.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdint.h>
2+
#include <arch/x86/paging.h>
3+
#include <log/printk.h>
4+
#include <string.h>
5+
#include <pmm.h>
6+
#include <vmm.h>
7+
#include <panic.h>
8+
#include <arch/x86/idt.h>
9+
#include <arch/x86/irq.h>
10+
11+
// x86 bits of VMM
12+
13+
void Kernel::VMM::arch_init()
14+
{
15+
printk(LOG_INFO, "vmm arch: Initialsing Paging...\n");
16+
// Idealy, we should identity map where the kernel is.
17+
}
18+
19+
void Kernel::VMM::arch_allocatePage(vmm_page_t page)
20+
{
21+
22+
}
23+
24+
vmm_page_t Kernel::VMM::addressToVmmPage(uintptr_t page)
25+
{
26+
vmm_page_t a;
27+
return a;
28+
}
29+
uintptr_t Kernel::VMM::VmmPageToAddress(vmm_page_t page)
30+
{
31+
return 0;
32+
}

bochsrc.txt

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# configuration file generated by Bochs
2+
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1, iodebug=1
3+
config_interface: textconfig
4+
display_library: x
5+
memory: host=32, guest=32
6+
romimage: file="/usr/share/bochs/BIOS-bochs-latest"
7+
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
8+
boot: cdrom
9+
floppy_bootsig_check: disabled=0
10+
# no floppya
11+
# no floppyb
12+
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
13+
ata0-master: type=cdrom, path="cdrom.iso", status=inserted, biosdetect=auto, model="Generic 1234"
14+
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
15+
ata2: enabled=0
16+
ata3: enabled=0
17+
pci: enabled=1, chipset=i440fx
18+
vga: extension=vbe, update_freq=5
19+
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
20+
cpuid: family=6, model=0x03, stepping=3, mmx=1, apic=xapic, sse=sse2, sse4a=0, sep=1, aes=0, xsave=0, xsaveopt=0, movbe=0, adx=0, smep=0, avx=0, avx_f16c=0, avx_fma=0, bmi=0, xop=0, tbm=0, fma4=0, vmx=1, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0, mwait=1
21+
cpuid: vendor_string="GenuineIntel"
22+
cpuid: brand_string=" Intel(R) Pentium(R) 4 CPU "
23+
24+
print_timestamps: enabled=0
25+
debugger_log: -
26+
magic_break: enabled=0
27+
port_e9_hack: enabled=0
28+
private_colormap: enabled=0
29+
clock: sync=none, time0=local, rtc_sync=0
30+
# no cmosimage
31+
# no loader
32+
log: -
33+
logprefix: %t%e%d
34+
panic: action=ask
35+
error: action=report
36+
info: action=report
37+
debug: action=ignore
38+
keyboard: type=mf, serial_delay=250, paste_delay=100000, keymap=
39+
user_shortcut: keys=none
40+
mouse: enabled=0, type=ps2, toggle=ctrl+mbutton
41+
parport1: enabled=1, file=""
42+
parport2: enabled=0
43+
com1: enabled=1, mode=null, dev=""
44+
com2: enabled=0
45+
com3: enabled=0
46+
com4: enabled=0

docs/TODO.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Todo List
2+
3+
[x] Booting
4+
[x] Printing data
5+
[x] Interrupt System
6+
[ ] Physical Memory Manager
7+
[ ] Virtual Memory Manager
8+
[ ] Heap
9+
[ ] Scheduling Infrastructure

includes/arch/x86/irq.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ typedef struct regs
8181
typedef void (*interrupt_handler_t)(registers_t *);
8282

8383

84+
void register_interrupt_handler (uint8_t n, interrupt_handler_t h);
85+
void deregister_interrupt_handler (uint8_t n);
8486
#endif

includes/arch/x86/paging.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef ARCH_X86_PAGING_H
2+
#define ARCH_X86_PAGING_H
3+
4+
#endif

includes/pmm.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Kernel {
88
class PMM {
99
public:
1010
static uintptr_t memsize;
11+
static uintptr_t topAllocatedAddress;
1112
static uintptr_t buddy_usedPages;
1213
static uintptr_t kernel_totalPages;
1314
static uintptr_t * buddy_startPage[PMM_BUDDY_BITMAPS];
@@ -17,10 +18,12 @@ namespace Kernel {
1718
static memory_section_t * section_slots[MEMORY_SECTION_SLOTS];
1819
public:
1920
static void refreshCache();
21+
static uintptr_t recalculateTopAllocatedAddress();
2022
static void debugPrintStatistics();
2123
static void init();
2224
static uintptr_t * allocate(unsigned int pages);
2325
static uintptr_t buddy_allocatePage(uintptr_t address);
26+
static uintptr_t * allocateSinglePage();
2427
static uintptr_t buddy_freePage(uintptr_t address);
2528
static uintptr_t buddy_testPage(uintptr_t address);
2629
static uintptr_t buddy_getFirstPage();

includes/vmm.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef KERNEL_MEMORY_VMM_H
2+
#define KERNEL_MEMORY_VMM_H
3+
#include <stddef.h>
4+
#include <stdint.h>
5+
#include <memory.h>
6+
#include <config.h>
7+
8+
typedef union vmm_page {
9+
uint32_t * x86_page;
10+
uint32_t * arm_page;
11+
} vmm_page_t;
12+
13+
namespace Kernel {
14+
class VMM {
15+
public:
16+
public:
17+
static void init();
18+
static void arch_init();
19+
20+
static void arch_allocatePage(vmm_page_t page);
21+
static void arch_freePage(vmm_page_t page);
22+
static void arch_mapPage(uintptr_t *phys, uintptr_t *virt, vmm_page_t page);
23+
static void arch_unmapPage(uintptr_t *phys, uintptr_t *virt, vmm_page_t page);
24+
25+
static void allocatePage(vmm_page_t page);
26+
static void freePage(vmm_page_t page);
27+
static void mapPage(uintptr_t *phys, uintptr_t *virt, vmm_page_t page);
28+
static void unmapPage(uintptr_t *phys, uintptr_t *virt, vmm_page_t page);
29+
static vmm_page_t addressToVmmPage(uintptr_t page);
30+
static uintptr_t VmmPageToAddress(vmm_page_t page);
31+
static void flushPage(vmm_page_t page);
32+
};
33+
};
34+
35+
#endif

kernel/init.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#include <log/printk.h>
22
#include <pmm.h>
3+
#include <vmm.h>
34
#include <panic.h>
45
int kmain(/*KernelInfo * k*/) {
5-
printk(LOG_INFO,"Control transfered to kernel init process.\n");
6-
printk(LOG_NOTICE,"========== Started Kernel Init ===============\n");
6+
77
init_static_memregions();
88
Kernel::PMM::init();
9-
Kernel::PMM::debugPrintStatistics();
10-
printk(LOG_WARN,"Kernel init process ended - Development has not made it this far yet.\n");
11-
panic("No init called!");
12-
printk(LOG_NOTICE,"========== Finished Kernel Init ==============\n");
9+
Kernel::VMM::init();
10+
printk(LOG_INFO,"kernel: Finished Init!\n");
1311
for(;;) {
1412

1513
}

0 commit comments

Comments
 (0)