Presentation is loading. Please wait.

Presentation is loading. Please wait.

漫谈 Linux ,龙芯及其软件开发 陈华才2010.03. 目录 Linux 及相关概念 Linux 及相关概念 Linux 开发者初步教程 Linux 开发者初步教程.

Similar presentations


Presentation on theme: "漫谈 Linux ,龙芯及其软件开发 陈华才2010.03. 目录 Linux 及相关概念 Linux 及相关概念 Linux 开发者初步教程 Linux 开发者初步教程."— Presentation transcript:

1 漫谈 Linux ,龙芯及其软件开发 陈华才2010.03

2 目录 Linux 及相关概念 Linux 及相关概念 Linux 开发者初步教程 Linux 开发者初步教程

3 Linux 及相关概念 软件 硬件 操作系统 CPU DOS , Windows Linux , Unix X86 , IA64 MIPS , ARM

4 Linux 及相关概念(续) X86 Linux DOS Windows FreeBSD X86 是使用最广泛的 CPU , Linux 是使用最广泛的 操作系统 X86 是使用最广泛的 CPU , Linux 是使用最广泛的 操作系统 FreeBSD 是 Unix 的一种,可以跑在 X86 PC 上 FreeBSD 是 Unix 的一种,可以跑在 X86 PC 上 龙芯( Godson , Loongson )是 MIPS 的一种 龙芯( Godson , Loongson )是 MIPS 的一种 X86IA64PowerPC 龙芯 Linux

5 Linux 及相关概念(续) Q : Windows 和 Linux 啥关系? Q : Windows 和 Linux 啥关系? A :决定于在什么平台上: 如果同在 X86 上, Windows 和 Linux 好比是中国人和美国人 的关系(近)。但 X86 上的 Windows 和龙芯上的 Linux 则如 同地球人和火星人的关系(远) 在 Linux/X86 上,可以用 Wine 来运行 Windows 程序,但 Linux/Loongson 上则不行 A :决定于在什么平台上: 如果同在 X86 上, Windows 和 Linux 好比是中国人和美国人 的关系(近)。但 X86 上的 Windows 和龙芯上的 Linux 则如 同地球人和火星人的关系(远) 在 Linux/X86 上,可以用 Wine 来运行 Windows 程序,但 Linux/Loongson 上则不行 Q : Linux/X86 与 Linux/Loongson 啥关系? Q : Linux/X86 与 Linux/Loongson 啥关系? A :一样的皮肤(表象),不一样的基因(本质) 从应用层面和源代码的高级语言层面看来,几乎完全一样。 从编译后的二进制代码看来,完全不同。 A :一样的皮肤(表象),不一样的基因(本质) 从应用层面和源代码的高级语言层面看来,几乎完全一样。 从编译后的二进制代码看来,完全不同。

6 Linux 与龙芯 龙芯 CPU 系列 龙芯 CPU 系列 – 龙芯一号: 32 位嵌入式 MIPS CPU – 龙芯二号: 64 位通用 MIPS CPU ,有 2A 、 2B 、 2C 、 2D 、 2E 和 2F 等型号(从 2E 开始进入实用阶段) – 龙芯三号: 64 位多核 MIPS CPU ,目前只有 3A Linux 最初只支持 X86 ,后来扩展到其他平台 Linux 最初只支持 X86 ,后来扩展到其他平台 –Linux-2.6.23 :开始支持龙芯 2E –Linux-2.6.33 :开始支持龙芯 2F

7 Linux 开发者初步教程 Q : Linux 有没有 VC ?有没有 Java ?有没有 …… ? Q : Linux 有没有 VC ?有没有 Java ?有没有 …… ? A : Linux 支持 C , C++ , Java , Pascal , ADA …… 几乎地球上的每一种编程语言。 但, Linux 不支持 VC ,因为 VC 不是语言,是 IDE (集成开发环境) A : Linux 支持 C , C++ , Java , Pascal , ADA …… 几乎地球上的每一种编程语言。 但, Linux 不支持 VC ,因为 VC 不是语言,是 IDE (集成开发环境) Q : Linux 有没有 IDE ? Q : Linux 有没有 IDE ? A :有。 Qt Creator , KDevelop , Glade …… A :有。 Qt Creator , KDevelop , Glade ……

8 Linux 开发者初步教程(续) 如果不用 IDE …… 如果不用 IDE …… – 编辑器 + 编译器 + 调试器 – 编辑器: Vim , Emacs , KEdit , GEdit …… Vim 插件,如 cscope , ctags 可用于函数定位 Vim 插件,如 cscope , ctags 可用于函数定位 如果不用插件,文件内用 / 命令搜索,目录内用 grep 命令搜索, find 用于文件名搜索 …… 如果不用插件,文件内用 / 命令搜索,目录内用 grep 命令搜索, find 用于文件名搜索 …… – 编译器: gcc , jdk …… gcc = GNU C Compiler  GNU Compiler Collector gcc = GNU C Compiler  GNU Compiler Collector – 调试器: gdb , ddd …… Linux 可以在纯文本环境下开发任意程序,包括 GUI 程序! Linux 可以在纯文本环境下开发任意程序,包括 GUI 程序!

9 Linux 开发者初步教程(续) 关于跨平台 关于跨平台 – 源代码跨平台 vs. 目标代码跨平台 前者是一次编写,处处编译( Qt/C++ ) 前者是一次编写,处处编译( Qt/C++ ) 后者是一次编译,处处运行( Java ) 后者是一次编译,处处运行( Java ) – 跨操作系统 vs. 跨硬件平台 Wine , Cygwin 等 API 模拟器即可实现跨操作系统 (硬件平台相同) Wine , Cygwin 等 API 模拟器即可实现跨操作系统 (硬件平台相同) Java , Python 脚本语言才可以跨硬件平台 Java , Python 脚本语言才可以跨硬件平台

10 如何参与 Linux 软件开发? Linux User 当久了,想成为一个 Linux Developer Linux User 当久了,想成为一个 Linux Developer –1 ,作为用户,给开发者提需求 –2 ,作为测试员,给开发者反映 Bug –3 ,包装开发,如制作 RPM 、 DEB 等软件包 –4 ,直接参与代码编写

11 如何阅读代码? 参与代码编写第一步,阅读已有的代码 参与代码编写第一步,阅读已有的代码 一个动辄上万行代码的工程,如何读懂, 从哪里读起? 一个动辄上万行代码的工程,如何读懂, 从哪里读起? –1 ,如果有文档 / 书籍,参照阅读 –2 ,如果没有文档(自由软件大都文档不全) 找准入口点 找准入口点 理清主脉络 理清主脉络 顾名思义看功能 顾名思义看功能

12 如何阅读代码?(续) 找准入口点 找准入口点 – 高级语言( C 语言) 应用程序:从 main() 开始 应用程序:从 main() 开始 内核模块:从 XXX_init() 开始 搜索关键语句 module_init(XXX_init); 内核模块:从 XXX_init() 开始 搜索关键语句 module_init(XXX_init); 内核本身: Linux 内核从 __start_kernel() 开始 Xen 内核从 __start_xen() 开始 内核本身: Linux 内核从 __start_kernel() 开始 Xen 内核从 __start_xen() 开始 – 汇编语言 可能从 start/_start 等类似词汇的标号处开始,大多 会用.global/.globl 伪指令标识 可能从 start/_start 等类似词汇的标号处开始,大多 会用.global/.globl 伪指令标识

13 如何阅读代码?(续) 理清主脉络 理清主脉络 – 去粗取精,眼不见为净,去掉没用的,留下有用的。 1 ,代码 vs. 注释 1 ,代码 vs. 注释 – 去掉 // … /* … */ #if 0 … #endif 2 ,程序流程 vs. 变量声明 2 ,程序流程 vs. 变量声明 – 去掉变量声明,简单赋值 3 ,功能语句 vs. 调试语句 3 ,功能语句 vs. 调试语句 – 去掉 printf(), printk(), debug() … 4 ,正常流程 vs. 异常流程 4 ,正常流程 vs. 异常流程 – 去掉返回值检查, try-catch 中的 catch 子句 …… 5 ,常见路径 vs. 罕见路径 5 ,常见路径 vs. 罕见路径 –Switch , if-else 结构等只保留最常见的一种情况

14 如何阅读代码?(续) 举例: Gxemul 举例: Gxemul – 一个运行在 X86 上的龙芯模拟器 – 入口点是 main() 函数

