Probably the final commit for this, only so this commit can be pushed to the new Gitea server.

This commit is contained in:
2020-12-04 00:06:27 -06:00
parent 5b66184ea0
commit dd1bc6acdc
9 changed files with 98 additions and 83 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

+3 -3
View File
@@ -1,10 +1,10 @@
#ifndef BUILD_NUMBER
#define BUILD_NUMBER "349"
#define BUILD_NUMBER "389"
#endif
#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
#ifndef 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
+6
View File
@@ -0,0 +1,6 @@
#ifndef STRING_H
#define STRING_H
#endif
+66 -69
View File
@@ -77,10 +77,20 @@ bool strcmpstart(char* str1, char* str2)
char* int_to_string(unsigned int value, int base)
{
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)
{
buf[0] = '0';
//*buf++ = '0';
//return buf;
return &buf[0];
}
@@ -88,9 +98,12 @@ char* int_to_string(unsigned int value, int base)
for(; value && i; --i, value /= base)
{
//*buf++ = "0123456789ABCDEF"[value % base];
buf[i] = "0123456789ABCDEF"[value % base];
}
//Free(ptr);
//return buf;
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));
}
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 main(uint32_t multiboot_magic, const void* multiboot_structure)
{
init_video();
puts("Video initialized.\n");
register int base asm("ebp");
puts("Base pointer address: ");
puts(int_to_string(base, 10));
puts("\n");
register int pointer asm("esp");
puts("Instruction pointer address: 0x");
puts(int_to_string(pointer, 16));
puts("\n");
//register int base asm("ebp");
//puts("Base pointer address: ");
//puts(int_to_string(base, 10));
//puts("\n");
//register int pointer asm("esp");
//puts("Instruction pointer address: 0x");
//puts(int_to_string(pointer, 16));
//puts("\n");
//Only for testing if the multiboot structure can be read or not.
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("\n");
uint32_t* videoBuffer = (uint32_t*)(((size_t)multiboot_structure) + 88);
puts("Framebuffer address: ");
puts(int_to_string((*videoBuffer), 16));
puts("\n");
//puts("Framebuffer address: ");
//puts(int_to_string((*videoBuffer), 16));
//puts("\n");
uint32_t* totalMem = (uint32_t*)(((size_t)multiboot_structure) + 8);
puts(int_to_string((*totalMem) * 1024, 10));
puts(" kilobytes of RAM installed on the system\n");
gdt_install();
puts("Global Descriptor Table initialized.\n");
//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;
MemoryManager(heap, heap);//(*totalMem)*1024 - heap - 10*1024); //second needs to be an address not size
//puts("Mem lower: 0x");
//puts(int_to_string(*(uint32_t*)(((size_t)multiboot_structure) + 4), 10));
puts("Heap size: ");
puts(int_to_string(heap / 1024, 10));
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);
//puts("Mem lower: 0x");
//puts(int_to_string(*(uint32_t*)(((size_t)multiboot_structure) + 4), 10));
//puts("Heap size: ");
//puts(int_to_string(heap / 1024, 10));
//puts(" in kilobytes.\n");
idt_install();
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");
kb_install();
puts("Keyboard installed.\n");
puts("SDOS Version ");
puts(version_str_short);
puts(" Initialized.\n");
puts("Compile Date ");
puts(__DATE__);
puts(strconcat("SDOS Version ", version_str_short));
puts(strconcat("\nCompile Date ", __DATE__));
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("\n");
puts("Setting up paging\n");
//puts("Setting up paging\n");
//setupstuff();
puts("Testing Malloc:\n");
unsigned char strr = setupstuff();
puts(strr);
puts("\n");
//puts(strconcat("\nCompile Date ", __DATE__));
//puts("\n");
run_shell();
//puts(&__BUILD_DATE);
//puts(&__BUILD_NUMBER);
//puts("Divide by zero check:\n");
//puts(5 / 0);
puts("Divide by zero check:\n");
puts(5 / 0);
}
void idle(void)
@@ -258,33 +279,9 @@ void idle(void)
//__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, ...
// ... turning out that you can put more of them into one page, saving memory
// 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("cli");
asm("hlt");
}
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
View File
@@ -58,17 +58,17 @@ void* Malloc(size_t size)
}
freeChunk->Allocated = true;
puts("Address of new chunk: 0x");
puts(int_to_string((size_t)freeChunk, 16));
puts("\n");
//puts("Address of new chunk: 0x");
//puts(int_to_string((size_t)freeChunk, 16));
//puts("\n");
return (void*)(((size_t) freeChunk) + sizeof(struct MemoryChunk));
}
void Free(void* ptr)
{
puts("Recieved pointer at 0x");
puts(int_to_string(ptr - sizeof(struct MemoryChunk), 16));
puts("\n");
//puts("Recieved pointer at 0x");
//puts(int_to_string(ptr - sizeof(struct MemoryChunk), 16));
//puts("\n");
struct MemoryChunk* chunk = (struct MemoryChunk*)(((size_t) ptr) - sizeof(struct MemoryChunk));
chunk->Allocated = false;
+5 -5
View File
@@ -60,10 +60,10 @@ void EnumPCISubsystem()
}
else if(dev.VendorId != lastId)
{
puts("Vendor ID not empty: ");
puts(int_to_string(dev.VendorId, 10));
puts("\n");
lastId = dev.VendorId;
//puts("Vendor ID not empty: ");
//puts(int_to_string(dev.VendorId, 10));
//puts("\n");
//lastId = dev.VendorId;
}
//puts("PCI BUS ");
//puts(int_to_string(bus, 16));
@@ -100,4 +100,4 @@ struct DeviceDescriptor GetDeviceDescriptor(uint16_t busNumber, uint16_t deviceN
result.Interrupt = Read(busNumber, deviceNumber, functionNumber, 0x3C);
return result;
}
}
+9
View File
@@ -0,0 +1,9 @@
void printf(char *format_string, ...)
{
va_list arg;
va_start(arg, format_string);
va_end(arg);
}
+3
View File
@@ -0,0 +1,3 @@
#include "../include/string.h"
#include "../include/system.h"
#include "../include/memorymanager.h"