From c48c2a976fe2fb2016ccc1b7c75217083a72ec37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 12 Feb 2005 03:40:03 +0000 Subject: [PATCH] Ported over the vga text console module from NewOS. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11349 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/console/Jamfile | 3 + src/add-ons/kernel/console/vga_text/Jamfile | 8 + .../kernel/console/vga_text/vga_text.c | 175 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 src/add-ons/kernel/console/Jamfile create mode 100644 src/add-ons/kernel/console/vga_text/Jamfile create mode 100644 src/add-ons/kernel/console/vga_text/vga_text.c diff --git a/src/add-ons/kernel/console/Jamfile b/src/add-ons/kernel/console/Jamfile new file mode 100644 index 0000000000..8b9b87d8a2 --- /dev/null +++ b/src/add-ons/kernel/console/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src add-ons kernel console ; + +SubInclude OBOS_TOP src add-ons kernel console vga_text ; diff --git a/src/add-ons/kernel/console/vga_text/Jamfile b/src/add-ons/kernel/console/vga_text/Jamfile new file mode 100644 index 0000000000..59d90b20f8 --- /dev/null +++ b/src/add-ons/kernel/console/vga_text/Jamfile @@ -0,0 +1,8 @@ +SubDir OBOS_TOP src add-ons kernel console vga_text ; + +UsePrivateHeaders kernel ; + +KernelAddon vga_text : kernel console : + vga_text.c + ; + diff --git a/src/add-ons/kernel/console/vga_text/vga_text.c b/src/add-ons/kernel/console/vga_text/vga_text.c new file mode 100644 index 0000000000..3dc24f2e6a --- /dev/null +++ b/src/add-ons/kernel/console/vga_text/vga_text.c @@ -0,0 +1,175 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include +#include +#include + +#include +#include + +#include + + +#define SCREEN_START 0xb8000 +#define SCREEN_END 0xc0000 +#define LINES 25 +#define COLUMNS 80 + +#define TEXT_INDEX 0x3d4 +#define TEXT_DATA 0x3d5 + +#define TEXT_CURSOR_LO 0x0f +#define TEXT_CURSOR_HI 0x0e + +static uint16 *gOrigin; +static isa_module_info *isa; + + +static int +text_init(void) +{ + addr_t i; + + if (get_module(B_ISA_MODULE_NAME, (module_info **)&isa) < 0) { + dprintf("text module_init: no isa bus found..\n"); + return -1; + } + + /* we always succeede, so init our stuff */ + dprintf("console/text: mapping vid mem\n"); + vm_map_physical_memory(vm_get_kernel_aspace_id(), "vid_mem", (void *)&gOrigin, B_ANY_KERNEL_ADDRESS, + SCREEN_END - SCREEN_START, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, SCREEN_START); + dprintf("console/text: mapped vid mem to virtual address %p\n", gOrigin); + + /* pre-touch all of the memory so that we dont fault while deep inside the kernel and displaying something */ + for(i = (addr_t)gOrigin; i < (addr_t)gOrigin + (SCREEN_END - SCREEN_START); i += B_PAGE_SIZE) { + uint16 val = *(volatile uint16 *)i; + *(volatile uint16 *)i = val; + } + return 0; +} + + +static int +text_uninit(void) +{ + put_module(B_ISA_MODULE_NAME); + + // ToDo: unmap video memory (someday) + return 0; +} + + +static status_t +get_size(int32 *width, int32 *height) +{ + *width = COLUMNS; + *height = LINES; + return 0; +} + + +static void +move_cursor(int32 x, int32 y) +{ + short int pos; + + if (x < 0 || y < 0) + pos = LINES * COLUMNS + 1; + else + pos = y * COLUMNS + x; + + isa->write_io_8(TEXT_INDEX, TEXT_CURSOR_LO); + isa->write_io_8(TEXT_DATA, (char)pos); + isa->write_io_8(TEXT_INDEX, TEXT_CURSOR_HI); + isa->write_io_8(TEXT_DATA, (char)(pos >> 8)); +} + + +static void +put_glyph(int32 x, int32 y, uint8 glyph, uint8 attr) +{ + uint16 pair = ((uint16)attr << 8) | (uint16)glyph; + uint16 *p = gOrigin+(y*COLUMNS)+x; + *p = pair; +} + + +static void +fill_glyph(int32 x, int32 y, int32 width, int32 height, uint8 glyph, uint8 attr) +{ + uint16 pair = ((uint16)attr << 8) | (uint16)glyph; + int y_limit = y + height; + + while (y < y_limit) { + uint16 *p = gOrigin+(y*COLUMNS)+x; + uint16 *p_limit = p + width; + while (p < p_limit) *p++ = pair; + y++; + } +} + + +static void +blit(int32 srcx, int32 srcy, int32 width, int32 height, int32 destx, int32 desty) +{ + if ((srcx == 0) && (width == COLUMNS)) { + // whole lines + memmove(gOrigin + (desty * COLUMNS), gOrigin + (srcy * COLUMNS), height * COLUMNS * 2); + } else { + // FIXME + } +} + + +static void +clear(uint8 attr) +{ + uint16 *base = (uint16 *)gOrigin; + uint32 i; + + for (i = 0; i < COLUMNS * LINES; i++) + base[i] = 0xf20; +} + + +static status_t +text_std_ops(int32 op, ...) +{ + switch (op) { + case B_MODULE_INIT: + return text_init(); + case B_MODULE_UNINIT: + return text_uninit(); + + default: + return B_ERROR; + } +} + + +static console_module_info sVGATextConsole = { + { + "console/vga_text/v1", + 0, + text_std_ops + }, + get_size, + move_cursor, + put_glyph, + fill_glyph, + blit, + clear, +}; + +module_info *modules[] = { + (module_info *)&sVGATextConsole, + NULL +};