1
0

Start adding simple video console which uses framebuffer

This commit is contained in:
Aaron Lindsay 2012-09-09 01:58:38 -04:00
parent c96a4e2a57
commit aaa714d89a
5 changed files with 81 additions and 14 deletions

View File

@ -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 $@')

6
include/console.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CONSOLE_H
#define CONSOLE_H
void console_init(struct fb *f);
#endif /* CONSOLE_H */

View File

@ -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

60
kernel/console.c Normal file
View File

@ -0,0 +1,60 @@
#include <font.h>
#include <framebuffer.h>
#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;
}

View File

@ -3,25 +3,24 @@
#include <devices/pl110.h>
#include <framebuffer.h>
#include <console.h>
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;
}