Skip to content

Commit 7bc5795

Browse files
committed
chore: a bit of cleanup
1 parent 928fcd6 commit 7bc5795

File tree

9 files changed

+55
-40
lines changed

9 files changed

+55
-40
lines changed

docs/internals/startup/index.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ description: >-
66
This section describes the startup process of MOS, from the bootloader to the creation of the first user process.
77
---
88

9-
This section describes the startup process of MOS, from the bootloader to the creation of the first user process.
9+
## 1. Bootloader
1010

11-
## 1. Command Line Parsing
11+
The very first stage of startup is the phase of bootloader, which is **limine** only for now, the bootloader will:
12+
13+
- Map correct ELF segments into memory and setup correct permissions
14+
- Read and sanitise the memory layout provided by the firmware
15+
- Map initrd, load cmdlines
16+
- Setup direct mapping, which maps the entire physical memory space to a specific range of virtual memory.
17+
- Potentially:
18+
- Start secondary CPUs (APs)
19+
- Find ACPI tables
20+
- Find firmware-provided device tree
21+
22+
## 2. Command Line Parsing
1223

1324
`cmdline` is important for the kernel, as it allows the user to pass arguments to the kernel at runtime. The kernel parses the command line and uses the arguments to configure itself.
1425

kernel/include/private/mos/filesystem/vfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ file_t *vfs_openat(int fd, const char *path, open_flags flags);
9999
* If the path is relative, the fd will be used as the directory to resolve the path from.
100100
* If FSTATAT_NOFOLLOW is set, when the path is used, symlinks will not be followed.
101101
*/
102-
long vfs_fstatat(fd_t fd, const char *path, file_stat_t *restrict stat, fstatat_flags flags);
102+
long vfs_fstatat(fd_t fd, const char *path, file_stat_t *stat, fstatat_flags flags);
103103

