diff --git a/Makefile b/Makefile index ecedcec..bc20b89 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,9 @@ LD = $(TOOL_PREFIX)ld # Define the flags we'll need for our tools INCLUDES = -I include -KCFLAGS = -Wall -Wextra -Werror -nostdlib -nostartfiles -ffreestanding -std=gnu99 $(INCLUDES) -KLDFLAGS = -T link.ld +KCFLAGS = -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(INCLUDES) +KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/ +EXTRA_LIBS = -lgcc KOBJS = @@ -30,7 +31,7 @@ all: aedrix-kernel aedrix-kernel: $(KOBJS) $(if $(VERBOSE:1=),@echo ' LD $@') - $(if $(VERBOSE:1=),@)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) + $(if $(VERBOSE:1=),@)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) $(EXTRA_LIBS) %.o: %.c $(if $(VERBOSE:1=),@echo ' CC $@') diff --git a/include/console.h b/include/console.h new file mode 100644 index 0000000..f275223 --- /dev/null +++ b/include/console.h @@ -0,0 +1,6 @@ +#ifndef CONSOLE_H +#define CONSOLE_H + +void console_init(struct fb *f); + +#endif /* CONSOLE_H */ diff --git a/kernel/Makefile.inc b/kernel/Makefile.inc index fdede64..ed6f474 100644 --- a/kernel/Makefile.inc +++ b/kernel/Makefile.inc @@ -1,5 +1,6 @@ KERNEL_PREFIX = kernel +KOBJS += $(KERNEL_PREFIX)/console.o KOBJS += $(KERNEL_PREFIX)/font.o KOBJS += $(KERNEL_PREFIX)/framebuffer.o KOBJS += $(KERNEL_PREFIX)/print.o diff --git a/kernel/console.c b/kernel/console.c new file mode 100644 index 0000000..ca603ef --- /dev/null +++ b/kernel/console.c @@ -0,0 +1,60 @@ +#include +#include + +#define CONSOLE_BUFFER_SIZE 16384 +char console_buffer[CONSOLE_BUFFER_SIZE]; +char console_output_buffer[CONSOLE_BUFFER_SIZE]; +char *console_buffer_p = console_buffer; +struct fb *console_framebuffer = 0; +struct font *console_font = 0; +unsigned int chars_per_line = 0, lines = 0; + +void console_char_to_fb(char c, unsigned int x, unsigned int y) { + unsigned int cx, cy, bit = 0; + char *font_char = &console_font->data[console_font->bytes_per_char * (c - console_font->ascii_offset)]; + + for (cy = 0; cy < console_font->height; cy++) { + for (cx = 0; cx < console_font->width; cx++) { + unsigned char on = font_char[bit / 8] & (1 << (bit % 8)); + if (on) + fb_write_pixel(console_framebuffer, x + cx, y + cy, 0xff, 0xff, 0xff); + else + fb_write_pixel(console_framebuffer, x + cx, y + cy, 0x00, 0x00, 0x00); + bit++; + } + } +} + +void console_refresh_fb() { + if (!console_framebuffer) + return; +} + +void console_clear() { + int i; + for (i = 0; i < CONSOLE_BUFFER_SIZE; i++) { + console_buffer[i] = 0; + } +} + +void console_init(struct fb *f) { + console_clear(); + console_refresh_fb(); + console_font = font_get(); + console_framebuffer = f; + chars_per_line = console_framebuffer->width / console_font->width; + lines = console_framebuffer->height / console_font->height; + + console_char_to_fb('A', 100, 100); + console_char_to_fb('E', 111, 100); + console_char_to_fb('D', 122, 100); + console_char_to_fb('R', 133, 100); + console_char_to_fb('I', 144, 100); + console_char_to_fb('X', 155, 100); +} + +void console_putc(char c) { + *console_buffer_p = c; + if (++console_buffer_p > console_buffer + CONSOLE_BUFFER_SIZE) + console_buffer_p = console_buffer; +} diff --git a/kernel/start_kernel.c b/kernel/start_kernel.c index d74721e..0a7e06a 100644 --- a/kernel/start_kernel.c +++ b/kernel/start_kernel.c @@ -3,25 +3,24 @@ #include #include +#include struct fb myfb; -void video(void) -{ - unsigned int x, y; - pl110_init(&myfb, 16); - x = 0, y = 0; - for (y=0; y<480; y++) - for (x=0; x<640; x++) - fb_write_pixel(&myfb, x, y, 0xff, 0x00, 0x00); +void video(void) { +// unsigned int x, y; + pl110_init(&myfb, 24); +// x = 0, y = 0; +// for (y=0; y<480; y++) +// for (x=0; x<640; x++) +// fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f); + console_init(&myfb); } -int main(void) -{ +int main(void) { print_init(&pl011_putc); //initialize the serial console video(); - print("hello, world!\n"); return 0; }