diff --git a/sys/kernel/execve.c b/sys/kernel/execve.c index a4eaf14..06d520e 100644 --- a/sys/kernel/execve.c +++ b/sys/kernel/execve.c @@ -30,10 +30,14 @@ #include #include -int sys_execve( struct thread *td, struct sys_execve_args *args ) { - int ret = sys_exec( td, args->fname, args->argv, args->envp ); - td->td_retval[0] = ret; - if (ret != 0) - td->td_retval[1] = -8; - return (ret); +int sys_execve(struct thread *td, struct sys_execve_args *args) { + + int ret = sys_exec(td, args->fname, args->argv, args->envp); + + td->td_retval[0] = ret; + + if (ret != 0) + td->td_retval[1] = -8; + + return (ret); } diff --git a/sys/kernel/ld.c b/sys/kernel/ld.c index 3064fe3..390d92b 100644 --- a/sys/kernel/ld.c +++ b/sys/kernel/ld.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002-2018 The UbixOS Project. + * Copyright (c) 2002-2018, 2020 The UbixOS Project. * All rights reserved. * * This was developed by Christopher W. Olsen for the UbixOS Project. @@ -38,158 +38,161 @@ #include uint32_t ldEnable(const char *interp) { - int i = 0x0; - int x = 0x0; - int rel = 0x0; - int sym = 0x0; - char *newLoc = 0x0; - char *shStr = 0x0; - char *dynStr = 0x0; - uint32_t *reMap = 0x0; - fileDescriptor_t *ldFd = 0x0; - Elf_Ehdr *binaryHeader = 0x0; - Elf_Phdr *programHeader = 0x0; - Elf_Shdr *sectionHeader = 0x0; - Elf_Sym *relSymTab = 0x0; - Elf_Rel *elfRel = 0x0; - Elf_Rela *elfRela = 0x0; - Elf_Addr addr; + int i = 0x0; + int x = 0x0; + int rel = 0x0; + int sym = 0x0; + char *newLoc = 0x0; + char *shStr = 0x0; + char *dynStr = 0x0; + uint32_t *reMap = 0x0; + fileDescriptor_t *ldFd = 0x0; + Elf_Ehdr *binaryHeader = 0x0; + Elf_Phdr *programHeader = 0x0; + Elf_Shdr *sectionHeader = 0x0; + Elf_Sym *relSymTab = 0x0; + Elf_Rel *elfRel = 0x0; + Elf_Rela *elfRela = 0x0; + Elf_Addr addr; - /* Open our dynamic linker */ - ldFd = fopen(interp, "rb"); + /* Open our dynamic linker */ + ldFd = fopen(interp, "rb"); - if (ldFd == 0x0) { - ldFd = fopen("sys:/libexec/ld.so", "rb"); - if (ldFd == 0x0) - return(0x0); - } + if (ldFd == 0x0) { + ldFd = fopen("sys:/libexec/ld.so", "rb"); + if (ldFd == 0x0) + return (0x0); + } kern_fseek(ldFd, 0x0, 0x0); - binaryHeader = (Elf32_Ehdr *) kmalloc(sizeof(Elf32_Ehdr)); + binaryHeader = (Elf32_Ehdr*) kmalloc(sizeof(Elf32_Ehdr)); - assert(binaryHeader); - fread(binaryHeader, sizeof(Elf32_Ehdr), 1, ldFd); + assert(binaryHeader); + fread(binaryHeader, sizeof(Elf32_Ehdr), 1, ldFd); - programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum); - assert(programHeader); + programHeader = (Elf_Phdr*) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum); + assert(programHeader); kern_fseek(ldFd, binaryHeader->e_phoff, 0); - fread(programHeader, sizeof(Elf_Shdr), binaryHeader->e_phnum, ldFd); + fread(programHeader, sizeof(Elf_Shdr), binaryHeader->e_phnum, ldFd); - sectionHeader = (Elf_Shdr *) kmalloc(sizeof(Elf_Shdr) * binaryHeader->e_shnum); + sectionHeader = (Elf_Shdr*) kmalloc(sizeof(Elf_Shdr) * binaryHeader->e_shnum); - assert(sectionHeader); + assert(sectionHeader); kern_fseek(ldFd, binaryHeader->e_shoff, 0); - fread(sectionHeader, sizeof(Elf_Shdr), binaryHeader->e_shnum, ldFd); + fread(sectionHeader, sizeof(Elf_Shdr), binaryHeader->e_shnum, ldFd); - shStr = (char *) kmalloc(sectionHeader[binaryHeader->e_shstrndx].sh_size); + shStr = (char*) kmalloc(sectionHeader[binaryHeader->e_shstrndx].sh_size); kern_fseek(ldFd, sectionHeader[binaryHeader->e_shstrndx].sh_offset, 0); - fread(shStr, sectionHeader[binaryHeader->e_shstrndx].sh_size, 1, ldFd); + fread(shStr, sectionHeader[binaryHeader->e_shstrndx].sh_size, 1, ldFd); - for (i = 0x0; i < binaryHeader->e_phnum; i++) { - switch (programHeader[i].p_type) { - case PT_LOAD: - newLoc = (char *) programHeader[i].p_vaddr + LD_START; - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0; x < (programHeader[i].p_memsz); x += 0x1000) { - /* make r/w or ro */ - if ((vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x + LD_START), PAGE_DEFAULT, _current->id, 0)) == 0x0) - K_PANIC("vmmRemapPage: ld"); - memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x + LD_START), 0x0, 0x1000); - } - /* Now Load Section To Memory */ + for (i = 0x0; i < binaryHeader->e_phnum; i++) { + switch (programHeader[i].p_type) { + case PT_LOAD: + newLoc = (char*) programHeader[i].p_vaddr + LD_START; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0; x < (programHeader[i].p_memsz); x += 0x1000) { + /* make r/w or ro */ + if ((vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x + LD_START), PAGE_DEFAULT, _current->id, 0)) == 0x0) + K_PANIC("vmmRemapPage: ld"); + memset((void*) ((programHeader[i].p_vaddr & 0xFFFFF000) + x + LD_START), 0x0, 0x1000); + } + /* Now Load Section To Memory */ kern_fseek(ldFd, programHeader[i].p_offset, 0x0); - fread(newLoc, programHeader[i].p_filesz, 1, ldFd); + fread(newLoc, programHeader[i].p_filesz, 1, ldFd); - break; - case PT_DYNAMIC: - /* Now Load Section To Memory */ - //fseek(ldFd, programHeader[i].p_offset, 0x0); - //fread(newLoc, programHeader[i].p_filesz, 1, ldFd); - break; - case PT_GNU_STACK: - /* Tells us if the stack should be executable. Failsafe to executable - until we add checking */ - break; - default: - kprintf("Unhandled Header (kernel) : %08x\n", programHeader[i].p_type); - break; - } - } - - for (i = 0x0; i < binaryHeader->e_shnum; i++) { - switch (sectionHeader[i].sh_type) { - case SHT_STRTAB: - if (!strcmp((shStr + sectionHeader[i].sh_name), ".dynstr")) { - dynStr = (char *) kmalloc(sectionHeader[i].sh_size); - //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); - //fread(dynStr, sectionHeader[i].sh_size, 1, ldFd); - } - break; - case SHT_REL: - elfRel = (Elf_Rel *) kmalloc(sectionHeader[i].sh_size); - //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); - //fread(elfRel, sectionHeader[i].sh_size, 1, ldFd); - - for (x = 0x0; x < sectionHeader[i].sh_size / sizeof(Elf_Rel); x++) { - rel = ELF32_R_SYM(elfRel[x].r_info); - reMap = (uint32_t *) ((uint32_t) LD_START + elfRel[x].r_offset); - switch (ELF32_R_TYPE(elfRel[x].r_info)) { - case R_386_32: - *reMap += ((uint32_t) LD_START + relSymTab[rel].st_value); - break; - case R_386_PC32: - *reMap += ((uint32_t) LD_START + relSymTab[rel].st_value) - (uint32_t) reMap; - break; - case R_386_RELATIVE: - *reMap += (uint32_t) LD_START; - break; - case R_386_NONE: - break; + break; + case PT_DYNAMIC: + kprintf("[%s:%i] PT_DYNAMIC", __FILE__, __LINE__); + /* Now Load Section To Memory */ + //fseek(ldFd, programHeader[i].p_offset, 0x0); + //fread(newLoc, programHeader[i].p_filesz, 1, ldFd); + break; + case PT_GNU_STACK: + kprintf("[%s:%i] PT_GNU_STACK", __FILE__, __LINE__); + /* Tells us if the stack should be executable. Failsafe to executable + until we add checking */ + break; default: - kprintf("[0x%X][0x%X](%i)[%s]\n", elfRel[x].r_offset, elfRel[x].r_info, rel, elfGetRelType(ELF32_R_TYPE(elfRel[x].r_info))); - kprintf("relTab [%s][0x%X][0x%X]\n", dynStr + relSymTab[rel].st_name, relSymTab[rel].st_value, relSymTab[rel].st_name); - break; - } + kprintf("Unhandled Header (kernel) : %08x\n", programHeader[i].p_type); + break; } - kfree(elfRel); - break; - case SHT_DYNSYM: - relSymTab = (Elf_Sym *) kmalloc(sectionHeader[i].sh_size); - kern_fseek(ldFd, sectionHeader[i].sh_offset, 0x0); - fread(relSymTab, sectionHeader[i].sh_size, 1, ldFd); - sym = i; - break; - case SHT_PROGBITS: - //kprintf("PROGBITS"); - break; - case SHT_HASH: - //kprintf("HASH"); - break; - case SHT_DYNAMIC: - //kprintf("DYNAMIC"); - break; - case SHT_SYMTAB: - //kprintf("SYMTAB"); - break; - default: - //kprintf("Invalid: %i]", sectionHeader[i].sh_type); - break; } - } - i = binaryHeader->e_entry + LD_START; + for (i = 0x0; i < binaryHeader->e_shnum; i++) { + switch (sectionHeader[i].sh_type) { + case SHT_STRTAB: + if (!strcmp((shStr + sectionHeader[i].sh_name), ".dynstr")) { + dynStr = (char*) kmalloc(sectionHeader[i].sh_size); + //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); + //fread(dynStr, sectionHeader[i].sh_size, 1, ldFd); + } + break; + case SHT_REL: + elfRel = (Elf_Rel*) kmalloc(sectionHeader[i].sh_size); + //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); + //fread(elfRel, sectionHeader[i].sh_size, 1, ldFd); - kfree(dynStr); - kfree(shStr); - kfree(relSymTab); - kfree(sectionHeader); - kfree(programHeader); - kfree(binaryHeader); - fclose(ldFd); + for (x = 0x0; x < sectionHeader[i].sh_size / sizeof(Elf_Rel); x++) { + rel = ELF32_R_SYM(elfRel[x].r_info); + reMap = (uint32_t*) ((uint32_t) LD_START + elfRel[x].r_offset); + switch (ELF32_R_TYPE(elfRel[x].r_info)) { + case R_386_32: + *reMap += ((uint32_t) LD_START + relSymTab[rel].st_value); + break; + case R_386_PC32: + *reMap += ((uint32_t) LD_START + relSymTab[rel].st_value) - (uint32_t) reMap; + break; + case R_386_RELATIVE: + *reMap += (uint32_t) LD_START; + break; + case R_386_NONE: + kprintf("[%s:%i] R_386_NONE", __FILE__, __LINE__); + break; + default: + kprintf("[0x%X][0x%X](%i)[%s]\n", elfRel[x].r_offset, elfRel[x].r_info, rel, elfGetRelType(ELF32_R_TYPE(elfRel[x].r_info))); + kprintf("relTab [%s][0x%X][0x%X]\n", dynStr + relSymTab[rel].st_name, relSymTab[rel].st_value, relSymTab[rel].st_name); + break; + } + } + kfree(elfRel); + break; + case SHT_DYNSYM: + relSymTab = (Elf_Sym*) kmalloc(sectionHeader[i].sh_size); + kern_fseek(ldFd, sectionHeader[i].sh_offset, 0x0); + fread(relSymTab, sectionHeader[i].sh_size, 1, ldFd); + sym = i; + break; + case SHT_PROGBITS: + kprintf("[%s:%i] SHT_PROGBITS", __FILE__, __LINE__); + break; + case SHT_HASH: + kprintf("[%s:%i] SHT_HASH", __FILE__, __LINE__); + break; + case SHT_DYNAMIC: + kprintf("[%s:%i] SHT_DYNAMIC", __FILE__, __LINE__); + break; + case SHT_SYMTAB: + kprintf("[%s:%i] SHT_SYMTAB", __FILE__, __LINE__); + break; + default: + kprintf("Invalid: %i]", sectionHeader[i].sh_type); + break; + } + } - return ((uint32_t) i); + i = binaryHeader->e_entry + LD_START; + + kfree(dynStr); + kfree(shStr); + kfree(relSymTab); + kfree(sectionHeader); + kfree(programHeader); + kfree(binaryHeader); + fclose(ldFd); + + return ((uint32_t) i); } diff --git a/sys/kernel/ubthread.c b/sys/kernel/ubthread.c index 1ec5c3b..a747359 100644 --- a/sys/kernel/ubthread.c +++ b/sys/kernel/ubthread.c @@ -42,129 +42,129 @@ struct ubthread_cond_list *conds = 0x0; struct ubthread_mutex_list *mutex = 0x0; -kTask_t *ubthread_self() { - return (_current); +kTask_t* ubthread_self() { + return (_current); } int ubthread_cond_init(ubthread_cond_t *cond, const uint32_t attr) { - ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); - memset(ubcond, 0x0, sizeof(struct ubthread_cond)); + ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); + memset(ubcond, 0x0, sizeof(struct ubthread_cond)); - ubcond->id = (int) cond; - ubcond->lock = ATOMIC_VAR_INIT(0); + ubcond->id = (int) cond; + ubcond->lock = ATOMIC_VAR_INIT(0); - *cond = ubcond; - return (0x0); + *cond = ubcond; + return (0x0); } int ubthread_mutex_init(ubthread_mutex_t *mutex, const uint32_t attr) { - ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); - memset(ubmutex, 0x0, sizeof(struct ubthread_mutex)); + ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); + memset(ubmutex, 0x0, sizeof(struct ubthread_mutex)); - ubmutex->id = (int) mutex; - ubmutex->lock = ATOMIC_VAR_INIT(0); + ubmutex->id = (int) mutex; + ubmutex->lock = ATOMIC_VAR_INIT(0); - *mutex = ubmutex; - return (0x0); + *mutex = ubmutex; + return (0x0); } int ubthread_cond_destroy(ubthread_cond_t *cond) { - kfree(*cond); - *cond = 0x0; - return (0x0); + kfree(*cond); + *cond = 0x0; + return (0x0); } int ubthread_mutex_destroy(ubthread_mutex_t *mutex) { - kfree(*mutex); - *mutex = 0x0; - return (0x0); + kfree(*mutex); + *mutex = 0x0; + return (0x0); } int ubthread_create(kTask_t **thread, const uInt32 *attr, void (*tproc)(void), void *arg) { - *thread = (void *) execThread(tproc,0x2000, arg); - return (0x0); + *thread = (void*) execThread(tproc, 0x2000, arg); + return (0x0); } int ubthread_mutex_lock(ubthread_mutex_t *mutex) { - ubthread_mutex_t ubmutex = *mutex; + ubthread_mutex_t ubmutex = *mutex; - if (ubmutex->lock == TRUE && ubmutex->pid == _current->id) { - kprintf("Mutex Already Locked By This Thread"); - kpanic("WHY?"); + if (ubmutex->lock == TRUE && ubmutex->pid == _current->id) { + kprintf("Mutex Already Locked By This Thread"); + kpanic("WHY?"); + return (0x0); + } + + while (1) { + if (xchg_32(&ubmutex->lock, TRUE) == FALSE) + break; + + while (ubmutex->lock == TRUE) + sched_yield(); + } + + ubmutex->pid = _current->id; return (0x0); - } - - while (1) { - if (xchg_32(&ubmutex->lock, TRUE) == FALSE) - break; - - while (ubmutex->lock == TRUE) - sched_yield(); - } - - ubmutex->pid = _current->id; - return (0x0); } int ubthread_mutex_unlock(ubthread_mutex_t *mutex) { - ubthread_mutex_t ubmutex = *mutex; + ubthread_mutex_t ubmutex = *mutex; - if (ubmutex->lock != TRUE) - kpanic("NOT LOCKED?"); + if (ubmutex->lock != TRUE) + kpanic("NOT LOCKED?"); - if (ubmutex->pid != _current->id) - kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id, *ubmutex); + if (ubmutex->pid != _current->id) + kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id, *ubmutex); - while (1) { - if (xchg_32(&ubmutex->lock, FALSE) == TRUE) - break; - while (ubmutex->lock == FALSE) - sched_yield(); - } + while (1) { + if (xchg_32(&ubmutex->lock, FALSE) == TRUE) + break; + while (ubmutex->lock == FALSE) + sched_yield(); + } - ubmutex->pid = 0x0; - return (0x0); + ubmutex->pid = 0x0; + return (0x0); } int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime) { - ubthread_cond_t ubcond = *cond; - ubthread_mutex_t ubmutex = *mutex; + ubthread_cond_t ubcond = *cond; + ubthread_mutex_t ubmutex = *mutex; - uint32_t enterTime = systemVitals->sysUptime + 20; + uint32_t enterTime = systemVitals->sysUptime + 20; - ubthread_mutex_unlock(mutex); + ubthread_mutex_unlock(mutex); - while (enterTime > systemVitals->sysUptime) { - if (ubcond->lock == FALSE) - break; - sched_yield(); - } + while (enterTime > systemVitals->sysUptime) { + if (ubcond->lock == FALSE) + break; + sched_yield(); + } - ubthread_mutex_lock(mutex); + ubthread_mutex_lock(mutex); - return (0x0); + return (0x0); } int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex) { - ubthread_cond_t ubcond = *cond; - ubthread_mutex_unlock(mutex); - while (ubcond->lock == TRUE) - sched_yield(); - ubthread_mutex_lock(mutex); - return (0x0); + ubthread_cond_t ubcond = *cond; + ubthread_mutex_unlock(mutex); + while (ubcond->lock == TRUE) + sched_yield(); + ubthread_mutex_lock(mutex); + return (0x0); } int ubthread_cond_signal(ubthread_cond_t *cond) { - ubthread_cond_t ubcond = *cond; - while (xchg_32(&ubcond->lock, FALSE)) - sched_yield(); - return (0x0); + ubthread_cond_t ubcond = *cond; + while (xchg_32(&ubcond->lock, FALSE)) + sched_yield(); + return (0x0); } int ubthread_cond_broadcast(ubthread_cond_t *cond) { - ubthread_cond_t ubcond = *cond; - while (xchg_32(&ubcond->lock, FALSE)) - sched_yield(); - return (0x0); + ubthread_cond_t ubcond = *cond; + while (xchg_32(&ubcond->lock, FALSE)) + sched_yield(); + return (0x0); } diff --git a/sys/sys/video.c b/sys/sys/video.c index 4f3019b..8b1ad8b 100644 --- a/sys/sys/video.c +++ b/sys/sys/video.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002-2018 The UbixOS Project. + * Copyright (c) 2002-2018, 2020 The UbixOS Project. * All rights reserved. * * This was developed by Christopher W. Olsen for the UbixOS Project. @@ -31,92 +31,147 @@ #include #include -static unsigned char *videoBuffer = (unsigned char *) 0xB8000; +static unsigned char *videoBuffer = (unsigned char*) 0xB8000; int printColor = defaultColor; void backSpace() { - uInt32 bufferOffset = 0x0; - outportByte(0x3d4, 0x0e); - bufferOffset = inportByte(0x3d5); - bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */ - outportByte(0x3d4, 0x0f); - bufferOffset += inportByte(0x3d5); - bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */ - videoBuffer[bufferOffset--] = 0x20; - videoBuffer[bufferOffset--] = printColor; - videoBuffer[bufferOffset] = 0x20; - bufferOffset >>= 0x1; - tty_foreground->tty_x = (bufferOffset & 0xFF); - tty_foreground->tty_y = (bufferOffset >> 0x8); - outportByte(0x3D4, 0x0f); - outportByte(0x3D5, tty_foreground->tty_x); - outportByte(0x3D4, 0x0e); - outportByte(0x3D5, tty_foreground->tty_y); - return; + uInt32 bufferOffset = 0x0; + outportByte(0x3d4, 0x0e); + bufferOffset = inportByte(0x3d5); + bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */ + outportByte(0x3d4, 0x0f); + bufferOffset += inportByte(0x3d5); + bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */ + videoBuffer[bufferOffset--] = 0x20; + videoBuffer[bufferOffset--] = printColor; + videoBuffer[bufferOffset] = 0x20; + bufferOffset >>= 0x1; + tty_foreground->tty_x = (bufferOffset & 0xFF); + tty_foreground->tty_y = (bufferOffset >> 0x8); + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, tty_foreground->tty_x); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, tty_foreground->tty_y); + return; } void kprint(char *string) { - unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; - /* Short circuit if we're in tty mode */ - if (NULL != tty_foreground) { - tty_print(string, tty_find(0)); + /* Short circuit if we're in tty mode */ + if (NULL != tty_foreground) { + tty_print(string, tty_find(0)); + return; + } + + /* We Need To Get The Y Position */ + outportByte(0x3D4, 0x0e); + bufferOffset = inportByte(0x3D5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + /* Then We Need To Add The X Position */ + outportByte(0x3D4, 0x0f); + bufferOffset += inportByte(0x3D5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + + while ((character = *string++)) { + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + videoBuffer[bufferOffset++] = character; + videoBuffer[bufferOffset++] = printColor; + break; + } /* switch */ + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + videoBuffer[i] = videoBuffer[i + 160]; + } /* for */ + for (i = 0; i < 80; i++) { + videoBuffer[(160 * 24) + (i * 2)] = 0x20; + videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; + } /* for */ + bufferOffset -= 160; + } /* if */ + } /* while */ + bufferOffset >>= 1; /* Set the new cursor position */ + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + return; - } +} - /* We Need To Get The Y Position */ - outportByte(0x3D4, 0x0e); - bufferOffset = inportByte(0x3D5); - bufferOffset <<= 8; /* Shift Address Left 8 Bits */ - /* Then We Need To Add The X Position */ - outportByte(0x3D4, 0x0f); - bufferOffset += inportByte(0x3D5); - bufferOffset <<= 1; /* Shift Address Left 1 Bits */ +void kprint_len(char *string, int len) { - while ((character = *string++)) { - switch (character) { - case '\n': - bufferOffset = (bufferOffset / 160) * 160 + 160; - break; - default: - videoBuffer[bufferOffset++] = character; - videoBuffer[bufferOffset++] = printColor; - break; - } /* switch */ - /* Check To See If We Are Out Of Bounds */ - if (bufferOffset >= 160 * 25) { - for (i = 0; i < 160 * 24; i++) { - videoBuffer[i] = videoBuffer[i + 160]; - } /* for */ - for (i = 0; i < 80; i++) { - videoBuffer[(160 * 24) + (i * 2)] = 0x20; - videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; - } /* for */ - bufferOffset -= 160; - } /* if */ - } /* while */ - bufferOffset >>= 1; /* Set the new cursor position */ - outportByte(0x3D4, 0x0f); - outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); - outportByte(0x3D4, 0x0e); - outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + int x = 0; - return; + /* Short circuit if we're in tty mode */ + if (NULL != tty_foreground) { + tty_print(string, tty_find(0)); + return; + } + + /* We Need To Get The Y Position */ + outportByte(0x3D4, 0x0e); + bufferOffset = inportByte(0x3D5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + /* Then We Need To Add The X Position */ + outportByte(0x3D4, 0x0f); + bufferOffset += inportByte(0x3D5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + + while ((character = *string++)) { + if (x++ == len) + break; + + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + videoBuffer[bufferOffset++] = character; + videoBuffer[bufferOffset++] = printColor; + break; + } /* switch */ + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + videoBuffer[i] = videoBuffer[i + 160]; + } /* for */ + for (i = 0; i < 80; i++) { + videoBuffer[(160 * 24) + (i * 2)] = 0x20; + videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; + } /* for */ + bufferOffset -= 160; + } /* if */ + } /* while */ + + bufferOffset >>= 1; /* Set the new cursor position */ + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + + return; } /* Clears The Screen */ void clearScreen() { - short i = 0x0; + short i = 0x0; - for (i = 0x0; i < (80 * 25); i++) { - videoBuffer[i * 2] = 0x20; - videoBuffer[i * 2 + 1] = defaultColor; - } - outportByte(0x3D4, 0x0f); - outportByte(0x3D5, 0); - outportByte(0x3D4, 0x0e); - outportByte(0x3D5, 0); + for (i = 0x0; i < (80 * 25); i++) { + videoBuffer[i * 2] = 0x20; + videoBuffer[i * 2 + 1] = defaultColor; + } + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, 0); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, 0); } /***