Skip to content

Commit

Permalink
Kernel: Change panic screen, disable XHCI for now as it does not even
Browse files Browse the repository at this point in the history
work
  • Loading branch information
fido2020 committed Jul 13, 2022
1 parent 03e9e4b commit a65e838
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
9 changes: 1 addition & 8 deletions Kernel/Modules/PCAudio/AC97.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Math.h>

namespace Audio {
void AC97IRQHandler(void* ctx, RegisterContext*) { ((AC97Controller*)ctx)->OnIRQ(); }

AC97Controller::AC97Controller(const PCIInfo& info) : PCIDevice(info) {
SetDeviceName("AC97 Audio Controller");
Expand Down Expand Up @@ -77,10 +76,6 @@ AC97Controller::AC97Controller(const PCIInfo& info) : PCIDevice(info) {
m_samplesPerBuffer = PAGE_SIZE_4K / m_pcmSampleSize / m_pcmNumChannels;

outportl(m_nabmPort + PO_BufferDescriptorList, bufferDescriptorListPhys);

// uint8_t irq = AllocateVector(PCIVectorAny);
// IDT::RegisterInterruptHandler(irq, AC97IRQHandler, this);

outportl(m_nabmPort + NBGlobalControl, globalControl);

uint8_t transferControl = inportb(nabmTransferControl);
Expand Down Expand Up @@ -167,9 +162,7 @@ int AC97Controller::WriteSamples(void* output, uint8_t* buffer, size_t size, boo

int samplesWritten = 0;
{
// Disable interrupts in case IRQ fires,
// interrupts are already disabled
ScopedSpinLock<true> lockController(m_lock);
ScopedSpinLock lockController(m_lock);

int currentBuffer = inportb(m_nabmPort + PO_CurrentEntry);
int lastValidEntry = inportb(m_nabmPort + PO_LastValidEntry);
Expand Down
4 changes: 2 additions & 2 deletions Kernel/include/Video/Video.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Video{
FancyRefPtr<VMObject> GetFramebufferVMO();

void DrawRect(unsigned int x, unsigned int y, unsigned int width, unsigned int height, uint8_t r, uint8_t g, uint8_t b);
void DrawChar(char c, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b);
void DrawString(const char* str, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b);
void DrawChar(char c, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b, int vscale = 1, int hscale = 1);
void DrawString(const char* str, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b, int vscale = 1, int hscale = 1);

void DrawBitmapImage(unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint8_t *data);
}
6 changes: 6 additions & 0 deletions Kernel/src/MM/KMalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Lock {
lock_t m_lock = 0;
};

lock_t allocatorInstanceLock = 0;

struct KernelAllocator {
uintptr_t map(size_t len) {
size_t pageCount = (len + PAGE_SIZE_4K - 1) / PAGE_SIZE_4K;
Expand Down Expand Up @@ -54,6 +56,8 @@ struct KernelAllocator {
KernelAllocator* allocator = nullptr;

frg::slab_allocator<KernelAllocator, Lock>& Allocator() {
acquireLock(&allocatorInstanceLock);

// This is a hack to get around the allocator not being initialized
if (!allocator) {
size_t pageCount = (sizeof(KernelAllocator) + PAGE_SIZE_4K - 1) / PAGE_SIZE_4K;
Expand All @@ -68,6 +72,8 @@ frg::slab_allocator<KernelAllocator, Lock>& Allocator() {
new (allocator) KernelAllocator;
}

releaseLock(&allocatorInstanceLock);

return allocator->slabAllocator;
}

Expand Down
6 changes: 4 additions & 2 deletions Kernel/src/Panic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ void KernelPanic(const char** reasons, int reasonCount) {

video_mode_t v = Video::GetVideoMode();
Video::DrawRect(0, 0, v.width, v.height, 0, 0, 0);
int pos = 20;
int pos = 5;
for (int i = 0; i < reasonCount; i++) {
Video::DrawString(reasons[i], v.width / 2 - strlen(reasons[i]) * 8 / 2, pos, 255, 0, 0);
Video::DrawString(reasons[i], 5, pos, 255, 128, 0);
pos += 10;
}

Video::DrawString("Fatal Exception", v.width / 2 - strlen("Fatal Exception") * 16 / 2, v.height / 2, 255, 255, 255, 3, 2);

Video::DrawString("Lemon has encountered a fatal error.", 0, v.height - 200, 255, 255, 255);
Video::DrawString("The system has been halted.", 0, v.height - 200 + 8, 255, 255, 255);

Expand Down
6 changes: 4 additions & 2 deletions Kernel/src/USB/XHCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ int XHCIController::Initialize() {
return 1;
}

PCI::EnumerateGenericPCIDevices(xhciClassCode, xhciSubclass, [](const PCIInfo& dev) -> void {
return 0;

/*PCI::EnumerateGenericPCIDevices(xhciClassCode, xhciSubclass, [](const PCIInfo& dev) -> void {
if (dev.progIf == xhciProgIF) {
xhciControllers.add_back(new XHCIController(dev));
}
});
return 0;
return 0;*/
}

XHCIController::XHCIController(const PCIInfo& dev) : PCIDevice(dev) {
Expand Down
32 changes: 22 additions & 10 deletions Kernel/src/Video/Video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,24 @@ void DrawRect(unsigned int x, unsigned int y, unsigned int width, unsigned int h
}
}

void DrawChar(char c, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b) {
uint32_t colour = r << 16 | g << 8 | b;
for (unsigned i = 0; i < 8; i++) {
int row = defaultFont[(int)c][i];
for (unsigned j = 0; j < 8; j++) {
if ((row & (1 << j)) >> j) {
((uint32_t*)videoMemory)[((y + i) * screenWidth) + x + j] = colour;
void DrawChar(char c, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b, int vscale, int hscale) {
if(vscale <= 1 && hscale <= 1) {
uint32_t colour = r << 16 | g << 8 | b;
for (unsigned i = 0; i < 8; i++) {
int row = defaultFont[(int)c][i];
for (unsigned j = 0; j < 8; j++) {
if ((row & (1 << j)) >> j) {
((uint32_t*)videoMemory)[((y + i) * screenWidth) + x + j] = colour;
}
}
}
} else {
for (unsigned i = 0; i < 8; i ++) {
int row = defaultFont[(int)c][i];
for (unsigned j = 0; j < 8; j++) {
if ((row & (1 << j)) >> j) {
DrawRect(x + j * hscale, y + i * vscale, hscale, vscale, r, g, b);
}
}
}
}
Expand Down Expand Up @@ -238,11 +249,12 @@ void DrawBitmapImage(unsigned int x, unsigned int y, unsigned int w, unsigned in
}
}

void DrawString(const char* str, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b) {
void DrawString(const char* str, unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b, int vscale, int hscale) {
int xOffset = 0;
int step = 8 * hscale;
while (*str != 0) {
Video::DrawChar(*str, x + xOffset, y, r, g, b);
xOffset += 8;
Video::DrawChar(*str, x + xOffset, y, r, g, b, vscale, hscale);
xOffset += step;
str++;
}
}
Expand Down

0 comments on commit a65e838

Please sign in to comment.