hurr derp

alentours-dev
Sergiusz Bazanski 2011-04-04 11:58:52 +02:00
parent b529e94df8
commit 0af44adf3c
42 changed files with 31312 additions and 34 deletions

View File

@ -19,11 +19,14 @@ CX:=$(ENV)/$(TARGET)-g++
AS:=nasm
LD:=$(ENV)/$(TARGET)-ld
# -O2 sets -foptimize-sibling-calls which breaks code...
CFLAGS:=-Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99 -g
CFLAGS+=-I ./include -Wno-packed-bitfield-compat
CFLAGS+=-I ./include -Wno-packed-bitfield-compat -O2 -fno-optimize-sibling-calls
CXFLAGS:= -Wall -Werror -nostdlib -fno-builtin -nostartfiles -I ./include
CXFLAGS+= -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector
CXFLAGS+= -Wno-packed-bitfield-compat
CXFLAGS+= -Wno-packed-bitfield-compat -O3
LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs
.PHONY: all clean kernel.bin emulate hdd.img

31189
dump Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
#ifndef __ATOMIC_OPERATIONS_H__
#define __ATOMIC_OPERATIONS_H__
#include "types.h"
typedef struct {
u32 Value;
} T_ATOMIC;
#define atomic_init(n) { (n) }
#define atomic_read(v) ((v)->Value)
#define atomic_set(v, n) (((v)->Value) = n)
static inline void atomic_add(T_ATOMIC Atom, u32 Value)
{
__asm__ volatile("lock addl %1, %0" : "+m"(Atom->Value) : "ir"(Value));
}
static inline void atomic_sub(T_ATOMIC Atom, u32 Value)
{
__asm__ volatile("lock subl %1, %0" : "+m"(Atom->Value) : "ir"(Value));
}
static inline void atomic_sub_and_test(T_ATOMIC Atom, u32 Value)
{
u8 C;
__asm__ volatile("lock subl %2, %0\n"
"sete %1\n"
: "+m"(Atom->Value), "=qm"(C)
: "ir" (Value) : "memory");
return C;
}
static inline void atomic_inc(T_ATOMIC Atom)
{
__asm__ volatile("lock incl %0" : "+m"(Atom->Value));
}
static inline void atomic_dec(T_ATOMIC Atom)
{
__asm__ volatile("lock decl %0" : "+m"(Atom->Value));
}
#endif

View File

@ -0,0 +1,17 @@
#ifndef __CSEMAPHORE_H__
#define __CSEMAPHORE_H__
#include "types.h"
namespace cb {
class CSemaphore {
private:
u32 m_Available;
public:
CSemaphore(u32 Available = 1);
void Acquire(void);
void Release(void);
};
};
#endif

BIN
kernel.bin Executable file

Binary file not shown.

BIN
obj/src/Tier0/_start.nao Normal file

Binary file not shown.

BIN
obj/src/Tier0/acpi.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/cpp.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/exceptions.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/gdt.nao Normal file

Binary file not shown.

BIN
obj/src/Tier0/gdt.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/heap.o Normal file

Binary file not shown.

Binary file not shown.

BIN
obj/src/Tier0/interrupts.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/kbd_layout.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/kmain.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/kstdio.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/kstdlib.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/paging.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/panic.o Normal file

Binary file not shown.

Binary file not shown.

BIN
obj/src/Tier0/pic.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/prng.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/ps2.o Normal file

Binary file not shown.

BIN
obj/src/Tier0/system.o Normal file

Binary file not shown.

Binary file not shown.

BIN
obj/src/Tier1/CKernel.xo Normal file

Binary file not shown.

BIN
obj/src/Tier1/CLogger.xo Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
obj/src/Tier1/CScheduler.xo Normal file

Binary file not shown.

BIN
obj/src/Tier1/CSemaphore.xo Normal file

Binary file not shown.

BIN
obj/src/Tier1/CTask.nao Normal file

Binary file not shown.

BIN
obj/src/Tier1/CTask.xo Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
obj/src/Tier1/new.xo Normal file

Binary file not shown.

View File

@ -101,10 +101,8 @@ void kmain(void *MultibootHeader, u32 Magic)
void kmain_newstack(void)
{
kprintf("[i] Now using real stack...\n");
cpp_call_ctors();
cpp_start_ckernel();
kprintf("[i] Returned from Tier1, sleeping forever.\n");
LOOPFOREVER;
}

View File

