Enable .bss zeroing and improve paging
This commit is contained in:
parent
457a211770
commit
5a9a57177f
7 changed files with 135 additions and 19 deletions
|
@ -3,6 +3,8 @@
|
|||
.extern bringelle
|
||||
.extern gdt_memcpy
|
||||
.extern mb_load_fb_tag
|
||||
.extern _bss_start
|
||||
.extern _bss_end
|
||||
|
||||
.set STACK_LOCATION, 0x1FFFFF
|
||||
|
||||
|
@ -73,6 +75,17 @@ movl $STACK_LOCATION,%esp
|
|||
mov $0x38, %eax
|
||||
ltr %ax
|
||||
|
||||
# Zeroing the .bss section
|
||||
mov $_bss_start, %eax
|
||||
mov $_bss_end, %ebx
|
||||
start_zeroing:
|
||||
movb $0x0, (%eax)
|
||||
cmp %eax, %ebx
|
||||
je end_zeroing
|
||||
inc %eax
|
||||
jmp start_zeroing
|
||||
end_zeroing:
|
||||
|
||||
# Start kernel main function
|
||||
call bringelle
|
||||
|
||||
|
|
|
@ -27,6 +27,11 @@ void bringelle(){
|
|||
print("Paging enable!\n");
|
||||
print("Kernel started !");
|
||||
|
||||
paging_allocate(5);
|
||||
print("\n");
|
||||
paging_dump(1024,-1);
|
||||
print("\n");
|
||||
|
||||
show_tics=1;
|
||||
// Utask
|
||||
print("Launch user task ");
|
||||
|
@ -54,6 +59,7 @@ void bringelle(){
|
|||
while(1);
|
||||
}
|
||||
|
||||
|
||||
void clock(){
|
||||
static int tic=0;
|
||||
static int sec=0;
|
||||
|
@ -66,7 +72,6 @@ void clock(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void page_fault(){
|
||||
print("Page fault!");
|
||||
}
|
||||
|
|
|
@ -1,21 +1,43 @@
|
|||
#include "paging.h"
|
||||
#include "libc/stdio.h"
|
||||
|
||||
/// Use a bitmap to keep track of allocated pages
|
||||
char pages_status[PAGING_MAX_PAGES/8];
|
||||
/// Kernel page directory (ATTENTION need to be 4096)
|
||||
u32 k_pd[PAGING_MAX_DIR_ENTRY] __attribute__((aligned(4096)));
|
||||
/// Kernel page table
|
||||
u32 k_pt[PAGING_MAX_DIR_ENTRY][1024] __attribute__((aligned(4096)));
|
||||
|
||||
void paging_enable(){
|
||||
int *page_dir=(int*)PAGING_DIR_LOCATION;
|
||||
int *page_table=(int*)PAGING_TABLE_LOCATION;
|
||||
// Init pages status
|
||||
for(int i=0;i<PAGING_MAX_PAGES/8;i++)
|
||||
pages_status[i]=0;
|
||||
|
||||
// Init page directory
|
||||
for(int i=0;i<1024;i++)
|
||||
page_dir[i]=0;
|
||||
page_dir[0]=(int)page_table;
|
||||
page_dir[0] |=7; // Permissions
|
||||
for(int i=0;i<PAGING_MAX_DIR_ENTRY;i++){
|
||||
k_pd[i]=0;
|
||||
}
|
||||
k_pd[0]=((int)&k_pt[0][0]);
|
||||
k_pd[0]|=7; // Permissions
|
||||
|
||||
// Init page table 0
|
||||
int addr_offset=0;
|
||||
for(int i=0;i<1024;i++){
|
||||
page_table[i]=addr_offset;
|
||||
page_table[i]|=7; // Permission
|
||||
addr_offset+=4096; // 4Ko pages
|
||||
k_pt[0][i]=addr_offset;
|
||||
k_pt[0][i]|=7; // Permission
|
||||
paging_set_usage(addr_offset,1); // Mark addr as used
|
||||
addr_offset+=PAGING_PAGE_SIZE; // 4Ko pages
|
||||
}
|
||||
|
||||
// Allow access to more ram
|
||||
for(int i=1;i<PAGING_MAX_DIR_ENTRY;i++){
|
||||
k_pd[i]=((int)&k_pt[i][0]);
|
||||
k_pd[i]|=7; // Permissions
|
||||
for(int j=0;j<1024;j++){
|
||||
k_pt[i][j]=addr_offset;
|
||||
k_pt[i][j]|=7; // Permission
|
||||
addr_offset+=PAGING_PAGE_SIZE; // 4Ko pages
|
||||
}
|
||||
}
|
||||
|
||||
// Turns on paging
|
||||
|
@ -25,7 +47,63 @@ void paging_enable(){
|
|||
"movl %%cr0, %%eax \n\t"
|
||||
"orl %1, %%eax \n\t"
|
||||
"movl %%eax, %%cr0 \n\t" // Turn on paging
|
||||
:: "i" (PAGING_DIR_LOCATION), "i" (PAGING_CR0_BIT)
|
||||
:: "b" (k_pd), "i" (PAGING_CR0_BIT)
|
||||
);
|
||||
}
|
||||
void paging_set_usage(int addr,char state){
|
||||
char bytes=pages_status[addr/PAGING_PAGE_SIZE/8];
|
||||
char bit=addr/PAGING_PAGE_SIZE%8;
|
||||
if(state=0)
|
||||
pages_status[addr/PAGING_PAGE_SIZE/8]=~(1<<bit)&bytes;
|
||||
else
|
||||
pages_status[addr/PAGING_PAGE_SIZE/8]=(1<<bit)|bytes;
|
||||
}
|
||||
|
||||
void paging_dump(int min,int max){
|
||||
for(int i=0;i<(PAGING_MAX_PAGES/8);i++){
|
||||
for(int j=0;j<8;j++){
|
||||
char status=(pages_status[i]>>j)&0x1;
|
||||
if((i*8+j)>=min){
|
||||
if((i*8+j)<max || max<0)
|
||||
printi(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* paging_allocate_next_page(){
|
||||
for(int i=0;i<(PAGING_MAX_PAGES/8);i++){
|
||||
char bytes=pages_status[i];
|
||||
for(int j=0;j<8;j++){
|
||||
char state=(bytes>>j)&1;
|
||||
if(state!=1){
|
||||
int page_id=i*8+j;
|
||||
int page_addr=PAGING_PAGE_SIZE*page_id;
|
||||
paging_set_usage(page_addr,1);
|
||||
return((char*)page_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
print("Could not allocate anymore pages! Stopping...");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
|
||||
char *paging_allocate(int p){
|
||||
int *page_dir=(int*)paging_allocate_next_page();
|
||||
int *page_table;
|
||||
int current_page_entry=0;
|
||||
int current_dir_entry=0;
|
||||
while(current_page_entry<p){
|
||||
if(current_page_entry%1024 == 0){
|
||||
current_dir_entry++;
|
||||
page_table=(int*)paging_allocate_next_page();
|
||||
page_dir[current_dir_entry]=(int)page_table;
|
||||
}
|
||||
int entry=current_page_entry%1024;
|
||||
page_table[current_page_entry]=(int)paging_allocate_next_page();
|
||||
current_page_entry++;
|
||||
print("Jean\n");
|
||||
}
|
||||
print("end");
|
||||
}
|
|
@ -2,12 +2,25 @@
|
|||
#define PAGING_H
|
||||
|
||||
#define PAGING_CR0_BIT 0x80000000
|
||||
#define PAGING_DIR_LOCATION 0x1000
|
||||
#define PAGING_TABLE_LOCATION 0x5000
|
||||
#define PAGING_PAGE_SIZE 4096
|
||||
#define PAGING_MAX_PAGES 2048
|
||||
#if PAGING_MAX_PAGES%1024>0
|
||||
#define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024+1
|
||||
#else
|
||||
#define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Configure and enable paging
|
||||
*/
|
||||
void paging_enable();
|
||||
|
||||
char* paging_allocate_next_page();
|
||||
void paging_set_usage(int addr,char state);
|
||||
/**
|
||||
* Create a new page directory containing
|
||||
* p pages.
|
||||
*/
|
||||
char *paging_allocate(int p);
|
||||
void paging_dump(int min,int max);
|
||||
#endif
|
0
src/core/scheduler.c
Normal file
0
src/core/scheduler.c
Normal file
5
src/core/scheduler.h
Normal file
5
src/core/scheduler.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#ifndef SCHEDULER_H
|
||||
#define SCHEDULER_H
|
||||
|
||||
|
||||
#endif
|
|
@ -5,23 +5,25 @@ OUTPUT_ARCH(i386)
|
|||
SECTIONS {
|
||||
|
||||
. = 1M;
|
||||
.text :
|
||||
.text : ALIGN(4)
|
||||
{
|
||||
*(.multiboot)
|
||||
*(.text)
|
||||
}
|
||||
.rodata :
|
||||
.rodata : ALIGN(4)
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
.data :
|
||||
.data : ALIGN(4)
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
.bss :
|
||||
.bss : ALIGN(4)
|
||||
{
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
_bss_start = .;
|
||||
*(.bss);
|
||||
_bss_end = .;
|
||||
*(COMMON);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue