Clean: kmain
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
// Kernel entry point
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https//github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
@@ -7,41 +12,13 @@
|
|||||||
#include "../drivers/ata.h"
|
#include "../drivers/ata.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../drivers/framebuffer.h"
|
#include "../drivers/framebuffer.h"
|
||||||
|
#include "kmain.h"
|
||||||
typedef struct {
|
|
||||||
uint32_t type;
|
|
||||||
uint32_t size;
|
|
||||||
uint64_t framebuffer_addr;
|
|
||||||
uint32_t framebuffer_pitch;
|
|
||||||
uint32_t framebuffer_width;
|
|
||||||
uint32_t framebuffer_height;
|
|
||||||
uint8_t framebuffer_bpp;
|
|
||||||
uint8_t framebuffer_type;
|
|
||||||
uint16_t reserved;
|
|
||||||
} multiboot2_tag_framebuffer;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t total_size;
|
|
||||||
uint32_t reserved;
|
|
||||||
uint8_t tags[0];
|
|
||||||
} multiboot2_info;
|
|
||||||
|
|
||||||
unsigned int g_multiboot_info_address;
|
|
||||||
|
|
||||||
uint32_t* framebuffer;
|
|
||||||
int scanline;
|
|
||||||
|
|
||||||
// in characters, not pixels
|
|
||||||
uint32_t VGA_WIDTH;
|
|
||||||
uint32_t VGA_HEIGHT;
|
|
||||||
|
|
||||||
|
|
||||||
void kmain(multiboot2_info *mb_info)
|
void kmain(multiboot2_info *mb_info)
|
||||||
{
|
{
|
||||||
|
|
||||||
multiboot2_tag_framebuffer *fb_info = NULL;
|
multiboot2_tag_framebuffer *fb_info = NULL;
|
||||||
|
|
||||||
uint8_t *tags = mb_info->tags;
|
uint8_t *tags = mb_info->tags;
|
||||||
while (1) {
|
while (1) {
|
||||||
uint32_t tag_type = *((uint32_t*) tags);
|
uint32_t tag_type = *((uint32_t*) tags);
|
||||||
uint32_t tag_size = *((uint32_t*) (tags + 4));
|
uint32_t tag_size = *((uint32_t*) (tags + 4));
|
||||||
@@ -54,61 +31,43 @@ uint8_t *tags = mb_info->tags;
|
|||||||
tags += ((tag_size + 7) & ~7);
|
tags += ((tag_size + 7) & ~7);
|
||||||
}
|
}
|
||||||
|
|
||||||
serial_printf(3, "Framebuffer Address: 0x%x\r", fb_info->framebuffer_addr);
|
serial_printf(3, "Framebuffer Address: 0x%x\r", fb_info->framebuffer_addr);
|
||||||
serial_printf(3, "Framebuffer Width: %u\r\n", fb_info->framebuffer_width);
|
serial_printf(3, "Framebuffer Width: %u\r\n", fb_info->framebuffer_width);
|
||||||
serial_printf(3, "Framebuffer Height: %u\r\n", fb_info->framebuffer_height);
|
serial_printf(3, "Framebuffer Height: %u\r\n", fb_info->framebuffer_height);
|
||||||
serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch);
|
serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch);
|
||||||
serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
|
|
||||||
if (fb_info) {
|
if (fb_info) {
|
||||||
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
||||||
|
|
||||||
uint32_t width = fb_info->framebuffer_width;
|
uint32_t width = fb_info->framebuffer_width;
|
||||||
uint32_t height = fb_info->framebuffer_height;
|
uint32_t height = fb_info->framebuffer_height;
|
||||||
//uint32_t pitch = fb_info->framebuffer_pitch;
|
|
||||||
uint32_t bpp = fb_info->framebuffer_bpp;
|
uint32_t bpp = fb_info->framebuffer_bpp;
|
||||||
|
|
||||||
|
//8x16 font, not padded
|
||||||
//8x16 font, not padded
|
VGA_WIDTH = width/8;
|
||||||
VGA_WIDTH = width/8;
|
VGA_HEIGHT = height/16;
|
||||||
VGA_HEIGHT = height/16;
|
scanline = width * (bpp/8);
|
||||||
|
|
||||||
scanline = width * (bpp/8);
|
|
||||||
|
|
||||||
|
|
||||||
/* TEST print charset
|
|
||||||
int y_offset = 2;
|
|
||||||
for (int i=0; i<512; i++)
|
|
||||||
{
|
|
||||||
if (i%(width/9)==0) y_offset++;
|
|
||||||
draw_char(0+i, 0+i, y_offset, white, black);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
||||||
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
||||||
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
|
init_serial();
|
||||||
init_serial();
|
gdt_install();
|
||||||
gdt_install();
|
idt_install();
|
||||||
idt_install();
|
isr_install();
|
||||||
isr_install();
|
irq_install();
|
||||||
irq_install();
|
__asm__ __volatile__("sti");
|
||||||
__asm__ __volatile__("sti");
|
|
||||||
|
|
||||||
//init_paging();
|
//init_paging();
|
||||||
|
//test_read_sector();
|
||||||
|
//uint32_t *ptr = (uint32_t*)0xA0000000;
|
||||||
|
//uint32_t do_page_fault = *ptr;
|
||||||
|
|
||||||
//test_read_sector();
|
timer_install();
|
||||||
|
keyboard_install();
|
||||||
//uint32_t *ptr = (uint32_t*)0xA0000000;
|
printf("[kernel] spawning shell...\n");
|
||||||
//uint32_t do_page_fault = *ptr;
|
shell_install();
|
||||||
|
|
||||||
timer_install();
|
|
||||||
keyboard_install();
|
|
||||||
printf("[kernel] spawning shell...\n");
|
|
||||||
shell_install();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/kernel/kmain.h
Normal file
36
src/kernel/kmain.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// Kernel entry point header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https//github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#ifndef KMAIN_H
|
||||||
|
#define KMAIN_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t type;
|
||||||
|
uint32_t size;
|
||||||
|
uint64_t framebuffer_addr;
|
||||||
|
uint32_t framebuffer_pitch;
|
||||||
|
uint32_t framebuffer_width;
|
||||||
|
uint32_t framebuffer_height;
|
||||||
|
uint8_t framebuffer_bpp;
|
||||||
|
uint8_t framebuffer_type;
|
||||||
|
uint16_t reserved;
|
||||||
|
} multiboot2_tag_framebuffer;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t total_size;
|
||||||
|
uint32_t reserved;
|
||||||
|
uint8_t tags[0];
|
||||||
|
} multiboot2_info;
|
||||||
|
|
||||||
|
unsigned int g_multiboot_info_address;
|
||||||
|
|
||||||
|
uint32_t* framebuffer;
|
||||||
|
int scanline;
|
||||||
|
|
||||||
|
// in characters, not pixels
|
||||||
|
uint32_t VGA_WIDTH;
|
||||||
|
uint32_t VGA_HEIGHT;
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user