You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.6 KiB
C++

#include "arch/lapic.h"
#include "boot/startup_ap.h"
#include "arch/core_interrupt.h"
#include "debug/copystream.h"
#include "debug/output.h"
#include "debug/assert.h"
#include "arch/cga.h"
#include "arch/textwindow.h"
#include "arch/serial.h"
#include "device/serialstream.h"
#include "device/textstream.h"
#include "device/ps2controller.h"
#include "arch/ioapic.h"
TextStream kout = TextStream(0, 80, 0, 10, true);
//TextStream dout[8] = {
// TextStream(0 ,20,12,25,false),
// TextStream(20,40,12,25,false),
// TextStream(40,60,12,25,false),
// TextStream(60,80,12,25,false),
// TextStream(0 ,0 ,0, 0,false),
// TextStream(0 ,0 ,0, 0,false),
// TextStream(0 ,0 ,0, 0,false),
// TextStream(0 ,0 ,0, 0,false),
//};
TextStream dout[Core::MAX] = {
{0, 40, 10, 14},
{40, 80, 10, 14},
{0, 40, 14, 18},
{40, 80, 14, 18},
{0, 40, 18, 22},
{40, 80, 18, 22},
{0, 40, 22, 25},
{40, 80, 22, 25},
};
CopyStream copystream[Core::MAX]{
{&dout[0], &sout},
{&dout[1], &sout},
{&dout[2], &sout},
{&dout[3], &sout},
{&dout[4], &sout},
{&dout[5], &sout},
{&dout[6], &sout},
{&dout[7], &sout},
};
OutputStream* copyout[Core::MAX]{
&dout[0],
&copystream[1],
&dout[2],
&dout[3],
&dout[4],
&dout[5],
&dout[6],
&dout[7]
};
void test(){
kout << "test" << endl << flush;
}
// Main function
// (the bootstrap processor starts here)}
extern "C" int main() {
unsigned int numCPUs = Core::count();
DBG_VERBOSE << "Number of CPUs: " << numCPUs << endl;
////test cga implemantation
// CGA::setCursor(1, 2);
// unsigned x,y;
// CGA::getCursor(x, y);
// CGA::setCursor(x+1, y+1);
// for(uint8_t i = 0; i < 10; i++)
// CGA::show(i, i, i+0x30, CGA::Attribute());
////test textwindow implemantation
//TextWindow tw_global = TextWindow(0, 80, 0, 25, true);
//tw_global.reset(' ', CGA::Attribute(CGA::LIGHT_GREEN, CGA::BLUE, false));
//// test SerialStream
//SerialStream ss = SerialStream();
//ss.print("test", 4);
//ss.setAttribute(SerialStream::UNDERSCORE);
//ss.print("test", 4);
//ss.setAttribute(SerialStream::RESET);
//ss.setForeground(SerialStream::MAGENTA);
//ss.print("test", 4);
//ss.setBackground(SerialStream::CYAN);
//ss.print("test", 4);
//ss.setPos(10, 10);
//ss.print("test\n", 5);
//ss.setBackground(SerialStream::BLACK);
kout << "Test <stream result> -> <expected>" << endl;
kout << "bool: " << true << " -> true" << endl;
kout << "zero: " << 0 << " -> 0" << endl;
kout << "binary: " << bin << 42 << dec << " -> 0b101010" << endl;
kout << "octal: " << oct << 42 << dec << " -> 052" << endl;
kout << "hex: " << hex << 42 << dec << " -> 0x2a" << endl;
kout << "uint64_t max: " << ~((uint64_t)0) << " -> 18446744073709551615" << endl;
kout << "int64_t max: " << ~(1ll<<63) << " -> 9223372036854775807" << endl;
kout << "int64_t min: " << (1ll<<63) << " -> -9223372036854775808" << endl;
kout << "some int64_t: " << (-1234567890123456789) << " -> -1234567890123456789" << endl;
kout << "some int64_t: " << (1234567890123456789) << " -> 1234567890123456789" << endl;
kout << "pointer: " << reinterpret_cast<void*>(1994473406541717165ull)
<< " -> 0x1badcafefee1dead" << endl;
kout << "smiley: " << static_cast<char>(1) << endl;
/* Start application processors
* To avoid unexpected behaviour, make sure that interrupts are not
* enabled before the APs are booted. Otherwise it might interfere with the
* Startup IPIs or even block devices like keyboard because of a missing EOI
*/
ApplicationProcessor::boot();
PS2Controller::init();
IOAPIC::init();
IOAPIC::config(1, Core::Interrupt::KEYBOARD);
IOAPIC::allow(1);
Core::Interrupt::enable();
Key key = Key();
while (true){
if (PS2Controller::fetch(key)) {
kout << key.ascii() << flush ;
}
}
return 0;
}
// Main function for application processors
extern "C" int main_ap() {
DBG_VERBOSE << "CPU core " << static_cast<int>(Core::getID()) << " / LAPIC "
<< static_cast<int>(LAPIC::getID()) << " in main_ap()" << endl;
Core::Interrupt::enable();
//TextWindow dout0 = TextWindow(0,20,13,19, false);
//dout0.reset();
//dout0.reset(' ', CGA::Attribute(CGA::LIGHT_GREEN, CGA::RED, false));
////test Serial
//Serial s = Serial();
//s.write('a');
//uint8_t from = static_cast<int>(LAPIC::getID()) * 20;
//uint8_t to = from+20;
//dout[LAPIC::getID()] = TextStream(from, to, 0, 6, false);
DBG << "test\n" << flush;
DBG << static_cast<int>(LAPIC::getID()) << endl << flush;
assert(Core::getID() != 1);
return 0;
}