hos/kernel/functions.h

98 lines
1.7 KiB
C

//functions.h
//05/07/03 Josh Holtrop
//for HOS
//Modified: 02/26/04
#ifndef __HOS_FUNCTIONS__
#define __HOS_FUNCTIONS__ __HOS_FUNCTIONS__
#include "hos_defines.h"
#include "sys/io.h"
extern dword _code;
extern dword _bss;
extern dword _end;
inline void enable_ints();
inline void disable_ints();
inline void restart();
inline void halt();
inline dword kernel_size();
inline void timer_init();
inline byte bcd2byte(byte bcd);
inline byte byte2bcd(byte bite);
//Enables (SeTs) Interrupt Flag on the processor
inline void enable_ints()
{
asm("sti");
}
//Disables (CLears) Interrupt Flag on the processor
inline void disable_ints()
{
asm("cli");
}
//Restarts the computer
inline void restart()
{
enable_ints();
byte temp;
do
{
temp = inportb(0x64);
if (temp & 1)
inportb(0x60);
} while(temp & 2);
outportb (0x64, 0xfe);
for (;;)
{
}
}
//Halts (freezes) the computer
inline void halt()
{
asm("cli");
asm("hlt");
while (1)
;
}
//Initializes 8253 Programmable Interrupt Timer
inline void timer_init()
{
//set timer : 2e9c = 100hz
outportb(0x43, 0x34);
outportb(0x40, 0x9c); //lsb
outportb(0x40, 0x2e); //msb
}
//Returns the size of the kernel (code & data)
// - this does not include the bss section
// - this should be 4kb aligned per the linker script
// - this should be the size of kernel.bin
inline dword kernel_size()
{
return (dword)(&_bss)-(dword)(&_code);
}
//converts a binary-coded-decimal byte to its decimal equivalent
inline byte bcd2byte(byte bcd)
{
return (10* ((bcd & 0xF0) >> 4)) + (bcd & 0x0F);
}
//converts a binary-coded-decimal byte to its decimal equivalent
inline byte byte2bcd(byte bite)
{
return ((bite / 10) << 4) | (bite % 10);
}
#endif