aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-29 15:01:54 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-29 15:01:54 +0200
commitf37f5d86b74870e878f69bd41a3c70a59c4ce1c1 (patch)
tree65620f0504fea111ba870457f32bc072dc27fe7a
parentfde8a1ab65d5e33d90123a3aaa9b5c15e249689f (diff)
Debug memory
-rw-r--r--src/boot/multiboot2.cc15
-rw-r--r--src/boot/multiboot2.hpp2
-rw-r--r--src/boucane.cc5
-rw-r--r--src/core/paging.cc38
-rw-r--r--src/core/paging.hpp51
-rw-r--r--src/drivers/acpi.cc4
-rw-r--r--src/drivers/framebuffer.cc38
-rw-r--r--src/drivers/memtext.cc5
-rw-r--r--src/drivers/memtext.hpp2
-rw-r--r--src/drivers/psftext.cc8
-rw-r--r--src/drivers/vgatext.cc6
-rw-r--r--tools/bochsrc1
12 files changed, 98 insertions, 77 deletions
diff --git a/src/boot/multiboot2.cc b/src/boot/multiboot2.cc
index bac1adb..da247ad 100644
--- a/src/boot/multiboot2.cc
+++ b/src/boot/multiboot2.cc
@@ -4,13 +4,12 @@
#include "libs/stdio.hpp"
u32* mb2_find_tag(u32 *mb2_info_addr, char type){
- PAGING_MAP(mb2_info_addr);
- u32 size=(u32)mb2_info_addr[0]; // Todo: check for size
- for(u64 i=0;i<size/8;i++)
- PAGING_MAP(mb2_info_addr+i*4096);
+ PAGE_MAP(mb2_info_addr);
+ u32 size=(u32)VIRT(mb2_info_addr)[0]; // Todo: check for size
+ PAGE_RMAP(mb2_info_addr, size);
- char *location=((char*)mb2_info_addr)+8; // Goto first tag
- char *start=(char*)mb2_info_addr;
+ char *location=((char*)VIRT(mb2_info_addr))+8; // Goto first tag
+ char *start=(char*)VIRT(mb2_info_addr);
while((location-start) < size){
// Goto next 64bit align address
@@ -23,6 +22,10 @@ u32* mb2_find_tag(u32 *mb2_info_addr, char type){
if(cur_type==type){
return (u32*)location;
}
+ if(type > 30){
+ printk("Strange multiboot infos structure...\n");
+ return 0;
+ }
location+=cur_size;
}
diff --git a/src/boot/multiboot2.hpp b/src/boot/multiboot2.hpp
index d36d593..f340269 100644
--- a/src/boot/multiboot2.hpp
+++ b/src/boot/multiboot2.hpp
@@ -16,7 +16,7 @@ typedef struct FRAMEBUFFER {
u32 height;
u8 bpp;
u8 type;
- u64 color_info_addr;
+ u8 reserved;
} __attribute__((packed)) FRAMEBUFFER;
u32* mb2_find_tag(u32 *mb2_info_addr, char type);
diff --git a/src/boucane.cc b/src/boucane.cc
index 5823a15..a333e9c 100644
--- a/src/boucane.cc
+++ b/src/boucane.cc
@@ -34,7 +34,7 @@ extern "C" void boucane(u64 mb_info){
paging_enable();
memtext_init();
idt_enable_interrupt();
-
+
// Looking for framebuffer
FRAMEBUFFER fb_info;
if(mb2_find_framebuffer((u32*)mb_info, &fb_info)){
@@ -57,6 +57,7 @@ extern "C" void boucane(u64 mb_info){
// Booting!
printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
-
+
+
while(1);
} \ No newline at end of file
diff --git a/src/core/paging.cc b/src/core/paging.cc
index c283c57..7ae1b25 100644
--- a/src/core/paging.cc
+++ b/src/core/paging.cc
@@ -11,11 +11,14 @@ u64* paging_allocate_table(){
u64 addr=(u64)kpages[kpages_next];
u64* allocated=(u64*)(addr-kvar_kernel_vma);
kpages_next++;
+ if(kpages_next>=PAGING_MAX_PAGE){
+ printk("Could not allocate more page structures. Kernel Panic!");
+ while(1);
+ }
return allocated;
}
void paging_enable() {
-
// Init status
for (int i = 0; i < PAGING_MAX_PAGE / 8; i++) {
paging_status[i] = 0;
@@ -33,10 +36,11 @@ void paging_enable() {
// Setting up new kernel address space
for(u64 i=0;i<=0x10000000;i+=4096){
- paging_allocate_addr(kpages[0],kvar_kernel_vma+i,i, 0x3,0); // Identity map
+ PAGE_MAP(i);
}
+
// 4096 bytes stack
- paging_allocate_addr(kpages[0],kvar_kernel_vma-4096,kvar_stack_pma,0x3,0);
+ PAGE_MAP_PHY(-4096, kvar_stack_pma);
// Load new pml4
u64 kpage_phy=((u64)kpages[0]-kvar_kernel_vma);
@@ -46,18 +50,6 @@ void paging_enable() {
:: "r" (kpage_phy));
}
-u64 paging_as_phy(u64* pml4_table, u64 virt){
- u16 pml4=virt>>39&0x1FF;
- u16 pdp=virt>>30&0x1FF;
- u16 pd=virt>>21&0x1FF;
- u16 pt=(virt>>12)&0x1FF;
-
- u64* pdp_table=(u64*)PAGE(pml4_table[pml4]);
- u64* pd_table=(u64*)PAGE(pdp_table[pdp]);
- u64* pt_table=(u64*)PAGE(pd_table[pd]);
- return((PAGE(pt_table[pt]))|(virt&0xFFF));
-}
-
u64* paging_allocate_contiguous(int npages){
int n_contiguous=0;
for (int i = 0; i < PAGING_MAX_PAGE / 8; i++) {
@@ -94,6 +86,8 @@ void paging_deallocate(u64 addr){
paging_status[page_number/8]=byte&(~(1<<(page_number%8)));
}
+
+/// TODO: Debug addess
void paging_deallocate_pml4(u64* pml4){
for(int i=0;i<512;i++){
u64* pdp=(u64*)PAGE(pml4[i]);
@@ -142,7 +136,7 @@ void paging_deallocate_table(u64* table){
}
}
-void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, u64 offset){
+void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
u16 pml4=virt>>39&0x1FF;
u16 pdp=virt>>30&0x1FF;
u16 pd=virt>>21&0x1FF;
@@ -153,29 +147,29 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, u64 o
if(pml4_table[pml4] == 0){
pml4_table[pml4]=(u64)paging_allocate_table();
pml4_table[pml4]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options,offset);
+ paging_allocate_addr(pml4_table,virt,phy,options);
return;
}
// Solve pd
- u64* pdp_table=(u64*)(PAGE(pml4_table[pml4])+offset);
+ u64* pdp_table=(u64*)(VIRT(PAGE(pml4_table[pml4])));
if(pdp_table[pdp] == 0){
pdp_table[pdp]=(u64)paging_allocate_table();
pdp_table[pdp]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options,offset);
+ paging_allocate_addr(pml4_table,virt,phy,options);
return;
}
// Solve pt
- u64* pd_table=(u64*)(PAGE(pdp_table[pdp])+offset);
+ u64* pd_table=(u64*)(VIRT(PAGE(pdp_table[pdp])));
if(pd_table[pd] == 0){
pd_table[pd]=(u64)paging_allocate_table();
pd_table[pd]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options,offset);
+ paging_allocate_addr(pml4_table,virt,phy,options);
return;
}
// Solve address
- u64* pt_table=(u64*)(PAGE(pd_table[pd])+offset);
+ u64* pt_table=(u64*)(VIRT(PAGE(pd_table[pd])));
if(pt_table[pt] == 0){
pt_table[pt]=PAGE(phy);
pt_table[pt]|=options;
diff --git a/src/core/paging.hpp b/src/core/paging.hpp
index a3c2fec..1aae24a 100644
--- a/src/core/paging.hpp
+++ b/src/core/paging.hpp
@@ -2,34 +2,40 @@
#include "core/types.hpp"
-#define MAX_TABLES 280
-#define PAGING_MAX_PAGE (20*512)
/**
* Current number of page (from the beginning of the ram) used by the kernel that
* should not be used by the paging allocation mechanism and should not be granted
* for allocation
*/
-#define PAGING_KERNEL_USED_PAGE (2*512)
/// @brief New number of page reachable at the end of the paging_enable() call
-#define PAGING_KERNEL_SPACE_MAX_PAGE (20*512)
-#define PAGING_ALLOCATE() paging_allocate_contiguous(1)
+#define MAX_TABLES 280
+#define PAGING_MAX_PAGE (20*512)
+#define PAGE_ALLOCATE() paging_allocate_contiguous(1)
+
+/// @brief Options
#define PAGING_OPT_P 1
#define PAGING_OPT_RW (1<<1)
#define PAGING_OPT_PCD (1<<3)
/// @brief Get page address that contain addr
#define PAGE(addr) (addr&(~(0xFFF)))
-#define PAGING_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma)
-#define PAGING_MAP_RANGE(addr, n) { \
- for(u64 i=0;i<(n);i++){ \
- paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma); \
-}}
+#define VIRT(addr) (addr+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 Mapping facilities
+#define PAGE_ID_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW)
+#define PAGE_ID_RMAP(addr, n) { \
+ for(u64 i=0;i<(n);i+=4096){ \
+ paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW); \
+}}
+#define PAGE_MAP(addr) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW)
+#define PAGE_RMAP(addr, n) { \
+ for(u64 i=0;i<(n);i+=4096){ \
+ paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW); \
+}}
+#define PAGE_MAP_PHY(addr,phy) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(phy),PAGING_OPT_P|PAGING_OPT_RW)
+#define PAGE_RMAP_PHY(addr,phy, n) { \
+ for(u64 i=0;i<(n);i+=4096){ \
+ paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(phy))+i,PAGING_OPT_P|PAGING_OPT_RW); \
}}
/// @brief All PAE table structures are allocated here
@@ -71,20 +77,7 @@ void paging_deallocate_pml4(u64* pml4);
void paging_deallocate_table(u64* table);
/**
- * Allocate table structure (pml4, pdp etc..)
- */
-u64* paging_allocate_table_local();
-
-/**
* Map virtual page associated to virt
* to the physical page associated with phy
- * Offset can be used to convert pml4_table address
- * content to virtual addresses (since physical addresses from the pml4_table are not
- * available after the trampoline into High-Half memory)
- */
-void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options, u64 offset);
-
-/**
- * Get associated physical address
*/
-u64 paging_as_phy(u64* pml4_table, u64 virt); \ No newline at end of file
+void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options);
diff --git a/src/drivers/acpi.cc b/src/drivers/acpi.cc
index 9c25202..ec7a2ff 100644
--- a/src/drivers/acpi.cc
+++ b/src/drivers/acpi.cc
@@ -32,7 +32,7 @@ char acpi_init(void* rsdp_p){
}
char acpi_load_rsdt(){
- PAGING_MAP(rsdp.rsdt_addr); // Ensure page is accessible
+ PAGE_ID_MAP(rsdp.rsdt_addr); // Ensure page is accessible
memcpy((void*)rsdp.rsdt_addr, &rsdt, sizeof(rsdt));
rsdt.first_entry_addr_ptr=rsdp.rsdt_addr+36;
if(rsdt.header.signature !=ACPI_RSDT_SIGNATURE){
@@ -54,7 +54,7 @@ char acpi_load_madt(){
u32 *addr=(u32*)(rsdt.first_entry_addr_ptr+i*4);
// Load header
ACPI_TABLE_HEADER header;
- PAGING_MAP(*addr);
+ PAGE_ID_MAP(*addr);
memcpy((void*)*addr, &header, sizeof(header));
// Check if it is MADT
if(header.signature==ACPI_MADT_SIGNATURE){
diff --git a/src/drivers/framebuffer.cc b/src/drivers/framebuffer.cc
index 9f90d84..f5b537b 100644
--- a/src/drivers/framebuffer.cc
+++ b/src/drivers/framebuffer.cc
@@ -7,10 +7,25 @@ FB_CFG fb_cfg;
void framebuffer_init(FB_CFG config){
fb_cfg=config;
- PAGING_MAP_RANGE(fb_cfg.location, fb_cfg.pitch*fb_cfg.height);
+ // Map buffer to the end of the memory
+ // indeed fb_cfg.location could be to big and
+ // thus leading to cross u64 size limit while summing it with
+ // kvar_kernel_vma in paging.cc/hpp
+ u64 start=0xFFFFFFFFFFFFFFFF - fb_cfg.pitch*fb_cfg.height;
+ // Ensure we start writing at the begining of the page since
+ // start is not necessarly 4096 bytes aligned
+ start=PAGE(start);
+ PAGE_RMAP_PHY(start-kvar_kernel_vma,fb_cfg.location, fb_cfg.pitch*fb_cfg.height);
+ fb_cfg.location=start;
}
void framebuffer_draw(FB_PIXEL p){
+ // Check overflow
+ p.x=p.x>(fb_cfg.width)?fb_cfg.width:p.x;
+ p.y=p.y>(fb_cfg.width)?fb_cfg.width:p.y;
+ p.x=p.x<0?0:p.x;
+ p.y=p.y<0?0:p.y;
+
u8 *pixel=(u8*)(fb_cfg.location+p.x*(fb_cfg.depth/8)+p.y*fb_cfg.pitch);
pixel[0]=p.r;
pixel[1]=p.g;
@@ -20,11 +35,24 @@ 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); // TODO change because page fault can occurs
+ for(u32 y=0;y<fb_cfg.height;y++){
+ if(npixel<fb_cfg.height){
+ for(u32 x=0;x<fb_cfg.width;x++){
+ u32 *pixel_dst=(u32*)(fb_cfg.location+x*(fb_cfg.depth/8)+y*fb_cfg.pitch);
+ u32 *pixel_src=(u32*)(fb_cfg.location+x*(fb_cfg.depth/8)+npixel*fb_cfg.pitch);
+ *pixel_dst=*pixel_src; // Faster than writing pixel by pixel
+ }
+ }
+ else{
+ for(u32 x=0;x<fb_cfg.width;x++){
+ u8 *pixel_dst=(u8*)(fb_cfg.location+x*(fb_cfg.depth/8)+y*fb_cfg.pitch);
+ *pixel_dst=0;// Faster than writing pixel by pixel
+ }
+ }
+ npixel++;
+ }
}
void framebuffer_clear(){
- memset((void*)fb_cfg.location, 0, fb_cfg.pitch*fb_cfg.height);
+ // memset((void*)fb_cfg.location, 0, fb_cfg.pitch*fb_cfg.height-1000);
} \ No newline at end of file
diff --git a/src/drivers/memtext.cc b/src/drivers/memtext.cc
index b5371b1..f010271 100644
--- a/src/drivers/memtext.cc
+++ b/src/drivers/memtext.cc
@@ -4,13 +4,12 @@
#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;
+ PAGE_RMAP(MEMTEXT_ADDR_LOCATION,8);
+ u64* p_addr=(u64*)VIRT(MEMTEXT_ADDR_LOCATION);
*p_addr=(u64)memtext_buffer;
// Cleaning buffer
diff --git a/src/drivers/memtext.hpp b/src/drivers/memtext.hpp
index 18b3014..c61c93d 100644
--- a/src/drivers/memtext.hpp
+++ b/src/drivers/memtext.hpp
@@ -2,7 +2,7 @@
#include "boucane.hpp"
-#define MEMTEXT_BUFFER_SIZE 1024
+#define MEMTEXT_BUFFER_SIZE 4096
#define MEMTEXT_ADDR_LOCATION 0x0
diff --git a/src/drivers/psftext.cc b/src/drivers/psftext.cc
index da7e8c9..1df4dd3 100644
--- a/src/drivers/psftext.cc
+++ b/src/drivers/psftext.cc
@@ -30,8 +30,10 @@ void psftext_putchar(char c){
if(c=='\n'){
psf_status.y++;
psf_status.x=0;
- if(psf_status.y>psf_status.nline)
+ if(psf_status.y>=psf_status.nline){
framebuffer_scrollup(psf_status.header.glyph_height);
+ psf_status.y--;
+ }
return;
}
@@ -60,7 +62,9 @@ void psftext_putchar(char c){
if(psf_status.x>psf_status.nchar){
psf_status.y++;
psf_status.x=0;
- if(psf_status.y>psf_status.nline)
+ if(psf_status.y>=psf_status.nline){
framebuffer_scrollup(psf_status.header.glyph_height);
+ psf_status.y--;
+ }
}
} \ No newline at end of file
diff --git a/src/drivers/vgatext.cc b/src/drivers/vgatext.cc
index be01f0e..6a5a1b2 100644
--- a/src/drivers/vgatext.cc
+++ b/src/drivers/vgatext.cc
@@ -6,7 +6,7 @@
#define MAX_LINE 25
VIDEO_STATE VS={
- (u8 *)0xB8000,
+ (u8 *)0,
0,
0,
BLACK,
@@ -14,8 +14,8 @@ VIDEO_STATE VS={
};
void vgatext_init(){
- PAGING_MAP(0xB8000);
- PAGING_MAP(0xB8000+4096);
+ PAGE_RMAP(0xB8000,4096*2);
+ VS.mem=(u8*)VIRT(0xB8000);
}
void vgatext_putchar(char c){
diff --git a/tools/bochsrc b/tools/bochsrc
index e73dc72..f4bfc41 100644
--- a/tools/bochsrc
+++ b/tools/bochsrc
@@ -1,4 +1,3 @@
romimage: file=$BXSHARE/BIOS-bochs-latest, options=fastboot
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
-cpu: count=1, ips=10000000, reset_on_triple_fault=0