diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f272a6b..0518986 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -23,6 +23,7 @@ SYS_GET_STRING_LENGTH = 15, SYS_READ_STRING = 16, SYS_DISCARD_STRING = 17, + SYS_REQUEST_MEMORY = 18, } SyscallIds; extern uint32_t getProvider(uint32_t module, char *name); diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f272a6b..0518986 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -23,6 +23,7 @@ SYS_GET_STRING_LENGTH = 15, SYS_READ_STRING = 16, SYS_DISCARD_STRING = 17, + SYS_REQUEST_MEMORY = 18, } SyscallIds; extern uint32_t getProvider(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 2ab51fa..2cb743e 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -45,3 +45,9 @@ uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } + +void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress) { + return PTR(syscall(SYS_REQUEST_MEMORY, pageCount, U32(targetAddress), + U32(physicalAddress), 0)); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f272a6b..0518986 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -23,6 +23,7 @@ SYS_GET_STRING_LENGTH = 15, SYS_READ_STRING = 16, SYS_DISCARD_STRING = 17, + SYS_REQUEST_MEMORY = 18, } SyscallIds; extern uint32_t getProvider(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 2ab51fa..2cb743e 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -45,3 +45,9 @@ uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } + +void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress) { + return PTR(syscall(SYS_REQUEST_MEMORY, pageCount, U32(targetAddress), + U32(physicalAddress), 0)); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 2c4f557..ac1f221 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("vga"); loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f272a6b..0518986 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -23,6 +23,7 @@ SYS_GET_STRING_LENGTH = 15, SYS_READ_STRING = 16, SYS_DISCARD_STRING = 17, + SYS_REQUEST_MEMORY = 18, } SyscallIds; extern uint32_t getProvider(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 2ab51fa..2cb743e 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -45,3 +45,9 @@ uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } + +void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress) { + return PTR(syscall(SYS_REQUEST_MEMORY, pageCount, U32(targetAddress), + U32(physicalAddress), 0)); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 2c4f557..ac1f221 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("vga"); loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); diff --git a/src/userland/vga/Makefile b/src/userland/vga/Makefile new file mode 100644 index 0000000..c09b032 --- /dev/null +++ b/src/userland/vga/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/vga: $(OBJS) ../../../build/hlib.o + @echo "linking user program vga driver" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/include/hlib.h b/src/include/hlib.h index 4ce58ca..2533469 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -6,6 +6,7 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) +#define NULL PTR(0) extern uint32_t installServiceProvider(char *name, int32_t(provider)(void *, uint32_t)); @@ -34,5 +35,7 @@ extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); extern uintptr_t hashString(char *string); +extern void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress); #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 36d00dd..d9ae0e1 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,8 +1,13 @@ #ifndef MEMORY_H #define MEMORY_H +#include #include +#define ADDRESS(pageId) PTR((pageId) << 12) +#define PAGE_ID(address) (U32(address) >> 12) +#define PAGE_OFFSET(address) (U32(address) & 0xFFF) + typedef struct AllocationBlock { uint8_t data[3948]; uint32_t allocatedFine[32]; @@ -34,6 +39,8 @@ uint32_t pageSearchStart; } PagingInfo; +extern PagingInfo *kernelPhysicalPages; + extern void setupMemory(); extern void reservePagesUntilPhysical(uint32_t endPageId); @@ -42,6 +49,7 @@ extern void *kernelMapPhysical(void *address); extern void *kernelMapPhysicalCount(void *address, uint32_t size); extern void *getPage(); +extern void *getPhysicalPage(); extern void *sharePage(PagingInfo *destination, void *sourceAddress, void *destinationAddress); extern void freePage(void *pageAddress); @@ -57,4 +65,10 @@ extern void *mapTemporary(void *address); extern void *getPagesCount(uint32_t size); +extern uint32_t findMultiplePages(PagingInfo *info, uint32_t size); +extern void reservePagesCount(PagingInfo *info, uint32_t startPageId, + uint32_t count); +extern void mapPage(PagingInfo *info, void *physical, void *virtual, + bool userPage); + #endif diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 9dca1f3..4332c44 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,10 +2,6 @@ #include #include -#define ADDRESS(pageId) PTR((pageId) << 12) -#define PAGE_ID(address) (U32(address) >> 12) -#define PAGE_OFFSET(address) (U32(address) & 0xFFF) - PageTableEntry *kernelCodePageTable, *kernelDataPageTable; PagingInfo *kernelPhysicalPages, *kernelVirtualPages; @@ -257,4 +253,4 @@ } while (info->isPageConnectedToNext[coarse] & fineBit); } -void freePage(void *address) {} +void freePage(void *address) { freePageFrom(kernelVirtualPages, address); } diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c new file mode 100644 index 0000000..a52ec08 --- /dev/null +++ b/src/kernel/service/memorySyscalls.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void handleRequestMemorySyscall(Syscall *call) { + Service *service = call->service; + uint32_t pageCount = call->parameters[0]; + void *target = PTR(call->parameters[1]); + void *physical = PTR(call->parameters[2]); + + uint32_t virtualStart = PAGE_ID(target); + if (!virtualStart) { + virtualStart = findMultiplePages(&service->pagingInfo, pageCount); + } + reservePagesCount(&service->pagingInfo, virtualStart, pageCount); + + if (!physical) { + for (uint32_t i = 0; i < pageCount; i++) { + uint32_t physicalPage = findPage(kernelPhysicalPages); + reservePagesCount(kernelPhysicalPages, physicalPage, 1); + mapPage(&service->pagingInfo, ADDRESS(physicalPage), + ADDRESS(virtualStart + i), true); + } + } else { + uint32_t physicalPage = PAGE_ID(physical); + reservePagesCount(kernelPhysicalPages, physicalPage, pageCount); + for (uint32_t i = 0; i < pageCount; i++) { + mapPage(&service->pagingInfo, ADDRESS(physicalPage + i), + ADDRESS(virtualStart + i), true); + } + } + call->returnValue = U32(ADDRESS(virtualStart)); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index abe9808..4ea80fc 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -58,6 +58,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; +extern uintptr_t handleRequestMemorySyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -78,6 +79,7 @@ (void *)&handleReadStringLengthSyscall, (void *)&handleReadStringSyscall, (void *)&handleDiscardStringSyscall, + (void *)&handleRequestMemorySyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index f272a6b..0518986 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -23,6 +23,7 @@ SYS_GET_STRING_LENGTH = 15, SYS_READ_STRING = 16, SYS_DISCARD_STRING = 17, + SYS_REQUEST_MEMORY = 18, } SyscallIds; extern uint32_t getProvider(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 2ab51fa..2cb743e 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -45,3 +45,9 @@ uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } + +void *requestMemory(uint32_t pageCount, void *targetAddress, + void *physicalAddress) { + return PTR(syscall(SYS_REQUEST_MEMORY, pageCount, U32(targetAddress), + U32(physicalAddress), 0)); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 2c4f557..ac1f221 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("vga"); loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); diff --git a/src/userland/vga/Makefile b/src/userland/vga/Makefile new file mode 100644 index 0000000..c09b032 --- /dev/null +++ b/src/userland/vga/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/vga: $(OBJS) ../../../build/hlib.o + @echo "linking user program vga driver" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/vga/main.c b/src/userland/vga/main.c new file mode 100644 index 0000000..007e2f4 --- /dev/null +++ b/src/userland/vga/main.c @@ -0,0 +1,9 @@ +#include +#include +#include + +int32_t main() { + uint32_t *videoSource = requestMemory(1, NULL, PTR(0xB8000)); + *videoSource = 0x07690748; + return 0; +}