Got the string concat funcion working.
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
#ifndef BUILD_NUMBER
|
#ifndef BUILD_NUMBER
|
||||||
#define BUILD_NUMBER "276"
|
#define BUILD_NUMBER "349"
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERSION_STR
|
#ifndef VERSION_STR
|
||||||
#define VERSION_STR "0.0.2+276 - Sat 31 Aug 2019 05:43:54 PM CDT"
|
#define VERSION_STR "0.0.2+349 - Sun 01 Sep 2019 03:15:31 PM CDT"
|
||||||
#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+276";
|
unsigned char* version_str_short = "0.0.2+349";
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ typedef struct MemoryChunk
|
|||||||
struct MemoryChunk* Prev;
|
struct MemoryChunk* Prev;
|
||||||
struct MemoryChunk* Next;
|
struct MemoryChunk* Next;
|
||||||
size_t Size;
|
size_t Size;
|
||||||
bool Allocated;
|
bool Allocated;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct MemoryChunk* First;
|
static struct MemoryChunk* First;
|
||||||
@@ -19,4 +19,4 @@ void* Malloc(size_t size);
|
|||||||
|
|
||||||
void Free(void* ptr);
|
void Free(void* ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-1
@@ -6,6 +6,7 @@ typedef unsigned int size_t;
|
|||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
/* MAIN.C */
|
/* MAIN.C */
|
||||||
extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
|
extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
|
||||||
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
|
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
|
||||||
@@ -36,4 +37,4 @@ void timer_handler(struct regs *r);
|
|||||||
void timer_install();
|
void timer_install();
|
||||||
/* KB.C */
|
/* KB.C */
|
||||||
void kb_install();
|
void kb_install();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ objects = obj/start.o \
|
|||||||
obj/shell.o \
|
obj/shell.o \
|
||||||
obj/memorymanager.o \
|
obj/memorymanager.o \
|
||||||
obj/pci.o \
|
obj/pci.o \
|
||||||
obj/port.o
|
obj/port.o \
|
||||||
|
|
||||||
run:kernel.iso
|
run:kernel.iso
|
||||||
qemu-system-x86_64 -m 256M -cdrom kernel.iso &
|
qemu-system-x86_64 -m 256M -cdrom kernel.iso &
|
||||||
|
|||||||
+51
-34
@@ -111,27 +111,17 @@ int string_to_int(char* str)
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Not working
|
|
||||||
unsigned char strconcat(unsigned char* dest, unsigned char* src)
|
unsigned char strconcat(unsigned char* dest, unsigned char* src)
|
||||||
{
|
{
|
||||||
//char *temp = (char *)dest;
|
|
||||||
int dest_length = strlen(dest);
|
int dest_length = strlen(dest);
|
||||||
int src_length = strlen(src);
|
int src_length = strlen(src);
|
||||||
unsigned char* buffer = (unsigned char*)Malloc(1024);//dest_length + src_length + 1);
|
|
||||||
|
uint8_t* buffer = Malloc(dest_length + src_length);
|
||||||
for(uint32_t i = dest_length; i != 0; i--)
|
unsigned char str = (unsigned char*) *buffer;
|
||||||
{
|
memcpy(str, dest, dest_length);
|
||||||
buffer[i] = dest - i;
|
memcpy((str + dest_length), src, src_length + 1);
|
||||||
puts(dest--);
|
Free((void*) buffer);
|
||||||
}
|
return str;
|
||||||
puts("\n");
|
|
||||||
for(uint32_t j = 0; j < src_length; j++)
|
|
||||||
{
|
|
||||||
buffer[j + dest_length - 1] = src + j;
|
|
||||||
puts(src--);
|
|
||||||
}
|
|
||||||
puts("\n");
|
|
||||||
return buffer;// - (dest_length + src_length + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We will use this later on for reading from the I/O ports to get data
|
/* We will use this later on for reading from the I/O ports to get data
|
||||||
@@ -214,24 +204,15 @@ extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
|||||||
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* allocated = (struct MemoryChunk*) Malloc(2048);
|
|
||||||
//size_t size = allocated->Next->Size;
|
|
||||||
//if(First) puts("Yes");
|
|
||||||
//else puts("no");
|
|
||||||
puts("First next address: 0x");
|
|
||||||
puts(int_to_string(First->Next, 16));
|
|
||||||
//puts("\n");
|
|
||||||
puts("\nFirst Size: 0x");
|
|
||||||
puts(int_to_string(First->Size, 16));
|
|
||||||
puts("\n");
|
|
||||||
|
|
||||||
struct MemoryChunk* al = (struct MemoryChunk*) (Malloc(3096) - sizeof(struct MemoryChunk));
|
struct MemoryChunk* al = (struct MemoryChunk*) Malloc(2984);
|
||||||
puts("AL size: (0x)");
|
struct MemoryChunk* al2 = (struct MemoryChunk*) Malloc(3984);
|
||||||
puts(int_to_string(al->Size, 10));
|
//for(int i = 0; i < 600; i++)
|
||||||
puts("\n");
|
//{
|
||||||
puts("First next address: 0x");
|
// target[i] = 9;
|
||||||
puts(int_to_string(First->Next, 16));
|
//}
|
||||||
puts("\n");
|
Free((void*) al);
|
||||||
|
Free((void*) al2);
|
||||||
|
|
||||||
idt_install();
|
idt_install();
|
||||||
puts("Interrupt Descriptor Table initialized.\n");
|
puts("Interrupt Descriptor Table initialized.\n");
|
||||||
@@ -253,12 +234,17 @@ extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
|||||||
puts("Compile Date ");
|
puts("Compile Date ");
|
||||||
puts(__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("Hello ", "World!\n"));
|
||||||
//puts(strconcat("Concat test ", "number 2\n"));
|
//puts(strconcat("Concat test ", "number 2\n"));
|
||||||
//puts(__DATE__);
|
//puts(__DATE__);
|
||||||
//puts("\n");
|
//puts("\n");
|
||||||
//puts(__TIME__);
|
//puts(__TIME__);
|
||||||
//puts("\n");
|
//puts("\n");
|
||||||
|
puts("Setting up paging\n");
|
||||||
|
//setupstuff();
|
||||||
run_shell();
|
run_shell();
|
||||||
//puts(&__BUILD_DATE);
|
//puts(&__BUILD_DATE);
|
||||||
//puts(&__BUILD_NUMBER);
|
//puts(&__BUILD_NUMBER);
|
||||||
@@ -271,3 +257,34 @@ void idle(void)
|
|||||||
asm("hlt");
|
asm("hlt");
|
||||||
//__asm__ __volatile__ ("hlt");
|
//__asm__ __volatile__ ("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupstuff()
|
||||||
|
{
|
||||||
|
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 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*/
|
||||||
|
}
|
||||||
|
|||||||
+15
-3
@@ -59,22 +59,34 @@ 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 + sizeof(struct MemoryChunk), 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)
|
||||||
{
|
{
|
||||||
struct MemoryChunk* chunk = (struct MemoryChunk*)((size_t) ptr - sizeof(struct MemoryChunk));
|
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;
|
chunk->Allocated = false;
|
||||||
|
|
||||||
if(chunk->Prev != 0 && !chunk->Prev->Allocated)
|
if(chunk->Prev != 0 && !chunk->Prev->Allocated)
|
||||||
{
|
{
|
||||||
chunk->Prev->Next = chunk->Next;
|
chunk->Prev->Next = chunk->Next;
|
||||||
|
chunk->Prev->Size += chunk->Size + sizeof(struct MemoryChunk);
|
||||||
|
if(chunk->Next != 0)
|
||||||
|
chunk->Next->Prev = chunk->Prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chunk->Next != 0 && !chunk->Next->Allocated)
|
||||||
|
{
|
||||||
|
chunk->Size += chunk->Next->Size + sizeof(struct MemoryChunk);
|
||||||
|
chunk->Next = chunk->Next->Next;
|
||||||
|
if(chunk->Next != 0)
|
||||||
|
chunk->Next->Prev = chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -104,7 +104,19 @@ void execmd()
|
|||||||
|
|
||||||
void proccess_command(char *text)
|
void proccess_command(char *text)
|
||||||
{
|
{
|
||||||
int length = strlen(text);
|
int cmdlets = 0;
|
||||||
|
int length = strlen(text);
|
||||||
|
for(int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
if(text[i] == ' ')
|
||||||
|
{
|
||||||
|
puts("Whitespace found!\n");
|
||||||
|
cmdlets++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
puts(strconcat("CMDLET count: ", int_to_string(cmdlets, 10)));
|
||||||
|
unsigned char *commands[cmdlets][length];
|
||||||
|
return;
|
||||||
int currentArrayIndex = 0;
|
int currentArrayIndex = 0;
|
||||||
if(length == 0) return;
|
if(length == 0) return;
|
||||||
unsigned char *array[length];
|
unsigned char *array[length];
|
||||||
|
|||||||
Reference in New Issue
Block a user