Changeset ,90
- Timestamp:
- 10/22/2008 08:52:05 PM (3 months ago)
- branch-nick:
- bzr
- Files:
-
- vesper/src/ElfParser.cpp (modified) (1 diff)
- vesper/src/ElfParser.h (modified) (5 diffs)
- vesper/src/Globals.cpp (modified) (4 diffs)
- vesper/src/Globals.h (modified) (1 diff)
- vesper/src/Kernel.cpp (modified) (8 diffs)
- vesper/src/Kernel.h (modified) (8 diffs)
- vesper/src/arch/x86/MemoryManager-arch.h (modified) (9 diffs)
- vesper/src/boot/Multiboot.cpp (modified) (4 diffs)
- vesper/src/boot/Multiboot.h (modified) (2 diffs)
- vesper/src/floppy.img (modified) (previous)
- vesper/src/lib/Atomic.h (modified) (1 diff)
- vesper/src/lib/DefaultConsole.cpp (modified) (11 diffs)
- vesper/src/lib/DefaultConsole.h (modified) (9 diffs)
- vesper/src/lib/Lockable.h (modified) (2 diffs)
- vesper/src/lib/Registers.h (modified) (1 diff)
- vesper/src/lib/Types.h (modified) (1 diff)
- vesper/src/lib/string.c (modified) (3 diffs)
- vesper/src/lib/string.h (modified) (1 diff)
- vesper/src/memory/Heap.cpp (modified) (2 diffs)
- vesper/src/memory/Heap.h (modified) (2 diffs)
- vesper/src/memory/MemoryManager.cpp (modified) (10 diffs)
- vesper/src/memory/MemoryManager.h (modified) (8 diffs)
- vesper/src/pd/InterruptDescriptorTable.cpp (modified) (3 diffs)
- vesper/src/pd/gdt.cpp (modified) (3 diffs)
- vesper/src/schedule/InterruptServiceRoutine.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
vesper/src/ElfParser.cpp
r84 r90 32 32 } 33 33 34 char *ElfParser::findSymbol(Address addr, Address*symbolStart)34 char* ElfParser::findSymbol(address_t addr, address_t *symbolStart) 35 35 { 36 Addressmax = 0;36 address_t max = 0; 37 37 Elf32Symbol *fallbackSymbol = 0; 38 38 for (unsigned int i = 0; i < symbolTable->sh_size / symbolTable->sh_entsize; i++) vesper/src/ElfParser.h
r84 r90 41 41 Returns the address of the last byte to be loaded in. 42 42 **/ 43 AddressgetLastAddress();43 address_t getLastAddress(); 44 44 45 45 /** … … 52 52 of that symbol in startAddr if startAddr != NULL. 53 53 **/ 54 char *findSymbol(Address addr, Address *symbolStart=NULL);54 char* findSymbol(address_t addr, address_t *symbolStart = NULL); 55 55 56 56 /** … … 59 59 using the hashtable sections in ELF. 60 60 **/ 61 Address findSymbol(char *str);61 address_t findSymbol(char* str); 62 62 63 63 /** … … 65 65 relocation symbol table. 66 66 **/ 67 Address findDynamicSymbolLocation(Addresso);67 address_t findDynamicSymbolLocation(address_t o); 68 68 69 69 /** … … 71 71 the symbol at offset o in the relocation symbol table. 72 72 **/ 73 char *findDynamicSymbolName( Addresso);73 char *findDynamicSymbolName(address_t o); 74 74 75 75 /** 76 76 Gets the address of the global offset table. 77 77 **/ 78 AddressgetGlobalOffsetTable();78 address_t getGlobalOffsetTable(); 79 79 80 80 /** 81 81 Returns the entry point of the executable. 82 82 **/ 83 AddressgetEntryPoint()83 address_t getEntryPoint() 84 84 { 85 return ( Address)header->e_entry;85 return (address_t)header->e_entry; 86 86 } 87 87 vesper/src/Globals.cpp
r84 r90 15 15 16 16 /* Global objects FIXME: use singletons instead? */ 17 Kernel kernel;18 Multiboot multiboot;17 class kernel kernel; 18 multiboot_t multiboot; 19 19 ElfParser kernelElfParser; 20 20 MemoryManager memoryManager; … … 22 22 23 23 /* This entry point is called from loader */ 24 void kernel_entry( MultibootHeader *multibootHeader)24 void kernel_entry(multiboot_header_t *multiboot_header) 25 25 { 26 26 kconsole.clear(); 27 multiboot = Multiboot(multibootHeader);27 multiboot = multiboot_t(multiboot_header); 28 28 kernel.run(); /* does not return */ 29 29 } … … 113 113 kconsole.set_attr(RED, YELLOW); 114 114 kconsole.print("PANIC (%s) at %s:%d\n", message, file, line); 115 kernel.print Backtrace();115 kernel.print_backtrace(); 116 116 117 117 // Halt by going into an infinite loop. … … 126 126 kconsole.set_attr(WHITE, RED); 127 127 kconsole.print("ASSERTION-FAILED(%s) at %s:%d\n", desc, file, line); 128 kernel.print Backtrace();128 kernel.print_backtrace(); 129 129 130 130 // Halt by going into an infinite loop. vesper/src/Globals.h
r84 r90 11 11 #include "string.h" 12 12 13 extern class Kernel kernel;14 extern class Multiboot multiboot;13 extern class kernel kernel; 14 extern class multiboot_t multiboot; 15 15 extern class ElfParser kernelElfParser; 16 16 extern class MemoryManager memoryManager; 17 17 extern class InterruptDescriptorTable interruptsTable; 18 18 19 extern "C" void kernel_entry(class MultibootHeader*mh) NORETURN;19 extern "C" void kernel_entry(class multiboot_header_t *mh) NORETURN; 20 20 21 21 void *operator new(size_t size); vesper/src/Kernel.cpp
r84 r90 20 20 PageFaultHandler pageFaultHandler; 21 21 22 void Kernel::run()22 void kernel::run() 23 23 { 24 if (!multiboot.is Elf())24 if (!multiboot.is_elf()) 25 25 PANIC("ELF information is missing in kernel!"); 26 26 27 27 // Make sure we aren't overwriting anything by writing at placementAddress. 28 relocate PlacementAddress();28 relocate_placement_address(); 29 29 30 kernelElfParser.loadKernel(multiboot.symtab Start(), multiboot.strtabStart());30 kernelElfParser.loadKernel(multiboot.symtab_start(), multiboot.strtab_start()); 31 31 32 32 GlobalDescriptorTable::init(); … … 35 35 interruptsTable.init(); 36 36 37 memoryManager.init(multiboot.upper Mem() * 1024);37 memoryManager.init(multiboot.upper_mem() * 1024); 38 38 memoryManager.remapStack(); 39 39 kconsole.debug_log("Remapped stack and ready to rock."); … … 41 41 Task::init(); 42 42 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. 43 45 44 46 // Load initrd and pass control to init component … … 47 49 } 48 50 49 void Kernel::relocatePlacementAddress()51 void kernel::relocate_placement_address() 50 52 { 51 AddressnewPlacementAddress = memoryManager.getPlacementAddress();52 if (multiboot.is Elf() && multiboot.symtabEnd() > newPlacementAddress)53 address_t newPlacementAddress = memoryManager.getPlacementAddress(); 54 if (multiboot.is_elf() && multiboot.symtab_end() > newPlacementAddress) 53 55 { 54 newPlacementAddress = multiboot.symtab End();56 newPlacementAddress = multiboot.symtab_end(); 55 57 } 56 if (multiboot.is Elf() && multiboot.strtabEnd() > newPlacementAddress)58 if (multiboot.is_elf() && multiboot.strtab_end() > newPlacementAddress) 57 59 { 58 newPlacementAddress = multiboot.strtab End();60 newPlacementAddress = multiboot.strtab_end(); 59 61 } 60 if (multiboot.mod Start() > newPlacementAddress)62 if (multiboot.mod_start() > newPlacementAddress) 61 63 { 62 newPlacementAddress = multiboot.mod End();64 newPlacementAddress = multiboot.mod_end(); 63 65 } 64 66 memoryManager.setPlacementAddress(newPlacementAddress); 65 67 } 66 68 67 void Kernel::dumpMemory(Addressstart, size_t size)69 void kernel::dump_memory(address_t start, size_t size) 68 70 { 69 71 char *ptr = (char *)start; … … 99 101 { 100 102 char c = *(ptr+i); 101 if (c == kconsole. EOL)103 if (c == kconsole.eol) 102 104 c = ' '; 103 105 kconsole.print_char(c); … … 109 111 } 110 112 111 Address Kernel::backtrace(Address basePointer, Address& returnAddress)113 address_t kernel::backtrace(address_t basePointer, address_t& returnAddress) 112 114 { 113 115 // We take a stack base pointer (in basePointer), return what it's pointing at 114 116 // 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))); 117 119 return nextBase; 118 120 } 119 121 120 Address Kernel::backtrace(int n)122 address_t kernel::backtrace(int n) 121 123 { 122 AddressbasePointer = readBasePointer();123 Addressebp = basePointer;124 Addresseip = 1;124 address_t basePointer = readBasePointer(); 125 address_t ebp = basePointer; 126 address_t eip = 1; 125 127 int i = 0; 126 128 while (ebp && eip /*&& eip < 0x87000000*/) … … 136 138 } 137 139 138 void Kernel::printBacktrace(AddressbasePointer, int n)140 void kernel::print_backtrace(address_t basePointer, int n) 139 141 { 140 Addresseip = 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. 141 143 if (basePointer == NULL) 142 144 { 143 145 basePointer = readBasePointer(); 144 146 } 145 Addressebp = basePointer;147 address_t ebp = basePointer; 146 148 kconsole.set_color(GREEN); 147 149 kconsole.print("*** Backtrace *** Tracing %d stack frames:\n", n); … … 160 162 } 161 163 162 void Kernel::printStacktrace(unsigned int n)164 void kernel::print_stacktrace(unsigned int n) 163 165 { 164 Addressesp = readStackPointer();165 AddressespBase = esp;166 address_t esp = readStackPointer(); 167 address_t espBase = esp; 166 168 kconsole.set_color(GREEN); 167 169 kconsole.print("<ESP=%08x>\n", esp); 168 170 for (unsigned int i = 0; i < n; i++) 169 171 { 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); 172 174 } 173 175 } vesper/src/Kernel.h
r84 r90 10 10 #include "Macros.h" 11 11 12 class Kernel12 class kernel 13 13 { 14 14 public: … … 21 21 * Dump @c size bytes from a memory region starting at virtual address @c start. 22 22 */ 23 static void dump Memory(Addressstart, size_t size);23 static void dump_memory(address_t start, size_t size); 24 24 25 25 /** … … 27 27 * pointer and also return the instruction pointer it returned to. 28 28 */ 29 static Address backtrace(Address basePointer, Address& returnAddress);29 static address_t backtrace(address_t base_pointer, address_t& return_address); 30 30 31 31 /** … … 33 33 * return address found there. 34 34 */ 35 static Addressbacktrace(int n);35 static address_t backtrace(int n); 36 36 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) 38 39 { 39 40 char *left = (char *)in1; … … 47 48 48 49 /** 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 /** 49 66 * memcpy - Copy one area of memory to another 50 67 * @dest: Where to copy to … … 55 72 * or memcpy_fromio() instead. 56 73 */ 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) 58 75 { 59 76 char *tmp = (char *)dest; … … 73 90 * Unlike memcpy(), memmove() copes with overlapping areas. 74 91 */ 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) 76 93 { 77 94 char *tmp; … … 98 115 * up to n stack frames. 99 116 */ 100 void print Backtrace(Address basePointer = 0, int n = 0);117 void print_backtrace(address_t base_pointer = 0, int n = 0); 101 118 102 119 /** 103 120 * Prints first n words from the stack 104 121 */ 105 void print Stacktrace(unsigned int n = 64);122 void print_stacktrace(unsigned int n = 64); 106 123 107 124 private: 108 void relocate PlacementAddress();125 void relocate_placement_address(); 109 126 }; 110 127 vesper/src/arch/x86/MemoryManager-arch.h
r84 r90 35 35 36 36 // Retrieval 37 Addressframe() {return pg.base << 12;}37 address_t frame() {return pg.base << 12;} 38 38 39 39 // Modification … … 43 43 void setAccessed(bool b) { pg.accessed = b ? 1 : 0; } 44 44 void setDirty(bool b) { pg.dirty = b ? 1 : 0; } 45 void setFrame( Addressf) { pg.base = (f >> 12); }45 void setFrame(address_t f) { pg.base = (f >> 12); } 46 46 47 47 private: … … 108 108 } 109 109 110 PageTable *clone( Address*phys)110 PageTable *clone(address_t *phys) 111 111 { 112 112 PageTable *table = new(true, phys) PageTable(); … … 144 144 tablesPhysical[i] = 0; 145 145 } 146 physicalAddr = ( Address)tablesPhysical;146 physicalAddr = (address_t)tablesPhysical; 147 147 } 148 148 … … 153 153 } 154 154 155 AddressgetPhysical()155 address_t getPhysical() 156 156 { 157 157 return physicalAddr; 158 158 } 159 159 160 Page *getPage( Addressaddr, bool make = true)160 Page *getPage(address_t addr, bool make = true) 161 161 { 162 162 addr /= PAGE_SIZE; … … 168 168 else if(make) 169 169 { 170 Addresstmp;170 address_t tmp; 171 171 tables[tableIdx] = new(true/*page aligned*/, &tmp/*give phys. addr */) PageTable(); 172 172 tablesPhysical[tableIdx] = tmp | 0x7; // PRESENT, RW, US … … 185 185 PageDirectory *clone() 186 186 { 187 Addressphys;187 address_t phys; 188 188 PageDirectory *dir = new(true, &phys) PageDirectory(); 189 189 190 190 // Get the offset of tablesPhysical from the start of 191 191 // the PageDirectory object. 192 uint32_t offset = ( Address)dir->tablesPhysical - (Address)dir;192 uint32_t offset = (address_t)dir->tablesPhysical - (address_t)dir; 193 193 194 194 // Then the physical address of dir->tablesPhysical is … … 209 209 { 210 210 // copy the table. 211 Addressphys;211 address_t phys; 212 212 dir->tables[i] = tables[i]->clone(&phys); 213 213 dir->tablesPhysical[i] = phys | 0x07; … … 260 260 location, for loading into the CR3 register. 261 261 **/ 262 AddresstablesPhysical[1024];262 address_t tablesPhysical[1024]; 263 263 264 264 /** 265 265 The physical address of tablesPhysical. 266 266 **/ 267 AddressphysicalAddr;267 address_t physicalAddr; 268 268 }; 269 269 vesper/src/boot/Multiboot.cpp
r84 r90 9 9 #include "ELF.h" 10 10 11 Multiboot::Multiboot(MultibootHeader*h)11 multiboot_t::multiboot_t(multiboot_header_t *h) 12 12 { 13 13 header = h; … … 17 17 18 18 // try and find the symtab/strtab 19 if (is Elf())19 if (is_elf()) 20 20 { 21 21 Elf32SectionHeader *shstrtab = (Elf32SectionHeader *)(header->addr + header->shndx * header->size); … … 32 32 { 33 33 char *c = (char *)shstrtab->sh_addr + sh->sh_name; 34 if ( Kernel::strEquals(c, ".strtab"))34 if (kernel::str_equals(c, ".strtab")) 35 35 { 36 36 strtab = sh; … … 41 41 } 42 42 43 Multiboot::~Multiboot()44 {45 }vesper/src/boot/Multiboot.h
r84 r90 27 27 * Boot information passed in by multiboot loader. 28 28 */ 29 struct MultibootHeader29 struct multiboot_header_t 30 30 { 31 31 uint32_t flags; … … 70 70 * Defines an interface to the multiboot header 71 71 */ 72 class Multiboot72 class multiboot_t 73 73 { 74 public:75 Multiboot() : header(NULL) {}76 Multiboot(MultibootHeader*h);74 public: 75 multiboot_t() : header(NULL) {} 76 multiboot_t(multiboot_header_t *h); 77 77 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; } 79 81 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 } 83 104 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) 85 112 { 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; 94 114 } 95 inline uint32_t modEnd()115 else 96 116 { 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; 105 118 } 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 } 106 153 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; } 155 156 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; 157 private: 158 multiboot_header_t *header; 159 Elf32SectionHeader *strtab; 160 Elf32SectionHeader *symtab; 163 161 }; 164 162 vesper/src/lib/Atomic.h
r84 r90 7 7 #pragma once 8 8 9 class Atomic9 class atomic_t 10 10 { 11 11 public: 12 static Address exchange(Address *lock, Address newVal);12 static address_t exchange(address_t *lock, address_t new_val); 13 13 }; vesper/src/lib/DefaultConsole.cpp
r84 r90 6 6 // 7 7 #include "DefaultConsole.h" 8 #include "Kernel.h" 8 9 #include "common.h" 9 10 10 const char DefaultConsole::EOL= 10;11 const char default_console::eol = 10; 11 12 12 13 // Screen dimensions (for default 80x25 console) … … 14 15 #define LINE_COUNT 25 15 16 16 DefaultConsole& DefaultConsole::self()17 default_console& default_console::self() 17 18 { 18 static DefaultConsole console;19 static default_console console; 19 20 return console; 20 21 } 21 22 22 DefaultConsole::DefaultConsole()23 default_console::default_console() 23 24 { 24 25 videoram = (unsigned char *) 0xb8000; … … 27 28 } 28 29 29 void DefaultConsole::clear()30 void default_console::clear() 30 31 { 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); 33 33 locate(0,0); 34 34 attr = 0x07; 35 35 } 36 36 37 void DefaultConsole::set_color(Color col)37 void default_console::set_color(Color col) 38 38 { 39 39 attr = (attr & 0xF0) | (col & 0x0F); 40 40 } 41 41 42 void DefaultConsole::set_background(Color col)42 void default_console::set_background(Color col) 43 43 { 44 44 attr = (attr & 0x0F) | ((col & 0x0F) << 8); 45 45 } 46 46 47 void DefaultConsole::set_attr(Color fore, Color back)47 void default_console::set_attr(Color fore, Color back) 48 48 { 49 49 set_color(fore); … … 51 51 } 52 52 53 void DefaultConsole::locate(int row, int col)53 void default_console::locate(int row, int col) 54 54 { 55 55 *cursor = (row * LINE_PITCH) + (col * 2); 56 56 // Set VGA hardware cursor 57 outb(0x3 D4, 14); // Tell the VGA board we are setting the high cursor byte.58 outb(0x3 D5, (*cursor) >> 8); // Send the high cursor byte.59 outb(0x3 D4, 15); // Tell the VGA board we are setting the low cursor byte.60 outb(0x3 D5, *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. 61 61 } 62 62 63 void DefaultConsole::scroll_up()63 void default_console::scroll_up() 64 64 { 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); 70 67 } 71 68 72 void DefaultConsole::newline()69 void default_console::newline() 73 70 { 74 print_char( EOL);71 print_char(eol); 75 72 } 76 73 77 void DefaultConsole::print_int(int n)74 void default_console::print_int(int n) 78 75 { 79 76 if (n == 0) … … 103 100 } 104 101 105 void DefaultConsole::print_byte(unsigned char n)102 void default_console::print_byte(unsigned char n) 106 103 { 107 const char hexdigits[17] = "0123456789 ABCDEF"; // 16+1 for terminating null104 const char hexdigits[17] = "0123456789abcdef"; // 16+1 for terminating null 108 105 char c = hexdigits[(n >> 4) & 0xF]; 109 106 print_char(c); … … 112 109 } 113 110 114 void DefaultConsole::print_hex(unsigned int n)111 void default_console::print_hex(unsigned int n) 115 112 { 113 print("0x"); 116 114 for(int i = 4; i > 0; i--) 117 115 print_byte((n >> (i-1)*8) & 0xFF); 118 116 } 119 117 120 void DefaultConsole::print_char(char ch)118 void default_console::print_char(char ch) 121 119 { 122 if (ch == EOL)120 if (ch == eol) 123 121 { 124 122 // move cursor to new line and align on line start … … 140 138 } 141 139 142 void DefaultConsole::print(const char *str, ...)140 void default_console::print(const char *str, ...) 143 141 { 144 142 #define BUFSIZE 512 … … 155 153 } 156 154 157 void DefaultConsole::wait_ack()155 void default_console::wait_ack() 158 156 { 159 157 uint8_t keycode; … … 166 164 167 165 keycode = inb(0x60); 168 } while(keycode != 0x1 C); // "make code" == enter166 } while(keycode != 0x1c); // "make code" == enter 169 167 170 168 do { … … 173 171 174 172 keycode = inb(0x60); 175 } while(keycode != 0x9 C); // "break code" == enter173 } while(keycode != 0x9c); // "break code" == enter 176 174 177 175 if (!(irqmask & 0x02)) // if irq1 was unmasked previously, 178 outb(0x21, inb(0x21) & 0x FD); // unmask it now without changing other flags176 outb(0x21, inb(0x21) & 0xfd); // unmask it now without changing other flags 179 177 } 180 178 181 void DefaultConsole::debug_log(const char *str, ...)179 void default_console::debug_log(const char *str, ...) 182 180 { 183 181 #define BUFSIZE 512 … … 192 190 set_attr(WHITE, BLACK); 193 191 print(buffer); 194 print_char( EOL);192 print_char(eol); 195 193 attr = old_attr; 196 194 } vesper/src/lib/DefaultConsole.h
r89 r90 9 9 #include "Macros.h" 10 10 11 #define kconsole DefaultConsole::self()12 #define endl DefaultConsole::EOL11 #define kconsole default_console::self() 12 #define endl default_console::eol 13 13 14 14 enum Color { … … 31 31 }; 32 32 33 class DefaultConsole33 class default_console 34 34 { 35 35 public: 36 static const char EOL;36 static const char eol; 37 37 38 static DefaultConsole &self();38 static default_console& self(); 39 39 40 40 void set_color(Color col); … … 57 57 58 58 private: 59 DefaultConsole();59 default_console(); 60 60 unsigned char* videoram; 61 61 unsigned int* cursor; … … 64 64 65 65 // Define stream io on console. 66 INLINE DefaultConsole& operator << (DefaultConsole& con, Color data)66 INLINE default_console& operator << (default_console& con, Color data) 67 67 { 68 68 con.set_color(data); … … 70 70 } 71 71 72 INLINE DefaultConsole& operator << (DefaultConsole& con, const char* data)72 INLINE default_console& operator << (default_console& con, const char* data) 73 73 { 74 74 con.print(data); … … 76 76 } 77 77 78 INLINE DefaultConsole& operator << (DefaultConsole& con, int data)78 INLINE default_console& operator << (default_console& con, int data) 79 79 { 80 80 con.print_int(data); … … 82 82 } 83 83 84 INLINE DefaultConsole& operator << (DefaultConsole& con, unsigned int data)84 INLINE default_console& operator << (default_console& con, unsigned int data) 85 85 { 86 86 con.print_hex(data); … … 88 88 } 89 89 90 INLINE DefaultConsol
