漫谈Linux龙芯及其软件开发

上传人:m**** 文档编号:587381236 上传时间:2024-09-05 格式:PPT 页数:22 大小:688.02KB
返回 下载 相关 举报
漫谈Linux龙芯及其软件开发_第1页
第1页 / 共22页
漫谈Linux龙芯及其软件开发_第2页
第2页 / 共22页
漫谈Linux龙芯及其软件开发_第3页
第3页 / 共22页
漫谈Linux龙芯及其软件开发_第4页
第4页 / 共22页
漫谈Linux龙芯及其软件开发_第5页
第5页 / 共22页
点击查看更多>>
资源描述

《漫谈Linux龙芯及其软件开发》由会员分享,可在线阅读,更多相关《漫谈Linux龙芯及其软件开发(22页珍藏版)》请在金锄头文库上搜索。

1、漫谈Linux,龙芯及其软件开发陈华才2010.03目录Linux及相关概念Linux开发者初步教程Linux及相关概念软件硬件操作系统CPUDOS,WindowsLinux,UnixX86,IA64MIPS,ARMLinux及相关概念(续)X86LinuxDOSWindowsFreeBSDX86X86是使用最广泛的是使用最广泛的CPUCPU,LinuxLinux是使用最广泛的是使用最广泛的操作系统操作系统FreeBSDFreeBSD是是UnixUnix的一种,可以跑在的一种,可以跑在X86 PCX86 PC上上龙芯(龙芯(GodsonGodson,LoongsonLoongson)是)是MI

2、PSMIPS的一种的一种X86IA64PowerPC龙芯LinuxLinux及相关概念(续)Q Q:WindowsWindows和和LinuxLinux啥关系?啥关系?A A:决定于在什么平台上:决定于在什么平台上:如果同在如果同在X86X86上,上,WindowsWindows和和LinuxLinux好比是中国人和美国人好比是中国人和美国人的关系(近)。但的关系(近)。但X86X86上的上的WindowsWindows和龙芯上的和龙芯上的LinuxLinux则如则如同地球人和火星人的关系(远)同地球人和火星人的关系(远)在在Linux/X86Linux/X86上,可以用上,可以用WineWi

3、ne来运行来运行WindowsWindows程序,但程序,但Linux/Linux/LoongsonLoongson上则不行上则不行Q Q:Linux/X86Linux/X86与与Linux/Linux/LoongsonLoongson啥关系?啥关系?A A:一样的皮肤(表象),不一样的基因(本质):一样的皮肤(表象),不一样的基因(本质)从应用层面和源代码的高级语言层面看来,几乎完全一样。从应用层面和源代码的高级语言层面看来,几乎完全一样。从编译后的二进制代码看来,完全不同。从编译后的二进制代码看来,完全不同。Linux与龙芯龙芯龙芯CPUCPU系列系列 龙芯一号:龙芯一号:3232位嵌入式

4、位嵌入式MIPS CPUMIPS CPU 龙芯二号:龙芯二号:6464位通用位通用MIPS CPUMIPS CPU,有,有2A2A、2B2B、2C2C、2D2D、2E2E和和2F2F等型号(从等型号(从2E2E开始进入实用阶段)开始进入实用阶段) 龙芯三号:龙芯三号:6464位多核位多核MIPS CPUMIPS CPU,目前只有,目前只有3A3ALinuxLinux最初只支持最初只支持X86X86,后来扩展到其他平台,后来扩展到其他平台 Linux-2.6.23Linux-2.6.23:开始支持龙芯:开始支持龙芯2E2E Linux-2.6.33Linux-2.6.33:开始支持龙芯:开始支持

5、龙芯2F2FLinux开发者初步教程Q Q:LinuxLinux有没有有没有VCVC?有没有?有没有JavaJava?有没有?有没有?A A:LinuxLinux支持支持C C,C+C+,JavaJava,PascalPascal,ADAADA几乎地球上的每一种编程语言。几乎地球上的每一种编程语言。但,但,LinuxLinux不支持不支持VCVC,因为,因为VCVC不是语言,是不是语言,是IDEIDE(集成开发环境)(集成开发环境)Q Q:LinuxLinux有没有有没有IDEIDE?A A:有。:有。Qt CreatorQt Creator,KDevelopKDevelop,GladeGla

6、deLinux开发者初步教程(续)如果不用如果不用IDEIDE 编辑器编辑器+ +编译器编译器+ +调试器调试器 编辑器:编辑器:VimVim,EmacsEmacs,KEditKEdit,GEditGEdit VimVim插件,如插件,如cscopecscope,ctagsctags可用于函数定位可用于函数定位 如果不用插件,文件内用如果不用插件,文件内用/ /命令搜索,目录内用命令搜索,目录内用grepgrep命令搜索,命令搜索,findfind用于文件名搜索用于文件名搜索 编译器:编译器:gccgcc,jdkjdk gccgcc = GNU C Compiler = GNU C Compi

7、ler GNU Compiler Collector GNU Compiler Collector 调试器:调试器:gdbgdb,ddddddLinuxLinux可以在纯文本环境下开发任意程序,包括可以在纯文本环境下开发任意程序,包括GUIGUI程序!程序!Linux开发者初步教程(续)关于跨平台源代码跨平台源代码跨平台 vs. vs. 目标代码跨平台目标代码跨平台前者是一次编写,处处编译(前者是一次编写,处处编译(Qt/C+Qt/C+)后者是一次编译,处处运行(后者是一次编译,处处运行(JavaJava)跨操作系统跨操作系统 vs. vs. 跨硬件平台跨硬件平台WineWine,Cygwin

8、Cygwin等等APIAPI模拟器即可实现跨操作系统模拟器即可实现跨操作系统(硬件平台相同)(硬件平台相同)JavaJava,PythonPython脚本语言才可以跨硬件平台脚本语言才可以跨硬件平台如何参与Linux软件开发?Linux User当久了,想成为一个Linux Developer1 1,作为用户,给开发者提需求,作为用户,给开发者提需求2 2,作为测试员,给开发者反映,作为测试员,给开发者反映BugBug3 3,包装开发,如制作,包装开发,如制作RPMRPM、DEBDEB等软件包等软件包4 4,直接参与代码编写,直接参与代码编写如何阅读代码?参与代码编写第一步,阅读已有的代码一个

9、动辄上万行代码的工程,如何读懂,从哪里读起?1 1,如果有文档,如果有文档/ /书籍,参照阅读书籍,参照阅读2 2,如果没有文档(自由软件大都文档不全),如果没有文档(自由软件大都文档不全)找准入口点找准入口点理清主脉络理清主脉络顾名思义看功能顾名思义看功能如何阅读代码?(续)找准入口点高级语言(高级语言(C C语言)语言)应用程序:从应用程序:从main()main()开始开始内核模块:从内核模块:从XXX_initXXX_init()()开始开始搜索关键语句搜索关键语句module_init(XXX_initmodule_init(XXX_init); );内核本身:内核本身:LinuxL

10、inux内核从内核从_start_kernelstart_kernel()()开始开始XenXen内核从内核从_start_xenstart_xen()()开始开始汇编语言汇编语言可能从可能从start/_startstart/_start等类似词汇的标号处开始,大多等类似词汇的标号处开始,大多会用会用.global/.global/.globlglobl伪指令标识伪指令标识如何阅读代码?(续)理清主脉络理清主脉络 去粗取精,眼不见为净,去掉没用的,留下有用的。去粗取精,眼不见为净,去掉没用的,留下有用的。1 1,代码,代码 vs. vs. 注释注释 去掉去掉/ /*/ #if 0 #/ /*

11、/ #if 0 #endifendif2 2,程序流程,程序流程 vs. vs. 变量声明变量声明 去掉变量声明,简单赋值去掉变量声明,简单赋值3 3,功能语句,功能语句 vs. vs. 调试语句调试语句 去掉去掉printfprintf(), (), printkprintk(), debug()(), debug()4 4,正常流程,正常流程 vs. vs. 异常流程异常流程 去掉返回值检查,去掉返回值检查,try-catchtry-catch中的中的catchcatch子句子句5 5,常见路径,常见路径 vs. vs. 罕见路径罕见路径 SwitchSwitch,if-elseif-el

12、se结构等只保留最常见的一种情况结构等只保留最常见的一种情况如何阅读代码?(续)举例:Gxemul一个运行在一个运行在X86X86上的龙芯模拟器上的龙芯模拟器入口点是入口点是main()main()函数函数int main(int argc, char *argv) /* Setting constants: */ const int constant_yes = 1; const int constant_true = 1; const int constant_no = 0; const int constant_false = 0; struct emul *emuls; char *d

13、iskimages = NULL; int n_diskimages = 0; int n_emuls; int i; progname = argv0; /* Initialize all emulator subsystems: */ console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *); if (emuls = NULL) fprintf(stderr, out of memoryn); e

14、xit(1); /* Allocate space for a simple emul setup: */ n_emuls = 1; emuls0 = emul_new(NULL); if (emuls0 = NULL) fprintf(stderr, out of memoryn); exit(1); get_cmd_args(argc, argv, emuls0, &diskimages, &n_diskimages); if (!skip_srandom_call) struct timeval tv; gettimeofday(&tv, NULL); srandom(tv.tv_sec

15、 getpid() tv.tv_usec); /* Print startup message: */ debug(GXemul); debug( Copyright (C) 2003-2006 Anders Gavaren); debug(Read the source code and/or documentation for other Copyright messages.nn); if (emuls0-machines0-machine_type = MACHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); /

16、* Simple initialization, from command line arguments: */ if (n_emuls 0) /* Make sure that there are no configuration files as well: */ for (i=1; iargc; i+) if (argvi0 = ) fprintf(stderr, You can either start one emulation with one machine directly from the commandnline, or start one or more emulatio

17、ns using configuration files. Not both.n); exit(1); /* Initialize one emul: */ emul_simple_init(emuls0); /* Initialize emulations from config files: */ for (i=1; iargc; i+) if (argvi0 = ) char tmpstr50; char *s = argvi + 1; if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls

18、 = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls = NULL) fprintf(stderr, out of memoryn); exit(1); /* Always allow slave xterms when using multiple emulations: */ console_allow_slaves(1); /* Destroy the temporary emuls0, since it will be overwritten: */ if (n_emuls = 1) emul_destroy(emu

19、ls0); emulsn_emuls - 1 = emul_create_from_configfile(s); snprintf(tmpstr, sizeof(tmpstr), emul%i, n_emuls-1); if (n_emuls = 0) fprintf(stderr, No emulations defined. Maybe you forgot to use -E xx and/or -e yy, to specifynthe machine type. For example:nn %s -e 3max -d disk.imgnn to boot an emulated D

20、ECstation 5000/200 with a disk image.n, progname); exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); /* Run all emulations: */ emul_run(emuls, n_emuls); /* * Deinitialize everything: */ console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NONE) n_emuls -; else for

