基于PC的嵌入式软件学习平台

发信人: autoca ( = 郁闷,想家,准备逃学), 信区: Embedded
标  题: 基于PC的嵌入式软件学习平台(1)
发信站: 郁金香BBS站 (2006年09月06日10:41:17 星期三), 站内信件


本文的目的首先是作为打发时间的一种方式,从DIY中找到纯粹的乐趣, 没人
规定截止期限, 没人逼你快点快点, 这个绝对是主要的.其次是为了尝试
用比较直观的方式补补操作系统的底子,这个不好玩. 有板子玩的同学
大可对此不屑一顾,看了不爽可别怪我哈.


    Build Your Own Embedded Software Learning Platform based on PC

I'm afraid that it's not a good choice to learn embedded development based
on PC. It seems that the best way to learn ESP(Embedded System Programming)
is absolutely via real embedded MCU or MPU. However, when it comes to
research on embedded operating system, PC can be an inevitable learning
platform.
Here I'd introduce my current way to learn embedded software. I attempt to do
it totally upon Linux, say, my current OS is Red Hat 9. As my purpose is to
learn embedded software, I'm probably going to try uC/OS_ii later. I'm doing
this just for fun. If you're also interested in OS DIY or if you have any
good advices, don't hesitate a moment to contact with me and let's share
each other's experience.

Here are some useful sources:
[0] http://bochs.sourceforge.net
[1] Daniel W. Lewis. FUNDERMENTALS OF EMBEDDED SOFTWARE - Where C and
Assembly Meet
[2] Yu Yuan. Zi Ji Dong Shou Xie Cao Zuo Xi Tong(于渊.自己动手写操作系统)
[3] Write your own operating system. http://my.execpc.com/~geezer/osd/
[*] google: say, "write os"

Strongly recommend Yu Yuan's book[2] to beginners learning Operating
System!
His platform is like this:
|-Windows
       |-VirtualPC(or Vmware)
             |-DOS
             |-Linux
                 |-bochs
But unfortunately, if you are also using an old and dirty PC which is
just like a snail when running VirtualPC or Vmware, it's obviously not
a good choice.
Moreover, maybe you also prefer Linux as I do, then this article is for
us.

Anyway, here's some infomation about the book:
http://www.china-pub.com/computers/common/info.asp?id=26116

It won't take you much time to set up the experiment environment. Perhaps
less than one hour as I know. If there's any problem, do send me
a message, or just mail me(linuxeer@gmail.com).


================================
STEP1:  Download & install bochs
================================
Bochs is a highly portable open source IA-32 (x86) PC emulator written in
C++,that runs on most popular platforms. It includes emulation of the Intel
x86 CPU, common I/O devices, and a custom BIOS.
.
(1) Download bochs-2.1.1.i386.rpm and install it.
    $su root
    #rpm -ivh bochs-2.1.1.i386.rpm
.
(2) See where it is installed:
    $ls /usr/share/bochs/
    $ls /usr/bin/bochs
.
(3) Run the demo:
    $bochs-dlx
    Funny, isn't it? ^_^
.
(4) You may find bochs info. and download it here:
    http://bochs.sourceforge.net/


================================
STEP2: Make your working path
================================
e.g.
    $mkdir ~/expOS
    $mkdir ~/expOS/exp01
    $ls /usr/share/bochs/
    Put these files in exp01/: bochsrc.txt, makefile.exp, mkall.sh,
    and your source files as well:  *.asm,*.inc, *.c, *.h
    $touch boot.asm, example.inc, example.c, example.h
    OK, now you can begin coding.
    After editing your src files, do this:
    $make -f makefile.exp

================================
STEP3: Coding & Compiling
================================
First, we need a bootloader.asm(or boot.asm + loader.asm).
Many examples of bootloader can be found by google.
e.g. $nasm -o boot.bin boot.asm

Further codeing is to be continued ...

================================
STEP4: How to run your program?
================================
*You need at least these files:
bochsrc.txt -   the bochs script
tinix.img   -   a floppy image file.
boot.bin    -   generated from boot.asm

Note: tinix is an OS name, see [2], a very good book on OS writen by Yu Yuan.

*And perhaps more files later as follows:
loader.bin
kernel.bin
yourapp.bin

(1) tinix.img  -    How to make a floppy image file(tinix.img)?
                    #dd if=/dev/zero of=tinix.img bs=512 count=2880
                    $ls tinix.img -l (1.44M)
(2) boot.bin   -    Write Boot Sector to floppy or its .img as follows:
                    $dd if=boot.bin of=tinix.img

After (1),(2) you may run bochs, $./bochs, to have a look at booting process.

(3) loader.bin -    Put LOADER in floppy or its image:
                    #mount -t msdos tinix.img /mnt/floppy -o loop
                    (Note: here tinix.img is a dos fat12 image)
                    #cp loader.bin /mnt/floppy
                    #ls /mnt/floppy
                    #umount /mnt/floppy (Don't forget this step!)
                    $./bochs (Do this under the src file directory including
                     bochsrc.txt, say, ~/expOS/exp01/)

(4) kernel.bin -    Similar to (3).
(5) yourapp.bin-    Similar to (3).


================================
APPENDIX_I: bochsrc.txt
================================

###############################################################
# bochsrc.txt file for Tinix.
###############################################################

# how much memory the emulated machine will have
megs: 32

# filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000
vgaromimage: $BXSHARE/VGABIOS-elpin-2.40

# what disk images will be used
floppya: 1_44=tinix.img, status=inserted

# choose the boot disk.
boot: a

# where do we send log messages?
log: bochsout.txt

# disable the mouse, since Tinix is text only
mouse: enabled=0

# enable key mapping, using US layout as default.
keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map

================================
APPENDIX_II: boot.asm [2]
================================
; $nasm boot.asm -o boot.bin
; $dd if=boot.bin of=tinix.img
; $./bochs
; See "Hello,OS world!" ?
;
    org 07c00h

    mov ax, cs
    mov ds, ax
    mov es, ax
    mov gs, ax

    call    DispStr
    jmp $

DispStr:                            ; void DispStr();
    mov ax, BootMsg
    mov bp, ax
    mov cx, StrLen
    mov ax, 01301h
    mov bx, 000ch           ; display color
    mov dl, 0
    int 10h
    ret

BootMsg:        db  "Hello,OS world!", 0
StrLen          equ 18

times   510-($-$$)  db  0
dw  0xaa55

==============
LITERATURE:
==============
[0] http://bochs.sourceforge.net
[1] Daniel W. Lewis. FUNDERMENTALS OF EMBEDDED SOFTWARE - Where C and
Assembly Meet
[2] Yu Yuan. Zi Ji Dong Shou Xie Cao Zuo Xi Tong
http://www.china-pub.com/computers/common/info.asp?id=26116

[3] Write your own operating system. http://my.execpc.com/~geezer/osd/

[*] google: write os

--
优秀的程序是自己写D,一流的程序是借鉴别人D,天才的程序是剽窃D,哈哈
※ 修改:·autoca 於 09月06日10:54:22 修改本文·[FROM: 郁金香BBS站]
※ 来源:·郁金香BBS站 bbs.stu.edu.cn·[FROM: 郁金香BBS站]
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值