Add print function, add more memory prints at startup
This commit is contained in:
parent
4f214b2d5a
commit
a042169845
2 changed files with 63 additions and 91 deletions
|
@ -2,7 +2,7 @@
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#error "You are not using a cross-compiler, you will most certainly run into trouble"
|
#error "You are not using a cross-compiler, you will most certainly run into trouble"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This tutorial will only work for the 32-bit ix86 targets. */
|
/* This tutorial will only work for the 32-bit ix86 targets. */
|
||||||
#if !defined(__i386__)
|
#if !defined(__i386__)
|
||||||
#error "This kernel needs to be compiled with a ix86-elf compiler"
|
#error "This kernel needs to be compiled with a ix86-elf compiler"
|
||||||
|
@ -16,76 +16,59 @@
|
||||||
#include "memory.c"
|
#include "memory.c"
|
||||||
#include "interrupts.c"
|
#include "interrupts.c"
|
||||||
#include "shell.c"
|
#include "shell.c"
|
||||||
|
#include "util/printer.c"
|
||||||
|
|
||||||
static inline bool are_interrupts_enabled() {
|
static inline bool are_interrupts_enabled() {
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
asm volatile ( "pushf\n\t"
|
asm volatile ( "pushf\n\t"
|
||||||
"pop %0"
|
"pop %0"
|
||||||
: "=g"(flags) );
|
: "=g"(flags));
|
||||||
return flags & (1 << 9);
|
return flags & (1 << 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kernel_main(void)
|
void kernel_main(void) {
|
||||||
{
|
/* Initialize terminal interface */
|
||||||
/* Initialize terminal interface */
|
terminal_initialize();
|
||||||
terminal_initialize();
|
|
||||||
|
terminal_putchar('H');
|
||||||
|
terminal_putchar('e');
|
||||||
|
terminal_putchar('l');
|
||||||
|
terminal_putchar('l');
|
||||||
|
terminal_putchar('o');
|
||||||
|
|
||||||
terminal_putchar('H');
|
|
||||||
terminal_putchar('e');
|
|
||||||
terminal_putchar('l');
|
|
||||||
terminal_putchar('l');
|
|
||||||
terminal_putchar('o');
|
|
||||||
|
|
||||||
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");
|
print(" 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");
|
print(" World!\n");
|
||||||
terminal_writestring("Newlines!\n");
|
print("Newlines!\n");
|
||||||
|
|
||||||
char* memory_str = alloc(sizeof(char) * 7);
|
char *memory_str = alloc(sizeof(char) * 7);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
memory_str[i] = "Memory"[i];
|
memory_str[i] = "Memory"[i];
|
||||||
}
|
}
|
||||||
memory_str[6] = 0;
|
memory_str[6] = 0;
|
||||||
|
|
||||||
char* management_str = alloc(sizeof(char) * 13);
|
char *management_str = alloc(sizeof(char) * 13);
|
||||||
for (int i = 0; i < 13; i++) {
|
for (int i = 0; i < 13; i++) {
|
||||||
management_str[i] = " management!\n"[i];
|
management_str[i] = " management!\n"[i];
|
||||||
}
|
}
|
||||||
management_str[13] = 0;
|
management_str[13] = 0;
|
||||||
|
|
||||||
|
print(memory_str);
|
||||||
|
print(management_str);
|
||||||
|
|
||||||
terminal_writestring(memory_str);
|
print("Mem after freeing\n");
|
||||||
terminal_writestring(management_str);
|
|
||||||
|
|
||||||
terminal_writestring("Mem after freeing!\n");
|
|
||||||
free(memory_str);
|
free(memory_str);
|
||||||
print_memory();
|
print_memory();
|
||||||
free(management_str);
|
free(management_str);
|
||||||
print_memory();
|
print_memory();
|
||||||
|
|
||||||
char* memory_after_free = alloc(sizeof(char) * 12);
|
|
||||||
for (int i = 0; i < 13; i++) {
|
print((are_interrupts_enabled()) ? "Interrupts!\n" : "No interrupts :(\n");
|
||||||
memory_after_free[i] = " Some text\n"[i];
|
|
||||||
|
interrupt_init();
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
shell_step();
|
||||||
}
|
}
|
||||||
memory_after_free[13] = 0;
|
|
||||||
|
|
||||||
terminal_writestring(memory_after_free);
|
|
||||||
|
|
||||||
terminal_writestring("Memory after new allocation!\n");
|
|
||||||
alloc(1000);
|
|
||||||
print_memory();
|
|
||||||
|
|
||||||
terminal_writestring("Free again\n");
|
|
||||||
free(memory_after_free);
|
|
||||||
print_memory();
|
|
||||||
|
|
||||||
|
|
||||||
terminal_writestring((are_interrupts_enabled())? "Interrupts!\n": "No interrupts :(\n");
|
|
||||||
|
|
||||||
interrupt_init();
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
shell_step();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "terminal.c"
|
#include "terminal.c"
|
||||||
|
#include "util/printer.c"
|
||||||
|
|
||||||
#define MEMORY_START 0x200000
|
#define MEMORY_START 0x200000
|
||||||
//#define MEMORY_END 0x300000
|
//#define MEMORY_END 0x300000
|
||||||
|
@ -71,45 +72,33 @@ void print_memory() {
|
||||||
page_tag *curr_page = start;
|
page_tag *curr_page = start;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (curr_page != NULL) {
|
while (curr_page != NULL) {
|
||||||
terminal_writeint(i, 10);
|
print("%d: [%x (%d)] [%x (%d)]\n",
|
||||||
terminal_write(": [", 3);
|
i,
|
||||||
terminal_writeint((int) curr_page, 16);
|
curr_page, sizeof(page_tag),
|
||||||
terminal_write(" ", 1);
|
(curr_page + 1), curr_page->size);
|
||||||
terminal_writeint(sizeof(page_tag), 10);
|
//
|
||||||
terminal_write("] [", 3);
|
// void *empty_start = (void *) curr_page + sizeof(page_tag) + curr_page->size;
|
||||||
terminal_writeint((int) (curr_page + 1), 16);
|
// if (empty_start + sizeof(page_tag) < (void *) curr_page->next) {
|
||||||
terminal_write(" ", 1);
|
// terminal_writestring("_: empty_page (");
|
||||||
terminal_writeint(curr_page->size, 10);
|
// terminal_writeint(sizeof(page_tag), 10);
|
||||||
terminal_writestring("]\n");
|
// terminal_writestring(", ");
|
||||||
|
// terminal_writeint(
|
||||||
// printf("%d: [%p (%zu)] [%p (%zu)]\n",
|
// (void *) curr_page->next -
|
||||||
// i,
|
// (empty_start + sizeof(page_tag)), 10);
|
||||||
// curr_page, sizeof(page_tag),
|
// terminal_writestring(")\n");
|
||||||
// curr_page + 1, curr_page->size);
|
//// printf("empty_page (%ld, %ld)\n",
|
||||||
|
//// sizeof(page_tag),
|
||||||
|
//// (void *) curr_page->next -
|
||||||
void *empty_start = (void *) curr_page + sizeof(page_tag) + curr_page->size;
|
//// (empty_start + sizeof(page_tag)));
|
||||||
if (empty_start + sizeof(page_tag) < (void *) curr_page->next) {
|
// } else if (empty_start < (void *) curr_page->next) {
|
||||||
terminal_writestring("empty_page (");
|
// terminal_writestring("_: not enough room (");
|
||||||
terminal_writeint(sizeof(page_tag), 10);
|
// terminal_writeint((void *) curr_page->next - empty_start, 10);
|
||||||
terminal_writestring(", ");
|
// terminal_writestring(")\n");
|
||||||
terminal_writeint(
|
//// printf("not enough room (%ld)\n",
|
||||||
(void *) curr_page->next -
|
//// (void *) curr_page->next - empty_start);
|
||||||
(empty_start + sizeof(page_tag)), 10);
|
// }
|
||||||
terminal_writestring(")\n");
|
|
||||||
// printf("empty_page (%ld, %ld)\n",
|
|
||||||
// sizeof(page_tag),
|
|
||||||
// (void *) curr_page->next -
|
|
||||||
// (empty_start + sizeof(page_tag)));
|
|
||||||
} else if (empty_start < (void *) curr_page->next) {
|
|
||||||
terminal_writestring("not enough room (");
|
|
||||||
terminal_writeint((void *) curr_page->next - empty_start, 10);
|
|
||||||
terminal_writestring(")\n");
|
|
||||||
// printf("not enough room (%ld)\n",
|
|
||||||
// (void *) curr_page->next - empty_start);
|
|
||||||
}
|
|
||||||
curr_page = curr_page->next;
|
curr_page = curr_page->next;
|
||||||
i++;
|
i += 1;
|
||||||
}
|
}
|
||||||
terminal_write("------------------\n\n", 20);
|
terminal_write("------------------\n\n", 20);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue