📄 kernel.c
字号:
/*
esp=0x3ffff0
ds=es=fs=gs=ss=0
cs=0x80000
0000:0000 boot drive ,word
0000:0002 start physical address of loader's data dword
copyright 2005 by YaoSiHai
www.woos.cn
*/
#include "kernel.h"
//KDSM must be at the start address of linked file!!!
_asm
{
_DATA segment dword public use32 'DATA'
align 4
kdsm db 'K','d','S','m'
_DATA ends
}
char *copyright ="shyna kernel v1";
void data_init();
void init_file_system_layer();
void hd_init();//initializing basic Disk Driver
void main_start()
{
int x,y;
char str[32];
byte *tp;
data_init();
tp=adjust_address("Initializing kernel...");
write_console(tp,0xa);
hd_init();//initializing basic Disk Driver
init_file_system_layer();
tp=adjust_address("Kernel is ready.\n");
write_console(tp,0xa);
tp=adjust_address("OK,this is the end of the DEMO kernel process\n");
write_console(tp,x);
while(1)
{
}
}
void init_file_system_layer()
{
write_console(adjust_address("File System-->"),0xa);
}
void hd_init()//initializing basic Disk Driver
{
write_console(adjust_address("Disk Driver-->"),0xa);
}
void data_init()
{
//at this point DS,SS is at Kernel(DS=GS=0)
int i;
char *pp=LOADER_CODE_START;
uint p,dt;
//step 1:
//Create a DS selector for this thread
while(1)
{
if(pp[0]=='K'&&pp[1]=='d'&&pp[2]=='S'&&pp[3]=='m')
{
//adjust ,needed by compiler and linker
p=pp;
p&=0xfffffff0;
break;
}
pp++;
}
_asm
{
;ds=0=gs;
mov eax,p;
mov dword ptr gs:[2],eax;
}
}
void memset(byte *p,byte what,int size)
{
//work at current ds
while(size>0)
{
*p=what;
p++;
size--;
}
}
void memcpy(byte *from,byte *to,int size)
{
//work at current ds
while(size>0)
{
*to=*from;
from++;
to++;
size--;
}
}
int memcmp(byte *a,byte*b,int size)
{
while(size>0)
{
if(*a==*b)
size--;
else return FALSE;
a++;b++;
}
return TRUE;
}
byte inb(uint reg)
{
_asm
{
push edx
mov edx,reg
xor eax,eax
in al,dx
pop edx
}
}
word inw(uint reg)
{
_asm
{
push edx
mov edx,reg
in ax,dx
pop edx
}
}
void outw(u32 data,u32 reg)
{
_asm
{
mov edx,reg
mov eax,data
out dx,ax
}
}
void outb(u32 data,u32 reg)
{
_asm
{
mov edx,reg
mov eax,data
out dx,al
}
}
byte * adjust_address(byte *s)
{
uint p;
_asm
{
mov eax,dword ptr gs:[2];
add eax,s;
mov p,eax;
}
return p;
}
int get_boot_drive_id()
{
int i;
_asm
{
xor eax,eax
mov ax,word ptr gs:[0];
mov i,eax;
}
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -