分享
 
 
 

内核FAQ 举例说明

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

内核FAQ(2001.05.01~2001.05.06)

http://LinuxAid.com.cn axing

返回〗〖转发〗

1、 我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!

2、 bootsect.s 中的一个小问题:movsw的问题

3、 0x20,&timer_interrupt它在哪里做过schedule

4、 linux每10ms中断一次,它在哪里做了schedule()

5、 编译核心后的问题:xwindow-->console看不见!

6、 kernel_thread

7、 请问如何得到linux下的命令代码

<b>1、我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!</b>

我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!

信息是:

you dont seem to have a kernel with sound module

enabled,

你编译内核时是不是把声卡安模块方式编译

我声卡支持选择的是y

oss选择的是m

我的声卡买了是YMH734的,可是查出是Aztech的声卡,

以前用oss试过也没没用,不知您有没有装过这种烂声卡!

这样整一遍内核看行不行:

#make mrproper

#make clean

#make menuconfig

在模块的选项中全选为Yes,即 <*>或[*]方式

声卡这部分中:

sound card support选[*]

其它的都选[M]

保存退出后,

#make dep

#make bzImage

#make modules

#make modules_install

为了系统能找到你编译的模块,(以2.4.2为例)将所生成的

模块从/lib/modules/2.4.2/misc/中cp到/lib/modules/misc/

然后再probe你的soundcoard,也许能成功。

<b>2、bootsect.s 中的一个小问题:movsw的问题</b>

ibm的汇编中,movsw进行的操作是:((DI))<-((SI)),那么在at&t汇编中呢?movsw指令进行什么操作呢?

CPU所干的事永远是一样的,不过汇编文法的格式不同而已。

some example:

movw %bx,%ax //mov ax,bx

xorl %eax,%eax //xor eax,eax

movw $1,%ax //mov ax,1

movb x,%ah //mov ah,byte ptr x

movw x,%ax //mov ax,word ptr x

movl x,%eax //mov eax,x

b(8-bit),w(16-bit),l(32-bit)

Most opcodes are identical between AF&T and Intel format,except for

these:

movsSD //movsx

movzSD //movz

S,D are the source and destinaion operand size suffixes.

movswl %ax,%ecx //movsx ecx,ax

Maybe mean something to you!!

<b>3、0x20,&timer_interrupt </b>

0x20,&timer_interrupt它在哪里做过schedule

100个中断/秒(即10ms)每次中断都可能schedule(),许多其它情况也会引起schedule(),比如程序在资源缺乏时会主动请求重新调度,以让出CPU。0x20 timer_interrupt的大致过程如下:

来时钟中断-->保存现场-->标记信息-->do_bottomhalf--->应该重新调度吗?

Yes-->调度

No -->从中断返回

<b>4、linux每10ms中断一次,它在哪里做了schedule() </b>

linux每10ms中断一次,它在哪里做了schedule()。

每当一个系统调用或中断完成时,将调用ret_from_sys_call(),其中有一句:

cmpl $0,__need_resched

jne reschedule

进行调度,时钟中断没10ms一次返回时依据具体情况进行调度选择。

<b>5、编译核心后的问题:xwindow-->console看不见!</b>

我编译了2.4.2,编译过程中一切正常,但重新用新内核启动后,可以进入console和xwindow,但是进入了xwindow后,我用Ctrl+Alt+Backspace想回到console,却黑屏,无论进行什么操作都不行。但是可以使用Ctrl+Alt+Del重新启动,stop过程中也是什么都看不到,但这个命令可以起作用。我用的是RedHat7.0,请各位大侠帮忙!谢谢!

极有可能是显示模式切换与设置时出了问题,建议你:

#cp /etc/X11/XF86Config /etc/X11/XF86Config_save_00

#xf86config

重新配置一遍X系统,看行不行

<b>6、kernel_thread</b>

kernel_thread(int.....)

