Debug, add memory print driver
This commit is contained in:
parent
067d6e340b
commit
fde8a1ab65
17 changed files with 108 additions and 36 deletions
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/types.hpp"
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
typedef struct TAG_HEADER {
|
||||
u32 type;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
#include "boucane.hpp"
|
||||
#include "core/paging.hpp"
|
||||
#include "drivers/memtext.hpp"
|
||||
#include "core/idt.hpp"
|
||||
#include "boot/multiboot2.hpp"
|
||||
#include "drivers/framebuffer.hpp"
|
||||
#include "drivers/psf.hpp"
|
||||
#include "drivers/psftext.hpp"
|
||||
#include "drivers/vgatext.hpp"
|
||||
#include "libs/stdio.hpp"
|
||||
#include "libs/string.hpp"
|
||||
|
||||
u64 kvar_kernel_vma;
|
||||
|
@ -13,6 +17,8 @@ u64 kvar_bss_end;
|
|||
u64 kvar_terminus_psf_start;
|
||||
u64 kvar_terminus_psf_end;
|
||||
|
||||
void (*printk)(char *str,...)=printf;
|
||||
|
||||
extern "C" void boucane(u64 mb_info){
|
||||
// Init linker variables
|
||||
asm volatile ("movq $__kernel_vma, %0":"=m"(kvar_kernel_vma));
|
||||
|
@ -26,11 +32,10 @@ extern "C" void boucane(u64 mb_info){
|
|||
// Init data structures
|
||||
asm volatile ("call load_gdt");
|
||||
paging_enable();
|
||||
memtext_init();
|
||||
idt_enable_interrupt();
|
||||
|
||||
|
||||
// Looking for framebuffer
|
||||
vga_t_init();
|
||||
vga_t_clear();
|
||||
FRAMEBUFFER fb_info;
|
||||
if(mb2_find_framebuffer((u32*)mb_info, &fb_info)){
|
||||
if(fb_info.bpp>16){
|
||||
|
@ -41,8 +46,12 @@ extern "C" void boucane(u64 mb_info){
|
|||
conf.width=fb_info.width;
|
||||
conf.height=fb_info.height;
|
||||
framebuffer_init(conf);
|
||||
psf_init((void*)kvar_terminus_psf_start);
|
||||
__putchar=psf_putchar;
|
||||
psftext_init((void*)kvar_terminus_psf_start);
|
||||
__putchar=psftext_putchar;
|
||||
}
|
||||
else{
|
||||
vgatext_init();
|
||||
__putchar=vgatext_putchar;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,3 +24,6 @@ extern u64 kvar_terminus_psf_end;
|
|||
// ---- Debug
|
||||
#define DUMP(var) asm volatile("push $0xABC; push %0; push $0xABC; _%=:; jmp _%="::"r"(var))
|
||||
#define DUMP2(var1,var2) asm volatile("push $0xABC; push %0; push %1; push $0xABC; _%=:; jmp _%="::"a"(var1),"b"(var2))
|
||||
|
||||
|
||||
extern void (*printk)(char *str,...);
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
void apic_enable();
|
|
@ -83,7 +83,7 @@ u64* paging_allocate_contiguous(int npages){
|
|||
}
|
||||
}
|
||||
|
||||
printk("Could not allocate %d contigous pages. Kernel panic!",npages);
|
||||
printk("Could not allocate %d contiguous pages. Kernel panic!",npages);
|
||||
while(1);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,19 @@
|
|||
paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma); \
|
||||
}}
|
||||
|
||||
|
||||
#define PAGING_MAP2(addr,phy) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(phy),PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma)
|
||||
#define PAGING_MAP2_RANGE(addr, phy, n) { \
|
||||
for(u64 i=0;i<(n);i++){ \
|
||||
paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(phy))+i,PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma); \
|
||||
}}
|
||||
|
||||
/// @brief All PAE table structures are allocated here
|
||||
extern u64 kpages[MAX_TABLES][512];
|
||||
|
||||
/// CF boucane.hpp
|
||||
extern u64 kvar_kernel_vma,kvar_stack_pma,kvar_userspace_pma;
|
||||
extern void (*printk)(char *str,...);
|
||||
|
||||
/**
|
||||
* Setup and enable PAE paging
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
#define ACPI_RSDP_SIGNATURE 0x2052545020445352
|
||||
#define ACPI_RSDT_SIGNATURE 0x54445352
|
||||
|
|
|
@ -22,7 +22,7 @@ void framebuffer_draw(FB_PIXEL p){
|
|||
void framebuffer_scrollup(u32 npixel){
|
||||
u64 start=fb_cfg.location+npixel*fb_cfg.pitch;
|
||||
u64 amount=fb_cfg.pitch*(fb_cfg.height-npixel);
|
||||
memcpy((void*)start,(void*)fb_cfg.location,amount);
|
||||
memcpy((void*)start,(void*)fb_cfg.location,amount); // TODO change because page fault can occurs
|
||||
}
|
||||
|
||||
void framebuffer_clear(){
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
typedef struct {
|
||||
u32 pitch;
|
||||
|
|
41
src/drivers/memtext.cc
Normal file
41
src/drivers/memtext.cc
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "memtext.hpp"
|
||||
#include "core/paging.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "libs/string.hpp"
|
||||
|
||||
|
||||
|
||||
char memtext_buffer[MEMTEXT_BUFFER_SIZE];
|
||||
u64 memtext_x=0;
|
||||
|
||||
void memtext_init(){
|
||||
PAGING_MAP2_RANGE(MEMTEXT_ADDR_LOCATION,0x0,8);
|
||||
u64* p_addr=(u64*)MEMTEXT_ADDR_LOCATION;
|
||||
*p_addr=(u64)memtext_buffer;
|
||||
|
||||
// Cleaning buffer
|
||||
for(memtext_x=0;memtext_x<MEMTEXT_BUFFER_SIZE;memtext_x++)
|
||||
memtext_buffer[memtext_x]=0;
|
||||
memtext_x=0;
|
||||
}
|
||||
|
||||
void memtext_putchar(char c){
|
||||
|
||||
if(memtext_x>=MEMTEXT_BUFFER_SIZE){
|
||||
memtext_scrollup(1);
|
||||
memtext_buffer[memtext_x-1]=c;
|
||||
return;
|
||||
}
|
||||
memtext_buffer[memtext_x]=c;
|
||||
memtext_x++;
|
||||
}
|
||||
|
||||
void memtext_scrollup(u32 n){
|
||||
u64 start=(u64)memtext_buffer;
|
||||
for(u64 i=0;i<MEMTEXT_BUFFER_SIZE;i++){
|
||||
if(i+n<MEMTEXT_BUFFER_SIZE)
|
||||
memtext_buffer[i]=memtext_buffer[i+n];
|
||||
else
|
||||
memtext_buffer[i]=0;
|
||||
}
|
||||
}
|
11
src/drivers/memtext.hpp
Normal file
11
src/drivers/memtext.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "boucane.hpp"
|
||||
|
||||
#define MEMTEXT_BUFFER_SIZE 1024
|
||||
#define MEMTEXT_ADDR_LOCATION 0x0
|
||||
|
||||
|
||||
void memtext_init();
|
||||
void memtext_putchar(char c);
|
||||
void memtext_scrollup(u32 n);
|
|
@ -1,11 +1,11 @@
|
|||
#include "psf.hpp"
|
||||
#include "psftext.hpp"
|
||||
#include "core/paging.hpp"
|
||||
#include "libs/string.hpp"
|
||||
#include "drivers/framebuffer.hpp"
|
||||
|
||||
PSF_STATUS psf_status;
|
||||
|
||||
void psf_init(void* psf_addr){
|
||||
void psftext_init(void* psf_addr){
|
||||
printk("Loading PSF font... ");
|
||||
memcpy(psf_addr, &psf_status.header, sizeof(PSF_HEADER));
|
||||
if(psf_status.header.magic!=PSF_MAGIC){
|
||||
|
@ -26,7 +26,7 @@ void psf_init(void* psf_addr){
|
|||
print("\n");
|
||||
}
|
||||
|
||||
void psf_putchar(char c){
|
||||
void psftext_putchar(char c){
|
||||
if(c=='\n'){
|
||||
psf_status.y++;
|
||||
psf_status.x=0;
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
#define PSF_MAGIC 0x864ab572
|
||||
|
||||
|
@ -27,5 +27,5 @@ typedef struct PSF_STATUS {
|
|||
|
||||
extern PSF_HEADER psf_header;
|
||||
|
||||
void psf_init(void* psf_addr);
|
||||
void psf_putchar(char c);
|
||||
void psftext_init(void* psf_addr);
|
||||
void psftext_putchar(char c);
|
|
@ -1,6 +1,6 @@
|
|||
#include "vga_t.hpp"
|
||||
#include "vgatext.hpp"
|
||||
|
||||
#include "include/boucane.hpp"
|
||||
#include "boucane.hpp"
|
||||
|
||||
#define MAX_COL 80
|
||||
#define MAX_LINE 25
|
||||
|
@ -13,19 +13,19 @@ VIDEO_STATE VS={
|
|||
GRAY,
|
||||
};
|
||||
|
||||
void vga_t_init(){
|
||||
void vgatext_init(){
|
||||
PAGING_MAP(0xB8000);
|
||||
PAGING_MAP(0xB8000+4096);
|
||||
}
|
||||
|
||||
void vga_t_putchar(char c){
|
||||
void vgatext_putchar(char c){
|
||||
// Handle newline here
|
||||
if(c=='\n'){
|
||||
VS.col=0;
|
||||
VS.line+=1;
|
||||
if(VS.line>=MAX_LINE){
|
||||
VS.line=MAX_LINE-1;
|
||||
vga_t_scrollup();
|
||||
vgatext_scrollup();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -41,18 +41,18 @@ void vga_t_putchar(char c){
|
|||
VS.line+=1;
|
||||
if(VS.line>=MAX_LINE){
|
||||
VS.line=MAX_LINE-1;
|
||||
vga_t_scrollup();
|
||||
vgatext_scrollup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vga_t_clear(){
|
||||
void vgatext_clear(){
|
||||
for(u8 i=0;i<MAX_LINE;i++){
|
||||
vga_t_scrollup();
|
||||
vgatext_scrollup();
|
||||
}
|
||||
}
|
||||
|
||||
void vga_t_scrollup(){
|
||||
void vgatext_scrollup(){
|
||||
// Move VS.line up
|
||||
for(u8 i=1;i<=MAX_LINE;i++){
|
||||
for(u8 j=0;j<=MAX_COL;j++)
|
|
@ -16,20 +16,20 @@ typedef struct VIDEO_STATE {
|
|||
u8 fg;
|
||||
} VIDEO_STATE;
|
||||
|
||||
void vga_t_init();
|
||||
void vgatext_init();
|
||||
|
||||
/**
|
||||
* Print char
|
||||
*/
|
||||
void vga_t_putchar(char);
|
||||
void vgatext_putchar(char);
|
||||
|
||||
/**
|
||||
* Scroll the framebuffer from one line
|
||||
*/
|
||||
void vga_t_scrollup();
|
||||
void vgatext_scrollup();
|
||||
|
||||
/**
|
||||
* Clear all char from the framebuffer
|
||||
*/
|
||||
void vga_t_clear();
|
||||
void vgatext_clear();
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#include "stdio.hpp"
|
||||
#include "drivers/vga_t.hpp"
|
||||
#include "drivers/memtext.hpp"
|
||||
#include "math.hpp"
|
||||
#include "string.hpp"
|
||||
|
||||
void (*__putchar)(char)=vga_t_putchar;
|
||||
void (*__putchar)(char)=memtext_putchar;
|
||||
|
||||
void printk(char *str,...) {
|
||||
void printf(char *str,...) {
|
||||
u64 rsi,rdx,rcx,r8,r9;
|
||||
u64* rbp;
|
||||
asm( "mov %%rsi, %0": "=a"(rsi));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "drivers/vga_t.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
/// @brief Current active framebuffer driver
|
||||
extern void (*__putchar)(char);
|
||||
|
@ -8,7 +8,7 @@ extern void (*__putchar)(char);
|
|||
/**
|
||||
* Print a char* in the framebuffer
|
||||
*/
|
||||
extern "C" void printk(char *,...);
|
||||
extern "C" void printf(char *,...);
|
||||
|
||||
/**
|
||||
* Print a char*
|
||||
|
|
Loading…
Add table
Reference in a new issue