Skip to content

Commit aafe379

Browse files
authored
Merge branch 'sysprog21:main' into main
2 parents 84077f1 + 29757b6 commit aafe379

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Linmo is a preemptive, multi-tasking operating system kernel built as an educati
2222
It offers a lightweight environment where all tasks share a single address space,
2323
keeping the memory footprint to a minimum.
2424

25+
The name Linmo pays tribute to Lin Mo (林默), the mortal name of the Chinese sea goddess [Mazu](https://en.wikipedia.org/wiki/Mazu) (媽祖),
26+
who was a legendary figure from 10th-century Fujian later deified as the guardian of sailors and fishermen across the Chinese-speaking world.
27+
Just as Mazu was believed to provide calm and guidance in turbulent seas,
28+
Linmo aims to offer a structured learning environment within the constrained and often chaotic domain of embedded system education.
29+
2530
Target Platform:
2631
* RISC-V (32-bit): RV32I architecture, tested with QEMU.
2732

include/lib/libc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ char *strncat(char *s1, const char *s2, int32_t n);
7070
int32_t strcmp(const char *s1, const char *s2);
7171
int32_t strncmp(const char *s1, const char *s2, int32_t n);
7272
char *strstr(const char *s1, const char *s2);
73-
int32_t strlen(const char *s1);
73+
size_t strlen(const char *s1);
7474
char *strchr(const char *s1, int32_t c);
7575
char *strpbrk(const char *s1, const char *s2);
7676
char *strsep(char **pp, const char *delim);

include/private/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ struct error_code {
3939
char *const desc;
4040
};
4141

42-
extern struct error_code *perror;
42+
extern const struct error_code *const perror;

kernel/error.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "private/error.h"
44

55
/* Ordered by enum value for quick linear search */
6-
static struct error_code error_desc[] = {
6+
static const struct error_code error_desc[] = {
77
{ERR_OK, "no error"},
88
{ERR_FAIL, "generic failure"},
99

@@ -35,4 +35,4 @@ static struct error_code error_desc[] = {
3535
{ERR_UNKNOWN, "unknown error"},
3636
};
3737

38-
struct error_code *perror = error_desc;
38+
const struct error_code *const perror = error_desc;

lib/libc.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ static inline int byte_is_match(uint32_t w, uint32_t pat)
2020
}
2121

2222
/* strlen that scans by words whenever possible for efficiency. */
23-
int32_t strlen(const char *s)
23+
size_t strlen(const char *s)
2424
{
2525
const char *p = s;
2626

2727
/* Align pointer to word boundary (4 bytes) */
2828
while ((uint32_t) p & 3) {
2929
if (!*p) /* If null terminator is found byte-by-byte */
30-
return (int32_t) (p - s);
30+
return (size_t) (p - s);
3131
p++;
3232
}
3333

@@ -42,7 +42,7 @@ int32_t strlen(const char *s)
4242
p = (const char *) w;
4343
while (*p) /* Scan byte-by-byte until the null terminator. */
4444
p++;
45-
return (int32_t) (p - s); /* Return total length. */
45+
return (size_t) (p - s); /* Return total length. */
4646
}
4747

4848
void *memcpy(void *dst, const void *src, uint32_t len)
@@ -463,15 +463,16 @@ int32_t strtol(const char *s, char **end, int32_t base)
463463
}
464464

465465
/* Base-10 string conversion without division or multiplication */
466-
static char* __str_base10(uint32_t value, char* buffer, int* length)
466+
static char *__str_base10(uint32_t value, char *buffer, int *length)
467467
{
468468
if (value == 0) {
469469
buffer[0] = '0';
470470
*length = 1;
471471
return buffer;
472472
}
473473

474-
char temp[12]; /* Max digits for 32-bit: 4,294,967,295 (10 digits) + sign + null */
474+
/* Max digits for 32-bit: 4,294,967,295 (10 digits) + sign + null */
475+
char tmp[12];
475476
int pos = 0;
476477

477478
while (value > 0) {
@@ -487,29 +488,29 @@ static char* __str_base10(uint32_t value, char* buffer, int* length)
487488
q += t;
488489
r -= (((t << 2) + t) << 1);
489490

490-
temp[pos++] = '0' + r;
491+
tmp[pos++] = '0' + r;
491492
value = q;
492493
}
493494

494495
/* Reverse digits into output buffer */
495496
*length = pos;
496497
for (int i = 0; i < pos; i++) {
497-
buffer[i] = temp[pos - 1 - i];
498+
buffer[i] = tmp[pos - 1 - i];
498499
}
499500

500501
return buffer;
501502
}
502503

503504
/* Handle signed integers */
504-
static char* __str_base10_signed(int32_t value, char* buffer, int* length) {
505+
static char *__str_base10_signed(int32_t value, char *buffer, int *length)
506+
{
505507
if (value < 0) {
506508
buffer[0] = '-';
507-
__str_base10((uint32_t)(-value), buffer + 1, length);
509+
__str_base10((uint32_t) (-value), buffer + 1, length);
508510
(*length)++;
509511
return buffer;
510-
} else {
511-
return __str_base10((uint32_t)value, buffer, length);
512512
}
513+
return __str_base10((uint32_t) value, buffer, length);
513514
}
514515

515516
/* Converts string @s to an integer. */

0 commit comments

Comments
 (0)