Changeset ,90

Show
Ignore:
Timestamp:
10/22/2008 08:52:05 PM (3 months ago)
Author:
Berkus <berkus@madfire.net>
branch-nick:
bzr
Message:

I tried the c++style and I liked it.
Migrate more memory funcs from string.c to kernel.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • vesper/src/ElfParser.cpp

    r84 r90  
    3232} 
    3333 
    34 char *ElfParser::findSymbol(Address addr, Address *symbolStart) 
     34char* ElfParser::findSymbol(address_t addr, address_t *symbolStart) 
    3535{ 
    36         Address max = 0; 
     36        address_t max = 0; 
    3737        Elf32Symbol *fallbackSymbol = 0; 
    3838        for (unsigned int i = 0; i < symbolTable->sh_size / symbolTable->sh_entsize; i++) 
  • vesper/src/ElfParser.h

    r84 r90  
    4141  Returns the address of the last byte to be loaded in. 
    4242  **/ 
    43   Address getLastAddress(); 
     43  address_t getLastAddress(); 
    4444 
    4545  /** 
     
    5252  of that symbol in startAddr if startAddr != NULL. 
    5353  **/ 
    54   char *findSymbol(Address addr, Address *symbolStart=NULL); 
     54  char* findSymbol(address_t addr, address_t *symbolStart = NULL); 
    5555 
    5656  /** 
     
    5959  using the hashtable sections in ELF. 
    6060  **/ 
    61   Address findSymbol(char *str); 
     61  address_t findSymbol(char* str); 
    6262 
    6363  /** 
     
    6565  relocation symbol table. 
    6666  **/ 
    67   Address findDynamicSymbolLocation(Address o); 
     67  address_t findDynamicSymbolLocation(address_t o); 
    6868 
    6969  /** 
     
    7171  the symbol at offset o in the relocation symbol table. 
    7272  **/ 
    73   char *findDynamicSymbolName(Address o); 
     73  char *findDynamicSymbolName(address_t o); 
    7474 
    7575  /** 
    7676  Gets the address of the global offset table. 
    7777  **/ 
    78   Address getGlobalOffsetTable(); 
     78  address_t getGlobalOffsetTable(); 
    7979 
    8080  /** 
    8181  Returns the entry point of the executable. 
    8282  **/ 
    83   Address getEntryPoint() 
     83  address_t getEntryPoint() 
    8484  { 
    85           return (Address)header->e_entry; 
     85          return (address_t)header->e_entry; 
    8686  } 
    8787 
  • vesper/src/Globals.cpp

    r84 r90  
    1515 
    1616/* Global objects FIXME: use singletons instead? */ 
    17 Kernel kernel; 
    18 Multiboot multiboot; 
     17class kernel kernel; 
     18multiboot_t multiboot; 
    1919ElfParser kernelElfParser; 
    2020MemoryManager memoryManager; 
     
    2222 
    2323/* This entry point is called from loader */ 
    24 void kernel_entry(MultibootHeader *multibootHeader) 
     24void kernel_entry(multiboot_header_t *multiboot_header) 
    2525{ 
    2626        kconsole.clear(); 
    27         multiboot = Multiboot(multibootHeader); 
     27        multiboot = multiboot_t(multiboot_header); 
    2828        kernel.run(); /* does not return */ 
    2929} 
     
    113113        kconsole.set_attr(RED, YELLOW); 
    114114        kconsole.print("PANIC (%s) at %s:%d\n", message, file, line); 
    115         kernel.printBacktrace(); 
     115        kernel.print_backtrace(); 
    116116 
    117117        // Halt by going into an infinite loop. 
     
    126126        kconsole.set_attr(WHITE, RED); 
    127127        kconsole.print("ASSERTION-FAILED(%s) at %s:%d\n", desc, file, line); 
    128         kernel.printBacktrace(); 
     128        kernel.print_backtrace(); 
    129129 
    130130        // Halt by going into an infinite loop. 
  • vesper/src/Globals.h

    r84 r90  
    1111#include "string.h" 
    1212 
    13 extern class Kernel kernel; 
    14 extern class Multiboot multiboot; 
     13extern class kernel kernel; 
     14extern class multiboot_t multiboot; 
    1515extern class ElfParser kernelElfParser; 
    1616extern class MemoryManager memoryManager; 
    1717extern class InterruptDescriptorTable interruptsTable; 
    1818 
    19 extern "C" void kernel_entry(class MultibootHeader *mh) NORETURN; 
     19extern "C" void kernel_entry(class multiboot_header_t *mh) NORETURN; 
    2020 
    2121void *operator new(size_t size); 
  • vesper/src/Kernel.cpp

    r84 r90  
    2020PageFaultHandler pageFaultHandler; 
    2121 
    22 void Kernel::run() 
     22void kernel::run() 
    2323{ 
    24         if (!multiboot.isElf()) 
     24        if (!multiboot.is_elf()) 
    2525                PANIC("ELF information is missing in kernel!"); 
    2626 
    2727        // Make sure we aren't overwriting anything by writing at placementAddress. 
    28         relocatePlacementAddress(); 
     28        relocate_placement_address(); 
    2929 
    30         kernelElfParser.loadKernel(multiboot.symtabStart(), multiboot.strtabStart()); 
     30        kernelElfParser.loadKernel(multiboot.symtab_start(), multiboot.strtab_start()); 
    3131 
    3232        GlobalDescriptorTable::init(); 
     
    3535        interruptsTable.init(); 
    3636 
    37         memoryManager.init(multiboot.upperMem() * 1024); 
     37        memoryManager.init(multiboot.upper_mem() * 1024); 
    3838        memoryManager.remapStack(); 
    3939        kconsole.debug_log("Remapped stack and ready to rock."); 
     
    4141        Task::init(); 
    4242        Timer::init();//crashes at start of timer init (stack problem?) 
     43// tasking causes stack fuckups after timer inits and causes a yield? 
     44// weird: seems to work now. check gcc optimizations. 
    4345 
    4446        // Load initrd and pass control to init component 
     
    4749} 
    4850 
    49 void Kernel::relocatePlacementAddress() 
     51void kernel::relocate_placement_address() 
    5052{ 
    51         Address newPlacementAddress = memoryManager.getPlacementAddress(); 
    52         if (multiboot.isElf() && multiboot.symtabEnd() > newPlacementAddress) 
     53        address_t newPlacementAddress = memoryManager.getPlacementAddress(); 
     54        if (multiboot.is_elf() && multiboot.symtab_end() > newPlacementAddress) 
    5355        { 
    54                 newPlacementAddress = multiboot.symtabEnd(); 
     56                newPlacementAddress = multiboot.symtab_end(); 
    5557        } 
    56         if (multiboot.isElf() && multiboot.strtabEnd() > newPlacementAddress) 
     58        if (multiboot.is_elf() && multiboot.strtab_end() > newPlacementAddress) 
    5759        { 
    58                 newPlacementAddress = multiboot.strtabEnd(); 
     60                newPlacementAddress = multiboot.strtab_end(); 
    5961        } 
    60         if (multiboot.modStart() > newPlacementAddress) 
     62        if (multiboot.mod_start() > newPlacementAddress) 
    6163        { 
    62                 newPlacementAddress = multiboot.modEnd(); 
     64                newPlacementAddress = multiboot.mod_end(); 
    6365        } 
    6466        memoryManager.setPlacementAddress(newPlacementAddress); 
    6567} 
    6668 
    67 void Kernel::dumpMemory(Address start, size_t size) 
     69void kernel::dump_memory(address_t start, size_t size) 
    6870{ 
    6971        char *ptr = (char *)start; 
     
    99101                { 
    100102                        char c = *(ptr+i); 
    101                         if (c == kconsole.EOL
     103                        if (c == kconsole.eol
    102104                                c = ' '; 
    103105                        kconsole.print_char(c); 
     
    109111} 
    110112 
    111 Address Kernel::backtrace(Address basePointer, Address& returnAddress) 
     113address_t kernel::backtrace(address_t basePointer, address_t& returnAddress) 
    112114{ 
    113115        // We take a stack base pointer (in basePointer), return what it's pointing at 
    114116        // and put the Address just above it in the stack in returnAddress. 
    115         Address nextBase = *((Address*)basePointer); 
    116         returnAddress    = *((Address*)(basePointer+sizeof(Address))); 
     117        address_t nextBase = *((address_t*)basePointer); 
     118        returnAddress    = *((address_t*)(basePointer+sizeof(address_t))); 
    117119        return nextBase; 
    118120} 
    119121 
    120 Address Kernel::backtrace(int n) 
     122address_t kernel::backtrace(int n) 
    121123{ 
    122         Address basePointer = readBasePointer(); 
    123         Address ebp = basePointer; 
    124         Address eip = 1; 
     124        address_t basePointer = readBasePointer(); 
     125        address_t ebp = basePointer; 
     126        address_t eip = 1; 
    125127        int i = 0; 
    126128        while (ebp && eip /*&& eip < 0x87000000*/) 
     
    136138} 
    137139 
    138 void Kernel::printBacktrace(Address basePointer, int n) 
     140void kernel::print_backtrace(address_t basePointer, int n) 
    139141{ 
    140         Address eip = 1; // Don't initialise to 0, will kill the loop immediately. 
     142        address_t eip = 1; // Don't initialise to 0, will kill the loop immediately. 
    141143        if (basePointer == NULL) 
    142144        { 
    143145                basePointer = readBasePointer(); 
    144146        } 
    145         Address ebp = basePointer; 
     147        address_t ebp = basePointer; 
    146148        kconsole.set_color(GREEN); 
    147149        kconsole.print("*** Backtrace *** Tracing %d stack frames:\n", n); 
     
    160162} 
    161163 
    162 void Kernel::printStacktrace(unsigned int n) 
     164void kernel::print_stacktrace(unsigned int n) 
    163165{ 
    164         Address esp = readStackPointer(); 
    165         Address espBase = esp; 
     166        address_t esp = readStackPointer(); 
     167        address_t espBase = esp; 
    166168        kconsole.set_color(GREEN); 
    167169        kconsole.print("<ESP=%08x>\n", esp); 
    168170        for (unsigned int i = 0; i < n; i++) 
    169171        { 
    170                 kconsole.print("<ESP+%4d> %08x\n", esp - espBase, *(Address*)esp); 
    171                 esp += sizeof(Address); 
     172                kconsole.print("<ESP+%4d> %08x\n", esp - espBase, *(address_t*)esp); 
     173                esp += sizeof(address_t); 
    172174        } 
    173175} 
  • vesper/src/Kernel.h

    r84 r90  
    1010#include "Macros.h" 
    1111 
    12 class Kernel 
     12class kernel 
    1313{ 
    1414public: 
     
    2121         * Dump @c size bytes from a memory region starting at virtual address @c start. 
    2222         */ 
    23         static void dumpMemory(Address start, size_t size); 
     23        static void dump_memory(address_t start, size_t size); 
    2424 
    2525        /** 
     
    2727         * pointer and also return the instruction pointer it returned to. 
    2828         */ 
    29         static Address backtrace(Address basePointer, Address& returnAddress); 
     29        static address_t backtrace(address_t base_pointer, address_t& return_address); 
    3030 
    3131        /** 
     
    3333         * return address found there. 
    3434         */ 
    35         static Address backtrace(int n); 
     35        static address_t backtrace(int n); 
    3636 
    37         inline static bool strEquals(const char *in1, const char *in2) 
     37        // TODO: move to string class 
     38        inline static bool str_equals(const char *in1, const char *in2) 
    3839        { 
    3940                char *left = (char *)in1; 
     
    4748 
    4849        /** 
     50         * memset - Fill a region of memory with the given value 
     51         * @s: Pointer to the start of the area. 
     52         * @c: The byte to fill the area with 
     53         * @count: The size of the area. 
     54         * 
     55         * Do not use memset() to access IO space, use memset_io() instead. 
     56         */ 
     57        INLINE static void* set_memory(void* dest, int value, size_t count) 
     58        { 
     59                char *xs = (char *)dest; 
     60                while (count--) 
     61                        *xs++ = value; 
     62                return dest; 
     63        } 
     64 
     65        /** 
    4966         * memcpy - Copy one area of memory to another 
    5067         * @dest: Where to copy to 
     
    5572         * or memcpy_fromio() instead. 
    5673         */ 
    57         inline static void* copyMemory(void* dest, const void* src, size_t count) 
     74        INLINE static void* copy_memory(void* dest, const void* src, size_t count) 
    5875        { 
    5976                char *tmp = (char *)dest; 
     
    7390         * Unlike memcpy(), memmove() copes with overlapping areas. 
    7491         */ 
    75         inline static void* moveMemory(void* dest, const void* src, size_t count) 
     92        INLINE static void* move_memory(void* dest, const void* src, size_t count) 
    7693        { 
    7794                char *tmp; 
     
    98115         * up to n stack frames. 
    99116         */ 
    100         void printBacktrace(Address basePointer = 0, int n = 0); 
     117        void print_backtrace(address_t base_pointer = 0, int n = 0); 
    101118 
    102119        /** 
    103120         * Prints first n words from the stack 
    104121         */ 
    105         void printStacktrace(unsigned int n = 64); 
     122        void print_stacktrace(unsigned int n = 64); 
    106123 
    107124private: 
    108         void relocatePlacementAddress(); 
     125        void relocate_placement_address(); 
    109126}; 
    110127 
  • vesper/src/arch/x86/MemoryManager-arch.h

    r84 r90  
    3535 
    3636        // Retrieval 
    37         Address frame()   {return pg.base << 12;} 
     37        address_t frame()   {return pg.base << 12;} 
    3838 
    3939        // Modification 
     
    4343        void setAccessed(bool b) { pg.accessed  = b ? 1 : 0; } 
    4444        void setDirty(bool b)    { pg.dirty     = b ? 1 : 0; } 
    45         void setFrame(Address f) { pg.base      = (f >> 12); } 
     45        void setFrame(address_t f) { pg.base      = (f >> 12); } 
    4646 
    4747private: 
     
    108108        } 
    109109 
    110         PageTable *clone(Address *phys) 
     110        PageTable *clone(address_t *phys) 
    111111        { 
    112112                PageTable *table = new(true, phys) PageTable(); 
     
    144144                        tablesPhysical[i] = 0; 
    145145                } 
    146                 physicalAddr = (Address)tablesPhysical; 
     146                physicalAddr = (address_t)tablesPhysical; 
    147147        } 
    148148 
     
    153153        } 
    154154 
    155         Address getPhysical() 
     155        address_t getPhysical() 
    156156        { 
    157157                return physicalAddr; 
    158158        } 
    159159 
    160         Page *getPage(Address addr, bool make = true) 
     160        Page *getPage(address_t addr, bool make = true) 
    161161        { 
    162162                addr /= PAGE_SIZE; 
     
    168168                else if(make) 
    169169                { 
    170                         Address tmp; 
     170                        address_t tmp; 
    171171                        tables[tableIdx] = new(true/*page aligned*/, &tmp/*give phys. addr */) PageTable(); 
    172172                        tablesPhysical[tableIdx] = tmp | 0x7; // PRESENT, RW, US 
     
    185185        PageDirectory *clone() 
    186186        { 
    187                 Address phys; 
     187                address_t phys; 
    188188                PageDirectory *dir = new(true, &phys) PageDirectory(); 
    189189 
    190190                // Get the offset of tablesPhysical from the start of 
    191191                // the PageDirectory object. 
    192                 uint32_t offset = (Address)dir->tablesPhysical - (Address)dir; 
     192                uint32_t offset = (address_t)dir->tablesPhysical - (address_t)dir; 
    193193 
    194194                // Then the physical address of dir->tablesPhysical is 
     
    209209                        { 
    210210                                // copy the table. 
    211                                 Address phys; 
     211                                address_t phys; 
    212212                                dir->tables[i] = tables[i]->clone(&phys); 
    213213                                dir->tablesPhysical[i] = phys | 0x07; 
     
    260260                location, for loading into the CR3 register. 
    261261        **/ 
    262         Address tablesPhysical[1024]; 
     262        address_t tablesPhysical[1024]; 
    263263 
    264264        /** 
    265265                The physical address of tablesPhysical. 
    266266        **/ 
    267         Address physicalAddr; 
     267        address_t physicalAddr; 
    268268}; 
    269269 
  • vesper/src/boot/Multiboot.cpp

    r84 r90  
    99#include "ELF.h" 
    1010 
    11 Multiboot::Multiboot(MultibootHeader *h) 
     11multiboot_t::multiboot_t(multiboot_header_t *h) 
    1212{ 
    1313        header = h; 
     
    1717 
    1818        // try and find the symtab/strtab 
    19         if (isElf()) 
     19        if (is_elf()) 
    2020        { 
    2121                Elf32SectionHeader *shstrtab = (Elf32SectionHeader *)(header->addr + header->shndx * header->size); 
     
    3232                        { 
    3333                                char *c = (char *)shstrtab->sh_addr + sh->sh_name; 
    34                                 if (Kernel::strEquals(c, ".strtab")) 
     34                                if (kernel::str_equals(c, ".strtab")) 
    3535                                { 
    3636                                        strtab = sh; 
     
    4141} 
    4242 
    43 Multiboot::~Multiboot() 
    44 { 
    45 } 
  • vesper/src/boot/Multiboot.h

    r84 r90  
    2727 * Boot information passed in by multiboot loader. 
    2828 */ 
    29 struct MultibootHeader 
     29struct multiboot_header_t 
    3030{ 
    3131        uint32_t flags; 
     
    7070 * Defines an interface to the multiboot header 
    7171 */ 
    72 class Multiboo
     72class multiboot_
    7373{ 
    74        public: 
    75                Multiboot() : header(NULL) {} 
    76                Multiboot(MultibootHeader *h); 
     74public: 
     75        multiboot_t() : header(NULL) {} 
     76        multiboot_t(multiboot_header_t *h); 
    7777 
    78                 ~Multiboot(); 
     78        INLINE uint32_t lower_mem()   { return header->mem_lower; } 
     79        INLINE uint32_t upper_mem()   { return header->mem_upper; } 
     80        INLINE uint32_t flags()       { return header->flags; } 
    7981 
    80                 inline uint32_t lowerMem()   { return header->mem_lower; } 
    81                 inline uint32_t upperMem()   { return header->mem_upper; } 
    82                 inline uint32_t flags()      { return header->flags; } 
     82        INLINE address_t mod_start() 
     83        { 
     84                if (header->mods_count) 
     85                { 
     86                        return *((uint32_t*)(header->mods_addr)); 
     87                } 
     88                else 
     89                { 
     90                        return 0; 
     91                } 
     92        } 
     93        INLINE address_t mod_end() 
     94        { 
     95                if (header->mods_count) 
     96                { 
     97                        return *(uint32_t*)((header->mods_addr)+4); 
     98                } 
     99                else 
     100                { 
     101                        return 0; 
     102                } 
     103        } 
    83104 
    84                 inline uint32_t modStart() 
     105        INLINE uint32_t elf_num_headers()      { return header->num; } 
     106        INLINE uint32_t elf_header_size()      { return header->size; } 
     107        INLINE uint32_t elf_header_addr()      { return header->addr; } 
     108        INLINE uint32_t elf_strtab_index()     { return header->shndx; } 
     109        INLINE address_t strtab_end() 
     110        { 
     111                if (strtab) 
    85112                { 
    86                         if (header->mods_count) 
    87                         { 
    88                                 return *((uint32_t*)(header->mods_addr)); 
    89                         } 
    90                         else 
    91                         { 
    92                                 return 0; 
    93                         } 
     113                        return (address_t)strtab->sh_addr + strtab->sh_size; 
    94114                } 
    95                 inline uint32_t modEnd() 
     115                else 
    96116                { 
    97                         if (header->mods_count) 
    98                         { 
    99                                 return *(uint32_t*)((header->mods_addr)+4); 
    100                         } 
    101                         else 
    102                         { 
    103                                 return 0; 
    104                         } 
     117                        return 0; 
    105118                } 
     119        } 
     120        INLINE address_t symtab_end() 
     121        { 
     122                if (symtab) 
     123                { 
     124                        return (address_t)symtab->sh_addr + symtab->sh_size; 
     125                } 
     126                else 
     127                { 
     128                        return 0; 
     129                } 
     130        } 
     131        INLINE Elf32SectionHeader *symtab_start() 
     132        { 
     133                if (symtab) 
     134                { 
     135                        return (Elf32SectionHeader *)symtab; 
     136                } 
     137                else 
     138                { 
     139                        return 0; 
     140                } 
     141        } 
     142        INLINE Elf32SectionHeader *strtab_start() 
     143        { 
     144                if (strtab) 
     145                { 
     146                        return (Elf32SectionHeader *)strtab; 
     147                } 
     148                else 
     149                { 
     150                        return 0; 
     151                } 
     152        } 
    106153 
    107                 inline uint32_t elfNumHeaders()      { return header->num; } 
    108                 inline uint32_t elfHeaderSize()      { return header->size; } 
    109                 inline uint32_t elfHeaderAddr()      { return header->addr; } 
    110                 inline uint32_t elfStrtabIndex()     { return header->shndx; } 
    111                 inline Address strtabEnd() 
    112                 { 
    113                         if (strtab) 
    114                         { 
    115                                 return (Address)strtab->sh_addr + strtab->sh_size; 
    116                         } 
    117                         else 
    118                         { 
    119                                 return 0; 
    120                         } 
    121                 } 
    122                 inline Address symtabEnd() 
    123                 { 
    124                         if (symtab) 
    125                         { 
    126                                 return (Address)symtab->sh_addr + symtab->sh_size; 
    127                         } 
    128                         else 
    129                         { 
    130                                 return 0; 
    131                         } 
    132                 } 
    133                 inline Elf32SectionHeader *symtabStart() 
    134                 { 
    135                         if (symtab) 
    136                         { 
    137                                 return (Elf32SectionHeader *)symtab; 
    138                         } 
    139                         else 
    140                         { 
    141                                 return 0; 
    142                         } 
    143                 } 
    144                 inline Elf32SectionHeader *strtabStart() 
    145                 { 
    146                         if (strtab) 
    147                         { 
    148                                 return (Elf32SectionHeader *)strtab; 
    149                         } 
    150                         else 
    151                         { 
    152                                 return 0; 
    153                         } 
    154                 } 
     154        INLINE bool is_elf() { return header->flags & MULTIBOOT_FLAG_ELF; } 
     155        INLINE bool has_mem_info() { return header->flags & MULTIBOOT_FLAG_MEM; } 
    155156 
    156                 bool isElf() { return header->flags & MULTIBOOT_FLAG_ELF; } 
    157                 bool hasMemInfo() { return header->flags & MULTIBOOT_FLAG_MEM; } 
    158  
    159         private: 
    160                 MultibootHeader *header; 
    161                 Elf32SectionHeader *strtab; 
    162                 Elf32SectionHeader *symtab; 
     157private: 
     158        multiboot_header_t *header; 
     159        Elf32SectionHeader *strtab; 
     160        Elf32SectionHeader *symtab; 
    163161}; 
    164162 
  • vesper/src/lib/Atomic.h

    r84 r90  
    77#pragma once 
    88 
    9 class Atomic 
     9class atomic_t 
    1010{ 
    1111public: 
    12         static Address exchange(Address *lock, Address newVal); 
     12        static address_t exchange(address_t *lock, address_t new_val); 
    1313}; 
  • vesper/src/lib/DefaultConsole.cpp

    r84 r90  
    66// 
    77#include "DefaultConsole.h" 
     8#include "Kernel.h" 
    89#include "common.h" 
    910 
    10 const char DefaultConsole::EOL = 10; 
     11const char default_console::eol = 10; 
    1112 
    1213// Screen dimensions (for default 80x25 console) 
     
    1415#define LINE_COUNT 25 
    1516 
    16 DefaultConsole& DefaultConsole::self() 
     17default_console& default_console::self() 
    1718{ 
    18         static DefaultConsole console; 
     19        static default_console console; 
    1920        return console; 
    2021} 
    2122 
    22 DefaultConsole::DefaultConsole() 
     23default_console::default_console() 
    2324{ 
    2425   videoram = (unsigned char *) 0xb8000; 
     
    2728} 
    2829 
    29 void DefaultConsole::clear() 
     30void default_console::clear() 
    3031{ 
    31         for(unsigned int i = 0; i < LINE_PITCH*LINE_COUNT; i++) 
    32                 videoram[i] = 0; 
     32        kernel::set_memory(videoram, 0, LINE_PITCH*LINE_COUNT); 
    3333        locate(0,0); 
    3434        attr = 0x07; 
    3535} 
    3636 
    37 void DefaultConsole::set_color(Color col) 
     37void default_console::set_color(Color col) 
    3838{ 
    3939        attr = (attr & 0xF0) | (col & 0x0F); 
    4040} 
    4141 
    42 void DefaultConsole::set_background(Color col) 
     42void default_console::set_background(Color col) 
    4343{ 
    4444        attr = (attr & 0x0F) | ((col & 0x0F) << 8); 
    4545} 
    4646 
    47 void DefaultConsole::set_attr(Color fore, Color back) 
     47void default_console::set_attr(Color fore, Color back) 
    4848{ 
    4949        set_color(fore); 
     
    5151} 
    5252 
    53 void DefaultConsole::locate(int row, int col) 
     53void default_console::locate(int row, int col) 
    5454{ 
    5555        *cursor = (row * LINE_PITCH) + (col * 2); 
    5656        // Set VGA hardware cursor 
    57         outb(0x3D4, 14); // Tell the VGA board we are setting the high cursor byte. 
    58         outb(0x3D5, (*cursor) >> 8); // Send the high cursor byte. 
    59         outb(0x3D4, 15); // Tell the VGA board we are setting the low cursor byte. 
    60         outb(0x3D5, *cursor);      // Send the low cursor byte. 
     57        outb(0x3d4, 14); // Tell the VGA board we are setting the high cursor byte. 
     58        outb(0x3d5, (*cursor) >> 8); // Send the high cursor byte. 
     59        outb(0x3d4, 15); // Tell the VGA board we are setting the low cursor byte. 
     60        outb(0x3d5, (*cursor) & 0xff);      // Send the low cursor byte. 
    6161} 
    6262 
    63 void DefaultConsole::scroll_up() 
     63void default_console::scroll_up() 
    6464{ 
    65         for (int i = 0; i < LINE_PITCH*(LINE_COUNT-1); i++) 
    66                 videoram[i] = videoram[i+LINE_PITCH]; 
    67  
    68         for (int i = LINE_PITCH*(LINE_COUNT-1); i < LINE_PITCH*LINE_COUNT; i++) 
    69                 videoram[i] = 0; 
     65        kernel::copy_memory(videoram, videoram+LINE_PITCH, LINE_PITCH*(LINE_COUNT-1)); 
     66        kernel::set_memory(videoram+LINE_PITCH*(LINE_COUNT-1), 0, LINE_PITCH); 
    7067} 
    7168 
    72 void DefaultConsole::newline() 
     69void default_console::newline() 
    7370{ 
    74         print_char(EOL); 
     71        print_char(eol); 
    7572} 
    7673 
    77 void DefaultConsole::print_int(int n) 
     74void default_console::print_int(int n) 
    7875{ 
    7976        if (n == 0) 
     
    103100} 
    104101 
    105 void DefaultConsole::print_byte(unsigned char n) 
     102void default_console::print_byte(unsigned char n) 
    106103{ 
    107         const char hexdigits[17] = "0123456789ABCDEF"; // 16+1 for terminating null 
     104        const char hexdigits[17] = "0123456789abcdef"; // 16+1 for terminating null 
    108105        char c = hexdigits[(n >> 4) & 0xF]; 
    109106        print_char(c); 
     
    112109} 
    113110 
    114 void DefaultConsole::print_hex(unsigned int n) 
     111void default_console::print_hex(unsigned int n) 
    115112{ 
     113        print("0x"); 
    116114        for(int i = 4; i > 0; i--) 
    117115                print_byte((n >> (i-1)*8) & 0xFF); 
    118116} 
    119117 
    120 void DefaultConsole::print_char(char ch) 
     118void default_console::print_char(char ch) 
    121119{ 
    122         if (ch == EOL
     120        if (ch == eol
    123121        { 
    124122                // move cursor to new line and align on line start 
     
    140138} 
    141139 
    142 void DefaultConsole::print(const char *str, ...) 
     140void default_console::print(const char *str, ...) 
    143141{ 
    144142        #define BUFSIZE 512 
     
    155153} 
    156154 
    157 void DefaultConsole::wait_ack() 
     155void default_console::wait_ack() 
    158156{ 
    159157        uint8_t keycode; 
     
    166164 
    167165                keycode = inb(0x60); 
    168         } while(keycode != 0x1C); // "make code" == enter 
     166        } while(keycode != 0x1c); // "make code" == enter 
    169167 
    170168        do { 
     
    173171 
    174172                keycode = inb(0x60); 
    175         } while(keycode != 0x9C); // "break code" == enter 
     173        } while(keycode != 0x9c); // "break code" == enter 
    176174 
    177175        if (!(irqmask & 0x02)) // if irq1 was unmasked previously, 
    178                 outb(0x21, inb(0x21) & 0xFD); // unmask it now without changing other flags 
     176                outb(0x21, inb(0x21) & 0xfd); // unmask it now without changing other flags 
    179177} 
    180178 
    181 void DefaultConsole::debug_log(const char *str, ...) 
     179void default_console::debug_log(const char *str, ...) 
    182180{ 
    183181        #define BUFSIZE 512 
     
    192190        set_attr(WHITE, BLACK); 
    193191        print(buffer); 
    194         print_char(EOL); 
     192        print_char(eol); 
    195193        attr = old_attr; 
    196194} 
  • vesper/src/lib/DefaultConsole.h

    r89 r90  
    99#include "Macros.h" 
    1010 
    11 #define kconsole DefaultConsole::self() 
    12 #define endl DefaultConsole::EOL 
     11#define kconsole default_console::self() 
     12#define endl default_console::eol 
    1313 
    1414enum Color { 
     
    3131}; 
    3232 
    33 class DefaultConsole 
     33class default_console 
    3434{ 
    3535public: 
    36         static const char EOL
     36        static const char eol
    3737 
    38         static DefaultConsole &self(); 
     38        static default_console& self(); 
    3939 
    4040        void set_color(Color col); 
     
    5757 
    5858private: 
    59         DefaultConsole(); 
     59        default_console(); 
    6060        unsigned char* videoram; 
    6161        unsigned int*  cursor; 
     
    6464 
    6565// Define stream io on console. 
    66 INLINE DefaultConsole& operator << (DefaultConsole& con, Color data) 
     66INLINE default_console& operator << (default_console& con, Color data) 
    6767{ 
    6868        con.set_color(data); 
     
    7070} 
    7171 
    72 INLINE DefaultConsole& operator << (DefaultConsole& con, const char* data) 
     72INLINE default_console& operator << (default_console& con, const char* data) 
    7373{ 
    7474        con.print(data); 
     
    7676} 
    7777 
    78 INLINE DefaultConsole& operator << (DefaultConsole& con, int data) 
     78INLINE default_console& operator << (default_console& con, int data) 
    7979{ 
    8080        con.print_int(data); 
     
    8282} 
    8383 
    84 INLINE DefaultConsole& operator << (DefaultConsole& con, unsigned int data) 
     84INLINE default_console& operator << (default_console& con, unsigned int data) 
    8585{ 
    8686        con.print_hex(data); 
     
    8888} 
    8989 
    90 INLINE DefaultConsol