Update kernel/x86-family/x86-family.{cpp,h} to current coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-04 02:12:09 +01:00
parent cacd010066
commit 6d79781497
2 changed files with 125 additions and 115 deletions

View File

@ -22,46 +22,47 @@
*******************************************************************************/ *******************************************************************************/
#include <stdint.h>
#include <sortix/kernel/kernel.h> #include <sortix/kernel/kernel.h>
namespace Sortix namespace Sortix {
namespace CPU {
void OutPortB(uint16_t port, uint8_t value)
{ {
namespace CPU asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
{
void OutPortB(uint16_t Port, uint8_t Value)
{
asm volatile ("outb %1, %0" : : "dN" (Port), "a" (Value));
} }
void OutPortW(uint16_t Port, uint16_t Value) void OutPortW(uint16_t port, uint16_t value)
{ {
asm volatile ("outw %1, %0" : : "dN" (Port), "a" (Value)); asm volatile ("outw %1, %0" : : "dN" (port), "a" (value));
} }
void OutPortL(uint16_t Port, uint32_t Value) void OutPortL(uint16_t port, uint32_t value)
{ {
asm volatile ("outl %1, %0" : : "dN" (Port), "a" (Value)); asm volatile ("outl %1, %0" : : "dN" (port), "a" (value));
} }
uint8_t InPortB(uint16_t Port) uint8_t InPortB(uint16_t port)
{ {
uint8_t Result; uint8_t result;
asm volatile("inb %1, %0" : "=a" (Result) : "dN" (Port)); asm volatile("inb %1, %0" : "=a" (result) : "dN" (port));
return Result; return result;
} }
uint16_t InPortW(uint16_t Port) uint16_t InPortW(uint16_t port)
{ {
uint16_t Result; uint16_t result;
asm volatile("inw %1, %0" : "=a" (Result) : "dN" (Port)); asm volatile("inw %1, %0" : "=a" (result) : "dN" (port));
return Result; return result;
} }
uint32_t InPortL(uint16_t Port) uint32_t InPortL(uint16_t port)
{ {
uint32_t Result; uint32_t result;
asm volatile("inl %1, %0" : "=a" (Result) : "dN" (Port)); asm volatile("inl %1, %0" : "=a" (result) : "dN" (port));
return Result; return result;
} }
void Reboot() void Reboot()
@ -73,10 +74,10 @@ namespace Sortix
const uint16_t KEYBOARD_IO = 0x60; const uint16_t KEYBOARD_IO = 0x60;
// Keyboard data is in buffer (output buffer is empty) (bit 0). // Keyboard data is in buffer (output buffer is empty) (bit 0).
const uint8_t KEYBOARD_DATA = (1<<0); const uint8_t KEYBOARD_DATA = 1 << 0;
// User data is in buffer (command buffer is empty) (bit 1). // User data is in buffer (command buffer is empty) (bit 1).
const uint8_t USER_DATA = (1<<1); const uint8_t USER_DATA = 1 << 1;
// Disable interrupts. // Disable interrupts.
asm volatile("cli"); asm volatile("cli");
@ -86,8 +87,9 @@ namespace Sortix
do do
{ {
byte = InPortB(KEYBOARD_INTERFACE); byte = InPortB(KEYBOARD_INTERFACE);
if ( ( byte & KEYBOARD_DATA ) != 0 ) { InPortB(KEYBOARD_IO); } if ( byte & KEYBOARD_DATA )
} while ( ( byte & USER_DATA ) != 0 ); InPortB(KEYBOARD_IO);
} while ( byte & USER_DATA );
// CPU reset command. // CPU reset command.
uint8_t KEYBOARD_RESET_CPU = 0xFE; uint8_t KEYBOARD_RESET_CPU = 0xFE;
@ -104,5 +106,6 @@ namespace Sortix
// TODO: Unimplemented, just reboot. // TODO: Unimplemented, just reboot.
Reboot(); Reboot();
} }
}
} } // namespace CPU
} // namespace Sortix

