100 lines
2.0 KiB
C
100 lines
2.0 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;
|
|
|
|
//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, 0xD4); //send command to mouse, not kbd
|
|
outportb(0x60, 0xF5); //disable data reporting
|
|
|
|
outportb(0x64, 0xA7); //disable mouse port
|
|
*/
|
|
outportb(0x64, 0xfe); //restart
|
|
|
|
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 dword kernel_size_used()
|
|
{
|
|
return (dword)(&_end)-(dword)(&_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 dword kernel_size()
|
|
{
|
|
return (dword)(&_bss)-(dword)(&_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
|
|
|
|
|