21、(i=0; imachines0, diskimagesi); if (n_emuls 0) for (i=1; iargc; i+) if (argvi0 = ) fprintf(stderr, You can either start one emulation with one machine directly from the commandnline, or start one or more emulations using configuration files. Not both.n); exit(1); emul_simple_init(emuls0); for (i=1;

22、iargc; i+) if (argvi0 = ) char tmpstr50; char *s = argvi + 1; if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls = NULL) fprintf(stderr, out of memoryn); exit(1); console_allow_slaves(1); if (n_emuls = 1) emul_des

23、troy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); snprintf(tmpstr, sizeof(tmpstr), emul%i, n_emuls-1); if (n_emuls = 0) fprintf(stderr, No emulations defined. Maybe you forgot to use -E xx and/or -e yy, to specifynthe machine type. For example:nn %s -e 3max -d disk.imgnn to boot an em

24、ulated DECstation 5000/200 with a disk image.n, progname); exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) for

25、(i=1; iargc; i+) if (argvi0 = ) fprintf(stderr, You can either start one emulation with one machine directly from the commandnline, or start one or more emulations using configuration files. Not both.n); exit(1); emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) char tmpstr50; char *s =

26、argvi + 1; if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls = NULL) fprintf(stderr, out of memoryn); exit(1); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_c

27、onfigfile(s); snprintf(tmpstr, sizeof(tmpstr), emul%i, n_emuls-1); if (n_emuls = 0) fprintf(stderr, No emulations defined. Maybe you forgot to use -E xx and/or -e yy, to specifynthe machine type. For example:nn %s -e 3max -d disk.imgnn to boot an emulated DECstation 5000/200 with a disk image.n, pro

28、gname); exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) for (i=1; iargc; i+) if (argvi0 = ) fprintf(stderr, You

29、 can either start one emulation with one machine directly from the commandnline, or start one or more emulations using configuration files. Not both.n); exit(1); emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls

