Ubuntu下编译linux-0.00

本文参考:http://blog.chinaunix.net/uid-24807808-id-3070257.html

linux-0.00下载地址:http://oldlinux.org/Linux.old/bochs/linux-0.00-050613.zip


原来的Makefile改为:

# Makefile for the simple example kernel.
AS86    =as86 -0 -a
LD86    =ld86 -0
AS      =as
LD      =ld -Ttext 0
LDFLAGS =-s -x -M

all:    Image

Image: boot system
        dd bs=32 if=boot of=Image skip=1
        objcopy -O binary system head
        cat head >> Image

disk: Image
        dd bs=8192 if=Image of=/dev/fd0
        sync;sync;sync

head.o: head.s

system: head.o
        $(LD) $(LDFLAGS) head.o  -o system > System.map

boot:   boot.s
        $(AS86) -o boot.o boot.s
        $(LD86) -s -o boot boot.o

clean:
        rm -f Image System.map core boot head *.o system
~                                                            

另外:最近在看赵炯老师的《Linux内核完全剖析》,在搭好bochs环境后,就想用用bochs,所以,按照书上说的,下载了一个测试版本,就做Linux-0.00内核。下面就说一下在bochs中编译Linux-0.00内核遇到的一下问题。

首先,下载Linux-0.00内核源码包,地址: http://oldlinux.org/Linux.old/bochs/linux-0.00-050613.zip

下载好后,进行解压,解压后的文件中有一个名为linux-0.00的压缩包,对其进行解压

进入linux-0.00,make编译。会发现make不成功,只有boot.s编译通过,而head.s编译却没有通过。

我们只需要根据提示的编译错误对源码进行修改

1. 将 movl src_loc,%bx

改为:movl src_loc,%ebx

原因:%ebx寄存器是32位,而%bx寄存器时16位。其实,%ebx是%bx的扩展,e就是extend

因为过去的机子寄存器时16位,从80386以后,寄存器大小都改为32位。


将 movl $65,%al

改为:movb $65,%al

原因:由于字长的改变,现在只能将一个字节放入%ax的第八位%al中。

movl中的l是long,movb中的b是byte.


2. 错误:boot/head.s: Assembler messages:

boot/head.s:231: Error: alignment not a power of 2

make: *** [boot/head.o] Error 1

将head.s中所有的.align 2改为.align 4,.align 3 改为 .align 8

原因:.align 2 是汇编语言指示符,其含义是指存储边界对齐调整

“2”表示把随后的代码或数据的偏移位置调整到地址值最后2比特位为零的位置(2^2),即按4字节对齐内存地址。

不过现在GNU as直接是写出对齐的值而非2的次方值了。


3. 现在可以试着编译,但是发现还会有关于startup的错误

d: warning: cannot find entry symbol _start; defaulting to 0000000008048054

boot.o: In function `start': (.text+0x1): relocation truncated to fit: R_386_16 against `.text'

boot.o: In function `ok_load': (.text+0x3f): relocation truncated to fit: R_386_16 against `.text'

boot.o: In function `ok_load': (.text+0x44): relocation truncated to fit: R_386_16 against `.text'

boot.o: In function `gdt_48': (.text+0x71): relocation truncated to fit: R_386_16 against `.text'

可以将head.s中的 startup: 改为 _startup: 指明程序的入口地址

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...