@ -33,7 +33,7 @@ CLogger &CKernel::Logger(void)
void CKernel::Start(void)
{
kprintf("[i] Hello from C++ land!\n");
if (m_Magic != CKERNEL_MAGIC)
{
kprintf("[e] Error! My constructor wasn't called properly.\n");
@ -52,7 +52,7 @@ void CKernel::Start(void)
m_DriverManager->LoadNew();
CTask *KernelTask = CreateKernelTask();
CScheduler::AddTask(KernelTask);
CScheduler::AddTask(KernelTask);
CScheduler::Enable();
CTask *ParentTask = CScheduler::GetCurrentTask();
@ -61,9 +61,9 @@ void CKernel::Start(void)
if (NewTask == ParentTask)
{
for (;;) {
for (u32 i = 0; i < 65000; i++)
for (volatile u32 i = 0; i < 350; i++)
{
for (u32 j = 0; j < 65; j++){}
for (volatile u32 j = 0; j < 650; j++){}
}
kprintf("[i] Hello! I'm the parent process.\n");
}
@ -71,9 +71,9 @@ void CKernel::Start(void)
else
{
for (;;) {
for (u32 i = 0; i < 65000; i++)
for (volatile u32 i = 0; i < 350; i++)
{
for (u32 j = 0; j < 65; j++){}
for (volatile u32 j = 0; j < 650; j++){}
}
kprintf("[i] Hello! I'm the child process.\n");
}

View File

@ -42,27 +42,19 @@ void CScheduler::AddTask(CTask *Task)
__asm__ volatile("sti");
}
void CScheduler::NextTask(void)
#pragma GCC optimize ("O0")
__attribute__((optimize("O0"))) void CScheduler::NextTask(void)
{
u32 NewEBP, NewESP, NewEIP, EBP, ESP, Directory;
__asm__ volatile("cli");
volatile u32 NewEBP, NewESP, NewEIP, EBP, ESP, Directory;
TTaskQueueNode *Next;
if (g_Scheduler.m_TaskQueueStart == 0)
/*if (g_Scheduler.m_TaskQueueStart == 0)
PANIC("No tasks in queue!");
if (g_Scheduler.m_TaskQueueCurrent == 0)
PANIC("Current task is null!");
// Return point
volatile u32 ReturnPoint = ctask_geteip();
if (ReturnPoint == 0xFEEDFACE)
{
//We are in the next task already
__asm__ volatile("mov %%esp, %0" : "=r"(ESP));
__asm__ volatile("mov %%ebp, %0" : "=r"(EBP));
return;
}
PANIC("Current task is null!");*/
// Fetch next task.
if (g_Scheduler.m_TaskQueueCurrent->Next == 0)
@ -70,15 +62,6 @@ void CScheduler::NextTask(void)
else
Next = g_Scheduler.m_TaskQueueCurrent->Next;
// Save current task details
__asm__ volatile("mov %%esp, %0" : "=r"(ESP));
__asm__ volatile("mov %%ebp, %0" : "=r"(EBP));
g_Scheduler.m_CurrentTask->m_EBP = EBP;
g_Scheduler.m_CurrentTask->m_ESP = ESP;
g_Scheduler.m_CurrentTask->m_EIP = ReturnPoint;
// Read task details
NewEBP = Next->Task->m_EBP;
NewESP = Next->Task->m_ESP;
@ -90,6 +73,24 @@ void CScheduler::NextTask(void)
return;
}
// Save current task details
__asm__ volatile("mov %%esp, %0" : "=r"(ESP));
__asm__ volatile("mov %%ebp, %0" : "=r"(EBP));
g_Scheduler.m_CurrentTask->m_EBP = EBP;
g_Scheduler.m_CurrentTask->m_ESP = ESP;
// Return point
volatile u32 ReturnPoint = ctask_geteip();
//kprintf("return point %x\n", ReturnPoint);
if (ReturnPoint == 0xFEEDFACE)
{
//We are in the next task already
return;
}
g_Scheduler.m_CurrentTask->m_EIP = ReturnPoint;
// Switch to next task
g_Scheduler.m_TaskQueueCurrent = Next;
g_Scheduler.m_CurrentTask = Next->Task;

25
src/Tier1/CSemaphore.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "Tier1/CSemaphore.h"
using namespace cb;
CSemaphore::CSemaphore(u32 Available)
{
m_Available = Available;
}
void CSemaphore::Acquire(void)
{
// Just spinlock...
while (1)
{
if (m_Available > 0)
{
m_Available--;
break;
}
}
}
void CSemaphore::Release(void)
{
m_Available++;
}