The _most_ basic memory managment
This commit is contained in:
parent
b5678a0246
commit
6aba1fb4a8
2 changed files with 31 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "terminal.c"
|
||||
#include "memory.c"
|
||||
|
||||
/* Check if the compiler thinks you are targeting the wrong operating system. */
|
||||
#if defined(__linux__)
|
||||
|
@ -14,6 +15,11 @@
|
|||
#error "This tutorial needs to be compiled with a ix86-elf compiler"
|
||||
#endif
|
||||
|
||||
struct person {
|
||||
long id;
|
||||
int age;
|
||||
char gender;
|
||||
};
|
||||
|
||||
void kernel_main(void)
|
||||
{
|
||||
|
@ -26,10 +32,24 @@ void kernel_main(void)
|
|||
terminal_putchar('l');
|
||||
terminal_putchar('o');
|
||||
|
||||
/* Newline support is left as an exercise. */
|
||||
terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK));
|
||||
terminal_writestring(" kernel");
|
||||
terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
|
||||
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
9
kernel/memory.c
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue