Import backup from 2003-12-23_2
This commit is contained in:
parent
71aaa7a598
commit
528527a7ed
@ -40,6 +40,13 @@ _read_cr3:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
[global _invlpg]
|
||||||
|
_invlpg:
|
||||||
|
mov eax, [esp+4]
|
||||||
|
invlpg [eax]
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
19
kernel.c
19
kernel.c
@ -33,6 +33,7 @@ extern dword read_cr3();
|
|||||||
#include "video.c"
|
#include "video.c"
|
||||||
|
|
||||||
dword timer = 0;
|
dword timer = 0;
|
||||||
|
dword callnum = 0;
|
||||||
|
|
||||||
//Main kernel initialization method
|
//Main kernel initialization method
|
||||||
void k_init()
|
void k_init()
|
||||||
@ -53,7 +54,23 @@ void k_init()
|
|||||||
|
|
||||||
printf("HOS 0.12 - Kernel Size: %u kb\n", kernel_size()/1024);
|
printf("HOS 0.12 - Kernel Size: %u kb\n", kernel_size()/1024);
|
||||||
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
|
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
|
||||||
printf("Free memory: %u bytes\n", mm_freemem());
|
printf("Free memory: %u bytes\t %u pages\n", mm_freemem(), mm_freemem()>>12);
|
||||||
|
|
||||||
|
if (videoMode)
|
||||||
|
{
|
||||||
|
dword p;
|
||||||
|
for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++)
|
||||||
|
video_psetp(p, 0x00000088);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
dword addr = (dword)mm_palloc();
|
||||||
|
callnum++;
|
||||||
|
printf("addr = 0x%x\tcallnum = %u\tfree pages = %u\n", addr, callnum, mm_freemem()>>12);
|
||||||
|
if (!addr)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
dword key = 0;
|
dword key = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
|
1
mm.c
1
mm.c
@ -76,6 +76,7 @@ void *mm_palloc()
|
|||||||
{
|
{
|
||||||
if (!(page_bitmap[bite] & (1 << bit))) //this bite/bit combination is available
|
if (!(page_bitmap[bite] & (1 << bit))) //this bite/bit combination is available
|
||||||
{
|
{
|
||||||
|
page_bitmap[bite] = page_bitmap[bite] | (1 << bit); //set page as used
|
||||||
return (void *)((bite << 15) + (bit << 12));
|
return (void *)((bite << 15) + (bit << 12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
video.c
11
video.c
@ -19,16 +19,13 @@ void video_init()
|
|||||||
switch(video_mode.BitsPerPixel)
|
switch(video_mode.BitsPerPixel)
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
vid_ptr16 = (word *) video_mode.PhysBasePtr;
|
|
||||||
video_psetp = &video_psetp16;
|
video_psetp = &video_psetp16;
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
vid_ptr24 = (byte *) video_mode.PhysBasePtr;
|
|
||||||
video_psetp = &video_psetp24;
|
video_psetp = &video_psetp24;
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
video_psetp = &video_psetp32;
|
video_psetp = &video_psetp32;
|
||||||
vid_ptr32 = (dword *) video_mode.PhysBasePtr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +145,9 @@ void video_psetp32(int pixel, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Dummy function to not draw anything if there is no graphical mode enabled
|
//Dummy function to not draw anything if there is no graphical mode enabled
|
||||||
void video_psetpnull(int pixel, dword color)
|
void video_psetpnull(int pixel, dword color) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
8
video.h
8
video.h
@ -54,10 +54,10 @@ typedef struct{
|
|||||||
} ModeInfoBlock;
|
} ModeInfoBlock;
|
||||||
|
|
||||||
ModeInfoBlock video_mode;
|
ModeInfoBlock video_mode;
|
||||||
dword videoMode; //what video mode # we are in, 0 for console mode
|
dword videoMode = 0; //what video mode # we are in, 0 for console mode
|
||||||
byte *vid_ptr24;
|
word *vid_ptr16 = (word *)0xF0000000;
|
||||||
word *vid_ptr16;
|
byte *vid_ptr24 = (byte *)0xF0000000;
|
||||||
dword *vid_ptr32;
|
dword *vid_ptr32 = (dword *)0xF0000000;
|
||||||
void (*video_psetp)(int, dword); //function pointer to set a pixel
|
void (*video_psetp)(int, dword); //function pointer to set a pixel
|
||||||
|
|
||||||
|
|
||||||
|
43
vmm.c
43
vmm.c
@ -7,15 +7,52 @@
|
|||||||
|
|
||||||
void vmm_init()
|
void vmm_init()
|
||||||
{
|
{
|
||||||
dword *pagetables = (dword *)0xC0104000; //this is the location of the page directory
|
dword *pageTables = (dword *)0xC0104000; //this is the location of the page directory
|
||||||
pagetables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself
|
pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself
|
||||||
if (videoMode) //we are in a graphical mode
|
if (videoMode) //we are in a graphical mode
|
||||||
{
|
{
|
||||||
|
dword vidPages = video_mode.XResolution * video_mode.YResolution * (video_mode.BitsPerPixel >> 3);
|
||||||
|
if (vidPages % 4096)
|
||||||
|
vidPages = (vidPages >> 12) + 1;
|
||||||
|
else
|
||||||
|
vidPages = (vidPages >> 12);
|
||||||
|
vmm_mapn(0xF0000000, video_mode.PhysBasePtr, vidPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vmm_map1(dword virt, dword physical)
|
||||||
|
{
|
||||||
|
dword pde = virt >> 22;
|
||||||
|
dword pte = (virt & 0x003FF000) >> 12;
|
||||||
|
dword *pageTables = (dword *)0xC0104000; //this is the location of the page directory
|
||||||
|
if (!(pageTables[pde] & 0x01)) //the page directory entry does not exist, we must allocate a page for it
|
||||||
|
{
|
||||||
|
dword *newpagetable = mm_palloc();
|
||||||
|
pageTables[pde] = ((dword)newpagetable) | 0x03;
|
||||||
|
invlpg(virt);
|
||||||
|
dword *newpteptr = (dword *)(0xFFC00000 | (pde << 12)); //points to first dword of newly allocated page table
|
||||||
|
int a;
|
||||||
|
for (a = 0; a < 1024; a++)
|
||||||
|
{
|
||||||
|
newpteptr[a] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dword *pteptr = (dword *)(0xFFC00000 | (pde << 12) | (pte << 2));
|
||||||
|
*pteptr = physical | 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vmm_mapn(dword virt, dword physical, dword n)
|
||||||
|
{
|
||||||
|
for (; n > 0; n--)
|
||||||
|
{
|
||||||
|
vmm_map1(virt, physical);
|
||||||
|
virt += 4096;
|
||||||
|
physical += 4096;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *malloc(dword bytes)
|
void *malloc(dword bytes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user