Refactor kernel cpu.h header.
This commit is contained in:
parent
a15ffa955b
commit
d0f68eec68
|
@ -29,12 +29,12 @@
|
||||||
#include <sortix/kernel/inode.h>
|
#include <sortix/kernel/inode.h>
|
||||||
#include <sortix/kernel/ioctx.h>
|
#include <sortix/kernel/ioctx.h>
|
||||||
#include <sortix/kernel/descriptor.h>
|
#include <sortix/kernel/descriptor.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
#include <sortix/stat.h>
|
#include <sortix/stat.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ata.h"
|
#include "ata.h"
|
||||||
#include "cpu.h"
|
|
||||||
|
|
||||||
// TODO: Use the PCI to detect ATA devices instead of relying on them being on
|
// TODO: Use the PCI to detect ATA devices instead of relying on them being on
|
||||||
// standard locations.
|
// standard locations.
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
#include <sortix/kernel/memorymanagement.h>
|
#include <sortix/kernel/memorymanagement.h>
|
||||||
#include <sortix/kernel/pci.h>
|
#include <sortix/kernel/pci.h>
|
||||||
#include <sortix/kernel/string.h>
|
#include <sortix/kernel/string.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
|
|
||||||
#include <sortix/mman.h>
|
#include <sortix/mman.h>
|
||||||
|
|
||||||
#include "x86-family/memorymanagement.h"
|
#include "x86-family/memorymanagement.h"
|
||||||
#include "lfbtextbuffer.h"
|
#include "lfbtextbuffer.h"
|
||||||
#include "cpu.h"
|
|
||||||
#include "bga.h"
|
#include "bga.h"
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
|
51
sortix/cpu.h
51
sortix/cpu.h
|
@ -1,51 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
|
||||||
|
|
||||||
This file is part of Sortix.
|
|
||||||
|
|
||||||
Sortix 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.
|
|
||||||
|
|
||||||
Sortix 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
|
|
||||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
cpu.h
|
|
||||||
Includes CPU-specific headers.
|
|
||||||
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SORTIX_CPU_H
|
|
||||||
#define SORTIX_CPU_H
|
|
||||||
|
|
||||||
// Include some x86 headers.
|
|
||||||
#ifdef PLATFORM_X86
|
|
||||||
#include "x86/x86.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Include some x64 headers.
|
|
||||||
#ifdef PLATFORM_X64
|
|
||||||
#include "x64/x64.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Sortix {
|
|
||||||
namespace CPU {
|
|
||||||
|
|
||||||
extern "C" void load_registers(InterruptRegisters* regs, size_t size) SORTIX_NORETURN;
|
|
||||||
inline void LoadRegisters(InterruptRegisters* regs) SORTIX_NORETURN;
|
|
||||||
inline void LoadRegisters(InterruptRegisters* regs)
|
|
||||||
{
|
|
||||||
load_registers(regs, sizeof(*regs));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace CPU
|
|
||||||
} // namespace CPU
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
||||||
|
|
||||||
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
Sortix 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.
|
||||||
|
|
||||||
|
Sortix 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
|
||||||
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
sortix/kernel/cpu.h
|
||||||
|
CPU-specific declarations.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef INCLUDE_SORTIX_KERNEL_CPU_H
|
||||||
|
#define INCLUDE_SORTIX_KERNEL_CPU_H
|
||||||
|
|
||||||
|
#include <sortix/kernel/decl.h>
|
||||||
|
|
||||||
|
namespace Sortix {
|
||||||
|
|
||||||
|
// Functions for 32-bit and 64-bit x86.
|
||||||
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
|
namespace CPU {
|
||||||
|
void OutPortB(uint16_t Port, uint8_t Value);
|
||||||
|
void OutPortW(uint16_t Port, uint16_t Value);
|
||||||
|
void OutPortL(uint16_t Port, uint32_t Value);
|
||||||
|
uint8_t InPortB(uint16_t Port);
|
||||||
|
uint16_t InPortW(uint16_t Port);
|
||||||
|
uint32_t InPortL(uint16_t Port);
|
||||||
|
void Reboot();
|
||||||
|
void ShutDown();
|
||||||
|
} // namespace CPU
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// CPU flag register bits for 32-bit and 64-bit x86.
|
||||||
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
|
const size_t FLAGS_CARRY = 1<<0; // 0x000001
|
||||||
|
const size_t FLAGS_RESERVED1 = 1<<1; // 0x000002, read as one
|
||||||
|
const size_t FLAGS_PARITY = 1<<2; // 0x000004
|
||||||
|
const size_t FLAGS_RESERVED2 = 1<<3; // 0x000008
|
||||||
|
const size_t FLAGS_AUX = 1<<4; // 0x000010
|
||||||
|
const size_t FLAGS_RESERVED3 = 1<<5; // 0x000020
|
||||||
|
const size_t FLAGS_ZERO = 1<<6; // 0x000040
|
||||||
|
const size_t FLAGS_SIGN = 1<<7; // 0x000080
|
||||||
|
const size_t FLAGS_TRAP = 1<<8; // 0x000100
|
||||||
|
const size_t FLAGS_INTERRUPT = 1<<9; // 0x000200
|
||||||
|
const size_t FLAGS_DIRECTION = 1<<10; // 0x000400
|
||||||
|
const size_t FLAGS_OVERFLOW = 1<<11; // 0x000800
|
||||||
|
const size_t FLAGS_IOPRIVLEVEL = 1<<12 | 1<<13;
|
||||||
|
const size_t FLAGS_NESTEDTASK = 1<<14; // 0x004000
|
||||||
|
const size_t FLAGS_RESERVED4 = 1<<15; // 0x008000
|
||||||
|
const size_t FLAGS_RESUME = 1<<16; // 0x010000
|
||||||
|
const size_t FLAGS_VIRTUAL8086 = 1<<17; // 0x020000
|
||||||
|
const size_t FLAGS_ALIGNCHECK = 1<<18; // 0x040000
|
||||||
|
const size_t FLAGS_VIRTINTR = 1<<19; // 0x080000
|
||||||
|
const size_t FLAGS_VIRTINTRPEND = 1<<20; // 0x100000
|
||||||
|
const size_t FLAGS_ID = 1<<21; // 0x200000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// x86 interrupt registers structure.
|
||||||
|
#if defined(__i386__)
|
||||||
|
namespace X86 {
|
||||||
|
struct InterruptRegisters
|
||||||
|
{
|
||||||
|
uint32_t signal_pending, kerrno, cr2;
|
||||||
|
uint32_t ds; // Data segment selector
|
||||||
|
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
|
||||||
|
uint32_t int_no, err_code; // Interrupt number and error code (if applicable)
|
||||||
|
uint32_t eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
|
||||||
|
|
||||||
|
public:
|
||||||
|
void LogRegisters() const;
|
||||||
|
bool InUserspace() const { return (cs & 0x3) != 0; }
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace X86
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// x86_64 interrupt
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
namespace X64 {
|
||||||
|
struct InterruptRegisters
|
||||||
|
{
|
||||||
|
uint64_t signal_pending, kerrno, cr2;
|
||||||
|
uint64_t ds; // Data segment selector
|
||||||
|
uint64_t rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax;
|
||||||
|
uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
|
||||||
|
uint64_t int_no, err_code; // Interrupt number and error code (if applicable)
|
||||||
|
uint64_t rip, cs, rflags, userrsp, ss; // Pushed by the processor automatically.
|
||||||
|
|
||||||
|
public:
|
||||||
|
void LogRegisters() const;
|
||||||
|
bool InUserspace() const { return (cs & 0x3) != 0; }
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace X64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Segment values for 32-bit and 64-bit x86.
|
||||||
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
|
const uint64_t KCS = 0x08;
|
||||||
|
const uint64_t KDS = 0x10;
|
||||||
|
const uint64_t KRPL = 0x0;
|
||||||
|
const uint64_t UCS = 0x18;
|
||||||
|
const uint64_t UDS = 0x20;
|
||||||
|
const uint64_t URPL = 0x3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Portable functions for loading registers.
|
||||||
|
namespace CPU {
|
||||||
|
extern "C" void load_registers(InterruptRegisters* regs, size_t size) SORTIX_NORETURN;
|
||||||
|
SORTIX_NORETURN inline void LoadRegisters(InterruptRegisters* regs)
|
||||||
|
{
|
||||||
|
load_registers(regs, sizeof(*regs));
|
||||||
|
}
|
||||||
|
} // namespace CPU
|
||||||
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
|
#endif
|
|
@ -25,13 +25,13 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/keyboard.h>
|
#include <sortix/kernel/keyboard.h>
|
||||||
#include <sortix/kernel/interrupt.h>
|
#include <sortix/kernel/interrupt.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
|
|
||||||
#include <sortix/keycodes.h>
|
#include <sortix/keycodes.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../cpu.h"
|
|
||||||
#include "ps2.h"
|
#include "ps2.h"
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/endian.h>
|
#include <sortix/kernel/endian.h>
|
||||||
#include <sortix/kernel/pci.h>
|
#include <sortix/kernel/pci.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "cpu.h" // TODO: Put this in some <sortix/kernel/cpu.h>
|
|
||||||
|
|
||||||
// TODO: Verify that the endian conversions in this file actually works. I have
|
// TODO: Verify that the endian conversions in this file actually works. I have
|
||||||
// a sneaking suspicion that they won't work on non-little endian platforms.
|
// a sneaking suspicion that they won't work on non-little endian platforms.
|
||||||
|
|
|
@ -33,8 +33,7 @@
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
#include <sortix/kernel/timer.h>
|
#include <sortix/kernel/timer.h>
|
||||||
#include <sortix/kernel/user-timer.h>
|
#include <sortix/kernel/user-timer.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
#include "cpu.h"
|
|
||||||
|
|
||||||
#define PROCESS_TIMER_NUM_MAX 32
|
#define PROCESS_TIMER_NUM_MAX 32
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <sortix/signal.h>
|
#include <sortix/signal.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include <sortix/kernel/cpu.h>
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/kthread.h>
|
#include <sortix/kernel/kthread.h>
|
||||||
#include <sortix/kernel/syscall.h>
|
#include <sortix/kernel/syscall.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include "cpu.h"
|
#include <sortix/kernel/cpu.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include "x64.h"
|
#include <sortix/kernel/cpu.h>
|
||||||
#include <sortix/kernel/log.h>
|
#include <sortix/kernel/log.h>
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
|
||||||
|
|
||||||
This file is part of Sortix.
|
|
||||||
|
|
||||||
Sortix 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.
|
|
||||||
|
|
||||||
Sortix 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
|
|
||||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
x64/x64.h
|
|
||||||
CPU stuff for the x64 platform.
|
|
||||||
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SORTIX_X64_H
|
|
||||||
#define SORTIX_X64_H
|
|
||||||
|
|
||||||
#include "../x86-family/x86-family.h"
|
|
||||||
|
|
||||||
namespace Sortix
|
|
||||||
{
|
|
||||||
namespace X64
|
|
||||||
{
|
|
||||||
struct InterruptRegisters
|
|
||||||
{
|
|
||||||
uint64_t signal_pending, kerrno, cr2;
|
|
||||||
uint64_t ds; // Data segment selector
|
|
||||||
uint64_t rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax;
|
|
||||||
uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
|
|
||||||
uint64_t int_no, err_code; // Interrupt number and error code (if applicable)
|
|
||||||
uint64_t rip, cs, rflags, userrsp, ss; // Pushed by the processor automatically.
|
|
||||||
|
|
||||||
public:
|
|
||||||
void LogRegisters() const;
|
|
||||||
bool InUserspace() const { return (cs & 0x3) != 0; }
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint64_t KCS = 0x08;
|
|
||||||
const uint64_t KDS = 0x10;
|
|
||||||
const uint64_t KRPL = 0x0;
|
|
||||||
const uint64_t UCS = 0x18;
|
|
||||||
const uint64_t UDS = 0x20;
|
|
||||||
const uint64_t URPL = 0x3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -33,8 +33,7 @@
|
||||||
#include <sortix/kernel/interrupt.h>
|
#include <sortix/kernel/interrupt.h>
|
||||||
#include <sortix/kernel/scheduler.h>
|
#include <sortix/kernel/scheduler.h>
|
||||||
#include <sortix/kernel/time.h>
|
#include <sortix/kernel/time.h>
|
||||||
|
#include <sortix/kernel/cpu.h>
|
||||||
#include "../cpu.h"
|
|
||||||
|
|
||||||
namespace Sortix {
|
namespace Sortix {
|
||||||
namespace Time {
|
namespace Time {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include "x86.h"
|
#include <sortix/kernel/cpu.h>
|
||||||
#include <sortix/kernel/log.h>
|
#include <sortix/kernel/log.h>
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
|
||||||
|
|
||||||
This file is part of Sortix.
|
|
||||||
|
|
||||||
Sortix 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.
|
|
||||||
|
|
||||||
Sortix 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
|
|
||||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
x86/x86.h
|
|
||||||
CPU stuff for the x86 platform.
|
|
||||||
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SORTIX_X86_H
|
|
||||||
#define SORTIX_X86_H
|
|
||||||
|
|
||||||
#include "../x86-family/x86-family.h"
|
|
||||||
|
|
||||||
namespace Sortix
|
|
||||||
{
|
|
||||||
namespace X86
|
|
||||||
{
|
|
||||||
struct InterruptRegisters
|
|
||||||
{
|
|
||||||
uint32_t signal_pending, kerrno, cr2;
|
|
||||||
uint32_t ds; // Data segment selector
|
|
||||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
|
|
||||||
uint32_t int_no, err_code; // Interrupt number and error code (if applicable)
|
|
||||||
uint32_t eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
|
|
||||||
|
|
||||||
public:
|
|
||||||
void LogRegisters() const;
|
|
||||||
bool InUserspace() const { return (cs & 0x3) != 0; }
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint64_t KCS = 0x08;
|
|
||||||
const uint64_t KDS = 0x10;
|
|
||||||
const uint64_t KRPL = 0x0;
|
|
||||||
const uint64_t UCS = 0x18;
|
|
||||||
const uint64_t UDS = 0x20;
|
|
||||||
const uint64_t URPL = 0x3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue