luxos/include/system.h

104 lines
2.6 KiB
C

#ifndef __SYSTEM_H
#define __SYSTEM_H
// Data type declarations
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;
/* This defines what the stack looks like after an ISR was running */
typedef struct
{
unsigned int gs, fs, es, ds; /* pushed the segs last */
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */
unsigned int int_no, err_code; /* our 'push byte #' and ecodes do this */
unsigned int eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */
} regs;
byte *TextVideoRam;
int cursor_x, cursor_y;
int current_mode_width;
int current_mode_height;
// System functions declaration
void system_init();
void *memcpy(void *dest, const void *src, int count);
void *memset(void *dest, char val, int count);
unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
int strlen (const char *str);
byte inportb (word _port);
byte inb (word _port);
void outportb (word _port, byte _data);
void outb (word _port, byte _data) ;
// GDT, IDT, ISRs, IRQ functions declarations
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
void gdt_install();
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
void idt_install();
void isrs_install();
void irq_install_handler(int irq, void (*handler)(regs *r));
void irq_uninstall_handler(int irq);
void irq_install();
// Initialize system
void *memcpy(void *dest, const void *src, int count)
{
const char *sp = (const char *)src;
char *dp = (char *)dest;
for(; count != 0; count--) *dp++ = *sp++;
return dest;
}
void *memset(void *dest, char val, int count)
{
char *temp = (char *)dest;
for( ; count != 0; count--) *temp++ = val;
return dest;
}
unsigned short *memsetw(unsigned short *dest, unsigned short val, int count)
{
unsigned short *temp = (unsigned short *)dest;
for( ; count != 0; count--) *temp++ = val;
return dest;
}
// strlen -- Get lenght of str
int strlen (const char *str)
{
int i;
for (i = 0; str[i]!=0; i++) {}
return i;
}
byte inportb (word _port) {
byte rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
byte inb (word _port) {
byte rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
void outportb (word _port, byte _data) {
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
void outb (word _port, byte _data) {
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
#endif