Arm OS comparing strings

I want to create arm os like MSDOS.
i have bootloader (strap.s)

.global _start
_start:
    ldr x0, =0x20000
    mov sp, x0
    bl notmain
hang:
    b hang

.global PUT32
PUT32:
    str w1,[x0]
    ret
    

This is 64bit booyloader which load C function from notmain.c:

#include <stdint.h>
#include "uart.h"
#include "commands.h"

#define MAX_INPUT_LENGTH 64

void notmain(void) {
    char c;
    char input_buffer[MAX_INPUT_LENGTH + 1]; // +1 для нуль-термінатора
    int input_pos = 0;

    uart_puts("UART test...n");
    uart_puts(">>>");

    while (1) {
        c = uart_getc();
        
        // Виведення кожного зчитаного символу для відладки
        uart_puts("Received char: ");
        uart_putc(c);
        uart_putc('n');

        if (c == 'r' || c == 'n') {
            uart_putc('r');
            uart_putc('n');
            input_buffer[input_pos] = ''; // Завершення рядка нуль-термінатором
            
            // Діагностика: виведення буфера перед передачею в process_command
            uart_puts("Input buffer: ");
            uart_puts(input_buffer);
            uart_putc('n');
            
            process_command(input_buffer);  // Виклик команди
            input_pos = 0; // Скидання буфера
            uart_puts(">>>");
        } else if (c == 'b' || c == 127) { // Backspace
            if (input_pos > 0) {
                input_pos--;
                uart_puts("b b"); // Видалення останнього символу з консолі
            }
        } else {
            if (input_pos < MAX_INPUT_LENGTH) {
                input_buffer[input_pos++] = c;
                uart_putc(c);  // Виведення символу на екран
            }
        }
    }
}

The provided code snippet implements the main input handling loop for a simple command-line interface in an ARM-based operating system using UART for communication.

in this code we have heade files: uart.h and commands.h

// uart.h
#ifndef UART_H
#define UART_H

#include <stdint.h>

void uart_putc(char c);
char uart_getc();
void uart_puts(const char *str);

#endif // UART_H

The uart.h header file provides the necessary declarations for UART communication functions, enabling other parts of the operating system to utilize these functions without needing to know the details of their implementation.
and i have also uart.c file

// uart.c
#include "uart.h"

#define UART0_BASE 0x09000000 
#define UART0_DR   (*(volatile uint32_t *)(UART0_BASE + 0x00)) 
#define UART0_FR   (*(volatile uint32_t *)(UART0_BASE + 0x18)) 

void uart_putc(char c){
    while(UART0_FR & (1 << 5)) {} 
    UART0_DR = c; 
}

char uart_getc(){
    while(UART0_FR & (1 << 4)) {} 
    return UART0_DR & 0xFF; 
}

void uart_puts(const char *str){
    while (*str){
        if(*str == 'n'){
            uart_putc('r');
            uart_putc('n');
            str++;
        } else {
            uart_putc(*str++);
        }
    }
}

This code provides essential functions for UART communication in the operating system, enabling the sending and receiving of individual characters and strings. This functionality is crucial for user interaction and debugging, allowing the system to communicate with users through a serial interface.

come back to commands.h:

// commands.h
#ifndef COMMANDS_H
#define COMMANDS_H

void process_command(const char *cmd);

#endif // COMMANDS_H

and i have commands.c file:

// commands.c
#include "commands.h"
#include "uart.h"
// Remove #include <string.h>

// Implement strcmp
int strcmp(const char *s1, const char *s2) {
    while (*s1 && (*s1 == *s2)) {
        s1++;
        s2++;
    }
    return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}

void process_command(const char *cmd) {
    int i = 0;
    // Skip '>' and spaces
    while (cmd[i] == '>' || cmd[i] == ' ') {
        i++;
    }

    // Extract command word
    char command[65];
    int j = 0;
    while (cmd[i] != '' && cmd[i] != ' ' && j < 64) {
        command[j++] = cmd[i++];
    }
    command[j] = '';

    // Check for "version" command
    if (strcmp(command, "version") == 0) {
        uart_puts("Version 0.1n");
    } else {
        uart_puts("Unknown commandn");
    }
}

The commands.c file provides the functionality to interpret user commands in the operating system. It includes a custom string comparison function and processes input to recognize a specific command (“version”). When the command is received, it communicates back to the user through UART, enabling interaction in a command-line interface. This design allows for easy expansion to include additional commands in the future.

i run code using wsl and use this commands:

aarch64-linux-gnu-as --warn --fatal-warnings -march=armv8-a strap.s -o strap.o
aarch64-linux-gnu-gcc -c -Wall -O2 -nostdlib -nostartfiles -ffreestanding -march=armv8-a notmain.c -o notmain.o
aarch64-linux-gnu-gcc -c -Wall -O2 -nostdlib -nostartfiles -ffreestanding -march=armv8-a uart.c -o uart.o
aarch64-linux-gnu-gcc -c -Wall -O2 -nostdlib -nostartfiles -ffreestanding -march=armv8-a commands.c -o commands.o
aarch64-linux-gnu-ld strap.o notmain.o uart.o commands.o -T memmap -o notmain.elf
aarch64-linux-gnu-objcopy notmain.elf -O binary os.bin
qemu-system-aarch64 -M virt -cpu cortex-a53 -m 128 -serial mon:stdio -kernel os.bin

but when i laucnhed code console shows me that command version is uncorrect:

How i tryed to fix it: just rewrite commands.c for debuging:

#include "commands.h"
#include "uart.h"

// Реалізація strcmp
int strcmp(const char *s1, const char *s2) {
    while (*s1 && (*s1 == *s2)) {
        s1++;
        s2++;
    }
    return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}

void process_command(const char *cmd) {
    // Виведення введеного рядка для діагностики
    uart_puts("Received command: ");
    uart_puts(cmd);
    uart_putc('n');

    // Пропуск пробілів на початку команди
    while (*cmd == ' ') {
        cmd++;
    }

    // Порівняння команди
    if (strcmp(cmd, "version") == 0) {
        uart_puts("Version 0.1n");
    } else {
        uart_puts("Unknown commandn");
    }
}

But i see that buffer is not setuped:

How i can fixed proublem whis scanning text from console and how i can set up buffer correctly?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật