Skip to content

Commit

Permalink
console: MACROS to print colored text, errors, warnings
Browse files Browse the repository at this point in the history
elf: fix compiler warning
  • Loading branch information
tuxuser committed Jan 27, 2012
1 parent 69942fa commit 51979e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 6 additions & 0 deletions libxenon/drivers/console/console.c
Expand Up @@ -190,6 +190,12 @@ void console_get_dimensions(unsigned int * width,unsigned int * height){
if (height) *height=max_y;
}

unsigned int console_get_color(int num){
if (num < 0 || num > 1)
return 0;
return console_color[num];
}

void console_close(void)
{
stdout_hook = 0;
Expand Down
24 changes: 23 additions & 1 deletion libxenon/drivers/console/console.h
Expand Up @@ -5,6 +5,8 @@
extern "C" {
#endif

unsigned int old_console_color[2];

#define CONSOLE_COLOR_RED 0x0000FF00
#define CONSOLE_COLOR_BLUE 0xD8444E00
#define CONSOLE_COLOR_GREEN 0x00800000
Expand All @@ -16,7 +18,27 @@ extern "C" {
#define CONSOLE_COLOR_YELLOW 0x00FFFF00
#define CONSOLE_COLOR_ORANGE 0x0066FF00
#define CONSOLE_COLOR_PINK 0xFF66FF00


#define PRINT_WARN(s) \
old_console_color[1] = console_get_color(1); \
console_set_colors(console_get_color(0),CONSOLE_COLOR_YELLOW; \
printf("W: %s",s); \
console_set_colors(console_get_color(0),old_console_color[1]);

#define PRINT_ERR(s) \
old_console_color[1] = console_get_color(1); \
console_set_colors(console_get_color(0),CONSOLE_COLOR_ORANGE; \
printf("EE: %s",s); \
console_set_colors(console_get_color(0),old_console_color[1]);

#define PRINT_COL(bg, fg, s) \
old_console_color[0] = console_get_color(0); old_console_color[1] = console_get_color(1); \
if (bg != -1) console_set_colors(bg,console_get_color(1)); \
if (fg != -1) console_set_colors(console_get_color(0),fg); \
printf(s); \
console_set_colors(old_console_color[0],old_console_color[1]);

unsigned int console_get_color(int num);
void console_set_colors(unsigned int background, unsigned int foreground); // can be called before init
void console_get_dimensions(unsigned int * width,unsigned int * height);
void console_putch(const char c);
Expand Down
7 changes: 4 additions & 3 deletions libxenon/drivers/elf/elf.c
Expand Up @@ -18,6 +18,7 @@ see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#include <libfdt/libfdt.h>
#include <nocfe/addrspace.h>

#include "elf.h"
#include "elf_abi.h"

#define INITRD_RELOC_START ((void*)0x85FE0000)
Expand Down Expand Up @@ -293,14 +294,14 @@ void elf_runWithDeviceTree (void *elf_addr, int elf_size, void *dt_addr, int dt_
kernel_relocate_initrd(initrd_start,initrd_size);

u64 start, end;
start = (u32)PHYSADDR((uint64_t)initrd_start);
start = (u32)PHYSADDR((u32)initrd_start);
res = fdt_setprop(ELF_DEVTREE_START, node, "linux,initrd-start", &start, sizeof(start));
if (res < 0){
printf("couldn't set chosen.linux,initrd-start property\n");
return;
}

end = (u32)PHYSADDR((uint64_t)initrd_start + (uint64_t)initrd_size);
end = (u32)PHYSADDR(((u32)initrd_start + (u32)initrd_size));
res = fdt_setprop(ELF_DEVTREE_START, node, "linux,initrd-end", &end, sizeof(end));
if (res < 0) {
printf("couldn't set chosen.linux,initrd-end property\n");
Expand Down Expand Up @@ -363,7 +364,7 @@ void kernel_relocate_initrd(void *start, size_t size)
initrd_size = size;

printf("Initrd at %p/0x%lx: %ld bytes (%ldKiB)\n", initrd_start, \
(u32)PHYSADDR((uint64_t)initrd_start), initrd_size, initrd_size/1024);
(u32)PHYSADDR((u32)initrd_start), initrd_size, initrd_size/1024);
}

void kernel_reset_initrd(void)
Expand Down

0 comments on commit 51979e1

Please sign in to comment.