104104
/**
105105
* @brief Read a symbolic link

kernel/include/private/mos/ipc/ipc_io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "mos/io/io.h"
66
#include "mos/ipc/ipc.h"
7-
#include "mos/platform/platform.h"
87

98
typedef struct
109
{

kernel/include/private/mos/syslog/printk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#define pr_fmt(fmt) fmt // default format string
1414
#endif
1515

16-
#define emit_syslog(level, feat, fmt, ...) do_syslog(level, current_thread, __FILE_NAME__, __func__, __LINE__, &mos_debug_info.feat, fmt, ##__VA_ARGS__)
17-
#define emit_syslog_nofeat(level, fmt, ...) do_syslog(level, current_thread, __FILE_NAME__, __func__, __LINE__, NULL, fmt, ##__VA_ARGS__)
16+
#define emit_syslog(level, feat, fmt, ...) do_syslog(level, __FILE_NAME__, __func__, __LINE__, &mos_debug_info.feat, fmt, ##__VA_ARGS__)
17+
#define emit_syslog_nofeat(level, fmt, ...) do_syslog(level, __FILE_NAME__, __func__, __LINE__, NULL, fmt, ##__VA_ARGS__)
1818

1919
#define lprintk_debug_wrapper(feat, level, fmt, ...) \
2020
do \

kernel/include/private/mos/syslog/syslog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ typedef enum
1616
MOS_LOG_UNSET = 0,
1717
} loglevel_t;
1818

19-
long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt, ...);
19+
long do_syslog(loglevel_t level, const char *file, const char *func, int line, const debug_info_entry *feat, const char *fmt, ...);

kernel/io/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static io_t io_null_impl = {
3131
.type = IO_NULL,
3232
.flags = IO_READABLE | IO_WRITABLE,
3333
.ops =
34-
&(io_op_t){
34+
&(io_op_t) {
3535
.read = _null_read,
3636
.write = _null_write,
3737
.seek = NULL,

kernel/ipc/ipc_io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "mos/io/io.h"
77
#include "mos/ipc/ipc.h"
88
#include "mos/mm/slab_autoinit.h"
9-
#include "mos/platform/platform.h"
109

1110
#include <mos_stdlib.h>
1211

kernel/syslog/syslog.c

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,9 @@
1313

1414
static spinlock_t global_syslog_lock = SPINLOCK_INIT;
1515

16-
long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt, ...)
16+
static void do_print_syslog(const pb_syslog_message *msg, const debug_info_entry *feat)
1717
{
18-
pb_syslog_message msg = {
19-
.timestamp = platform_get_timestamp(),
20-
.cpu_id = platform_current_cpu_id(),
21-
};
22-
23-
msg.info.level = (syslog_level) level;
24-
msg.info.featid = feat ? feat->id : 0;
25-
msg.info.source_location.line = line;
26-
strncpy(msg.info.source_location.filename, file, sizeof(msg.info.source_location.filename));
27-
strncpy(msg.info.source_location.function, func, sizeof(msg.info.source_location.function));
28-
29-
if (thread)
30-
{
31-
msg.thread.tid = thread->tid;
32-
msg.process.pid = thread->owner->pid;
33-
strncpy(msg.thread.name, thread->name, sizeof(msg.thread.name));
34-
strncpy(msg.process.name, thread->owner->name, sizeof(msg.process.name));
35-
}
36-
37-
va_list args;
38-
va_start(args, fmt);
39-
vsnprintf(msg.message, sizeof(msg.message), fmt, args);
40-
va_end(args);
41-
18+
const loglevel_t level = (loglevel_t) msg->info.level;
4219
spinlock_acquire(&global_syslog_lock);
4320

4421
if (level != MOS_LOG_UNSET)
@@ -48,29 +25,58 @@ long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char
4825
lprintk(level, "%-10s | ", feat->name);
4926

5027
#if MOS_CONFIG(MOS_PRINTK_WITH_TIMESTAMP)
51-
lprintk(level, "%-16llu | ", platform_get_timestamp());
28+
lprintk(level, "%-16lu | ", msg->timestamp);
5229
#endif
5330

5431
#if MOS_CONFIG(MOS_PRINTK_WITH_DATETIME)
5532
lprintk(level, "%s | ", (const char *) platform_get_datetime_str());
5633
#endif
5734

5835
#if MOS_CONFIG(MOS_PRINTK_WITH_CPU_ID)
59-
lprintk(level, "cpu %2d | ", msg.cpu_id);
36+
lprintk(level, "cpu %2d | ", msg->cpu_id);
6037
#endif
6138

6239
#if MOS_CONFIG(MOS_PRINTK_WITH_FILENAME)
63-
lprintk(level, "%-15s | ", msg.info.source_location.filename);
40+
lprintk(level, "%-15s | ", msg->info.source_location.filename);
6441
#endif
6542

6643
#if MOS_CONFIG(MOS_PRINTK_WITH_THREAD_ID)
67-
lprintk(level, "%pt\t| ", ((void *) thread));
44+
lprintk(level, "tid:%d,%s\t| ", msg->thread.tid, msg->thread.name);
6845
#endif
6946
}
7047

71-
lprintk(level, "%s", msg.message);
48+
lprintk(level, "%s", msg->message);
7249

7350
spinlock_release(&global_syslog_lock);
51+
}
52+
53+
long do_syslog(loglevel_t level, const char *file, const char *func, int line, const debug_info_entry *feat, const char *fmt, ...)
54+
{
55+
auto const thread = current_thread;
56+
pb_syslog_message msg = {
57+
.timestamp = platform_get_timestamp(),
58+
.cpu_id = platform_current_cpu_id(),
59+
};
60+
61+
msg.info.level = (syslog_level) level;
62+
msg.info.featid = feat ? feat->id : 0;
63+
msg.info.source_location.line = line;
64+
strncpy(msg.info.source_location.filename, file, sizeof(msg.info.source_location.filename));
65+
strncpy(msg.info.source_location.function, func, sizeof(msg.info.source_location.function));
66+
67+
if (thread)
68+
{
69+
msg.thread.tid = thread->tid;
70+
msg.process.pid = thread->owner->pid;
71+
strncpy(msg.thread.name, thread->name, sizeof(msg.thread.name));
72+
strncpy(msg.process.name, thread->owner->name, sizeof(msg.process.name));
73+
}
74+
75+
va_list args;
76+
va_start(args, fmt);
77+
vsnprintf(msg.message, sizeof(msg.message), fmt, args);
78+
va_end(args);
7479

80+
do_print_syslog(&msg, feat);
7581
return 0;
7682
}

libs/nanopb/nanopb

Submodule nanopb updated 51 files

0 commit comments

Comments
 (0)