Commit initial
This commit is contained in:
50
kernel/include/args.h
Normal file
50
kernel/include/args.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* args.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef ARGS_H
|
||||
#define ARGS_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/* Strcutres de r<>cup<75>ration de contexte */
|
||||
typedef struct {
|
||||
T_dword baseAddr_1;
|
||||
T_dword baseAddr_2;
|
||||
T_dword size_1;
|
||||
T_dword size_2;
|
||||
T_dword type;
|
||||
T_dword unused;
|
||||
}__attribute__((packed)) T_memMapEntry;
|
||||
|
||||
typedef struct {
|
||||
T_byte cursor_X;
|
||||
T_byte cursor_Y;
|
||||
T_dword phyMemSize;
|
||||
T_byte memListEntryNumber;
|
||||
T_dword initProcessAddr;
|
||||
T_dword initProcessSize;
|
||||
T_memMapEntry* memMap;
|
||||
}__attribute__((packed)) T_kernelArgs;
|
||||
|
||||
T_kernelArgs* args;
|
||||
|
||||
#endif
|
51
kernel/include/asm_x86.h
Normal file
51
kernel/include/asm_x86.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* asm_x86.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef ASM_X86_H
|
||||
#define ASM_X86_H
|
||||
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "interrupt.h"
|
||||
|
||||
void _loadGdtR(T_gdt*);
|
||||
void _loadTaskRegister();
|
||||
void _loadIdtR(T_idt*);
|
||||
void _clearInterrupt();
|
||||
void _startInterrupt();
|
||||
void _out(T_word, T_byte);
|
||||
T_byte _in(T_word);
|
||||
void _outw(T_word, T_word);
|
||||
T_word _inw(T_word);
|
||||
void _outdw(T_word, T_dword);
|
||||
T_dword _indw(T_word);
|
||||
void _enablePaging();
|
||||
void _emptyTLB();
|
||||
void _loadCr3(T_dword);
|
||||
T_dword _readCr3();
|
||||
T_dword _readCr2();
|
||||
T_dword _saveEflags();
|
||||
T_dword _restoreEflags(T_dword);
|
||||
T_dword _atomicTestAndSet(unsigned int*);
|
||||
T_dword _getStackFrameAddr(unsigned int);
|
||||
|
||||
#endif
|
32
kernel/include/elf_loader.h
Normal file
32
kernel/include/elf_loader.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* elf_loader.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef ELF_LOADER_H
|
||||
#define ELF_LOADER_H
|
||||
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
int ELF32_checkFile(void*);
|
||||
unsigned int ELF32_load(void*, T_list*);
|
||||
|
||||
#endif
|
99
kernel/include/interrupt.h
Normal file
99
kernel/include/interrupt.h
Normal file
@ -0,0 +1,99 @@
|
||||
/* interrupt.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef INTERRUPT_H
|
||||
#define INTERRUPT_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/* === Configuration du PIC 8259A === */
|
||||
|
||||
#define PIC_MASTER_CMD_REG 0x20
|
||||
#define PIC_MASTER_DATA_REG 0x21
|
||||
#define PIC_MASTER_IDT_OFFSET 0x20
|
||||
|
||||
#define PIC_SLAVE_CMD_REG 0xA0
|
||||
#define PIC_SLAVE_DATA_REG 0xA1
|
||||
#define PIC_SLAVE_IDT_OFFSET 0x28
|
||||
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
void PIC_init();
|
||||
void PIC_maskIRQ(T_byte);
|
||||
void PIC_sendEOI();
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
|
||||
/* ===== Manipulation de l'IDT ===== */
|
||||
|
||||
#define IDT_BASE 0x200800
|
||||
#define INT_DESC_SIZE 8
|
||||
#define IDT_SIZE 256
|
||||
|
||||
#define DIVIDE_BY_0_INT 0
|
||||
#define NMI_INT 2
|
||||
#define BREAKPOINT_INT 3
|
||||
#define OVERFLOW_INT 4
|
||||
#define INVALID_TSS_INT 10
|
||||
|
||||
#define SEG_FAULT_INT 11
|
||||
#define STACK_SEG_FAULT_INT 12
|
||||
#define GP_FAULT_INT 13
|
||||
#define PAGE_FAULT_INT 14
|
||||
|
||||
#define TIMER_INT 32
|
||||
#define KB_INT 33
|
||||
#define SYS_CALL_INT 64
|
||||
|
||||
typedef struct {
|
||||
T_word offset0_15;
|
||||
T_word segment;
|
||||
T_word type;
|
||||
T_word offset16_31;
|
||||
}__attribute__((packed)) T_IDT_desc;
|
||||
|
||||
typedef struct {
|
||||
T_word limite;
|
||||
T_dword base;
|
||||
}__attribute__((packed)) T_IDT_reg;
|
||||
|
||||
|
||||
void IDT_init();
|
||||
void IDT_createDesc(T_dword, T_word, T_word, unsigned int);
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
|
||||
/* Routine d'interruption en assembleur (redirection vers routines en C) */
|
||||
|
||||
void _defaultInt();
|
||||
void _SEG_fault();
|
||||
void _GP_fault();
|
||||
void _page_fault();
|
||||
void _clockInterrupt();
|
||||
void _syscall();
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
|
||||
#endif
|
31
kernel/include/ipc.h
Normal file
31
kernel/include/ipc.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* ipc.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef IPC_H
|
||||
#define IPC_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void IPC_mutexLock(unsigned int*);
|
||||
void IPC_mutexUnlock(unsigned int*);
|
||||
|
||||
#endif
|
223
kernel/include/memory.h
Normal file
223
kernel/include/memory.h
Normal file
@ -0,0 +1,223 @@
|
||||
/* memory.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/* ###### Main Memory Management ###### */
|
||||
#define KERNEL_SPACE_SIZE 0x10000000 /* Mémoire potentiellement utilisable par le kernel, adresse virtuelle de fin de l'espace noyau, aligné sur 4 Mo */
|
||||
|
||||
/* Configation dynamique */
|
||||
#define KERNEL_SPACE_PT_COUNT (KERNEL_SPACE_SIZE / (PAGE_PER_PT * PAGE_SIZE))
|
||||
#define KERNEL_SPACE_PAGE_COUNT (KERNEL_SPACE_PT_COUNT * PAGE_PER_PT)
|
||||
|
||||
#define KERNEL_PHY_SPACE_SIZE (KERNEL_PT_ADDR + (KERNEL_SPACE_PT_COUNT * PT_SIZE))
|
||||
#define KERNEL_PHY_SPACE_PAGE_COUNT (KERNEL_PHY_SPACE_SIZE / PAGE_SIZE)
|
||||
|
||||
#define KERNEL_VM_SIZE (KERNEL_SPACE_SIZE - KERNEL_PHY_SPACE_SIZE)
|
||||
#define KERNEL_VM_PAGE_COUNT (KERNEL_VM_SIZE / PAGE_SIZE)
|
||||
/* ----------------------- */
|
||||
|
||||
/* Configation statique */
|
||||
#define KERNEL_PD_ADDR 0x303000
|
||||
#define KERNEL_PT_ADDR 0x304000
|
||||
|
||||
#define PD_SIZE 4096
|
||||
#define PT_SIZE 4096
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#define MAX_PT_COUNT 1024
|
||||
#define MAX_PAGE_COUNT 1048576
|
||||
|
||||
#define PAGE_OFFSET_BITS 12
|
||||
#define PAGE_PER_PT 1024
|
||||
/* ----------------------- */
|
||||
|
||||
/* Special types */
|
||||
typedef T_dword T_page;
|
||||
typedef T_Page* T_pageTable;
|
||||
typedef T_pageTable* T_pageDir;
|
||||
/* ----------------------- */
|
||||
|
||||
#ifdef MEMORY_PRIVATE
|
||||
T_PageDirectory kpageDir;
|
||||
T_PageTable kageTable;
|
||||
unsigned int KernPageTableMutex;
|
||||
#endif
|
||||
|
||||
void kinitSpace();
|
||||
unsigned int kaddPage(T_Page);
|
||||
void kremovePage(T_Page);
|
||||
T_Page kgetPage();
|
||||
void* kgetPhyAddr(void*);
|
||||
|
||||
/* ##################################### */
|
||||
|
||||
|
||||
|
||||
/* ###### Segment Management ###### */
|
||||
|
||||
#define GDT_BASE 0x200000
|
||||
#define SEG_DESC_SIZE 8
|
||||
#define SEG_DESC_NUMBER 256
|
||||
|
||||
#define MAIN_KERNEL_STACK 0xA0000
|
||||
|
||||
#define TSS_BASE 0x201000
|
||||
|
||||
struct MemSegDescriptor
|
||||
{
|
||||
bits16 limite0_15;
|
||||
bits16 base0_15;
|
||||
bits8 base16_23;
|
||||
bits8 acces;
|
||||
bits8 limite16_19:4;
|
||||
bits8 other:4;
|
||||
bits8 base24_31;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct GdtReg
|
||||
{
|
||||
bits16 limite;
|
||||
bits32 base;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct TaskStateSegment
|
||||
{
|
||||
bits16 prevTask;
|
||||
bits16 reserved_1;
|
||||
bits32 esp0;
|
||||
bits16 ss0;
|
||||
bits16 reserved_2;
|
||||
bits32 esp1;
|
||||
bits16 ss1;
|
||||
bits16 reserved_3;
|
||||
bits32 esp2;
|
||||
bits16 ss2;
|
||||
bits16 reserved_4;
|
||||
bits32 cr3;
|
||||
bits32 eip;
|
||||
bits32 eflags;
|
||||
bits32 eax;
|
||||
bits32 ecx;
|
||||
bits32 edx;
|
||||
bits32 ebx;
|
||||
bits32 esp;
|
||||
bits32 ebp;
|
||||
bits32 esi;
|
||||
bits32 edi;
|
||||
bits16 es;
|
||||
bits16 reserved_5;
|
||||
bits16 cs;
|
||||
bits16 reserved_6;
|
||||
bits16 ss;
|
||||
bits16 reserved_7;
|
||||
bits16 ds;
|
||||
bits16 reserved_8;
|
||||
bits16 fs;
|
||||
bits16 reserved_9;
|
||||
bits16 gs;
|
||||
bits16 reserved_10;
|
||||
bits16 ldtSegSelect;
|
||||
bits16 reserved_11;
|
||||
bits16 flagDebug;
|
||||
bits16 io_map;
|
||||
}__attribute__((packed));
|
||||
|
||||
/* Special types */
|
||||
typedef struct MemSegDescriptor T_GdtDesc;
|
||||
typedef struct GdtReg T_GDT;
|
||||
typedef struct TaskStateSegment T_TSS;
|
||||
/* ----------------------- */
|
||||
|
||||
T_TSS *tss;
|
||||
|
||||
void InitGDT();
|
||||
void CreateSegDescriptor(bits32, bits32, bits8, bits8, unsigned int);
|
||||
|
||||
/* ##################################### */
|
||||
|
||||
|
||||
|
||||
/* ###### Page Management ###### */
|
||||
|
||||
#ifdef MEMORY_PRIVATE
|
||||
#define PHY_PAGE_MAP_ADDR 0x203000
|
||||
|
||||
#define PAGE_FREE 0
|
||||
#define PAGE_USED 1
|
||||
#define PAGE_NOT_PRESENT 4
|
||||
bits8 *PageMap;
|
||||
unsigned int PhyPageMapMutex;
|
||||
#endif
|
||||
|
||||
#define PAGE_FLAG_PRESENT 1
|
||||
#define PAGE_FLAG_RW 2
|
||||
#define PAGE_FLAG_USER 4
|
||||
|
||||
T_Page GetPhyPage();
|
||||
void ReleasePhyPage(T_Page);
|
||||
|
||||
/* ##################################### */
|
||||
|
||||
|
||||
|
||||
/* ###### Alloc Management ###### */
|
||||
|
||||
#ifdef MEMORY_PRIVATE
|
||||
#define FREE 0
|
||||
#define USED 1
|
||||
|
||||
unsigned int KERNEL_HEAP_BASE;
|
||||
unsigned int KERNEL_HEAP_LIMIT;
|
||||
|
||||
struct AllocAreaModel {
|
||||
T_byte state; /* 1:used 0:free */
|
||||
struct AllocAreaModel *next;
|
||||
}__attribute__((packed));
|
||||
|
||||
unsigned int AllocMutex;
|
||||
#endif
|
||||
|
||||
void* malloc(unsigned int);
|
||||
void free(void*);
|
||||
struct AllocAreaModel* EnlargeHeap();
|
||||
|
||||
/* ##################################### */
|
||||
|
||||
|
||||
|
||||
/* ###### Paging Management ###### */
|
||||
|
||||
T_PageDirectory CreateTaskPageDirectory();
|
||||
void DestroyTaskPageDirectory(T_PageDirectory);
|
||||
unsigned int AddPage(T_Page, bits32);
|
||||
void RemovePage(T_Page);
|
||||
unsigned int LinkPhyPage(T_Page, T_Page, bits32);
|
||||
void UnlinkPhyPage(T_Page);
|
||||
void* GetPhyAddr(void*);
|
||||
|
||||
/* ##################################### */
|
||||
|
||||
#endif
|
58
kernel/include/print.h
Normal file
58
kernel/include/print.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* print.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "types.h"
|
||||
|
||||
#define TEXTCOLOR_BLACK 0x0
|
||||
#define TEXTCOLOR_DARK_BLUE 0x1
|
||||
#define TEXTCOLOR_DARK_GREEN 0x2
|
||||
#define TEXTCOLOR_DARK_CYAN 0x3
|
||||
#define TEXTCOLOR_DARK_RED 0x4
|
||||
#define TEXTCOLOR_DARK_MAGENTA 0x5
|
||||
#define TEXTCOLOR_DARK_BROWN 0x6
|
||||
#define TEXTCOLOR_DARK_GRAY 0x8
|
||||
#define TEXTCOLOR_LIGHT_GRAY 0x7
|
||||
#define TEXTCOLOR_LIGHT_BLUE 0x9
|
||||
#define TEXTCOLOR_LIGHT_GREEN 0xA
|
||||
#define TEXTCOLOR_LIGHT_CYAN 0xB
|
||||
#define TEXTCOLOR_LIGHT_RED 0xC
|
||||
#define TEXTCOLOR_LIGHT_MAGENTA 0xD
|
||||
#define TEXTCOLOR_LIGHT_YELLOW 0xE
|
||||
#define TEXTCOLOR_WHITE 0xF
|
||||
|
||||
#define BACK_BLUE 0x1
|
||||
#define BACK_GREEN 0x2
|
||||
#define BACK_CYAN 0x3
|
||||
#define BACK_RED 0x4
|
||||
#define BACK_MAGENTA 0x5
|
||||
#define BACK_BROWN 0x6
|
||||
#define BACK_GRAY 0x7
|
||||
|
||||
void printError(char*, ...);
|
||||
void print(char*, ...);
|
||||
void printColor(char*, T_byte, ...);
|
||||
|
||||
#endif
|
126
kernel/include/process.h
Normal file
126
kernel/include/process.h
Normal file
@ -0,0 +1,126 @@
|
||||
/* process.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
#include "ipc.h"
|
||||
|
||||
|
||||
#define USER_SPACE_BASE_ADDR (KERNEL_SPACE_SIZE)
|
||||
#define USER_STACK_ADDR 0xFFBFF000
|
||||
#define USER_SPACE_END_ADDR 0xFFBFE000
|
||||
|
||||
#define PROCESS_STATUS_RUNNING 0
|
||||
#define PROCESS_STATUS_WAIT_MUTEX 1
|
||||
#define PROCESS_STATUS_SLEEP 2
|
||||
#define PROCESS_STATUS_ZOMBIE 3
|
||||
|
||||
struct ProcessModel
|
||||
{
|
||||
struct ProcessModel* next; /* 0 */
|
||||
struct ProcessModel* prev; /* 4 */
|
||||
|
||||
bits32 reg_EAX; /* 8 */
|
||||
bits32 reg_EBX; /* 12 */
|
||||
bits32 reg_ECX; /* 16 */
|
||||
bits32 reg_EDX; /* 20 */
|
||||
bits32 reg_ESI; /* 24 */
|
||||
bits32 reg_EDI; /* 28 */
|
||||
bits32 reg_EBP; /* 32 */
|
||||
bits32 reg_ESP; /* 36 */
|
||||
bits32 reg_EIP; /* 40 */
|
||||
bits32 reg_EFLAGS; /* 44 */
|
||||
bits16 reg_CS; /* 48 */
|
||||
bits16 reg_DS; /* 50 */
|
||||
bits16 reg_ES; /* 52 */
|
||||
bits16 reg_FS; /* 54 */
|
||||
bits16 reg_GS; /* 56 */
|
||||
bits16 reg_SS; /* 58 */
|
||||
bits32 reg_CR3; /* 60 */
|
||||
|
||||
bits32 kernelStackPtr;
|
||||
T_PageDirectory pageDir;
|
||||
T_LinkedList processRegionsList;
|
||||
|
||||
unsigned int pid;
|
||||
struct ProcessModel* parent;
|
||||
T_LinkedList processChildrenList;
|
||||
unsigned int signal;
|
||||
void* signalAction[32];
|
||||
|
||||
bits8 status; /* 0:actif 1:wait mutex 2:sleep 3:zombie */
|
||||
unsigned int* ipcWaitMutex;
|
||||
unsigned int ipcInSection;
|
||||
};
|
||||
typedef struct ProcessModel T_Process;
|
||||
|
||||
#ifdef PROCESS_PRIVATE
|
||||
#define PROCESS_REGION_RO 0
|
||||
#define PROCESS_REGION_RW 1
|
||||
#define PROCESS_REGION_HEAP 3
|
||||
|
||||
struct ProcessRegion
|
||||
{
|
||||
struct ProcessRegion* next;
|
||||
struct ProcessRegion* prev;
|
||||
T_Page startPage;
|
||||
T_Page endPage;
|
||||
unsigned char type;
|
||||
};
|
||||
|
||||
struct ProcessChild
|
||||
{
|
||||
struct ProcessChild* next;
|
||||
struct ProcessChild* prev;
|
||||
T_Process* process;
|
||||
};
|
||||
|
||||
unsigned int PidCounter;
|
||||
#endif
|
||||
|
||||
T_LinkedList Processes;
|
||||
T_Process* CurrentProcess;
|
||||
T_Process Process_0;
|
||||
|
||||
void InitProcessManager();
|
||||
unsigned int CreateProcess(void*);
|
||||
|
||||
/* Fonctions éxécutées par le processus lui meme */
|
||||
void DestroyProcess();
|
||||
unsigned int ProcessCreateRegion_RO(T_Page, T_Page*, unsigned int, T_LinkedList*);
|
||||
unsigned int ProcessCreateRegion_RW(T_Page, unsigned int, T_LinkedList*);
|
||||
void ProcessRemoveRegion(T_Page, unsigned int, T_LinkedList*);
|
||||
/* ############################################# */
|
||||
|
||||
/* Fonctions d'ordonnancement */
|
||||
void _LoadContext(T_Process*);
|
||||
bits32* _SaveContex();
|
||||
T_Process* SchedulingAlgorithm();
|
||||
void Schedule();
|
||||
void ScheduleAtClock();
|
||||
/* ############################################# */
|
||||
|
||||
#endif
|
40
kernel/include/signal.h
Normal file
40
kernel/include/signal.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* signal.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef SIGNAL_H
|
||||
#define SIGNAL_H
|
||||
|
||||
#include "process.h"
|
||||
|
||||
/* Du plus important au moins important */
|
||||
#define SIGNAL_KILL 0
|
||||
#define SIGNAL_TERM 1
|
||||
#define SIGNAL_KCHILD 2
|
||||
|
||||
void SendSignal(unsigned int, T_Process*);
|
||||
void ClearSignal(unsigned int, T_Process*);
|
||||
unsigned int FetchSignal(unsigned int, T_Process*);
|
||||
|
||||
void HandleSignal(unsigned int, T_Process*);
|
||||
|
||||
#endif
|
31
kernel/include/types.h
Normal file
31
kernel/include/types.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* types.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
typedef unsigned char T_byte;
|
||||
typedef unsigned short T_word;
|
||||
typedef unsigned int T_dword;
|
||||
|
||||
#endif
|
||||
|
57
kernel/include/utils.h
Normal file
57
kernel/include/utils.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* utils.h - This file is a part of NutsOS
|
||||
*
|
||||
* NutsOS
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* NutsOS 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NutsOS 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
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void memcopy(char*, char*, unsigned int);
|
||||
int strcmp(char*, char*);
|
||||
void IntToChar(bits32, char*, int);
|
||||
unsigned int expo(unsigned int, unsigned int);
|
||||
|
||||
struct List
|
||||
{
|
||||
unsigned int entryCount;
|
||||
struct ElementModel *firstEntry;
|
||||
struct ElementModel *lastEntry;
|
||||
};
|
||||
|
||||
typedef struct List T_LinkedList;
|
||||
|
||||
struct ElementModel
|
||||
{
|
||||
struct ElementModel *next;
|
||||
struct ElementModel *prev;
|
||||
}__attribute__((packed));
|
||||
|
||||
void LinkedListPushFront(void*, T_LinkedList*);
|
||||
void LinkedListPopFront(T_LinkedList*);
|
||||
void LinkedListPushBack(void*, T_LinkedList*);
|
||||
void LinkedListPopBack(T_LinkedList*);
|
||||
void LinkedListInsert(void*, void*, void*, T_LinkedList*);
|
||||
void LinkedListRemove(void*, T_LinkedList*);
|
||||
|
||||
void InsertElement(void*, void*, void*);
|
||||
void RemoveElement(void*);
|
||||
#endif
|
Reference in New Issue
Block a user