Skip to content

Commit

Permalink
Now kdisp*() only defined for non-graphical, debug builds
Browse files Browse the repository at this point in the history
We were writing to VGA text buffer even for graphics builds, which makes
no sense. With this change VGA Text related functions are only included
for non-graphical, debug builds.

Note:
* For Graphical, debug builds though kearly_printf will be defined,
  it will not print anywhere. It will later print to VirtualScreen, but
  its yet implemented.
  • Loading branch information
coderarjob committed Nov 16, 2024
1 parent 13240ed commit a6bbbe9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
typedef struct KernelStateInfo {
enum {
KERNEL_PHASE_STATE_BOOT_COMPLETE = 0,
#if defined(DEBUG) && !defined(GRAPHICS_MODE_ENABLED)
KERNEL_PHASE_STATE_TEXTDISP_READY,
#endif
KERNEL_PHASE_STATE_PMM_READY,
KERNEL_PHASE_STATE_SALLOC_READY,
KERNEL_PHASE_STATE_VMM_READY,
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/kpanic.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ void kpanic_ndu (UINT line, const CHAR* file, const CHAR* fmt, ...)

#ifdef DEBUG
kdebug_printf ("%s", buffer);
#ifndef GRAPHICS_MODE_ENABLED
kearly_printf (buffer);
#endif
#endif

k_halt();
Expand Down
19 changes: 12 additions & 7 deletions src/kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ static IntTypes s_readtype (const CHAR **fmt, CHAR *c);
static U64 s_readint (IntTypes inttype, va_list *l);

#if defined(DEBUG)
static void s_prnstr (const CHAR *str);
#if !defined(GRAPHICS_MODE_ENABLED)
static void s_prnstr (const CHAR* str);

static void s_prnstr (const CHAR *str)
static void s_prnstr (const CHAR* str)
{
for (;*str;str++)
for (; *str; str++)
kdisp_putc (*str);
}
#endif

/***************************************************************************************************
* Prints on screen the arguments in the format specified.
Expand All @@ -50,8 +52,6 @@ static void s_prnstr (const CHAR *str)
**************************************************************************************************/
INT kearly_printf (const CHAR *fmt, ...)
{
KERNEL_PHASE_VALIDATE(KERNEL_PHASE_STATE_TEXTDISP_READY);

va_list l;
va_start (l, fmt);

Expand All @@ -60,10 +60,15 @@ INT kearly_printf (const CHAR *fmt, ...)

va_end (l);

s_prnstr (buffer);
#if !defined(GRAPHICS_MODE_ENABLED)
KERNEL_PHASE_VALIDATE(KERNEL_PHASE_STATE_TEXTDISP_READY);
s_prnstr (buffer);
#else
// TODO: VirtualScreen not yet implemented.
#endif
return len;
}
#endif
#endif // DEBUG

/***************************************************************************************************
* Writes to a string pointer the arguments in the format specified.
Expand Down
5 changes: 4 additions & 1 deletion src/kernel/x86/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ set(KERNEL_X86_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/process.c
${CMAKE_CURRENT_SOURCE_DIR}/syscalls.c
${CMAKE_CURRENT_SOURCE_DIR}/tss.c
${CMAKE_CURRENT_SOURCE_DIR}/vgadisp.c
)

if (MOS_BUILD_MODE STREQUAL "DEBUG" AND NOT MOS_GRAPHICS_ENABLED)
LIST(APPEND KERNEL_X86_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/vgatext.c)
endif()

compile_lib(
NAME kernel_X86
SOURCES ${KERNEL_X86_SOURCES}
Expand Down
7 changes: 6 additions & 1 deletion src/kernel/x86/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ void kernel_main ()
FUNC_ENTRY();

KERNEL_PHASE_SET(KERNEL_PHASE_STATE_BOOT_COMPLETE);

#if defined(DEBUG) && !defined(GRAPHICS_MODE_ENABLED)
// Initialize Text display
kdisp_init ();
kdisp_init();
#endif

// Initilaize Physical Memory Manger
kpmm_init ();
Expand Down Expand Up @@ -148,9 +151,11 @@ void kernel_main ()
KERNEL_PHASE_SET(KERNEL_PHASE_STATE_KERNEL_READY);
kearly_printf ("\r[OK]");

#if defined(DEBUG) && !defined(GRAPHICS_MODE_ENABLED)
kdisp_ioctl (DISP_SETATTR,k_dispAttr (BLACK,GREEN,0));
kearly_println ("Kernel initialization finished..");
kdisp_ioctl (DISP_SETATTR,k_dispAttr (BLACK,LIGHT_GRAY,0));
#endif

//---------------
int cpuflags_present = 0;
Expand Down

0 comments on commit a6bbbe9

Please sign in to comment.