Probably the final commit for this, only so this commit can be pushed to the new Gitea server.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -1,10 +1,10 @@
|
|||||||
#ifndef BUILD_NUMBER
|
#ifndef BUILD_NUMBER
|
||||||
#define BUILD_NUMBER "349"
|
#define BUILD_NUMBER "389"
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERSION_STR
|
#ifndef VERSION_STR
|
||||||
#define VERSION_STR "0.0.2+349 - Sun 01 Sep 2019 03:15:31 PM CDT"
|
#define VERSION_STR "0.0.2+389 - Fri Dec 4 12:05:33 AM CST 2020"
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERSION_STR_SHORT
|
#ifndef VERSION_STR_SHORT
|
||||||
#define VERSION_STR_SHORT
|
#define VERSION_STR_SHORT
|
||||||
unsigned char* version_str_short = "0.0.2+349";
|
unsigned char* version_str_short = "0.0.2+389";
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef STRING_H
|
||||||
|
#define STRING_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+64
-67
@@ -77,10 +77,20 @@ bool strcmpstart(char* str1, char* str2)
|
|||||||
char* int_to_string(unsigned int value, int base)
|
char* int_to_string(unsigned int value, int base)
|
||||||
{
|
{
|
||||||
static char buf[32] = {0};
|
static char buf[32] = {0};
|
||||||
|
//void* ptr = Malloc(32);
|
||||||
|
//if(ptr == 0)
|
||||||
|
//{
|
||||||
|
//puts("Malloc failed to allocate!\n");
|
||||||
|
//return "";
|
||||||
|
//}
|
||||||
|
|
||||||
|
//char buf = (char*) ptr;
|
||||||
|
|
||||||
if(value == 0)
|
if(value == 0)
|
||||||
{
|
{
|
||||||
buf[0] = '0';
|
buf[0] = '0';
|
||||||
|
//*buf++ = '0';
|
||||||
|
//return buf;
|
||||||
return &buf[0];
|
return &buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,9 +98,12 @@ char* int_to_string(unsigned int value, int base)
|
|||||||
|
|
||||||
for(; value && i; --i, value /= base)
|
for(; value && i; --i, value /= base)
|
||||||
{
|
{
|
||||||
|
//*buf++ = "0123456789ABCDEF"[value % base];
|
||||||
buf[i] = "0123456789ABCDEF"[value % base];
|
buf[i] = "0123456789ABCDEF"[value % base];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Free(ptr);
|
||||||
|
//return buf;
|
||||||
return &buf[i+1];
|
return &buf[i+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,20 +156,39 @@ void outportb (unsigned short _port, unsigned char _data)
|
|||||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char setupstuff()
|
||||||
|
{
|
||||||
|
uint8_t* buffer = Malloc(4096);
|
||||||
|
unsigned char str = (unsigned char*) *buffer;
|
||||||
|
//str = "Top kek";
|
||||||
|
memcpy(str, "Top kek", 8);
|
||||||
|
puts("From inside the method:\n");
|
||||||
|
puts(str);
|
||||||
|
puts("\n");
|
||||||
|
Free((void*) buffer);
|
||||||
|
uint8_t* buffer2 = Malloc(4096);
|
||||||
|
unsigned char str2 = *buffer2;
|
||||||
|
//str2 = "Even more memey then the last";
|
||||||
|
memcpy(str2, "More memes", 11);
|
||||||
|
Free(buffer2);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
//extern void* _sys_stack;
|
//extern void* _sys_stack;
|
||||||
|
|
||||||
extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
||||||
{
|
{
|
||||||
init_video();
|
init_video();
|
||||||
puts("Video initialized.\n");
|
puts("Video initialized.\n");
|
||||||
register int base asm("ebp");
|
//register int base asm("ebp");
|
||||||
puts("Base pointer address: ");
|
//puts("Base pointer address: ");
|
||||||
puts(int_to_string(base, 10));
|
//puts(int_to_string(base, 10));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
register int pointer asm("esp");
|
//register int pointer asm("esp");
|
||||||
puts("Instruction pointer address: 0x");
|
//puts("Instruction pointer address: 0x");
|
||||||
puts(int_to_string(pointer, 16));
|
//puts(int_to_string(pointer, 16));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
//Only for testing if the multiboot structure can be read or not.
|
//Only for testing if the multiboot structure can be read or not.
|
||||||
if(multiboot_magic == 0x2BADB002)
|
if(multiboot_magic == 0x2BADB002)
|
||||||
{
|
{
|
||||||
@@ -188,31 +220,23 @@ extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
|||||||
puts(int_to_string(multiboot_structure, 16));
|
puts(int_to_string(multiboot_structure, 16));
|
||||||
puts("\n");
|
puts("\n");
|
||||||
uint32_t* videoBuffer = (uint32_t*)(((size_t)multiboot_structure) + 88);
|
uint32_t* videoBuffer = (uint32_t*)(((size_t)multiboot_structure) + 88);
|
||||||
puts("Framebuffer address: ");
|
//puts("Framebuffer address: ");
|
||||||
puts(int_to_string((*videoBuffer), 16));
|
//puts(int_to_string((*videoBuffer), 16));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
uint32_t* totalMem = (uint32_t*)(((size_t)multiboot_structure) + 8);
|
uint32_t* totalMem = (uint32_t*)(((size_t)multiboot_structure) + 8);
|
||||||
puts(int_to_string((*totalMem) * 1024, 10));
|
puts(int_to_string((*totalMem) * 1024, 10));
|
||||||
puts(" kilobytes of RAM installed on the system\n");
|
puts(" kilobytes of RAM installed on the system\n");
|
||||||
gdt_install();
|
gdt_install();
|
||||||
puts("Global Descriptor Table initialized.\n");
|
puts("Global Descriptor Table initialized.\n");
|
||||||
//Set a new heap to the same size as the total system memory, in bytes.
|
//Set a new heap to the same size as the total system memory, in bytes.
|
||||||
|
puts("Intializing pyscial memory manager.\n");
|
||||||
size_t heap = ((*totalMem) - 10240) * 1024;
|
size_t heap = ((*totalMem) - 10240) * 1024;
|
||||||
MemoryManager(heap, heap);//(*totalMem)*1024 - heap - 10*1024); //second needs to be an address not size
|
MemoryManager(heap, heap);//(*totalMem)*1024 - heap - 10*1024); //second needs to be an address not size
|
||||||
//puts("Mem lower: 0x");
|
//puts("Mem lower: 0x");
|
||||||
//puts(int_to_string(*(uint32_t*)(((size_t)multiboot_structure) + 4), 10));
|
//puts(int_to_string(*(uint32_t*)(((size_t)multiboot_structure) + 4), 10));
|
||||||
puts("Heap size: ");
|
//puts("Heap size: ");
|
||||||
puts(int_to_string(heap / 1024, 10));
|
//puts(int_to_string(heap / 1024, 10));
|
||||||
puts(" in kilobytes.\n");
|
//puts(" in kilobytes.\n");
|
||||||
|
|
||||||
struct MemoryChunk* al = (struct MemoryChunk*) Malloc(2984);
|
|
||||||
struct MemoryChunk* al2 = (struct MemoryChunk*) Malloc(3984);
|
|
||||||
//for(int i = 0; i < 600; i++)
|
|
||||||
//{
|
|
||||||
// target[i] = 9;
|
|
||||||
//}
|
|
||||||
Free((void*) al);
|
|
||||||
Free((void*) al2);
|
|
||||||
|
|
||||||
idt_install();
|
idt_install();
|
||||||
puts("Interrupt Descriptor Table initialized.\n");
|
puts("Interrupt Descriptor Table initialized.\n");
|
||||||
@@ -228,28 +252,25 @@ extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
|||||||
//puts("Installed Timer.\n");
|
//puts("Installed Timer.\n");
|
||||||
kb_install();
|
kb_install();
|
||||||
puts("Keyboard installed.\n");
|
puts("Keyboard installed.\n");
|
||||||
puts("SDOS Version ");
|
puts(strconcat("SDOS Version ", version_str_short));
|
||||||
puts(version_str_short);
|
puts(strconcat("\nCompile Date ", __DATE__));
|
||||||
puts(" Initialized.\n");
|
|
||||||
puts("Compile Date ");
|
|
||||||
puts(__DATE__);
|
|
||||||
puts("\n");
|
puts("\n");
|
||||||
unsigned char result = strconcat("Hello", " World!\n");
|
|
||||||
puts(result);
|
|
||||||
//Free(eh);
|
|
||||||
//puts(strconcat("Hello ", "World!\n"));
|
|
||||||
//puts(strconcat("Concat test ", "number 2\n"));
|
|
||||||
//puts(__DATE__);
|
|
||||||
//puts("\n");
|
|
||||||
//puts(__TIME__);
|
//puts(__TIME__);
|
||||||
//puts("\n");
|
//puts("\n");
|
||||||
puts("Setting up paging\n");
|
//puts("Setting up paging\n");
|
||||||
//setupstuff();
|
//setupstuff();
|
||||||
|
puts("Testing Malloc:\n");
|
||||||
|
unsigned char strr = setupstuff();
|
||||||
|
puts(strr);
|
||||||
|
puts("\n");
|
||||||
|
//puts(strconcat("\nCompile Date ", __DATE__));
|
||||||
|
//puts("\n");
|
||||||
|
|
||||||
run_shell();
|
run_shell();
|
||||||
//puts(&__BUILD_DATE);
|
//puts(&__BUILD_DATE);
|
||||||
//puts(&__BUILD_NUMBER);
|
//puts(&__BUILD_NUMBER);
|
||||||
//puts("Divide by zero check:\n");
|
puts("Divide by zero check:\n");
|
||||||
//puts(5 / 0);
|
puts(5 / 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle(void)
|
void idle(void)
|
||||||
@@ -258,33 +279,9 @@ void idle(void)
|
|||||||
//__asm__ __volatile__ ("hlt");
|
//__asm__ __volatile__ ("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupstuff()
|
void halt(void)
|
||||||
{
|
{
|
||||||
uint64_t page_dir_ptr_tab[4] __attribute__((aligned(0x20))); // must be aligned to (at least)0x20, ...
|
asm("cli");
|
||||||
// ... turning out that you can put more of them into one page, saving memory
|
asm("hlt");
|
||||||
|
|
||||||
// 512 entries
|
|
||||||
uint64_t page_dir[512] __attribute__((aligned(0x1000))); // must be aligned to page boundary
|
|
||||||
uint64_t page_tab[512] __attribute__((aligned(0x1000)));
|
|
||||||
|
|
||||||
page_dir_ptr_tab[0] = (uint64_t)&page_dir | 1; // set the page directory into the PDPT and mark it present
|
|
||||||
page_dir[0] = (uint64_t)&page_tab | 3; //set the page table into the PD and mark it present/writable
|
|
||||||
|
|
||||||
unsigned int i, address = 0;
|
|
||||||
for(i = 0; i < 512; i++)
|
|
||||||
{
|
|
||||||
page_tab[i] = address | 3; // map address and mark it present/writable
|
|
||||||
address = address + 0x1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asm volatile ("movl %cr4, %eax; bts $5, %eax; movl %eax, %cr4"); // set bit5 in CR4 to enable PAE
|
|
||||||
asm volatile ("movl %%eax, %%cr3" :: "a" (&page_dir_ptr_tab)); // load PDPT into CR3
|
|
||||||
asm volatile ("movl %cr0, %eax; orl $0x80000000, %eax; movl %eax, %cr0;");
|
|
||||||
|
|
||||||
//uint64_t * page_dir_temp = (uint64_t*) page_dir_ptr_tab[3]; // get the page directory (you should 'and' the flags away)
|
|
||||||
page_dir[511] = (uint64_t*) page_dir_ptr_tab[3];//(uint64_t)page_dir_temp; // map pd to itself
|
|
||||||
page_dir[510] = page_dir_ptr_tab[2]; // map pd3 to it
|
|
||||||
page_dir[509] = page_dir_ptr_tab[1]; // map pd2 to it
|
|
||||||
page_dir[508] = page_dir_ptr_tab[0]; // map pd1 to it
|
|
||||||
page_dir[507] = (uint64_t)&page_dir_ptr_tab; /* map the PDPT to the directory*/
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-6
@@ -58,17 +58,17 @@ void* Malloc(size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
freeChunk->Allocated = true;
|
freeChunk->Allocated = true;
|
||||||
puts("Address of new chunk: 0x");
|
//puts("Address of new chunk: 0x");
|
||||||
puts(int_to_string((size_t)freeChunk, 16));
|
//puts(int_to_string((size_t)freeChunk, 16));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
return (void*)(((size_t) freeChunk) + sizeof(struct MemoryChunk));
|
return (void*)(((size_t) freeChunk) + sizeof(struct MemoryChunk));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free(void* ptr)
|
void Free(void* ptr)
|
||||||
{
|
{
|
||||||
puts("Recieved pointer at 0x");
|
//puts("Recieved pointer at 0x");
|
||||||
puts(int_to_string(ptr - sizeof(struct MemoryChunk), 16));
|
//puts(int_to_string(ptr - sizeof(struct MemoryChunk), 16));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
struct MemoryChunk* chunk = (struct MemoryChunk*)(((size_t) ptr) - sizeof(struct MemoryChunk));
|
struct MemoryChunk* chunk = (struct MemoryChunk*)(((size_t) ptr) - sizeof(struct MemoryChunk));
|
||||||
|
|
||||||
chunk->Allocated = false;
|
chunk->Allocated = false;
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ void EnumPCISubsystem()
|
|||||||
}
|
}
|
||||||
else if(dev.VendorId != lastId)
|
else if(dev.VendorId != lastId)
|
||||||
{
|
{
|
||||||
puts("Vendor ID not empty: ");
|
//puts("Vendor ID not empty: ");
|
||||||
puts(int_to_string(dev.VendorId, 10));
|
//puts(int_to_string(dev.VendorId, 10));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
lastId = dev.VendorId;
|
//lastId = dev.VendorId;
|
||||||
}
|
}
|
||||||
//puts("PCI BUS ");
|
//puts("PCI BUS ");
|
||||||
//puts(int_to_string(bus, 16));
|
//puts(int_to_string(bus, 16));
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
void printf(char *format_string, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
|
||||||
|
va_start(arg, format_string);
|
||||||
|
|
||||||
|
va_end(arg);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include "../include/string.h"
|
||||||
|
#include "../include/system.h"
|
||||||
|
#include "../include/memorymanager.h"
|
||||||
Reference in New Issue
Block a user