30、 = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls = NULL) fprintf(stderr, out of memoryn); exit(1); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); snprintf(tmpstr, sizeof(tmpstr), emul%i, n_emuls-1); if (n_emuls = 0) fpr

31、intf(stderr, No emulations defined. Maybe you forgot to use -E xx and/or -e yy, to specifynthe machine type. For example:nn %s -e 3max -d disk.imgnn to boot an emulated DECstation 5000/200 with a disk image.n, progname); exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emu

32、l_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) for (i=1; iargc; i+) if (argvi0 = ) fprintf(stderr, You can either start one emulation with one machine directly from the commandnline, or sta

33、rt one or more emulations using configuration files. Not both.n); exit(1); emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls = NULL) fprintf(stderr, o

34、ut of memoryn); exit(1); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); snprintf(tmpstr, sizeof(tmpstr), emul%i, n_emuls-1); if (n_emuls = 0) fprintf(stderr, No emulations defined. Maybe you forgot to use -E xx and/or -e yy, to spec

35、ifynthe machine type. For example:nn %s -e 3max -d disk.imgnn to boot an emulated DECstation 5000/200 with a disk image.n, progname); exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NO

36、NE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) for (i=1; iargc; i+) if (argvi0 = ) exit(1); emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_em

37、uls); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); if (n_emuls = 0) exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHIN

38、E_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) for (i=1; iargc; i+) if (argvi0 = ) exit(1); emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) *

39、n_emuls); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); if (n_emuls = 0) exit(1); device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MA

40、CHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) emul_simple_init(emuls0); for (i=1; iargc; i+) if (argvi0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_

41、emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0-machine_type = MACHINE_NONE) n_emuls -; else for (i=0; imachines0, diskimagesi); if (n_emuls 0) emul_simple_init(emuls0); for (i=1; iargc; i+) if (argv

42、i0 = ) if (strlen(s) = 0 & i+1 argc & argvi+10 != ) i+; s = argvi; n_emuls +; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_emuls = 1) emul_destroy(emuls0); emulsn_emuls - 1 = emul_create_from_configfile(s); emul_run(emuls, n_emuls); console_deinit(); for (i

43、=0; in_emuls; i+) emul_destroy(emulsi); return 0;int main(int argc, char *argv) console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *); emuls0 = emul_new(NULL); get_cmd_args(argc, argv, emuls0, &diskimages, &n_diskimages); for (

44、i=0; imachines0, diskimagesi); if (n_emuls 0) emul_simple_init(emuls0); emul_run(emuls, n_emuls); console_deinit(); for (i=0; imachines0, diskimagesi); /给机器添加磁盘 emul_simple_init(emuls0); /模拟机器初始化 emul_run(emuls, n_emuls); /运行模拟机器 console_deinit(); /控制台销毁 emul_destroy(emulsi); /模拟机器销毁 return 0; /返回是不

45、是很简单?几点看法学习学习Linux Linux 仇视仇视WindowsWindows 存在的就是合理的,存在的就是合理的,WindowsWindows有其优点有其优点 仇视微软是一种病态仇视微软是一种病态 LinusLinus TorvaldsTorvalds LinuxLinux要吸收要吸收WindowsWindows的优点的优点学习学习Linux Linux 抛弃抛弃WindowsWindows 各取所需,要什么用什么各取所需,要什么用什么 和谐共处,双系统并不丢人和谐共处,双系统并不丢人学习学习Linux Linux 抛弃抛弃GUIGUI 爱美之心人皆有之,爱美之心人皆有之,KDE/GnomeKDE/Gnome有功无罪有功无罪 命令行不是拿来炫耀的,而是给人多一种选择命令行不是拿来炫耀的,而是给人多一种选择学习学习Linux Linux 人云亦云人云亦云 真正的高手大都低调,哗众取宠的大都是半吊子真正的高手大都低调,哗众取宠的大都是半吊子 谁用谁知道,没有调查就没有发言权谁用谁知道,没有调查就没有发言权谢谢!欢迎提问

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号