Skip to content

Commit fc36ce4

Browse files
committed
fix shell prompt bug, fix kernel
1 parent 34f4acc commit fc36ce4

File tree

9 files changed

+41
-9
lines changed

9 files changed

+41
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 34f4acc8359288ab92953aaaaa2d1dc4ccf9de50
2+
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
3+
Date: Sat Aug 23 03:21:09 2025 +0700
4+
5+
update shell, add free command, improve libc
6+
17
commit 0867ca069cf902e68c0ef2e5e605c32d2d0cabcc
28
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
39
Date: Fri Aug 22 22:24:39 2025 +0700

src/bootloader/bootsector.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ KERNEL_OFFSET equ 0x1000 ; Смещение в памяти, из которог
1212
mov [BOOT_DRIVE], dl ; BIOS хранит наш загрузочный диск в формате DL, поэтому
1313
; лучше запомнить это на будущее. (Помните об этом
1414
; BIOS задает нам загрузочный диск в формате "dl" при загрузке)
15-
mov bp, 0x9000 ; Устанавливаем стек
15+
mov bp, 0xA0000 ; Устанавливаем стек
1616
mov sp, bp
1717

1818
mov bx, MSG_REAL_MODE ; Печатаем сообщение

src/bootloader/switch_to32.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ init_pm: ; в PM, наши старые сегменты бесполезн
5353
mov fs, ax
5454
mov gs, ax
5555

56-
mov ebp, 0x90000 ; Обновляем позицию стека, чтобы он был на самом
56+
mov ebp, 0xF0000 ; Обновляем позицию стека, чтобы он был на самом
5757
mov esp, ebp ; верху свободного места
5858

59-
call BEGIN_PM ; Вызываем функцию из ./main.asm
59+
call BEGIN_PM

src/kernel/drivers/keyboard.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define BACKSPACE 0x0E
1818
#define ENTER 0x1C
1919

20+
extern int shell_cursor_offset;
21+
extern int shell_prompt_offset;
22+
2023
static char key_buffer[256];
2124

2225
#define SC_MAX 57
@@ -38,8 +41,17 @@ static void keyboard_callback(registers_t regs) {
3841

3942
if (scancode > SC_MAX) return;
4043
if (scancode == BACKSPACE) {
44+
if (shell_cursor_offset <= shell_prompt_offset) {
45+
return;
46+
}
47+
4148
backspace(key_buffer);
4249
kprint_backspace();
50+
51+
backspace(key_buffer);
52+
kprint_backspace();
53+
54+
shell_cursor_offset = get_cursor_offset();
4355
} else if (scancode == ENTER) {
4456
kprint("\n");
4557
user_input(key_buffer); /* функция под управлением ядра */
@@ -51,6 +63,7 @@ static void keyboard_callback(registers_t regs) {
5163
if(strlen(key_buffer) < sizeof(key_buffer) - 1) {
5264
append(key_buffer, letter);
5365
kprint(str);
66+
shell_cursor_offset += 2;
5467
} else {
5568
kprint("Keyboard buffer is overflow.");
5669
}

src/kernel/drivers/screen.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "../libc/string.h"
1717

1818
/* Декларирования частных функций */
19-
int get_cursor_offset();
2019
void set_cursor_offset(int offset);
2120
int print_char(char c, int col, int row, char attr);
2221
int get_offset(int col, int row);
@@ -105,12 +104,15 @@ void kprint_colored(char *message, int color) {
105104
}
106105

107106
void kprint_backspace() {
108-
// Вывод бекспейса (удаления символа)
109-
int offset = get_cursor_offset()-2;
107+
int offset = get_cursor_offset() - 2;
110108
int row = get_offset_row(offset);
111109
int col = get_offset_col(offset);
112-
// TODO: подумать над заменением WHITE_ON_BLACK единой переменной
113-
print_char(0x08, col, row, WHITE_ON_BLACK);
110+
111+
// print_char(0x08, col, row, WHITE_ON_BLACK);
112+
113+
print_char(' ', col, row, WHITE_ON_BLACK);
114+
115+
set_cursor_offset(offset);
114116
}
115117

116118

src/kernel/drivers/screen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#define REG_SCREEN_DATA 0x3d5
9191

9292
/* Публичное API ядра */
93+
int get_cursor_offset();
9394
void clear_screen();
9495
void halted_cpu_screen_clear();
9596
void kprint_at(char *message, int col, int row, int color);

src/kernel/kernel/kernel.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "../libc/mem.h"
1616
#include "../libc/string.h"
1717

18+
int shell_cursor_offset = 0;
19+
int shell_prompt_offset = 0;
20+
1821
void kmain() {
1922
// Запускаемая функция ядра //
2023
clear_screen();
@@ -67,7 +70,7 @@ void user_input(char *input) {
6770
{.text="MEMDUMP", .hint="Dump memory", .command=&mem_dump},
6871
{.text="MALLOC", .hint="Alloc memory. Usage: MALLOC <size>", .command=&kmalloc_command},
6972
{.text="FREE", .hint="Free memory. Usage: FREE <address>", .command=&free_command},
70-
{.text="ECHO", .hint="Echo an text", .command=&echo_command}
73+
{.text="ECHO", .hint="Echo an text", .command=&echo_command},
7174
};
7275

7376
int executed = 0;
@@ -98,4 +101,7 @@ void user_input(char *input) {
98101

99102
// Вывод строки шелла
100103
kprint("\n!#> ");
104+
105+
shell_cursor_offset = get_cursor_offset(); // get_cursor_offset из screen.c
106+
shell_prompt_offset = shell_cursor_offset;
101107
}

src/kernel/kernel/kernel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
void user_input(char *input);
55

6+
extern int shell_cursor_offset;
7+
extern int shell_prompt_offset;
8+
69
#endif

src/kernel/libc/string.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void append(char s[], char n) {
9696

9797
void backspace(char s[]) {
9898
int len = strlen(s);
99+
99100
s[len-1] = '\0';
100101
}
101102

0 commit comments

Comments
 (0)