[Prev][Next][Index][Thread]

Re: request for your source code




sorry to persons are not interested to this code,
Task.c it is main kernel file,
Gnuxxx make files

Run:
	make a directory with name oskit/example/x86/sharif in your
	oskit source files, then copy these files there.
	make Task or make will make for you  a multi tasking kernel
	that its task run in user mode.

ToDO:
	1. I'm trying to enable paging before creating task,
	2. also I want to have user process in oskit without 
	using TSS structure because as some of guy said to me
	using TSS is very expensive.
/*
*	User Task & Multi tasking system.
*	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*	Written By Mahmoud Taghizadeh.
*/
//				asm ("ljmp %0, $0"::"g"(BASE_TSS));

#include <stdio.h>
#include <oskit/machine/base_cpu.h>
#include <oskit/x86/pmode.h>
#include <oskit/x86/base_gdt.h>
#include <oskit/machine/base_vm.h>
#include <oskit/x86/tss.h>
#include <oskit/x86/base_tss.h>
#include <oskit/dev/dev.h>
#include <oskit/x86/proc_reg.h>
#include <oskit/x86/base_idt.h>
#include <oskit/debug.h>
#include <oskit/x86/pio.h>
#include <oskit/x86/pc/pit.h>
#include <oskit/x86/eflags.h>
#include <oskit/x86/pc/base_irq.h>
#include <oskit/x86/base_trap.h>
#include <oskit/x86/trap.h>

#define SHARIF_TSS_2 0x58
	
CODE32
extern  oskit_addr_t sharif_pdir_pa;	
struct x86_tss scheduler_tss1;
struct x86_tss my_tss;

long dataseg[100];
long mydataseg[100];

void delay(void) {
	unsigned int i,j, k;
	for (i = 0; i < 30000; ++i)
		for (j = 0; j < 500; ++j)
			k = k +1;
}

int sv = 0;
unsigned long count = 0;

void user_code(void) {
	while (1) {
		delay()	;
		printf("User Code \n");
	}
}

void scheduler(void) 
{
	while (1) {
		if (++count  > 50) {
			count = 0;
			sv++;
			if (sv % 2 ) {
//	I use CurCol for change color of printed message,
//	this variable is undefined in standard oskit code.
//				CurCol = 0x0C;
				base_gdt[SHARIF_TSS / 8].access |= 
					ACC_TSS_BUSY;
				scheduler_tss1.back_link = SHARIF_TSS;
			} else {
//				CurCol = 0x0F;
				scheduler_tss1.back_link = BASE_TSS;
				base_gdt[BASE_TSS / 8].access |= 
					ACC_TSS_BUSY;
			}
		}
		outb(0x20, 0x20);
		asm ("iret");
	}
}
	
void main (void) {
	
	if (i16_get_msw() & CR0_PE)
		printf("The processor is in protected mode environment.\n");
	
	base_gdt_init();
	base_gdt_load();
	base_tss_init();
	base_tss_load();
/*TASK descriptor*/	
/*
	We have 3 task.
	main task.
	scheduler
	sharif task.
*/

	fill_descriptor(&base_gdt[SHARIF_TSS_2 / 8], 
		kvtolin(&scheduler_tss1), sizeof(scheduler_tss1) - 1, 
		ACC_PL_U | ACC_TSS | ACC_P, 0);

	fill_descriptor(&base_gdt[SHARIF_TSS / 8], 
		kvtolin(&my_tss), sizeof(my_tss) - 1, 
		ACC_PL_U | ACC_TSS | ACC_P, 0);

/*user-mode descriptor*/
	fill_descriptor(&base_gdt[USER_CS / 8],
			0x00000000, 0xffffffff,
			ACC_PL_U | ACC_CODE_R, SZ_32);
	fill_descriptor(&base_gdt[USER_DS / 8],
			0x00000000, 0xffffffff,
			ACC_PL_U | ACC_DATA_W, SZ_32);

	base_tss.eflags = base_tss.eflags | 0x202 ;
	
	scheduler_tss1.eip = (long)&scheduler;
	scheduler_tss1.cs  = KERNEL_CS;
	scheduler_tss1.es  = KERNEL_DS;
	scheduler_tss1.ds  = KERNEL_DS;
	scheduler_tss1.ss  = KERNEL_DS;
	scheduler_tss1.fs  = KERNEL_DS;
	scheduler_tss1.gs  = KERNEL_DS;
	scheduler_tss1.ss0 = KERNEL_DS;
	scheduler_tss1.ss1 = KERNEL_DS;
	scheduler_tss1.ss2 = KERNEL_DS;
	scheduler_tss1.esp =  sizeof(dataseg) * 100 + (long)dataseg; 
	scheduler_tss1.esp0 = sizeof(dataseg) * 100 + (long)dataseg;
	scheduler_tss1.esp1 = sizeof(dataseg) * 100 + (long)dataseg;
	scheduler_tss1.esp2 = sizeof(dataseg) * 100 + (long)dataseg;
	scheduler_tss1.io_bit_map_offset = sizeof(scheduler_tss1);
	scheduler_tss1.ldt = 0;
	scheduler_tss1.eflags = 0x202;
	base_gdt[SHARIF_TSS_2 / 8].access &= ~ACC_TSS_BUSY;

	my_tss.eip = (long)&user_code;
	my_tss.cs  =  USER_CS;
	my_tss.es  =  USER_DS;
	my_tss.ds  =  USER_DS;
	my_tss.ss  =  USER_DS;
	my_tss.fs  =  USER_DS;
	my_tss.gs  =  USER_DS;
	my_tss.ss0 =  KERNEL_DS;
	my_tss.ss1 =  KERNEL_DS;
	my_tss.ss2 =  KERNEL_DS;
	my_tss.esp =  sizeof(mydataseg) * 100 + (long)mydataseg;   
	my_tss.esp0 = sizeof(mydataseg) * 100 + (long)mydataseg;
	my_tss.esp1 = sizeof(mydataseg) * 100 + (long)mydataseg;      
	my_tss.esp2 = sizeof(mydataseg) * 100 + (long)mydataseg;   
	my_tss.io_bit_map_offset = sizeof(my_tss);
	my_tss.ldt = 0;
/*
	Its for using in/out instruction in user mode program.
*/
	my_tss.eflags = 0x202 | EFL_IOPL_USER; 
	base_gdt[SHARIF_TSS / 8].access &= ~ACC_TSS_BUSY;
	osenv_intr_disable();
	fill_gate(&base_idt[irq_master_base + 0], 0, SHARIF_TSS_2, 
		ACC_TASK_GATE | ACC_PL_K, 0);

	pit_init(100);
	osenv_irq_enable(0);
	osenv_intr_enable();   
	
	while (1) {
		delay();	
		printf("Main program \n");
	}
	
	printf("Never reach here \n");
	return;
}
	
	
ifndef _oskit_examples_x86_makerules_
_oskit_examples_x86_makerules__ = yes

