The _most_ basic memory managment

This commit is contained in:
Robbe Van Herck 2020-01-07 14:53:27 +01:00
parent b5678a0246
commit 6aba1fb4a8
No known key found for this signature in database
GPG key ID: A66F76F7B81BD784
2 changed files with 31 additions and 2 deletions

View file

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include "terminal.c" #include "terminal.c"
#include "memory.c"
/* Check if the compiler thinks you are targeting the wrong operating system. */ /* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__) #if defined(__linux__)
@ -14,6 +15,11 @@
#error "This tutorial needs to be compiled with a ix86-elf compiler" #error "This tutorial needs to be compiled with a ix86-elf compiler"
#endif #endif
struct person {
long id;
int age;
char gender;
};
void kernel_main(void) void kernel_main(void)
{ {
@ -26,10 +32,24 @@ void kernel_main(void)
terminal_putchar('l'); terminal_putchar('l');
terminal_putchar('o'); terminal_putchar('o');
/* Newline support is left as an exercise. */
terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK));
terminal_writestring(" kernel"); terminal_writestring(" kernel");
terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK)); terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
terminal_writestring(" World!\n"); terminal_writestring(" World!\n");
terminal_writestring("Newlines!"); terminal_writestring("Newlines!\n");
char* memory_str = alloc(sizeof(char) * 7);
for (int i = 0; i < 6; i++) {
memory_str[i] = "Memory"[i];
}
memory_str[6] = 0;
char* management_str = alloc(sizeof(char) * 13);
for (int i = 0; i < 12; i++) {
management_str[i] = " management!"[i];
}
management_str[12] = 0;
terminal_writestring(memory_str);
terminal_writestring(management_str);
} }

9
kernel/memory.c Normal file
View file

@ -0,0 +1,9 @@
#include <stddef.h>
void* _curr_end = (void*) 0x10000;
void* alloc(size_t size) {
void* thanks_jp = _curr_end;
_curr_end += size;
return thanks_jp;
}