Skip to main content

API Reference

Complete API reference for all Echo Kernel components and subsystems.

Table of Contents

Kernel Core

Namespace: kernel

Core kernel functionality and system control.

Functions

void main(void)

Kernel entry point. Initializes system and starts the shell.

void shutdown(void)

Safely shuts down the system using multiple methods:

  1. QEMU ACPI shutdown
  2. APM shutdown
  3. Standard ACPI shutdown
  4. Keyboard controller reset
  5. CPU halt as fallback
void sleep(int ms)

Delays execution for specified milliseconds using CPU busy-wait.

  • Parameters:
    • ms: Milliseconds to sleep

Namespace: kernel::eshell

Shell interface implementation.

Functions

void start_eshell(void)

Initializes and starts the shell interface.

void loop(void)

Main shell loop that processes user input and executes commands.

Hardware I/O

Namespace: ports

Port-based hardware I/O operations.

Constants

static constexpr uint16_t QEMU_SHUTDOWN_PORT = 0xB004

QEMU-specific ACPI shutdown port.

static constexpr uint16_t APM_SHUTDOWN_PORT = 0x604

Advanced Power Management port.

static constexpr uint16_t ACPI_SHUTDOWN_PORT = 0x4004

Standard ACPI shutdown port.

static constexpr uint16_t KBC_RESET_PORT = 0x64

Keyboard controller reset port.

Functions

static inline void outb(uint16_t port, uint8_t value)

Writes an 8-bit value to a port.

  • Parameters:
    • port: Port address
    • value: 8-bit value to write
static inline uint8_t inb(uint16_t port)

Reads an 8-bit value from a port.

  • Parameters:
    • port: Port address
  • Returns: Value read from port
static inline void outw(uint16_t port, uint16_t value)

Writes a 16-bit value to a port.

  • Parameters:
    • port: Port address
    • value: 16-bit value to write
static inline uint16_t inw(uint16_t port)

Reads a 16-bit value from a port.

  • Parameters:
    • port: Port address
  • Returns: Value read from port

Display System

Namespace: display

Screen output and text display functionality.

Constants

// Color Constants
const uint8_t CL_BLACK = 0
const uint8_t CL_BLUE = 1
const uint8_t CL_GREEN = 2
const uint8_t CL_CYAN = 3
const uint8_t CL_RED = 4
const uint8_t CL_MAGENTA = 5
const uint8_t CL_BROWN = 6
const uint8_t CL_LIGHT_GREY = 7
const uint8_t CL_DARK_GREY = 8
const uint8_t CL_LIGHT_BLUE = 9
const uint8_t CL_LIGHT_GREEN = 10
const uint8_t CL_LIGHT_CYAN = 11
const uint8_t CL_LIGHT_RED = 12
const uint8_t CL_LIGHT_MAGENTA = 13
const uint8_t CL_LIGHT_BROWN = 14
const uint8_t CL_WHITE = 15

Functions

void clear_screen(void)

Clears the screen and resets cursor position.

void print(const char* str)

Prints a string to the screen.

  • Parameters:
    • str: String to print
void printc(const char* str, uint8_t color)

Prints a colored string to the screen.

  • Parameters:
    • str: String to print
    • color: Color value from constants
void print_newline(void)

Moves cursor to the next line.

Keyboard System

Namespace: keyboard

Keyboard input handling.

Functions

char* get_input(const char* prefix)

Gets a line of input from the keyboard.

  • Parameters:
    • prefix: String to display before input
  • Returns: Input string

Library Functions

Namespace: lib

Common utility functions.

Functions

int strlen(const char* str)

Returns the length of a string.

  • Parameters:
    • str: Input string
  • Returns: String length
int strcmp(const char* str1, const char* str2)

Compares two strings.

  • Parameters:
    • str1: First string
    • str2: Second string
  • Returns: 0 if equal, non-zero if different
void memcpy(void* dest, const void* src, int count)

Copies memory from source to destination.

  • Parameters:
    • dest: Destination pointer
    • src: Source pointer
    • count: Number of bytes to copy
void memset(void* dest, char val, int count)

Sets memory to a specific value.

  • Parameters:
    • dest: Destination pointer
    • val: Value to set
    • count: Number of bytes to set

Bootloader

Functions

void boot(void)

Main boot sequence function.

  • Initializes IDT
  • Sets up display
  • Launches kernel

Standard Library

String Functions

size_t strlen(const char* str)

Returns string length.

  • Parameters: str - Input string
  • Returns: Number of characters before null terminator

int strcmp(const char* str1, const char* str2)

Compares two strings.

  • Returns:
    • 0 if equal
    • Negative value if str1 is less than str2
    • Positive value if str1 is greater than str2

char* strcpy(char* dest, const char* src)

Copies string including null terminator.

  • Returns: Pointer to dest

char* strncpy(char* dest, const char* src, size_t n)

Copies up to n characters.

  • Returns: Pointer to dest

char* strcat(char* dest, const char* src)

Concatenates strings.

  • Returns: Pointer to dest

char* strncat(char* dest, const char* src, size_t n)

Concatenates up to n characters.

  • Returns: Pointer to dest

const char* strchr(const char* str, int ch)

Finds first occurrence of character.

  • Returns: Pointer to character or nullptr

Memory Functions

void* memcpy(void* dest, const void* src, size_t n)

Copies n bytes between memory regions.

  • Returns: Pointer to dest

void* memset(void* ptr, int value, size_t n)

Fills memory with specified value.

  • Returns: Pointer to ptr

int memcmp(const void* ptr1, const void* ptr2, size_t n)

Compares memory regions.

  • Returns: 0 if equal, difference otherwise

Character Functions

bool isdigit(char c)

Checks if character is digit (0-9).

bool isalpha(char c)

Checks if character is letter (a-z, A-Z).

bool isalnum(char c)

Checks if character is alphanumeric.

bool islower(char c)

Checks if character is lowercase.

bool isupper(char c)

Checks if character is uppercase.

char tolower(char c)

Converts to lowercase.

char toupper(char c)

Converts to uppercase.

Time Functions

void sleep(uint32_t milliseconds)

Delays execution.

  • Parameters: milliseconds - Delay duration

Conversion Functions

int atoi(const char* str)

Converts string to integer.

  • Parameters: str - Number string
  • Returns: Integer value

char* itoa(int value, char* str, int base)

Converts integer to string.

  • Parameters:
    • value - Number to convert
    • str - Output buffer
    • base - Number base (2-36)
  • Returns: Pointer to str

Hardware Ports

PortDescription
0x60Keyboard Data Port
0x64Keyboard Status Port
0xb8000Video Memory Base

Memory Map

AddressUsage
0xb8000Video Memory Start
0xb8000 + SCREENSIZEVideo Memory End

Error Codes

Most functions return one of these types:

  • Boolean: true for success, false for failure
  • Pointers: nullptr for failure
  • Integers: 0 for success, non-zero for specific errors

Usage Notes

  1. Display Functions

    • Always check screen boundaries
    • Handle scrolling automatically
    • Color attributes combine foreground and background (using bit shift)
  2. Keyboard Functions

    • Initialize IDT before using keyboard
    • Check input buffer limits
    • Handle input termination (Enter key)
  3. Memory Functions

    • Verify buffer sizes
    • Check for overlap in memcpy
    • Ensure proper alignment
  4. String Functions

    • Ensure destination buffers are large enough
    • Always check for null terminators
    • Use n-variants for better safety