{

.

.

.

cmp %%sp,%%si

je 1f 这里是不是永远都会跳到1:???????

.

.

.

.

1:

kernel_thread调用clone系统调用创建一个新的进程(根据标志决定是用同一个进程号或另一个进程号),clone实际完成和fork几乎相同的工作,根据返回值为零和非零决定当前是新创建进程和父进程,父进程则跳转到1,新进程则调用fn函数,对照fork应该可以理解,另外三个“:”后面涉及一些linux下汇编的mov语法,你最好熟悉一下。

<b>7、请问如何得到linux下的命令代码</b>

请问如何得到linux下的各种命令的代码,例如ping,adduser

系统中并没有提供,你只有从网上自己找了

ping源码:

* PING.C

/*

/* ping source code distribute by cpu || digger.

/* for unix family only. compil and link success in sco unix.

/* i think linux no problem too. u can try it.

/* before read this code, you shoud know about the principle of

/* tcp/ip, especially icmp protocol, u also should also know some

/* about BSD socket API, and unix system signal programming.

/*

/* cc -o ping ping.c -lsocket, then u will get executable file,

/* but must act as root when cc it, and then set euid attribute

/* for this ping, then u can execute it as common user.

/* because only root can have authority to creat raw socket.

/*

/* i love socket, if so do u,

/* call me, cpu == digger

# include

# include

# include

# include

# include

# include

# include

# include

# include

# include

# define ICMP_ECHO 8 /* icmp echo requir */

# define ICMP_ECHOREPLY 0 /* icmp echo reply */

# define ICMP_HEADSIZE 8 /* icmp packet header size */

# define IP_HEADSIZE 20 /* ip packet header size */

typedef struct tagIpHead /* icmp packet header */

{

u_char ip_verlen; /* ip version and ip header lenth*/

u_char ip_tos; /* ip type of service */

u_short ip_len; /* ip packet lenghth */

u_short ip_id; /* ip packet identification */

u_short ip_fragoff; /* ip packet fragment and offset */

u_char ip_ttl; /* ip packet time to live */

u_char ip_proto; /* ip packet protocol type */

u_short ip_chksum; /* ip packet header checksum */

u_long ip_src_addr; /* ip source ip adress */

u_long ip_dst_addr; /* ip destination ip adress */

} IPHEAD;

typedef struct tagIcmpHead /* icmp header */

{

u_char icmp_type; /* icmp service type */

/* 8 echo require, 0 echo reply */

u_char icmp_code; /* icmp header code */

u_short icmp_chksum; /* icmp header chksum */

u_short icmp_id; /* icmp packet identification */

u_short icmp_seq; /* icmp packet sequent */

u_char icmp_data[1]; /* icmp data, use as pointer */

} ICMPHEAD;

u_short ChkSum( u_short * pIcmpData, int iDataLen )

/* for check sum of icmp header */

{

u_short iSum;

u_short iOddByte;

iSum = 0;

while ( iDataLen > 1 ) { /* xor the next unsigned int data */

iSum ^= *pIcmpData++;

iDataLen -= 2;

}

if ( iDataLen == 1 ) { /* the rest odd byte */

iOddByte = 0;

*((u_char *)&iOddByte) = *(u_char *)pIcmpData;

iSum ^= iOddByte;

}

iSum ^= 0xffff; /* xor 0xffff == not it */

return(iSum);

}

long time_now() /* return time passed by */

/* since 1970.1.1 00:00:00, */

/* in 1/1000000 second */

{

struct timeval now;

long lPassed;

gettimeofday(&now, 0);

lPassed = now.tv_sec * 1000000 + now.tv_usec;

/* now.tv_sec in second */

/* now.tv_usec in 1/1000000 second */

return lPassed;

}

char* host; /* destination host */

char* prog; /* program name */

extern errno; /* system global parameter */

long lSendTime; /* each time when send, change it */

u_short seq; /* the icmp packet seqence */

int iTimeOut; /* time out parameter */

int sock, sent, recvd, max, min, total;

/* sent : icmp packet already sent */

/* recvd: proper icmp packet received */

/* max, min: max min round trip time */

/* total: total round trip time */

/* store to calculate average */

u_long lHostIp; /* host ip adress */

struct sockaddr_in it; /* destination host information */

int ping();

void stat();

main(int argc, char** argv)

{

struct hostent* h;

char buf[200];

char dst_host[32];

int i, namelen;

IPHEAD* pIpHead;

ICMPHEAD* pIcmpHead;

if (argc < 2) { /* ping the destination host */

/* every timeout second */

/* default timeout is 1 second */

printf("usage: %s [-timeout] host|IP ", argv[0]);

exit(0);

}

prog = argv[0];

host = argc == 2 ? argv[1] : argv[2];

iTimeOut = argc == 2 ? 1 : atoi(argv[1]);

/* creat the raw socket for icmp */

if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) {

perror("socket");

exit(2);

}

/* set destination host information */

bzero(&it, sizeof(it));

it.sin_family = AF_INET;

/* check host format */

if ( ( lHostIp = inet_addr(host) ) != INADDR_NONE ) {

/* is available ip adress */

it.sin_addr.s_addr = lHostIp;

strcpy( dst_host, host );

} else if ( h = gethostbyname(host) ) {

/* is available host name */

/* from hosts file of local host */

/* or from DNS */

bcopy(h->h_addr, &it.sin_addr, h->h_length);

sprintf( dst_host, "%s (%s)", host,

inet_ntoa(it.sin_addr) );

} else {

/* bad ip adress or host name */

/* exit */

fprintf( stderr, "bad IP or host " );

exit(3);

}

namelen = sizeof(it);

printf(" Digger pinging %s, send %d bytes ",

dst_host,

IP_HEADSIZE + ICMP_HEADSIZE + sizeof(long)

);

seq = 0; /* first icmp_seq = 0 */

sigset(SIGINT, stat); /* when press del or ctrl+c, call stat */

/* to statistic the result , and then exit */

sigset(SIGALRM, ping); /* hook ping function to timer */

alarm(iTimeOut); /* start timer, call ping every timeout */

/* seconds */

ping();

for ( ;; ) { /* waiting for every echo back */

/* icmp packet and check it */

register size;

register u_char ttl;

register delta;

register iIpHeadLen;

/* block to received echo back datagram */

size = recvfrom(sock, buf, sizeof(buf), 0,

(struct sockaddr *)&it, &namelen);

if (size == -1 && errno == EINTR) {

/* receive error or system call */

/* interrupted */

continue;

}

/* calculate the round trip time, */

/* time when receive minus time when send */

delta = (int)((time_now() - lSendTime)/1000);

/* get echo back packet and check its ip header */

pIpHead = (IPHEAD *)buf;

/* get the ip packet lenth */

/* if too small, not the icmp echoreply packet */

/* give it up */

iIpHeadLen = (int)((pIpHead->ip_verlen & 0x0f) << 2);

if (size < iIpHeadLen + ICMP_HEADSIZE) {

continue;

}

ttl = pIpHead->ip_ttl; /* time to live param */

/* get the icmp header information */

pIcmpHead = (ICMPHEAD *)(buf + iIpHeadLen);

/* not icmp echo reply packet, give it up */

if (pIcmpHead->icmp_type != ICMP_ECHOREPLY) {

continue;

}

/* not proper icmp sequent number, give it up */

if (pIcmpHead->icmp_id != seq || pIcmpHead->icmp_seq != seq) {

continue;

}

/* print out result for each icmp */

/* echo reply information */

sprintf( buf, "icmp_seq=%u bytes=%d ttl=%d",

pIcmpHead->icmp_seq, size, ttl );

fprintf(stderr, "reply from %s: %s time=%d ms ",

host, buf, delta);

/* calculate some statistic information */

/* max, min, average round trip time */

/* received icmp echo reply packet numbers */

max = MAX(delta, max);

min = min ? MIN(delta, min) : delta;

total += delta;

++ recvd;

/* for next icmp sequence */

++ seq;

}

}

