90 lines
1.8 KiB
C
90 lines
1.8 KiB
C
#include"stdio.h"
|
|
#include"stdint.h"
|
|
#include"stdbool.h"
|
|
|
|
#define at at8
|
|
#define at8(x) (*(char*)x)
|
|
|
|
uint8_t 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(uint16_t port,uint8_t val)
|
|
{
|
|
asm("out %0,%1"::"a"(val),"Nd"(port));
|
|
}
|
|
|
|
uint8_t inb(uint16_t port)
|
|
{
|
|
uint8_t 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"
|
|
);
|
|
}
|
|
|
|
|
|
uint8_t*const vram=(uint8_t*)0xB8000;
|
|
void putpixel(uint8_t*const screen,int32_t x,int32_t y,int32_t color)
|
|
{
|
|
const uint32_t width=320;
|
|
const uint32_t height=240;
|
|
uint32_t where=x*width+y*height;
|
|
screen[where]=color&0xff;
|
|
screen[where+1]=(color>>8)&0xff;
|
|
screen[where+2]=(color>>16)&0xff;
|
|
}
|
|
|
|
// Entry point
|
|
void kernelmain(void*multiboot_structure,uint32_t magicnumber)
|
|
{
|
|
|
|
// Clear text mode buffer
|
|
for(int32_t i=0;i<1000;++i)
|
|
((uint16_t*)0xb8000)[i]=0;
|
|
|
|
puts("");
|
|
puts("");
|
|
puts("This is an operating system or something.");
|
|
|
|
print("Multiboot structure:");
|
|
printi16((int32_t)multiboot_structure);
|
|
puts("");
|
|
|
|
print("Magic number:");
|
|
printi16((int32_t)magicnumber);
|
|
puts("");
|
|
|
|
putpixel(vram,3,3,0x0000ffff);
|
|
|
|
//((char*)0x64)[0]=(uint8_t)0xaa;
|
|
outb(0x64,0xaa);
|
|
outb(0x64,0xee);
|
|
|
|
uint32_t lastchar=0;
|
|
|
|
stdout->seek=0;
|
|
// Check PS/2 status register
|
|
while(true)
|
|
{
|
|
|
|
uint32_t 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();
|
|
}
|