diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..af51e39 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +# The System Makefile (C) 2002-2004 The UbixOS Project +# +# $Id$ + +all: kernel tools + +kernel: src + (cd src/sys;make) + +tools: src + (cd src/tools;make) + +install: + (cd src/sys;make install) + +clean: + (cd src/sys;make clean) diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile index 8761f3b..81d0470 100644 --- a/src/sys/compile/Makefile +++ b/src/sys/compile/Makefile @@ -1,5 +1,6 @@ +# Kernel Makefile (C) 2002-2004 The UbixOS Project +# # $Id$ -# Kernel Makefile (C) 2002 The UbixOS Project # Include Global 'Source' Options include ../../Makefile.inc @@ -9,12 +10,10 @@ OBJS = null.o #Kernel Parts -KPARTS = ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../vfs/*.o ../ubixfs/*.o ../pci/*.o ../sde/*.o ../devfs/*.o ../net/core/*.o ../net/net/*.o ../net/api/*.o ../net/netif/*.o ../mpi/*.o ../ufs/*.o -#../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 +KPARTS = ../init/*.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 $@ diff --git a/src/sys/include/sys/gdt.h b/src/sys/include/sys/gdt.h new file mode 100644 index 0000000..8db1ee7 --- /dev/null +++ b/src/sys/include/sys/gdt.h @@ -0,0 +1,113 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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$ + +*****************************************************************************************/ + +#ifndef _GDT_H +#define _GDT_H + +/* Descriptor Definitions */ +#define dCall 0x0C00 /* 386 Call Gate */ +#define dCode 0x1800 /* Code Segment */ +#define dData 0x1000 /* Data Segment */ +#define dInt 0x0E00 /* 386 Interrupt Gate */ +#define dLdt 0x200 /* Local Descriptor Table (LDT) */ +#define dTask 0x500 /* Task gate */ +#define dTrap 0x0F00 /* 386 Trap Gate */ +#define dTss 0x900 /* Task State Segment (TSS) */ + +/* Descriptor Options */ +#define dDpl3 0x6000 /* DPL3 or mask for DPL */ +#define dDpl2 0x4000 /* DPL2 or mask for DPL */ +#define dDpl1 0x2000 /* DPL1 or mask for DPL */ +#define dDpl0 0x0000 /* DPL0 or mask for DPL */ +#define dPresent 0x8000 /* Present */ +#define dNpresent 0x8000 /* Not Present */ +#define dAcc 0x100 /* Accessed (Data or Code) */ +#define dWrite 0x200 /* Writable (Data segments only) */ +#define dRead 0x200 /* Readable (Code segments only) */ +#define dBusy 0xB00 /* Busy (TSS only) was 200 */ +#define dEexdown 0x400 /* Expand down (Data segments only) */ +#define dConform 0x400 /* Conforming (Code segments only) */ +#define dBig 0x40 /* Default to 32 bit mode */ +#define dBiglim 0x80 /* Limit is in 4K units */ + +/* GDT Descriptor */ +struct gdtDescriptor { + unsigned short limitLow; /* Limit 0..15 */ + unsigned short baseLow; /* Base 0..15 */ + unsigned char baseMed; /* Base 16..23 */ + unsigned char access; /* Access Byte */ + unsigned int limitHigh:4; /* Limit 16..19 */ + unsigned int granularity:4; /* Granularity */ + unsigned char baseHigh; /* Base 24..31 */ + } __attribute__ ((packed)); + +struct gdtGate { + unsigned short offsetLow; /* Offset 0..15 */ + unsigned short selector; /* Selector */ + unsigned short access; /* Access Flags */ + unsigned short offsetHigh; /* Offset 16..31 */ + } __attribute__ ((packed)); + +union descriptorTableUnion { + struct gdtDescriptor descriptor; /* Normal descriptor */ + struct gdtGate gate; /* Gate descriptor */ + unsigned long dummy; /* Any other info */ + }; + + +#define ubixDescriptorTable(name,length) union descriptorTableUnion name[length] = +#define ubixStandardDescriptor(base, limit, control) {descriptor: \ + {(limit & 0xffff), \ + (base & 0xffff), \ + ((base >> 16) & 0xff), \ + ((control+dPresent) >> 8), \ + (limit >> 16), \ + ((control & 0xff) >> 4), \ + (base >> 24)}} +#define ubixGateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \ + (control+dPresent), (offset >> 16) }} + +extern union descriptorTableUnion ubixGDT[9]; + +#endif + +/*** + $Log$ + Revision 1.5 2004/08/15 16:47:49 reddawg + Fixed + + Revision 1.4 2004/07/22 20:53:07 reddawg + atkbd: fixed problem + + Revision 1.3 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/init/Makefile b/src/sys/init/Makefile new file mode 100644 index 0000000..c3c2d99 --- /dev/null +++ b/src/sys/init/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = start.o main.o static.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/init/main.c b/src/sys/init/main.c new file mode 100644 index 0000000..3d7b74c --- /dev/null +++ b/src/sys/init/main.c @@ -0,0 +1,72 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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 + +/***************************************************************************************** + Desc: The Kernels Descriptor table: + 0x00 - Dummy Entry + 0x08 - Ring 0 CS + 0x10 - Ring 0 DS + 0x18 - Dummy LDT + 0x20 - Scheduler TSS + 0x28 - Ring 3 CS + 0x30 - Ring 3 DS + 0x38 - GPF TSS + 0x40 - Stack Fault TSS + + Notes: + +*****************************************************************************************/ +ubixDescriptorTable(ubixGDT,9) { + {dummy:0}, +#if 0 + ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dLdt)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), + ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), +#endif + }; +struct { + unsigned short limit __attribute__ ((packed)); + union descriptorTableUnion *gdt __attribute__ ((packed)); + } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; + +int main() { + while (1); + } + +/*** + END + ***/ + diff --git a/src/sys/init/start.S b/src/sys/init/start.S new file mode 100644 index 0000000..8a1d46b --- /dev/null +++ b/src/sys/init/start.S @@ -0,0 +1,58 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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$ + +*****************************************************************************************/ + +.globl _start +.text +.code32 +_start: + lgdtl (loadGDT) + mov $0x10,%eax + mov %eax,%ds + mov %eax,%es + mov %eax,%fs + mov %eax,%gs + mov %eax,%ss + mov $kStack,%eax + addl $0x2000,%eax + mov %eax,%esp + mov %eax,%ebp + mov $0x18,%ax + lldt %ax + mov $0x20,%ax + ltr %ax + ljmp $0x08,$start_next +start_next: + call main + +.data +.comm kStack,0x2000 + +/*** + END + ***/ diff --git a/src/sys/init/static.c b/src/sys/init/static.c new file mode 100644 index 0000000..11e4d9a --- /dev/null +++ b/src/sys/init/static.c @@ -0,0 +1,49 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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$ + +*****************************************************************************************/ + +int static_constructors(void) { + extern void (* __ctor_list)(); + void (** l_ctor)() = &__ctor_list; + int l_ctorCount = *(int *)l_ctor; + + l_ctor++; + while(l_ctorCount) + { + (*l_ctor)(); + l_ctorCount--; + l_ctor++; + } + + return 0; +} + +/*** + END + ***/ +