⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 service.c

📁 一个操作系统的源代码
💻 C
字号:
/** services.c                                **                                                               ** Original Author: Kasper Verdich Lund                          ** Date: 10.26.99      **  ** Description: **                                        ** Revision History:  ** First version      ** ** 0.0.1 10.26.99 Kasper Verdich Lund - (no comments) ** 0.0.2 12.22.99 Guido de Jong - more services implemented ** ** This program is free software, you can redistribute it and/or ** modify it under the terms of the GNU General Public License   ** as published by the Free Software Foundation; either version  ** 2 of the License, or (at your option) any later version.      **                                                               ** This program is distributed in the hope that it will be       ** useful, but WITHOUT ANY WARRANTY; without even the implied    ** warranty or MERCHANTABILITY or FITNESS FOR A PARTICULAR       ** PURPOSE.  See the GNU General Public License for more        ** details.                                                      **                                                               ** You should have received a copy of the GNU General Public     ** License along with this program; if not, write to the         ** Free Software Foundation, Inc., 59 Temple Place, Suite 330,   ** Boston, MA 02111-1307 USA                                     **                                                               *********************************************************Apostle OS**/#include <address_space.h>#include <gdt.h>#include <idt.h>#include <io.h>#include <ipc.h>#include <mem.h>#include <process.h>#include <scheduler.h>#include <service.h>#include <types.h>#ifdef DEBUG#include <debug/conio.h>#endif/* NOTICE: Services cannot use malloc or calloc yet. It * has to do with the fact that malloc or calloc might have * to map memory into the kernel vspace, and that this mapping * is not yet propagated correctly to all address spaces in * the system */void setupServices(void){  interruptIDT(&IDT[0x30], KERNEL_CS, (dword)&__SendTo, 3);  interruptIDT(&IDT[0x31], KERNEL_CS, (dword)&__ReceiveFrom, 3);  interruptIDT(&IDT[0x32], KERNEL_CS, (dword)&__CallRemote, 3);  interruptIDT(&IDT[0x33], KERNEL_CS, (dword)&__SendReceive, 3);  interruptIDT(&IDT[0x34], KERNEL_CS, (dword)&__Unmap, 3);  interruptIDT(&IDT[0x35], KERNEL_CS, (dword)&__CreateProcess, 3);  interruptIDT(&IDT[0x36], KERNEL_CS, (dword)&__Exit, 3);  interruptIDT(&IDT[0x37], KERNEL_CS, (dword)&__ProcessID, 3);  interruptIDT(&IDT[0x3a], KERNEL_CS, (dword)&__Yield, 3);  interruptIDT(&IDT[0x3b], KERNEL_CS, (dword)&__Sleep, 3);  interruptIDT(&IDT[0x40], KERNEL_CS, (dword)&__EnableMultithreading, 3);  interruptIDT(&IDT[0x41], KERNEL_CS, (dword)&__DisableMultithreading, 3);  interruptIDT(&IDT[0x90], KERNEL_CS, (dword)&__service0x90, 3);  interruptIDT(&IDT[0x91], KERNEL_CS, (dword)&__service0x91, 3); }void Unmap(dword eax, dword esi){#ifdef DEBUG  DebugPrintF("Unmap called\n");#endif  flush(currentProcess->addressSpace, FP_ADDR((FlexiblePage)esi),        FP_SIZE((FlexiblePage)esi), eax & UNMAP_PARTIAL, eax & UNMAP_METOO);}Process *CreateProcess(dword eax, dword esi){  Process *p = NewProcess();	/* this is a problem, see NOTICE */#ifdef DEBUG  DebugPrintF("Create Process called\n");#endif  map(currentProcess->addressSpace, FP_ADDR((FlexiblePage)esi),      p->addressSpace, (void *)0x20000000, FP_SIZE((FlexiblePage)esi),      eax & (PAGE_USER | PAGE_WRITABLE | PAGE_PRESENT));  InsertProcess(&readyQueue, p, FALSE);  return p;}void Exit(void){#ifdef DEBUG  DebugPrintF("Exit called\n");#endif  DeleteProcess(currentProcess);  Reallocate();}Process* ProcessID(void){#ifdef DEBUG  DebugPrintF("Get Process ID called\n");#endif  return currentProcess;}void Yield(dword edi, dword esi, dword ebp,           dword ebx, dword edx, dword ecx, dword eax,           dword eip, dword cs, dword eflags, dword esp, dword ss){#ifdef DEBUG  DebugPrintF("Yield called\n");#endif  /* save current state in ACB */  currentActivation->eax = eax;  currentActivation->ebx = ebx;  currentActivation->ecx = ecx;   currentActivation->edx = edx;  currentActivation->esi = esi;  currentActivation->edi = edi;  currentActivation->eflags = eflags;  currentActivation->eip = eip;  currentActivation->esp = esp;   currentActivation->ebp = ebp;  if (!currentProcess->singleThreaded)    {      currentProcess->deallocated = 1;      currentProcess->pendingUpcallType = Preempted;      currentProcess->pendingActivation = currentActivation;    }  InsertProcess(&readyQueue, currentProcess, FALSE);  Reallocate();}void Sleep(dword eax){#ifdef DEBUG  DebugPrintF("Sleep called (%d)\n", eax);#endif  Wait((int)eax, NULL, 0, 0);    }/* system call 0x40 - enable multithreading * parameters:  *   eax = upcall entry point * result: *   none */void EnableMultithreading(dword edi, dword esi, dword ebp, dword esp0,			  dword ebx, dword edx, dword ecx, dword eax,			  dword eip, dword cs, dword eflags, 			  dword esp, dword ss){#ifdef DEBUG  DebugPrintF("enable multithreading called: offset = 0x%08x\n", eax);#endif  if (currentProcess->singleThreaded)    {      currentProcess->singleThreaded = FALSE;      currentProcess->upcallOffset = eax;        currentActivation->eax = eax;      currentActivation->ebx = ebx;      currentActivation->ecx = ecx;       currentActivation->edx = edx;      currentActivation->esi = esi;      currentActivation->edi = edi;      currentActivation->eflags = eflags;      currentActivation->eip = eip;      currentActivation->esp = esp;       currentActivation->ebp = ebp;      InsertProcess(&readyQueue, currentProcess, FALSE);      Reallocate();    }  /* otherwise just return */}/* system call 0x41 - disable multithreading * parameters:  *   none * result: *   none */void DisableMultithreading(void){#ifdef DEBUG  DebugPrintF("disable multithreading called\n");#endif  if (!currentProcess->singleThreaded)    {      /* remove any activations to save memory       * and to make activation specific communication       * such as replies to calls fail        * activations blocked in kernel should also be removed       * to make kernel request fail */      currentProcess->singleThreaded = TRUE;      InsertProcess(&readyQueue, currentProcess, FALSE);      Reallocate();    }  /* otherwise just return */}void service0x90(void){  char *s = (char *)0xb8001;  (*s)++;}void service0x91(void){  char *s = (char *)0xb8003;  (*s)++;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -