Title: Linux??????
1Linux??????
- ????????????
- ???(0512-87161312)
- xlanchen_at_ustc.edu.cn
2??????
- ????
- Linux??
- ??????
- ????????
- ??
- ??? vs ???
- ????
- ?????????
- VMware ?QEMU?VirtualBox
- SourceInsight
- ??????GNU Tools?
3??????
- ????
- Linux??
- ??????
- ????????
- ??
- ??? vs ???
- ????
- ?????????
- VMware?QEMU?VirtualBox
- SourceInsight
- ??????GNU Tools?
4???Linux?
- Linux????Unix(Unix-like)?????,?1991???????????
- ?Linux???????,What is Linux?
5From www.kernel.org
- Linux??????
- Linux is a clone of the operating system Unix,
written from scratch by Linus Torvalds with
assistance from a loosely-knit team of hackers
across the Net. It aims towards POSIX and Single
UNIX Specification compliance. - Linux???
- It has all the features you would expect in a
modern fully-fledged Unix, including true
multitasking, virtual memory, shared libraries,
demand loading, shared copy-on-write executables,
proper memory management, and multistack
networking including IPv4 and IPv6.
Portable Operating System Interface
Standard????????????IEEE??,??ISO????????
Institute for Electrical and Electronic
Engineers??????????
International Organization for Standardization???
??????????????????????(????)
6- Linux?????????
- Although originally developed first for 32-bit
x86-based PCs (386 or higher), today Linux also
runs on (at least) the Alpha AXP, Sun SPARC,
Motorola 68000, PowerPC, ARM, Hitachi SuperH, IBM
S/390, MIPS, HP PA-RISC, Intel IA-64, AMD x86-64,
AXIS CRIS, Renesas M32R, Atmel AVR32, Renesas
H8/300, NEC V850, Tensilica Xtensa, and Analog
Devices Blackfin architectures for many of these
architectures in both 32- and 64-bit variants.
7- ????????????
- Linux is easily portable to most general-purpose
32- or 64-bit architectures as long as they have
a paged memory management unit (PMMU) and a port
of the GNU C compiler (gcc) (part of The GNU
Compiler Collection, GCC). Linux has also been
ported to a number of architectures without a
PMMU, although functionality is then obviously
somewhat limited. See the µClinux project for
more info.
8Linux
- ???????,Linux???????,??
- Linux???Linux???Linux????????
- ????,Linux???Linux Torvalds???(?????????????)???
- GNU/Linux
- GNU/Linux???????,Linux????Linux??,???Linux????????
??GNU?????
9 10Linux??????
- http//www.kernel.org/
- The Linux Kernel Archives Mirror System
11Linux????
- 1991?11?,??????????? Linus Torvalds??????,?????Lin
ux,???????????????,????????????????,?????????? - 1993,????????????,???Linux 1.0 ?
- 1994?,Linux ????????? Slackware ??
12 - 1996?,???????????????????? Linux ?? 1.2.13(? Open
Linux ????)?? POSIX ?? - 2001?,Linux2.4?????
- 2003?,Linux2.6?????
13Linux?????????
- Linux??????????????POSIX?????????
- ???????????????,??
- ????????,?????
- ????,
- ??SMP,??TCP/IP,
- ???????32??64?CPU ?
- ???????????????,??
- NFS,VFS,???EXT???????
14Linux??
- Linux?????
- ?????Linux????
15Linux?????
- Linux??????Linus Torvalds????????Linux????(???????
??????)???????????? - Linux??????????
- ??????,??????
- ??????????????,?????????
- Linux??????3?????
r.x.y
?3???y????,?????????
?1???r?????
?2???x????????????,??x???,?????????,???????????
16?????Linux????
17Linux?????
- ????CPU
- X86, ARM, MIPS, SH, i960, PPC, etc.
- ?????(Open source)
- ???????
- ????
- ??GNU tools
18- ????,????,???,??????
- ?????
- ?????????,????????
- ?????????
- ??????????????????
- ????????????????
- ??????????????????????,?????,????,??,??,??,??,????
?????
19- ???????????
- ???????????,????????????????????????
- ????,??????,??????????,????????,???????,??????
??????,??????,?????????,?? -------Linux??? - Linux?????????????
- ???????????
20??????
- ????
- Linux??
- ??????
- ????????
- ??
- ??? vs ???
- ????
- ?????????
- VMware ?QEMU?VirtualBox
- SourceInsight
- ??????GNU Tools?
21?????????
- ???????????????????,???????
- ??(????,????,???????,????,??????,????,I/O??,????)
- ????(?????,shell????)
- ???????
- ?????,?????????
- ?????(????)???????????
22?????Linux???????
??????
Shell,lib
System call
Kernel implementation
????????
23???????????
???????ls??
??????????????????
?????,????????????
Shell????????,????ls??
??????
???shell?
????????,????,??????????
????????
??????fork????shell?????
?????????????,???
???????????
?????,??????COW??
fork???? ??????fork?
??exec?????ls??????????
??????,???????,????,????
?????,?????????
???????
??????????
?????,???????????
Shell?ls?????
24???????????
25??
- ???C????????????????????????
- ??????
- ????
- ??????
- ????????
- ??
- C?????????????????
- ??????????????????????????????????????
- ?x86??????
26??????????
- ????????
- esp,????(stack pointer)
- ebp,????(base pointer)
- ????
- push??????4???(32?)
- pop??????4???
- ebp?C???????????????
???
esp
esp
ebp
???
27?????????????
- ???????
- cs eip????????????
- ??????????????????
- ??/????????????,cs eip????????????
- call???cs eip??????,cs eip????????????
- ret?????????????cs eip??,??cs eip?
- ????????
- ????
28????
- ATT?????Intel????
- ATT??????????????Intel??
- ATT opcodebwl src, dest
- ???reg
- ????bwl - 8, 16, 32 bits
- ??????sectiondisp(base, index, scale)
- ????base indexscale disp
?????1,2,4,8
???0
29//?????????????pushl ebpmovl esp,
ebp //?????????????movl ebp,esppopl ebp
ret
// ??? call target
//???????//do sth.
call?? 1)?????????A????? 2)??eip????????????
???A???eip?
30?????????
- call xxx
- ??call??
- ??call?,cs eip??????call?????,????????,??cs
eip????xxx????? - ??xxx
- ????? pushl ebp
- ????? movl esp, ebp
- ?????????,????????
- ??xxx
- movl ebp,esp
- popl ebp
- ret
esp
ebp
???
esp
ebp
esp
cs eip
esp
ebp
???
31- C??????????
- ?????
- ???????
32?????
- ???test.c
- ????????C??
- main????????p1?p2
- ????gcc g ??test.c??????test
- ????objdump S??test??????
33??p2?????
- ?test?????????p2??????
- int p2(int x,int y)
-
- push ebp
- mov esp,ebp
- return xy
- mov 0xc(ebp),eax
- add 0x8(ebp),eax
-
- pop ebp
- ret
????
???
ebp
esp
ebp
esp
??? ?? ??
x
y
????
ebp
???
34??main??????????p2?
esp
-
- zp2(x,y)
- pushl 0xfffffff8(ebp)
- pushl 0xfffffff4(ebp)
- call 804839b ltp2gt
- add 0x8,esp
- mov eax,0xfffffffc(ebp)
- printf("ddd\n",z,x,y)
- pushl 0xfffffff8(ebp)
- pushl 0xfffffff4(ebp)
- pushl 0xfffffffc(ebp)
- push 0x8048510
- call 80482b0 ltprintf_at_pltgt
-
???? ?? ??
ebp
ebp
???
cseip
esp
x??
esp
y??
esp
??? ?? ??
ebp
???
p2??????????main??
35??main??????
- int main(void)
-
- push ebp
- mov esp,ebp
- sub 0x18,esp
-
- char c'a'
- movb 0x61,0xfffffff3(ebp)
- int x,y,z
- x1
- movl 0x1,0xfffffff4(ebp)
- y2
- movl 0x2,0xfffffff8(ebp)
-
???
esp
ca
x1
y2
ebp
ebp
esp
esp
???
ebp
???
36????????????
eip
p1
p1
eip
p2
p2
esp
p1???
p2??
eip
main p1(c) p2(x,y)
eip
eip
eip
eip
eip
main
c
x,y
esp
eip
main??
eip
eip
eip
eip
??
??????
37?????????????????
???????,main????????p2,??p2????????????p1
38????????????
eip
p1
p1
esp
p1??
eip
p2 p1(c)
eip
eip
p2
eip
eip
c
esp
eip
p2??
eip
eip
main p2(x,y)
x,y
eip
esp
eip
main
main??
eip
eip
??
??????
39???????????
- ??????????????,?????struct pt_regs regs
- ??????????????????????,??????????????????????stru
ct pt_regs regs - ??void do_IRQ(struct pt_regs regs)
- ???????????????do_IRQ,????????????????
- call do_IRQ
40?????pt_regs??
- ??? vs ???
- ??????
- ???????????
- ??????????????
- ??????
- ??????
- ??/int????????????????
- ???????????????????cseip??
41pt_regs??
42SAVE_ALL?RESTORE_ALL
43do_IRQ?????
- ??????????????
- pushl n-256
- SAVE_ALL
- call do_IRQ
- jmp ret_from_intr
44do_IRQ???????
??,do_IRQ????????pt_regs ?????,???????????? ??????
?
regparm(x) x!0??gcc?????????????x?????,???????
EAX,EDX,ECX ?asmlinkage????????????(x0)? ???????
?
45??????????
- Why?
- ?????
- ?????????????
- ???????????????
- ????????
- ?????/?????
46- ??,??????????
- ????????????????
- (??????,?????????????????????,????????????)
- ???????????????
- (????????????????,????????????????????,???????)
47- ???????????
- ????CPU?????????????
- ???????,??????????,?????????,??CPU???????????
- ?????????????,????????????????????????????
- ??intel x86 CPU??????????0-3,Linux???????0??3???
??????????
48- ?????????????????
- cs???????????????????
- CPU???????????cseip????????cs?????????,eip?????
??? - ?????????
- ?????Linux?,????????????0xc0000000???????????????
?,0x00000000-0xbfffffff???????????????? - ???????????????????????
49????
- ??????,???????
- ?????
- ?????
- ?????
- ????
- ??
- ??????????
50- ?????????
- ???????(32?,4GB),??????
- ?Linux?,3G???????,3G???????
- 4G????????????????????????(?????????)
- ????4KB
- ??????
- ??????????,????????????????????
- ????????????????
51- ?????,??????????????,????????
- Linux??????
- ????3G???????????
- ??????????????????????
- ??????/??/??????(?????)
52??CPU???????
wait keyborad queue
idle
??x
??????
eip esp cs ds??
????
CPU
Wakeup progress
????
??????
esp
esp
0xc0000000
eip
idtr
intr
some action
8259
cgets()
esp
main
keyboard
??x
53????????
0xffffffff
0xe0000000
?Linux?,???? ??????3G?? ????, ???????,? ?????????
0x20000000
(512M)
0xc0000000
(3G)
???????
0x00400000
???? ??????
0x00000000
0x00000000
????
????
54??????
- ????
- Linux??
- ??????
- ????????
- ??
- ??? vs ???
- ????
- ?????????
- VMware?QEMU?VirtualBox
- SourceInsight
- ??????GNU Tools?
55VMware
- ??x86????
- ???Windows?Linux??????
- VMWare?????????
- ????????(IDE?SCSI)?DVD/CD-ROM????????????????USB??
- ??????????,?Host OS???????
- ?????ISO?????
- ???VMware???????????????,?????????VMware????
56QEMU
- http//wiki.qemu.org/Main_Page
- QEMU is a generic and open source machine
emulator and virtualizer. - When used as a machine emulator, QEMU can run
OSes and programs made for one machine (e.g. an
ARM board) on a different machine (e.g. your own
PC). By using dynamic translation, it achieves
very good performance. - When used as a virtualizer, QEMU achieves near
native performances by executing the guest code
directly on the host CPU. QEMU supports
virtualization when executing under the Xen
hypervisor or using the KVM kernel module in
Linux. When using KVM, QEMU can virtualize x86,
server and embedded PowerPC, and S390 guests.
57VirtualBox
- http//www.virtualbox.org/
- VirtualBox is a powerful x86 and AMD64/Intel64
virtualization product for enterprise as well as
home use. Not only is VirtualBox an extremely
feature rich, high performance product for
enterprise customers, it is also the only
professional solution that is freely available as
Open Source Software under the terms of the GNU
General Public License (GPL). - Presently, VirtualBox runs on Windows, Linux,
Macintosh and OpenSolaris hosts and supports a
large number of guest operating systems including
but not limited to Windows (NT 4.0, 2000, XP,
Server 2003, Vista, Windows 7), DOS/Windows 3.x,
Linux (2.4 and 2.6), Solaris and OpenSolaris, and
OpenBSD. - ??sudo apt-get install virtualbox
58SourceInsight
- ??????????
- ??????C/C, C?Java???????
- ????????????????,??????????????
- ?http//www.sourceinsight.com/???????????,??????30
???
59??????
????? ???
Project????
??????
???,????
????????
???
??????
??????????
???????????
60Thanks!