Ò»¡¢»ù±¾Ë¼Ï룺
ÔÚϵͳµ÷Óú¯ÊýÖÐÌí¼Óϵͳ³Ë·¨ sysMul(int a, int b); ¼ÆËã aÓëbµÄ³Ë»ý¡£½«¸Ãϵͳ·½·¨·âװΪ³Ë·½ usrPow(int a, int n); ¼ÆËã a µÄ n ´Î·½¡£
¶þ¡¢×¼±¸¹¤×÷£º
1.»·¾³£ºFedora 6
2.ÎÒʹÓõÄFedora6ÖÐûÓÐÌṩԴ´úÂ룬ÓÖ?£¬»¹ºÃÔÚÏÈÇ°µÄʵÑéÖÐÒѾ°²×°¹ý2.6.18.1ÄÚºËÔ´´úÂë°ü£»²»ÏêÊöÁË¡£
Èý¡¢Ïêϸ²½Öè
1. ÔÚkernel/sys.cÖÐÌí¼Óϵͳµ÷дº¯Êý£º
asmlinkage int sysMul(int a, int b)
{
int c;
c = a*b;
return c;
}
2.¸øеÄϵͳµ÷Ó÷ÖÅäµ÷Óúţº
ÔÚinclude/asm-i386/unistd.hÖÐÌí¼ÓÈçÏ´úÂ룺
#define __NR_sysAdd 264
3.ÔÚϵͳµ÷Óñí/arch/i386/kernel/entry.S ÖÐÌí¼Ó´úÂëÖ¸ÏòÐÂдµÄϵͳµ÷Óú¯Êý£º.long SYMBOL_NAME(sysMul)
4.ʹÓÃһϵÁÐmake£¬±àÒëÄںˣ¨Õâ¸öºÍskyeyeÀïÅÜuClinux¹ý³Ì²î²»¶à£¬²»ÏêÊöÁË£©£¬½«Éú³ÉµÄÄں˷ŵ½bootĿ¼ÖÐÈ¥£¬
5.ÐÞ¸Ägrub£¬Ìí¼ÓÒ»¸öеÄÒýµ¼Ï
ÔÚmenu.lstÖÐÌí¼ÓÈçÏ´úÂ룺
title testRoot
root(hd0, 0)
kernel /bzImage ro root=/dev/hda1
6.ÖØÆôºó£¬ÔÚÆô¶¯Ä¿Â¼ÀïÓÐÁËtestRootÑ¡ÏÏÖÔÚϵͳ°üº¬ÎÒÃÇ×Ô¼ºÐ´µÄϵͳµ÷ÓÃsysMul()ÁË
7.¿ªÊ¼ÎÒÃÇÓû§Àý³ÌµÄ±àдÁË£¬ÔÚrootĿ¼Ï½¨ uPow.cÎļþ
1) ·âװϵͳµ÷ÓõÄÓÐAPIζµÀ¶ùµÄusrPow()º¯Êý
#inculde
#include
_syscall2(int, sysMul, int, a, int, b)
int usrPow(int m, int n)
{
int i;
int r = 1;
for (i=0; i < n; i++)
{
r = sysMul(r, m);
}
return r;
}
2)дʹÓÃÓû§API usrPow()º¯ÊýµÄmain()
main()
{
int bNum, pNum;
int result;
printf("input:\n");
scanf("%d%d", &bNum, &pNum);
result = usrPow(bNum, pNum);
printf("result = ", result);
}
8.±àÒë
gcc -o uPow uPow.c
9.ÔËÐС£