Debug interrupts, allow to show bmp images
This commit is contained in:
parent
717556178c
commit
66f2ca6246
12 changed files with 209 additions and 12 deletions
|
@ -25,6 +25,9 @@ $(EXEC): boot/boot.o $(BOOT_OBJ) $(DRIVERS_OBJ) $(LIBS_OBJ) $(CORE_OBJ) $(RES_OB
|
|||
%.o: %.psf
|
||||
objcopy -I binary -O elf64-x86-64 --prefix-symbol res $^ $@
|
||||
|
||||
%.o: %.bmp
|
||||
objcopy -I binary -O elf64-x86-64 --prefix-symbol res $^ $@
|
||||
|
||||
clean:
|
||||
rm -f $(EXEC)
|
||||
find ./ -name "*.o" -delete
|
||||
|
|
|
@ -69,4 +69,13 @@ char mb2_find_framebuffer(u32* mb2_info_addr, FRAMEBUFFER *fb){
|
|||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char mb2_find_mem(u32* mb2_info_addr, MEM_INFO *mem){
|
||||
u32* addr=mb2_find_tag(mb2_info_addr,4);
|
||||
if(addr){
|
||||
memcpy(addr, mem, sizeof(MEM_INFO));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -19,8 +19,16 @@ typedef struct FRAMEBUFFER {
|
|||
u8 reserved;
|
||||
} __attribute__((packed)) FRAMEBUFFER;
|
||||
|
||||
typedef struct {
|
||||
TAG_HEADER header;
|
||||
u32 mem_lower;
|
||||
u32 mem_upper;
|
||||
} __attribute__((packed)) MEM_INFO;
|
||||
|
||||
|
||||
u32* mb2_find_tag(u32 *mb2_info_addr, char type);
|
||||
char mb2_find_bootloader_name(u32* mb2_info_addr, char *return_name);
|
||||
char mb2_find_new_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size);
|
||||
char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size);
|
||||
char mb2_find_framebuffer(u32* mb2_info_addr, FRAMEBUFFER *fb);
|
||||
char mb2_find_framebuffer(u32* mb2_info_addr, FRAMEBUFFER *fb);
|
||||
char mb2_find_mem(u32* mb2_info_addr, MEM_INFO *mem);
|
|
@ -8,6 +8,7 @@
|
|||
#include "drivers/vgatext.hpp"
|
||||
#include "libs/stdio.hpp"
|
||||
#include "libs/string.hpp"
|
||||
#include "drivers/bmp.hpp"
|
||||
|
||||
u64 kvar_kernel_vma;
|
||||
u64 kvar_stack_pma;
|
||||
|
@ -16,6 +17,8 @@ u64 kvar_bss_start;
|
|||
u64 kvar_bss_end;
|
||||
u64 kvar_terminus_psf_start;
|
||||
u64 kvar_terminus_psf_end;
|
||||
u64 kvar_logo_bmp_start;
|
||||
u64 kvar_logo_bmp_end;
|
||||
|
||||
void (*printk)(char *str,...)=printf;
|
||||
|
||||
|
@ -28,6 +31,8 @@ extern "C" void boucane(u64 mb_info){
|
|||
asm volatile ("movq $__bss_end, %0":"=m"(kvar_bss_end));
|
||||
asm volatile ("movq $res_binary_res_terminus_psf_start, %0":"=m"(kvar_terminus_psf_start));
|
||||
asm volatile ("movq $res_binary_res_terminus_psf_end, %0":"=m"(kvar_terminus_psf_end));
|
||||
asm volatile ("movq $res_binary_res_logo_bmp_start, %0":"=m"(kvar_logo_bmp_start));
|
||||
asm volatile ("movq $res_binary_res_logo_bmp_end, %0":"=m"(kvar_logo_bmp_end));
|
||||
|
||||
// Init data structures
|
||||
asm volatile ("call load_gdt");
|
||||
|
@ -54,9 +59,20 @@ extern "C" void boucane(u64 mb_info){
|
|||
__putchar=vgatext_putchar;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Booting!
|
||||
printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
|
||||
|
||||
char bootloader[20];
|
||||
if(mb2_find_bootloader_name((u32*)mb_info,bootloader)){
|
||||
printk("System informations -- BOOT:%s ", bootloader);
|
||||
}
|
||||
|
||||
MEM_INFO mem_infos;
|
||||
if(mb2_find_mem((u32*)mb_info,&mem_infos)){
|
||||
u64 mem=mem_infos.mem_upper-mem_infos.mem_lower;
|
||||
mem/=1024;
|
||||
printk("RAM:%dMB\n", mem);
|
||||
}
|
||||
while(1);
|
||||
}
|
|
@ -20,6 +20,8 @@ extern u64 kvar_bss_end;
|
|||
/// @brief Binary references
|
||||
extern u64 kvar_terminus_psf_start;
|
||||
extern u64 kvar_terminus_psf_end;
|
||||
extern u64 kvar_logo_bmp_start;
|
||||
extern u64 kvar_logo_bmp_end;
|
||||
|
||||
// ---- Debug
|
||||
#define DUMP(var) asm volatile("push $0xABC; push %0; push $0xABC; _%=:; jmp _%="::"r"(var))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "idt.hpp"
|
||||
#include "boucane.hpp"
|
||||
#include "core/paging.hpp"
|
||||
#include "libs/string.hpp"
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
.macro call_printk msg
|
||||
mov \msg, %rdi
|
||||
mov $0, %eax # Required for variadic functions
|
||||
call printk
|
||||
mov $printk,%rcx
|
||||
call *(%rcx)
|
||||
.endm
|
||||
|
||||
.globl INT_DEFAULT
|
||||
|
|
|
@ -36,7 +36,10 @@ void paging_enable() {
|
|||
|
||||
// Setting up new kernel address space
|
||||
for(u64 i=0;i<=0x10000000;i+=4096){
|
||||
// Higher half mapping
|
||||
PAGE_MAP(i);
|
||||
// Allow access to RAM:
|
||||
paging_allocate_addr(kpages[0], i, i, PAGING_OPT_P|PAGING_OPT_RW, 1);
|
||||
}
|
||||
|
||||
// 4096 bytes stack
|
||||
|
@ -145,32 +148,35 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char
|
|||
|
||||
// Solve pdp
|
||||
if(pml4_table[pml4] == 0){
|
||||
pml4_table[pml4]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pml4_table[pml4]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE());
|
||||
pml4_table[pml4]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve pd
|
||||
u64* pdp_table=(u64*)(VIRT(PAGE(pml4_table[pml4])));
|
||||
u64* pdp_table=(u64*)(PAGE(pml4_table[pml4]));
|
||||
pdp_table=useKernelTables ? VIRT(pdp_table) : pdp_table;
|
||||
if(pdp_table[pdp] == 0){
|
||||
pdp_table[pdp]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pdp_table[pdp]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE());
|
||||
pdp_table[pdp]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve pt
|
||||
u64* pd_table=(u64*)(VIRT(PAGE(pdp_table[pdp])));
|
||||
u64* pd_table=(u64*)(PAGE(pdp_table[pdp]));
|
||||
pd_table=useKernelTables ? VIRT(pd_table) : pd_table;
|
||||
if(pd_table[pd] == 0){
|
||||
pd_table[pd]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pd_table[pd]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE());
|
||||
pd_table[pd]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve address
|
||||
u64* pt_table=(u64*)(VIRT(PAGE(pd_table[pd])));
|
||||
u64* pt_table=(u64*)(PAGE(pd_table[pd]));
|
||||
pt_table=useKernelTables ? VIRT(pt_table) : pt_table;
|
||||
if(pt_table[pt] == 0){
|
||||
pt_table[pt]=PAGE(phy);
|
||||
pt_table[pt]|=options;
|
||||
|
@ -180,8 +186,7 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char
|
|||
}
|
||||
|
||||
u64* paging_create_task(int npages){
|
||||
u64 *pml4=VIRT(PAGE_ALLOCATE());
|
||||
u64 sum=(u64)pml4+kvar_kernel_vma;
|
||||
paging_allocate_addr(pml4, 0, (u64)PAGE_ALLOCATE(), PAGING_OPT_P|PAGING_OPT_RW, 0);
|
||||
u64 *pml4=PAGE_ALLOCATE();
|
||||
// paging_allocate_addr(pml4, 0, (u64)PAGE_ALLOCATE(), PAGING_OPT_P|PAGING_OPT_RW, 0);
|
||||
return pml4;
|
||||
}
|
39
src/drivers/bmp.cc
Normal file
39
src/drivers/bmp.cc
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "bmp.hpp"
|
||||
#include "libs/string.hpp"
|
||||
|
||||
#include "drivers/framebuffer.hpp"
|
||||
|
||||
void bmp_draw(u8* bmp_data, int posx, int posy){
|
||||
BMP_HEADER header;
|
||||
memcpy(bmp_data, &header, sizeof(BMP_HEADER));
|
||||
if(header.signature!=0x4d42){
|
||||
printk("Invalid BMP data\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not forget, each row is 32bits aligned
|
||||
u32 Bpp=header.bpp/8;
|
||||
u32 lineW=header.width*Bpp;
|
||||
while((lineW&0x3)!=0){
|
||||
lineW++;
|
||||
}
|
||||
|
||||
for(u32 y=0;y<header.height;y++){
|
||||
for(u32 x=0;x<header.width;x++){
|
||||
u32 pos=x*Bpp+y*lineW;
|
||||
u8 *pixel=((u8*)bmp_data)+header.data_offset+pos;
|
||||
FB_PIXEL p;
|
||||
p.x=posx+x;
|
||||
p.y=posy+(header.height-y);
|
||||
p.r=pixel[0];
|
||||
p.g=pixel[1];
|
||||
p.b=pixel[2];
|
||||
//printk("R%d G%d B%d\n",p.r,p.g,p.b);
|
||||
p.a=0;
|
||||
framebuffer_draw(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
18
src/drivers/bmp.hpp
Normal file
18
src/drivers/bmp.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "boucane.hpp"
|
||||
|
||||
typedef struct {
|
||||
u16 signature;
|
||||
u32 filesize;
|
||||
u32 reserved;
|
||||
u32 data_offset;
|
||||
u32 info_header_size;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u16 planes;
|
||||
u16 bpp;
|
||||
u32 compression;
|
||||
} __attribute__((packed)) BMP_HEADER;
|
||||
|
||||
void bmp_draw(u8* bmp_data, int x, int y);
|
BIN
src/res/logo.bmp
Normal file
BIN
src/res/logo.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 356 KiB |
Loading…
Add table
Add a link
Reference in a new issue