diff --git a/lib/objgfx40/ogFont.cpp b/lib/objgfx40/ogFont.cpp index 0de0532..61d5e73 100644 --- a/lib/objgfx40/ogFont.cpp +++ b/lib/objgfx40/ogFont.cpp @@ -256,9 +256,12 @@ bits += bits; ++xx; + } while (--xCount); } // for yCount + } // if + return; } // ogBitFont::PutChar diff --git a/sys/fs/fat/fat.c b/sys/fs/fat/fat.c index c89fc42..a2dd4df 100644 --- a/sys/fs/fat/fat.c +++ b/sys/fs/fat/fat.c @@ -57,6 +57,7 @@ int fat_initialize(struct vfs_mountPoint *mp) { FL_FILE *file; _mp = mp; + // Attach media access functions to library if (fl_attach_media(media_read, media_write) != FAT_INIT_OK) { kprintf("ERROR: Media attach failed\n"); @@ -152,7 +153,6 @@ } else { _file = fl_fopen(file, "w"); - //kprintf("open for writing"); } } else @@ -173,10 +173,12 @@ } int unlink_fat() { + kprintf("[%s:%i] unlink_fat"); return (0); } int mkdir_fat() { + kprintf("[%s:%i] mkdir_fat"); return (0); } diff --git a/sys/include/vmm/mmap.h b/sys/include/vmm/mmap.h new file mode 100644 index 0000000..99cea6b --- /dev/null +++ b/sys/include/vmm/mmap.h @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2020 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _VMM_VMM_H +#define _VMM_VMM_H + +// @formatter:off +typedef __uint32_t __vm_size_t; // MrOlsen (2016-01-15) TEMP: Put These somewhere else +typedef __vm_size_t vm_size_t; // vm_size_t +// @formatter:on + +#define EINVAL 22 // Invalid argument +#define MAP_ALIGNED(n) ((n) << MAP_ALIGNMENT_SHIFT) +#define MAP_ALIGNMENT_SHIFT 24 +#define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff) +#define MAP_ALIGNED_SUPER MAP_ALIGNED(1) /* align on a superpage */ +#define NBBY 8 /* number of bits in a byte */ + +/* PROTs */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* FLAGs */ + +/* + * Do I Need These? + */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ +#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ +#define MAP_RESERVED0080 0x0080 /* previously misimplemented MAP_INHERIT */ +#define MAP_RESERVED0100 0x0100 /* previously unimplemented MAP_NOEXTEND */ +#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ +#define MAP_STACK 0x0400 /* region grows down, like a stack */ +#define MAP_NOSYNC 0x0800 /* page to but do not sync underlying file */ + +/* + * Mapping type + */ +#define MAP_FILE 0x0000 /* map from file (default) */ +#define MAP_ANON 0x1000 /* allocated from memory, swap space */ + +#endif diff --git a/sys/include/vmm/vmm.h b/sys/include/vmm/vmm.h index bb769b1..8ed741a 100644 --- a/sys/include/vmm/vmm.h +++ b/sys/include/vmm/vmm.h @@ -31,6 +31,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -42,10 +43,10 @@ #define memNotavail 2 #define vmmID -3 - /* - #define vmmMemoryMapAddr 0xE6667000 - #define VMM_MMAP_ADDR_PMODE2 0xE6667000 - */ + /* + #define vmmMemoryMapAddr 0xE6667000 + #define VMM_MMAP_ADDR_PMODE2 0xE6667000 + */ #define VMM_MMAP_ADDR_PMODE VMM_KERN_START /* (PD_BASE_ADDR + PAGE_SIZE) */ #define VMM_MMAP_ADDR_RMODE 0x101000 @@ -67,64 +68,64 @@ #define VMM_KERN_STACK_START 0xFE000000 #define VMM_KERN_STACK_END 0xFFFFFFFF - extern struct spinLock pdSpinLock; + extern struct spinLock pdSpinLock; + struct freebsd6_mmap_args { + char addr_l_[PADL_(caddr_t)]; + caddr_t addr; + char addr_r_[PADR_(caddr_t)]; - struct freebsd6_mmap_args { - char addr_l_[PADL_(caddr_t)]; - caddr_t addr; - char addr_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; + size_t len; + char len_r_[PADR_(size_t)]; - char len_l_[PADL_(size_t)]; - size_t len; - char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; + int prot; + char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; - char prot_l_[PADL_(int)]; - int prot; - char prot_r_[PADR_(int)]; - char flags_l_[PADL_(int)]; + int flags; + char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; + int fd; + char fd_r_[PADR_(int)]; - int flags; - char flags_r_[PADR_(int)]; - char fd_l_[PADL_(int)]; - int fd; - char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; + int pad; + char pad_r_[PADR_(int)]; - char pad_l_[PADL_(int)]; - int pad; - char pad_r_[PADR_(int)]; + char pos_l_[PADL_(off_t)]; + off_t pos; + char pos_r_[PADR_(off_t)]; + }; - char pos_l_[PADL_(off_t)]; - off_t pos; - char pos_r_[PADR_(off_t)]; - }; + typedef struct { + uint32_t pageAddr; + u_int16_t status; + u_int16_t reserved; + pid_t pid; + int cowCounter; + } mMap; - typedef struct { - uint32_t pageAddr; - u_int16_t status; - u_int16_t reserved; - pid_t pid; - int cowCounter; - } mMap; + typedef enum { + VMM_FREE = 0, + VMM_KEEP = 1 + } unmapFlags_t; - typedef enum { - VMM_FREE = 0, VMM_KEEP = 1 - } unmapFlags_t; + extern int numPages; + extern mMap *vmmMemoryMap; - extern int numPages; - extern mMap *vmmMemoryMap; + int vmm_init(); + int vmm_memMapInit(); + int countMemory(); + uint32_t vmm_findFreePage(pidType pid); + int freePage(uint32_t pageAddr); + int adjustCowCounter(uint32_t baseAddr, int adjustment); + void vmm_freeProcessPages(pidType pid); - int vmm_init(); - int vmm_memMapInit(); - int countMemory(); - uint32_t vmm_findFreePage(pidType pid); - int freePage(uint32_t pageAddr); - int adjustCowCounter(uint32_t baseAddr, int adjustment); - void vmm_freeProcessPages(pidType pid); - - int vmm_allocPageTable(uint32_t, pidType); - void vmm_unmapPage(uint32_t, unmapFlags_t); - void vmm_unmapPages(void *, uint32_t, unmapFlags_t); + int vmm_allocPageTable(uint32_t, pidType); + void vmm_unmapPage(uint32_t, unmapFlags_t); + void vmm_unmapPages(void*, uint32_t, unmapFlags_t); #ifdef __cplusplus } diff --git a/sys/lib/kmalloc.c b/sys/lib/kmalloc.c index 078217c..2abef49 100644 --- a/sys/lib/kmalloc.c +++ b/sys/lib/kmalloc.c @@ -51,8 +51,10 @@ /* Set up our spinlocks so we do not corrupt linked lists if we have re-entrancy */ -static struct spinLock mallocSpinLock = SPIN_LOCK_INITIALIZER; -static struct spinLock emptyDescSpinLock = SPIN_LOCK_INITIALIZER; +static struct spinLock mallocSpinLock = SPIN_LOCK_INITIALIZER +; +static struct spinLock emptyDescSpinLock = SPIN_LOCK_INITIALIZER +; /************************************************************************ @@ -64,48 +66,48 @@ 02/17/03 - Is This Efficient? ************************************************************************/ -static void *getEmptyDesc() { - int i = 0x0; - struct memDescriptor *tmpDesc = 0x0; +static void* getEmptyDesc() { + int i = 0x0; + struct memDescriptor *tmpDesc = 0x0; - spinLock(&emptyDescSpinLock); + spinLock(&emptyDescSpinLock); - tmpDesc = emptyKernDesc; + tmpDesc = emptyKernDesc; - if (tmpDesc != 0x0) { + if (tmpDesc != 0x0) { + emptyKernDesc = tmpDesc->next; + if (emptyKernDesc != 0x0) + emptyKernDesc->prev = 0x0; + + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + spinUnlock(&emptyDescSpinLock); + return (tmpDesc); + } + if ((emptyKernDesc = (struct memDescriptor*) vmm_getFreeMallocPage(4)) == 0x0) + kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); + + /* zero out the memory so we know there is no garbage */ + memset(emptyKernDesc, 0x0, 0x4000); + + emptyKernDesc[0].next = &emptyKernDesc[1]; + + for (i = 0x1; i < ((0x4000 / sizeof(struct memDescriptor))); i++) { + if (i + 1 < (0x4000 / sizeof(struct memDescriptor))) + emptyKernDesc[i].next = &emptyKernDesc[i + 1]; + else + emptyKernDesc[i].next = 0x0; + emptyKernDesc[i].prev = &emptyKernDesc[i - 1]; + } + + tmpDesc = &emptyKernDesc[0]; + emptyKernDesc = tmpDesc->next; - if (emptyKernDesc != 0x0) - emptyKernDesc->prev = 0x0; - + emptyKernDesc->prev = 0x0; tmpDesc->next = 0x0; tmpDesc->prev = 0x0; spinUnlock(&emptyDescSpinLock); return (tmpDesc); - } - if ((emptyKernDesc = (struct memDescriptor *) vmm_getFreeMallocPage(4)) == 0x0) - kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); - - /* zero out the memory so we know there is no garbage */ - memset(emptyKernDesc, 0x0, 0x4000); - - emptyKernDesc[0].next = &emptyKernDesc[1]; - - for (i = 0x1; i < ((0x4000 / sizeof(struct memDescriptor))); i++) { - if (i + 1 < (0x4000 / sizeof(struct memDescriptor))) - emptyKernDesc[i].next = &emptyKernDesc[i + 1]; - else - emptyKernDesc[i].next = 0x0; - emptyKernDesc[i].prev = &emptyKernDesc[i - 1]; - } - - tmpDesc = &emptyKernDesc[0]; - - emptyKernDesc = tmpDesc->next; - emptyKernDesc->prev = 0x0; - tmpDesc->next = 0x0; - tmpDesc->prev = 0x0; - spinUnlock(&emptyDescSpinLock); - return (tmpDesc); } /************************************************************************ @@ -121,13 +123,13 @@ ************************************************************************/ static int insertFreeDesc(struct memDescriptor *freeDesc) { - struct memDescriptor *tmpDesc = 0x0; - assert(freeDesc); + struct memDescriptor *tmpDesc = 0x0; + assert(freeDesc); - if (freeDesc->limit <= 0x0) - kpanic("Inserting Descriptor with no limit\n"); + if (freeDesc->limit <= 0x0) + kpanic("Inserting Descriptor with no limit\n"); - if (freeKernDesc != 0x0) { + if (freeKernDesc != 0x0) { #if 0 freeDesc->next = freeKernDesc; @@ -136,38 +138,38 @@ freeKernDesc = freeDesc; #endif - for (tmpDesc = freeKernDesc; tmpDesc != 0x0; tmpDesc = tmpDesc->next) { - if (freeDesc->limit <= tmpDesc->limit) { + for (tmpDesc = freeKernDesc; tmpDesc != 0x0; tmpDesc = tmpDesc->next) { + if (freeDesc->limit <= tmpDesc->limit) { - freeDesc->prev = tmpDesc->prev; - if (tmpDesc->prev != 0x0) - tmpDesc->prev->next = freeDesc; + freeDesc->prev = tmpDesc->prev; + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = freeDesc; - tmpDesc->prev = freeDesc; - freeDesc->next = tmpDesc; + tmpDesc->prev = freeDesc; + freeDesc->next = tmpDesc; - if (tmpDesc == freeKernDesc) - freeKernDesc = freeDesc; + if (tmpDesc == freeKernDesc) + freeKernDesc = freeDesc; + return (0x0); + } + if (tmpDesc->next == 0x0) { + tmpDesc->next = freeDesc; + freeDesc->prev = tmpDesc; + freeDesc->next = 0x0; + return (0x0); + } + } + kpanic("didnt Insert\n"); return (0x0); - } - if (tmpDesc->next == 0x0) { - tmpDesc->next = freeDesc; - freeDesc->prev = tmpDesc; - freeDesc->next = 0x0; - return (0x0); - } } - kpanic("didnt Insert\n"); - return (0x0); - } - else { - freeDesc->prev = 0x0; - freeDesc->next = 0x0; - freeKernDesc = freeDesc; - return (0x0); - } + else { + freeDesc->prev = 0x0; + freeDesc->next = 0x0; + freeKernDesc = freeDesc; + return (0x0); + } - return (0x1); + return (0x1); } /************************************************************************ @@ -180,57 +182,55 @@ 03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 ************************************************************************/ -#ifdef _IGNORE static void mergeMemBlocks() { - struct memDescriptor *tmpDesc1 = 0x0; - struct memDescriptor *tmpDesc2 = 0x0; - uInt32 baseAddr = 0x0; + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + u_int32_t baseAddr = 0x0; - return; + kprintf("[%s:%i] MMB", __FILE__, __LINE__); - //Loop The Free Descriptors See If We Can Merge Them - mergeStart: for (tmpDesc1 = freeKernDesc; tmpDesc1 != 0x0; tmpDesc1 = tmpDesc1->next) { - /* - Compare The Base Addr With The Other Descriptors If You Find The One - That You Are Looking For Lets Merge Them - */ - if (tmpDesc1->limit != 0x0) { - baseAddr = (uInt32) tmpDesc1->baseAddr + (uInt32) tmpDesc1->limit; - for (tmpDesc2 = freeKernDesc; tmpDesc2; tmpDesc2 = tmpDesc2->next) { - if ((uInt32) tmpDesc2->baseAddr == baseAddr) { - tmpDesc1->limit += tmpDesc2->limit; - tmpDesc2->baseAddr = 0x0; - tmpDesc2->limit = 0x0; - if (tmpDesc2->prev) { - tmpDesc2->prev->next = tmpDesc2->next; - } - if (tmpDesc2->next) { - tmpDesc2->next->prev = tmpDesc2->prev; - } - tmpDesc2->prev = 0x0; - tmpDesc2->next = emptyKernDesc; - emptyKernDesc->prev = tmpDesc2; - emptyKernDesc = tmpDesc2; - if (tmpDesc1->prev) { - tmpDesc1->prev->next = tmpDesc1->next; - } - if (tmpDesc1->next) { - tmpDesc1->next->prev = tmpDesc1->prev; - } - tmpDesc1->prev = 0x0; - tmpDesc1->next = 0x0; - kprintf("mergememBlocks: [%i]\n", tmpDesc1->limit); - insertFreeDesc(tmpDesc1); - //tmpDesc1 = freeKernDesc; - goto mergeStart; - break; + //Loop The Free Descriptors See If We Can Merge Them + mergeStart: for (tmpDesc1 = freeKernDesc; tmpDesc1 != 0x0; tmpDesc1 = tmpDesc1->next) { + /* + Compare The Base Addr With The Other Descriptors If You Find The One + That You Are Looking For Lets Merge Them + */ + if (tmpDesc1->limit != 0x0) { + baseAddr = (uInt32) tmpDesc1->baseAddr + (uInt32) tmpDesc1->limit; + for (tmpDesc2 = freeKernDesc; tmpDesc2; tmpDesc2 = tmpDesc2->next) { + if ((uInt32) tmpDesc2->baseAddr == baseAddr) { + tmpDesc1->limit += tmpDesc2->limit; + tmpDesc2->baseAddr = 0x0; + tmpDesc2->limit = 0x0; + if (tmpDesc2->prev) { + tmpDesc2->prev->next = tmpDesc2->next; + } + if (tmpDesc2->next) { + tmpDesc2->next->prev = tmpDesc2->prev; + } + tmpDesc2->prev = 0x0; + tmpDesc2->next = emptyKernDesc; + emptyKernDesc->prev = tmpDesc2; + emptyKernDesc = tmpDesc2; + if (tmpDesc1->prev) { + tmpDesc1->prev->next = tmpDesc1->next; + } + if (tmpDesc1->next) { + tmpDesc1->next->prev = tmpDesc1->prev; + } + tmpDesc1->prev = 0x0; + tmpDesc1->next = 0x0; + kprintf("mergememBlocks: [%i]\n", tmpDesc1->limit); + insertFreeDesc(tmpDesc1); + //tmpDesc1 = freeKernDesc; + goto mergeStart; + break; + } + } } - } } - } - return; + return; } -#endif /************************************************************************ @@ -242,96 +242,96 @@ 02/17/03 - Do I Still Need To Pass In The Pid? ************************************************************************/ -void *kmalloc(uInt32 len) { - struct memDescriptor *tmpDesc1 = 0x0; - struct memDescriptor *tmpDesc2 = 0x0; - char *buf = 0x0; - int i = 0x0; - uInt16 pages = 0x0; +void* kmalloc(uInt32 len) { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + char *buf = 0x0; + int i = 0x0; + uInt16 pages = 0x0; - spinLock(&mallocSpinLock); + spinLock(&mallocSpinLock); - len = MALLOC_ALIGN(len); + len = MALLOC_ALIGN(len); - if (len == 0x0) { - spinUnlock(&mallocSpinLock); - kprintf("kmalloc: len = 0!\n"); - return (0x0); - } - for (tmpDesc1 = freeKernDesc; tmpDesc1 != 0x0; tmpDesc1 = tmpDesc1->next) { - assert(tmpDesc1); - if (tmpDesc1->limit >= len) { - if (tmpDesc1->prev != 0x0) - tmpDesc1->prev->next = tmpDesc1->next; - if (tmpDesc1->next != 0x0) - tmpDesc1->next->prev = tmpDesc1->prev; + if (len == 0x0) { + spinUnlock(&mallocSpinLock); + kprintf("kmalloc: len = 0!\n"); + return (0x0); + } + for (tmpDesc1 = freeKernDesc; tmpDesc1 != 0x0; tmpDesc1 = tmpDesc1->next) { + assert(tmpDesc1); + if (tmpDesc1->limit >= len) { + if (tmpDesc1->prev != 0x0) + tmpDesc1->prev->next = tmpDesc1->next; + if (tmpDesc1->next != 0x0) + tmpDesc1->next->prev = tmpDesc1->prev; - if (tmpDesc1 == freeKernDesc) - freeKernDesc = tmpDesc1->next; + if (tmpDesc1 == freeKernDesc) + freeKernDesc = tmpDesc1->next; - tmpDesc1->prev = 0x0; - tmpDesc1->next = usedKernDesc; - if (usedKernDesc != 0x0) - usedKernDesc->prev = tmpDesc1; - usedKernDesc = tmpDesc1; - if (tmpDesc1->limit > len) { - tmpDesc2 = getEmptyDesc(); - assert(tmpDesc2); - tmpDesc2->limit = tmpDesc1->limit - len; + tmpDesc1->prev = 0x0; + tmpDesc1->next = usedKernDesc; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + if (tmpDesc1->limit > len) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->limit = tmpDesc1->limit - len; + tmpDesc1->limit = len; + tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; + tmpDesc2->next = 0x0; + tmpDesc2->prev = 0x0; + insertFreeDesc(tmpDesc2); + } + buf = (char*) tmpDesc1->baseAddr; + for (i = 0; i < tmpDesc1->limit; i++) { + buf[i] = (char) 0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("m1[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + assert(tmpDesc1->baseAddr); + return (tmpDesc1->baseAddr); + } + } + tmpDesc1 = getEmptyDesc(); + //kprintf("no empty desc\n"); + if (tmpDesc1 != 0x0) { + pages = ((len + 4095) / 4096); + tmpDesc1->baseAddr = (struct memDescriptor*) vmm_getFreeMallocPage(pages); tmpDesc1->limit = len; - tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; - tmpDesc2->next = 0x0; - tmpDesc2->prev = 0x0; - insertFreeDesc(tmpDesc2); - } - buf = (char *) tmpDesc1->baseAddr; - for (i = 0; i < tmpDesc1->limit; i++) { - buf[i] = (char) 0x0; - } - spinUnlock(&mallocSpinLock); - //kprintf("m1[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); - assert(tmpDesc1->baseAddr); - return (tmpDesc1->baseAddr); - } - } - tmpDesc1 = getEmptyDesc(); - //kprintf("no empty desc\n"); - if (tmpDesc1 != 0x0) { - pages = ((len + 4095) / 4096); - tmpDesc1->baseAddr = (struct memDescriptor *) vmm_getFreeMallocPage(pages); - tmpDesc1->limit = len; - tmpDesc1->next = usedKernDesc; - tmpDesc1->prev = 0x0; - if (usedKernDesc != 0x0) - usedKernDesc->prev = tmpDesc1; - usedKernDesc = tmpDesc1; + tmpDesc1->next = usedKernDesc; + tmpDesc1->prev = 0x0; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; - if (((pages * 4096) - len) > 0x0) { - tmpDesc2 = getEmptyDesc(); - assert(tmpDesc2); - tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; - tmpDesc2->limit = ((pages * 4096) - len); - tmpDesc2->prev = 0x0; - tmpDesc2->next = 0x0; - if (tmpDesc2->limit <= 0x0) - kprintf("kmalloc-2 tmpDesc2: [%i]\n", tmpDesc2->limit); - insertFreeDesc(tmpDesc2); - } + if (((pages * 4096) - len) > 0x0) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; + tmpDesc2->limit = ((pages * 4096) - len); + tmpDesc2->prev = 0x0; + tmpDesc2->next = 0x0; + if (tmpDesc2->limit <= 0x0) + kprintf("kmalloc-2 tmpDesc2: [%i]\n", tmpDesc2->limit); + insertFreeDesc(tmpDesc2); + } - buf = (char *) tmpDesc1->baseAddr; - for (i = 0; i < tmpDesc1->limit; i++) { - buf[i] = (char) 0x0; + buf = (char*) tmpDesc1->baseAddr; + for (i = 0; i < tmpDesc1->limit; i++) { + buf[i] = (char) 0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); + //kprintf("m2[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + assert(tmpDesc1->baseAddr); + return (tmpDesc1->baseAddr); } + //Return Null If Unable To Malloc spinUnlock(&mallocSpinLock); - //kprintf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); - //kprintf("m2[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); - assert(tmpDesc1->baseAddr); - return (tmpDesc1->baseAddr); - } - //Return Null If Unable To Malloc - spinUnlock(&mallocSpinLock); - //kprintf("baseAddr3[0x0]"); - return (0x0); + //kprintf("baseAddr3[0x0]"); + return (0x0); } /************************************************************************ @@ -345,45 +345,46 @@ ************************************************************************/ void kfree(void *baseAddr) { - struct memDescriptor *tmpDesc = 0x0; + struct memDescriptor *tmpDesc = 0x0; - if (baseAddr == 0x0) - return; - assert(baseAddr); + if (baseAddr == 0x0) + return; + assert(baseAddr); - assert(usedKernDesc); - spinLock(&mallocSpinLock); + assert(usedKernDesc); + spinLock(&mallocSpinLock); - for (tmpDesc = usedKernDesc; tmpDesc != 0x0; tmpDesc = tmpDesc->next) { + for (tmpDesc = usedKernDesc; tmpDesc != 0x0; tmpDesc = tmpDesc->next) { - if (tmpDesc->baseAddr == baseAddr) { - memset(tmpDesc->baseAddr, 0xBE, tmpDesc->limit); + if (tmpDesc->baseAddr == baseAddr) { + memset(tmpDesc->baseAddr, 0xBE, tmpDesc->limit); - if (usedKernDesc == tmpDesc) - usedKernDesc = tmpDesc->next; + if (usedKernDesc == tmpDesc) + usedKernDesc = tmpDesc->next; - if (tmpDesc->prev != 0x0) - tmpDesc->prev->next = tmpDesc->next; + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = tmpDesc->next; - if (tmpDesc->next != 0x0) - tmpDesc->next->prev = tmpDesc->prev; + if (tmpDesc->next != 0x0) + tmpDesc->next->prev = tmpDesc->prev; - tmpDesc->next = 0x0; - tmpDesc->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; - if (tmpDesc->limit <= 0x0) - kprintf("kfree tmpDesc1: [%i]\n", tmpDesc->limit); - //kprintf("{0x%X}",tmpDesc->baseAddr); - insertFreeDesc(tmpDesc); + if (tmpDesc->limit <= 0x0) + kprintf("kfree tmpDesc1: [%i]\n", tmpDesc->limit); - // mergeMemBlocks(); - spinUnlock(&mallocSpinLock); - return; + //kprintf("{0x%X}",tmpDesc->baseAddr); + insertFreeDesc(tmpDesc); + + // mergeMemBlocks(); + spinUnlock(&mallocSpinLock); + return; + } } - } - spinUnlock(&mallocSpinLock); - kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n", (uInt32) baseAddr); - return; + spinUnlock(&mallocSpinLock); + kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n", (uInt32) baseAddr); + return; } /*** diff --git a/sys/vmm/vmm_mmap.c b/sys/vmm/vmm_mmap.c index af40b90..fbfac3a 100644 --- a/sys/vmm/vmm_mmap.c +++ b/sys/vmm/vmm_mmap.c @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -34,187 +35,152 @@ #include #include -/* MrOlsen (2016-01-15) TEMP: Put These somewhere else */ -typedef __uint32_t __vm_size_t; typedef __vm_size_t -vm_size_t; -#define EINVAL 22 /* Invalid argument */ -#define MAP_ALIGNED(n) ((n) << MAP_ALIGNMENT_SHIFT) -#define MAP_ALIGNMENT_SHIFT 24 -#define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff) -#define MAP_ALIGNED_SUPER MAP_ALIGNED(1) /* align on a superpage */ -#define NBBY 8 /* number of bits in a byte */ - -/* PROTs */ -#define PROT_NONE 0x00 /* no permissions */ -#define PROT_READ 0x01 /* pages can be read */ -#define PROT_WRITE 0x02 /* pages can be written */ -#define PROT_EXEC 0x04 /* pages can be executed */ - -/* FLAGs */ - -/* - * Do I Need These? - */ -#define MAP_SHARED 0x0001 /* share changes */ -#define MAP_PRIVATE 0x0002 /* changes are private */ -#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ -#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ -#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ -#define MAP_RESERVED0080 0x0080 /* previously misimplemented MAP_INHERIT */ -#define MAP_RESERVED0100 0x0100 /* previously unimplemented MAP_NOEXTEND */ -#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ -#define MAP_STACK 0x0400 /* region grows down, like a stack */ -#define MAP_NOSYNC 0x0800 /* page to but do not sync underlying file */ - -/* - * Mapping type - */ -#define MAP_FILE 0x0000 /* map from file (default) */ -#define MAP_ANON 0x1000 /* allocated from memory, swap space */ - int freebsd6_mmap(struct thread *td, struct freebsd6_mmap_args *uap) { - vm_size_t size, pageoff; - off_t pos; - int align, flags, error; - vm_offset_t addr; + vm_size_t size, pageoff; + off_t pos; + int align, flags, error; + vm_offset_t addr; - int i; + int i; - error = 0; + error = 0; - size = uap->len; - flags = uap->flags; - pos = uap->pos; + size = uap->len; + flags = uap->flags; + pos = uap->pos; - kprintf("uap->flags: [0x%X]\n", uap->flags); - kprintf("uap->addr: [0x%X]\n", uap->addr); - kprintf("uap->len: [0x%X]\n", uap->len); - kprintf("uap->prot: [0x%X]\n", uap->prot); - kprintf("uap->fd: [%i]\n", uap->fd); - kprintf("uap->pad: [0x%X]\n", uap->pad); - kprintf("uap->pos: [0x%X]\n", uap->pos); + kprintf("uap->flags: [0x%X]\n", uap->flags); + kprintf("uap->addr: [0x%X]\n", uap->addr); + kprintf("uap->len: [0x%X]\n", uap->len); + kprintf("uap->prot: [0x%X]\n", uap->prot); + kprintf("uap->fd: [%i]\n", uap->fd); + kprintf("uap->pad: [0x%X]\n", uap->pad); + kprintf("uap->pos: [0x%X]\n", uap->pos); - if ((uap->flags & MAP_ANON) != 0) - pos = 0; - - /* - * Align the file position to a page boundary, - * and save its page offset component. - */ - - pageoff = (pos & PAGE_MASK); - pos -= pageoff; - - /* Adjust size for rounding (on both ends). */ - size += pageoff; - size = (vm_size_t) round_page(size); - - /* Ensure alignment is at least a page and fits in a pointer. */ - align = flags & MAP_ALIGNMENT_MASK; - if (align != 0 && align != MAP_ALIGNED_SUPER && (align >> MAP_ALIGNMENT_SHIFT >= sizeof(void *) * NBBY || align >> MAP_ALIGNMENT_SHIFT < PAGE_SHIFT)) - return (EINVAL); - - if (flags & MAP_FIXED) { - kprintf("FIXED NOT SUPPORTED YET"); - return (EINVAL); - } - else { - /* At Some Point I Need To Proc Lock Incase It's Threaded */ - /* MrOlsen (2016-01-15) Temporary comment out - if ( addr == 0 || (addr >= round_page( (vm_offset_t) vms->vm_taddr ) && addr < round_page( (vm_offset_t) vms->vm_daddr + lim_max( td->td_proc, RLIMIT_DATA ) )) ) - addr = round_page( (vm_offset_t) vms->vm_daddr + lim_max( td->td_proc, RLIMIT_DATA ) ); - */ - } - - if (flags & MAP_ANON) { - /* - * Mapping blank space is trivial. - */ + if ((uap->flags & MAP_ANON) != 0) + pos = 0; /* - handle = NULL; - handle_type = OBJT_DEFAULT; - maxprot = VM_PROT_ALL; - cap_maxprot = VM_PROT_ALL; + * Align the file position to a page boundary, + * and save its page offset component. */ - for (i = addr; i < (addr + size); i += 0x1000) { - if (vmm_remapPage(vmm_findFreePage(_current->id), i, PAGE_DEFAULT, _current->id, 0) == 0x0) - K_PANIC("remap Failed"); + + pageoff = (pos & PAGE_MASK); + pos -= pageoff; + + /* Adjust size for rounding (on both ends). */ + size += pageoff; + size = (vm_size_t) round_page(size); + + /* Ensure alignment is at least a page and fits in a pointer. */ + align = flags & MAP_ALIGNMENT_MASK; + if (align != 0 && align != MAP_ALIGNED_SUPER && (align >> MAP_ALIGNMENT_SHIFT >= sizeof(void*) * NBBY || align >> MAP_ALIGNMENT_SHIFT < PAGE_SHIFT)) + return (EINVAL); + + if (flags & MAP_FIXED) { + kprintf("FIXED NOT SUPPORTED YET"); + return (EINVAL); } - kprintf("td->vm_dsize should be adjust but isn't"); - } - else { - /* Mapping File */ - kprintf("File Mapping Not Supported Yet"); - return (EINVAL); - } + else { + /* At Some Point I Need To Proc Lock Incase It's Threaded */ + /* MrOlsen (2016-01-15) Temporary comment out + if ( addr == 0 || (addr >= round_page( (vm_offset_t) vms->vm_taddr ) && addr < round_page( (vm_offset_t) vms->vm_daddr + lim_max( td->td_proc, RLIMIT_DATA ) )) ) + addr = round_page( (vm_offset_t) vms->vm_daddr + lim_max( td->td_proc, RLIMIT_DATA ) ); + */ + } - return (0x0); + if (flags & MAP_ANON) { + /* + * Mapping blank space is trivial. + */ + + /* + handle = NULL; + handle_type = OBJT_DEFAULT; + maxprot = VM_PROT_ALL; + cap_maxprot = VM_PROT_ALL; + */ + for (i = addr; i < (addr + size); i += 0x1000) { + if (vmm_remapPage(vmm_findFreePage(_current->id), i, PAGE_DEFAULT, _current->id, 0) == 0x0) + K_PANIC("remap Failed"); + } + kprintf("td->vm_dsize should be adjust but isn't"); + } + else { + /* Mapping File */ + kprintf("File Mapping Not Supported Yet"); + return (EINVAL); + } + + return (0x0); } int sys_munmap(struct thread *td, struct sys_munmap_args *uap) { - //TEMP - td->td_retval[0] = 0; - return (0); + //TEMP + kprintf("[%s:%i] munmap", __FILE__, __LINE__); + td->td_retval[0] = 0; + return (0); } -; + int sys_mmap(struct thread *td, struct sys_mmap_args *uap) { - vm_offset_t addr = 0x0; - char *tmp = 0x0; - struct file *fd = 0x0; - int x; + vm_offset_t addr = 0x0; + char *tmp = 0x0; + struct file *fd = 0x0; + int x; - addr = (vm_offset_t) uap->addr; + kprintf("[%s:%i] mmap", __FILE__, __LINE__); - if (uap->fd == -1) { - if (uap->addr != 0x0) { - for (x = 0x0; x < round_page(uap->len); x += 0x1000) { - vmm_unmapPage(((uint32_t) uap->addr & 0xFFFFF000) + x, VMM_FREE); - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), (((uint32_t) uap->addr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) - K_PANIC("Remap Page Failed"); + addr = (vm_offset_t) uap->addr; - } - tmp = uap->addr; - bzero(tmp, uap->len); - td->td_retval[0] = (uint32_t) tmp; - return (0x0); + if (uap->fd == -1) { + if (uap->addr != 0x0) { + for (x = 0x0; x < round_page(uap->len); x += 0x1000) { + vmm_unmapPage(((uint32_t) uap->addr & 0xFFFFF000) + x, VMM_FREE); + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), (((uint32_t) uap->addr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) + K_PANIC("Remap Page Failed"); + + } + tmp = uap->addr; + bzero(tmp, uap->len); + td->td_retval[0] = (uint32_t) tmp; + return (0x0); + } + + td->td_retval[0] = vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_TASK); + bzero(td->td_retval[0], uap->len); + return (0x0); //vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_THRD)); } - - td->td_retval[0] = vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_TASK); - bzero(td->td_retval[0], uap->len); - return (0x0); //vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_THRD)); - } - else { - - getfd(td, &fd, uap->fd); - - if (uap->addr == 0x0) - tmp = (char *) vmm_getFreeVirtualPage(_current->id, round_page(uap->len) / 0x1000, VM_TASK); else { - for (x = 0x0; x < round_page(uap->len); x += 0x1000) { + getfd(td, &fd, uap->fd); - vmm_unmapPage(((uint32_t) uap->addr & 0xFFFFF000) + x, 1); + if (uap->addr == 0x0) + tmp = (char*) vmm_getFreeVirtualPage(_current->id, round_page(uap->len) / 0x1000, VM_TASK); + else { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), (((uint32_t) uap->addr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) - K_PANIC("Remap Page Failed"); + for (x = 0x0; x < round_page(uap->len); x += 0x1000) { - } + vmm_unmapPage(((uint32_t) uap->addr & 0xFFFFF000) + x, 1); - tmp = uap->addr; + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), (((uint32_t) uap->addr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) + K_PANIC("Remap Page Failed"); - } + } + + tmp = uap->addr; + + } kern_fseek(fd->fd, uap->pos, 0x0); - fread(tmp, uap->len, 0x1, fd->fd); + fread(tmp, uap->len, 0x1, fd->fd); - td->td_retval[0] = (uint32_t) tmp; + td->td_retval[0] = (uint32_t) tmp; - if (td->td_retval[0] == (caddr_t) -1) - kpanic("MMAP_FAILED"); - } - return (0x0); + if (td->td_retval[0] == (caddr_t) -1) + kpanic("MMAP_FAILED"); + } + return (0x0); }