免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2767 | 回复: 7
打印 上一主题 下一主题

linux kernel 引导过程求解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-03 11:21 |只看该作者 |倒序浏览
/*
*        bootsect.S                Copyright (C) 1991, 1992 Linus Torvalds
*
*        modified by Drew Eckhardt
*        modified by Bruce Evans (bde)
*        modified by Chris Noe (May 1999) (as86 -> gas)
*        gutted by H. Peter Anvin (Jan 2003)
*
* BIG FAT NOTE: We're in real mode using 64k segments.  Therefore segment
* addresses must be multiplied by 16 to obtain their respective linear
* addresses. To avoid confusion, linear addresses are written using leading
* hex while segment addresses are written as segmentffset.
*
*/

#include <asm/boot.h>

SETUPSECTS        = 4                        /* default nr of setup-sectors */
BOOTSEG                = 0x07C0                /* original address of boot-sector */
INITSEG                = DEF_INITSEG                /* we move boot here - out of the way */
SETUPSEG        = DEF_SETUPSEG                /* setup starts here */
SYSSEG                = DEF_SYSSEG                /* system loaded at 0x10000 (65536) */
SYSSIZE                = DEF_SYSSIZE                /* system size: # of 16-byte clicks */
                                        /* to be loaded */
ROOT_DEV        = 0                         /* ROOT_DEV is now written by "build" */
SWAP_DEV        = 0                        /* SWAP_DEV is now written by "build" */

#ifndef SVGA_MODE
#define SVGA_MODE ASK_VGA
#endif

#ifndef RAMDISK
#define RAMDISK 0
#endif

#ifndef ROOT_RDONLY
#define ROOT_RDONLY 1
#endif

.code16
.text

.global _start
_start:

        # Normalize the start address
        jmpl        $BOOTSEG, $start2

start2:
        movw        %cs, %ax
        movw        %ax, %ds
        movw        %ax, %es
        movw        %ax, %ss
        movw        $0x7c00, %sp
        sti
        cld

        movw        $bugger_off_msg, %si

msg_loop:
        lodsb
        andb        %al, %al
        jz        die
        movb        $0xe, %ah
        movw        $7, %bx
        int        $0x10
        jmp        msg_loop

die:
        # Allow the user to press a key, then reboot
        xorw        %ax, %ax
        int        $0x16
        int        $0x19

        # int 0x19 should never return.  In case it does anyway,
        # invoke the BIOS reset code...
        ljmp        $0xf000,$0xfff0


bugger_off_msg:
        .ascii        "Direct booting from floppy is no longer supported.\r\n"
        .ascii        "lease use a boot loader program instead.\r\n"
        .ascii        "\n"
        .ascii        "Remove disk and press any key to reboot . . .\r\n"
        .byte        0


        # Kernel attributes; used by setup

        .org 497
setup_sects:        .byte SETUPSECTS
root_flags:        .word ROOT_RDONLY
syssize:        .word SYSSIZE
swap_dev:        .word SWAP_DEV
ram_size:        .word RAMDISK
vid_mode:        .word SVGA_MODE
root_dev:        .word ROOT_DEV
boot_flag:        .word 0xAA55


这是2.6.15.6 里面的bootsect.s,作用我是知道的,求解各变量和macro的作用,多谢

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
2 [报告]
发表于 2011-12-03 13:19 |只看该作者
/*
*        bootsect.S                Copyright (C) 1991, 1992 Linus Torvalds
*
*        modified by Drew Eckhardt
*        mod ...
ahutwgs 发表于 2011-12-03 11:21



    好像注释上说得很清楚了
楼主需要了解哪个变量

论坛徽章:
0
3 [报告]
发表于 2011-12-03 14:43 |只看该作者
比如说
一、
#ifndef SVGA_MODE
#define SVGA_MODE ASK_VGA
#endif

#ifndef RAMDISK
#define RAMDISK 0
#endif

#ifndef ROOT_RDONLY
#define ROOT_RDONLY 1
#endif

二、
ljmp        $0xf000,$0xfff0
这些地址的内容是什么呢?

thank you

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
4 [报告]
发表于 2011-12-03 15:46 |只看该作者

  1.   4 /* Internal svga startup constants */
  2.   5 #define NORMAL_VGA      0xffff          /* 80x25 mode */
  3.   6 #define EXTENDED_VGA    0xfffe          /* 80x50 mode */
  4.   7 #define ASK_VGA         0xfffd          /* ask for it at bootup */
复制代码
ljmp        $0xf000,$0xfff0

一般不会到这里,在这之前就有int了
int        $0x16
        int        $0x19

        # int 0x19 should never return.  In case it does anyway,
        # invoke the BIOS reset code...

如果到这里了,就相当于0xffff0 (重启)

论坛徽章:
0
5 [报告]
发表于 2011-12-03 16:17 |只看该作者
thank you.....

才学的是intel 的汇编,对AT&T汇编的风格不是很..... ,请问ljmp        $0xf000,$0xfff0  为什么后面有两个 操作数?

论坛徽章:
0
6 [报告]
发表于 2011-12-04 06:59 |只看该作者
我查了下资料,这个菜鸟问题我懂了…… 呵呵……

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
7 [报告]
发表于 2011-12-04 08:47 |只看该作者
这些东西每个arch都不一样,要想弄明白就要看相应的手册,而不是靠猜测

论坛徽章:
0
8 [报告]
发表于 2011-12-05 19:29 |只看该作者
嗯,谢谢楼上的提醒,我昨天看了boot.txt,虽然英文版的看了有点吃力,不过基本上是可以看明白的,呵呵…… 自己才开始自学这方面的东西,觉得挺有意思的,才开始嘛,所以不懂的肯定多点,谢谢前辈们的指教。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP