diff --git a/include/fs/impl.h b/include/fs/impl.h index f8c55cc..935beb2 100644 --- a/include/fs/impl.h +++ b/include/fs/impl.h @@ -36,6 +36,7 @@ uint8_t loadFile(inode_t* inode, void* dest) { if (totalBlocks > 0) { // TODO: Indirect extents + return 1; } return 0; diff --git a/include/screen/graphics.h b/include/screen/graphics.h index 157787d..f8e70ce 100644 --- a/include/screen/graphics.h +++ b/include/screen/graphics.h @@ -26,7 +26,6 @@ void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) { int8_t sx = (x1 < x2) ? 1 : -1; int8_t sy = (y1 < y2) ? 1 : -1; int16_t err = dx + dy; - // TODO: Sometimes the condition isn't met for some reason and it breaks everything while (!(x1 == x2 && y1 == y2)) { diff --git a/kern.iso b/kern.iso index cdf5b25..2af9ee8 100644 Binary files a/kern.iso and b/kern.iso differ diff --git a/src/stage2.asm b/src/stage2.asm index 73b9130..7b51d60 100644 --- a/src/stage2.asm +++ b/src/stage2.asm @@ -368,7 +368,7 @@ CODE_SEG equ GDT.codeDescriptor - GDT.start DATA_SEG equ GDT.dataDescriptor - GDT.start ;; VBE Stuff -;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !! +;; XXX IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO XXX width: dw 1920 height: dw 1080 bpp: db 32 diff --git a/src/stage3.c b/src/stage3.c index bedd81d..1d0dd9a 100644 --- a/src/stage3.c +++ b/src/stage3.c @@ -6,6 +6,8 @@ #include #include +void bigError(); + __attribute__ ((section("entry"))) void main() { // Physical memory manager setup @@ -27,22 +29,29 @@ void main() { deinitMemoryRegion(MEMMAP_AREA, maxBlocks / BLOCKS_PER_BYTE); // Load root dir, find kernel INode and parse it - superblock_t* superblock = (superblock_t*)SUPERBLOCK_LOC; - superblock->rootInodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t); - diskRead(superblock->dataStart * 8, 8, (void*)SCRATCH_BLOCK_LOC); + superblock_t* sb = (superblock_t*)SUPERBLOCK_LOC; + sb->rootInodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t); + inode_t* root = (inode_t*)sb->rootInodePtr; + diskRead(root->extent[0].block * 8, root->extent[0].length * 8, (void*)SCRATCH_BLOCK_LOC); inode_t* inode; if ((inode = getInode("kernel.bin")) == NULL) { - __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef)); + // kernel.bin doesn't exist??? very bad -> error + bigError(0xDEAD); } else { loadFile(inode, (void*)KERNEL_LOC); } - if ((inode = getInode("term16n.fnt")) == NULL) { - __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef)); - } else { loadFile(inode, (void*)FONT_LOC); } + if ((inode = getInode("term16n.fnt")) != NULL) { + loadFile(inode, (void*)FONT_LOC); + } else if ((inode = getInode("testfont.fnt")) != NULL) { + loadFile(inode, (void*)FONT_LOC); + } else { + // No font found, bad. + bigError(0xBeef); + } // Virtual memory manager setup if (setupVirtualMemoryManager() != 0) { - while (1); + bigError(0xCafe); } // Identity map VBE framebuffer @@ -67,5 +76,64 @@ void main() { // Call/jump to kernel ((void(*)(void))0xC0000000)(); + bigError(0xffffffff); +} + +void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { + uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; + uint8_t bytesPerPx = gfxMode->bpp / 8; + uint32_t convColor = convertColor(c); + + for (uint32_t dx = 0; dx < w; dx++) { + for (uint32_t dy = 0; dy < h; dy++) { + uint32_t offset = (((y + dy) * gfxMode->xRes) + (x + dx)) * bytesPerPx; + + for (uint8_t i = 0; i < gfxMode->bpp; i++) { + vidmem[offset + i] = (uint8_t)(convColor >> (i*8)); + } + } + } +} + +/* + * Something went VERY wrong. + * Eg. kernel.bin is missing, no filesystem, Virtual Memory failed, etc. + */ +void bigError(uint32_t err) { + // Red BG + rect(0x00ff0000, 0, 0, gfxMode->xRes, gfxMode->yRes); + // E + rect(0x00ffffff, 20, 10, 10, 50); + rect(0x00ffffff, 30, 10, 30, 10); + rect(0x00ffffff, 30, 30, 30, 10); + rect(0x00ffffff, 30, 50, 30, 10); + // R + rect(0x00ffffff, 70, 10, 10, 50); + rect(0x00ffffff, 70, 10, 30, 10); + rect(0x00ffffff, 70, 30, 30, 10); + rect(0x00ffffff, 90, 10, 10, 30); + rect(0x00ffffff, 80, 40, 10, 10); + rect(0x00ffffff, 90, 50, 10, 10); + // R + rect(0x00ffffff, 110, 10, 10, 50); + rect(0x00ffffff, 110, 10, 30, 10); + rect(0x00ffffff, 110, 30, 30, 10); + rect(0x00ffffff, 130, 10, 10, 30); + rect(0x00ffffff, 120, 40, 10, 10); + rect(0x00ffffff, 130, 50, 10, 10); + // O + rect(0x00ffffff, 150, 10, 10, 50); + rect(0x00ffffff, 170, 10, 10, 50); + rect(0x00ffffff, 150, 10, 30, 10); + rect(0x00ffffff, 150, 50, 30, 10); + // R + rect(0x00ffffff, 190, 10, 10, 50); + rect(0x00ffffff, 190, 10, 30, 10); + rect(0x00ffffff, 190, 30, 30, 10); + rect(0x00ffffff, 210, 10, 10, 30); + rect(0x00ffffff, 200, 40, 10, 10); + rect(0x00ffffff, 210, 50, 10, 10); + + __asm__ volatile ("cli; hlt" :: "a"(err)); }