Skip to content

Commit

Permalink
Added some god system calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 28, 2009
1 parent a47f074 commit 7adf66b
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 54 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -43,6 +43,7 @@ x86_DIR = sources/Processor/x86

KERNEL_FILES += ${x86_DIR}/Processor.cpp \
${x86_DIR}/DescriptorTables/DescriptorTables.cpp ${x86_DIR}/DescriptorTables/Global.cpp ${x86_DIR}/DescriptorTables/Interrupt.cpp \
${x86_DIR}/Interrupt/Interrupts.cpp \
${x86_DIR}/Memory/Memory.cpp ${x86_DIR}/Memory/Paging.cpp ${x86_DIR}/Memory/Frame.cpp

ASM_FILES += ${x86_DIR}/DescriptorTables/Global.S ${x86_DIR}/DescriptorTables/Interrupt.S \
Expand All @@ -66,5 +67,5 @@ $(KERNEL_FILES:.cpp=.o): $(KERNEL_FILES)

clean:
rm -f ${NAME}
find . | egrep "\.o" | xargs rm -f
find sources | egrep "\.o" | xargs rm -f

2 changes: 0 additions & 2 deletions include/Interrupt/Interrupt.h
Expand Up @@ -31,8 +31,6 @@ class Interrupt
typedef void (*Handler)(Registers&);

public:
static void init (Handler system);

static void handle (Type type, Registers& registers);

static void define (Type::u8 number, Handler handler);
Expand Down
33 changes: 33 additions & 0 deletions include/Processor/x86/Interrupt/Interrupts.h
@@ -0,0 +1,33 @@
/****************************************************************************
* Copyright (C) 2009 meh. [http://meh.doesntexist.org] *
* *
* This file is part of lulzKey. *
* *
* See COPYING or http://www.gnu.org/licenses/agpl-3.0.txt *
****************************************************************************/

#include <Interrupt/Interrupt.h>

namespace Kernel {

namespace Processor {

namespace Interrupts {

void init (void);

/**
* System interrupts, only the god service can call them.
*
* 1 - disable paging { void (void) }
* 2 - enable paging { void (void) }
* 3 - set paging directory to the ebx { void (physycal table address) }
* 4 - flush TLB { void (void) }
*/
void system (Interrupt::Registers& regs);

}

}

}
6 changes: 0 additions & 6 deletions sources/Interrupt/Interrupt.cpp
Expand Up @@ -13,12 +13,6 @@ namespace Kernel {

Interrupt::Handler Interrupt::_handlers[256] = {0};

void
Interrupt::init (Interrupt::Handler system)
{
Interrupt::define(0x42, system);
}

void
Interrupt::handle (Interrupt::Type type, Interrupt::Registers& registers)
{
Expand Down
Empty file removed sources/Processor/Processor.cpp
Empty file.
64 changes: 64 additions & 0 deletions sources/Processor/x86/Interrupt/Interrupts.cpp
@@ -0,0 +1,64 @@
/****************************************************************************
* Copyright (C) 2009 meh. [http://meh.doesntexist.org] *
* *
* This file is part of lulzKey. *
* *
* See COPYING or http://www.gnu.org/licenses/agpl-3.0.txt *
****************************************************************************/

#include <Processor/x86/Interrupt/Interrupts.h>

namespace Kernel {

namespace Processor {

namespace Interrupts {

void
init (void)
{

}

void
system (Interrupt::Registers& regs)
{
if (regs.ring <= 1) {
switch (regs.eax) {
case 1: // disable paging
asm volatile (
"mov %%cr0, %%edx \n"
"and $0x7fffffff, %%edx \n"
"mov %%edx, %%cr0 \n"
::: "edx");
break;

case 2: // enable paging
asm volatile (
"movl %%cr0, %%edx \n"
"orl $0x80000000, %%edx \n"
"movl %%edx, %%cr0 \n"
::: "edx");
break;

case 3: // set paging directory to ebx
asm volatile (
"movl %0, %%cr3 \n" :: "r" (regs.ebx)
);
break;

case 4: // flush TLB
asm volatile (
"mov %%cr3, %%edx \n"
"mov %%edx, %%cr3 \n"
::: "edx");
}
}
}

}

}

}

8 changes: 4 additions & 4 deletions sources/Processor/x86/Memory/Paging.cpp
Expand Up @@ -60,10 +60,10 @@ switchPage (Directory* directory)
"movl %0, %%cr3 \n"

// Enable paging
"movl %%cr0, %%eax \n"
"orl $0x80000000, %%eax \n"
"movl %%eax, %%cr0"
:: "r" (&directory->tablesPhysical) : "eax");
"movl %%cr0, %%edx \n"
"orl $0x80000000, %%edx \n"
"movl %%edx, %%cr0"
:: "r" (&directory->tablesPhysical) : "edx");
}

Page*
Expand Down
42 changes: 2 additions & 40 deletions sources/Processor/x86/Processor.cpp
Expand Up @@ -14,59 +14,21 @@

#include <Processor/Processor.h>
#include <Processor/x86/DescriptorTables/DescriptorTables.h>
#include <Processor/x86/Interrupt/Interrupts.h>
#include <Processor/x86/Memory/Memory.h>
#include <Processor/x86/Memory/Paging.h>

#include <Interrupt/Interrupt.h>

namespace Kernel {

namespace Processor {

extern "C" int __end;

/**
* System interrupts, only the god service can call them.
*
* 1 - disable paging { void (void) }
* 2 - enable paging { void (void) }
* 3 - set paging directory to the ebx { void (physycal table address) }
*/
void
system (Interrupt::Registers& regs)
{
if (regs.ring == 1) {
switch (regs.eax) {
case 1:
asm volatile (
"mov %%cr0, %%eax \n"
"and $0x7fffffff, %%eax \n"
"mov %%eax, %%cr0 \n"
::: "eax");
break;

case 2:
asm volatile(
"movl %%cr0, %%eax \n"
"orl $0x80000000, %%eax \n"
"movl %%eax, %%cr0 \n"
::: "eax");
break;

case 3:
asm volatile(
"movl %0, %%cr3 \n" :: "r" (regs.ebx)
);
break;
}
}
}

void
init (Multiboot& boot)
{
DescriptorTables::init();
Interrupt::init(&system);
Interrupts::init();

Memory::address = (Type::u32) &__end; // boot.end();
Memory::Paging::init(boot.memory()->upper);
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Expand Up @@ -10,7 +10,7 @@ STAGE2=`stat -c %s test/stage2`
KERNEL=`stat -c %s lulzKey`

TMP=`mktemp`
FLOPPY=`mktemp`
FLOPPY=`mktemp /tmp/qemu.XXXXXX`

dd if=/dev/zero of="$TMP" bs=1 count=750 &> /dev/null
cat test/stage1 test/stage2 "$TMP" lulzKey > "$FLOPPY"
Expand Down

0 comments on commit 7adf66b

Please sign in to comment.