toaruos/main.c

136 lines
2.0 KiB
C
Raw Normal View History

2011-01-15 20:01:19 -05:00
#include <system.h>
/*
* memcpy
* Copy from source to destination. Assumes that
* source and destination are not overlapping.
*/
unsigned char *
memcpy(
unsigned char *dest,
const unsigned char *src,
int count
) {
int i;
i = 0;
for ( ; i < count; ++i ) {
dest[i] = src[i];
}
return dest;
}
/*
* memset
* Set `count` bytes to `val`.
*/
unsigned char *
memset(
unsigned char *dest,
unsigned char val,
int count
) {
int i;
i = 0;
for ( ; i < count; ++i ) {
dest[i] = val;
}
return dest;
}
/*
* memsetw
* Set `count` shorts to `val`.
*/
unsigned short *
memsetw(
unsigned short *dest,
unsigned short val,
int count
) {
int i;
i = 0;
for ( ; i < count; ++i ) {
dest[i] = val;
}
return dest;
}
/*
* strlen
* Returns the length of a given `str`.
*/
int
strlen(
const char *str
) {
int i = 0;
while (str[i] != (char)0) {
++i;
}
return i;
}
/*
* inportb
* Read from an I/O port.
*/
unsigned char
inportb(
unsigned short _port
) {
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
/*
* outportb
* Write to an I/O port.
*/
void
outportb(
unsigned short _port,
unsigned char _data
) {
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
2011-01-16 11:56:44 -05:00
void beer() {
int i = 99;
while (i > 0) {
if (i == 1) {
puts ("One bottle of beer on the wall, one bottle of beer. Take one down, pass it around, ");
} else {
2011-01-17 10:24:55 -06:00
kprintf("%d bottles of beer on the wall, %d bottles of beer...\n", i, i);
2011-01-16 11:56:44 -05:00
}
i--;
if (i == 1) {
2011-01-17 10:24:55 -06:00
puts("One bottle of beer on the wall.\n");
2011-01-16 11:56:44 -05:00
} else {
2011-01-17 10:24:55 -06:00
kprintf("%d bottles of beer on the wall.\n", i);
2011-01-16 11:56:44 -05:00
}
timer_wait(3);
}
puts("No more bottles of beer on the wall.\n");
}
2011-01-15 20:01:19 -05:00
/*
* Kernel Entry Point
*/
int
main() {
2011-01-15 20:59:11 -05:00
gdt_install();
2011-01-15 22:11:17 -05:00
idt_install();
2011-01-15 22:41:17 -05:00
isrs_install();
2011-01-15 23:17:42 -05:00
irq_install();
2011-01-16 11:56:44 -05:00
__asm__ __volatile__("sti");
timer_install();
2011-01-16 13:45:51 -05:00
keyboard_install();
2011-01-15 20:01:19 -05:00
init_video();
2011-01-15 22:19:12 -05:00
puts("Good Morning!\n");
2011-01-16 11:56:44 -05:00
beer();
2011-01-15 20:01:19 -05:00
for (;;);
return 0;
}