Skip to content

Commit

Permalink
Add a feature named enable-console-log
Browse files Browse the repository at this point in the history
This feature can be used to enable printing log messages to
console in addition to storing them in the log buffer.

Use ENABLE_CONSOLE_LOG=1 to enable this feature. By default,
this feature is disabled for release builds and enabled for
debug builds.

Signed-off-by: Vasant Karasulli <[email protected]>
  • Loading branch information
vsntk18 committed Oct 18, 2024
1 parent 05bc4de commit 6536aee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ SVSM_ARGS_TEST += --no-default-features --features ${FEATURES_TEST}
ifdef RELEASE
TARGET_PATH=release
CARGO_ARGS += --release
ENABLE_CONSOLE_LOG ?= 0
else
TARGET_PATH=debug
ENABLE_CONSOLE_LOG ?= 1
endif

STAGE2_ARGS =
ifeq ($(ENABLE_CONSOLE_LOG), 1)
SVSM_ARGS += --features enable-console-log
STAGE2_ARGS += --features enable-console-log
endif

ifdef OFFLINE
Expand Down Expand Up @@ -124,7 +132,7 @@ bin/meta.bin: utils/gen_meta utils/print-meta bin
./utils/gen_meta $@

bin/stage2.bin: bin
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} --bin stage2
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} ${STAGE2_ARGS} --bin stage2
objcopy -O binary ${STAGE2_ELF} $@

bin/svsm-kernel.elf: bin
Expand Down
1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test.workspace = true
default = []
enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
mstpm = ["dep:libmstpm"]
enable-console-log = []

[dev-dependencies]

Expand Down
12 changes: 12 additions & 0 deletions kernel/src/cpu/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,30 @@ impl log::Log for BufferLogger {
line_buf
.write_fmt(format_args!("[{}] {}: {}\n", comp, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}: {}\n", comp, lvl, rec_args));
}
}

log::Level::Info => {
line_buf
.write_fmt(format_args!("[{}] {}\n", comp, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}\n", comp, rec_args));
}
}

log::Level::Debug | log::Level::Trace => {
line_buf
.write_fmt(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args));
}
}
}
}
Expand Down

0 comments on commit 6536aee

Please sign in to comment.