ping()

{

char buf[200];

int iPacketSize;

/* make the icmp header information */

ICMPHEAD *pIcmpHead = (ICMPHEAD *)buf;

pIcmpHead->icmp_type = ICMP_ECHO;

pIcmpHead->icmp_code = 0;

pIcmpHead->icmp_id = seq;

pIcmpHead->icmp_seq = seq;

pIcmpHead->icmp_chksum = 0;

/* store time information as icmp packet content, 4 bytes */

/* u may store other information instead */

*((long *)pIcmpHead->icmp_data) = time_now();

iPacketSize = ICMP_HEADSIZE + 4; /* icmp packet length */

/* icmp header check sum */

pIcmpHead->icmp_chksum = ChkSum((u_short *)pIcmpHead,

iPacketSize );

/* remember the time when send for calculate round trip time */

lSendTime = time_now();

/* send the icmp packet to des host */

if ( sendto(sock, buf, iPacketSize, 0, (struct sockaddr *)&it,

sizeof(it) ) < 0) {

perror("send failed");

exit(6);

}

/* packet number been sent */

++sent;

/* reset the timer hooker to me again */

alarm(iTimeOut);

}

void stat() /* print the statistic information for this time's ping */

{

if (sent) {

printf(" ----- %s ping statistics summerized by Digger----- "

, host );

printf("%d packets sent, %d packets received, %.2f%% lost ",

sent, recvd, (float)(sent-recvd)/(float)sent*100 );

}

if (recvd) {

printf("round_trip min/avg/max: %d/%d/%d ms ",

min, total/recvd, max );

}

exit(0);

}

'

责任编辑:axing(2001-06-06 18:45)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有