Continuing cleanup...

This commit is contained in:
Cody Brocious 2016-06-04 15:46:58 -06:00
parent f91e74ef2b
commit 6c9c929cc1
4 changed files with 35 additions and 31 deletions

20
Box.cpp
View file

@ -5,20 +5,20 @@ Box *box;
Box::Box() {
box = this;
cpu = new Cpu();
hypercall = new Hypercall();
cpu = make_unique<Cpu>();
hypercall = make_unique<Hypercall>();
hm = new HandleManager();
pm = new PageManager();
hm = make_unique<HandleManager>();
pm = make_unique<PageManager>();
pm->add_region(0, 64 * ONE_MB);
tm = new ThreadManager();
io = new IOManager();
tm = make_unique<ThreadManager>();
io = make_unique<IOManager>();
debugger = new Debugger();
debugger = make_unique<Debugger>();
gpu = new Gpu();
lpc = new Lpc();
smbus = new Smbus();
gpu = make_unique<Gpu>();
lpc = make_unique<Lpc>();
smbus = make_unique<Smbus>();
}
void Box::add_mmio(uint32_t base, uint32_t pages, Device *dev) {

20
Box.hpp
View file

@ -9,17 +9,17 @@ public:
void add_port(uint32_t port, Device *dev);
void add_pci(uint16_t bus, uint16_t slot, Device *dev);
Cpu *cpu;
Hypercall *hypercall;
HandleManager *hm;
PageManager *pm;
ThreadManager *tm;
IOManager *io;
Debugger *debugger;
unique_ptr<Cpu> cpu;
unique_ptr<Hypercall> hypercall;
unique_ptr<HandleManager> hm;
unique_ptr<PageManager> pm;
unique_ptr<ThreadManager> tm;
unique_ptr<IOManager> io;
unique_ptr<Debugger> debugger;
Gpu *gpu;
Lpc *lpc;
Smbus *smbus;
unique_ptr<Gpu> gpu;
unique_ptr<Lpc> lpc;
unique_ptr<Smbus> smbus;
map<uint32_t, Device *> mmio;
map<uint32_t, Device *> ports;

10
Cpu.cpp
View file

@ -53,6 +53,12 @@ Cpu::Cpu() {
hv->reg(CR4, 0x2000);
}
Cpu::~Cpu() {
delete hv;
delete[] mem;
delete[] kmem;
}
void Cpu::map_pages(uint32_t virt, uint32_t phys, uint32_t count, bool present) {
auto dir = (uint32_t *) (mem + 64*ONE_MB);
for(auto i = 0; i < count; ++i) {
@ -135,10 +141,6 @@ void Cpu::write_memory(uint32_t addr, uint32_t size, void *buffer) {
}
}
Cpu::~Cpu() {
delete hv;
}
#define TASK_TIMER 20 // Milliseconds
#define TASK_INTERRUPT 80

View file

@ -1,6 +1,6 @@
#include "Zookeeper.hpp"
uint32_t load_multiboot(Cpu *cpu, uint32_t *header) {
uint32_t load_multiboot(uint32_t *header) {
assert(header[1] & 0x10000);
uint8_t *rel = (uint8_t *) header;
@ -10,14 +10,14 @@ uint32_t load_multiboot(Cpu *cpu, uint32_t *header) {
memsize = (memsize & ~PAGE_MASK) + PAGE_SIZE;
assert(memsize <= KRAM_SIZE);
memcpy(cpu->kmem + (header[4] - KBASE), rel + (header[4] - header[3]), memsize);
memset(cpu->kmem + (header[5] - KBASE), 0, header[6] - header[5]);
cpu->map_pages(KBASE, KBASE, memsize / PAGE_SIZE);
memcpy(box->cpu->kmem + (header[4] - KBASE), rel + (header[4] - header[3]), memsize);
memset(box->cpu->kmem + (header[5] - KBASE), 0, header[6] - header[5]);
box->cpu->map_pages(KBASE, KBASE, memsize / PAGE_SIZE);
return header[7];
}
uint32_t load_kernel(Cpu *cpu) {
uint32_t load_kernel() {
FILE *fp = fopen("nightbeliever.krnl", "r");
fseek(fp, 0, SEEK_END);
uint32_t size = ftell(fp);
@ -30,7 +30,7 @@ uint32_t load_kernel(Cpu *cpu) {
uint32_t entry;
do {
if(*seek == 0x1BADB002 && seek[2] == -(seek[0] + seek[1])) {
if((entry = load_multiboot(cpu, seek)) != -1)
if((entry = load_multiboot(seek)) != -1)
break;
}
} while(++seek != end);
@ -50,13 +50,15 @@ void intHandler(int _) {
int main(int argc, char **argv) {
new Box;
uint32_t entry = load_kernel(box->cpu);
uint32_t entry = load_kernel();
auto xbe = new Xbe((char *) "test1.xbe");
xbe->LoadImage();
signal(SIGINT, intHandler);
box->cpu->run(entry);
delete box;
return 0;
}