Skip to content

Commit

Permalink
chore: a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyhunter committed Feb 9, 2025
1 parent 928fcd6 commit 7bc5795
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 40 deletions.
15 changes: 13 additions & 2 deletions docs/internals/startup/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ description: >-
This section describes the startup process of MOS, from the bootloader to the creation of the first user process.
---

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

## 1. Command Line Parsing
The very first stage of startup is the phase of bootloader, which is **limine** only for now, the bootloader will:

- Map correct ELF segments into memory and setup correct permissions
- Read and sanitise the memory layout provided by the firmware
- Map initrd, load cmdlines
- Setup direct mapping, which maps the entire physical memory space to a specific range of virtual memory.
- Potentially:
- Start secondary CPUs (APs)
- Find ACPI tables
- Find firmware-provided device tree

## 2. Command Line Parsing

`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.

Expand Down
2 changes: 1 addition & 1 deletion kernel/include/private/mos/filesystem/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ file_t *vfs_openat(int fd, const char *path, open_flags flags);
* If the path is relative, the fd will be used as the directory to resolve the path from.
* If FSTATAT_NOFOLLOW is set, when the path is used, symlinks will not be followed.
*/
long vfs_fstatat(fd_t fd, const char *path, file_stat_t *restrict stat, fstatat_flags flags);
long vfs_fstatat(fd_t fd, const char *path, file_stat_t *stat, fstatat_flags flags);

/**
* @brief Read a symbolic link
Expand Down
1 change: 0 additions & 1 deletion kernel/include/private/mos/ipc/ipc_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "mos/io/io.h"
#include "mos/ipc/ipc.h"
#include "mos/platform/platform.h"

typedef struct
{
Expand Down
4 changes: 2 additions & 2 deletions kernel/include/private/mos/syslog/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#define pr_fmt(fmt) fmt // default format string
#endif

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

#define lprintk_debug_wrapper(feat, level, fmt, ...) \
do \
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/private/mos/syslog/syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ typedef enum
MOS_LOG_UNSET = 0,
} loglevel_t;

long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt, ...);
long do_syslog(loglevel_t level, const char *file, const char *func, int line, const debug_info_entry *feat, const char *fmt, ...);
2 changes: 1 addition & 1 deletion kernel/io/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static io_t io_null_impl = {
.type = IO_NULL,
.flags = IO_READABLE | IO_WRITABLE,
.ops =
&(io_op_t){
&(io_op_t) {
.read = _null_read,
.write = _null_write,
.seek = NULL,
Expand Down
1 change: 0 additions & 1 deletion kernel/ipc/ipc_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "mos/io/io.h"
#include "mos/ipc/ipc.h"
#include "mos/mm/slab_autoinit.h"
#include "mos/platform/platform.h"

#include <mos_stdlib.h>

Expand Down
66 changes: 36 additions & 30 deletions kernel/syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,9 @@

static spinlock_t global_syslog_lock = SPINLOCK_INIT;

long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt, ...)
static void do_print_syslog(const pb_syslog_message *msg, const debug_info_entry *feat)
{
pb_syslog_message msg = {
.timestamp = platform_get_timestamp(),
.cpu_id = platform_current_cpu_id(),
};

msg.info.level = (syslog_level) level;
msg.info.featid = feat ? feat->id : 0;
msg.info.source_location.line = line;
strncpy(msg.info.source_location.filename, file, sizeof(msg.info.source_location.filename));
strncpy(msg.info.source_location.function, func, sizeof(msg.info.source_location.function));

if (thread)
{
msg.thread.tid = thread->tid;
msg.process.pid = thread->owner->pid;
strncpy(msg.thread.name, thread->name, sizeof(msg.thread.name));
strncpy(msg.process.name, thread->owner->name, sizeof(msg.process.name));
}

va_list args;
va_start(args, fmt);
vsnprintf(msg.message, sizeof(msg.message), fmt, args);
va_end(args);

const loglevel_t level = (loglevel_t) msg->info.level;
spinlock_acquire(&global_syslog_lock);

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

#if MOS_CONFIG(MOS_PRINTK_WITH_TIMESTAMP)
lprintk(level, "%-16llu | ", platform_get_timestamp());
lprintk(level, "%-16lu | ", msg->timestamp);
#endif

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

#if MOS_CONFIG(MOS_PRINTK_WITH_CPU_ID)
lprintk(level, "cpu %2d | ", msg.cpu_id);
lprintk(level, "cpu %2d | ", msg->cpu_id);
#endif

#if MOS_CONFIG(MOS_PRINTK_WITH_FILENAME)
lprintk(level, "%-15s | ", msg.info.source_location.filename);
lprintk(level, "%-15s | ", msg->info.source_location.filename);
#endif

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

lprintk(level, "%s", msg.message);
lprintk(level, "%s", msg->message);

spinlock_release(&global_syslog_lock);
}

long do_syslog(loglevel_t level, const char *file, const char *func, int line, const debug_info_entry *feat, const char *fmt, ...)
{
auto const thread = current_thread;
pb_syslog_message msg = {
.timestamp = platform_get_timestamp(),
.cpu_id = platform_current_cpu_id(),
};

msg.info.level = (syslog_level) level;
msg.info.featid = feat ? feat->id : 0;
msg.info.source_location.line = line;
strncpy(msg.info.source_location.filename, file, sizeof(msg.info.source_location.filename));
strncpy(msg.info.source_location.function, func, sizeof(msg.info.source_location.function));

if (thread)
{
msg.thread.tid = thread->tid;
msg.process.pid = thread->owner->pid;
strncpy(msg.thread.name, thread->name, sizeof(msg.thread.name));
strncpy(msg.process.name, thread->owner->name, sizeof(msg.process.name));
}

va_list args;
va_start(args, fmt);
vsnprintf(msg.message, sizeof(msg.message), fmt, args);
va_end(args);

do_print_syslog(&msg, feat);
return 0;
}
2 changes: 1 addition & 1 deletion libs/nanopb/nanopb
Submodule nanopb updated 51 files
+1 −1 .github/workflows/bazel.yml
+6 −6 .github/workflows/binary_packages.yml
+1 −1 .github/workflows/cifuzz.yml
+2 −2 .github/workflows/cmake.yml
+2 −2 .github/workflows/codeql.yml
+1 −1 .github/workflows/compiler_tests.yml
+1 −1 .github/workflows/ios_swift_tests.yml
+35 −0 .github/workflows/olddistro_tests.yml
+1 −1 .github/workflows/platformio_tests.yml
+2 −2 .github/workflows/pypi_publish.yml
+0 −36 .github/workflows/python2_tests.yml
+3 −3 .github/workflows/simulator_tests.yml
+1 −1 .github/workflows/trigger_on_code_change.yml
+3 −3 .github/workflows/trigger_on_schedule.yml
+13 −0 AUTHORS.txt
+19 −0 CHANGELOG.txt
+1 −1 CMakeLists.txt
+3 −3 MODULE.bazel
+1 −1 conanfile.py
+1 −1 docs/concepts.md
+36 −4 docs/migration.md
+58 −0 docs/reference.md
+6 −8 extra/FindNanopb.cmake
+2 −2 extra/poetry/pyproject.toml
+56 −32 generator/nanopb_generator.py
+0 −13 generator/nanopb_generator.py2
+1 −17 generator/proto/__init__.py
+539 −118 generator/proto/google/protobuf/descriptor.proto
+21 −5 generator/proto/nanopb.proto
+0 −16 generator/protoc-gen-nanopb-py2
+1 −1 library.json
+17 −1 pb.h
+11 −0 pb_decode.c
+12 −1 pb_decode.h
+14 −9 pb_encode.c
+13 −3 pb_encode.h
+13 −5 tests/enum_sizes/SConscript
+41 −0 tests/enum_sizes/enum_intsize.proto
+3 −2 tests/enum_sizes/enum_intsize_unittests.cc
+0 −3 tests/enum_sizes/enumsizes_intsize_unittests.h
+0 −35 tests/enum_sizes/packed_enum.proto
+1 −4 tests/enum_sizes/packed_enum_unittests.c
+1 −0 tests/namingstyle/naming_style.proto
+4 −0 tests/namingstyle/test_naming_style_c.c
+17 −0 tests/options/options.proto
+3 −0 tests/options/options_h.expected
+7 −0 tests/regression/issue_869/SConscript
+623 −0 tests/regression/issue_869/bigfile.proto
+8 −0 tests/regression/issue_956/SConscript
+4 −0 tests/regression/issue_956/skipmap.expected
+28 −0 tests/regression/issue_956/skipmap.proto

0 comments on commit 7bc5795

Please sign in to comment.