Skip to content

Commit 14696be

Browse files
committed
fix bugs and improve docstrings
1 parent 4e7d5fc commit 14696be

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 4e7d5fc5f7531d9720774b37aebc1d97a38836b9
2+
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
3+
Date: Sun Aug 24 02:40:25 2025 +0700
4+
5+
feat/docs: add fib, binpow, xorshift32 functions, improve libc, update readme
6+
17
commit 8d209352971e854b05d78d786cd4c1107fee1535
28
Author: Alexeev Bronislav <alexeev.dev@mail.ru>
39
Date: Sun Aug 24 01:53:08 2025 +0700

src/kernel/cpu/isr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "idt.h"
33
#include "../drivers/screen.h"
44
#include "../drivers/keyboard.h"
5-
#include "../libc/string.h"
5+
#include "../kklibc/stdlib.h"
66
#include "timer.h"
77
#include "../drivers/lowlevel_io.h"
88

src/kernel/cpu/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "timer.h"
22
#include "isr.h"
33
#include "../drivers/lowlevel_io.h"
4-
#include "../libc/function.h"
4+
#include "../kklibc/function.h"
55

66
u32 tick = 0;
77

src/kernel/cpu/timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef TIMER_H
22
#define TIMER_H
33

4-
#include "type.h"
4+
#include "../kklibc/ctypes.h"
55

66
void init_timer(u32 freq);
77

src/kernel/drivers/keyboard.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern int shell_prompt_offset;
2222

2323
static char key_buffer[256];
2424

25+
// TODO добавить обработку lower и upper букв
26+
2527
#define SC_MAX 57
2628
const char *sc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6",
2729
"7", "8", "9", "0", "-", "=", "Backspace", "Tab", "Q", "W", "E",

src/kernel/drivers/screen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int get_offset_col(int offset);
3030
* Если col, row отрицательные, то используем текущий оффсет
3131
*/
3232
void kprint_at(char *message, int col, int row, int color) {
33-
struct { int clrcode; int color; } colors[] = {
33+
struct { int clrcode; int color; } colors[] = { // структура цветов, clrcode - код цвета для передачи и color - сам цвет
3434
{.clrcode=WHITE_ON_BLACK_CLR_CODE, .color=WHITE_ON_BLACK},
3535
{.clrcode=BLUE_ON_BLACK_CLR_CODE, .color=BLUE_ON_BLACK},
3636
{.clrcode=GREEN_ON_BLACK_CLR_CODE, .color=GREEN_ON_BLACK},

src/kernel/kklibc/stdlib.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "stdlib.h"
33
#include "stdio.h"
44

5-
u32 xorshift32(u32* state) {
5+
u32 xorshift32(u32* state) { // генератор псевдослучайных чисел xorshift32
66
u32 x = state[0];
77
x ^= x << 13;
88
x ^= x >> 17;
@@ -11,6 +11,7 @@ u32 xorshift32(u32* state) {
1111
return x;
1212
}
1313

14+
// рандомное число в диапазоне
1415
u32 rand_range(u32* state, u32 min, u32 max) {
1516
if (max < min) {
1617
return 0;
@@ -23,6 +24,7 @@ u32 rand(u32* state) {
2324
return xorshift32(state);
2425
}
2526

27+
// reboot
2628
void reboot() {
2729
unsigned char reset_value = 0x06;
2830
__asm__ __volatile__ (
@@ -33,6 +35,7 @@ void reboot() {
3335
);
3436
}
3537

38+
// wait ожидание
3639
void wait(int ms) {
3740
volatile int count;
3841
while (ms--)
@@ -45,14 +48,14 @@ void wait(int ms) {
4548
}
4649
}
4750

48-
void memory_copy(u8 *source, u8 *dest, int nbytes) {
51+
void memory_copy(u8 *source, u8 *dest, int nbytes) { // копируем память
4952
int i;
5053
for (i = 0; i < nbytes; i++) {
5154
*(dest + i) = *(source + i);
5255
}
5356
}
5457

55-
void memory_set(u8 *dest, u8 val, u32 len) {
58+
void memory_set(u8 *dest, u8 val, u32 len) { // задаем память
5659
u8 *temp = (u8 *)dest;
5760
for ( ; len != 0; len--) *temp++ = val;
5861
}
@@ -77,8 +80,7 @@ void int_to_ascii(int n, char str[]) {
7780
int strtoint(char* str) {
7881
int rc = 0;
7982
unsigned i = 0;
80-
// C guarantees that '0'-'9' have consecutive values
81-
while (str[i] >= '0' && str[i] <= '9') {
83+
while (str[i] >= '0' && str[i] <= '9') { // перевод строк в числа
8284
rc *= 10;
8385
rc += str[i] - '0';
8486
++i;
@@ -87,7 +89,7 @@ int strtoint(char* str) {
8789
return rc;
8890
}
8991

90-
void hex_to_ascii(int n, char str[]) {
92+
void hex_to_ascii(int n, char str[]) { // из hex в строку
9193
append(str, '0');
9294
append(str, 'x');
9395

@@ -108,14 +110,14 @@ void hex_to_ascii(int n, char str[]) {
108110
else append(str, tmp + '0');
109111
}
110112

111-
void strcpy(char *dest, char *src) {
113+
void strcpy(char *dest, char *src) { // копирование строки
112114
while (*src) {
113115
*dest++ = *src++;
114116
}
115117
*dest = '\0';
116118
}
117119

118-
int hex_strtoint(char *str) {
120+
int hex_strtoint(char *str) { // строка в число hex
119121
int result = 0;
120122
while (*str) {
121123
result *= 16;
@@ -128,7 +130,7 @@ int hex_strtoint(char *str) {
128130
}
129131

130132
/* K&R */
131-
void reverse(char s[]) {
133+
void reverse(char s[]) { // реверс
132134
int c, i, j;
133135
for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
134136
c = s[i];
@@ -138,19 +140,19 @@ void reverse(char s[]) {
138140
}
139141

140142
/* K&R */
141-
int strlen(char s[]) {
143+
int strlen(char s[]) { // длина строки
142144
int i = 0;
143145
while (s[i] != '\0') ++i;
144146
return i;
145147
}
146148

147-
void append(char s[], char n) {
149+
void append(char s[], char n) { // добавление новой строки в исходную
148150
int len = strlen(s);
149151
s[len] = n;
150152
s[len+1] = '\0';
151153
}
152154

153-
void backspace(char s[]) {
155+
void backspace(char s[]) { // бекспейс
154156
int len = strlen(s);
155157

156158
s[len-1] = '\0';

0 commit comments

Comments
 (0)