Import backup from 2003-12-29
This commit is contained in:
parent
715bb9341a
commit
e83408ce83
9
kernel.c
9
kernel.c
@ -62,16 +62,15 @@ void k_init()
|
||||
kbd_resetLEDs(); //after enabling interrupts!!
|
||||
if (videoMode)
|
||||
{
|
||||
int x, y;
|
||||
for (x = 0; x < video_mode.XResolution; x++)
|
||||
for (y = 0; y < video_mode.YResolution; y++)
|
||||
video_pset(x, y, 0x00000044);
|
||||
int p = video_mode.XResolution*video_mode.YResolution-1;
|
||||
for (; p >= 0; p--)
|
||||
video_psetp(p, 0x00000044);
|
||||
video_drawConsole();
|
||||
}
|
||||
|
||||
printf("HOS 0.13 - Kernel Size: %u kb\n", kernel_size()>>10);
|
||||
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
|
||||
printf("Free memory: %u bytes\t %u pages\n", mm_freemem(), mm_freemem()>>12);
|
||||
printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12);
|
||||
|
||||
dword key = 0;
|
||||
for (;;)
|
||||
|
62
vmm.c
62
vmm.c
@ -18,9 +18,34 @@ void vmm_init()
|
||||
vidPages = (vidPages >> 12);
|
||||
vmm_mapn(0xF0000000, video_mode.PhysBasePtr, vidPages);
|
||||
}
|
||||
dword firstHeapEntryBlock = (dword)mm_palloc();
|
||||
vmm_map1((dword)firstHeapEntry, firstHeapEntryBlock);
|
||||
HeapEntryBlock *heb = (HeapEntryBlock *)firstHeapEntry;
|
||||
vmm_heb_init(heb);
|
||||
heb->entry[0].base = (dword)firstHeapEntry; //start of kernel's heap memory
|
||||
heb->entry[0].size = 4096; //the first HeapEntryBlock is 1 page long
|
||||
heb->entry[0].attributes = VMM_HE_HEB; //this is a HeapEntryBlock
|
||||
heb->entry[1].base = (dword)firstHeapEntry+4096; //this is the start of the rest of the kernel's heap memory
|
||||
heb->entry[1].size = 0x10000000-4096; //the rest of the kernel's heap memory: 256mb - 4kb
|
||||
heb->entry[1].attributes = VMM_HE_HOLE; //this is a hold - an unmapped section of heap memory
|
||||
}
|
||||
|
||||
|
||||
void vmm_heb_init(HeapEntryBlock *heb)
|
||||
{
|
||||
int a;
|
||||
for (a = 0; a < 256; a++)
|
||||
{
|
||||
heb->entry[a].base = 0;
|
||||
heb->entry[a].size = 0;
|
||||
heb->entry[a].attributes = VMM_HE_UNUSED;
|
||||
heb->entry[a].link = (dword)&(heb->entry[a+1]);
|
||||
}
|
||||
heb->entry[255].link = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void vmm_map1(dword virt, dword physical)
|
||||
{
|
||||
dword pde = virt >> 22;
|
||||
@ -40,6 +65,7 @@ void vmm_map1(dword virt, dword physical)
|
||||
}
|
||||
dword *pteptr = (dword *)(0xFFC00000 | (pde << 12) | (pte << 2));
|
||||
*pteptr = physical | 0x03;
|
||||
invlpg(virt);
|
||||
}
|
||||
|
||||
|
||||
@ -54,11 +80,43 @@ void vmm_mapn(dword virt, dword physical, dword n)
|
||||
}
|
||||
|
||||
|
||||
void vmm_unmap1(dword virt)
|
||||
{
|
||||
dword *pteptr = (dword *)(0xFFC00000 | ((virt & 0xFFC00000) >> 10) | ((virt & 0x003FF000) >> 10));
|
||||
*pteptr = 0;
|
||||
invlpg(virt);
|
||||
}
|
||||
|
||||
|
||||
void vmm_unmapn(dword virt, dword n)
|
||||
{
|
||||
for (; n > 0; n--)
|
||||
{
|
||||
vmm_unmap1(virt);
|
||||
virt += 4096;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *malloc(dword bytes)
|
||||
{
|
||||
|
||||
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
for (;;)
|
||||
{
|
||||
if ((he->size >= bytes) && (he->attributes = VMM_HE_FREE))
|
||||
{
|
||||
if (he->size == bytes)
|
||||
{
|
||||
he->attributes = VMM_HE_USED;
|
||||
return (void *)(he->base);
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the next HeapEntry, save in it the free mem, save in this entry the used mem...
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
27
vmm.h
27
vmm.h
@ -1,16 +1,41 @@
|
||||
|
||||
// vmm.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 09/30/03
|
||||
// Rewritten from scratch: 12/23/03
|
||||
// Modified: 12/29/03
|
||||
|
||||
|
||||
#define VMM_HE_UNUSED 0 //available entry
|
||||
#define VMM_HE_FREE 1 //free section of memory
|
||||
#define VMM_HE_USED 2 //used section of memory
|
||||
#define VMM_HE_HOLE 3 //a "hole" (unmapped) section of virtual memory
|
||||
#define VMM_HE_HEB 4 //HeapEntryBlock
|
||||
|
||||
|
||||
typedef struct {
|
||||
dword base; //virtual base address
|
||||
dword size; //size in bytes
|
||||
dword attributes; //free/used/hole
|
||||
dword link; //link to next HeapEntry
|
||||
} __attribute__((packed)) HeapEntry;
|
||||
|
||||
|
||||
typedef struct {
|
||||
HeapEntry entry[256]; //256 HeapEntry objects = 4kb (1 page)
|
||||
} __attribute__((packed)) HeapEntryBlock;
|
||||
|
||||
|
||||
void vmm_init();
|
||||
void *malloc(dword bytes);
|
||||
int free(void *ptr);
|
||||
void vmm_map1(dword virt, dword physical);
|
||||
void vmm_mapn(dword virt, dword physical, dword n);
|
||||
void vmm_unmap1(dword virt);
|
||||
void vmm_unmapn(dword virt, dword n);
|
||||
void vmm_heb_init(HeapEntryBlock *heb);
|
||||
|
||||
|
||||
HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000;
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user