TARGETS = Task

all: $(TARGETS)

SRCDIRS +=	$(OSKIT_SRCDIR)/examples/x86
INCDIRS +=	$(OSKIT_SRCDIR)/oskit/c	
CLEAN_FILES +=	$(TARGETS) *.gdb
OSKIT_CFLAGS += -DOSKIT

#
# The C library is made up of several pieces. The core library, the
# POSIX interface that converts syscalls to COM, and the actual COM 
# interfaces. Note that the C library is built with the COM library.
#
CLIB   = -loskit_c 
CLIB_P = -loskit_c_p -loskit_gprof -loskit_c_p -loskit_kern_p

FOBJS = sharif_trap_align.o sharif_trap_bound.o sharif_trap_debug.o \
sharif_trap_dfault.o sharif_trap_divide.o sharif_trap_float.o \
sharif_trap_fpu.o sharif_trap_int3.o sharif_trap_invalop.o \
sharif_trap_invaltss.o sharif_trap_machine.o sharif_trap_nmi.o \
sharif_trap_nofpu.o sharif_trap_overflow.o sharif_trap_pagefault.o \
sharif_trap_protec.o sharif_trap_signopres.o sharif_trap_stack.o \
sharif_traps.o



include $(OSKIT_SRCDIR)/GNUmakerules

DEPENDLIBS = $(filter %.a, $(foreach DIR,$(LIBDIRS),$(wildcard $(DIR)/*)))

# XXX requires -lgcc for long long ops
LIBGCC := `$(CC) --print-libgcc-file-name`

Sharif: $(OBJDIR)/lib/multiboot.o sharif.o timer.o anno_test.o anno_asm.o direct.o trap_dump.o $(FOBJS) $(DEPENDLIBS)
	$(LD) -Ttext 100000 $(LDFLAGS) $(OSKIT_LDFLAGS) -o $@ $(filter-out %.a,$^)\
		-loskit_startup -loskit_clientos -loskit_amm -loskit_dev -loskit_kern -loskit_lmm $(CLIB) $(OBJDIR)/lib/crtn.o

Task: $(OBJDIR)/lib/multiboot.o Task.o paging_sharif.o $(DEPENDLIBS)
	$(LD) -Ttext 100000 $(LDFLAGS) $(OSKIT_LDFLAGS) -o $@ $(filter-out %.a,$^)\
		-loskit_startup -loskit_clientos -loskit_amm -loskit_dev -loskit_kern -loskit_lmm $(CLIB) -loskit_kern $(OBJDIR)/lib/crtn.o

endif
#
# Copyright (c) 1996, 1998 University of Utah and the Flux Group.
# All rights reserved.
# 
# This file is part of the Flux OSKit.  The OSKit is free software, also known
# as "open source;" you can redistribute it and/or modify it under the terms
# of the GNU General Public License (GPL), version 2, as published by the Free
# Software Foundation (FSF).  To explore alternate licensing terms, contact
# the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
# 
# The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
# received a copy of the GPL along with the OSKit; see the file COPYING.  If
# not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
#

#### Start of configuration section ####

OSKIT_SRCDIR	= ../../..
OBJDIR		= ../../..

prefix		= /usr/local
exec_prefix	= ${prefix}

include $(OBJDIR)/Makeconf

##### End of configuration section #####

#include $(OSKIT_SRCDIR)/examples/$(HOST_ARCH)/sharif/GNUmakerules
include GNUmakerules