Changeset 76fca31 in mainline
- Timestamp:
- 2008-12-16T19:02:07Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5ae4443
- Parents:
- 8fe5980
- Files:
-
- 1 deleted
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/debugger.c
r8fe5980 r76fca31 55 55 SPINLOCK_INITIALIZE(bkpoint_lock); 56 56 57 #ifdef CONFIG_KCONSOLE 58 57 59 static int cmd_print_breakpoints(cmd_arg_t *argv); 58 60 static cmd_info_t bkpts_info = { … … 100 102 }; 101 103 102 #endif 103 104 /** Print table of active breakpoints */ 105 int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) 106 { 107 unsigned int i; 108 char *symbol; 109 110 #ifdef __32_BITS__ 111 printf("# Count Address In symbol\n"); 112 printf("-- ----- ---------- ---------\n"); 113 #endif 114 115 #ifdef __64_BITS__ 116 printf("# Count Address In symbol\n"); 117 printf("-- ----- ------------------ ---------\n"); 118 #endif 119 120 for (i = 0; i < BKPOINTS_MAX; i++) 121 if (breakpoints[i].address) { 122 symbol = get_symtab_entry(breakpoints[i].address); 123 124 #ifdef __32_BITS__ 125 printf("%-2u %-5d %#10zx %s\n", i, 126 breakpoints[i].counter, breakpoints[i].address, 127 symbol); 128 #endif 129 130 #ifdef __64_BITS__ 131 printf("%-2u %-5d %#18zx %s\n", i, 132 breakpoints[i].counter, breakpoints[i].address, 133 symbol); 134 #endif 135 136 } 137 return 1; 138 } 104 #endif /* CONFIG_DEBUG_AS_WATCHPOINT */ 105 #endif /* CONFIG_KCONSOLE */ 139 106 140 107 /* Setup DR register according to table */ … … 268 235 printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate), 269 236 get_symtab_entry(getip(istate))); 270 printf("***Type 'exit' to exit kconsole.\n"); 271 atomic_set(&haltstate,1); 272 kconsole((void *) "debug"); 273 atomic_set(&haltstate,0); 237 238 #ifdef CONFIG_KCONSOLE 239 atomic_set(&haltstate, 1); 240 kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false); 241 atomic_set(&haltstate, 0); 242 #endif 274 243 } 275 244 … … 300 269 } 301 270 302 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 303 304 /** Remove breakpoint from table */ 305 int cmd_del_breakpoint(cmd_arg_t *argv) 306 { 307 unative_t bpno = argv->intval; 308 if (bpno > BKPOINTS_MAX) { 309 printf("Invalid breakpoint number.\n"); 310 return 0; 311 } 312 breakpoint_del(argv->intval); 313 return 1; 314 } 315 316 /** Add new breakpoint to table */ 317 static int cmd_add_breakpoint(cmd_arg_t *argv) 318 { 319 int flags; 320 int id; 321 322 if (argv == &add_argv) { 323 flags = BKPOINT_INSTR; 324 } else { /* addwatchp */ 325 flags = BKPOINT_WRITE; 326 } 327 printf("Adding breakpoint on address: %p\n", argv->intval); 328 id = breakpoint_add((void *)argv->intval, flags, -1); 329 if (id < 0) 330 printf("Add breakpoint failed.\n"); 331 else 332 printf("Added breakpoint %d.\n", id); 333 334 return 1; 335 } 336 #endif 271 337 272 338 273 static void debug_exception(int n __attribute__((unused)), istate_t *istate) … … 380 315 for (i = 0; i < BKPOINTS_MAX; i++) 381 316 breakpoints[i].address = NULL; 382 317 318 #ifdef CONFIG_KCONSOLE 383 319 cmd_initialize(&bkpts_info); 384 320 if (!cmd_register(&bkpts_info)) 385 p anic("couldnot register command %s\n", bkpts_info.name);321 printf("Cannot register command %s\n", bkpts_info.name); 386 322 387 323 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 388 324 cmd_initialize(&delbkpt_info); 389 325 if (!cmd_register(&delbkpt_info)) 390 p anic("couldnot register command %s\n", delbkpt_info.name);326 printf("Cannot register command %s\n", delbkpt_info.name); 391 327 392 328 cmd_initialize(&addbkpt_info); 393 329 if (!cmd_register(&addbkpt_info)) 394 p anic("couldnot register command %s\n", addbkpt_info.name);330 printf("Cannot register command %s\n", addbkpt_info.name); 395 331 396 332 cmd_initialize(&addwatchp_info); 397 333 if (!cmd_register(&addwatchp_info)) 398 panic("could not register command %s\n", addwatchp_info.name); 399 #endif 334 printf("Cannot register command %s\n", addwatchp_info.name); 335 #endif /* CONFIG_DEBUG_AS_WATCHPOINT */ 336 #endif /* CONFIG_KCONSOLE */ 400 337 401 338 exc_register(VECTOR_DEBUG, "debugger", debug_exception); … … 405 342 } 406 343 344 #ifdef CONFIG_KCONSOLE 345 /** Print table of active breakpoints */ 346 int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) 347 { 348 unsigned int i; 349 char *symbol; 350 351 #ifdef __32_BITS__ 352 printf("# Count Address In symbol\n"); 353 printf("-- ----- ---------- ---------\n"); 354 #endif 355 356 #ifdef __64_BITS__ 357 printf("# Count Address In symbol\n"); 358 printf("-- ----- ------------------ ---------\n"); 359 #endif 360 361 for (i = 0; i < BKPOINTS_MAX; i++) 362 if (breakpoints[i].address) { 363 symbol = get_symtab_entry(breakpoints[i].address); 364 365 #ifdef __32_BITS__ 366 printf("%-2u %-5d %#10zx %s\n", i, 367 breakpoints[i].counter, breakpoints[i].address, 368 symbol); 369 #endif 370 371 #ifdef __64_BITS__ 372 printf("%-2u %-5d %#18zx %s\n", i, 373 breakpoints[i].counter, breakpoints[i].address, 374 symbol); 375 #endif 376 377 } 378 return 1; 379 } 380 381 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 382 383 /** Remove breakpoint from table */ 384 int cmd_del_breakpoint(cmd_arg_t *argv) 385 { 386 unative_t bpno = argv->intval; 387 if (bpno > BKPOINTS_MAX) { 388 printf("Invalid breakpoint number.\n"); 389 return 0; 390 } 391 breakpoint_del(argv->intval); 392 return 1; 393 } 394 395 /** Add new breakpoint to table */ 396 static int cmd_add_breakpoint(cmd_arg_t *argv) 397 { 398 int flags; 399 int id; 400 401 if (argv == &add_argv) { 402 flags = BKPOINT_INSTR; 403 } else { /* addwatchp */ 404 flags = BKPOINT_WRITE; 405 } 406 printf("Adding breakpoint on address: %p\n", argv->intval); 407 id = breakpoint_add((void *)argv->intval, flags, -1); 408 if (id < 0) 409 printf("Add breakpoint failed.\n"); 410 else 411 printf("Added breakpoint %d.\n", id); 412 413 return 1; 414 } 415 #endif /* CONFIG_DEBUG_AS_WATCHPOINT */ 416 #endif /* CONFIG_KCONSOLE */ 417 407 418 /** @} 408 419 */ -
kernel/arch/ia32/include/drivers/ega.h
r8fe5980 r76fca31 41 41 #define SCREEN (ROW * ROWS) 42 42 43 extern void ega_redraw(void); 43 44 extern void ega_init(void); 44 45 -
kernel/arch/ia32/include/drivers/vesa.h
r8fe5980 r76fca31 37 37 38 38 extern int vesa_present(void); 39 extern void vesa_redraw(void); 39 40 extern void vesa_init(void); 40 41 -
kernel/arch/ia32/src/cpu/cpu.c
r8fe5980 r76fca31 66 66 static char *vendor_str[] = { 67 67 "Unknown Vendor", 68 "A uthenticAMD",69 " GenuineIntel"68 "AMD", 69 "Intel" 70 70 }; 71 71 … … 78 78 : 79 79 : 80 : "%eax"80 : "%eax" 81 81 ); 82 82 } … … 90 90 : 91 91 : 92 : "%eax"92 : "%eax" 93 93 ); 94 94 } … … 141 141 * Check for AMD processor. 142 142 */ 143 if (info.cpuid_ebx==AMD_CPUID_EBX && info.cpuid_ecx==AMD_CPUID_ECX && info.cpuid_edx==AMD_CPUID_EDX) { 143 if ((info.cpuid_ebx == AMD_CPUID_EBX) 144 && (info.cpuid_ecx == AMD_CPUID_ECX) 145 && (info.cpuid_edx == AMD_CPUID_EDX)) 144 146 CPU->arch.vendor = VendorAMD; 145 } 146 147 147 148 /* 148 149 * Check for Intel processor. 149 150 */ 150 if (info.cpuid_ebx==INTEL_CPUID_EBX && info.cpuid_ecx==INTEL_CPUID_ECX && info.cpuid_edx==INTEL_CPUID_EDX) { 151 if ((info.cpuid_ebx == INTEL_CPUID_EBX) 152 && (info.cpuid_ecx == INTEL_CPUID_ECX) 153 && (info.cpuid_edx == INTEL_CPUID_EDX)) 151 154 CPU->arch.vendor = VendorIntel; 152 } 153 155 154 156 cpuid(1, &info); 155 CPU->arch.family = (info.cpuid_eax >>8)&0xf;156 CPU->arch.model = (info.cpuid_eax >>4)&0xf;157 CPU->arch.stepping = (info.cpuid_eax >>0)&0xf;157 CPU->arch.family = (info.cpuid_eax >> 8) & 0x0f; 158 CPU->arch.model = (info.cpuid_eax >> 4) & 0x0f; 159 CPU->arch.stepping = (info.cpuid_eax >> 0) & 0x0f; 158 160 } 159 161 } 160 162 161 void cpu_print_report(cpu_t* m)163 void cpu_print_report(cpu_t* cpu) 162 164 { 163 printf("cpu% d: (%s family=%d model=%d stepping=%d) %dMHz\n",164 m->id, vendor_str[m->arch.vendor], m->arch.family, m->arch.model, m->arch.stepping,165 m->frequency_mhz);165 printf("cpu%u: (%s family=%u model=%u stepping=%u) %" PRIu16 " MHz\n", 166 cpu->id, vendor_str[cpu->arch.vendor], cpu->arch.family, 167 cpu->arch.model, cpu->arch.stepping, cpu->frequency_mhz); 166 168 } 167 169 -
kernel/arch/ia32/src/drivers/vesa.c
r8fe5980 r76fca31 98 98 } 99 99 100 void vesa_redraw(void) 101 { 102 fb_redraw(); 103 } 104 100 105 #endif 101 106 -
kernel/arch/ia32/src/ia32.c
r8fe5980 r76fca31 94 94 else 95 95 #endif 96 ega_init(); 96 ega_init(); /* video */ 97 97 98 98 /* Enable debugger */ … … 160 160 void arch_grab_console(void) 161 161 { 162 #ifdef CONFIG_FB 163 vesa_redraw(); 164 #else 165 ega_redraw(); 166 #endif 167 162 168 i8042_grab(); 163 169 } 170 164 171 /** Return console to userspace 165 172 * -
kernel/arch/mips32/src/cpu/cpu.c
r8fe5980 r76fca31 49 49 { "MIPS", "R3000" }, /* 0x02 */ 50 50 { "MIPS", "R6000" }, /* 0x03 */ 51 { "MIPS", " 51 { "MIPS", "R4000/R4400" }, /* 0x04 */ 52 52 { "LSI Logic", "R3000" }, /* 0x05 */ 53 53 { "MIPS", "R6000A" }, /* 0x06 */ … … 124 124 } 125 125 126 printf("cpu% d: %s %s (rev=%d.%d, imp=%d)\n",126 printf("cpu%u: %s %s (rev=%d.%d, imp=%d)\n", 127 127 m->id, data->vendor, data->model, m->arch.rev_num >> 4, 128 m->arch.rev_num & 0x f, m->arch.imp_num);128 m->arch.rev_num & 0x0f, m->arch.imp_num); 129 129 } 130 130 -
kernel/arch/mips32/src/debugger.c
r8fe5980 r76fca31 47 47 bpinfo_t breakpoints[BKPOINTS_MAX]; 48 48 SPINLOCK_INITIALIZE(bkpoint_lock); 49 50 #ifdef CONFIG_KCONSOLE 49 51 50 52 static int cmd_print_breakpoints(cmd_arg_t *argv); … … 124 126 }; 125 127 128 126 129 /** Test, if the given instruction is a jump or branch instruction 127 130 * 128 131 * @param instr Instruction code 129 132 * @return true - it is jump instruction, false otherwise 133 * 130 134 */ 131 135 static bool is_jump(unative_t instr) … … 268 272 } 269 273 274 #endif 275 270 276 /** Initialize debugger */ 271 277 void debugger_init() … … 275 281 for (i = 0; i < BKPOINTS_MAX; i++) 276 282 breakpoints[i].address = NULL; 277 283 284 #ifdef CONFIG_KCONSOLE 278 285 cmd_initialize(&bkpts_info); 279 286 if (!cmd_register(&bkpts_info)) 280 p anic("couldnot register command %s\n", bkpts_info.name);287 printf("Cannot register command %s\n", bkpts_info.name); 281 288 282 289 cmd_initialize(&delbkpt_info); 283 290 if (!cmd_register(&delbkpt_info)) 284 p anic("couldnot register command %s\n", delbkpt_info.name);291 printf("Cannot register command %s\n", delbkpt_info.name); 285 292 286 293 cmd_initialize(&addbkpt_info); 287 294 if (!cmd_register(&addbkpt_info)) 288 p anic("couldnot register command %s\n", addbkpt_info.name);295 printf("Cannot register command %s\n", addbkpt_info.name); 289 296 290 297 cmd_initialize(&addbkpte_info); 291 298 if (!cmd_register(&addbkpte_info)) 292 panic("could not register command %s\n", addbkpte_info.name); 299 printf("Cannot register command %s\n", addbkpte_info.name); 300 #endif 293 301 } 294 302 … … 368 376 cur->bkfunc(cur, istate); 369 377 } else { 370 printf("***Type 'exit' to exit kconsole.\n"); 378 #ifdef CONFIG_KCONSOLE 371 379 /* This disables all other processors - we are not SMP, 372 380 * actually this gets us to cpu_halt, if scheduler() is run … … 374 382 * so this is a good idea 375 383 */ 376 atomic_set(&haltstate, 1);384 atomic_set(&haltstate, 1); 377 385 spinlock_unlock(&bkpoint_lock); 378 379 kconsole("debug" );380 386 387 kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false); 388 381 389 spinlock_lock(&bkpoint_lock); 382 atomic_set(&haltstate,0); 390 atomic_set(&haltstate, 0); 391 #endif 383 392 } 384 393 if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) { -
kernel/arch/mips32/src/exception.c
r8fe5980 r76fca31 46 46 #include <interrupt.h> 47 47 #include <func.h> 48 #include <console/kconsole.h>49 48 #include <ddi/irq.h> 50 49 #include <arch/debugger.h> -
kernel/genarch/include/fb/fb.h
r8fe5980 r76fca31 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 66 66 67 67 SPINLOCK_EXTERN(fb_lock); 68 69 void fb_redraw(void); 68 70 void fb_init(fb_properties_t *props); 69 71 -
kernel/genarch/include/fb/font-8x16.h
r8fe5980 r76fca31 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 36 36 #define KERN_FONT_8X16_H_ 37 37 38 #define FONT_GLIPHS 256 39 #define FONT_SCANLINES 16 38 #define FONT_GLYPHS 256 39 #define FONT_WIDTH 8 40 #define FONT_SCANLINES 16 40 41 41 extern unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES]; 42 #include <arch/types.h> 43 44 extern uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES]; 42 45 43 46 #endif -
kernel/genarch/include/fb/visuals.h
r8fe5980 r76fca31 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 36 36 #define KERN_VISUALS_H_ 37 37 38 #define VISUAL_INDIRECT_8 38 #define VISUAL_INDIRECT_8 0 39 39 40 #define VISUAL_RGB_5_5_5 41 #define VISUAL_RGB_5_6_5 42 #define VISUAL_RGB_8_8_8 43 #define VISUAL_RGB_8_8_8_0 44 #define VISUAL_RGB_0_8_8_8 40 #define VISUAL_RGB_5_5_5 1 41 #define VISUAL_RGB_5_6_5 2 42 #define VISUAL_RGB_8_8_8 3 43 #define VISUAL_RGB_8_8_8_0 4 44 #define VISUAL_RGB_0_8_8_8 5 45 45 46 #define VISUAL_BGR_0_8_8_8 46 #define VISUAL_BGR_0_8_8_8 6 47 47 48 48 #endif -
kernel/genarch/src/acpi/acpi.c
r8fe5980 r76fca31 50 50 struct acpi_xsdt *acpi_xsdt = NULL; 51 51 52 struct acpi_signature_map signature_map[] = { 53 { (uint8_t *)"APIC", (void *) &acpi_madt, "Multiple APIC Description Table" } 52 struct acpi_signature_map signature_map[] = { 53 { 54 (uint8_t *) "APIC", 55 (void *) &acpi_madt, 56 "Multiple APIC Description Table" 57 } 54 58 }; 55 59 … … 106 110 goto next; 107 111 *signature_map[j].sdt_ptr = h; 108 printf("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);112 LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description); 109 113 } 110 114 } … … 127 131 goto next; 128 132 *signature_map[j].sdt_ptr = h; 129 printf("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);133 LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description); 130 134 } 131 135 } … … 161 165 162 166 rsdp_found: 163 printf("%p: ACPI Root System Description Pointer\n", acpi_rsdp);167 LOG("%p: ACPI Root System Description Pointer\n", acpi_rsdp); 164 168 165 169 acpi_rsdt = (struct acpi_rsdt *) (unative_t) acpi_rsdp->rsdt_address; -
kernel/genarch/src/fb/fb.c
r8fe5980 r76fca31 1 1 /* 2 * Copyright (c) 2008 Martin Decky 2 3 * Copyright (c) 2006 Ondrej Palkovsky 3 4 * All rights reserved. … … 27 28 */ 28 29 29 /** @addtogroup genarch 30 /** @addtogroup genarch 30 31 * @{ 31 32 */ … … 40 41 #include <sysinfo/sysinfo.h> 41 42 #include <mm/slab.h> 43 #include <align.h> 42 44 #include <panic.h> 43 45 #include <memstr.h> … … 48 50 #include <arch/types.h> 49 51 50 #include "helenos.xbm"51 52 static parea_t fb_parea; /**< Physical memory area for fb. */53 54 52 SPINLOCK_INITIALIZE(fb_lock); 55 53 56 static uint8_t *fbaddress = NULL; 57 58 static uint8_t *blankline = NULL; 59 static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ 60 static index_t dboffset; 61 62 static unsigned int xres = 0; 63 static unsigned int yres = 0; 64 static unsigned int scanline = 0; 65 static unsigned int pixelbytes = 0; 66 #ifdef FB_INVERT_COLORS 67 static bool invert_colors = true; 54 /**< Physical memory area for fb. */ 55 static parea_t fb_parea; 56 57 static uint8_t *fb_addr; 58 static uint8_t *backbuf; 59 static uint8_t *glyphs; 60 61 static void *bgpixel; 62 63 static unsigned int xres; 64 static unsigned int yres; 65 66 static unsigned int scanline; 67 static unsigned int glyphscanline; 68 69 static unsigned int pixelbytes; 70 static unsigned int glyphbytes; 71 72 static unsigned int cols; 73 static unsigned int rows; 74 static unsigned int position = 0; 75 76 #define BG_COLOR 0x000080 77 #define FG_COLOR 0xffff00 78 79 #define CURSOR 219 80 81 #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) 82 #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) 83 #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) 84 85 #define COL2X(col) ((col) * FONT_WIDTH) 86 #define ROW2Y(row) ((row) * FONT_SCANLINES) 87 88 #define X2COL(x) ((x) / FONT_WIDTH) 89 #define Y2ROW(y) ((y) / FONT_SCANLINES) 90 91 #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) 92 #define BB_POS(col, row) ((row) * cols + (col)) 93 #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) 94 95 96 static void (*rgb_conv)(void *, uint32_t); 97 98 99 /** ARGB 8:8:8:8 conversion 100 * 101 */ 102 static void rgb_0888(void *dst, uint32_t rgb) 103 { 104 *((uint32_t *) dst) = rgb & 0xffffff; 105 } 106 107 108 /** ABGR 8:8:8:8 conversion 109 * 110 */ 111 static void bgr_0888(void *dst, uint32_t rgb) 112 { 113 *((uint32_t *) dst) 114 = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); 115 } 116 117 118 /** BGR 8:8:8 conversion 119 * 120 */ 121 static void rgb_888(void *dst, uint32_t rgb) 122 { 123 #if defined(FB_INVERT_ENDIAN) 124 *((uint32_t *) dst) 125 = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8) 126 | (*((uint32_t *) dst) & 0xff0000); 68 127 #else 69 static bool invert_colors = false; 128 *((uint32_t *) dst) 129 = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000); 70 130 #endif 71 72 static unsigned int position = 0; 73 static unsigned int columns = 0; 74 static unsigned int rows = 0; 75 76 #define COL_WIDTH 8 77 #define ROW_BYTES (scanline * FONT_SCANLINES) 78 79 #define BGCOLOR 0x000080 80 #define FGCOLOR 0xffff00 81 #define LOGOCOLOR 0x2020b0 82 83 #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) 84 #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) 85 #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) 86 87 #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) 88 89 /***************************************************************/ 90 /* Pixel specific fuctions */ 91 92 static void (*rgb2scr)(void *, int); 93 static int (*scr2rgb)(void *); 94 95 static inline int COLOR(int color) 96 { 97 return invert_colors ? ~color : color; 98 } 99 100 /* Conversion routines between different color representations */ 101 static void rgb_byte0888(void *dst, int rgb) 102 { 103 *((int *) dst) = rgb; 104 } 105 106 static int byte0888_rgb(void *src) 107 { 108 return (*((int *) src)) & 0xffffff; 109 } 110 111 static void bgr_byte0888(void *dst, int rgb) 112 { 113 *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | 114 RED(rgb, 8); 115 } 116 117 static int byte0888_bgr(void *src) 118 { 119 int color = *(uint32_t *)(src); 120 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | 121 ((color >> 16) & 0xff); 122 } 123 124 static void rgb_byte888(void *dst, int rgb) 125 { 126 uint8_t *scr = (uint8_t *) dst; 127 #if defined(FB_INVERT_ENDIAN) 128 scr[0] = RED(rgb, 8); 129 scr[1] = GREEN(rgb, 8); 130 scr[2] = BLUE(rgb, 8); 131 #else 132 scr[2] = RED(rgb, 8); 133 scr[1] = GREEN(rgb, 8); 134 scr[0] = BLUE(rgb, 8); 135 #endif 136 } 137 138 static int byte888_rgb(void *src) 139 { 140 uint8_t *scr = (uint8_t *) src; 141 #if defined(FB_INVERT_ENDIAN) 142 return scr[0] << 16 | scr[1] << 8 | scr[2]; 143 #else 144 return scr[2] << 16 | scr[1] << 8 | scr[0]; 145 #endif 146 } 147 148 /** 16-bit depth (5:5:5) */ 149 static void rgb_byte555(void *dst, int rgb) 150 { 151 /* 5-bit, 5-bits, 5-bits */ 152 *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | 153 BLUE(rgb, 5); 154 } 155 156 /** 16-bit depth (5:5:5) */ 157 static int byte555_rgb(void *src) 158 { 159 int color = *(uint16_t *)(src); 160 return (((color >> 10) & 0x1f) << (16 + 3)) | 161 (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); 162 } 163 164 /** 16-bit depth (5:6:5) */ 165 static void rgb_byte565(void *dst, int rgb) 166 { 167 /* 5-bit, 6-bits, 5-bits */ 168 *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | 169 BLUE(rgb, 5); 170 } 171 172 /** 16-bit depth (5:6:5) */ 173 static int byte565_rgb(void *src) 174 { 175 int color = *(uint16_t *)(src); 176 return (((color >> 11) & 0x1f) << (16 + 3)) | 177 (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); 178 } 179 180 /** Put pixel - 8-bit depth (color palette/3:2:3, inverted) 131 } 132 133 134 /** RGB 5:5:5 conversion 135 * 136 */ 137 static void rgb_555(void *dst, uint32_t rgb) 138 { 139 *((uint16_t *) dst) 140 = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); 141 } 142 143 144 /** RGB 5:6:5 conversion 145 * 146 */ 147 static void rgb_565(void *dst, uint32_t rgb) 148 { 149 *((uint16_t *) dst) 150 = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); 151 } 152 153 154 /** RGB 3:2:3 181 155 * 182 156 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer … … 186 160 * and setting it to simulate the 8-bit truecolor. 187 161 * 188 * Currently we set the palette on the sparc64 port.162 * Currently we set the palette on the ia32 and sparc64 port. 189 163 * 190 164 * Note that the byte is being inverted by this function. The reason is … … 194 168 * 0 and 255 to other colors. 195 169 */ 196 static void rgb_byte8(void *dst, int rgb) 197 { 198 *((uint8_t *) dst) = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | 199 BLUE(rgb, 3)); 200 } 201 202 /** Return pixel color - 8-bit depth (color palette/3:2:3) 203 * 204 * See the comment for rgb_byte(). 205 */ 206 static int byte8_rgb(void *src) 207 { 208 int color = 255 - (*(uint8_t *)src); 209 return (((color >> 5) & 0x7) << (16 + 5)) | 210 (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); 211 } 212 213 static void putpixel(unsigned int x, unsigned int y, int color) 214 { 215 (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); 216 217 if (dbbuffer) { 218 int dline = (y + dboffset) % yres; 219 (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); 220 } 221 } 222 223 /** Get pixel from viewport */ 224 static int getpixel(unsigned int x, unsigned int y) 225 { 226 if (dbbuffer) { 227 int dline = (y + dboffset) % yres; 228 return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); 229 } 230 return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); 231 } 232 233 234 /** Fill screen with background color */ 235 static void clear_screen(void) 236 { 237 unsigned int y; 238 239 for (y = 0; y < yres; y++) { 240 memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); 241 if (dbbuffer) 242 memcpy(&dbbuffer[scanline * y], blankline, 243 xres * pixelbytes); 244 } 245 } 246 247 248 /** Scroll screen one row up */ 170 static void rgb_323(void *dst, uint32_t rgb) 171 { 172 *((uint8_t *) dst) 173 = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); 174 } 175 176 177 /** Draw character at given position 178 * 179 */ 180 static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) 181 { 182 unsigned int x = COL2X(col); 183 unsigned int y = ROW2Y(row); 184 unsigned int yd; 185 186 backbuf[BB_POS(col, row)] = glyph; 187 188 for (yd = 0; yd < FONT_SCANLINES; yd++) 189 memcpy(&fb_addr[FB_POS(x, y + yd)], 190 &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); 191 } 192 193 194 /** Scroll screen down by one row 195 * 196 * 197 */ 249 198 static void scroll_screen(void) 250 199 { 251 if (dbbuffer) { 252 count_t first; 200 unsigned int row; 201 202 for (row = 0; row < rows; row++) { 203 unsigned int y = ROW2Y(row); 204 unsigned int yd; 253 205 254 /* Clear the last row */ 255 memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); 256 257 dboffset = (dboffset + FONT_SCANLINES) % yres; 258 first = yres - dboffset; 259 260 /* Move all rows one row up */ 261 if (xres * pixelbytes == scanline) { 262 memcpy(fbaddress, &dbbuffer[dboffset * scanline], 263 first * scanline); 264 memcpy(&fbaddress[first * scanline], dbbuffer, 265 dboffset * scanline); 266 } else { 267 /* 268 * When the scanline is bigger than number of bytes 269 * in the X-resolution, chances are that the 270 * frame buffer memory past the X-resolution is special 271 * in some way. For example, the SUNW,ffb framebuffer 272 * wraps this area around the beginning of the same 273 * line. To avoid troubles, copy only memory as 274 * specified by the resolution. 275 */ 276 unsigned int i; 277 278 for (i = 0; i < first; i++) 279 memcpy(&fbaddress[i * scanline], 280 &dbbuffer[(dboffset + i) * scanline], 281 xres * pixelbytes); 282 for (i = 0; i < dboffset; i++) 283 memcpy(&fbaddress[(first + i) * scanline], 284 &dbbuffer[i * scanline], xres * pixelbytes); 206 for (yd = 0; yd < FONT_SCANLINES; yd++) { 207 unsigned int x; 208 unsigned int col; 209 210 for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) { 211 uint8_t glyph; 212 213 if (row < rows - 1) { 214 if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)]) 215 continue; 216 217 glyph = backbuf[BB_POS(col, row + 1)]; 218 } else 219 glyph = 0; 220 221 memcpy(&fb_addr[FB_POS(x, y + yd)], 222 &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); 223 } 285 224 } 286 } else { 287 uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; 288 289 if (xres * pixelbytes == scanline) { 290 /* Move all rows one row up */ 291 memcpy((void *) fbaddress, 292 (void *) &fbaddress[ROW_BYTES], 293 scanline * yres - ROW_BYTES); 294 /* Clear the last row */ 295 memcpy((void *) lastline, (void *) blankline, 296 ROW_BYTES); 297 } else { 298 /* 299 * See the comment in the dbbuffer case. 300 */ 301 unsigned int i; 302 303 /* Move all rows one row up */ 304 for (i = 0; i < yres - FONT_SCANLINES; i++) 305 memcpy(&fbaddress[i * scanline], 306 &fbaddress[(i + FONT_SCANLINES) * scanline], 307 xres * pixelbytes); 308 /* Clear the last row */ 309 for (i = 0; i < FONT_SCANLINES; i++) 310 memcpy(&lastline[i * scanline], 311 &blankline[i * scanline], 312 xres * pixelbytes); 313 } 314 } 315 } 316 317 318 static void invert_pixel(unsigned int x, unsigned int y) 319 { 320 putpixel(x, y, ~getpixel(x, y)); 321 } 322 323 324 /** Draw one line of glyph at a given position */ 325 static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) 326 { 327 unsigned int i; 328 329 for (i = 0; i < 8; i++) 330 if (glline & (1 << (7 - i))) { 331 putpixel(x + i, y, FGCOLOR); 332 } else 333 putpixel(x + i, y, BGCOLOR); 334 } 335 336 /***************************************************************/ 337 /* Character-console functions */ 338 339 /** Draw character at given position */ 340 static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) 341 { 342 unsigned int y; 343 344 for (y = 0; y < FONT_SCANLINES; y++) 345 draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], 346 col * COL_WIDTH, row * FONT_SCANLINES + y); 347 } 348 349 /** Invert character at given position */ 350 static void invert_char(unsigned int col, unsigned int row) 351 { 352 unsigned int x; 353 unsigned int y; 354 355 for (x = 0; x < COL_WIDTH; x++) 356 for (y = 0; y < FONT_SCANLINES; y++) 357 invert_pixel(col * COL_WIDTH + x, 358 row * FONT_SCANLINES + y); 359 } 360 361 /** Draw character at default position */ 362 static void draw_char(char chr) 363 { 364 draw_glyph(chr, position % columns, position / columns); 365 } 366 367 static void draw_logo(unsigned int startx, unsigned int starty) 368 { 369 unsigned int x; 370 unsigned int y; 371 unsigned int byte; 372 unsigned int rowbytes; 373 374 rowbytes = (helenos_width - 1) / 8 + 1; 375 376 for (y = 0; y < helenos_height; y++) 377 for (x = 0; x < helenos_width; x++) { 378 byte = helenos_bits[rowbytes * y + x / 8]; 379 byte >>= x % 8; 380 if (byte & 1) 381 putpixel(startx + x, starty + y, 382 COLOR(LOGOCOLOR)); 383 } 384 } 385 386 /***************************************************************/ 387 /* Stdout specific functions */ 388 389 static void invert_cursor(void) 390 { 391 invert_char(position % columns, position / columns); 392 } 225 } 226 227 memcpy(backbuf, backbuf + cols, cols * (rows - 1)); 228 memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0); 229 } 230 231 232 static void cursor_put(void) 233 { 234 draw_glyph(CURSOR, position % cols, position / cols); 235 } 236 237 238 static void cursor_remove(void) 239 { 240 draw_glyph(0, position % cols, position / cols); 241 } 242 393 243 394 244 /** Print character to screen 395 245 * 396 * Emulate basic terminal commands 246 * Emulate basic terminal commands. 247 * 397 248 */ 398 249 static void fb_putchar(chardev_t *dev, char ch) … … 402 253 switch (ch) { 403 254 case '\n': 404 invert_cursor();405 position += col umns;406 position -= position % col umns;255 cursor_remove(); 256 position += cols; 257 position -= position % cols; 407 258 break; 408 259 case '\r': 409 invert_cursor();410 position -= position % col umns;260 cursor_remove(); 261 position -= position % cols; 411 262 break; 412 263 case '\b': 413 invert_cursor();414 if (position % col umns)264 cursor_remove(); 265 if (position % cols) 415 266 position--; 416 267 break; 417 268 case '\t': 418 invert_cursor();269 cursor_remove(); 419 270 do { 420 draw_ char(' ');271 draw_glyph((uint8_t) ' ', position % cols, position / cols); 421 272 position++; 422 } while ((position % 8) && position < columns * rows);273 } while ((position % 8) && (position < cols * rows)); 423 274 break; 424 275 default: 425 draw_ char(ch);276 draw_glyph((uint8_t) ch, position % cols, position / cols); 426 277 position++; 427 278 } 428 279 429 if (position >= col umns * rows) {430 position -= col umns;280 if (position >= cols * rows) { 281 position -= cols; 431 282 scroll_screen(); 432 283 } 433 284 434 invert_cursor();285 cursor_put(); 435 286 436 287 spinlock_unlock(&fb_lock); … … 443 294 444 295 296 /** Render glyphs 297 * 298 * Convert glyphs from device independent font 299 * description to current visual representation. 300 * 301 */ 302 static void render_glyphs(void) 303 { 304 unsigned int glyph; 305 306 for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { 307 unsigned int y; 308 309 for (y = 0; y < FONT_SCANLINES; y++) { 310 unsigned int x; 311 312 for (x = 0; x < FONT_WIDTH; x++) 313 rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes], 314 (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR); 315 } 316 } 317 318 rgb_conv(bgpixel, BG_COLOR); 319 } 320 321 322 /** Refresh the screen 323 * 324 */ 325 void fb_redraw(void) 326 { 327 unsigned int row; 328 329 for (row = 0; row < rows; row++) { 330 unsigned int y = ROW2Y(row); 331 unsigned int yd; 332 333 for (yd = 0; yd < FONT_SCANLINES; yd++) { 334 unsigned int x; 335 unsigned int col; 336 337 for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) 338 memcpy(&fb_addr[FB_POS(x, y + yd)], 339 &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)], 340 glyphscanline); 341 } 342 } 343 344 if (COL2X(cols) < xres) { 345 unsigned int y; 346 347 for (y = 0; y < yres; y++) { 348 unsigned int x; 349 350 for (x = COL2X(cols); x < xres; x++) 351 memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes); 352 } 353 } 354 355 if (ROW2Y(rows) < yres) { 356 unsigned int y; 357 358 for (y = ROW2Y(rows); y < yres; y++) { 359 unsigned int x; 360 361 for (x = 0; x < xres; x++) 362 memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes); 363 } 364 } 365 } 366 367 445 368 /** Initialize framebuffer as a chardev output device 446 369 * 447 * @param props Properties of the framebuffer device. 370 * @param addr Physical address of the framebuffer 371 * @param x Screen width in pixels 372 * @param y Screen height in pixels 373 * @param scan Bytes per one scanline 374 * @param visual Color model 375 * 448 376 */ 449 377 void fb_init(fb_properties_t *props) … … 451 379 switch (props->visual) { 452 380 case VISUAL_INDIRECT_8: 453 rgb2scr = rgb_byte8; 454 scr2rgb = byte8_rgb; 381 rgb_conv = rgb_323; 455 382 pixelbytes = 1; 456 383 break; 457 384 case VISUAL_RGB_5_5_5: 458 rgb2scr = rgb_byte555; 459 scr2rgb = byte555_rgb; 385 rgb_conv = rgb_555; 460 386 pixelbytes = 2; 461 387 break; 462 388 case VISUAL_RGB_5_6_5: 463 rgb2scr = rgb_byte565; 464 scr2rgb = byte565_rgb; 389 rgb_conv = rgb_565; 465 390 pixelbytes = 2; 466 391 break; 467 392 case VISUAL_RGB_8_8_8: 468 rgb2scr = rgb_byte888; 469 scr2rgb = byte888_rgb; 393 rgb_conv = rgb_888; 470 394 pixelbytes = 3; 471 395 break; 472 396 case VISUAL_RGB_8_8_8_0: 473 rgb2scr = rgb_byte888; 474 scr2rgb = byte888_rgb; 397 rgb_conv = rgb_888; 475 398 pixelbytes = 4; 476 399 break; 477 400 case VISUAL_RGB_0_8_8_8: 478 rgb2scr = rgb_byte0888; 479 scr2rgb = byte0888_rgb; 401 rgb_conv = rgb_0888; 480 402 pixelbytes = 4; 481 403 break; 482 404 case VISUAL_BGR_0_8_8_8: 483 rgb2scr = bgr_byte0888; 484 scr2rgb = byte0888_bgr; 405 rgb_conv = bgr_0888; 485 406 pixelbytes = 4; 486 407 break; … … 488 409 panic("Unsupported visual.\n"); 489 410 } 490 491 unsigned int fbsize = props->scan * props->y;492 493 /* Map the framebuffer */494 fbaddress = (uint8_t *) hw_map((uintptr_t) props->addr,495 fbsize + props->offset);496 fbaddress += props->offset;497 411 498 412 xres = props->x; … … 500 414 scanline = props->scan; 501 415 502 rows = props->y / FONT_SCANLINES; 503 columns = props->x / COL_WIDTH; 504 416 cols = xres / FONT_WIDTH; 417 rows = yres / FONT_SCANLINES; 418 419 glyphscanline = FONT_WIDTH * pixelbytes; 420 glyphbytes = glyphscanline * FONT_SCANLINES; 421 422 unsigned int fbsize = scanline * yres; 423 unsigned int bbsize = cols * rows; 424 unsigned int glyphsize = FONT_GLYPHS * glyphbytes; 425 426 backbuf = (uint8_t *) malloc(bbsize, 0); 427 if (!backbuf) 428 panic("Unable to allocate backbuffer.\n"); 429 430 glyphs = (uint8_t *) malloc(glyphsize, 0); 431 if (!glyphs) 432 panic("Unable to allocate glyphs.\n"); 433 434 bgpixel = malloc(pixelbytes, 0); 435 if (!bgpixel) 436 panic("Unable to allocate background pixel.\n"); 437 438 memsetb(backbuf, bbsize, 0); 439 memsetb(glyphs, glyphsize, 0); 440 memsetb(bgpixel, pixelbytes, 0); 441 442 render_glyphs(); 443 444 fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); 445 505 446 fb_parea.pbase = (uintptr_t) props->addr + props->offset; 506 fb_parea.vbase = (uintptr_t) fb address;447 fb_parea.vbase = (uintptr_t) fb_addr; 507 448 fb_parea.frames = SIZE2FRAMES(fbsize); 508 449 fb_parea.cacheable = false; 509 450 ddi_parea_register(&fb_parea); 510 451 511 452 sysinfo_set_item_val("fb", NULL, true); 512 453 sysinfo_set_item_val("fb.kind", NULL, 1); 513 454 sysinfo_set_item_val("fb.width", NULL, xres); 514 455 sysinfo_set_item_val("fb.height", NULL, yres); 515 sysinfo_set_item_val("fb.scanline", NULL, props->scan);456 sysinfo_set_item_val("fb.scanline", NULL, scanline); 516 457 sysinfo_set_item_val("fb.visual", NULL, props->visual); 517 458 sysinfo_set_item_val("fb.address.physical", NULL, props->addr); 518 sysinfo_set_item_val("fb.offset", NULL, props->offset); 519 sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); 520 521 /* Allocate double buffer */ 522 unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; 523 dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); 524 if (!dbbuffer) 525 printf("Failed to allocate scroll buffer.\n"); 526 dboffset = 0; 527 528 /* Initialized blank line */ 529 blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); 530 if (!blankline) 531 panic("Failed to allocate blank line for framebuffer."); 532 unsigned int x, y; 533 for (y = 0; y < FONT_SCANLINES; y++) 534 for (x = 0; x < xres; x++) 535 (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); 536 537 clear_screen(); 538 539 /* Update size of screen to match text area */ 540 yres = rows * FONT_SCANLINES; 541 542 draw_logo(xres - helenos_width, 0); 543 invert_cursor(); 544 459 460 fb_redraw(); 461 545 462 chardev_initialize("fb", &framebuffer, &fb_ops); 546 463 stdout = &framebuffer; -
kernel/genarch/src/fb/font-8x16.c
r8fe5980 r76fca31 35 35 #include <genarch/fb/font-8x16.h> 36 36 37 u nsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES] = {37 uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES] = { 38 38 39 39 /* 0 0x00 '^@' */ -
kernel/genarch/src/mm/asid.c
r8fe5980 r76fca31 33 33 /** 34 34 * @file 35 * @brief 35 * @brief ASID management. 36 36 * 37 37 * Modern processor architectures optimize TLB utilization -
kernel/generic/include/console/kconsole.h
r8fe5980 r76fca31 88 88 89 89 extern void kconsole_init(void); 90 extern void kconsole(void *prompt); 90 extern void kconsole(char *prompt, char *msg, bool kcon); 91 extern void kconsole_thread(void *data); 91 92 92 93 extern int cmd_register(cmd_info_t *cmd); -
kernel/generic/src/console/cmd.c
r8fe5980 r76fca31 502 502 cmd_initialize(basic_commands[i]); 503 503 if (!cmd_register(basic_commands[i])) 504 p anic("couldnot register command %s\n", basic_commands[i]->name);504 printf("Cannot register command %s\n", basic_commands[i]->name); 505 505 } 506 506 } -
kernel/generic/src/console/console.c
r8fe5980 r76fca31 168 168 else 169 169 printf("cpu: "); 170 printf("halted - no kconsole\n");170 printf("halted (no kconsole)\n"); 171 171 cpu_halt(); 172 172 } -
kernel/generic/src/console/kconsole.c
r8fe5980 r76fca31 402 402 } 403 403 404 /** Kernel console managing thread.404 /** Kernel console prompt. 405 405 * 406 406 * @param prompt Kernel console prompt (e.g kconsole/panic). 407 */ 408 void kconsole(void *prompt) 407 * @param msg Message to display in the beginning. 408 * @param kcon Wait for keypress to show the prompt 409 * and never exit. 410 * 411 */ 412 void kconsole(char *prompt, char *msg, bool kcon) 409 413 { 410 414 cmd_info_t *cmd_info; … … 413 417 414 418 if (!stdin) { 415 printf("%s: no stdin\n", __func__);419 LOG("No stdin for kernel console"); 416 420 return; 417 421 } 422 423 if (msg) 424 printf("%s", msg); 425 426 if (kcon) 427 _getc(stdin); 418 428 419 429 while (true) { … … 422 432 if (!len) 423 433 continue; 434 424 435 cmd_info = parse_cmdline(cmdline, len); 425 436 if (!cmd_info) 426 437 continue; 427 if (strncmp(cmd_info->name, "exit", 428 min(strlen(cmd_info->name), 5)) == 0) 438 439 if ((!kcon) 440 && (strncmp(cmd_info->name, "exit", min(strlen(cmd_info->name), 5)) == 0)) 429 441 break; 442 430 443 (void) cmd_info->func(cmd_info->argv); 431 444 } 445 } 446 447 /** Kernel console managing thread. 448 * 449 */ 450 void kconsole_thread(void *data) 451 { 452 kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true); 432 453 } 433 454 -
kernel/generic/src/cpu/cpu.c
r8fe5980 r76fca31 87 87 #endif /* CONFIG_SMP */ 88 88 89 CPU = &cpus[config.cpu_active -1];89 CPU = &cpus[config.cpu_active - 1]; 90 90 91 91 CPU->active = 1; -
kernel/generic/src/interrupt/interrupt.c
r8fe5980 r76fca31 110 110 } 111 111 112 #ifdef CONFIG_KCONSOLE 113 112 114 /** kconsole cmd - print all exceptions */ 113 static int exc_print_cmd(cmd_arg_t *argv)115 static int cmd_exc_print(cmd_arg_t *argv) 114 116 { 115 117 #if (IVT_ITEMS > 0) … … 159 161 } 160 162 163 161 164 static cmd_info_t exc_info = { 162 165 .name = "exc", 163 166 .description = "Print exception table.", 164 .func = exc_print_cmd,167 .func = cmd_exc_print, 165 168 .help = NULL, 166 169 .argc = 0, 167 170 .argv = NULL 168 171 }; 172 173 #endif 169 174 170 175 /** Initialize generic exception handling support */ … … 176 181 exc_register(i, "undef", (iroutine) exc_undef); 177 182 183 #ifdef CONFIG_KCONSOLE 178 184 cmd_initialize(&exc_info); 179 185 if (!cmd_register(&exc_info)) 180 panic("could not register command %s\n", exc_info.name); 186 printf("Cannot register command %s\n", exc_info.name); 187 #endif 181 188 } 182 189 -
kernel/generic/src/lib/func.c
r8fe5980 r76fca31 56 56 bool rundebugger = false; 57 57 58 // TODO test_and_set not defined on all arches59 // if (!test_and_set(&haltstate))60 58 if (!atomic_get(&haltstate)) { 61 59 atomic_set(&haltstate, 1); … … 67 65 68 66 interrupts_disable(); 69 #ifdef CONFIG_DEBUG 70 if (rundebugger) { 71 printf("\n");72 kconsole("panic" ); /* Run kconsole as a last resort to user */73 } 74 #endif 67 68 #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE)) 69 if (rundebugger) 70 kconsole("panic", "\nLast resort kernel console ready\n", false); 71 #endif 72 75 73 if (CPU) 76 74 printf("cpu%u: halted\n", CPU->id); -
kernel/generic/src/main/kinit.c
r8fe5980 r76fca31 83 83 void kinit(void *arg) 84 84 { 85 thread_t *t; 85 86 #if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE) 87 thread_t *thread; 88 #endif 86 89 87 90 /* … … 101 104 * Just a beautification. 102 105 */ 103 if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED,104 "kmp", true))) {105 spinlock_lock(&t ->lock);106 t ->cpu = &cpus[0];107 spinlock_unlock(&t ->lock);108 thread_ready(t );106 thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true); 107 if (thread != NULL) { 108 spinlock_lock(&thread->lock); 109 thread->cpu = &cpus[0]; 110 spinlock_unlock(&thread->lock); 111 thread_ready(thread); 109 112 } else 110 panic(" thread_create/kmp\n");111 thread_join(t );112 thread_detach(t );113 panic("Unable to create kmp thread\n"); 114 thread_join(thread); 115 thread_detach(thread); 113 116 } 114 117 #endif /* CONFIG_SMP */ 115 /* 116 * Now that all CPUs are up, we can report what we've found. 117 */ 118 cpu_list(); 119 118 120 119 #ifdef CONFIG_SMP 121 120 if (config.cpu_count > 1) { … … 126 125 */ 127 126 for (i = 0; i < config.cpu_count; i++) { 128 129 if ((t = thread_create(kcpulb, NULL, TASK, 130 THREAD_FLAG_WIRED, "kcpulb", true))) { 131 spinlock_lock(&t->lock); 132 t->cpu = &cpus[i]; 133 spinlock_unlock(&t->lock); 134 thread_ready(t); 127 thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true); 128 if (thread != NULL) { 129 spinlock_lock(&thread->lock); 130 thread->cpu = &cpus[i]; 131 spinlock_unlock(&thread->lock); 132 thread_ready(thread); 135 133 } else 136 p anic("thread_create/kcpulb\n");134 printf("Unable to create kcpulb thread for cpu" PRIc "\n", i); 137 135 138 136 } 139 137 } 140 138 #endif /* CONFIG_SMP */ 141 139 142 140 /* 143 141 * At this point SMP, if present, is configured. … … 145 143 arch_post_smp_init(); 146 144 147 /* 148 * Create kernel console. 149 */ 150 t = thread_create(kconsole, (void *) "kconsole", TASK, 0, "kconsole", 151 false); 152 if (t) 153 thread_ready(t); 154 else 155 panic("thread_create/kconsole\n"); 156 145 #ifdef CONFIG_KCONSOLE 146 if (stdin) { 147 /* 148 * Create kernel console. 149 */ 150 thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false); 151 if (thread != NULL) 152 thread_ready(thread); 153 else 154 printf("Unable to create kconsole thread\n"); 155 } 156 #endif /* CONFIG_KCONSOLE */ 157 157 158 interrupts_enable(); 158 159 … … 165 166 for (i = 0; i < init.cnt; i++) { 166 167 if (init.tasks[i].addr % FRAME_SIZE) { 167 printf("init[%" PRIc "].addr is not frame aligned ", i);168 printf("init[%" PRIc "].addr is not frame aligned\n", i); 168 169 continue; 169 170 } 170 171 171 172 int rc = program_create_from_image((void *) init.tasks[i].addr, 172 173 "init-bin", &programs[i]); 173 174 if ( rc == 0 && programs[i].task != NULL) {174 175 if ((rc == 0) && (programs[i].task != NULL)) { 175 176 /* 176 177 * Set capabilities to init userspace tasks. … … 185 186 } else { 186 187 /* RAM disk image */ 187 int rd = init_rd((rd_header_t *) init.tasks[i].addr, 188 init.tasks[i].size); 188 int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size); 189 189 190 190 if (rd != RE_OK) 191 printf("Init binary %" PRIc " not used, error " 192 "code %d.\n", i, rd); 191 printf("Init binary %" PRIc " not used (error %d)\n", i, rd); 193 192 } 194 193 } … … 204 203 } 205 204 205 #ifdef CONFIG_KCONSOLE 206 206 if (!stdin) { 207 printf("kinit: No stdin\nKernel alive: "); 208 209 uint64_t i = 0; 207 210 while (1) { 211 printf(PRIu64 " ", i); 208 212 thread_sleep(1); 209 printf("kinit... "); 210 } 211 } 213 i++; 214 } 215 } 216 #endif /* CONFIG_KCONSOLE */ 212 217 } 213 218 -
kernel/generic/src/main/main.c
r8fe5980 r76fca31 192 192 /* Keep this the first thing. */ 193 193 the_initialize(THE); 194 195 LOG();196 194 197 195 version_print(); … … 201 199 config.base, config.kernel_size, config.stack_base, 202 200 config.stack_size); 203 204 201 202 #ifdef CONFIG_KCONSOLE 205 203 /* 206 204 * kconsole data structures must be initialized very early … … 209 207 */ 210 208 LOG_EXEC(kconsole_init()); 209 #endif 211 210 212 211 /* … … 253 252 count_t i; 254 253 for (i = 0; i < init.cnt; i++) 255 printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc254 LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc 256 255 "].size=%#" PRIs "\n", i, init.tasks[i].addr, i, 257 256 init.tasks[i].size); … … 272 271 * Create the first thread. 273 272 */ 274 thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit",275 273 thread_t *kinit_thread 274 = thread_create(kinit, NULL, kernel, 0, "kinit", true); 276 275 if (!kinit_thread) 277 276 panic("Can't create kinit thread\n"); -
kernel/generic/src/mm/as.c
r8fe5980 r76fca31 147 147 AS_KERNEL = as_create(FLAG_AS_KERNEL); 148 148 if (!AS_KERNEL) 149 panic("can't create kernel address space\n"); 150 149 panic("Cannot create kernel address space\n"); 150 151 /* Make sure the kernel address space 152 * reference count never drops to zero. 153 */ 154 atomic_set(&AS_KERNEL->refcount, 1); 151 155 } 152 156 … … 177 181 page_table_create(flags); 178 182 #endif 179 183 180 184 return as; 181 185 } … … 770 774 * into private anonymous memory (unless it's already there). 771 775 * 772 * @param as Address space. 773 * @param flags Flags of the area memory. 774 * @param address Address withing the area to be changed. 775 * 776 * @return Zero on success or a value from @ref errno.h on failure. 776 * @param as Address space. 777 * @param flags Flags of the area memory. 778 * @param address Address within the area to be changed. 779 * 780 * @return Zero on success or a value from @ref errno.h on failure. 781 * 777 782 */ 778 783 int as_area_change_flags(as_t *as, int flags, uintptr_t address) … … 786 791 index_t frame_idx; 787 792 count_t used_pages; 788 793 789 794 /* Flags for the new memory mapping */ 790 795 page_flags = area_flags_to_page_flags(flags); … … 800 805 } 801 806 802 if ( area->sh_info || area->backend != &anon_backend) {807 if ((area->sh_info) || (area->backend != &anon_backend)) { 803 808 /* Copying shared areas not supported yet */ 804 809 /* Copying non-anonymous memory not supported yet */ … … 871 876 872 877 tlb_invalidate_pages(as->asid, area->base, area->pages); 878 873 879 /* 874 880 * Invalidate potential software translation caches (e.g. TSB on -
kernel/generic/src/syscall/syscall.c
r8fe5980 r76fca31 93 93 static unative_t sys_debug_enable_console(void) 94 94 { 95 #ifdef CONFIG_KCONSOLE 95 96 arch_grab_console(); 96 return 0; 97 return true; 98 #else 99 return false; 100 #endif 97 101 } 98 102 -
uspace/lib/libc/include/ipc/fb.h
r8fe5980 r76fca31 52 52 FB_DRAW_TEXT_DATA, 53 53 FB_FLUSH, 54 FB_VIEWPORT_DB,55 54 FB_DRAW_PPM, 56 55 FB_PREPARE_SHM, … … 60 59 FB_VP2PIXMAP, 61 60 FB_DROP_PIXMAP, 62 FB_TRANS_PUTCHAR,63 61 FB_ANIM_CREATE, 64 62 FB_ANIM_DROP, -
uspace/srv/console/console.c
r8fe5980 r76fca31 87 87 * switching */ 88 88 89 static int kernel_pixmap = -1; /**< Number of fb pixmap, where kernel90 * console is stored */91 92 89 93 90 /** Find unused virtual console. … … 188 185 } 189 186 190 /** Save current screen to pixmap, draw old pixmap191 *192 * @param oldpixmap Old pixmap193 * @return ID of pixmap of current screen194 */195 static int switch_screens(int oldpixmap)196 {197 int newpmap;198 199 /* Save screen */200 newpmap = async_req_0_0(fb_info.phone, FB_VP2PIXMAP);201 if (newpmap < 0)202 return -1;203 204 if (oldpixmap != -1) {205 /* Show old screen */206 async_msg_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap);207 /* Drop old pixmap */208 async_msg_1(fb_info.phone, FB_DROP_PIXMAP, oldpixmap);209 }210 211 return newpmap;212 }213 214 187 /** Switch to new console */ 215 188 static void change_console(int newcons) 216 189 { 217 190 connection_t *conn; 218 static int console_pixmap = -1;219 191 int i, j, rc; 220 192 keyfield_t *field; 221 193 style_t *style; 222 194 223 195 if (newcons == active_console) 224 196 return; 225 197 226 198 if (newcons == KERNEL_CONSOLE) { 199 async_serialize_start(); 200 curs_visibility(0); 201 gcons_in_kernel(); 202 async_serialize_end(); 203 204 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) 205 active_console = KERNEL_CONSOLE; 206 else 207 newcons == active_console; 208 } 209 210 if (newcons != KERNEL_CONSOLE) { 211 async_serialize_start(); 212 227 213 if (active_console == KERNEL_CONSOLE) 228 return; 229 active_console = KERNEL_CONSOLE; 214 gcons_redraw_console(); 215 216 active_console = newcons; 217 gcons_change_console(newcons); 218 conn = &connections[active_console]; 219 220 set_style(&conn->screenbuffer.style); 230 221 curs_visibility(0); 231 232 async_serialize_start(); 233 if (kernel_pixmap == -1) { 234 /* store/restore unsupported */ 235 set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); 222 if (interbuffer) { 223 for (i = 0; i < conn->screenbuffer.size_x; i++) 224 for (j = 0; j < conn->screenbuffer.size_y; j++) { 225 unsigned int size_x; 226 227 size_x = conn->screenbuffer.size_x; 228 interbuffer[i + j * size_x] = 229 *get_field_at(&conn->screenbuffer, i, j); 230 } 231 /* This call can preempt, but we are already at the end */ 232 rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); 233 } 234 235 if ((!interbuffer) || (rc != 0)) { 236 set_style(&conn->screenbuffer.style); 236 237 clrscr(); 237 } else { 238 gcons_in_kernel(); 239 console_pixmap = switch_screens(kernel_pixmap); 240 kernel_pixmap = -1; 238 style = &conn->screenbuffer.style; 239 240 for (j = 0; j < conn->screenbuffer.size_y; j++) 241 for (i = 0; i < conn->screenbuffer.size_x; i++) { 242 field = get_field_at(&conn->screenbuffer, i, j); 243 if (!style_same(*style, field->style)) 244 set_style(&field->style); 245 style = &field->style; 246 if ((field->character == ' ') && 247 (style_same(field->style, 248 conn->screenbuffer.style))) 249 continue; 250 251 prtchr(field->character, j, i); 252 } 241 253 } 254 255 curs_goto(conn->screenbuffer.position_y, 256 conn->screenbuffer.position_x); 257 curs_visibility(conn->screenbuffer.is_cursor_visible); 258 242 259 async_serialize_end(); 243 244 __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); 245 return; 246 } 247 248 async_serialize_start(); 249 250 if (console_pixmap != -1) { 251 kernel_pixmap = switch_screens(console_pixmap); 252 console_pixmap = -1; 253 } 254 active_console = newcons; 255 gcons_change_console(newcons); 256 conn = &connections[active_console]; 257 258 set_style(&conn->screenbuffer.style); 259 curs_visibility(0); 260 if (interbuffer) { 261 for (i = 0; i < conn->screenbuffer.size_x; i++) 262 for (j = 0; j < conn->screenbuffer.size_y; j++) { 263 unsigned int size_x; 264 265 size_x = conn->screenbuffer.size_x; 266 interbuffer[i + j * size_x] = 267 *get_field_at(&conn->screenbuffer, i, j); 268 } 269 /* This call can preempt, but we are already at the end */ 270 rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); 271 } 272 273 if ((!interbuffer) || (rc != 0)) { 274 set_style(&conn->screenbuffer.style); 275 clrscr(); 276 style = &conn->screenbuffer.style; 277 278 for (j = 0; j < conn->screenbuffer.size_y; j++) 279 for (i = 0; i < conn->screenbuffer.size_x; i++) { 280 field = get_field_at(&conn->screenbuffer, i, j); 281 if (!style_same(*style, field->style)) 282 set_style(&field->style); 283 style = &field->style; 284 if ((field->character == ' ') && 285 (style_same(field->style, 286 conn->screenbuffer.style))) 287 continue; 288 289 prtchr(field->character, j, i); 290 } 291 } 292 293 curs_goto(conn->screenbuffer.position_y, 294 conn->screenbuffer.position_x); 295 curs_visibility(conn->screenbuffer.is_cursor_visible); 296 297 async_serialize_end(); 260 } 298 261 } 299 262 … … 498 461 499 462 /* Connect to framebuffer driver */ 500 501 463 fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); 502 464 while (fb_info.phone < 0) { … … 505 467 } 506 468 507 /* Save old kernel screen */508 kernel_pixmap = switch_screens(-1);509 510 469 /* Initialize gcons */ 511 470 gcons_init(fb_info.phone); 512 471 /* Synchronize, the gcons can have something in queue */ 513 472 async_req_0_0(fb_info.phone, FB_FLUSH); 514 /* Enable double buffering */515 async_msg_2(fb_info.phone, FB_VIEWPORT_DB, (sysarg_t) -1, 1);516 473 517 474 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, -
uspace/srv/console/gcons.c
r8fe5980 r76fca31 82 82 static void vp_switch(int vp) 83 83 { 84 async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);84 async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp); 85 85 } 86 86 … … 106 106 static void tran_putch(char c, int row, int col) 107 107 { 108 async_msg_3(fbphone, FB_ TRANS_PUTCHAR, c, row, col);108 async_msg_3(fbphone, FB_PUTCHAR, c, row, col); 109 109 } 110 110 … … 190 190 else 191 191 console_state[consnum] = CONS_DISCONNECTED; 192 192 193 193 if (active_console == KERNEL_CONSOLE) 194 194 return; 195 195 196 196 redraw_state(consnum); 197 197 vp_switch(console_vp); … … 218 218 void gcons_in_kernel(void) 219 219 { 220 if (console_state[active_console] == CONS_DISCONNECTED_SEL)221 console_state[active_console] = CONS_DISCONNECTED;222 else223 console_state[active_console] = CONS_IDLE;224 redraw_state(active_console);225 226 220 if (animation != -1) 227 221 async_msg_1(fbphone, FB_ANIM_STOP, animation); 228 229 active_console = KERNEL_CONSOLE; /* Set to kernel console */222 223 active_console = KERNEL_CONSOLE; 230 224 vp_switch(0); 231 225 } … … 343 337 extern char _binary_nameic_ppm_start[0]; 344 338 extern int _binary_nameic_ppm_size; 345 /** Redraws console graphics */ 346 static void gcons_redraw_console(void) 339 340 /** Redraws console graphics */ 341 void gcons_redraw_console(void) 347 342 { 348 343 int i; 349 344 350 345 if (!use_gcons) 351 346 return; … … 358 353 draw_pixmap(_binary_nameic_ppm_start, 359 354 (size_t) &_binary_nameic_ppm_size, 5, 17); 360 355 361 356 for (i = 0; i < CONSOLE_COUNT; i++) 362 357 redraw_state(i); … … 460 455 int i; 461 456 int status_start = STATUS_START; 462 457 463 458 fbphone = phone; 464 459 465 460 rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres); 466 461 if (rc) 467 462 return; 468 463 469 if ( xres < 800 || yres < 600)470 return; 471 464 if ((xres < 800) || (yres < 600)) 465 return; 466 472 467 /* create console viewport */ 473 468 /* Align width & height to character size */ … … 507 502 508 503 make_anim(); 509 504 510 505 use_gcons = 1; 511 506 console_state[0] = CONS_DISCONNECTED_SEL; … … 513 508 gcons_redraw_console(); 514 509 } 515 510 516 511 /** @} 517 512 */ 518 -
uspace/srv/console/gcons.h
r8fe5980 r76fca31 37 37 38 38 void gcons_init(int phone); 39 void gcons_redraw_console(void); 39 40 void gcons_change_console(int consnum); 40 41 void gcons_notify_char(int consnum); -
uspace/srv/console/screenbuffer.h
r8fe5980 r76fca31 36 36 #define __SCREENBUFFER_H__ 37 37 38 #include <stdint.h> 38 39 39 40 #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ … … 41 42 42 43 typedef struct { 43 u nsigned int bg_color;/**< background color */44 u nsigned int fg_color;/**< foreground color */44 uint32_t bg_color; /**< background color */ 45 uint32_t fg_color; /**< foreground color */ 45 46 } style_t; 46 47 -
uspace/srv/fb/fb.c
r8fe5980 r76fca31 1 1 /* 2 * Copyright (c) 2008 Martin Decky 2 3 * Copyright (c) 2006 Jakub Vana 3 4 * Copyright (c) 2006 Ondrej Palkovsky … … 33 34 * @ingroup fbs 34 35 * @{ 35 */ 36 */ 36 37 37 38 /** @file … … 63 64 #include "pointer_mask.xbm" 64 65 65 #define DEFAULT_BGCOLOR 0xf0f0f0 66 #define DEFAULT_FGCOLOR 0x0 67 68 /***************************************************************/ 69 /* Pixel specific fuctions */ 70 71 typedef void (*conv2scr_fn_t)(void *, int); 72 typedef int (*conv2rgb_fn_t)(void *); 66 #define DEFAULT_BGCOLOR 0xf0f0f0 67 #define DEFAULT_FGCOLOR 0x000000 68 69 #define MAX_ANIM_LEN 8 70 #define MAX_ANIMATIONS 4 71 #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ 72 #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ 73 74 typedef void (*rgb_conv_t)(void *, uint32_t); 73 75 74 76 struct { 75 uint8_t *fb address;76 77 uint8_t *fb_addr; 78 77 79 unsigned int xres; 78 80 unsigned int yres; 81 79 82 unsigned int scanline; 83 unsigned int glyphscanline; 84 80 85 unsigned int pixelbytes; 81 unsigned int invert_colors; 82 83 conv2scr_fn_t rgb2scr; 84 conv2rgb_fn_t scr2rgb; 86 unsigned int glyphbytes; 87 88 rgb_conv_t rgb_conv; 85 89 } screen; 86 90 87 91 typedef struct { 88 int initialized; 89 unsigned int x, y; 90 unsigned int width, height; 91 92 bool initialized; 93 unsigned int x; 94 unsigned int y; 95 unsigned int width; 96 unsigned int height; 97 92 98 /* Text support in window */ 93 unsigned int rows, cols; 94 /* Style for text printing */ 99 unsigned int cols; 100 unsigned int rows; 101 102 /* Style and glyphs for text printing */ 95 103 style_t style; 104 uint8_t *glyphs; 105 uint8_t *bgpixel; 106 96 107 /* Auto-cursor position */ 97 int cursor_active, cur_col, cur_row; 98 int cursor_shown; 99 /* Double buffering */ 100 uint8_t *dbdata; 101 unsigned int dboffset; 102 unsigned int paused; 108 bool cursor_active; 109 unsigned int cur_col; 110 unsigned int cur_row; 111 bool cursor_shown; 112 113 /* Back buffer */ 114 unsigned int bbsize; 115 uint8_t *backbuf; 103 116 } viewport_t; 104 117 105 #define MAX_ANIM_LEN 8106 #define MAX_ANIMATIONS 4107 118 typedef struct { 108 intinitialized;109 intenabled;119 bool initialized; 120 bool enabled; 110 121 unsigned int vp; 111 122 112 123 unsigned int pos; 113 124 unsigned int animlen; 114 125 unsigned int pixmaps[MAX_ANIM_LEN]; 115 126 } animation_t; 127 116 128 static animation_t animations[MAX_ANIMATIONS]; 117 static int anims_enabled; 118 119 /** Maximum number of saved pixmaps 120 * Pixmap is a saved rectangle 121 */ 122 #define MAX_PIXMAPS 256 129 static bool anims_enabled; 130 123 131 typedef struct { 124 132 unsigned int width; … … 126 134 uint8_t *data; 127 135 } pixmap_t; 136 128 137 static pixmap_t pixmaps[MAX_PIXMAPS]; 129 130 /* Viewport is a rectangular area on the screen */131 #define MAX_VIEWPORTS 128132 138 static viewport_t viewports[128]; 133 139 134 /* Allow only 1 connection */ 135 static int client_connected = 0; 136 137 #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) 138 #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) 139 #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) 140 141 #define COL_WIDTH 8 142 #define ROW_BYTES (screen.scanline * FONT_SCANLINES) 143 144 #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) 145 146 static inline int COLOR(int color) 147 { 148 return screen.invert_colors ? ~color : color; 149 } 150 151 /* Conversion routines between different color representations */ 152 static void 153 rgb_byte0888(void *dst, int rgb) 154 { 155 *(int *)dst = rgb; 156 } 157 158 static int 159 byte0888_rgb(void *src) 160 { 161 return (*(int *)src) & 0xffffff; 162 } 163 164 static void 165 bgr_byte0888(void *dst, int rgb) 166 { 167 *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | 168 RED(rgb, 8); 169 } 170 171 static int 172 byte0888_bgr(void *src) 173 { 174 int color = *(uint32_t *)(src); 175 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | 176 ((color >> 16) & 0xff); 177 } 178 179 static void 180 rgb_byte888(void *dst, int rgb) 181 { 182 uint8_t *scr = dst; 140 static bool client_connected = false; /**< Allow only 1 connection */ 141 142 #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) 143 #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) 144 #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) 145 146 #define COL2X(col) ((col) * FONT_WIDTH) 147 #define ROW2Y(row) ((row) * FONT_SCANLINES) 148 149 #define X2COL(x) ((x) / FONT_WIDTH) 150 #define Y2ROW(y) ((y) / FONT_SCANLINES) 151 152 #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) 153 #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) 154 #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) 155 156 157 /** ARGB 8:8:8:8 conversion 158 * 159 */ 160 static void rgb_0888(void *dst, uint32_t rgb) 161 { 162 *((uint32_t *) dst) = rgb & 0xffffff; 163 } 164 165 166 /** ABGR 8:8:8:8 conversion 167 * 168 */ 169 static void bgr_0888(void *dst, uint32_t rgb) 170 { 171 *((uint32_t *) dst) 172 = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); 173 } 174 175 176 /** BGR 8:8:8 conversion 177 * 178 */ 179 static void rgb_888(void *dst, uint32_t rgb) 180 { 183 181 #if defined(FB_INVERT_ENDIAN) 184 scr[0] = RED(rgb, 8);185 scr[1] = GREEN(rgb, 8);186 scr[2] = BLUE(rgb, 8);182 *((uint32_t *) dst) 183 = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8) 184 | (*((uint32_t *) dst) & 0xff0000); 187 185 #else 188 scr[2] = RED(rgb, 8); 189 scr[1] = GREEN(rgb, 8); 190 scr[0] = BLUE(rgb, 8); 186 *((uint32_t *) dst) 187 = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000); 191 188 #endif 192 189 } 193 190 194 static int 195 byte888_rgb(void *src) 196 { 197 uint8_t *scr = src; 198 #if defined(FB_INVERT_ENDIAN) 199 return scr[0] << 16 | scr[1] << 8 | scr[2]; 200 #else 201 return scr[2] << 16 | scr[1] << 8 | scr[0]; 202 #endif 203 } 204 205 /** 16-bit depth (5:5:5) */ 206 static void 207 rgb_byte555(void *dst, int rgb) 208 { 209 /* 5-bit, 5-bits, 5-bits */ 210 *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | 211 BLUE(rgb, 5); 212 } 213 214 /** 16-bit depth (5:5:5) */ 215 static int 216 byte555_rgb(void *src) 217 { 218 int color = *(uint16_t *)(src); 219 return (((color >> 10) & 0x1f) << (16 + 3)) | 220 (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); 221 } 222 223 /** 16-bit depth (5:6:5) */ 224 static void 225 rgb_byte565(void *dst, int rgb) 226 { 227 /* 5-bit, 6-bits, 5-bits */ 228 *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | 229 BLUE(rgb, 5); 230 } 231 232 /** 16-bit depth (5:6:5) */ 233 static int 234 byte565_rgb(void *src) 235 { 236 int color = *(uint16_t *)(src); 237 return (((color >> 11) & 0x1f) << (16 + 3)) | 238 (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); 239 } 240 241 /** Put pixel - 8-bit depth (3:2:3) */ 242 static void 243 rgb_byte8(void *dst, int rgb) 244 { 245 *(uint8_t *)dst = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | 246 BLUE(rgb, 3)); 247 } 248 249 /** Return pixel color - 8-bit depth (3:2:3) */ 250 static int 251 byte8_rgb(void *src) 252 { 253 int color = 255 - (*(uint8_t *)src); 254 return (((color >> 5) & 0x7) << (16 + 5)) | 255 (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); 256 } 257 258 /** Put pixel into viewport 259 * 260 * @param vport Viewport identification 261 * @param x X coord relative to viewport 262 * @param y Y coord relative to viewport 263 * @param color RGB color 264 */ 265 static void 266 putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color) 267 { 268 int dx = vport->x + x; 269 int dy = vport->y + y; 270 271 if (! (vport->paused && vport->dbdata)) 272 (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)], 273 COLOR(color)); 274 275 if (vport->dbdata) { 276 int dline = (y + vport->dboffset) % vport->height; 277 int doffset = screen.pixelbytes * (dline * vport->width + x); 278 (*screen.rgb2scr)(&vport->dbdata[doffset], COLOR(color)); 279 } 280 } 281 282 /** Get pixel from viewport */ 283 static int 284 getpixel(viewport_t *vport, unsigned int x, unsigned int y) 285 { 286 int dx = vport->x + x; 287 int dy = vport->y + y; 288 289 return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)])); 290 } 291 292 static inline void 293 putpixel_mem(char *mem, unsigned int x, unsigned int y, int color) 294 { 295 (*screen.rgb2scr)(&mem[POINTPOS(x, y)], COLOR(color)); 296 } 297 298 static void 299 draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, 300 unsigned int width, unsigned int height, int color) 301 { 302 unsigned int x, y; 303 static void *tmpline; 304 305 if (!tmpline) 306 tmpline = malloc(screen.scanline * screen.pixelbytes); 307 308 /* Clear first line */ 309 for (x = 0; x < width; x++) 310 putpixel_mem(tmpline, x, 0, color); 311 312 if (!vport->paused) { 313 /* Recompute to screen coords */ 314 sx += vport->x; 315 sy += vport->y; 316 /* Copy the rest */ 317 for (y = sy;y < sy+height; y++) 318 memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline, 319 screen.pixelbytes * width); 320 } 321 if (vport->dbdata) { 322 for (y = sy; y < sy + height; y++) { 323 int rline = (y + vport->dboffset) % vport->height; 324 int rpos = (rline * vport->width + sx) * 325 screen.pixelbytes; 326 memcpy(&vport->dbdata[rpos], tmpline, 327 screen.pixelbytes * width); 328 } 329 } 330 331 } 332 333 /** Fill viewport with background color */ 334 static void 335 clear_port(viewport_t *vport) 336 { 337 draw_rectangle(vport, 0, 0, vport->width, vport->height, 338 vport->style.bg_color); 339 } 340 341 /** Scroll unbuffered viewport up/down 191 192 /** RGB 5:5:5 conversion 193 * 194 */ 195 static void rgb_555(void *dst, uint32_t rgb) 196 { 197 *((uint16_t *) dst) 198 = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); 199 } 200 201 202 /** RGB 5:6:5 conversion 203 * 204 */ 205 static void rgb_565(void *dst, uint32_t rgb) 206 { 207 *((uint16_t *) dst) 208 = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); 209 } 210 211 212 /** RGB 3:2:3 213 * 214 */ 215 static void rgb_323(void *dst, uint32_t rgb) 216 { 217 *((uint8_t *) dst) 218 = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); 219 } 220 221 222 /** Redraw viewport 223 * 224 * @param vport Viewport to redraw 225 * 226 */ 227 static void vport_redraw(viewport_t *vport) 228 { 229 unsigned int row; 230 231 for (row = 0; row < vport->rows; row++) { 232 unsigned int y = vport->y + ROW2Y(row); 233 unsigned int yd; 234 235 for (yd = 0; yd < FONT_SCANLINES; yd++) { 236 unsigned int x; 237 unsigned int col; 238 239 for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) 240 memcpy(&screen.fb_addr[FB_POS(x, y + yd)], 241 &vport->glyphs[GLYPH_POS(vport->backbuf[BB_POS(vport, col, row)], yd, false)], 242 screen.glyphscanline); 243 } 244 } 245 246 if (COL2X(vport->cols) < vport->width) { 247 unsigned int y; 248 249 for (y = 0; y < vport->height; y++) { 250 unsigned int x; 251 252 for (x = COL2X(vport->cols); x < vport->width; x++) 253 memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes); 254 } 255 } 256 257 if (ROW2Y(vport->rows) < vport->height) { 258 unsigned int y; 259 260 for (y = ROW2Y(vport->rows); y < vport->height; y++) { 261 unsigned int x; 262 263 for (x = 0; x < vport->width; x++) 264 memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes); 265 } 266 } 267 } 268 269 270 /** Clear viewport 271 * 272 * @param vport Viewport to clear 273 * 274 */ 275 static void vport_clear(viewport_t *vport) 276 { 277 memset(vport->backbuf, 0, vport->bbsize); 278 vport_redraw(vport); 279 } 280 281 282 /** Scroll viewport by given number of lines 342 283 * 343 284 * @param vport Viewport to scroll 344 * @param lines Positive number - scroll up, negative - scroll down 345 */ 346 static void 347 scroll_port_nodb(viewport_t *vport, int lines) 348 { 349 int y; 350 285 * @param lines Number of lines to scroll 286 * 287 */ 288 static void vport_scroll(viewport_t *vport, int lines) 289 { 290 unsigned int row; 291 292 for (row = 0; row < vport->rows; row++) { 293 unsigned int y = vport->y + ROW2Y(row); 294 unsigned int yd; 295 296 for (yd = 0; yd < FONT_SCANLINES; yd++) { 297 unsigned int x; 298 unsigned int col; 299 300 for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) { 301 uint8_t glyph; 302 303 if ((row + lines >= 0) && (row + lines < vport->rows)) { 304 if (vport->backbuf[BB_POS(vport, col, row)] == vport->backbuf[BB_POS(vport, col, row + lines)]) 305 continue; 306 307 glyph = vport->backbuf[BB_POS(vport, col, row + lines)]; 308 } else 309 glyph = 0; 310 311 memcpy(&screen.fb_addr[FB_POS(x, y + yd)], 312 &vport->glyphs[GLYPH_POS(glyph, yd, false)], screen.glyphscanline); 313 } 314 } 315 } 316 351 317 if (lines > 0) { 352 for (y = vport->y; y < vport->y+vport->height - lines; y++) 353 memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], 354 &screen.fbaddress[POINTPOS(vport->x,y + lines)], 355 screen.pixelbytes * vport->width); 356 draw_rectangle(vport, 0, vport->height - lines, vport->width, 357 lines, vport->style.bg_color); 358 } else if (lines < 0) { 359 lines = -lines; 360 for (y = vport->y + vport->height-1; y >= vport->y + lines; y--) 361 memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], 362 &screen.fbaddress[POINTPOS(vport->x,y - lines)], 363 screen.pixelbytes * vport->width); 364 draw_rectangle(vport, 0, 0, vport->width, lines, 365 vport->style.bg_color); 366 } 367 } 368 369 /** Refresh given viewport from double buffer */ 370 static void 371 refresh_viewport_db(viewport_t *vport) 372 { 373 unsigned int y, srcy, srcoff, dsty, dstx; 374 375 for (y = 0; y < vport->height; y++) { 376 srcy = (y + vport->dboffset) % vport->height; 377 srcoff = (vport->width * srcy) * screen.pixelbytes; 378 379 dstx = vport->x; 380 dsty = vport->y + y; 381 382 memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)], 383 &vport->dbdata[srcoff], vport->width * screen.pixelbytes); 384 } 385 } 386 387 /** Scroll viewport that has double buffering enabled */ 388 static void 389 scroll_port_db(viewport_t *vport, int lines) 390 { 391 ++vport->paused; 392 if (lines > 0) { 393 draw_rectangle(vport, 0, 0, vport->width, lines, 394 vport->style.bg_color); 395 vport->dboffset += lines; 396 vport->dboffset %= vport->height; 397 } else if (lines < 0) { 398 lines = -lines; 399 draw_rectangle(vport, 0, vport->height-lines, vport->width, 400 lines, vport->style.bg_color); 401 402 if (vport->dboffset < lines) 403 vport->dboffset += vport->height; 404 vport->dboffset -= lines; 405 } 406 407 --vport->paused; 408 409 refresh_viewport_db(vport); 410 } 411 412 /** Scrolls viewport given number of lines */ 413 static void 414 scroll_port(viewport_t *vport, int lines) 415 { 416 if (vport->dbdata) 417 scroll_port_db(vport, lines); 418 else 419 scroll_port_nodb(vport, lines); 420 421 } 422 423 static void 424 invert_pixel(viewport_t *vport, unsigned int x, unsigned int y) 425 { 426 putpixel(vport, x, y, ~getpixel(vport, x, y)); 427 } 428 429 430 /***************************************************************/ 431 /* Character-console functions */ 432 433 /** Draw character at given position 434 * 435 * @param vport Viewport where the character is printed 436 * @param sx Coordinates of top-left of the character 437 * @param sy Coordinates of top-left of the character 438 * @param style Color of the character 439 * @param transparent If false, print background color 440 */ 441 static void 442 draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, unsigned int sy, 443 style_t style, int transparent) 444 { 445 int i; 446 unsigned int y; 447 unsigned int glline; 448 449 for (y = 0; y < FONT_SCANLINES; y++) { 450 glline = fb_font[glyph * FONT_SCANLINES + y]; 451 for (i = 0; i < 8; i++) { 452 if (glline & (1 << (7 - i))) 453 putpixel(vport, sx + i, sy + y, style.fg_color); 454 else if (!transparent) 455 putpixel(vport, sx + i, sy + y, style.bg_color); 456 } 457 } 458 } 459 460 /** Invert character at given position */ 461 static void 462 invert_char(viewport_t *vport,unsigned int row, unsigned int col) 463 { 464 unsigned int x; 465 unsigned int y; 466 467 for (x = 0; x < COL_WIDTH; x++) 468 for (y = 0; y < FONT_SCANLINES; y++) 469 invert_pixel(vport, col * COL_WIDTH + x, row * 470 FONT_SCANLINES + y); 471 } 472 473 /***************************************************************/ 474 /* Stdout specific functions */ 318 memcpy(vport->backbuf, vport->backbuf + vport->cols * lines, vport->cols * (vport->rows - lines)); 319 memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 0, vport->cols * lines); 320 } else { 321 memcpy(vport->backbuf - vport->cols * lines, vport->backbuf, vport->cols * (vport->rows + lines)); 322 memset(vport->backbuf, 0, - vport->cols * lines); 323 } 324 } 325 326 327 /** Render glyphs 328 * 329 * Convert glyphs from device independent font 330 * description to current visual representation. 331 * 332 * @param vport Viewport 333 * 334 */ 335 static void render_glyphs(viewport_t* vport) 336 { 337 unsigned int glyph; 338 339 for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { 340 unsigned int y; 341 342 for (y = 0; y < FONT_SCANLINES; y++) { 343 unsigned int x; 344 345 for (x = 0; x < FONT_WIDTH; x++) { 346 screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], 347 (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) 348 ? vport->style.fg_color : vport->style.bg_color); 349 350 uint32_t curcolor; 351 352 if (y < FONT_SCANLINES - 2) 353 curcolor = 354 (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) 355 ? vport->style.fg_color : vport->style.bg_color; 356 else 357 curcolor = vport->style.fg_color; 358 359 screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], curcolor); 360 } 361 } 362 } 363 364 screen.rgb_conv(vport->bgpixel, vport->style.bg_color); 365 } 475 366 476 367 477 368 /** Create new viewport 478 369 * 479 * @return New viewport number 480 */ 481 static int 482 viewport_create(unsigned int x, unsigned int y,unsigned int width, 483 unsigned int height) 484 { 485 int i; 486 370 * @param x Origin of the viewport (x). 371 * @param y Origin of the viewport (y). 372 * @param width Width of the viewport. 373 * @param height Height of the viewport. 374 * 375 * @return New viewport number. 376 * 377 */ 378 static int vport_create(unsigned int x, unsigned int y, 379 unsigned int width, unsigned int height) 380 { 381 unsigned int i; 382 487 383 for (i = 0; i < MAX_VIEWPORTS; i++) { 488 384 if (!viewports[i].initialized) … … 491 387 if (i == MAX_VIEWPORTS) 492 388 return ELIMIT; 493 389 390 unsigned int cols = width / FONT_WIDTH; 391 unsigned int rows = height / FONT_SCANLINES; 392 unsigned int bbsize = cols * rows; 393 unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; 394 395 uint8_t *backbuf = (uint8_t *) malloc(bbsize); 396 if (!backbuf) 397 return ENOMEM; 398 399 uint8_t *glyphs = (uint8_t *) malloc(glyphsize); 400 if (!glyphs) { 401 free(backbuf); 402 return ENOMEM; 403 } 404 405 uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); 406 if (!bgpixel) { 407 free(glyphs); 408 free(backbuf); 409 return ENOMEM; 410 } 411 412 memset(backbuf, 0, bbsize); 413 memset(glyphs, 0, glyphsize); 414 memset(bgpixel, 0, screen.pixelbytes); 415 494 416 viewports[i].x = x; 495 417 viewports[i].y = y; … … 497 419 viewports[i].height = height; 498 420 499 viewports[i]. rows = height / FONT_SCANLINES;500 viewports[i]. cols = width / COL_WIDTH;501 421 viewports[i].cols = cols; 422 viewports[i].rows = rows; 423 502 424 viewports[i].style.bg_color = DEFAULT_BGCOLOR; 503 425 viewports[i].style.fg_color = DEFAULT_FGCOLOR; 504 426 427 viewports[i].glyphs = glyphs; 428 viewports[i].bgpixel = bgpixel; 429 505 430 viewports[i].cur_col = 0; 506 431 viewports[i].cur_row = 0; 507 viewports[i].cursor_active = 0; 508 509 viewports[i].initialized = 1; 510 432 viewports[i].cursor_active = false; 433 viewports[i].cursor_shown = false; 434 435 viewports[i].bbsize = bbsize; 436 viewports[i].backbuf = backbuf; 437 438 viewports[i].initialized = true; 439 440 render_glyphs(&viewports[i]); 441 511 442 return i; 512 443 } 513 444 445 514 446 /** Initialize framebuffer as a chardev output device 515 447 * 516 * @param addr Address of theframebuffer 517 * @param xres Screen width in pixels 518 * @param yres Screen height in pixels 519 * @param visual Bits per pixel (8, 16, 24, 32) 520 * @param scan Bytes per one scanline 521 * @param invert_colors Inverted colors. 522 * 523 */ 524 static bool 525 screen_init(void *addr, unsigned int offset, unsigned int xres, 526 unsigned int yres, unsigned int scan, unsigned int visual, 527 bool invert_colors) 448 * @param addr Address of the framebuffer 449 * @param xres Screen width in pixels 450 * @param yres Screen height in pixels 451 * @param visual Bits per pixel (8, 16, 24, 32) 452 * @param scan Bytes per one scanline 453 * 454 */ 455 static bool screen_init(void *addr, unsigned int xres, unsigned int yres, 456 unsigned int scan, unsigned int visual) 528 457 { 529 458 switch (visual) { 530 459 case VISUAL_INDIRECT_8: 531 screen.rgb2scr = rgb_byte8; 532 screen.scr2rgb = byte8_rgb; 460 screen.rgb_conv = rgb_323; 533 461 screen.pixelbytes = 1; 534 462 break; 535 463 case VISUAL_RGB_5_5_5: 536 screen.rgb2scr = rgb_byte555; 537 screen.scr2rgb = byte555_rgb; 464 screen.rgb_conv = rgb_555; 538 465 screen.pixelbytes = 2; 539 466 break; 540 467 case VISUAL_RGB_5_6_5: 541 screen.rgb2scr = rgb_byte565; 542 screen.scr2rgb = byte565_rgb; 468 screen.rgb_conv = rgb_565; 543 469 screen.pixelbytes = 2; 544 470 break; 545 471 case VISUAL_RGB_8_8_8: 546 screen.rgb2scr = rgb_byte888; 547 screen.scr2rgb = byte888_rgb; 472 screen.rgb_conv = rgb_888; 548 473 screen.pixelbytes = 3; 549 474 break; 550 475 case VISUAL_RGB_8_8_8_0: 551 screen.rgb2scr = rgb_byte888; 552 screen.scr2rgb = byte888_rgb; 476 screen.rgb_conv = rgb_888; 553 477 screen.pixelbytes = 4; 554 478 break; 555 479 case VISUAL_RGB_0_8_8_8: 556 screen.rgb2scr = rgb_byte0888; 557 screen.scr2rgb = byte0888_rgb; 480 screen.rgb_conv = rgb_0888; 558 481 screen.pixelbytes = 4; 559 482 break; 560 483 case VISUAL_BGR_0_8_8_8: 561 screen.rgb2scr = bgr_byte0888; 562 screen.scr2rgb = byte0888_bgr; 484 screen.rgb_conv = bgr_0888; 563 485 screen.pixelbytes = 4; 564 486 break; … … 567 489 } 568 490 569 screen.fb address = (unsigned char *) (((uintptr_t) addr));491 screen.fb_addr = (unsigned char *) addr; 570 492 screen.xres = xres; 571 493 screen.yres = yres; 572 494 screen.scanline = scan; 573 screen.invert_colors = invert_colors; 495 496 screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; 497 screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; 574 498 575 499 /* Create first viewport */ 576 v iewport_create(0, 0, xres, yres);500 vport_create(0, 0, xres, yres); 577 501 578 502 return true; 579 503 } 580 504 581 /** Hide cursor if it is shown */ 582 static void 583 cursor_hide(viewport_t *vport) 584 { 585 if (vport->cursor_active && vport->cursor_shown) { 586 invert_char(vport, vport->cur_row, vport->cur_col); 587 vport->cursor_shown = 0; 588 } 589 } 590 591 /** Show cursor if cursor showing is enabled */ 592 static void 593 cursor_print(viewport_t *vport) 505 506 /** Draw glyph at given position relative to viewport 507 * 508 * @param vport Viewport identification 509 * @param cursor Draw glyph with cursor 510 * @param col Screen position relative to viewport 511 * @param row Screen position relative to viewport 512 * 513 */ 514 static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col, unsigned int row) 515 { 516 unsigned int x = vport->x + COL2X(col); 517 unsigned int y = vport->y + ROW2Y(row); 518 unsigned int yd; 519 520 uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; 521 522 for (yd = 0; yd < FONT_SCANLINES; yd++) 523 memcpy(&screen.fb_addr[FB_POS(x, y + yd)], 524 &vport->glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline); 525 } 526 527 528 /** Hide cursor if it is shown 529 * 530 */ 531 static void cursor_hide(viewport_t *vport) 532 { 533 if ((vport->cursor_active) && (vport->cursor_shown)) { 534 draw_glyph(vport, false, vport->cur_col, vport->cur_row); 535 vport->cursor_shown = false; 536 } 537 } 538 539 540 /** Show cursor if cursor showing is enabled 541 * 542 */ 543 static void cursor_show(viewport_t *vport) 594 544 { 595 545 /* Do not check for cursor_shown */ 596 546 if (vport->cursor_active) { 597 invert_char(vport, vport->cur_row, vport->cur_col); 598 vport->cursor_shown = 1; 599 } 600 } 601 602 /** Invert cursor, if it is enabled */ 603 static void 604 cursor_blink(viewport_t *vport) 547 draw_glyph(vport, true, vport->cur_col, vport->cur_row); 548 vport->cursor_shown = true; 549 } 550 } 551 552 553 /** Invert cursor, if it is enabled 554 * 555 */ 556 static void cursor_blink(viewport_t *vport) 605 557 { 606 558 if (vport->cursor_shown) 607 559 cursor_hide(vport); 608 560 else 609 cursor_print(vport); 610 } 611 612 /** Draw character at given position relative to viewport 613 * 614 * @param vport Viewport identification 615 * @param c Character to print 616 * @param row Screen position relative to viewport 617 * @param col Screen position relative to viewport 618 * @param transparent If false, print background color with character 619 */ 620 static void 621 draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col, 622 style_t style, int transparent) 623 { 624 /* Optimize - do not hide cursor if we are going to overwrite it */ 625 if (vport->cursor_active && vport->cursor_shown && 626 (vport->cur_col != col || vport->cur_row != row)) 627 invert_char(vport, vport->cur_row, vport->cur_col); 628 629 draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style, 630 transparent); 631 561 cursor_show(vport); 562 } 563 564 565 /** Draw character at given position relative to viewport 566 * 567 * @param vport Viewport identification 568 * @param c Character to draw 569 * @param col Screen position relative to viewport 570 * @param row Screen position relative to viewport 571 * 572 */ 573 static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row) 574 { 575 /* Do not hide cursor if we are going to overwrite it */ 576 if ((vport->cursor_active) && (vport->cursor_shown) && 577 ((vport->cur_col != col) || (vport->cur_row != row))) 578 cursor_hide(vport); 579 580 uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; 581 582 if (glyph != c) { 583 vport->backbuf[BB_POS(vport, col, row)] = c; 584 draw_glyph(vport, false, col, row); 585 } 586 632 587 vport->cur_col = col; 633 588 vport->cur_row = row; 634 589 635 590 vport->cur_col++; 636 591 if (vport->cur_col >= vport->cols) { … … 640 595 vport->cur_row--; 641 596 } 642 cursor_print(vport); 643 } 597 598 cursor_show(vport); 599 } 600 644 601 645 602 /** Draw text data to viewport 646 603 * 647 604 * @param vport Viewport id 648 * @param data Text data fitting exactly into viewport 649 */ 650 static void 651 draw_text_data(viewport_t *vport, keyfield_t *data) 652 { 653 int i; 654 int col,row; 655 656 clear_port(vport); 605 * @param data Text data fitting exactly into viewport 606 * 607 */ 608 static void draw_text_data(viewport_t *vport, keyfield_t *data) 609 { 610 unsigned int i; 611 657 612 for (i = 0; i < vport->cols * vport->rows; i++) { 658 if (data[i].character == ' ' && style_same(data[i].style, 659 vport->style)) 660 continue; 661 col = i % vport->cols; 662 row = i / vport->cols; 663 draw_glyph(vport, data[i].character, col * COL_WIDTH, row * 664 FONT_SCANLINES, data[i].style, style_same(data[i].style, 665 vport->style)); 666 } 667 cursor_print(vport); 668 } 669 670 /** Return first free pixmap */ 671 static int 672 find_free_pixmap(void) 673 { 674 int i; 675 676 for (i = 0;i < MAX_PIXMAPS;i++) 613 unsigned int col = i % vport->cols; 614 unsigned int row = i / vport->cols; 615 616 uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; 617 618 // TODO: use data[i].style 619 620 if (glyph != data[i].character) { 621 vport->backbuf[BB_POS(vport, col, row)] = data[i].character; 622 draw_glyph(vport, false, col, row); 623 } 624 } 625 cursor_show(vport); 626 } 627 628 629 static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) 630 { 631 int pm = *((int *) data); 632 pixmap_t *pmap = &pixmaps[pm]; 633 unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; 634 635 screen.rgb_conv(&pmap->data[pos], color); 636 } 637 638 639 static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) 640 { 641 viewport_t *vport = (viewport_t *) data; 642 unsigned int dx = vport->x + x; 643 unsigned int dy = vport->y + y; 644 645 screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); 646 } 647 648 649 /** Return first free pixmap 650 * 651 */ 652 static int find_free_pixmap(void) 653 { 654 unsigned int i; 655 656 for (i = 0; i < MAX_PIXMAPS; i++) 677 657 if (!pixmaps[i].data) 678 658 return i; 659 679 660 return -1; 680 661 } 681 662 682 static void 683 putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color) 684 { 685 pixmap_t *pmap = &pixmaps[pm]; 686 int pos = (y * pmap->width + x) * screen.pixelbytes; 687 688 (*screen.rgb2scr)(&pmap->data[pos],COLOR(color)); 689 } 690 691 /** Create a new pixmap and return appropriate ID */ 692 static int 693 shm2pixmap(unsigned char *shm, size_t size) 663 664 /** Create a new pixmap and return appropriate ID 665 * 666 */ 667 static int shm2pixmap(unsigned char *shm, size_t size) 694 668 { 695 669 int pm; 696 670 pixmap_t *pmap; 697 671 698 672 pm = find_free_pixmap(); 699 673 if (pm == -1) 700 674 return ELIMIT; 675 701 676 pmap = &pixmaps[pm]; 702 677 … … 707 682 if (!pmap->data) 708 683 return ENOMEM; 709 710 ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, 711 (putpixel_cb_t)putpixel_pixmap, (void *)pm); 712 684 685 ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); 686 713 687 return pm; 714 688 } 689 715 690 716 691 /** Handle shared memory communication calls … … 719 694 * - FB_PREPARE_SHM(client shm identification) 720 695 * - IPC_M_AS_AREA_SEND 721 * - FB_DRAW_PPM(startx, starty)696 * - FB_DRAW_PPM(startx, starty) 722 697 * - FB_DROP_SHM 723 698 * … … 727 702 * 728 703 * @param callid Callid of the current call 729 * @param call Current call data 730 * @param vp Active viewport 731 * @return 0 if the call was not handled byt this function, 1 otherwise 732 * 733 * note: this function is not threads safe, you would have 704 * @param call Current call data 705 * @param vp Active viewport 706 * 707 * @return false if the call was not handled byt this function, true otherwise 708 * 709 * Note: this function is not threads safe, you would have 734 710 * to redefine static variables with __thread 735 * /736 static int 737 s hm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)711 * 712 */ 713 static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 738 714 { 739 715 static keyfield_t *interbuffer = NULL; 740 716 static size_t intersize = 0; 741 717 742 718 static unsigned char *shm = NULL; 743 719 static ipcarg_t shm_id = 0; 744 720 static size_t shm_size; 745 746 int handled = 1;747 int retval = 0;721 722 bool handled = true; 723 int retval = EOK; 748 724 viewport_t *vport = &viewports[vp]; 749 unsigned int x, y; 750 725 unsigned int x; 726 unsigned int y; 727 751 728 switch (IPC_GET_METHOD(*call)) { 752 729 case IPC_M_SHARE_OUT: … … 755 732 void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); 756 733 shm_size = IPC_GET_ARG2(*call); 757 if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) 734 if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) 758 735 shm = dest; 759 736 else 760 737 shm_id = 0; 738 761 739 if (shm[0] != 'P') 762 while (1)763 ;764 return 1;740 return false; 741 742 return true; 765 743 } else { 766 744 intersize = IPC_GET_ARG2(*call); 767 745 receive_comm_area(callid, call, (void *) &interbuffer); 768 746 } 769 return 1;747 return true; 770 748 case FB_PREPARE_SHM: 771 749 if (shm_id) … … 782 760 shm_id = 0; 783 761 break; 784 762 785 763 case FB_SHM2PIXMAP: 786 764 if (!shm) { … … 797 775 x = IPC_GET_ARG1(*call); 798 776 y = IPC_GET_ARG2(*call); 799 if (x > vport->width || y > vport->height) { 777 778 if ((x > vport->width) || (y > vport->height)) { 800 779 retval = EINVAL; 801 780 break; … … 803 782 804 783 ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), 805 IPC_GET_ARG2(*call), vport->width - x, vport->height - y, 806 (putpixel_cb_t)putpixel, vport); 784 IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); 807 785 break; 808 786 case FB_DRAW_TEXT_DATA: … … 811 789 break; 812 790 } 813 if (intersize < vport->cols * vport->rows * 814 sizeof(*interbuffer)) { 791 if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) { 815 792 retval = EINVAL; 816 793 break; … … 819 796 break; 820 797 default: 821 handled = 0;798 handled = false; 822 799 } 823 800 … … 827 804 } 828 805 829 static void 830 copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) 831 { 832 int y; 833 int tmp, srcrowsize; 834 int realwidth, realheight, realrowsize; 835 int width = vport->width; 836 int height = vport->height; 837 806 807 static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) 808 { 809 unsigned int width = vport->width; 810 unsigned int height = vport->height; 811 838 812 if (width + vport->x > screen.xres) 839 813 width = screen.xres - vport->x; … … 841 815 height = screen.yres - vport->y; 842 816 843 realwidth = pmap->width <= width ? pmap->width : width; 844 realheight = pmap->height <= height ? pmap->height : height; 845 846 srcrowsize = vport->width * screen.pixelbytes; 847 realrowsize = realwidth * screen.pixelbytes; 848 817 unsigned int realwidth = pmap->width <= width ? pmap->width : width; 818 unsigned int realheight = pmap->height <= height ? pmap->height : height; 819 820 unsigned int srcrowsize = vport->width * screen.pixelbytes; 821 unsigned int realrowsize = realwidth * screen.pixelbytes; 822 823 unsigned int y; 849 824 for (y = 0; y < realheight; y++) { 850 tmp = (vport->y + y) * screen.scanline +851 vport->x * screen.pixelbytes;852 memcpy(pmap->data + srcrowsize * y, screen.fbaddress + tmp,853 realrowsize); 854 } 855 } 856 857 /** Save viewport to pixmap */ 858 static int 859 s ave_vp_to_pixmap(viewport_t *vport)825 unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; 826 memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); 827 } 828 } 829 830 831 /** Save viewport to pixmap 832 * 833 */ 834 static int save_vp_to_pixmap(viewport_t *vport) 860 835 { 861 836 int pm; 862 837 pixmap_t *pmap; 863 838 864 839 pm = find_free_pixmap(); 865 840 if (pm == -1) … … 870 845 if (!pmap->data) 871 846 return ENOMEM; 872 847 873 848 pmap->width = vport->width; 874 849 pmap->height = vport->height; 875 850 876 851 copy_vp_to_pixmap(vport, pmap); 877 852 878 853 return pm; 879 854 } 855 880 856 881 857 /** Draw pixmap on screen … … 883 859 * @param vp Viewport to draw on 884 860 * @param pm Pixmap identifier 861 * 885 862 */ 886 863 static int draw_pixmap(int vp, int pm) … … 888 865 pixmap_t *pmap = &pixmaps[pm]; 889 866 viewport_t *vport = &viewports[vp]; 890 int y; 891 int tmp, srcrowsize; 892 int realwidth, realheight, realrowsize; 893 int width = vport->width; 894 int height = vport->height; 895 867 868 unsigned int width = vport->width; 869 unsigned int height = vport->height; 870 896 871 if (width + vport->x > screen.xres) 897 872 width = screen.xres - vport->x; 898 873 if (height + vport->y > screen.yres) 899 874 height = screen.yres - vport->y; 900 875 901 876 if (!pmap->data) 902 877 return EINVAL; 903 904 realwidth = pmap->width <= width ? pmap->width : width; 905 realheight = pmap->height <= height ? pmap->height : height; 906 907 srcrowsize = vport->width * screen.pixelbytes; 908 realrowsize = realwidth * screen.pixelbytes; 909 878 879 unsigned int realwidth = pmap->width <= width ? pmap->width : width; 880 unsigned int realheight = pmap->height <= height ? pmap->height : height; 881 882 unsigned int srcrowsize = vport->width * screen.pixelbytes; 883 unsigned int realrowsize = realwidth * screen.pixelbytes; 884 885 unsigned int y; 910 886 for (y = 0; y < realheight; y++) { 911 tmp = (vport->y + y) * screen.scanline + 912 vport->x * screen.pixelbytes; 913 memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, 914 realrowsize); 915 } 916 return 0; 917 } 918 919 /** Tick animation one step forward */ 920 static void 921 anims_tick(void) 922 { 923 int i; 887 unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; 888 memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); 889 } 890 891 return EOK; 892 } 893 894 895 /** Tick animation one step forward 896 * 897 */ 898 static void anims_tick(void) 899 { 900 unsigned int i; 924 901 static int counts = 0; 925 902 … … 930 907 931 908 for (i = 0; i < MAX_ANIMATIONS; i++) { 932 if ( !animations[i].animlen || !animations[i].initialized||933 !animations[i].enabled)909 if ((!animations[i].animlen) || (!animations[i].initialized) || 910 (!animations[i].enabled)) 934 911 continue; 935 draw_pixmap(animations[i].vp,936 937 animations[i].pos = (animations[i].pos + 1) % 938 animations[i].animlen;939 940 } 941 942 943 static int pointer_x,pointer_y;944 static intpointer_shown, pointer_enabled;912 913 draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); 914 animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; 915 } 916 } 917 918 919 static unsigned int pointer_x; 920 static unsigned int pointer_y; 921 static bool pointer_shown, pointer_enabled; 945 922 static int pointer_vport = -1; 946 923 static int pointer_pixmap = -1; 947 924 948 static void 949 mouse_show(void)925 926 static void mouse_show(void) 950 927 { 951 928 int i, j; … … 953 930 int color; 954 931 int bytepos; 955 956 if ( pointer_shown || !pointer_enabled)932 933 if ((pointer_shown) || (!pointer_enabled)) 957 934 return; 958 935 959 936 /* Save image under the cursor */ 960 937 if (pointer_vport == -1) { 961 pointer_vport = viewport_create(pointer_x, pointer_y, 962 pointer_width, pointer_height); 938 pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); 963 939 if (pointer_vport < 0) 964 940 return; … … 967 943 viewports[pointer_vport].y = pointer_y; 968 944 } 969 945 970 946 if (pointer_pixmap == -1) 971 947 pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); 972 948 else 973 copy_vp_to_pixmap(&viewports[pointer_vport], 974 &pixmaps[pointer_pixmap]); 975 949 copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); 950 976 951 /* Draw cursor */ 977 952 for (i = 0; i < pointer_height; i++) … … 992 967 } 993 968 994 static void 995 mouse_hide(void)969 970 static void mouse_hide(void) 996 971 { 997 972 /* Restore image under the cursor */ … … 1002 977 } 1003 978 1004 static void 1005 mouse_move(unsigned int x, unsigned int y)979 980 static void mouse_move(unsigned int x, unsigned int y) 1006 981 { 1007 982 mouse_hide(); … … 1011 986 } 1012 987 1013 static int 1014 anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)1015 { 1016 int handled = 1;1017 int retval = 0;1018 int i, nvp;988 989 static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 990 { 991 bool handled = true; 992 int retval = EOK; 993 int i, nvp; 1019 994 int newval; 1020 995 1021 996 switch (IPC_GET_METHOD(*call)) { 1022 997 case FB_ANIM_CREATE: … … 1108 1083 } 1109 1084 1110 /** Handler for messages concerning pixmap handling */ 1111 static int 1112 pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 1113 { 1114 int handled = 1; 1115 int retval = 0; 1116 int i,nvp; 1117 1085 1086 /** Handler for messages concerning pixmap handling 1087 * 1088 */ 1089 static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 1090 { 1091 bool handled = true; 1092 int retval = EOK; 1093 int i, nvp; 1094 1118 1095 switch (IPC_GET_METHOD(*call)) { 1119 1096 case FB_VP_DRAW_PIXMAP: … … 1153 1130 handled = 0; 1154 1131 } 1155 1132 1156 1133 if (handled) 1157 1134 ipc_answer_0(callid, retval); … … 1163 1140 * 1164 1141 */ 1165 static void 1166 fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) 1167 { 1168 ipc_callid_t callid; 1169 ipc_call_t call; 1170 int retval; 1171 int i; 1172 unsigned int row,col; 1173 char c; 1174 1175 int vp = 0; 1176 viewport_t *vport = &viewports[0]; 1177 1142 static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) 1143 { 1144 unsigned int vp = 0; 1145 viewport_t *vport = &viewports[vp]; 1146 1178 1147 if (client_connected) { 1179 1148 ipc_answer_0(iid, ELIMIT); 1180 1149 return; 1181 1150 } 1182 client_connected = 1; 1183 ipc_answer_0(iid, EOK); /* Accept connection */ 1184 1185 while (1) { 1186 if (vport->cursor_active || anims_enabled) 1151 1152 /* Accept connection */ 1153 client_connected = true; 1154 ipc_answer_0(iid, EOK); 1155 1156 while (true) { 1157 ipc_callid_t callid; 1158 ipc_call_t call; 1159 int retval; 1160 unsigned int i; 1161 int scroll; 1162 uint8_t glyph; 1163 unsigned int row, col; 1164 1165 if ((vport->cursor_active) || (anims_enabled)) 1187 1166 callid = async_get_call_timeout(&call, 250000); 1188 1167 else 1189 1168 callid = async_get_call(&call); 1190 1169 1191 1170 mouse_hide(); 1192 1171 if (!callid) { … … 1196 1175 continue; 1197 1176 } 1177 1198 1178 if (shm_handle(callid, &call, vp)) 1199 1179 continue; 1180 1200 1181 if (pixmap_handle(callid, &call, vp)) 1201 1182 continue; 1183 1202 1184 if (anim_handle(callid, &call, vp)) 1203 1185 continue; 1204 1205 1186 1187 switch (IPC_GET_METHOD(call)) { 1206 1188 case IPC_M_PHONE_HUNGUP: 1207 client_connected = 0; 1208 /* cleanup other viewports */ 1189 client_connected = false; 1190 1191 /* Cleanup other viewports */ 1209 1192 for (i = 1; i < MAX_VIEWPORTS; i++) 1210 vport->initialized = 0; 1211 return; /* Exit thread */ 1212 1193 vport->initialized = false; 1194 1195 /* Exit thread */ 1196 return; 1197 1213 1198 case FB_PUTCHAR: 1214 case FB_TRANS_PUTCHAR: 1215 c = IPC_GET_ARG1(call); 1199 glyph = IPC_GET_ARG1(call); 1216 1200 row = IPC_GET_ARG2(call); 1217 1201 col = IPC_GET_ARG3(call); 1218 if (row >= vport->rows || col >= vport->cols) { 1202 1203 if ((col >= vport->cols) || (row >= vport->rows)) { 1219 1204 retval = EINVAL; 1220 1205 break; 1221 1206 } 1222 1207 ipc_answer_0(callid, EOK); 1223 1224 draw_char(vport, c, row, col, vport->style, 1225 IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR); 1226 continue; /* msg already answered */ 1208 1209 draw_char(vport, glyph, col, row); 1210 1211 /* Message already answered */ 1212 continue; 1227 1213 case FB_CLEAR: 1228 clear_port(vport);1229 cursor_ print(vport);1230 retval = 0;1231 break; 1232 1214 vport_clear(vport); 1215 cursor_show(vport); 1216 retval = EOK; 1217 break; 1218 case FB_CURSOR_GOTO: 1233 1219 row = IPC_GET_ARG1(call); 1234 1220 col = IPC_GET_ARG2(call); 1235 if (row >= vport->rows || col >= vport->cols) { 1221 1222 if ((col >= vport->cols) || (row >= vport->rows)) { 1236 1223 retval = EINVAL; 1237 1224 break; 1238 1225 } 1239 retval = 0; 1226 retval = EOK; 1227 1240 1228 cursor_hide(vport); 1241 1229 vport->cur_col = col; 1242 1230 vport->cur_row = row; 1243 cursor_ print(vport);1244 1231 cursor_show(vport); 1232 break; 1245 1233 case FB_CURSOR_VISIBILITY: 1246 1234 cursor_hide(vport); 1247 1235 vport->cursor_active = IPC_GET_ARG1(call); 1248 cursor_ print(vport);1249 retval = 0;1236 cursor_show(vport); 1237 retval = EOK; 1250 1238 break; 1251 1239 case FB_GET_CSIZE: … … 1253 1241 continue; 1254 1242 case FB_SCROLL: 1255 i= IPC_GET_ARG1(call);1256 if ( i > vport->rows || i < (- (int)vport->rows)) {1243 scroll = IPC_GET_ARG1(call); 1244 if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { 1257 1245 retval = EINVAL; 1258 1246 break; 1259 1247 } 1260 1248 cursor_hide(vport); 1261 scroll_port(vport, i*FONT_SCANLINES); 1262 cursor_print(vport); 1263 retval = 0; 1264 break; 1265 case FB_VIEWPORT_DB: 1266 /* Enable double buffering */ 1249 vport_scroll(vport, scroll); 1250 cursor_show(vport); 1251 retval = EOK; 1252 break; 1253 case FB_VIEWPORT_SWITCH: 1267 1254 i = IPC_GET_ARG1(call); 1268 if (i == -1) 1269 i = vp; 1270 if (i < 0 || i >= MAX_VIEWPORTS) { 1255 if (i >= MAX_VIEWPORTS) { 1271 1256 retval = EINVAL; 1272 1257 break; 1273 1258 } 1274 if (!viewports[i].initialized ) { 1275 retval = EADDRNOTAVAIL; 1276 break; 1277 } 1278 viewports[i].dboffset = 0; 1279 if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata) 1280 viewports[i].dbdata = 1281 malloc(screen.pixelbytes * 1282 viewports[i].width * viewports[i].height); 1283 else if (IPC_GET_ARG2(call) == 0 && 1284 viewports[i].dbdata) { 1285 free(viewports[i].dbdata); 1286 viewports[i].dbdata = NULL; 1287 } 1288 retval = 0; 1289 break; 1290 case FB_VIEWPORT_SWITCH: 1291 i = IPC_GET_ARG1(call); 1292 if (i < 0 || i >= MAX_VIEWPORTS) { 1293 retval = EINVAL; 1294 break; 1295 } 1296 if (! viewports[i].initialized ) { 1259 if (!viewports[i].initialized) { 1297 1260 retval = EADDRNOTAVAIL; 1298 1261 break; … … 1301 1264 vp = i; 1302 1265 vport = &viewports[vp]; 1303 cursor_ print(vport);1304 retval = 0;1266 cursor_show(vport); 1267 retval = EOK; 1305 1268 break; 1306 1269 case FB_VIEWPORT_CREATE: 1307 retval = v iewport_create(IPC_GET_ARG1(call) >> 16,1270 retval = vport_create(IPC_GET_ARG1(call) >> 16, 1308 1271 IPC_GET_ARG1(call) & 0xffff, 1309 1272 IPC_GET_ARG2(call) >> 16, … … 1312 1275 case FB_VIEWPORT_DELETE: 1313 1276 i = IPC_GET_ARG1(call); 1314 if (i < 0 || i>= MAX_VIEWPORTS) {1277 if (i >= MAX_VIEWPORTS) { 1315 1278 retval = EINVAL; 1316 1279 break; 1317 1280 } 1318 if (! viewports[i].initialized) {1281 if (!viewports[i].initialized) { 1319 1282 retval = EADDRNOTAVAIL; 1320 1283 break; 1321 1284 } 1322 viewports[i].initialized = 0; 1323 if (viewports[i].dbdata) { 1324 free(viewports[i].dbdata); 1325 viewports[i].dbdata = NULL; 1326 } 1327 retval = 0; 1285 viewports[i].initialized = false; 1286 if (viewports[i].glyphs) 1287 free(viewports[i].glyphs); 1288 if (viewports[i].bgpixel) 1289 free(viewports[i].bgpixel); 1290 if (viewports[i].backbuf) 1291 free(viewports[i].backbuf); 1292 retval = EOK; 1328 1293 break; 1329 1294 case FB_SET_STYLE: 1330 1295 vport->style.fg_color = IPC_GET_ARG1(call); 1331 1296 vport->style.bg_color = IPC_GET_ARG2(call); 1332 retval = 0; 1297 render_glyphs(vport); 1298 retval = EOK; 1333 1299 break; 1334 1300 case FB_GET_RESOLUTION: … … 1336 1302 continue; 1337 1303 case FB_POINTER_MOVE: 1338 pointer_enabled = 1;1304 pointer_enabled = true; 1339 1305 mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 1340 retval = 0;1306 retval = EOK; 1341 1307 break; 1342 1308 default: … … 1347 1313 } 1348 1314 1349 /** Initialization of framebuffer */ 1350 int 1351 fb_init(void) 1352 { 1353 void *fb_ph_addr; 1354 unsigned int fb_width; 1355 unsigned int fb_height; 1356 unsigned int fb_scanline; 1357 unsigned int fb_visual; 1358 unsigned int fb_offset; 1359 bool fb_invert_colors; 1360 void *fb_addr; 1361 size_t asz; 1362 1315 /** Initialization of framebuffer 1316 * 1317 */ 1318 int fb_init(void) 1319 { 1363 1320 async_set_client_connection(fb_client_connection); 1364 1365 fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); 1366 fb_offset = sysinfo_value("fb.offset"); 1367 fb_width = sysinfo_value("fb.width"); 1368 fb_height = sysinfo_value("fb.height"); 1369 fb_scanline = sysinfo_value("fb.scanline"); 1370 fb_visual = sysinfo_value("fb.visual"); 1371 fb_invert_colors = sysinfo_value("fb.invert-colors"); 1372 1373 asz = fb_scanline * fb_height; 1374 fb_addr = as_get_mappable_page(asz); 1375 1376 physmem_map(fb_ph_addr + fb_offset, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> 1377 PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); 1378 1379 if (screen_init(fb_addr, fb_offset, fb_width, fb_height, fb_scanline, fb_visual, 1380 fb_invert_colors)) 1321 1322 void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); 1323 unsigned int fb_offset = sysinfo_value("fb.offset"); 1324 unsigned int fb_width = sysinfo_value("fb.width"); 1325 unsigned int fb_height = sysinfo_value("fb.height"); 1326 unsigned int fb_scanline = sysinfo_value("fb.scanline"); 1327 unsigned int fb_visual = sysinfo_value("fb.visual"); 1328 1329 unsigned int fbsize = fb_scanline * fb_height; 1330 void *fb_addr = as_get_mappable_page(fbsize); 1331 1332 physmem_map(fb_ph_addr + fb_offset, fb_addr, 1333 ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); 1334 1335 if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) 1381 1336 return 0; 1382 1337 … … 1384 1339 } 1385 1340 1386 /** 1341 /** 1387 1342 * @} 1388 1343 */ -
uspace/srv/fb/fb.h
r8fe5980 r76fca31 30 30 * @ingroup fbs 31 31 * @{ 32 */ 32 */ 33 33 /** @file 34 34 */ … … 37 37 #define FB_FB_H_ 38 38 39 typedef void (* putpixel_cb_t)(void *, unsigned int, unsigned int, int); 39 #include <stdint.h> 40 41 typedef void (* putpixel_cb_t)(void *, unsigned int, unsigned int, uint32_t); 40 42 41 43 extern int fb_init(void); -
uspace/srv/fb/font-8x16.c
r8fe5980 r76fca31 29 29 #include "font-8x16.h" 30 30 31 unsigned char fb_font[FONT_GL IPHS * FONT_SCANLINES] = {31 unsigned char fb_font[FONT_GLYPHS * FONT_SCANLINES] = { 32 32 33 33 /* 0 0x00 '^@' */ -
uspace/srv/fb/font-8x16.h
r8fe5980 r76fca31 30 30 #define FB_FONT_8X16_H_ 31 31 32 #define FONT_GLIPHS 256 33 #define FONT_SCANLINES 16 32 #define FONT_GLYPHS 256 33 #define FONT_WIDTH 8 34 #define FONT_SCANLINES 16 34 35 35 extern unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES]; 36 37 extern unsigned char fb_font[FONT_GLYPHS * FONT_SCANLINES]; 36 38 37 39 #endif -
uspace/srv/fb/main.c
r8fe5980 r76fca31 47 47 { 48 48 void *dest; 49 49 50 50 dest = as_get_mappable_page(IPC_GET_ARG2(*call)); 51 51 if (ipc_answer_1(callid, EOK, (sysarg_t) dest) == 0) { … … 62 62 ipcarg_t phonead; 63 63 bool initialized = false; 64 64 65 65 #ifdef FB_ENABLED 66 66 if (sysinfo_value("fb.kind") == 1) { 67 67 if (fb_init() == 0) 68 68 initialized = true; 69 } 69 } 70 70 #endif 71 71 #ifdef EGA_ENABLED … … 90 90 if (!initialized) 91 91 return -1; 92 92 93 93 if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, &phonead) != 0) 94 94 return -1; … … 96 96 printf(NAME ": Accepting connections\n"); 97 97 async_manager(); 98 98 99 /* Never reached */ 99 100 return 0; -
uspace/srv/fb/ppm.c
r8fe5980 r76fca31 93 93 unsigned int color; 94 94 unsigned int coef; 95 95 96 96 /* Read magic */ 97 if ( data[0] != 'P' || data[1] != '6')97 if ((data[0] != 'P') || (data[1] != '6')) 98 98 return EINVAL; 99 100 data +=2;99 100 data += 2; 101 101 skip_whitespace(&data); 102 102 read_num(&data, &width); 103 103 skip_whitespace(&data); 104 read_num(&data, &height);104 read_num(&data, &height); 105 105 skip_whitespace(&data); 106 read_num(&data, &maxcolor);106 read_num(&data, &maxcolor); 107 107 data++; 108 109 if ( maxcolor == 0 || maxcolor > 255 || width * height > datasz) {108 109 if ((maxcolor == 0) || (maxcolor > 255) || (width * height > datasz)) 110 110 return EINVAL; 111 }111 112 112 coef = 255 / maxcolor; 113 113 if (coef * maxcolor > 255) … … 126 126 data += 3; 127 127 } 128 128 129 129 return 0; 130 130 }
Note:
See TracChangeset
for help on using the changeset viewer.