15 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 **diskimages = NULL; int n_diskimages = 0; int n_emuls; int i; progname = argv[0]; /* 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 memory\n"); exit(1); } /* Allocate space for a simple emul setup: */ n_emuls = 1; emuls[0] = emul_new(NULL); if (emuls[0] == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { struct timeval tv; gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } /* Print startup message: */ debug("GXemul"); debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for other Copyright messages.\n\n"); if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i machines[0], diskimages[i]); } /* Simple initialization, from command line arguments: */ if (n_emuls > 0) { /* Make sure that there are no configuration files as well: */ for (i=1; i<argc; i++) if (argv[i][0] == '@') { fprintf(stderr, "You can either start one " "emulation with one machine directly from " "the command\nline, or start one or more " "emulations using configuration files." " Not both.\n"); exit(1); } /* Initialize one emul: */ emul_simple_init(emuls[0]); } /* Initialize emulations from config files: */ for (i=1; i<argc; i++) { if (argv[i][0] == '@') { char tmpstr[50]; char *s = argv[i] + 1; if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } /* Always allow slave xterms when using multiple emulations: */ console_allow_slaves(1); /* Destroy the temporary emuls[0], since it will be overwritten: */ if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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 specify\nthe machine type." " For example:\n\n %s -e 3max -d disk.img\n\n" "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); /* Run all emulations: */ emul_run(emuls, n_emuls); /* * Deinitialize everything: */ console_deinit(); for (i=0; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } int main(int argc, char *argv[]) { const int constant_yes = 1; const int constant_true = 1; const int constant_no = 0; const int constant_false = 0; struct emul **emuls; char **diskimages = NULL; int n_diskimages = 0; int n_emuls; int i; progname = argv[0]; console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } n_emuls = 1; emuls[0] = emul_new(NULL); if (emuls[0] == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { struct timeval tv; gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } debug("GXemul"); debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for other Copyright messages.\n\n"); if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { fprintf(stderr, "You can either start one " "emulation with one machine directly from " "the command\nline, or start one or more " "emulations using configuration files." " Not both.\n"); exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { char tmpstr[50]; char *s = argv[i] + 1; if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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 specify\nthe machine type." " For example:\n\n %s -e 3max -d disk.img\n\n" "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; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } 去掉注释 105 行变 92 行

16 int main(int argc, char *argv[]) { const int constant_yes = 1; const int constant_true = 1; const int constant_no = 0; const int constant_false = 0; struct emul **emuls; char **diskimages = NULL; int n_diskimages = 0; int n_emuls; int i; progname = argv[0]; console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } n_emuls = 1; emuls[0] = emul_new(NULL); if (emuls[0] == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { struct timeval tv; gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } debug("GXemul"); debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for other Copyright messages.\n\n"); if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { fprintf(stderr, "You can either start one " "emulation with one machine directly from " "the command\nline, or start one or more " "emulations using configuration files." " Not both.\n"); exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { char tmpstr[50]; char *s = argv[i] + 1; if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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 specify\nthe machine type." " For example:\n\n %s -e 3max -d disk.img\n\n" "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; i<n_emuls; i++) emul_destroy(emuls[i]); 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 *)); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } emuls[0] = emul_new(NULL); if (emuls[0] == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } debug("GXemul"); debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for other Copyright messages.\n\n"); if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { fprintf(stderr, "You can either start one " "emulation with one machine directly from " "the command\nline, or start one or more " "emulations using configuration files." " Not both.\n"); exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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 specify\nthe machine type." " For example:\n\n %s -e 3max -d disk.img\n\n" "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; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } 去掉变量声明 92 行变 76 行

17 int main(int argc, char *argv[]) { console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } emuls[0] = emul_new(NULL); if (emuls[0] == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } debug("GXemul"); debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for other Copyright messages.\n\n"); if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { fprintf(stderr, "You can either start one " "emulation with one machine directly from " "the command\nline, or start one or more " "emulations using configuration files." " Not both.\n"); exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); if (emuls == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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 specify\nthe machine type." " For example:\n\n %s -e 3max -d disk.img\n\n" "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; i<n_emuls; i++) emul_destroy(emuls[i]); 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 *)); emuls[0] = emul_new(NULL); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i<n_diskimages; i++) diskimage_add(emuls[0]->machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } 去掉调试语句 76 行变 53 行

18 int main(int argc, char *argv[]) { console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); emuls[0] = emul_new(NULL); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i<n_diskimages; i++) diskimage_add(emuls[0]->machines[0], diskimages[i]); } if (n_emuls > 0) { for (i=1; i<argc; i++) if (argv[i][0] == '@') { exit(1); } emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_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; i<n_emuls; i++) emul_destroy(emuls[i]); 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 *)); emuls[0] = emul_new(NULL); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i<n_diskimages; i++) diskimage_add(emuls[0]->machines[0], diskimages[i]); } if (n_emuls > 0) { emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_emuls - 1] = emul_create_from_configfile(s); } emul_run(emuls, n_emuls); console_deinit(); for (i=0; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } 去掉异常处理 53 行变 44 行

