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: 指明程序的入口地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值