diff --git a/sys/arch/armv6/Makefile b/sys/arch/armv6/Makefile new file mode 100644 index 0000000..de38484 --- /dev/null +++ b/sys/arch/armv6/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# $Id: Makefile 134 2016-01-15 14:50:24Z reddawg $ + +# Include Global 'Source' Options +include ../../Makefile.incl +include ../Makefile.incl + +# Objects +OBJS = schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_new.o sys_call.o bioscall.o fork.o syscall.o systemtask.o sched.o cpu.o +# ap-boot.o smp.o vitals.o(obsolete) + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/sys/arch/armv6/ap-boot.S b/sys/arch/armv6/ap-boot.S new file mode 100644 index 0000000..c08bd1e --- /dev/null +++ b/sys/arch/armv6/ap-boot.S @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Okay, this file contains the code that's going to bootstrap the AP cpus + */ + + + .globl ap_trampoline_start,ap_trampoline_end + .text + .code16 +ap_trampoline_start: + cli + cld + + movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments + movw %ax,%ds + movw %ax,%es + movw %ax,%ss + + // Do some bochs-specific bullshit + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + //lgdt ap_gdt; + lgdt ap_trampoline_gdt_limit - ap_trampoline_start + movl %cr0,%eax + orl $0x1,%eax + movl %eax,%cr0 // PMODE! + +.code32 + .byte 0x66 + ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS + +ap_trampoline_32: + mov $0x32,%al // '2' + mov $0xe9,%dx + outb %al,%dx + + mov $0x10,%ax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + mov %ax,%ss + + // Spinlock + mov ap_trampoline_spl - ap_trampoline_start,%edi +ap_spl: + //cmp $1,(%edi) + //je ap_spl + + mov $1,%eax // Value to be set + xchgl (%edi),%eax + cmp $0,%eax + je ap_spl + // /Spinlock + + mov $0x30,%al // '0' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_stackptr - ap_trampoline_start,%ebx + mov %ebx,%esp + add $0x1000,%ebx + mov %ebx,ap_trampoline_stackptr - ap_trampoline_start + + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + + // spinunlock + mov $0,%eax + mov ap_trampoline_spl - ap_trampoline_start,%edi + xchgl (%edi),%eax + // /spinunlock + + mov $0x33,%al // '3' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_epoint,%eax + call *%eax +1: + hlt + jmp 1b // Halt if we ever get here somehow + + // Stack.. This sucks, since CPU initialization isn't serialized +ap_trampoline_stackptr: + .long 0x10000 // 256KB +ap_trampoline_epoint: + .long c_ap_boot + +ap_trampoline_spl: + .long 0 +ap_gdt: + .long ubixGDT + + // GDT +ap_trampoline_gdt: + .word 0 +ap_trampoline_gdt_limit: + .word 128 // Room for 32 descriptors +ap_trampoline_gdt_base: + .long 0x20000 // 128KB (move this later) + + +ap_trampoline_end: diff --git a/sys/arch/armv6/bioscall.c b/sys/arch/armv6/bioscall.c new file mode 100644 index 0000000..c27a8db --- /dev/null +++ b/sys/arch/armv6/bioscall.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +asm( + ".globl bios16Code\n" + ".code16 \n" + "bios16Code: \n" + "int $0x10 \n" + "int $0x69 \n" + ".code32 \n" + ); + + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { + short segment = 0x0,offset = 0x0; + uInt32 tmpAddr = (uInt32)&bios16Code; + kTask_t *newProcess = 0x0; + + offset = tmpAddr & 0xF; // lower 4 bits + segment = tmpAddr >> 4; + + newProcess = schedNewTask(); + assert(newProcess); + + + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); + newProcess->tss.eip = offset & 0xFFFF; + newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; + newProcess->tss.eax = eax & 0xFFFF; + newProcess->tss.ebx = ebx & 0xFFFF; + newProcess->tss.ecx = ecx & 0xFFFF; + newProcess->tss.edx = edx & 0xFFFF; + newProcess->tss.esp = 0x1000 & 0xFFFF; + newProcess->tss.ebp = 0x1000 & 0xFFFF; + newProcess->tss.esi = esi & 0xFFFF; + newProcess->tss.edi = edi & 0xFFFF; + newProcess->tss.es = es & 0xFFFF; + newProcess->tss.cs = segment & 0xFFFF; + newProcess->tss.ss = 0x1000 & 0xFFFF; + newProcess->tss.ds = ds & 0xFFFF; + newProcess->tss.fs = 0x0 & 0xFFFF; + newProcess->tss.gs = 0x0 & 0xFFFF; + newProcess->tss.ldt = 0x0 & 0xFFFF; + newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; + newProcess->tss.io_map = 0x0 & 0xFFFF; + newProcess->tss.io_map = sizeof(struct tssStruct)-8192; + newProcess->oInfo.v86Task = 0x1; + + newProcess->state = READY; + + while (newProcess->state > 0); + + return; + } + +/*** + END + ***/ + diff --git a/sys/arch/armv6/exec.c b/sys/arch/armv6/exec.c new file mode 100644 index 0000000..3af2f28 --- /dev/null +++ b/sys/arch/armv6/exec.c @@ -0,0 +1,750 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STACK_ADDR 0xC800000 + +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ + +//#define AUXARGS_ENTRY(pos, id, val) {memcpy((void *)pos++,(void *)id,sizeof(long)); memcpy((void *)pos++,(void *)val,sizeof(long));} +#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} + +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + + *****************************************************************************************/ +uInt32 execThread(void (*tproc)(void), uInt32 stack, char *arg) { + kTask_t * newProcess = 0x0; + /* Find A New Thread */ + newProcess = schedNewTask(); + assert(newProcess); + if (stack < 0x100000) + kpanic("exec: stack not in valid area: [0x%X]\n", stack); + + /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; + newProcess->tss.eip = (unsigned int) tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + /* + newProcess->tss.es = 0x30+3; + newProcess->tss.cs = 0x28+3; + newProcess->tss.ss = 0x30+3; + newProcess->tss.ds = 0x30+3; + newProcess->tss.fs = 0x30+3; + newProcess->tss.gs = 0x30+3; + */ + + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + + //newProcess->imageFd = 0x0; + + /* Set up default stack for thread here filled with arg list 3 times */ + asm volatile( + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "movl %%esp,%%eax \n" + "movl %%eax,%1 \n" + "movl %%ecx,%%esp \n" + "popa \n" + : + : "b" (arg),"m" (newProcess->tss.esp) + ); + + /* Put new thread into the READY state */ + sched_setStatus(newProcess->id, READY); + + /* Return with the new process ID */ + return ((uInt32) newProcess); +} + +/***************************************************************************************** + + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: + + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + + *****************************************************************************************/ +void execFile(char *file, int argc, char **argv, int console) { + + int i = 0x0; + int x = 0x0; + uint32_t *tmp = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + + /* Get A New Task For This Proccess */ + _current = schedNewTask(); + assert(_current); + _current->gid = 0x0; + _current->uid = 0x0; + _current->term = tty_find(console); + if (_current->term == 0x0) + kprintf("Error: invalid console\n"); + + /* Set tty ownership */ + _current->term->owner = _current->id; + + /* Now We Must Create A Virtual Space For This Proccess To Run In */ + _current->tss.cr3 = (uInt32) vmmCreateVirtualSpace(_current->id); + + /* To Better Load This Application We Will Switch Over To Its VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(_current->tss.cr3)) + ); + + /* Lets Find The File */ + tmpFd = fopen(file, "r"); + + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + if (tmpFd->perms == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader)); + + //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); + fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum); + fseek(tmpFd, binaryHeader->ePhoff, 0); + + //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); + //kprintf(">d<"); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->ePhnum; i++) { + if (programHeader[i].phType == 1) { + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Remap Page Failed"); + + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); + /* Now Load Section To Memory */ + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + kprintf("pH: [0x%X]\n", programHeader[i].phMemsz); + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); + } + } + } + } + + /* Set Virtual Memory Start */ + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); + + /* Set Up Stack Space */ + for (x = 1; x < 100; x++) { + vmm_remapPage(vmm_findFreePage(_current->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK); + } + + /* Kernel Stack 0x2000 bytes long */ + vmm_remapPage(vmm_findFreePage(_current->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmm_findFreePage(_current->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK); + + /* Set All The Proper Information For The Task */ + _current->tss.back_link = 0x0; + _current->tss.esp0 = 0x5BC000; + _current->tss.ss0 = 0x10; + _current->tss.esp1 = 0x0; + _current->tss.ss1 = 0x0; + _current->tss.esp2 = 0x0; + _current->tss.ss2 = 0x0; + _current->tss.eip = (long) binaryHeader->eEntry; + _current->tss.eflags = 0x206; + _current->tss.esp = STACK_ADDR - 12; + _current->tss.ebp = STACK_ADDR; + _current->tss.esi = 0x0; + _current->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + _current->tss.es = 0x30 + 3; + _current->tss.cs = 0x28 + 3; + _current->tss.ss = 0x30 + 3; + _current->tss.ds = 0x30 + 3; + _current->tss.fs = 0x30 + 3; + _current->tss.gs = 0x30 + 3; + + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x0000; + _current->tss.io_map = 0x8000; + + sched_setStatus(_current->id, READY); + + kfree(binaryHeader); + kfree(programHeader); + fclose(tmpFd); + + tmp = (uInt32 *) _current->tss.esp0 - 5; + tmp[0] = binaryHeader->eEntry; + tmp[3] = STACK_ADDR - 12; + + tmp = (uInt32 *) STACK_ADDR - 2; + + if (_current->id > 4) + kprintf("argv[0]: [%s]\n", argv[0]); + kprintf("argv: [0x%X]\n", argv); + tmp[0] = (uint32_t) argv; + tmp[1] = (uint32_t) argv; + + /* Switch Back To The Kernels VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(kernelPageDirectory)) + ); + + /* Finally Return */ + return; +} + +/***************************************************************************************** + + Function: void sysExec(); + Description: This Is The System Call To Execute A New Task + + Notes: + 04-22-03 - It Now Loads Sections Not The Full File + + *****************************************************************************************/ +void sysExec(char *file, char *ap) { + int i = 0x0; + int x = 0x0; + int argc = 0x0; + unsigned int *tmp = 0x0; + uInt32 ldAddr = 0x0; + uInt32 seg_size = 0x0; + uInt32 seg_addr = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **argvNew = 0x0; + char *args = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynamic *elfDynamicS = 0x0; + struct i386_frame *iFrame = 0x0; + + tmpFd = fopen(file, "r"); + _current->files[0] = tmpFd; + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + return; + } + if (tmpFd->perms == 0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + + if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) + endTask(_current->id); + fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); + /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) + endTask(_current->id); + + assert(programHeader); + fseek(tmpFd, binaryHeader->ePhoff, 0); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); + + if ((sectionHeader = (elfSectionHeader *) kmalloc(sizeof(elfSectionHeader) * binaryHeader->eShnum)) == 0x0) + endTask(_current->id); + + assert(sectionHeader); + fseek(tmpFd, binaryHeader->eShoff, 0); + fread(sectionHeader, sizeof(elfSectionHeader) * binaryHeader->eShnum, 1, tmpFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0; i < binaryHeader->ePhnum; i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + + /* Now Load Section To Memory */ + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); + } + } + kprintf("setting daddr\n"); + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_DYNAMIC: + //newLoc = (char *)programHeader[i].phVaddr; + elfDynamicS = (elfDynamic *) programHeader[i].phVaddr; + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); + break; + case PT_INTERP: + interp = (char *) kmalloc(programHeader[i].phFilesz); + fseek(tmpFd, programHeader[i].phOffset, 0); + fread((void *) interp, programHeader[i].phFilesz, 1, tmpFd); + kprintf("Interp: [%s]\n", interp); + ldAddr = ldEnable(); + break; + default: + break; + } + } + + /* What is this doing? 11/23/06 */ + if (elfDynamicS != 0x0) { + for (i = 0; i < 12; i++) { + if (elfDynamicS[i].dynVal == 0x3) { + tmp = (void *) elfDynamicS[i].dynPtr; + if (tmp == 0x0) + kpanic("tmp: NULL\n"); + tmp[2] = (uInt32) ldAddr; + tmp[1] = (uInt32) tmpFd; + break; + } + /* + else { + kprintf("dyn_val: %i",elfDynamicS[i].dynVal); + } + */ + } + } + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + + argv = ≈ + + if (argv[1] != 0x0) { + argc = (int) argv[0]; + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + x = 0x0; + argvNew = (char **) kmalloc(sizeof(char *) * argc); + for (i = 0x0; i < argc; i++) { + strcpy(args + x, argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + //args[x] = '\0'; + //x++; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //! Adjust iframe + iFrame = (struct i386_frame *) _current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = binaryHeader->eEntry; + iFrame->user_esp = STACK_ADDR - 12; + + //if (_current->id > 3) { + + iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 3)); + tmp = (void *) iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0; i < argc; i++) { + tmp[i + 1] = (u_int) argv[i]; + } + tmp[argc + 1] = 0x0; + tmp[argc + 2] = 0x1; + //} + //else { + //tmp = (uint32_t *)STACK_ADDR - 2; + //tmp[0] = 0x1; + //tmp[1] = 0x0; + //tmp[1] = (uint32_t)argv; + //} + kfree(argvNew); + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + kfree(binaryHeader); + kfree(programHeader); + + return; +} + +/*! + * \brief New exec... + * + */ +void sys_exec(char *file, char *ap) { + int error = 0x0; + int i = 0x0; + int x = 0x0; + int argc = 0x0; + uint32_t *tmp = 0x0; + uint32_t seg_size = 0x0; + uint32_t seg_addr = 0x0; + uint32_t addr = 0x0; + uint32_t eip = 0x0; + uint32_t proghdr = 0x0; + char *args = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **argvNew = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + struct i386_frame *iFrame = 0x0; + //Elf_Auxargs *auxargs = 0x0; + + _current->files[0] = fopen(file, "r"); + if (_current->files[0] == 0x0) + return; //We Need To Set errno + + /* Load the ELF header */ + if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) + K_PANIC("malloc failed!"); + fread(binaryHeader, sizeof(elfHeader), 1, _current->files[0]); + + /* Check If App Is A Real Application */ + if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { + kfree(binaryHeader); + fclose(_current->files[0]); + return; //We Need To Set errno + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) + K_PANIC("malloc failed!"); + fseek(_current->files[0], binaryHeader->ePhoff, 0); + fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, _current->files[0]); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0x0; i < binaryHeader->ePhnum; i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); + } + + /* Now Load Section To Memory */ + fseek(_current->files[0], programHeader[i].phOffset, 0); + fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, _current->files[0]); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) + K_PANIC("vmm_setPageAttributes failed"); + } + } + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_INTERP: + interp = (char *) kmalloc(programHeader[i].phFilesz); + if (interp == 0x0) + K_PANIC("malloc failed") + ; + + fseek(_current->files[0], programHeader[i].phOffset, 0); + fread((void *) interp, programHeader[i].phFilesz, 1, _current->files[0]); + kprintf("Interp: [%s]\n", interp); + //ldAddr = ldEnable(); + break; + case PT_PHDR: + proghdr = programHeader[i].phVaddr; + break; + default: + break; + } + } + + addr = LD_START; + + if (interp != 0x0) { + //kprintf("TEST"); + elf_loadfile(_current, interp, &addr, &eip); + } + //kprintf("[0x%X][0x%X]\n",eip,addr); + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *) seg_addr; + + //! copy in arg strings + argv = ap; + + if (argv[1] != 0x0) { + argc = argv[0]; + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + x = 0x0; + argvNew = (char **) kmalloc(sizeof(char *) * argc); + for (i = 0x0; i < argc; i++) { + strcpy(args + x, argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //! Adjust iframe + iFrame = _current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = eip; + + //if (_current->id > 3) { + + iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 4)); // + (sizeof(Elf_Auxargs) * 2))); + kprintf("\n\n\nuser_esp: [0x%X]\n", iFrame->user_esp); + tmp = iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0; i < argc; i++) { + tmp[i + 1] = argv[i]; + } + //! Build ENV + args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); + memset(args, 0x0, 0x1000); + strcpy(args, "LIBRARY_PATH=/lib"); + tmp[argc + 2] = args; + kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); + tmp[argc + 3] = 0x0; + kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); + //auxargs = iFrame->user_esp + argc + 3; + tmp = iFrame->user_esp; + tmp += argc + 4; + + /* + auxargs->execfd = -1; + auxargs->phdr = proghdr; + auxargs->phent = binaryHeader->ePhentsize; + auxargs->phnum = binaryHeader->ePhnum; + auxargs->pagesz = PAGE_SIZE; + auxargs->base = addr; + auxargs->flags = 0x0; + auxargs->entry = binaryHeader->eEntry; + auxargs->trace = 0x0; + + AUXARGS_ENTRY(tmp, AT_PHDR, auxargs->phdr); + AUXARGS_ENTRY(tmp, AT_PHENT, auxargs->phent); + AUXARGS_ENTRY(tmp, AT_PHNUM, auxargs->phnum); + AUXARGS_ENTRY(tmp, AT_PAGESZ, auxargs->pagesz); + AUXARGS_ENTRY(tmp, AT_FLAGS, auxargs->flags); + AUXARGS_ENTRY(tmp, AT_ENTRY, auxargs->entry); + AUXARGS_ENTRY(tmp, AT_BASE, auxargs->base); + AUXARGS_ENTRY(tmp, AT_NULL, 0); + + kprintf("AT_BASE: [0x%X]\n",auxargs->base); + */ + + //iFrame->ebx = 0x0; + //iFrame->ebx = 0x0; + //iFrame->eip = binaryHeader->eEntry; + //kprintf("\n\nDOH: [0x%X]\n\n",iFrame->eip); +//while (1); + //while (1); + /* + error = elf_loadfile(_current,file,0x0,0x0); + if (error) + K_PANIC("elf_loadfile failed"); + */ + return; +} + +/*** + END + ***/ diff --git a/sys/arch/armv6/fork.c b/sys/arch/armv6/fork.c new file mode 100644 index 0000000..20fcde6 --- /dev/null +++ b/sys/arch/armv6/fork.c @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/***************************************************************************************** + Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, + long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, + long esp,long ss) + + Desc: This function will copy a process + + Notes: + + *****************************************************************************************/ +/* Had to remove static though tihs function is only used in this file */ +int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { + volatile struct taskStruct * tmpProcPtr = newProcess; + assert(newProcess); + assert(_current); + + /* Set Up New Tasks Information */ + memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); + + newProcess->tss.eip = eip; + newProcess->oInfo.vmStart = _current->oInfo.vmStart; + newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + /* Create A Copy Of The VM Space For New Task */ + newProcess->tss.cr3 = (uInt32) vmmCopyVirtualSpace(newProcess->id); + newProcess->state = FORK; + + /* Fix gcc optimization problems */ + while (tmpProcPtr->state == FORK) + sched_yield(); + + /* Return Id of Proccess */ + return (newProcess->id); +} + +/***************************************************************************************** + Functoin: void sysFork(); + + Desc: This function will fork a new task + + Notes: + + 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + + *****************************************************************************************/ +asm( + ".globl sysFork \n" + "sysFork: \n" + " xor %eax,%eax \n" + " call schedNewTask \n" + " testl %eax,%eax \n" + " je fork_ret \n" + " pushl %esi \n" + " pushl %edi \n" + " pushl %ebp \n" + " pushl %eax \n" + " call fork_copyProcess \n" + " movl %eax,(%ebx) \n" + " addl $16,%esp \n" + "fork_ret: \n" + " ret \n" +); diff --git a/sys/arch/armv6/kpanic.c b/sys/arch/armv6/kpanic.c new file mode 100644 index 0000000..e4b43c7 --- /dev/null +++ b/sys/arch/armv6/kpanic.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +/*! + * \brief print panic message and halt system + * + * \param fmt panic message + * + */ +void kpanic(const char *fmt, ...) { + char buf[512]; + va_list args; + + vaStart(args, fmt); + vsprintf(buf, fmt, args); + vaEnd(args); + + /* It's important that we print on the current terminal so let's reset foreground */ + tty_foreground = NULL; + kprintf("kPanic: %s", buf); + + /* Halt The System */ + //asm("cli"); + irqDisable(0x0); + + while (1) { + asm("hlt"); + } + +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sched.c b/sys/arch/armv6/sched.c new file mode 100644 index 0000000..5f6ffc6 --- /dev/null +++ b/sys/arch/armv6/sched.c @@ -0,0 +1,279 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static kTask_t *taskList = 0x0; +static kTask_t *delList = 0x0; +static uInt32 nextID = -1; + +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; + +static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + + Function: int sched_init() + + Description: This function is used to enable the kernel scheduler + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +int sched_init() { + taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); + if (taskList == 0x0) + kpanic("Unable to create task list"); + + taskList->id = nextID++; + + /* Print out information on scheduler */ + kprintf("sched0 - Address: [0x%X]\n", taskList); + + /* Return so we know everything went well */ + return (0x0); +} + +void sched() { + uInt32 memAddr = 0x0; + kTask_t *tmpTask = 0x0; + kTask_t *delTask = 0x0; + + if (!spinTryLock(&schedulerSpinLock)) + return; + + tmpTask = _current->next; + //outportByte(0xE9,_current->id + '0'); + schedStart: + + /* Yield the next task from the current prio queue */ + for (; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->state > 0x0) { + _current = tmpTask; + if (_current->state == FORK) + _current->state = READY; + break; + } + else if (tmpTask->state == DEAD) { + delTask = tmpTask; + tmpTask = tmpTask->next; + sched_deleteTask(delTask->id); + sched_addDelTask(delTask); + goto schedStart; + } + } + + /* Finished all the tasks, restarting the list */ + if (0x0 == tmpTask) { + tmpTask = taskList; + goto schedStart; + } + + if (_current->state > 0x0) { + if (_current->oInfo.v86Task == 0x1) + irqDisable(0x0); + asm("cli"); + memAddr = (uInt32) &(_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + spinUnlock(&schedulerSpinLock); + asm("sti"); + asm("ljmp $0x20,$0\n"); + } + else { + spinUnlock(&schedulerSpinLock); + } + + return; +} + +kTask_t *schedNewTask() { + int i = 0; + kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); + struct file *fp = 0x0; + if (tmpTask == 0x0) + kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); + + memset(tmpTask, 0x0, sizeof(kTask_t)); + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->state = NEW; + + /* HACK */ + for (i = 0; i < 3; i++) { + fp = (void *) kmalloc(sizeof(struct file)); + tmpTask->td.o_files[i] = (uint32_t) fp; + fp->f_flag = 0x4; + } + + spinLock(&schedulerSpinLock); + tmpTask->id = nextID++; + tmpTask->next = taskList; + tmpTask->prev = 0x0; + taskList->prev = tmpTask; + taskList = tmpTask; + + spinUnlock(&schedulerSpinLock); + + return (tmpTask); +} + +int sched_deleteTask(pidType id) { + kTask_t *tmpTask = 0x0; + + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + if (tmpTask->prev != 0x0) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next != 0x0) + tmpTask->next->prev = tmpTask->prev; + if (taskList == tmpTask) + taskList = tmpTask->next; + + return (0x0); + } + } + return (0x1); +} + +int sched_addDelTask(kTask_t *tmpTask) { + tmpTask->next = delList; + tmpTask->prev = 0x0; + if (delList != 0x0) + delList->prev = tmpTask; + delList = tmpTask; + return (0x0); +} + +kTask_t *sched_getDelTask() { + kTask_t *tmpTask = 0x0; + + if (delList == 0x0) + return (0x0); + + tmpTask = delList; + delList = delList->next; + return (tmpTask); +} + +kTask_t * +schedFindTask(uInt32 id) { + kTask_t *tmpTask = 0x0; + + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) + return (tmpTask); + } + + return (0x0); +} + +/************************************************************************ + + Function: void schedEndTask() + + Description: This function will end a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ +void schedEndTask(pidType pid) { + endTask(_current->id); + sched_yield(); +} + +/************************************************************************ + + Function: int schedEndTask() + + Description: This function will yield a task + + Notes: + + 02/20/2004 - Approved for quality + + ************************************************************************/ + +void sched_yield() { + sched(); +} + +/* + asm( + ".globl sched_yield \n" + "sched_yield: \n" + " cli \n" + " call sched \n" + ); + */ + +/************************************************************************ + + Function: int sched_setStatus(pidType pid,tState state) + + Description: Change the tasks status + + Notes: + + ************************************************************************/ +int sched_setStatus(pidType pid, tState state) { + kTask_t *tmpTask = schedFindTask(pid); + if (tmpTask == 0x0) + return (0x1); + tmpTask->state = state; + return (0x0); +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/schedyield.S b/sys/arch/armv6/schedyield.S new file mode 100644 index 0000000..1072793 --- /dev/null +++ b/sys/arch/armv6/schedyield.S @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl sched_yield_new +.text +.code32 +sched_yield_new: + pusha /* Save all of the registers */ + push %ss + push %ds + push %es + push %fs + push %gs + call sched + mov %eax,%esp + pop %gs + pop %fs + pop %es + pop %ds + pop %ss + popa /* Restore Registers */ + iret + +/*** + END + ***/ diff --git a/sys/arch/armv6/spinlock.c b/sys/arch/armv6/spinlock.c new file mode 100644 index 0000000..790d1fb --- /dev/null +++ b/sys/arch/armv6/spinlock.c @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +void spinLockInit(spinLock_t *lock) { + *lock = SPIN_LOCK_INITIALIZER; + } + +void spinUnlock(spinLock_t *lock) { + *lock = 0x0; + /* + register int unlocked; + asm volatile( + "xchgl %0, %1" + : "=&r" (unlocked), "=m" (*lock) : "0" (0) + ); + */ + } + +int spinTryLock(spinLock_t *lock) { + register int locked; + asm volatile("xchgl %0, %1" + : "=&r" (locked), "=m" (*lock) : "0" (1) + ); + return(!locked); + } + +void spinLock(spinLock_t *lock) { + while (!spinTryLock(lock)) + { + while (*lock == 1) + sched_yield(); + } +} + +void spinLock_scheduler(spinLock_t *lock) { + while (!spinTryLock(lock)) + while (*lock == 1); + } + + +int spinLockLocked(spinLock_t *lock) { + return(*lock != 0); + } + + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sys_call.S b/sys/arch/armv6/sys_call.S new file mode 100644 index 0000000..b4a557e --- /dev/null +++ b/sys/arch/armv6/sys_call.S @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl _sysCall +.text +.code32 +_sysCall: + cmpl totalCalls,%eax + jae invalidSysCall + + cld + pushl %edx + pushl %ecx + pushl %ebx + call *systemCalls(,%eax,4) + popl %ebx + popl %ecx + popl %edx /* Restore Registers */ + + iret + +invalidSysCall: + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/sys/arch/armv6/sys_call_new.S b/sys/arch/armv6/sys_call_new.S new file mode 100644 index 0000000..2f73600 --- /dev/null +++ b/sys/arch/armv6/sys_call_new.S @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx + +.globl _sysCall_new +.text +.code32 +_sysCall_new: + pushl $2 /* sizeof "int 0x80" */ + subl $4,%esp /* skip over tf_trapno */ + pushal + pushl %ds + pushl %es + pushl %fs + /* switch to kernel segments */ + movl $0x10,%eax + movl %eax,%ds + movl %eax,%es + movl %eax,%fs + //FAKE_MCOUNT(TF_EIP(%esp)) + call syscall + //MEXITCOUNT + //jmp doreti + popl %fs + popl %es + popl %ds + popal + addl $8,%esp + iret + +invalidSysCall: + push %eax + call invalidCall + pop %eax + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/sys/arch/armv6/syscall.c b/sys/arch/armv6/syscall.c new file mode 100644 index 0000000..36a81d8 --- /dev/null +++ b/sys/arch/armv6/syscall.c @@ -0,0 +1,247 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include + +//long fuword(const void *base); + +//void sdeTestThread(); + +asm( + ".globl _sysCallNew \n" + "_sysCallNew: \n" + " pusha \n" + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " cmpl totalCalls,%eax \n" + " jae invalidSysCallNew \n" + " mov %esp,%ebx \n" + " add $12,%ebx \n" + " push (%ebx) \n" + " call *systemCalls(,%eax,4) \n" + " add $4,%esp \n" + " jmp doneNew \n" + "invalidSysCallNew: \n" + " call InvalidSystemCall \n" + "doneNew: \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" +); + +void InvalidSystemCall() { + kprintf("attempt was made to an invalid system call\n"); + return; +} + +typedef struct _UbixUser UbixUser; +struct _UbixUser { + char *username; + char *password; + int uid; + int gid; + char *home; + char *shell; +}; + +void sysAuth(UbixUser *uu) { + kprintf("authenticating user %s\n", uu->username); + + /* MrOlsen 2016-01-01 uh? + if(uu->username == "root" && uu->password == "user") + { + uu->uid = 0; + uu->gid = 0; + } + */ + uu->uid = -1; + uu->gid = -1; + return; +} + +void sysPasswd(char *passwd) { + kprintf("changing user password for user %d\n", _current->uid); + return; +} + +void sysAddModule() { + return; +} + +void sysRmModule() { + return; +} + +void sysGetpid(int *pid) { + if (pid) + *pid = _current->id; + return; +} + +void sysGetUid(int *uid) { + if (uid) + *uid = _current->uid; + return; +} + +void sysGetGid(int *gid) { + if (gid) + *gid = _current->gid; + return; +} + +void sysSetUid(int uid, int *status) { + if (_current->uid == 0x0) { + _current->uid = uid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; +} + +void sysSetGid(int gid, int *status) { + if (_current->gid == 0x0) { + _current->gid = gid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; +} + +void sysExit(int status) { + endTask(_current->id); +} + +void sysCheckPid(int pid, int *ptr) { + kTask_t *tmpTask = schedFindTask(pid); + if ((tmpTask != 0x0) && (ptr != 0x0)) + *ptr = tmpTask->state; + else + *ptr = 0x0; + return; +} + +/************************************************************************ + + Function: void sysGetFreePage(); + Description: Allocs A Page To The Users VM Space + Notes: + + ************************************************************************/ +void sysGetFreePage(long *ptr, int count, int type) { + if (ptr) { + if (type == 2) + *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_THRD); + else + *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_TASK); + } + return; +} + +void sysGetDrives(uInt32 *ptr) { + if (ptr) + *ptr = 0x0; //(uInt32)devices; + return; +} + +void sysGetUptime(uInt32 *ptr) { + if (ptr) + *ptr = systemVitals->sysTicks; + return; +} + +void sysGetTime(uInt32 *ptr) { + if (ptr) + *ptr = systemVitals->sysUptime + systemVitals->timeStart; + return; +} + +void sysGetCwd(char *data, int len) { + if (data) + sprintf(data, "%s", _current->oInfo.cwd); + return; +} + +void sysSchedYield() { + sched_yield(); +} + +void sysStartSDE() { + int i = 0x0; + for (i = 0; i < 1400; i++) { + asm("hlt"); + } + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + for (i = 0; i < 1400; i++) { + asm("hlt"); + } + return; +} + +void invalidCall(int sys_call) { + kprintf("Invalid System Call #[%i]\n", sys_call); + return; +} + +/*** + END + ***/ + diff --git a/sys/arch/armv6/systemtask.c b/sys/arch/armv6/systemtask.c new file mode 100644 index 0000000..c0a999e --- /dev/null +++ b/sys/arch/armv6/systemtask.c @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned char *videoBuffer = (char *)0xB8000; + + +void systemTask() { + mpi_message_t myMsg; + uInt32 counter = 0x0; + int i = 0x0; + int *x = 0x0; + kTask_t *tmpTask = 0x0; + + if (mpi_createMbox("system") != 0x0) { + kpanic("Error: Error creating mailbox: system\n"); + } + + while(1) { + if (mpi_fetchMessage("system",&myMsg) == 0x0) { + kprintf("A"); + switch(myMsg.header) { + case 0x69: + x = (int *)&myMsg.data; + kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid); + schedFindTask(myMsg.pid)->term = tty_find(*x); + break; + case 1000: + kprintf("Restarting the system in 5 seconds\n"); + counter = systemVitals->sysUptime + 5; + while (systemVitals->sysUptime < counter) { + sched_yield(); + } + kprintf("Rebooting NOW!!!\n"); + while(inportByte(0x64) & 0x02); + outportByte(0x64, 0xFE); + break; + case 31337: + kprintf("system: backdoor opened\n"); + break; + case 0x80: + if (!strcmp(myMsg.data,"sdeStart")) { + kprintf("Starting SDE\n"); + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + } + else if (!strcmp(myMsg.data,"freePage")) { + kprintf("kkk Free Pages"); + } + else if (!strcmp(myMsg.data,"sdeStop")) { + printOff = 0x0; + biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0); + for (i=0x0;i<100;i++) asm("hlt"); + } + break; + default: + kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data); + break; + } + } + + /* + Here we get the next task from the delete task queue + we first check to see if it has an fd attached for the binary and after that + we free the pages for the process and then free the task + */ + tmpTask = sched_getDelTask(); + if (tmpTask != 0x0) { + if (tmpTask->files[0] != 0x0) + fclose(tmpTask->files[0]); + vmmFreeProcessPages(tmpTask->id); + kfree(tmpTask); + } + videoBuffer[0] = systemVitals->sysTicks; + sched_yield(); + } + + return; + } + +/*** + END + ***/ + diff --git a/sys/arch/armv6/timer.S b/sys/arch/armv6/timer.S new file mode 100644 index 0000000..c7aa642 --- /dev/null +++ b/sys/arch/armv6/timer.S @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.globl timerInt +.text +.code32 +timerInt: + pusha /* Save all of the registers */ + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx + movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ + incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ + movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + movl $200,%ebx /* Have Passed */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz next + incl 8(%ecx) +next: + movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 12(%ecx),%ebx /* We Can CALL sched */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz done + call sched +done: + popa /* Restore Registers */ + iret + +/*** + END + ***/ + diff --git a/sys/armv6/Makefile b/sys/armv6/Makefile deleted file mode 100644 index de38484..0000000 --- a/sys/armv6/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# (C) 2002 The UbixOS Project -# $Id: Makefile 134 2016-01-15 14:50:24Z reddawg $ - -# Include Global 'Source' Options -include ../../Makefile.incl -include ../Makefile.incl - -# Objects -OBJS = schedyield.o kpanic.o timer.o spinlock.o i386_exec.o sys_call_new.o sys_call.o bioscall.o fork.o syscall.o systemtask.o sched.o cpu.o -# ap-boot.o smp.o vitals.o(obsolete) - -all: $(OBJS) - -# Compile Types -.cc.o: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< -.cc.s: - $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< -.c.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< -.c.s: - $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< -.S.o: - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< - -# Clean up the junk -clean: - $(REMOVE) $(OBJS) diff --git a/sys/armv6/ap-boot.S b/sys/armv6/ap-boot.S deleted file mode 100644 index c08bd1e..0000000 --- a/sys/armv6/ap-boot.S +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Okay, this file contains the code that's going to bootstrap the AP cpus - */ - - - .globl ap_trampoline_start,ap_trampoline_end - .text - .code16 -ap_trampoline_start: - cli - cld - - movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments - movw %ax,%ds - movw %ax,%es - movw %ax,%ss - - // Do some bochs-specific bullshit - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - //lgdt ap_gdt; - lgdt ap_trampoline_gdt_limit - ap_trampoline_start - movl %cr0,%eax - orl $0x1,%eax - movl %eax,%cr0 // PMODE! - -.code32 - .byte 0x66 - ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS - -ap_trampoline_32: - mov $0x32,%al // '2' - mov $0xe9,%dx - outb %al,%dx - - mov $0x10,%ax - mov %ax,%ds - mov %ax,%es - mov %ax,%fs - mov %ax,%gs - mov %ax,%ss - - // Spinlock - mov ap_trampoline_spl - ap_trampoline_start,%edi -ap_spl: - //cmp $1,(%edi) - //je ap_spl - - mov $1,%eax // Value to be set - xchgl (%edi),%eax - cmp $0,%eax - je ap_spl - // /Spinlock - - mov $0x30,%al // '0' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_stackptr - ap_trampoline_start,%ebx - mov %ebx,%esp - add $0x1000,%ebx - mov %ebx,ap_trampoline_stackptr - ap_trampoline_start - - mov $0x31,%al // '1' - mov $0xe9,%dx - outb %al,%dx - - // spinunlock - mov $0,%eax - mov ap_trampoline_spl - ap_trampoline_start,%edi - xchgl (%edi),%eax - // /spinunlock - - mov $0x33,%al // '3' - mov $0xe9,%dx - outb %al,%dx - - mov ap_trampoline_epoint,%eax - call *%eax -1: - hlt - jmp 1b // Halt if we ever get here somehow - - // Stack.. This sucks, since CPU initialization isn't serialized -ap_trampoline_stackptr: - .long 0x10000 // 256KB -ap_trampoline_epoint: - .long c_ap_boot - -ap_trampoline_spl: - .long 0 -ap_gdt: - .long ubixGDT - - // GDT -ap_trampoline_gdt: - .word 0 -ap_trampoline_gdt_limit: - .word 128 // Room for 32 descriptors -ap_trampoline_gdt_base: - .long 0x20000 // 128KB (move this later) - - -ap_trampoline_end: diff --git a/sys/armv6/bioscall.c b/sys/armv6/bioscall.c deleted file mode 100644 index c27a8db..0000000 --- a/sys/armv6/bioscall.c +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -asm( - ".globl bios16Code\n" - ".code16 \n" - "bios16Code: \n" - "int $0x10 \n" - "int $0x69 \n" - ".code32 \n" - ); - - -void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { - short segment = 0x0,offset = 0x0; - uInt32 tmpAddr = (uInt32)&bios16Code; - kTask_t *newProcess = 0x0; - - offset = tmpAddr & 0xF; // lower 4 bits - segment = tmpAddr >> 4; - - newProcess = schedNewTask(); - assert(newProcess); - - - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); - newProcess->tss.eip = offset & 0xFFFF; - newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; - newProcess->tss.eax = eax & 0xFFFF; - newProcess->tss.ebx = ebx & 0xFFFF; - newProcess->tss.ecx = ecx & 0xFFFF; - newProcess->tss.edx = edx & 0xFFFF; - newProcess->tss.esp = 0x1000 & 0xFFFF; - newProcess->tss.ebp = 0x1000 & 0xFFFF; - newProcess->tss.esi = esi & 0xFFFF; - newProcess->tss.edi = edi & 0xFFFF; - newProcess->tss.es = es & 0xFFFF; - newProcess->tss.cs = segment & 0xFFFF; - newProcess->tss.ss = 0x1000 & 0xFFFF; - newProcess->tss.ds = ds & 0xFFFF; - newProcess->tss.fs = 0x0 & 0xFFFF; - newProcess->tss.gs = 0x0 & 0xFFFF; - newProcess->tss.ldt = 0x0 & 0xFFFF; - newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; - newProcess->tss.io_map = 0x0 & 0xFFFF; - newProcess->tss.io_map = sizeof(struct tssStruct)-8192; - newProcess->oInfo.v86Task = 0x1; - - newProcess->state = READY; - - while (newProcess->state > 0); - - return; - } - -/*** - END - ***/ - diff --git a/sys/armv6/exec.c b/sys/armv6/exec.c deleted file mode 100644 index 3af2f28..0000000 --- a/sys/armv6/exec.c +++ /dev/null @@ -1,750 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STACK_ADDR 0xC800000 - -#define AT_NULL 0 /* Terminates the vector. */ -#define AT_IGNORE 1 /* Ignored entry. */ -#define AT_EXECFD 2 /* File descriptor of program to load. */ -#define AT_PHDR 3 /* Program header of program already loaded. */ -#define AT_PHENT 4 /* Size of each program header entry. */ -#define AT_PHNUM 5 /* Number of program header entries. */ -#define AT_PAGESZ 6 /* Page size in bytes. */ -#define AT_BASE 7 /* Interpreter's base address. */ -#define AT_FLAGS 8 /* Flags (unused for i386). */ -#define AT_ENTRY 9 /* Where interpreter should transfer control. */ - -//#define AUXARGS_ENTRY(pos, id, val) {memcpy((void *)pos++,(void *)id,sizeof(long)); memcpy((void *)pos++,(void *)val,sizeof(long));} -#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} - -/***************************************************************************************** - - Function: execThread(void (*)(void),int,char *); - Description: This function will create a thread from code in the current memory space - - Notes: - - 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space - so do not use out side of kernel space - - *****************************************************************************************/ -uInt32 execThread(void (*tproc)(void), uInt32 stack, char *arg) { - kTask_t * newProcess = 0x0; - /* Find A New Thread */ - newProcess = schedNewTask(); - assert(newProcess); - if (stack < 0x100000) - kpanic("exec: stack not in valid area: [0x%X]\n", stack); - - /* Set All The Correct Thread Attributes */ - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = 0x0; - newProcess->tss.ss0 = 0x0; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (unsigned int) kernelPageDirectory; - newProcess->tss.eip = (unsigned int) tproc; - newProcess->tss.eflags = 0x206; - newProcess->tss.esp = stack; - newProcess->tss.ebp = stack; - newProcess->tss.esi = 0x0; - newProcess->tss.edi = 0x0; - - /* Set these up to be ring 3 tasks */ - /* - newProcess->tss.es = 0x30+3; - newProcess->tss.cs = 0x28+3; - newProcess->tss.ss = 0x30+3; - newProcess->tss.ds = 0x30+3; - newProcess->tss.fs = 0x30+3; - newProcess->tss.gs = 0x30+3; - */ - - newProcess->tss.es = 0x10; - newProcess->tss.cs = 0x08; - newProcess->tss.ss = 0x10; - newProcess->tss.ds = 0x10; - newProcess->tss.fs = 0x10; - newProcess->tss.gs = 0x10; - - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - newProcess->oInfo.vmStart = 0x6400000; - - //newProcess->imageFd = 0x0; - - /* Set up default stack for thread here filled with arg list 3 times */ - asm volatile( - "pusha \n" - "movl %%esp,%%ecx \n" - "movl %1,%%eax \n" - "movl %%eax,%%esp \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "pushl %%ebx \n" - "movl %%esp,%%eax \n" - "movl %%eax,%1 \n" - "movl %%ecx,%%esp \n" - "popa \n" - : - : "b" (arg),"m" (newProcess->tss.esp) - ); - - /* Put new thread into the READY state */ - sched_setStatus(newProcess->id, READY); - - /* Return with the new process ID */ - return ((uInt32) newProcess); -} - -/***************************************************************************************** - - Function: void execFile(char *file); - Description: This Function Executes A Kile Into A New VM Space With Out - Having To Fork - Notes: - - 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few - Memory Leaks The Memory Allocated To Load The Binary Into Is - Now Unmapped So It Can Be Used Again And Not Held Onto Until - The Program Exits - - 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up - The Freshly Allocated Pages With The Correct Permissions - - *****************************************************************************************/ -void execFile(char *file, int argc, char **argv, int console) { - - int i = 0x0; - int x = 0x0; - uint32_t *tmp = 0x0; - - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - - /* Get A New Task For This Proccess */ - _current = schedNewTask(); - assert(_current); - _current->gid = 0x0; - _current->uid = 0x0; - _current->term = tty_find(console); - if (_current->term == 0x0) - kprintf("Error: invalid console\n"); - - /* Set tty ownership */ - _current->term->owner = _current->id; - - /* Now We Must Create A Virtual Space For This Proccess To Run In */ - _current->tss.cr3 = (uInt32) vmmCreateVirtualSpace(_current->id); - - /* To Better Load This Application We Will Switch Over To Its VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uInt32 *)(_current->tss.cr3)) - ); - - /* Lets Find The File */ - tmpFd = fopen(file, "r"); - - /* If We Dont Find the File Return */ - if (tmpFd == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - if (tmpFd->perms == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - - /* Load ELF Header */ - binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader)); - - //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); - fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); - - /* Check If App Is A Real Application */ - if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eType != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eEntry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - - /* Load The Program Header(s) */ - programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum); - fseek(tmpFd, binaryHeader->ePhoff, 0); - - //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); - //kprintf(">d<"); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->ePhnum; i++) { - if (programHeader[i].phType == 1) { - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Remap Page Failed"); - - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); - /* Now Load Section To Memory */ - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - kprintf("pH: [0x%X]\n", programHeader[i].phMemsz); - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__); - } - } - } - } - - /* Set Virtual Memory Start */ - _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *) (programHeader[i].phVaddr & 0xFFFFF000); - - /* Set Up Stack Space */ - for (x = 1; x < 100; x++) { - vmm_remapPage(vmm_findFreePage(_current->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK); - } - - /* Kernel Stack 0x2000 bytes long */ - vmm_remapPage(vmm_findFreePage(_current->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK); - vmm_remapPage(vmm_findFreePage(_current->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK); - - /* Set All The Proper Information For The Task */ - _current->tss.back_link = 0x0; - _current->tss.esp0 = 0x5BC000; - _current->tss.ss0 = 0x10; - _current->tss.esp1 = 0x0; - _current->tss.ss1 = 0x0; - _current->tss.esp2 = 0x0; - _current->tss.ss2 = 0x0; - _current->tss.eip = (long) binaryHeader->eEntry; - _current->tss.eflags = 0x206; - _current->tss.esp = STACK_ADDR - 12; - _current->tss.ebp = STACK_ADDR; - _current->tss.esi = 0x0; - _current->tss.edi = 0x0; - - /* Set these up to be ring 3 tasks */ - _current->tss.es = 0x30 + 3; - _current->tss.cs = 0x28 + 3; - _current->tss.ss = 0x30 + 3; - _current->tss.ds = 0x30 + 3; - _current->tss.fs = 0x30 + 3; - _current->tss.gs = 0x30 + 3; - - _current->tss.ldt = 0x18; - _current->tss.trace_bitmap = 0x0000; - _current->tss.io_map = 0x8000; - - sched_setStatus(_current->id, READY); - - kfree(binaryHeader); - kfree(programHeader); - fclose(tmpFd); - - tmp = (uInt32 *) _current->tss.esp0 - 5; - tmp[0] = binaryHeader->eEntry; - tmp[3] = STACK_ADDR - 12; - - tmp = (uInt32 *) STACK_ADDR - 2; - - if (_current->id > 4) - kprintf("argv[0]: [%s]\n", argv[0]); - kprintf("argv: [0x%X]\n", argv); - tmp[0] = (uint32_t) argv; - tmp[1] = (uint32_t) argv; - - /* Switch Back To The Kernels VM Space */ - asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - : : "d" ((uInt32 *)(kernelPageDirectory)) - ); - - /* Finally Return */ - return; -} - -/***************************************************************************************** - - Function: void sysExec(); - Description: This Is The System Call To Execute A New Task - - Notes: - 04-22-03 - It Now Loads Sections Not The Full File - - *****************************************************************************************/ -void sysExec(char *file, char *ap) { - int i = 0x0; - int x = 0x0; - int argc = 0x0; - unsigned int *tmp = 0x0; - uInt32 ldAddr = 0x0; - uInt32 seg_size = 0x0; - uInt32 seg_addr = 0x0; - char *interp = 0x0; - char **argv = 0x0; - char **argvNew = 0x0; - char *args = 0x0; - - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - elfSectionHeader *sectionHeader = 0x0; - elfDynamic *elfDynamicS = 0x0; - struct i386_frame *iFrame = 0x0; - - tmpFd = fopen(file, "r"); - _current->files[0] = tmpFd; - /* If We Dont Find the File Return */ - if (tmpFd == 0x0) { - return; - } - if (tmpFd->perms == 0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - fclose(tmpFd); - return; - } - - /* Load ELF Header */ - - if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) - endTask(_current->id); - fread(binaryHeader, sizeof(elfHeader), 1, tmpFd); - /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ - - /* Check If App Is A Real Application */ - if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - - return; - } - else if (binaryHeader->eType != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - else if (binaryHeader->eEntry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); - kfree(binaryHeader); - fclose(tmpFd); - return; - } - - /* Load The Program Header(s) */ - if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) - endTask(_current->id); - - assert(programHeader); - fseek(tmpFd, binaryHeader->ePhoff, 0); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd); - - if ((sectionHeader = (elfSectionHeader *) kmalloc(sizeof(elfSectionHeader) * binaryHeader->eShnum)) == 0x0) - endTask(_current->id); - - assert(sectionHeader); - fseek(tmpFd, binaryHeader->eShoff, 0); - fread(sectionHeader, sizeof(elfSectionHeader) * binaryHeader->eShnum, 1, tmpFd); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0; i < binaryHeader->ePhnum; i++) { - switch (programHeader[i].phType) { - case PT_LOAD: - seg_addr = trunc_page(programHeader[i].phVaddr); - seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); - - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Error: Remap Page Failed"); - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - - /* Now Load Section To Memory */ - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__); - } - } - kprintf("setting daddr\n"); - if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { - /* We're suposed to do something here? */ - } - else { - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - } - - _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); - break; - case PT_DYNAMIC: - //newLoc = (char *)programHeader[i].phVaddr; - elfDynamicS = (elfDynamic *) programHeader[i].phVaddr; - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, tmpFd); - break; - case PT_INTERP: - interp = (char *) kmalloc(programHeader[i].phFilesz); - fseek(tmpFd, programHeader[i].phOffset, 0); - fread((void *) interp, programHeader[i].phFilesz, 1, tmpFd); - kprintf("Interp: [%s]\n", interp); - ldAddr = ldEnable(); - break; - default: - break; - } - } - - /* What is this doing? 11/23/06 */ - if (elfDynamicS != 0x0) { - for (i = 0; i < 12; i++) { - if (elfDynamicS[i].dynVal == 0x3) { - tmp = (void *) elfDynamicS[i].dynPtr; - if (tmp == 0x0) - kpanic("tmp: NULL\n"); - tmp[2] = (uInt32) ldAddr; - tmp[1] = (uInt32) tmpFd; - break; - } - /* - else { - kprintf("dyn_val: %i",elfDynamicS[i].dynVal); - } - */ - } - } - - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - - argv = ≈ - - if (argv[1] != 0x0) { - argc = (int) argv[0]; - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - x = 0x0; - argvNew = (char **) kmalloc(sizeof(char *) * argc); - for (i = 0x0; i < argc; i++) { - strcpy(args + x, argv[i + 1]); - argvNew[i] = args + x; - x += strlen(argv[i + 1]) + 1; - //args[x] = '\0'; - //x++; - } - argv = argvNew; - } - - //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); - - //! Adjust iframe - iFrame = (struct i386_frame *) _current->tss.esp0 - sizeof(struct i386_frame); - iFrame->ebp = STACK_ADDR; - iFrame->eip = binaryHeader->eEntry; - iFrame->user_esp = STACK_ADDR - 12; - - //if (_current->id > 3) { - - iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 3)); - tmp = (void *) iFrame->user_esp; - - //! build argc and argv[] - tmp[0] = argc; - for (i = 0; i < argc; i++) { - tmp[i + 1] = (u_int) argv[i]; - } - tmp[argc + 1] = 0x0; - tmp[argc + 2] = 0x1; - //} - //else { - //tmp = (uint32_t *)STACK_ADDR - 2; - //tmp[0] = 0x1; - //tmp[1] = 0x0; - //tmp[1] = (uint32_t)argv; - //} - kfree(argvNew); - /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ - kfree(binaryHeader); - kfree(programHeader); - - return; -} - -/*! - * \brief New exec... - * - */ -void sys_exec(char *file, char *ap) { - int error = 0x0; - int i = 0x0; - int x = 0x0; - int argc = 0x0; - uint32_t *tmp = 0x0; - uint32_t seg_size = 0x0; - uint32_t seg_addr = 0x0; - uint32_t addr = 0x0; - uint32_t eip = 0x0; - uint32_t proghdr = 0x0; - char *args = 0x0; - char *interp = 0x0; - char **argv = 0x0; - char **argvNew = 0x0; - elfHeader *binaryHeader = 0x0; - elfProgramHeader *programHeader = 0x0; - struct i386_frame *iFrame = 0x0; - //Elf_Auxargs *auxargs = 0x0; - - _current->files[0] = fopen(file, "r"); - if (_current->files[0] == 0x0) - return; //We Need To Set errno - - /* Load the ELF header */ - if ((binaryHeader = (elfHeader *) kmalloc(sizeof(elfHeader))) == 0x0) - K_PANIC("malloc failed!"); - fread(binaryHeader, sizeof(elfHeader), 1, _current->files[0]); - - /* Check If App Is A Real Application */ - if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { - kfree(binaryHeader); - fclose(_current->files[0]); - return; //We Need To Set errno - } - - /* Load The Program Header(s) */ - if ((programHeader = (elfProgramHeader *) kmalloc(sizeof(elfProgramHeader) * binaryHeader->ePhnum)) == 0x0) - K_PANIC("malloc failed!"); - fseek(_current->files[0], binaryHeader->ePhoff, 0); - fread(programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, _current->files[0]); - - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for (i = 0x0; i < binaryHeader->ePhnum; i++) { - switch (programHeader[i].phType) { - case PT_LOAD: - seg_addr = trunc_page(programHeader[i].phVaddr); - seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); - - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].phVaddr & 0xFFFFF000) + x), PAGE_DEFAULT) == 0x0) - K_PANIC("Error: Remap Page Failed"); - memset((void *) ((programHeader[i].phVaddr & 0xFFFFF000) + x), 0x0, 0x1000); - } - - /* Now Load Section To Memory */ - fseek(_current->files[0], programHeader[i].phOffset, 0); - fread((void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, _current->files[0]); - if ((programHeader[i].phFlags & 0x2) != 0x2) { - for (x = 0x0; x < (programHeader[i].phMemsz); x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0) - K_PANIC("vmm_setPageAttributes failed"); - } - } - if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { - /* We're suposed to do something here? */ - } - else { - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - } - - _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); - break; - case PT_INTERP: - interp = (char *) kmalloc(programHeader[i].phFilesz); - if (interp == 0x0) - K_PANIC("malloc failed") - ; - - fseek(_current->files[0], programHeader[i].phOffset, 0); - fread((void *) interp, programHeader[i].phFilesz, 1, _current->files[0]); - kprintf("Interp: [%s]\n", interp); - //ldAddr = ldEnable(); - break; - case PT_PHDR: - proghdr = programHeader[i].phVaddr; - break; - default: - break; - } - } - - addr = LD_START; - - if (interp != 0x0) { - //kprintf("TEST"); - elf_loadfile(_current, interp, &addr, &eip); - } - //kprintf("[0x%X][0x%X]\n",eip,addr); - - _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *) seg_addr; - - //! copy in arg strings - argv = ap; - - if (argv[1] != 0x0) { - argc = argv[0]; - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - x = 0x0; - argvNew = (char **) kmalloc(sizeof(char *) * argc); - for (i = 0x0; i < argc; i++) { - strcpy(args + x, argv[i + 1]); - argvNew[i] = args + x; - x += strlen(argv[i + 1]) + 1; - } - argv = argvNew; - } - - //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); - - //! Adjust iframe - iFrame = _current->tss.esp0 - sizeof(struct i386_frame); - iFrame->ebp = STACK_ADDR; - iFrame->eip = eip; - - //if (_current->id > 3) { - - iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 4)); // + (sizeof(Elf_Auxargs) * 2))); - kprintf("\n\n\nuser_esp: [0x%X]\n", iFrame->user_esp); - tmp = iFrame->user_esp; - - //! build argc and argv[] - tmp[0] = argc; - for (i = 0; i < argc; i++) { - tmp[i + 1] = argv[i]; - } - //! Build ENV - args = (char *) vmmGetFreeVirtualPage(_current->id, 1, VM_TASK); - memset(args, 0x0, 0x1000); - strcpy(args, "LIBRARY_PATH=/lib"); - tmp[argc + 2] = args; - kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); - tmp[argc + 3] = 0x0; - kprintf("env: [0x%X][0x%X]\n", (uInt32) tmp + argc + 2, tmp[argc + 2]); - //auxargs = iFrame->user_esp + argc + 3; - tmp = iFrame->user_esp; - tmp += argc + 4; - - /* - auxargs->execfd = -1; - auxargs->phdr = proghdr; - auxargs->phent = binaryHeader->ePhentsize; - auxargs->phnum = binaryHeader->ePhnum; - auxargs->pagesz = PAGE_SIZE; - auxargs->base = addr; - auxargs->flags = 0x0; - auxargs->entry = binaryHeader->eEntry; - auxargs->trace = 0x0; - - AUXARGS_ENTRY(tmp, AT_PHDR, auxargs->phdr); - AUXARGS_ENTRY(tmp, AT_PHENT, auxargs->phent); - AUXARGS_ENTRY(tmp, AT_PHNUM, auxargs->phnum); - AUXARGS_ENTRY(tmp, AT_PAGESZ, auxargs->pagesz); - AUXARGS_ENTRY(tmp, AT_FLAGS, auxargs->flags); - AUXARGS_ENTRY(tmp, AT_ENTRY, auxargs->entry); - AUXARGS_ENTRY(tmp, AT_BASE, auxargs->base); - AUXARGS_ENTRY(tmp, AT_NULL, 0); - - kprintf("AT_BASE: [0x%X]\n",auxargs->base); - */ - - //iFrame->ebx = 0x0; - //iFrame->ebx = 0x0; - //iFrame->eip = binaryHeader->eEntry; - //kprintf("\n\nDOH: [0x%X]\n\n",iFrame->eip); -//while (1); - //while (1); - /* - error = elf_loadfile(_current,file,0x0,0x0); - if (error) - K_PANIC("elf_loadfile failed"); - */ - return; -} - -/*** - END - ***/ diff --git a/sys/armv6/fork.c b/sys/armv6/fork.c deleted file mode 100644 index 20fcde6..0000000 --- a/sys/armv6/fork.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/***************************************************************************************** - Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, - long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, - long esp,long ss) - - Desc: This function will copy a process - - Notes: - - *****************************************************************************************/ -/* Had to remove static though tihs function is only used in this file */ -int fork_copyProcess(struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss) { - volatile struct taskStruct * tmpProcPtr = newProcess; - assert(newProcess); - assert(_current); - - /* Set Up New Tasks Information */ - memcpy(newProcess->oInfo.cwd, _current->oInfo.cwd, 1024); - - newProcess->tss.eip = eip; - newProcess->oInfo.vmStart = _current->oInfo.vmStart; - newProcess->term = _current->term; - newProcess->term->owner = newProcess->id; - newProcess->uid = _current->uid; - newProcess->gid = _current->gid; - newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = _current->tss.esp0; - newProcess->tss.ss0 = 0x10; - newProcess->tss.esp1 = 0x0; - newProcess->tss.ss1 = 0x0; - newProcess->tss.esp2 = 0x0; - newProcess->tss.ss2 = 0x0; - newProcess->tss.eflags = eflags; - newProcess->tss.eax = 0x0; - newProcess->tss.ebx = ebx; - newProcess->tss.ecx = ecx; - newProcess->tss.edx = edx; - newProcess->tss.esi = esi; - newProcess->tss.edi = edi; - newProcess->tss.ebp = ebp; - newProcess->tss.esp = esp; - newProcess->tss.cs = cs & 0xFF; - newProcess->tss.ss = ss & 0xFF; - newProcess->tss.ds = _current->tss.ds & 0xFF; - newProcess->tss.fs = _current->tss.fs & 0xFF; - newProcess->tss.gs = _current->tss.gs & 0xFF; - newProcess->tss.es = _current->tss.es & 0xFF; - newProcess->tss.ldt = 0x18; - newProcess->tss.trace_bitmap = 0x0000; - newProcess->tss.io_map = 0x8000; - /* Create A Copy Of The VM Space For New Task */ - newProcess->tss.cr3 = (uInt32) vmmCopyVirtualSpace(newProcess->id); - newProcess->state = FORK; - - /* Fix gcc optimization problems */ - while (tmpProcPtr->state == FORK) - sched_yield(); - - /* Return Id of Proccess */ - return (newProcess->id); -} - -/***************************************************************************************** - Functoin: void sysFork(); - - Desc: This function will fork a new task - - Notes: - - 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I - Chose The Best Path To Impliment It I Guess We Will See - What The Future May Bring - - *****************************************************************************************/ -asm( - ".globl sysFork \n" - "sysFork: \n" - " xor %eax,%eax \n" - " call schedNewTask \n" - " testl %eax,%eax \n" - " je fork_ret \n" - " pushl %esi \n" - " pushl %edi \n" - " pushl %ebp \n" - " pushl %eax \n" - " call fork_copyProcess \n" - " movl %eax,(%ebx) \n" - " addl $16,%esp \n" - "fork_ret: \n" - " ret \n" -); diff --git a/sys/armv6/kpanic.c b/sys/armv6/kpanic.c deleted file mode 100644 index e4b43c7..0000000 --- a/sys/armv6/kpanic.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -/*! - * \brief print panic message and halt system - * - * \param fmt panic message - * - */ -void kpanic(const char *fmt, ...) { - char buf[512]; - va_list args; - - vaStart(args, fmt); - vsprintf(buf, fmt, args); - vaEnd(args); - - /* It's important that we print on the current terminal so let's reset foreground */ - tty_foreground = NULL; - kprintf("kPanic: %s", buf); - - /* Halt The System */ - //asm("cli"); - irqDisable(0x0); - - while (1) { - asm("hlt"); - } - -} - -/*** - END - ***/ - diff --git a/sys/armv6/sched.c b/sys/armv6/sched.c deleted file mode 100644 index 5f6ffc6..0000000 --- a/sys/armv6/sched.c +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static kTask_t *taskList = 0x0; -static kTask_t *delList = 0x0; -static uInt32 nextID = -1; - -kTask_t *_current = 0x0; -kTask_t *_usedMath = 0x0; - -static struct spinLock schedulerSpinLock = SPIN_LOCK_INITIALIZER; - -/************************************************************************ - - Function: int sched_init() - - Description: This function is used to enable the kernel scheduler - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -int sched_init() { - taskList = (kTask_t *) kmalloc(sizeof(kTask_t)); - if (taskList == 0x0) - kpanic("Unable to create task list"); - - taskList->id = nextID++; - - /* Print out information on scheduler */ - kprintf("sched0 - Address: [0x%X]\n", taskList); - - /* Return so we know everything went well */ - return (0x0); -} - -void sched() { - uInt32 memAddr = 0x0; - kTask_t *tmpTask = 0x0; - kTask_t *delTask = 0x0; - - if (!spinTryLock(&schedulerSpinLock)) - return; - - tmpTask = _current->next; - //outportByte(0xE9,_current->id + '0'); - schedStart: - - /* Yield the next task from the current prio queue */ - for (; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->state > 0x0) { - _current = tmpTask; - if (_current->state == FORK) - _current->state = READY; - break; - } - else if (tmpTask->state == DEAD) { - delTask = tmpTask; - tmpTask = tmpTask->next; - sched_deleteTask(delTask->id); - sched_addDelTask(delTask); - goto schedStart; - } - } - - /* Finished all the tasks, restarting the list */ - if (0x0 == tmpTask) { - tmpTask = taskList; - goto schedStart; - } - - if (_current->state > 0x0) { - if (_current->oInfo.v86Task == 0x1) - irqDisable(0x0); - asm("cli"); - memAddr = (uInt32) &(_current->tss); - ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); - ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); - ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); - ubixGDT[4].descriptor.access = '\x89'; - spinUnlock(&schedulerSpinLock); - asm("sti"); - asm("ljmp $0x20,$0\n"); - } - else { - spinUnlock(&schedulerSpinLock); - } - - return; -} - -kTask_t *schedNewTask() { - int i = 0; - kTask_t *tmpTask = (kTask_t *) kmalloc(sizeof(kTask_t)); - struct file *fp = 0x0; - if (tmpTask == 0x0) - kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); - - memset(tmpTask, 0x0, sizeof(kTask_t)); - /* Filling in tasks attrs */ - tmpTask->usedMath = 0x0; - tmpTask->state = NEW; - - /* HACK */ - for (i = 0; i < 3; i++) { - fp = (void *) kmalloc(sizeof(struct file)); - tmpTask->td.o_files[i] = (uint32_t) fp; - fp->f_flag = 0x4; - } - - spinLock(&schedulerSpinLock); - tmpTask->id = nextID++; - tmpTask->next = taskList; - tmpTask->prev = 0x0; - taskList->prev = tmpTask; - taskList = tmpTask; - - spinUnlock(&schedulerSpinLock); - - return (tmpTask); -} - -int sched_deleteTask(pidType id) { - kTask_t *tmpTask = 0x0; - - /* Checking each task from the prio queue */ - for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { - if (tmpTask->id == id) { - if (tmpTask->prev != 0x0) - tmpTask->prev->next = tmpTask->next; - if (tmpTask->next != 0x0) - tmpTask->next->prev = tmpTask->prev; - if (taskList == tmpTask) - taskList = tmpTask->next; - - return (0x0); - } - } - return (0x1); -} - -int sched_addDelTask(kTask_t *tmpTask) { - tmpTask->next = delList; - tmpTask->prev = 0x0; - if (delList != 0x0) - delList->prev = tmpTask; - delList = tmpTask; - return (0x0); -} - -kTask_t *sched_getDelTask() { - kTask_t *tmpTask = 0x0; - - if (delList == 0x0) - return (0x0); - - tmpTask = delList; - delList = delList->next; - return (tmpTask); -} - -kTask_t * -schedFindTask(uInt32 id) { - kTask_t *tmpTask = 0x0; - - for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { - if (tmpTask->id == id) - return (tmpTask); - } - - return (0x0); -} - -/************************************************************************ - - Function: void schedEndTask() - - Description: This function will end a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ -void schedEndTask(pidType pid) { - endTask(_current->id); - sched_yield(); -} - -/************************************************************************ - - Function: int schedEndTask() - - Description: This function will yield a task - - Notes: - - 02/20/2004 - Approved for quality - - ************************************************************************/ - -void sched_yield() { - sched(); -} - -/* - asm( - ".globl sched_yield \n" - "sched_yield: \n" - " cli \n" - " call sched \n" - ); - */ - -/************************************************************************ - - Function: int sched_setStatus(pidType pid,tState state) - - Description: Change the tasks status - - Notes: - - ************************************************************************/ -int sched_setStatus(pidType pid, tState state) { - kTask_t *tmpTask = schedFindTask(pid); - if (tmpTask == 0x0) - return (0x1); - tmpTask->state = state; - return (0x0); -} - -/*** - END - ***/ - diff --git a/sys/armv6/schedyield.S b/sys/armv6/schedyield.S deleted file mode 100644 index 1072793..0000000 --- a/sys/armv6/schedyield.S +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl sched_yield_new -.text -.code32 -sched_yield_new: - pusha /* Save all of the registers */ - push %ss - push %ds - push %es - push %fs - push %gs - call sched - mov %eax,%esp - pop %gs - pop %fs - pop %es - pop %ds - pop %ss - popa /* Restore Registers */ - iret - -/*** - END - ***/ diff --git a/sys/armv6/spinlock.c b/sys/armv6/spinlock.c deleted file mode 100644 index 790d1fb..0000000 --- a/sys/armv6/spinlock.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -void spinLockInit(spinLock_t *lock) { - *lock = SPIN_LOCK_INITIALIZER; - } - -void spinUnlock(spinLock_t *lock) { - *lock = 0x0; - /* - register int unlocked; - asm volatile( - "xchgl %0, %1" - : "=&r" (unlocked), "=m" (*lock) : "0" (0) - ); - */ - } - -int spinTryLock(spinLock_t *lock) { - register int locked; - asm volatile("xchgl %0, %1" - : "=&r" (locked), "=m" (*lock) : "0" (1) - ); - return(!locked); - } - -void spinLock(spinLock_t *lock) { - while (!spinTryLock(lock)) - { - while (*lock == 1) - sched_yield(); - } -} - -void spinLock_scheduler(spinLock_t *lock) { - while (!spinTryLock(lock)) - while (*lock == 1); - } - - -int spinLockLocked(spinLock_t *lock) { - return(*lock != 0); - } - - -/*** - END - ***/ - diff --git a/sys/armv6/sys_call.S b/sys/armv6/sys_call.S deleted file mode 100644 index b4a557e..0000000 --- a/sys/armv6/sys_call.S +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl _sysCall -.text -.code32 -_sysCall: - cmpl totalCalls,%eax - jae invalidSysCall - - cld - pushl %edx - pushl %ecx - pushl %ebx - call *systemCalls(,%eax,4) - popl %ebx - popl %ecx - popl %edx /* Restore Registers */ - - iret - -invalidSysCall: - movl $-1,%eax - iret - -/*** - END - ***/ - diff --git a/sys/armv6/sys_call_new.S b/sys/armv6/sys_call_new.S deleted file mode 100644 index 2f73600..0000000 --- a/sys/armv6/sys_call_new.S +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx - -.globl _sysCall_new -.text -.code32 -_sysCall_new: - pushl $2 /* sizeof "int 0x80" */ - subl $4,%esp /* skip over tf_trapno */ - pushal - pushl %ds - pushl %es - pushl %fs - /* switch to kernel segments */ - movl $0x10,%eax - movl %eax,%ds - movl %eax,%es - movl %eax,%fs - //FAKE_MCOUNT(TF_EIP(%esp)) - call syscall - //MEXITCOUNT - //jmp doreti - popl %fs - popl %es - popl %ds - popal - addl $8,%esp - iret - -invalidSysCall: - push %eax - call invalidCall - pop %eax - movl $-1,%eax - iret - -/*** - END - ***/ - diff --git a/sys/armv6/syscall.c b/sys/armv6/syscall.c deleted file mode 100644 index 36a81d8..0000000 --- a/sys/armv6/syscall.c +++ /dev/null @@ -1,247 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* #include */ -#include -#include - -//long fuword(const void *base); - -//void sdeTestThread(); - -asm( - ".globl _sysCallNew \n" - "_sysCallNew: \n" - " pusha \n" - " push %ss \n" - " push %ds \n" - " push %es \n" - " push %fs \n" - " push %gs \n" - " cmpl totalCalls,%eax \n" - " jae invalidSysCallNew \n" - " mov %esp,%ebx \n" - " add $12,%ebx \n" - " push (%ebx) \n" - " call *systemCalls(,%eax,4) \n" - " add $4,%esp \n" - " jmp doneNew \n" - "invalidSysCallNew: \n" - " call InvalidSystemCall \n" - "doneNew: \n" - " pop %gs \n" - " pop %fs \n" - " pop %es \n" - " pop %ds \n" - " pop %ss \n" - " popa \n" - " iret \n" -); - -void InvalidSystemCall() { - kprintf("attempt was made to an invalid system call\n"); - return; -} - -typedef struct _UbixUser UbixUser; -struct _UbixUser { - char *username; - char *password; - int uid; - int gid; - char *home; - char *shell; -}; - -void sysAuth(UbixUser *uu) { - kprintf("authenticating user %s\n", uu->username); - - /* MrOlsen 2016-01-01 uh? - if(uu->username == "root" && uu->password == "user") - { - uu->uid = 0; - uu->gid = 0; - } - */ - uu->uid = -1; - uu->gid = -1; - return; -} - -void sysPasswd(char *passwd) { - kprintf("changing user password for user %d\n", _current->uid); - return; -} - -void sysAddModule() { - return; -} - -void sysRmModule() { - return; -} - -void sysGetpid(int *pid) { - if (pid) - *pid = _current->id; - return; -} - -void sysGetUid(int *uid) { - if (uid) - *uid = _current->uid; - return; -} - -void sysGetGid(int *gid) { - if (gid) - *gid = _current->gid; - return; -} - -void sysSetUid(int uid, int *status) { - if (_current->uid == 0x0) { - _current->uid = uid; - if (status) - *status = 0x0; - } - else { - if (status) - *status = 1; - } - return; -} - -void sysSetGid(int gid, int *status) { - if (_current->gid == 0x0) { - _current->gid = gid; - if (status) - *status = 0x0; - } - else { - if (status) - *status = 1; - } - return; -} - -void sysExit(int status) { - endTask(_current->id); -} - -void sysCheckPid(int pid, int *ptr) { - kTask_t *tmpTask = schedFindTask(pid); - if ((tmpTask != 0x0) && (ptr != 0x0)) - *ptr = tmpTask->state; - else - *ptr = 0x0; - return; -} - -/************************************************************************ - - Function: void sysGetFreePage(); - Description: Allocs A Page To The Users VM Space - Notes: - - ************************************************************************/ -void sysGetFreePage(long *ptr, int count, int type) { - if (ptr) { - if (type == 2) - *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_THRD); - else - *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_TASK); - } - return; -} - -void sysGetDrives(uInt32 *ptr) { - if (ptr) - *ptr = 0x0; //(uInt32)devices; - return; -} - -void sysGetUptime(uInt32 *ptr) { - if (ptr) - *ptr = systemVitals->sysTicks; - return; -} - -void sysGetTime(uInt32 *ptr) { - if (ptr) - *ptr = systemVitals->sysUptime + systemVitals->timeStart; - return; -} - -void sysGetCwd(char *data, int len) { - if (data) - sprintf(data, "%s", _current->oInfo.cwd); - return; -} - -void sysSchedYield() { - sched_yield(); -} - -void sysStartSDE() { - int i = 0x0; - for (i = 0; i < 1400; i++) { - asm("hlt"); - } - //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); - for (i = 0; i < 1400; i++) { - asm("hlt"); - } - return; -} - -void invalidCall(int sys_call) { - kprintf("Invalid System Call #[%i]\n", sys_call); - return; -} - -/*** - END - ***/ - diff --git a/sys/armv6/systemtask.c b/sys/armv6/systemtask.c deleted file mode 100644 index c0a999e..0000000 --- a/sys/armv6/systemtask.c +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static unsigned char *videoBuffer = (char *)0xB8000; - - -void systemTask() { - mpi_message_t myMsg; - uInt32 counter = 0x0; - int i = 0x0; - int *x = 0x0; - kTask_t *tmpTask = 0x0; - - if (mpi_createMbox("system") != 0x0) { - kpanic("Error: Error creating mailbox: system\n"); - } - - while(1) { - if (mpi_fetchMessage("system",&myMsg) == 0x0) { - kprintf("A"); - switch(myMsg.header) { - case 0x69: - x = (int *)&myMsg.data; - kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid); - schedFindTask(myMsg.pid)->term = tty_find(*x); - break; - case 1000: - kprintf("Restarting the system in 5 seconds\n"); - counter = systemVitals->sysUptime + 5; - while (systemVitals->sysUptime < counter) { - sched_yield(); - } - kprintf("Rebooting NOW!!!\n"); - while(inportByte(0x64) & 0x02); - outportByte(0x64, 0xFE); - break; - case 31337: - kprintf("system: backdoor opened\n"); - break; - case 0x80: - if (!strcmp(myMsg.data,"sdeStart")) { - kprintf("Starting SDE\n"); - //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); - } - else if (!strcmp(myMsg.data,"freePage")) { - kprintf("kkk Free Pages"); - } - else if (!strcmp(myMsg.data,"sdeStop")) { - printOff = 0x0; - biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0); - for (i=0x0;i<100;i++) asm("hlt"); - } - break; - default: - kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data); - break; - } - } - - /* - Here we get the next task from the delete task queue - we first check to see if it has an fd attached for the binary and after that - we free the pages for the process and then free the task - */ - tmpTask = sched_getDelTask(); - if (tmpTask != 0x0) { - if (tmpTask->files[0] != 0x0) - fclose(tmpTask->files[0]); - vmmFreeProcessPages(tmpTask->id); - kfree(tmpTask); - } - videoBuffer[0] = systemVitals->sysTicks; - sched_yield(); - } - - return; - } - -/*** - END - ***/ - diff --git a/sys/armv6/timer.S b/sys/armv6/timer.S deleted file mode 100644 index c7aa642..0000000 --- a/sys/armv6/timer.S +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors in the documentation and/or - * other materials provided with the distribution. - * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -.globl timerInt -.text -.code32 -timerInt: - pusha /* Save all of the registers */ - mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ - mov $0x20,%ax - outb %al,%dx - movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ - incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ - movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ - movl $200,%ebx /* Have Passed */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz next - incl 8(%ecx) -next: - movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ - movl 12(%ecx),%ebx /* We Can CALL sched */ - xor %edx,%edx - div %ebx - test %edx,%edx - jnz done - call sched -done: - popa /* Restore Registers */ - iret - -/*** - END - ***/ -