Introducing my New BSD licensed OS
Posted: Wed Jul 15, 2009 8:02 pm
What I have so far is a 64bit OS that loads using GRUB. Here is the source code break down:
602 entry.asm
67 entry32.asm
115 init.cpp
84 mm.cpp
737 smp.cpp
574 video.cpp
62 options.h
2241 total
This shows the number of lines of each file. The system is called "Options".
I'm attaching video.cpp so you can get a feel for the system, if you want full source get it here:
http://code.google.com/p/vm64dec/downloads/list.
The upper 512 GB of linear memory is reserved for linear page-table space. It works like this: I have two PML4's (the level 4 page table), one is the master and one is a mirror of it.
Here is some code regarding memory management that makes use of the linear page-table space:
The above code maps in a 4kb physical page in 64bit linear memory space. It allocates page tables (level 3,2,1) as needed to fulfill the request. It is used very early on in system initialization.
I have made a 32bit uniprocessor multitasking scheduler before (actually several) but never a multiprocessing scheduler. I've also never implemented disk swapping. I don't want to work myself into a corner, so I am being careful about the order I do things in.
(Truthfully I'm 26 years old now and I've been doing OS development since 8th grade. Don't have too much to show for it, I'm the guy who always starts over because he didn't understand requirements properly and wanted to just sit down and code...) If anyone out there is trying to get started with a free 64bit OS and needs some help, I can help out.
602 entry.asm
67 entry32.asm
115 init.cpp
84 mm.cpp
737 smp.cpp
574 video.cpp
62 options.h
2241 total
This shows the number of lines of each file. The system is called "Options".
I'm attaching video.cpp so you can get a feel for the system, if you want full source get it here:
http://code.google.com/p/vm64dec/downloads/list.
The upper 512 GB of linear memory is reserved for linear page-table space. It works like this: I have two PML4's (the level 4 page table), one is the master and one is a mirror of it.
Here is some code regarding memory management that makes use of the linear page-table space:
Code: Select all
U8 init_mmap(U8 physical)
{
init_malign(4096 - 1);
U8 linear = kernel_load_address + init_linear_size;
init_linear_size += 4096;
U8 *real_pml4 = first_pml4; // fixme--this only works for the init process
U8 *table = (U8 *)(0xfffffffffffff000L);
U8 entry = (linear & 0x0000ffffffffffffL) >> (48 - 9);
if(table[entry] == 0)
{
U8 value = init_malloc_phys() | 3;
table[entry] = value;
real_pml4[entry] = value;
reload_cr3();
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 2);
zero_page((0xffffffffffe00000L + 8 * entry) & 0xfffffffffffff000L);
}
table = (U8 *)(0xffffffffffe00000L);
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 2);
if(table[entry] == 0)
{
U8 value = init_malloc_phys() | 3;
table[entry] = value;
reload_cr3();
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 3);
zero_page((0xffffffffc0000000L + 8 * entry) & 0xfffffffffffff000L);
}
table = (U8 *)(0xffffffffc0000000L);
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 3);
if(table[entry] == 0)
{
U8 value = init_malloc_phys() | 3;
table[entry] = value;
reload_cr3();
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 4);
zero_page((-512L*1024L*1024L*1024L + 8L * entry) & 0xfffffffffffff000L);
}
table = (U8 *)(-512L*1024L*1024L*1024L);
entry = (linear & 0x0000ffffffffffffL) >> (48 - 9 * 4);
table[entry] = physical | 3;
reload_cr3();
return linear;
}
I have made a 32bit uniprocessor multitasking scheduler before (actually several) but never a multiprocessing scheduler. I've also never implemented disk swapping. I don't want to work myself into a corner, so I am being careful about the order I do things in.
(Truthfully I'm 26 years old now and I've been doing OS development since 8th grade. Don't have too much to show for it, I'm the guy who always starts over because he didn't understand requirements properly and wanted to just sit down and code...) If anyone out there is trying to get started with a free 64bit OS and needs some help, I can help out.