<pre>#include <stdbool.h> #include <kernel/tty.h> #include <stdint.h> #include <stdio.h> #include <stddef.h> #include <string.h> #include <stdarg.h> #include "GDTandIDT.h" #include "mm.h" #include "schedule.h" #include "fs.h" #include "initrd.h" #define MAX_INPUT_LENGTH 256 char read_char() {} void print_char(char c) {} int strcmp(const char* str1, const char* str2) { while (*str1 && (*str1 == *str2)) { str1++; str2++; } return *(unsigned char*)str1 - *(unsigned char*)str2; } void read_command(char* buffer, size_t size) { size_t i = 0; char c; while (i < size - 1 && (c = read_char()) != '\n') { buffer[i++] = c; print_char(c); } buffer[i] = '\0'; print_char('\n'); } void execute_command(char* command) { if (strcmp(command, "help") == 0) { printf("Available commands:\n"); printf(" - help: Display available commands\n"); printf(" - version: Display kernel version\n"); } else if (strcmp(command, "version") == 0) { printf("Kernel version 1.0\n"); } else { printf("Unknown command. Type 'help' to see available commands.\n"); } } void print_prompt() { printf("> "); } void kernel_main(void) { init_gdt(); init_idt(); terminal_initialize(); init_dynamic_mem(); size_t allocation_size = 1024; void* allocated_memory; int allocation_count = 0; char command[MAX_INPUT_LENGTH]; while ((allocated_memory = malloc(allocation_size)) != NULL) { allocation_count++; allocation_size *= 2; } if (allocated_memory != NULL) { *(int*)allocated_memory = 42; } free(allocated_memory); while (1) { print_prompt(); read_command(command, MAX_INPUT_LENGTH); execute_command(command); schedule(); kbd(); } }
read_char
print_char
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)