内核FAQ
时间:2007-02-17 来源:PHP爱好者
1、 我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!
2、 bootsect.s 中的一个小问题:movsw的问题
3、 0x20,&timer_interrupt它在哪里做过schedule
4、 linux每10ms中断一次,它在哪里做了schedule()
5、 编译核心后的问题:xwindow-->console看不见!
6、 kernel_thread
7、 请问如何得到linux下的命令代码
1、我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!
我编译内核时选了声卡支持,还把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选
2、 bootsect.s 中的一个小问题:movsw的问题
3、 0x20,&timer_interrupt它在哪里做过schedule
4、 linux每10ms中断一次,它在哪里做了schedule()
5、 编译核心后的问题:xwindow-->console看不见!
6、 kernel_thread
7、 请问如何得到linux下的命令代码
1、我编译内核时选了声卡支持,还把oss加入了模块,为什么出如下问题!
我编译内核时选了声卡支持,还把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,也许能成功。
2、bootsect.s 中的一个小问题:movsw的问题
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!!
3、0x20,&timer_interrupt
0x20,&timer_interrupt它在哪里做过schedule
100个中断/秒(即10ms)每次中断都可能schedule(),许多其它情况也会引起schedule(),比如程序在资源缺乏时会主动请求重新调度,以让出CPU。0x20 timer_interrupt的大致过程如下:
来时钟中断-->保存现场-->标记信息-->do_bottomhalf--->应该重新调度吗?
Yes-->调度
No -->从中断返回
4、linux每10ms中断一次,它在哪里做了schedule()
linux每10ms中断一次,它在哪里做了schedule()。
每当一个系统调用或中断完成时,将调用ret_from_sys_call(),其中有一句:
cmpl $0,__need_resched
jne reschedule
进行调度,时钟中断没10ms一次返回时依据具体情况进行调度选择。
5、编译核心后的问题:xwindow-->console看不见!
我编译了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系统,看行不行
6、kernel_thread
kernel_thread(int.....)
{
.
.
.
cmp %%sp,%%si
je 1f 这里是不是永远都会跳到1:???????
.
.
.
.
1:
kernel_thread调用clone系统调用创建一个新的进程(根据标志决定是用同一个进程号或另一个进程号),clone实际完成和fork几乎相同的工作,根据返回值为零和非零决定当前是新创建进程和父进程,父进程则跳转到1,新进程则调用fn函数,对照fork应该可以理解,另外三个“:”后面涉及一些linux下汇编的mov语法,你最好熟悉一下。
7、请问如何得到linux下的命令代码
请问如何得到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);
}
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +