whee back to my netbook

alentours-dev
Sergiusz Bazanski 2011-04-04 18:25:20 +02:00
parent 9bca69f428
commit 80156c1ae8
13 changed files with 142 additions and 31201 deletions

31189
dump

File diff suppressed because it is too large Load Diff

View File

@ -11,17 +11,17 @@ typedef struct {
#define atomic_read(v) ((v)->Value)
#define atomic_set(v, n) (((v)->Value) = n)
static inline void atomic_add(T_ATOMIC Atom, u32 Value)
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)
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)
static inline u8 atomic_sub_and_test(T_ATOMIC *Atom, u32 Value)
{
u8 C;
__asm__ volatile("lock subl %2, %0\n"
@ -31,15 +31,30 @@ static inline void atomic_sub_and_test(T_ATOMIC Atom, u32 Value)
return C;
}
static inline void atomic_inc(T_ATOMIC Atom)
static inline void atomic_inc(T_ATOMIC *Atom)
{
__asm__ volatile("lock incl %0" : "+m"(Atom->Value));
}
static inline void atomic_dec(T_ATOMIC Atom)
static inline void atomic_dec(T_ATOMIC *Atom)
{
__asm__ volatile("lock decl %0" : "+m"(Atom->Value));
}
static inline u8 atomic_dec_and_test(T_ATOMIC *Atom)
{
u8 C;
__asm__ volatile("lock decl %0\n"
"sete %1" : "+m"(Atom->Value), "=qm"(C) :: "memory");
return C;
}
static inline u8 atomic_inc_and_test(T_ATOMIC *Atom)
{
u8 C;
__asm__ volatile("lock incl %0\n"
"sete %1" : "+m"(Atom->Value), "=qm"(C) :: "memory");
return C;
}
#endif

View File

@ -5,6 +5,7 @@
#define LOOPFOREVER for(;;){}
void kstdio_init(void);
void koutb(u16 Port, u8 Data);
u8 kinb(u16 Port);
void kio_wait(void);

37
include/Tier0/semaphore.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef __SEMAPHORE_H__
#define __SEMAPHORE_H__
#include "types.h"
#include "Tier0/atomic_operations.h"
typedef T_ATOMIC T_SEMAPHORE;
static inline void semaphore_init(T_SEMAPHORE *Semaphore)
{
atomic_set(Semaphore, 1);
}
static inline void semaphore_init_with_number(T_SEMAPHORE *Semaphore, u32 N)
{
atomic_set(Semaphore, N);
}
static inline void semaphore_acquire(T_SEMAPHORE *Semaphore)
{
// Spinlock again
while(1)
{
if (atomic_read(Semaphore) > 0)
{
atomic_dec(Semaphore);
break;
}
}
}
static inline void semaphore_release(T_SEMAPHORE *Semaphore)
{
atomic_inc(Semaphore);
}
#endif

View File

@ -3,10 +3,14 @@
#include "types.h"
extern "C" {
#include "Tier0/atomic_operations.h"
};
namespace cb {
class CSemaphore {
private:
u32 m_Available;
T_ATOMIC m_Available;
public:
CSemaphore(u32 Available = 1);
void Acquire(void);

10
include/Tier1/CTimer.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __CTIMER_H__
#define __CTIMER_H__
namespace cb {
class CTimer {
void Enable(bool Enabled);
};
};
#endif

View File

@ -0,0 +1,25 @@
#ifndef __ITIMERSUBSRCIBER_H__
#define __ITIMERSUBSCRIBER_H__
#include "Tier1/CTimer.h"
namespace cb {
class CTimer;
// An interface used to subscribe to a CTimer
class ITimerSubscriber {
public:
// Gets called after subscribing to a tick with TickDelta
virtual void Tick(u32 TickDelta);
// Returns wether we should be called
virtual bool Enabled(void);
// Basic functions called be derivee
// Unsubscribe from the current subscribed CTimer
void Unsubscribe(void);
void Subscribe(CTimer *Timer, u32 Tick);
};
};
#endif

View File

@ -0,0 +1,18 @@
#ifndef __CVECTOR_H__
#define __CVECTOR_H__
class cb {
// An STL-like vector implementation for internal use in the kernel
template <typename _T> class CVector {
public:
CVector(u32 StartElements = 32);
void Push(_T Element);
void Pop(_T Element);
u32 IterationStart(void);
u32 IterationEnd(void);
private:
_T *m_Members;
};
};
#endif

View File

@ -29,6 +29,7 @@ void kmain_newstack(void);
// Real kernel entry point, called from _start.asm
void kmain(void *MultibootHeader, u32 Magic)
{
kstdio_init();
kclear();
kprintf(" _ \n"
" ___ _ _ ___ _ _ _____| |_ ___ ___ \n"

View File

@ -1,6 +1,7 @@
#include "types.h"
#include "Tier0/kstdio.h"
#include "Tier0/kstdlib.h"
#include "Tier0/semaphore.h"
#include <stdarg.h>
#define va_start(v,l) __builtin_va_start(v,l)
@ -12,6 +13,13 @@ typedef __builtin_va_list va_list;
u8 g_kstdio_current_line = 0;
u8 g_kstdio_cur_x = 0, g_kstdio_cur_y = 0;
T_SEMAPHORE ScreenWriteLock;
void kstdio_init(void)
{
semaphore_init(&ScreenWriteLock);
}
void koutb(u16 Port, u8 Data)
{
__asm__ volatile("outb %1, %0" :: "dN" (Port), "a" (Data));
@ -56,6 +64,7 @@ void kputi(s32 Number)
void kprintf(const s8 *szFormat, ...)
{
semaphore_acquire(&ScreenWriteLock);
va_list ap;
va_start(ap, szFormat);
@ -101,12 +110,14 @@ void kprintf(const s8 *szFormat, ...)
Offset++;
}
}
va_end(ap);
semaphore_release(&ScreenWriteLock);
}
void kscroll_up(void)
{
//semaphore_acquire(&ScreenWriteLock);
u16 Blank = 0x20 | (0x0F << 8);
u16 Temp;
@ -118,6 +129,7 @@ void kscroll_up(void)
kmemsetw((void*)(0xC00B8000 + (25 - Temp) * 160), Blank, 160);
g_kstdio_cur_y = 25 - 1;
}
//semaphore_release(&ScreenWriteLock);
}
u32 kstrlen(const s8 *szString)

View File

@ -120,7 +120,7 @@ CTask *CScheduler::GetCurrentTask(void)
void CScheduler::Enable(void)
{
u32 Divisor = 0xFFFF;
u32 Divisor = 100;
koutb(0x43, 0x36);
u8 Low = (u8)(Divisor & 0xFF);
u8 High = (u8)((Divisor >> 8) & 0xFF);

View File

@ -3,7 +3,7 @@ using namespace cb;
CSemaphore::CSemaphore(u32 Available)
{
m_Available = Available;
atomic_set(&m_Available, Available);
}
void CSemaphore::Acquire(void)
@ -11,9 +11,9 @@ void CSemaphore::Acquire(void)
// Just spinlock...
while (1)
{
if (m_Available > 0)
if (atomic_read(&m_Available) > 0)
{
m_Available--;
atomic_dec(&m_Available);
break;
}
}
@ -21,5 +21,5 @@ void CSemaphore::Acquire(void)
void CSemaphore::Release(void)
{
m_Available++;
atomic_inc(&m_Available);
}

View File

@ -0,0 +1,7 @@
#include "Tier1/Utils/CVector.h"
using namespace cb;
template <typename _T> CVector::CVector(u32 StartElements)
{
}