hos/kernel/functions.h

95 lines
1.8 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 u32_t _code;
extern u32_t _bss;
extern u32_t _end;
//Enables (SeTs) Interrupt Flag on the processor
static inline void enable_ints()
{
asm("sti");
}
//Disables (CLears) Interrupt Flag on the processor
static inline void disable_ints()
{
asm("cli");
}
//Restarts the computer
static 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
static inline void halt()
{
asm("cli");
asm("hlt");
while (1) ;
}
//Initializes 8253 Programmable Interrupt Timer
static 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 include the bss section
// - this should be 4kb aligned per the linker script
// - this is the amount of RAM the kernel code, data, & bss take
static inline u32_t kernel_size_used()
{
return (u32_t)(&_end)-(u32_t)(&_code);
}
//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
static inline u32_t kernel_size()
{
return (u32_t)(&_bss)-(u32_t)(&_code);
}
//converts a binary-coded-decimal byte to its decimal equivalent
static inline byte bcd2byte(byte bcd)
{
return (10 * ((bcd & 0xF0) >> 4)) + (bcd & 0x0F);
}
//converts a binary-coded-decimal byte to its decimal equivalent
static inline byte byte2bcd(byte bite)
{
return ((bite / 10) << 4) | (bite % 10);
}
#endif