19 int main(int argc, char *argv[]) { console_init(); cpu_init(); device_init(); machine_init(); timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); emuls[0] = emul_new(NULL); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); if (!skip_srandom_call) { gettimeofday(&tv, NULL); srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; } else { for (i=0; i<n_diskimages; i++) diskimage_add(emuls[0]->machines[0], diskimages[i]); } if (n_emuls > 0) { emul_simple_init(emuls[0]); } for (i=1; i<argc; i++) { if (argv[i][0] == '@') { if (strlen(s) == 0 && i+1 < argc && argv[i+1][0] != '@') { i++; s = argv[i]; } n_emuls ++; emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); console_allow_slaves(1); if (n_emuls == 1) { emul_destroy(emuls[0]); } emuls[n_emuls - 1] = emul_create_from_configfile(s); } emul_run(emuls, n_emuls); console_deinit(); for (i=0; i<n_emuls; i++) emul_destroy(emuls[i]); 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 *)); emuls[0] = emul_new(NULL); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); for (i=0; i<n_diskimages; i++) diskimage_add(emuls[0]->machines[0], diskimages[i]); if (n_emuls > 0) { emul_simple_init(emuls[0]); } emul_run(emuls, n_emuls); console_deinit(); for (i=0; i<n_emuls; i++) emul_destroy(emuls[i]); return 0; } 去掉罕见路径 44 行变 24 行

20 最终处理 去掉参数处理,内存分配 / 释放操作 … 去掉参数处理,内存分配 / 释放操作 … 顾名思义看功能 顾名思义看功能 int main(int argc, char *argv[]) { console_init(); // 控制台初始化 cpu_init(); //CPU 初始化 device_init(); // 设备初始化 machine_init(); // 机器架构初始化 timer_init(); // 时钟初始化 useremul_init(); // 用户模拟器初始化 emuls[0] = emul_new(NULL); // 构建模拟的机器 diskimage_add(emuls[0]->machines[0], diskimages[i]); // 给机器添加磁盘 emul_simple_init(emuls[0]); // 模拟机器初始化 emul_run(emuls, n_emuls); // 运行模拟机器 console_deinit(); // 控制台销毁 emul_destroy(emuls[i]); // 模拟机器销毁 return 0; // 返回 } 是不是很 简单?

21 几点看法 学习 Linux ≠ 仇视 Windows 学习 Linux ≠ 仇视 Windows – 存在的就是合理的, Windows 有其优点 – 仇视微软是一种病态 -- Linus Torvalds –Linux 要吸收 Windows 的优点 学习 Linux ≠ 抛弃 Windows 学习 Linux ≠ 抛弃 Windows – 各取所需,要什么用什么 – 和谐共处,双系统并不丢人 学习 Linux ≠ 抛弃 GUI 学习 Linux ≠ 抛弃 GUI – 爱美之心人皆有之, KDE/Gnome 有功无罪 – 命令行不是拿来炫耀的,而是给人多一种选择 学习 Linux ≠ 人云亦云 学习 Linux ≠ 人云亦云 – 真正的高手大都低调,哗众取宠的大都是半吊子 – 谁用谁知道,没有调查就没有发言权

22 谢谢! 欢迎提问


Download ppt "漫谈 Linux ,龙芯及其软件开发 陈华才2010.03. 目录 Linux 及相关概念 Linux 及相关概念 Linux 开发者初步教程 Linux 开发者初步教程."

Similar presentations


Ads by Google