75 lines
1.5 KiB
C
75 lines
1.5 KiB
C
#include"stdio.h"
|
|
#include"stdbool.h"
|
|
|
|
#define at at8
|
|
#define at8(x) (*(char*)x)
|
|
|
|
unsigned char kbdus[128]={0,27,'1','2','3','4','5','6','7','8','9','0','-','=','\b','\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',0,'a','s','d','f','g','h','j','k','l',';','\'','`',0,'\\','z','x','c','v','b','n','m',',','.','/',0,'*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
void outb(unsigned short port,unsigned char val)
|
|
{
|
|
asm("out %0,%1"::"a"(val),"Nd"(port));
|
|
}
|
|
|
|
unsigned char inb(unsigned short port)
|
|
{
|
|
unsigned char ret;
|
|
asm("in %1,%0":"=a"(ret):"Nd"(port));
|
|
return ret;
|
|
}
|
|
|
|
__attribute__ ((naked)) static void halt(void)
|
|
{
|
|
asm(
|
|
"cli\n"
|
|
"hlt\n"
|
|
"jmp halt\n"
|
|
);
|
|
}
|
|
|
|
// Entry point
|
|
void kernelmain(void*multiboot_structure,unsigned magicnumber)
|
|
{
|
|
|
|
// Clear text mode buffer
|
|
for(int i=0;i<1000;++i)
|
|
((unsigned short*)0xb8000)[i]=0;
|
|
|
|
puts("");
|
|
puts("");
|
|
puts("This is an operating system or something.");
|
|
|
|
print("Multiboot structure:");
|
|
printi16((int)multiboot_structure);
|
|
puts("");
|
|
|
|
print("Magic number:");
|
|
printi16((int)magicnumber);
|
|
puts("");
|
|
|
|
//((char*)0x64)[0]=(unsigned char)0xaa;
|
|
outb(0x64,0xaa);
|
|
outb(0x64,0xee);
|
|
|
|
unsigned int lastchar=0;
|
|
|
|
stdout->seek=0;
|
|
// Check PS/2 status register
|
|
while(true)
|
|
{
|
|
|
|
unsigned int r=inb(0x60);
|
|
while(!(r&0x80)&&(r!=lastchar))
|
|
{
|
|
if(r=='\b')stdout->seek-=2;
|
|
else if(r!=0)fputc(kbdus[r],stdout);
|
|
lastchar=r;
|
|
}
|
|
|
|
if(stdout->seek>=1000)
|
|
stdout->seek=0;
|
|
}
|
|
|
|
halt();
|
|
}
|