hurr derp
parent
b529e94df8
commit
0af44adf3c
7
Makefile
7
Makefile
|
@ -19,11 +19,14 @@ CX:=$(ENV)/$(TARGET)-g++
|
||||||
AS:=nasm
|
AS:=nasm
|
||||||
LD:=$(ENV)/$(TARGET)-ld
|
LD:=$(ENV)/$(TARGET)-ld
|
||||||
|
|
||||||
|
# -O2 sets -foptimize-sibling-calls which breaks code...
|
||||||
CFLAGS:=-Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99 -g
|
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:= -Wall -Werror -nostdlib -fno-builtin -nostartfiles -I ./include
|
||||||
CXFLAGS+= -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector
|
CXFLAGS+= -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector
|
||||||
CXFLAGS+= -Wno-packed-bitfield-compat
|
CXFLAGS+= -Wno-packed-bitfield-compat -O3
|
||||||
LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs
|
LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs
|
||||||
|
|
||||||
.PHONY: all clean kernel.bin emulate hdd.img
|
.PHONY: all clean kernel.bin emulate hdd.img
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -101,10 +101,8 @@ void kmain(void *MultibootHeader, u32 Magic)
|
||||||
void kmain_newstack(void)
|
void kmain_newstack(void)
|
||||||
{
|
{
|
||||||
kprintf("[i] Now using real stack...\n");
|
kprintf("[i] Now using real stack...\n");
|
||||||
|
|
||||||
cpp_call_ctors();
|
cpp_call_ctors();
|
||||||
cpp_start_ckernel();
|
cpp_start_ckernel();
|
||||||
|
|
||||||
kprintf("[i] Returned from Tier1, sleeping forever.\n");
|
kprintf("[i] Returned from Tier1, sleeping forever.\n");
|
||||||
LOOPFOREVER;
|
LOOPFOREVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,9 @@ void CKernel::Start(void)
|
||||||
if (NewTask == ParentTask)
|
if (NewTask == ParentTask)
|
||||||
{
|
{
|
||||||
for (;;) {
|
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");
|
kprintf("[i] Hello! I'm the parent process.\n");
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,9 @@ void CKernel::Start(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (;;) {
|
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");
|
kprintf("[i] Hello! I'm the child process.\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,27 +42,19 @@ void CScheduler::AddTask(CTask *Task)
|
||||||
__asm__ volatile("sti");
|
__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;
|
TTaskQueueNode *Next;
|
||||||
|
|
||||||
if (g_Scheduler.m_TaskQueueStart == 0)
|
/*if (g_Scheduler.m_TaskQueueStart == 0)
|
||||||
PANIC("No tasks in queue!");
|
PANIC("No tasks in queue!");
|
||||||
|
|
||||||
if (g_Scheduler.m_TaskQueueCurrent == 0)
|
if (g_Scheduler.m_TaskQueueCurrent == 0)
|
||||||
PANIC("Current task is null!");
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch next task.
|
// Fetch next task.
|
||||||
if (g_Scheduler.m_TaskQueueCurrent->Next == 0)
|
if (g_Scheduler.m_TaskQueueCurrent->Next == 0)
|
||||||
|
@ -70,15 +62,6 @@ void CScheduler::NextTask(void)
|
||||||
else
|
else
|
||||||
Next = g_Scheduler.m_TaskQueueCurrent->Next;
|
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
|
// Read task details
|
||||||
NewEBP = Next->Task->m_EBP;
|
NewEBP = Next->Task->m_EBP;
|
||||||
NewESP = Next->Task->m_ESP;
|
NewESP = Next->Task->m_ESP;
|
||||||
|
@ -90,6 +73,24 @@ void CScheduler::NextTask(void)
|
||||||
return;
|
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
|
// Switch to next task
|
||||||
g_Scheduler.m_TaskQueueCurrent = Next;
|
g_Scheduler.m_TaskQueueCurrent = Next;
|
||||||
g_Scheduler.m_CurrentTask = Next->Task;
|
g_Scheduler.m_CurrentTask = Next->Task;
|
||||||
|
|
|
@ -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++;
|
||||||
|
}
|
Loading…
Reference in New Issue