added PMM for PC
This commit is contained in:
parent
8f9423b5cd
commit
886e585d80
16 changed files with 78 additions and 8 deletions
|
@ -16,7 +16,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/i686-elf.cmake .. &&
|
|||
make -j$(nproc) &&
|
||||
popd &&
|
||||
buildtools/grub-iso.sh &&
|
||||
mv bootable.iso out/x86-pc.iso
|
||||
mv bootable.iso out/x86-pc.iso &&
|
||||
cp build/kernel/kernel out/x86-pc.elf
|
||||
|
||||
#x86-PC config
|
||||
{
|
||||
|
@ -29,7 +30,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/x86_64-elf.cmake .. &&
|
|||
make -j$(nproc) &&
|
||||
popd &&
|
||||
buildtools/grub-iso.sh &&
|
||||
mv bootable.iso out/x86_64-pc.iso
|
||||
mv bootable.iso out/x86_64-pc.iso &&
|
||||
cp build/kernel/kernel out/x86_64-pc.elf
|
||||
|
||||
#arm-3ds9 config
|
||||
{
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
#include <base.hpp>
|
||||
#include <config.h>
|
||||
#include "../../../mmaps/3ds11.mh"
|
||||
#include "../../../hw/pmm/pmm.hpp"
|
||||
|
||||
PICAfb term;
|
||||
PMM_MMAP lpmm;
|
||||
void main();
|
||||
extern "C" void start() { main(); }
|
||||
void drivers_init() {
|
||||
pmm=(PMM*)(&lpmm);
|
||||
setMainTTY(&term);
|
||||
--term;
|
||||
initVectors();
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
#include <base.hpp>
|
||||
#include <config.h>
|
||||
#include "../../../mmaps/3ds9.mh"
|
||||
#include "../../../hw/pmm/pmm.hpp"
|
||||
|
||||
PICAfb term;
|
||||
PMM_MMAP lpmm;
|
||||
void main();
|
||||
extern "C" void start() { main();
|
||||
for(;;);
|
||||
}
|
||||
void drivers_init() {
|
||||
pmm=(PMM*)(&lpmm);
|
||||
setMainTTY(&term);
|
||||
--term;
|
||||
initVectors();
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/arm/3ds11/include -mcpu=cortex-a7 -mlittle-endian -mtune=cortex-a7 -mfloat-abi=hard -mtp=soft -O2")
|
||||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/arm/3ds11/include -mcpu=cortex-a7 -mlittle-endian -mtune=cortex-a7 -mfloat-abi=hard -mtp=soft -O0")
|
||||
SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
#include <base.hpp>
|
||||
#include <config.h>
|
||||
#include "../../../mmaps/raspi2.mh"
|
||||
#include "../../../hw/pmm/pmm.hpp"
|
||||
|
||||
Serial term;
|
||||
PMM_MMAP lpmm;
|
||||
void main();
|
||||
extern "C" void start() { main(); }
|
||||
void drivers_init() {
|
||||
pmm=(PMM*)(&lpmm);
|
||||
setMainTTY(&term);
|
||||
--term;
|
||||
initVectors();
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86/pc/include")
|
||||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86/pc/include -O2")
|
||||
SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
#include "../../../hw/pc/8259/pic.hpp"
|
||||
#include "../../../hw/pc/idt/idt.hpp"
|
||||
#include "../../../hw/pc/pmm/pmm.hpp"
|
||||
#include <base.hpp>
|
||||
static multiboot_info_t *mb_info;
|
||||
#ifndef ENABLE_FRAMEBUFFER
|
||||
|
@ -14,12 +15,14 @@ CGATerm term;
|
|||
#else
|
||||
VESAfb term(mb_info);
|
||||
#endif
|
||||
PMM_MB lpmm(mb_info);
|
||||
void main();
|
||||
extern "C" void start(int eax, multiboot_info_t *ebx) {
|
||||
mb_info = ebx;
|
||||
main();
|
||||
}
|
||||
void drivers_init() {
|
||||
pmm=(PMM*)(&lpmm);
|
||||
setMainTTY(&term);
|
||||
--term;
|
||||
initIDT();
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86_64/pc/include")
|
||||
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86_64/pc/include -O2")
|
||||
SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}")
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
#include "../../../hw/pc/8259/pic.hpp"
|
||||
#include "../../../hw/pc/idt/idt.hpp"
|
||||
#include "../../../hw/pc/pmm/pmm.hpp"
|
||||
|
||||
#include <base.hpp>
|
||||
static multiboot_info_t *mb_info;
|
||||
|
@ -15,12 +16,14 @@ CGATerm term;
|
|||
#else
|
||||
VESAfb term(mb_info);
|
||||
#endif
|
||||
PMM_MB lpmm(mb_info);
|
||||
void main();
|
||||
extern "C" void start(int eax, multiboot_info_t *ebx) {
|
||||
mb_info = ebx;
|
||||
main();
|
||||
}
|
||||
void drivers_init() {
|
||||
pmm=(PMM*)(&lpmm);
|
||||
setMainTTY(&term);
|
||||
--term;
|
||||
initIDT();
|
||||
|
|
21
kernel/hw/pc/pmm/pmm.cpp
Normal file
21
kernel/hw/pc/pmm/pmm.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "pmm.hpp"
|
||||
PMM_MB::PMM_MB(multiboot_info_t *mb_info): PMM(0x1000), mb_info(mb_info) {}
|
||||
|
||||
PMM_MB::~PMM_MB() {}
|
||||
|
||||
auto PMM_MB::isFree(phys_t addr) -> bool {
|
||||
auto mmap = (multiboot_memory_map_t*)((uintptr_t)(mb_info->mmap_addr));
|
||||
bool free=false;
|
||||
for(uint32_t i=0;i<mb_info->mmap_length;i++) {
|
||||
if((mmap[i].addr > addr) || (mmap[i].addr + mmap[i].len < addr))
|
||||
continue;
|
||||
if(mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE)
|
||||
return false;
|
||||
free=true;
|
||||
}
|
||||
if(!free)
|
||||
return false;
|
||||
if(addr == (phys_t)((uintptr_t)mb_info))
|
||||
return false;
|
||||
return PMM::isFree(addr);
|
||||
}
|
12
kernel/hw/pc/pmm/pmm.hpp
Normal file
12
kernel/hw/pc/pmm/pmm.hpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include <pmm.hpp>
|
||||
#include <multiboot.h>
|
||||
class PMM_MB: public PMM {
|
||||
protected:
|
||||
multiboot_info_t *mb_info;
|
||||
virtual auto isFree(phys_t addr) -> bool;
|
||||
public:
|
||||
PMM_MB()=delete;
|
||||
PMM_MB(multiboot_info_t *mb_info);
|
||||
virtual ~PMM_MB();
|
||||
};
|
|
@ -79,7 +79,7 @@ PMM_MMAP::PMM_MMAP(): PMM(0x1000) {
|
|||
uint8_t *off=(uint8_t*)(&header+1);
|
||||
for(uint32_t i=0;i<header.length;i++) {
|
||||
MMAPTag &tag = *((MMAPTag*)off);
|
||||
off+=tag.size;
|
||||
off+=tag.size+2;
|
||||
switch(tag.id) {
|
||||
case 0:
|
||||
case 1:
|
||||
|
@ -122,7 +122,7 @@ auto PMM_MMAP::isFree(phys_t addr) -> bool {
|
|||
uint8_t *off=(uint8_t*)(&header+1);
|
||||
for(uint32_t i=0;i<header.length;i++) {
|
||||
MMAPTag &tag = *((MMAPTag*)off);
|
||||
off+=tag.size;
|
||||
off+=tag.size+2;
|
||||
if(tag.id != 5)
|
||||
continue;
|
||||
if((tag.REGION.start > addr) || (tag.REGION.end < addr))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
DEVICETYPE CONSOLE
|
||||
DEVICETYPE EMBEDDED
|
||||
DEVICENAME RASPI2
|
||||
CPUARCH ARM
|
||||
ENDIAN LITTLE
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
#include <kobject.hpp>
|
||||
#include <tty.hpp>
|
||||
#include <pmm.hpp>
|
||||
extern TTY *out; ///< main TTY for output
|
||||
extern PMM *pmm;
|
||||
/***
|
||||
* Sets the main TTY to some other TTY object.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <base.hpp>
|
||||
TTY *out;
|
||||
PMM *pmm;
|
||||
bool tty_set = false;
|
||||
void setMainTTY(TTY *obj) {
|
||||
++*obj;
|
||||
|
|
|
@ -12,6 +12,23 @@ auto PMM::isFree(phys_t addr) -> bool {
|
|||
return true;
|
||||
}
|
||||
PMM::PMM(phys_t page_size): page_size(page_size), head(nullptr) {
|
||||
#ifndef __x86_64__
|
||||
for(phys_t i=page_size; i; i+=page_size) {
|
||||
if(isFree(i))
|
||||
*this << i;
|
||||
}
|
||||
#else
|
||||
//Find out highest GB
|
||||
phys_t top=0;
|
||||
for(phys_t i=page_size; i<1024*1024*1024*1024; i+=1024*1024*1024) {
|
||||
if(isFree(i))
|
||||
top=i;
|
||||
}
|
||||
for(phys_t i=page_size; i < top; i+=page_size) {
|
||||
if(isFree(i))
|
||||
*this << i;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PMM::~PMM() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue