diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d9f7e23 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +# $Id$ +# The System Makefile (C) 2002, 2005 The UbixOS Project + +all: kernel + +kernel: src + (cd src/sys;make) + +install: + (cd src/sys;make install) + +clean: + (cd src/sys;make clean) + diff --git a/src/Makefile.inc b/src/Makefile.inc new file mode 100644 index 0000000..7d7c3f3 --- /dev/null +++ b/src/Makefile.inc @@ -0,0 +1,13 @@ +# $Id$ +# Global 'Source' Options +# (C) 2005 The UbixOS Project + +# allow you to change your default compiler without affecting your other work +CFLAGS = +CC = gcc +CXX = g++ +LD = ld +AR = ar +REMOVE = rm -rf + +FD_DEVICE = /dev/fd0 diff --git a/src/sys/Makefile b/src/sys/Makefile new file mode 100644 index 0000000..c1c237b --- /dev/null +++ b/src/sys/Makefile @@ -0,0 +1,23 @@ +# $Id$ +# Kernel Makefile (C) 2002, 2005 The UbixOS Project + +all: init-code sys-code kernel-img + +init-code: init + (cd init;make) + +sys-code: sys + (cd sys;make) + +kernel-img: compile + (/bin/echo "/* " > ./compile/null.c) + (date >> ./compile/null.c) + (echo $user >> ./compile/null.c) + (/bin/echo " */" >> ./compile/null.c) + (cd compile;make) + +clean: + (cd init;make clean) + (cd sys;make clean) + (cd compile;make clean) + diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc new file mode 100644 index 0000000..1deafc3 --- /dev/null +++ b/src/sys/Makefile.inc @@ -0,0 +1,6 @@ +# $Id: +# global 'sys' options + +INCLUDES = -I../include +CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O +KERNEL = ubix.elf diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile new file mode 100644 index 0000000..4e5c08f --- /dev/null +++ b/src/sys/compile/Makefile @@ -0,0 +1,38 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = null.o + +#Kernel Parts +KPARTS = ../init/*.o ../sys/*.o + +# Link the kernel statically with fixed text+data address @1M +$(KERNEL) : $(OBJS) + #$(LD) -nostdlib -nostdinc --warn-section-align -o $@ $(OBJS) $(KPARTS) -Ttext 0x30000 -Tdata 0x20000 + $(LD) -T ./ldscript.i386 -o $@ $(OBJS) $(KPARTS) + #/usr/bin/strip $@ + +# Compile the source files +.cc.o: + $(CXX) -${CFLAGS} $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) ${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) $(KERNEL) null.c diff --git a/src/sys/compile/ldscript.i386 b/src/sys/compile/ldscript.i386 new file mode 100644 index 0000000..731e787 --- /dev/null +++ b/src/sys/compile/ldscript.i386 @@ -0,0 +1,77 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) + +ENTRY(_start) +SEARCH_DIR("libgcc"); +SECTIONS +{ + . = 0x30000 + SIZEOF_HEADERS; + + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } + .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } + .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } + .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } + .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } + .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : { *(.init) } =0x9090 + .plt : { *(.plt) } + + /* text/read-only data */ + .text : { *(.text .gnu.linkonce.t.*) } =0x9090 + + .rodata : { *(.rodata) .rodata.* .gnu.linkonce.r.* } + + /* writable data */ + . = ALIGN(0x1000); + __data_start = .; + .data : { *(.data .gnu.linkonce.d.*) } + + __ctor_list = .; + .ctors : + { + LONG((__ctor_end - __ctor_list) / 4 - 2) + *(.ctors) + LONG(0) + } + __ctor_end = .; + + __dtor_list = .; + .dtors : + { + LONG((__dtor_end - __dtor_list) / 4 - 2) + *(.dtors) + LONG(0) + } + __dtor_end = .; + + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + + /* unintialized data (in same segment as writable data) */ + __bss_start = .; + .bss : { *(.bss) } + + . = ALIGN(0x1000); + _end = . ; + + /* Strip unnecessary stuff */ + /DISCARD/ : { *(.comment .note .eh_frame) } +} diff --git a/src/sys/sys/Makefile b/src/sys/sys/Makefile new file mode 100644 index 0000000..d98324f --- /dev/null +++ b/src/sys/sys/Makefile @@ -0,0 +1,27 @@ +# (C) 2002, 2005 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = io.o video.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.cc.s: + $(CXX) ${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/src/sys/sys/io.c b/src/sys/sys/io.c new file mode 100644 index 0000000..5ddaea4 --- /dev/null +++ b/src/sys/sys/io.c @@ -0,0 +1,146 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. 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. 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 COPYRIGHT HOLDERS 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. + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: inline unsigned char inportByte(unsigned int port); +Description: This Funciton Will Input One Byte From A Port +Notes: + +************************************************************************/ +unsigned char inportByte(unsigned int port) { + unsigned char retVal; + asm volatile( + "inb %%dx,%%al" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/************************************************************************ + +Function: inline unsigned char inportWord(unsigned int port); +Description: This Funciton Will Input One Word From A Port +Notes: + +************************************************************************/ +unsigned short inportWord(unsigned int port) { + unsigned short retVal; + asm volatile( + "inw %%dx,%%ax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/************************************************************************ + +Function: inline void outportByte(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Byte To A Port +Notes: + +************************************************************************/ +void outportByte(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportByteP(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Byte To A Port With A Delay +Notes: + +************************************************************************/ +void outportByteP(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx\n" + "outb %%al,$0x80\n" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportWord(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Word To A Port +Notes: + +************************************************************************/ +void outportWord(unsigned int port,unsigned short value) { + asm volatile( + "outw %%ax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportDWord(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One DWord To A Port +Notes: + +************************************************************************/ +void outportDWord(unsigned int port,unsigned long value) { + asm volatile( + "outl %%eax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline unsigned char inportDWord(unsigned int port); +Description: This Funciton Will Input One DWord From A Port +Notes: + +************************************************************************/ +unsigned long inportDWord(unsigned int port) { + unsigned long retVal; + asm volatile( + "inl %%dx,%%eax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/*** + END + ***/ diff --git a/src/sys/sys/video.c b/src/sys/sys/video.c new file mode 100644 index 0000000..d88ee49 --- /dev/null +++ b/src/sys/sys/video.c @@ -0,0 +1,121 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. 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. 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 COPYRIGHT HOLDERS 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static unsigned char *videoBuffer = (char *)0xB8000; +int printColor = defaultColor; + + +void backSpace() { + uInt32 bufferOffset = 0x0; + outportByte(0x3d4, 0x0e); + bufferOffset = inportByte(0x3d5); + bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */ + outportByte(0x3d4, 0x0f); + bufferOffset += inportByte(0x3d5); + bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */ + videoBuffer[bufferOffset--] = 0x20; + videoBuffer[bufferOffset--] = printColor; + videoBuffer[bufferOffset] = 0x20; + bufferOffset >>= 0x1; + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + return; + } + +void +kprint(char *string) +{ + + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + + /* We Need To Get The Y Position */ + outportByte(0x3D4, 0x0e); + bufferOffset = inportByte(0x3D5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + /* Then We Need To Add The X Position */ + outportByte(0x3D4, 0x0f); + bufferOffset += inportByte(0x3D5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + + while ((character = *string++)) { + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + videoBuffer[bufferOffset++] = character; + videoBuffer[bufferOffset++] = printColor; + break; + } /* switch */ + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + videoBuffer[i] = videoBuffer[i + 160]; + } /* for */ + for (i = 0; i < 80; i++) { + videoBuffer[(160 * 24) + (i * 2)] = 0x20; + videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; + } /* for */ + bufferOffset -= 160; + } /* if */ + } /* while */ + bufferOffset >>= 1; /* Set the new cursor position */ + + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + + return; +} + +/* Clears The Screen */ +void clearScreen() { + short i = 0x0; + + for (i = 0x0; i < (80 * 25); i++) { + videoBuffer[i * 2] = 0x20; + videoBuffer[i * 2 + 1] = defaultColor; + } + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, 0); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, 0); + } + +/*** + END + ***/