Changeset 76fca31 in mainline for kernel


Ignore:
Timestamp:
2008-12-16T19:02:07Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5ae4443
Parents:
8fe5980
Message:

kconsole is optional
kernel & uspace framebuffer rewrite with speedups (some things are slightly broken yet)

Location:
kernel
Files:
1 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/debugger.c

    r8fe5980 r76fca31  
    5555SPINLOCK_INITIALIZE(bkpoint_lock);
    5656
     57#ifdef CONFIG_KCONSOLE
     58
    5759static int cmd_print_breakpoints(cmd_arg_t *argv);
    5860static cmd_info_t bkpts_info = {
     
    100102};
    101103
    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 */
    139106
    140107/* Setup DR register according to table */
     
    268235        printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
    269236            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
    274243}
    275244
     
    300269}
    301270
    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
    337272
    338273static void debug_exception(int n __attribute__((unused)), istate_t *istate)
     
    380315        for (i = 0; i < BKPOINTS_MAX; i++)
    381316                breakpoints[i].address = NULL;
    382        
     317
     318#ifdef CONFIG_KCONSOLE
    383319        cmd_initialize(&bkpts_info);
    384320        if (!cmd_register(&bkpts_info))
    385                 panic("could not register command %s\n", bkpts_info.name);
     321                printf("Cannot register command %s\n", bkpts_info.name);
    386322
    387323#ifndef CONFIG_DEBUG_AS_WATCHPOINT
    388324        cmd_initialize(&delbkpt_info);
    389325        if (!cmd_register(&delbkpt_info))
    390                 panic("could not register command %s\n", delbkpt_info.name);
     326                printf("Cannot register command %s\n", delbkpt_info.name);
    391327
    392328        cmd_initialize(&addbkpt_info);
    393329        if (!cmd_register(&addbkpt_info))
    394                 panic("could not register command %s\n", addbkpt_info.name);
     330                printf("Cannot register command %s\n", addbkpt_info.name);
    395331
    396332        cmd_initialize(&addwatchp_info);
    397333        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 */
    400337       
    401338        exc_register(VECTOR_DEBUG, "debugger", debug_exception);
     
    405342}
    406343
     344#ifdef CONFIG_KCONSOLE
     345/** Print table of active breakpoints */
     346int 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 */
     384int 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 */
     396static 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
    407418/** @}
    408419 */
  • kernel/arch/ia32/include/drivers/ega.h

    r8fe5980 r76fca31  
    4141#define SCREEN          (ROW * ROWS)
    4242
     43extern void ega_redraw(void);
    4344extern void ega_init(void);
    4445
  • kernel/arch/ia32/include/drivers/vesa.h

    r8fe5980 r76fca31  
    3737
    3838extern int vesa_present(void);
     39extern void vesa_redraw(void);
    3940extern void vesa_init(void);
    4041
  • kernel/arch/ia32/src/cpu/cpu.c

    r8fe5980 r76fca31  
    6666static char *vendor_str[] = {
    6767        "Unknown Vendor",
    68         "AuthenticAMD",
    69         "GenuineIntel"
     68        "AMD",
     69        "Intel"
    7070};
    7171
     
    7878                :
    7979                :
    80                 :"%eax"
     80                : "%eax"
    8181        );
    8282}
     
    9090                :
    9191                :
    92                 :"%eax"
     92                : "%eax"
    9393        );     
    9494}
     
    141141                 * Check for AMD processor.
    142142                 */
    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))
    144146                        CPU->arch.vendor = VendorAMD;
    145                 }
    146 
     147               
    147148                /*
    148149                 * Check for Intel processor.
    149150                 */             
    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))
    151154                        CPU->arch.vendor = VendorIntel;
    152                 }
    153                                
     155               
    154156                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;                                             
    158160        }
    159161}
    160162
    161 void cpu_print_report(cpu_t* m)
     163void cpu_print_report(cpu_t* cpu)
    162164{
    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);
    166168}
    167169
  • kernel/arch/ia32/src/drivers/vesa.c

    r8fe5980 r76fca31  
    9898}
    9999
     100void vesa_redraw(void)
     101{
     102        fb_redraw();
     103}
     104
    100105#endif
    101106
  • kernel/arch/ia32/src/ia32.c

    r8fe5980 r76fca31  
    9494                else
    9595#endif
    96                         ega_init();     /* video */
     96                        ega_init(); /* video */
    9797               
    9898                /* Enable debugger */
     
    160160void arch_grab_console(void)
    161161{
     162#ifdef CONFIG_FB
     163        vesa_redraw();
     164#else
     165        ega_redraw();
     166#endif
     167       
    162168        i8042_grab();
    163169}
     170
    164171/** Return console to userspace
    165172 *
  • kernel/arch/mips32/src/cpu/cpu.c

    r8fe5980 r76fca31  
    4949        { "MIPS", "R3000" },            /* 0x02 */
    5050        { "MIPS", "R6000" },            /* 0x03 */
    51         { "MIPS", " R4000/R4400" },     /* 0x04 */
     51        { "MIPS", "R4000/R4400" },      /* 0x04 */
    5252        { "LSI Logic", "R3000" },       /* 0x05 */
    5353        { "MIPS", "R6000A" },           /* 0x06 */
     
    124124        }
    125125
    126         printf("cpu%d: %s %s (rev=%d.%d, imp=%d)\n",
     126        printf("cpu%u: %s %s (rev=%d.%d, imp=%d)\n",
    127127                m->id, data->vendor, data->model, m->arch.rev_num >> 4,
    128                 m->arch.rev_num & 0xf, m->arch.imp_num);
     128                m->arch.rev_num & 0x0f, m->arch.imp_num);
    129129}
    130130
  • kernel/arch/mips32/src/debugger.c

    r8fe5980 r76fca31  
    4747bpinfo_t breakpoints[BKPOINTS_MAX];
    4848SPINLOCK_INITIALIZE(bkpoint_lock);
     49
     50#ifdef CONFIG_KCONSOLE
    4951
    5052static int cmd_print_breakpoints(cmd_arg_t *argv);
     
    124126};
    125127
     128
    126129/** Test, if the given instruction is a jump or branch instruction
    127130 *
    128131 * @param instr Instruction code
    129132 * @return true - it is jump instruction, false otherwise
     133 *
    130134 */
    131135static bool is_jump(unative_t instr)
     
    268272}
    269273
     274#endif
     275
    270276/** Initialize debugger */
    271277void debugger_init()
     
    275281        for (i = 0; i < BKPOINTS_MAX; i++)
    276282                breakpoints[i].address = NULL;
    277        
     283
     284#ifdef CONFIG_KCONSOLE
    278285        cmd_initialize(&bkpts_info);
    279286        if (!cmd_register(&bkpts_info))
    280                 panic("could not register command %s\n", bkpts_info.name);
     287                printf("Cannot register command %s\n", bkpts_info.name);
    281288
    282289        cmd_initialize(&delbkpt_info);
    283290        if (!cmd_register(&delbkpt_info))
    284                 panic("could not register command %s\n", delbkpt_info.name);
     291                printf("Cannot register command %s\n", delbkpt_info.name);
    285292
    286293        cmd_initialize(&addbkpt_info);
    287294        if (!cmd_register(&addbkpt_info))
    288                 panic("could not register command %s\n", addbkpt_info.name);
     295                printf("Cannot register command %s\n", addbkpt_info.name);
    289296
    290297        cmd_initialize(&addbkpte_info);
    291298        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
    293301}
    294302
     
    368376                        cur->bkfunc(cur, istate);
    369377        } else {
    370                 printf("***Type 'exit' to exit kconsole.\n");
     378#ifdef CONFIG_KCONSOLE
    371379                /* This disables all other processors - we are not SMP,
    372380                 * actually this gets us to cpu_halt, if scheduler() is run
     
    374382                 *   so this is a good idea
    375383                 */     
    376                 atomic_set(&haltstate,1);
     384                atomic_set(&haltstate, 1);
    377385                spinlock_unlock(&bkpoint_lock);
    378 
    379                 kconsole("debug");
    380 
     386               
     387                kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false);
     388               
    381389                spinlock_lock(&bkpoint_lock);
    382                 atomic_set(&haltstate,0);
     390                atomic_set(&haltstate, 0);
     391#endif
    383392        }
    384393        if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) {
  • kernel/arch/mips32/src/exception.c

    r8fe5980 r76fca31  
    4646#include <interrupt.h>
    4747#include <func.h>
    48 #include <console/kconsole.h>
    4948#include <ddi/irq.h>
    5049#include <arch/debugger.h>
  • kernel/genarch/include/fb/fb.h

    r8fe5980 r76fca31  
    2727 */
    2828
    29 /** @addtogroup genarch 
     29/** @addtogroup genarch
    3030 * @{
    3131 */
     
    6666
    6767SPINLOCK_EXTERN(fb_lock);
     68
     69void fb_redraw(void);
    6870void fb_init(fb_properties_t *props);
    6971
  • kernel/genarch/include/fb/font-8x16.h

    r8fe5980 r76fca31  
    2727 */
    2828
    29 /** @addtogroup genarch 
     29/** @addtogroup genarch
    3030 * @{
    3131 */
     
    3636#define KERN_FONT_8X16_H_
    3737
    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
    4041
    41 extern unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES];
     42#include <arch/types.h>
     43
     44extern uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES];
    4245
    4346#endif
  • kernel/genarch/include/fb/visuals.h

    r8fe5980 r76fca31  
    2727 */
    2828
    29 /** @addtogroup genarch 
     29/** @addtogroup genarch
    3030 * @{
    3131 */
     
    3636#define KERN_VISUALS_H_
    3737
    38 #define VISUAL_INDIRECT_8       0
     38#define VISUAL_INDIRECT_8   0
    3939
    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
     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
    4545
    46 #define VISUAL_BGR_0_8_8_8      6
     46#define VISUAL_BGR_0_8_8_8  6
    4747
    4848#endif
  • kernel/genarch/src/acpi/acpi.c

    r8fe5980 r76fca31  
    5050struct acpi_xsdt *acpi_xsdt = NULL;
    5151
    52 struct acpi_signature_map signature_map[] = {
    53         { (uint8_t *)"APIC", (void *) &acpi_madt, "Multiple APIC Description Table" }
     52struct acpi_signature_map signature_map[] = {
     53        {
     54                (uint8_t *) "APIC",
     55                (void *) &acpi_madt,
     56                "Multiple APIC Description Table"
     57        }
    5458};
    5559
     
    106110                                        goto next;
    107111                                *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);
    109113                        }
    110114                }
     
    127131                                        goto next;
    128132                                *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);
    130134                        }
    131135                }
     
    161165
    162166rsdp_found:
    163         printf("%p: ACPI Root System Description Pointer\n", acpi_rsdp);
     167        LOG("%p: ACPI Root System Description Pointer\n", acpi_rsdp);
    164168
    165169        acpi_rsdt = (struct acpi_rsdt *) (unative_t) acpi_rsdp->rsdt_address;
  • kernel/genarch/src/fb/fb.c

    r8fe5980 r76fca31  
    11/*
     2 * Copyright (c) 2008 Martin Decky
    23 * Copyright (c) 2006 Ondrej Palkovsky
    34 * All rights reserved.
     
    2728 */
    2829
    29 /** @addtogroup genarch 
     30/** @addtogroup genarch
    3031 * @{
    3132 */
     
    4041#include <sysinfo/sysinfo.h>
    4142#include <mm/slab.h>
     43#include <align.h>
    4244#include <panic.h>
    4345#include <memstr.h>
     
    4850#include <arch/types.h>
    4951
    50 #include "helenos.xbm"
    51 
    52 static parea_t fb_parea;                /**< Physical memory area for fb. */
    53 
    5452SPINLOCK_INITIALIZE(fb_lock);
    5553
    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. */
     55static parea_t fb_parea;
     56
     57static uint8_t *fb_addr;
     58static uint8_t *backbuf;
     59static uint8_t *glyphs;
     60
     61static void *bgpixel;
     62
     63static unsigned int xres;
     64static unsigned int yres;
     65
     66static unsigned int scanline;
     67static unsigned int glyphscanline;
     68
     69static unsigned int pixelbytes;
     70static unsigned int glyphbytes;
     71
     72static unsigned int cols;
     73static unsigned int rows;
     74static 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
     96static void (*rgb_conv)(void *, uint32_t);
     97
     98
     99/** ARGB 8:8:8:8 conversion
     100 *
     101 */
     102static 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 */
     111static 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 */
     121static 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);
    68127#else
    69 static bool invert_colors = false;
     128        *((uint32_t *) dst)
     129            = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000);
    70130#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 */
     137static 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 */
     147static 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
    181155 *
    182156 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
     
    186160 * and setting it to simulate the 8-bit truecolor.
    187161 *
    188  * Currently we set the palette on the sparc64 port.
     162 * Currently we set the palette on the ia32 and sparc64 port.
    189163 *
    190164 * Note that the byte is being inverted by this function. The reason is
     
    194168 * 0 and 255 to other colors.
    195169 */
    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 */
     170static 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 */
     180static 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 */
    249198static void scroll_screen(void)
    250199{
    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;
    253205               
    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                        }
    285224                }
    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
     232static void cursor_put(void)
     233{
     234        draw_glyph(CURSOR, position % cols, position / cols);
     235}
     236
     237
     238static void cursor_remove(void)
     239{
     240        draw_glyph(0, position % cols, position / cols);
     241}
     242
    393243
    394244/** Print character to screen
    395245 *
    396  *  Emulate basic terminal commands
     246 * Emulate basic terminal commands.
     247 *
    397248 */
    398249static void fb_putchar(chardev_t *dev, char ch)
     
    402253        switch (ch) {
    403254        case '\n':
    404                 invert_cursor();
    405                 position += columns;
    406                 position -= position % columns;
     255                cursor_remove();
     256                position += cols;
     257                position -= position % cols;
    407258                break;
    408259        case '\r':
    409                 invert_cursor();
    410                 position -= position % columns;
     260                cursor_remove();
     261                position -= position % cols;
    411262                break;
    412263        case '\b':
    413                 invert_cursor();
    414                 if (position % columns)
     264                cursor_remove();
     265                if (position % cols)
    415266                        position--;
    416267                break;
    417268        case '\t':
    418                 invert_cursor();
     269                cursor_remove();
    419270                do {
    420                         draw_char(' ');
     271                        draw_glyph((uint8_t) ' ', position % cols, position / cols);
    421272                        position++;
    422                 } while ((position % 8) && position < columns * rows);
     273                } while ((position % 8) && (position < cols * rows));
    423274                break;
    424275        default:
    425                 draw_char(ch);
     276                draw_glyph((uint8_t) ch, position % cols, position / cols);
    426277                position++;
    427278        }
    428279       
    429         if (position >= columns * rows) {
    430                 position -= columns;
     280        if (position >= cols * rows) {
     281                position -= cols;
    431282                scroll_screen();
    432283        }
    433284       
    434         invert_cursor();
     285        cursor_put();
    435286       
    436287        spinlock_unlock(&fb_lock);
     
    443294
    444295
     296/** Render glyphs
     297 *
     298 * Convert glyphs from device independent font
     299 * description to current visual representation.
     300 *
     301 */
     302static 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 */
     325void 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
    445368/** Initialize framebuffer as a chardev output device
    446369 *
    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 *
    448376 */
    449377void fb_init(fb_properties_t *props)
     
    451379        switch (props->visual) {
    452380        case VISUAL_INDIRECT_8:
    453                 rgb2scr = rgb_byte8;
    454                 scr2rgb = byte8_rgb;
     381                rgb_conv = rgb_323;
    455382                pixelbytes = 1;
    456383                break;
    457384        case VISUAL_RGB_5_5_5:
    458                 rgb2scr = rgb_byte555;
    459                 scr2rgb = byte555_rgb;
     385                rgb_conv = rgb_555;
    460386                pixelbytes = 2;
    461387                break;
    462388        case VISUAL_RGB_5_6_5:
    463                 rgb2scr = rgb_byte565;
    464                 scr2rgb = byte565_rgb;
     389                rgb_conv = rgb_565;
    465390                pixelbytes = 2;
    466391                break;
    467392        case VISUAL_RGB_8_8_8:
    468                 rgb2scr = rgb_byte888;
    469                 scr2rgb = byte888_rgb;
     393                rgb_conv = rgb_888;
    470394                pixelbytes = 3;
    471395                break;
    472396        case VISUAL_RGB_8_8_8_0:
    473                 rgb2scr = rgb_byte888;
    474                 scr2rgb = byte888_rgb;
     397                rgb_conv = rgb_888;
    475398                pixelbytes = 4;
    476399                break;
    477400        case VISUAL_RGB_0_8_8_8:
    478                 rgb2scr = rgb_byte0888;
    479                 scr2rgb = byte0888_rgb;
     401                rgb_conv = rgb_0888;
    480402                pixelbytes = 4;
    481403                break;
    482404        case VISUAL_BGR_0_8_8_8:
    483                 rgb2scr = bgr_byte0888;
    484                 scr2rgb = byte0888_bgr;
     405                rgb_conv = bgr_0888;
    485406                pixelbytes = 4;
    486407                break;
     
    488409                panic("Unsupported visual.\n");
    489410        }
    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;
    497411       
    498412        xres = props->x;
     
    500414        scanline = props->scan;
    501415       
    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       
    505446        fb_parea.pbase = (uintptr_t) props->addr + props->offset;
    506         fb_parea.vbase = (uintptr_t) fbaddress;
     447        fb_parea.vbase = (uintptr_t) fb_addr;
    507448        fb_parea.frames = SIZE2FRAMES(fbsize);
    508449        fb_parea.cacheable = false;
    509450        ddi_parea_register(&fb_parea);
    510 
     451       
    511452        sysinfo_set_item_val("fb", NULL, true);
    512453        sysinfo_set_item_val("fb.kind", NULL, 1);
    513454        sysinfo_set_item_val("fb.width", NULL, xres);
    514455        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);
    516457        sysinfo_set_item_val("fb.visual", NULL, props->visual);
    517458        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       
    545462        chardev_initialize("fb", &framebuffer, &fb_ops);
    546463        stdout = &framebuffer;
  • kernel/genarch/src/fb/font-8x16.c

    r8fe5980 r76fca31  
    3535#include <genarch/fb/font-8x16.h>
    3636
    37 unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES] = {
     37uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES] = {
    3838
    3939        /* 0 0x00 '^@' */
  • kernel/genarch/src/mm/asid.c

    r8fe5980 r76fca31  
    3333/**
    3434 * @file
    35  * @brief       ASID management.
     35 * @brief ASID management.
    3636 *
    3737 * Modern processor architectures optimize TLB utilization
  • kernel/generic/include/console/kconsole.h

    r8fe5980 r76fca31  
    8888
    8989extern void kconsole_init(void);
    90 extern void kconsole(void *prompt);
     90extern void kconsole(char *prompt, char *msg, bool kcon);
     91extern void kconsole_thread(void *data);
    9192
    9293extern int cmd_register(cmd_info_t *cmd);
  • kernel/generic/src/console/cmd.c

    r8fe5980 r76fca31  
    502502                cmd_initialize(basic_commands[i]);
    503503                if (!cmd_register(basic_commands[i]))
    504                         panic("could not register command %s\n", basic_commands[i]->name);
     504                        printf("Cannot register command %s\n", basic_commands[i]->name);
    505505        }
    506506}
  • kernel/generic/src/console/console.c

    r8fe5980 r76fca31  
    168168                else
    169169                        printf("cpu: ");
    170                 printf("halted - no kconsole\n");
     170                printf("halted (no kconsole)\n");
    171171                cpu_halt();
    172172        }
  • kernel/generic/src/console/kconsole.c

    r8fe5980 r76fca31  
    402402}
    403403
    404 /** Kernel console managing thread.
     404/** Kernel console prompt.
    405405 *
    406406 * @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 */
     412void kconsole(char *prompt, char *msg, bool kcon)
    409413{
    410414        cmd_info_t *cmd_info;
     
    413417
    414418        if (!stdin) {
    415                 printf("%s: no stdin\n", __func__);
     419                LOG("No stdin for kernel console");
    416420                return;
    417421        }
     422       
     423        if (msg)
     424                printf("%s", msg);
     425       
     426        if (kcon)
     427                _getc(stdin);
    418428       
    419429        while (true) {
     
    422432                if (!len)
    423433                        continue;
     434               
    424435                cmd_info = parse_cmdline(cmdline, len);
    425436                if (!cmd_info)
    426437                        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))
    429441                        break;
     442               
    430443                (void) cmd_info->func(cmd_info->argv);
    431444        }
     445}
     446
     447/** Kernel console managing thread.
     448 *
     449 */
     450void kconsole_thread(void *data)
     451{
     452        kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
    432453}
    433454
  • kernel/generic/src/cpu/cpu.c

    r8fe5980 r76fca31  
    8787#endif /* CONFIG_SMP */
    8888
    89         CPU = &cpus[config.cpu_active-1];
     89        CPU = &cpus[config.cpu_active - 1];
    9090       
    9191        CPU->active = 1;
  • kernel/generic/src/interrupt/interrupt.c

    r8fe5980 r76fca31  
    110110}
    111111
     112#ifdef CONFIG_KCONSOLE
     113
    112114/** kconsole cmd - print all exceptions */
    113 static int exc_print_cmd(cmd_arg_t *argv)
     115static int cmd_exc_print(cmd_arg_t *argv)
    114116{
    115117#if (IVT_ITEMS > 0)
     
    159161}
    160162
     163
    161164static cmd_info_t exc_info = {
    162165        .name = "exc",
    163166        .description = "Print exception table.",
    164         .func = exc_print_cmd,
     167        .func = cmd_exc_print,
    165168        .help = NULL,
    166169        .argc = 0,
    167170        .argv = NULL
    168171};
     172
     173#endif
    169174
    170175/** Initialize generic exception handling support */
     
    176181                exc_register(i, "undef", (iroutine) exc_undef);
    177182
     183#ifdef CONFIG_KCONSOLE
    178184        cmd_initialize(&exc_info);
    179185        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
    181188}
    182189
  • kernel/generic/src/lib/func.c

    r8fe5980 r76fca31  
    5656        bool rundebugger = false;
    5757
    58 //      TODO test_and_set not defined on all arches
    59 //      if (!test_and_set(&haltstate))
    6058        if (!atomic_get(&haltstate)) {
    6159                atomic_set(&haltstate, 1);
     
    6765
    6866        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       
    7573        if (CPU)
    7674                printf("cpu%u: halted\n", CPU->id);
  • kernel/generic/src/main/kinit.c

    r8fe5980 r76fca31  
    8383void kinit(void *arg)
    8484{
    85         thread_t *t;
     85
     86#if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE)
     87        thread_t *thread;
     88#endif
    8689
    8790        /*
     
    101104                 * Just a beautification.
    102105                 */
    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);
    109112                } 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);
    113116        }
    114117#endif /* CONFIG_SMP */
    115         /*
    116          * Now that all CPUs are up, we can report what we've found.
    117          */
    118         cpu_list();
    119 
     118       
    120119#ifdef CONFIG_SMP
    121120        if (config.cpu_count > 1) {
     
    126125                 */
    127126                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);
    135133                        } else
    136                                 panic("thread_create/kcpulb\n");
     134                                printf("Unable to create kcpulb thread for cpu" PRIc "\n", i);
    137135
    138136                }
    139137        }
    140138#endif /* CONFIG_SMP */
    141 
     139       
    142140        /*
    143141         * At this point SMP, if present, is configured.
     
    145143        arch_post_smp_init();
    146144
    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       
    157158        interrupts_enable();
    158159       
     
    165166        for (i = 0; i < init.cnt; i++) {
    166167                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);
    168169                        continue;
    169170                }
    170 
     171               
    171172                int rc = program_create_from_image((void *) init.tasks[i].addr,
    172173                    "init-bin", &programs[i]);
    173 
    174                 if (rc == 0 && programs[i].task != NULL) {
     174               
     175                if ((rc == 0) && (programs[i].task != NULL)) {
    175176                        /*
    176177                         * Set capabilities to init userspace tasks.
     
    185186                } else {
    186187                        /* 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);
    189189                       
    190190                        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);
    193192                }
    194193        }
     
    204203        }
    205204
     205#ifdef CONFIG_KCONSOLE
    206206        if (!stdin) {
     207                printf("kinit: No stdin\nKernel alive: ");
     208               
     209                uint64_t i = 0;
    207210                while (1) {
     211                        printf(PRIu64 " ", i);
    208212                        thread_sleep(1);
    209                         printf("kinit... ");
    210                 }
    211         }
     213                        i++;
     214                }
     215        }
     216#endif /* CONFIG_KCONSOLE */
    212217}
    213218
  • kernel/generic/src/main/main.c

    r8fe5980 r76fca31  
    192192        /* Keep this the first thing. */
    193193        the_initialize(THE);
    194 
    195         LOG();
    196194       
    197195        version_print();
     
    201199            config.base, config.kernel_size, config.stack_base,
    202200            config.stack_size);
    203        
    204 
     201
     202#ifdef CONFIG_KCONSOLE
    205203        /*
    206204         * kconsole data structures must be initialized very early
     
    209207         */
    210208        LOG_EXEC(kconsole_init());
     209#endif
    211210       
    212211        /*
     
    253252                count_t i;
    254253                for (i = 0; i < init.cnt; i++)
    255                         printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
     254                        LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
    256255                            "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
    257256                            init.tasks[i].size);
     
    272271         * Create the first thread.
    273272         */
    274         thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit",
    275             true);
     273        thread_t *kinit_thread
     274                = thread_create(kinit, NULL, kernel, 0, "kinit", true);
    276275        if (!kinit_thread)
    277276                panic("Can't create kinit thread\n");
  • kernel/generic/src/mm/as.c

    r8fe5980 r76fca31  
    147147        AS_KERNEL = as_create(FLAG_AS_KERNEL);
    148148        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);
    151155}
    152156
     
    177181        page_table_create(flags);
    178182#endif
    179 
     183       
    180184        return as;
    181185}
     
    770774 * into private anonymous memory (unless it's already there).
    771775 *
    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 *
    777782 */
    778783int as_area_change_flags(as_t *as, int flags, uintptr_t address)
     
    786791        index_t frame_idx;
    787792        count_t used_pages;
    788 
     793       
    789794        /* Flags for the new memory mapping */
    790795        page_flags = area_flags_to_page_flags(flags);
     
    800805        }
    801806
    802         if (area->sh_info || area->backend != &anon_backend) {
     807        if ((area->sh_info) || (area->backend != &anon_backend)) {
    803808                /* Copying shared areas not supported yet */
    804809                /* Copying non-anonymous memory not supported yet */
     
    871876
    872877        tlb_invalidate_pages(as->asid, area->base, area->pages);
     878       
    873879        /*
    874880         * Invalidate potential software translation caches (e.g. TSB on
  • kernel/generic/src/syscall/syscall.c

    r8fe5980 r76fca31  
    9393static unative_t sys_debug_enable_console(void)
    9494{
     95#ifdef CONFIG_KCONSOLE
    9596        arch_grab_console();
    96         return 0;
     97        return true;
     98#else
     99        return false;
     100#endif
    97101}
    98102
Note: See TracChangeset for help on using the changeset viewer.