View File

@ -25,41 +25,48 @@
#ifndef SORTIX_X86_FAMILY_H #ifndef SORTIX_X86_FAMILY_H
#define SORTIX_X86_FAMILY_H #define SORTIX_X86_FAMILY_H
namespace Sortix #include <stddef.h>
{ #include <stdint.h>
namespace CPU
{ namespace Sortix {
void OutPortB(uint16_t Port, uint8_t Value); namespace CPU {
void OutPortW(uint16_t Port, uint16_t Value);
void OutPortL(uint16_t Port, uint32_t Value); void OutPortB(uint16_t port, uint8_t value);
uint8_t InPortB(uint16_t Port); void OutPortW(uint16_t port, uint16_t value);
uint16_t InPortW(uint16_t Port); void OutPortL(uint16_t port, uint32_t value);
uint32_t InPortL(uint16_t Port); uint8_t InPortB(uint16_t port);
uint16_t InPortW(uint16_t port);
uint32_t InPortL(uint16_t port);
void Reboot(); void Reboot();
void ShutDown(); void ShutDown();
}
const size_t FLAGS_CARRY = (1<<0); // 0x000001 } // namespace CPU
const size_t FLAGS_RESERVED1 = (1<<1); // 0x000002, read as one } // namespace Sortix
const size_t FLAGS_PARITY = (1<<2); // 0x000004
const size_t FLAGS_RESERVED2 = (1<<3); // 0x000008 namespace Sortix {
const size_t FLAGS_AUX = (1<<4); // 0x000010
const size_t FLAGS_RESERVED3 = (1<<5); // 0x000020 const size_t FLAGS_CARRY = 1 << 0; // 0x000001
const size_t FLAGS_ZERO = (1<<6); // 0x000040 const size_t FLAGS_RESERVED1 = 1 << 1; // 0x000002, read as one
const size_t FLAGS_SIGN = (1<<7); // 0x000080 const size_t FLAGS_PARITY = 1 << 2; // 0x000004
const size_t FLAGS_TRAP = (1<<8); // 0x000100 const size_t FLAGS_RESERVED2 = 1 << 3; // 0x000008
const size_t FLAGS_INTERRUPT = (1<<9); // 0x000200 const size_t FLAGS_AUX = 1 << 4; // 0x000010
const size_t FLAGS_DIRECTION = (1<<10); // 0x000400 const size_t FLAGS_RESERVED3 = 1 << 5; // 0x000020
const size_t FLAGS_OVERFLOW = (1<<11); // 0x000800 const size_t FLAGS_ZERO = 1 << 6; // 0x000040
const size_t FLAGS_IOPRIVLEVEL = (1<<12) | (1<<13); const size_t FLAGS_SIGN = 1 << 7; // 0x000080
const size_t FLAGS_NESTEDTASK = (1<<14); // 0x004000 const size_t FLAGS_TRAP = 1 << 8; // 0x000100
const size_t FLAGS_RESERVED4 = (1<<15); // 0x008000 const size_t FLAGS_INTERRUPT = 1 << 9; // 0x000200
const size_t FLAGS_RESUME = (1<<16); // 0x010000 const size_t FLAGS_DIRECTION = 1 << 10; // 0x000400
const size_t FLAGS_VIRTUAL8086 = (1<<17); // 0x020000 const size_t FLAGS_OVERFLOW = 1 << 11; // 0x000800
const size_t FLAGS_ALIGNCHECK = (1<<18); // 0x040000 const size_t FLAGS_IOPRIVLEVEL = 1 << 12) | 1 << 13;
const size_t FLAGS_VIRTINTR = (1<<19); // 0x080000 const size_t FLAGS_NESTEDTASK = 1 << 14; // 0x004000
const size_t FLAGS_VIRTINTRPEND = (1<<20); // 0x100000 const size_t FLAGS_RESERVED4 = 1 << 15; // 0x008000
const size_t FLAGS_ID = (1<<21); // 0x200000 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
} // namespace Sortix
#endif #endif