如何编译linux 0.01?

如何编译linux 0.01?

当我遇到重新编译 Linux 内核时,我对这个话题有点感兴趣。因此,为了更深入地观察输出,我从 github 下载了 linux 内核 0.01 (https://github.com/liudonghua123/linux-0.01)。当我运行时make(没有额外的参数)。我收到错误:-

$ cd 'linux_kernel(0.01)-source_code'
$ make
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -fno-stack-protector  \
-nostdinc -Iinclude -c -o init/main.o init/main.c
In file included from include/sys/stat.h:5,
                 from include/unistd.h:53,
                 from init/main.c:2:
include/stdint.h:153: warning: "__INT64_C" redefined
  153 | #  define __INT64_C(c) c ## LL
      | 
<built-in>: note: this is the location of the previous definition
In file included from include/sys/stat.h:5,
                 from include/unistd.h:53,
                 from init/main.c:2:
include/stdint.h:154: warning: "__UINT64_C" redefined
  154 | #  define __UINT64_C(c) c ## ULL
      | 
<built-in>: note: this is the location of the previous definition
In file included from init/main.c:3:
include/time.h:39:8: warning: conflicting types for built-in function ‘strftime’; expected ‘long unsigned int(char *, long unsigned int,  const char *, const void *)’ [-Wbuiltin-declaration-mismatch]
   39 | size_t strftime(char * s, size_t smax, const char * fmt, const struct tm * tp);
      |        ^~~~~~~~
include/time.h:1:1: note: ‘strftime’ is declared in header ‘<time.h>’
  +++ |+#include <time.h>
    1 | #ifndef _TIME_H
init/main.c: In function ‘printf’:
init/main.c:114:45: warning: passing argument 3 of ‘vsprintf’ from incompatible pointer type [-Wincompatible-pointer-types]
  114 |  write(1,printbuf,i=vsprintf(printbuf, fmt, args));
      |                                             ^~~~
      |                                             |
      |                                             va_list {aka char *}
init/main.c:38:12: note: expected ‘__va_list_tag *’ but argument is of type ‘va_list’ {aka ‘char *’}
   38 | extern int vsprintf();
      |            ^~~~~~~~
init/main.c: Assembler messages:
init/main.c:93: Error: invalid instruction suffix for `push'
init/main.c:94: Error: invalid instruction suffix for `push'
init/main.c:95: Error: invalid instruction suffix for `pushf'
init/main.c:96: Error: invalid instruction suffix for `push'
init/main.c:97: Error: invalid instruction suffix for `push'
make: *** [Makefile:27: init/main.o] Error 1
$

(我已经从 shell 中复制了确切的单词)

怎么修?

答案1

0.01 内核无法为 64 位 x86 构建;在 x86 上,您应该以 32 位为目标。最重要的是,最近的链接器更改意味着代码无法链接;我们可以通过允许多个定义来解决这个问题。

还有一些剩余的问题,可以通过编辑来修复,以便kernel/console.c导出:columnsattr

static unsigned long lines=LINES;
unsigned long columns=COLUMNS;
static unsigned long state=0;
static unsigned long npar,par[NPAR];
static unsigned long ques=0;
unsigned char attr=0x07;

接着就,随即,

make CC="gcc -m32" AS="as --32" LD="ld -melf_i386 --allow-multiple-definition" clean Image

将成功完成(假设您有适当的 GCC 和 binutils,以及 Bruce Evans'as86ld86),至少使用 GCC 10。我还没有尝试过启动生成的内核;我不确定 ELF 内核是否能正常工作。

答案2

查看此存储库,了解为了能够在 Ubuntu 18.04 64 和 32 位版本上进行编译而进行的更改。它还有一个在 qemu 上运行的 make 命令。 https://github.com/mariuz/linux-0.01

相关内容