����6 ‑1 linux/boot/bootsect.S
1 !
2 ! SYS_SIZE is the number of clicks (16 bytes) to be loaded.
3 ! 0x3000 is 0x30000 bytes = 196kB, more than enough for current
4 ! versions of linux
! SYS_SIZE��Ҫ���ص�ϵͳģ�鳤�ȣ���λ�ǽڣ�ÿ��16�ֽڡ�0x3000��Ϊ0x30000�ֽ�=196KB��
! ����1024�ֽ�Ϊ1KB�ƣ���Ӧ����192KB�����ڵ�ǰ�ں˰汾����ռ䳤�����㹻�ˡ�����ֵΪ
! 0x8000ʱ����ʾ�ں����Ϊ512KB����Ϊ�ڴ�0x90000����ʼ����ƶ����bootsect��setup
! �Ĵ��룬��˸�ֵ��ó���0x9000����ʾ584KB����
! �����̾��'!'��ֺ�';'��ʾ����ע����俪ʼ��
5 !
! ͷ�ļ�linux/config.h�ж������ں��õ���һЩ�������ź�Linus�Լ�ʹ�õ�Ĭ��Ӳ�̲����顣
! �������ж���������һЩ������
! DEF_SYSSIZE = 0x3000 - Ĭ��ϵͳģ�鳤�ȡ���λ�ǽڣ�ÿ��Ϊ16�ֽڣ�
! DEF_INITSEG = 0x9000 - Ĭ�ϱ���������ƶ�Ŀ�Ķ�λ�ã�
! DEF_SETUPSEG = 0x9020 - Ĭ��setup��������λ�ã�
! DEF_SYSSEG = 0x1000 - Ĭ�ϴӴ��̼���ϵͳģ�鵽�ڴ�Ķ�λ�á�
6 #include <linux/config.h>
7 SYSSIZE = DEF_SYSSIZE ! ����һ����Ż���š�ָ���������Ӻ�systemģ��Ĵ�С��
8 !
9 ! bootsect.s (C) 1991 Linus Torvalds
10 ! modified by Drew Eckhardt
11 !
12 ! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves
13 ! iself out of the way to address 0x90000, and jumps there.
14 !
15 ! It then loads 'setup' directly after itself (0x90200), and the system
16 ! at 0x10000, using BIOS interrupts.
17 !
18 ! NOTE! currently system is at most 8*65536 bytes long. This should be no
19 ! problem, even in the future. I want to keep it simple. This 512 kB
20 ! kernel size should be enough, especially as this doesn't contain the
21 ! buffer cache as in minix
22 !
23 ! The loader has been made as simple as possible, and continuos
24 ! read errors will result in a unbreakable loop. Reboot by hand. It
25 ! loads pretty fast by getting whole sectors at a time whenever possible.
!
! ������ǰ�����ֵ����ģ�
! bootsect.s (C) 1991 Linus Torvalds
! Drew Eckhardt��
!
! bootsect.s ��ROM BIOS�����ӳ��������0x7c00 (31KB)���������Լ��Ƶ��˵�ַ0x90000
! (576KB)��������ת�����
!
! ��Ȼ��ʹ��BIOS�жϽ�'setup'ֱ�Ӽ��ص��Լ��ĺ���(0x90200)(576.5KB)������system��
! �ص���ַ0x10000����
!
! ע��! Ŀǰ���ں�ϵͳ�������Ϊ(8*65536)(512KB)�ֽڣ���ʹ���ڽ�����ҲӦ��û����
! ��ġ������������ּ����ˡ�����512KB������ں˳���Ӧ���㹻�ˣ�����������û����
! MINIX��һ���������������ٻ��塣
!
! ���س����Ѿ����ù����ˣ����Գ����ض�����������������ѭ����ֻ���ֹ�������ֻҪ���ܣ�
! ͨ��һ�ζ�ȡ���е����������ع��̿������úܿ졣
26
! αָ�α��������.globl��.global���ڶ������ı�ʶ�����ⲿ�Ļ�ȫ�ֵģ����Ҽ�ʹ��
! ʹ��Ҳǿ�����롣 .text��.data��.bss���ڷֱ��嵱ǰ����Ρ����ݶκ�δ��ʼ�����ݶΡ�
! �����Ӷ��Ŀ��ģ��ʱ�����ӳ���ld86����������ǵ����Ѹ���Ŀ��ģ���е���Ӧ�ηֱ�
! ��ϣ��ϲ�����һ������������ζ�������ͬһ�ص���ַ��Χ�У���˱�����ʵ���ϲ��ֶΡ�
! ���⣬�����ð�ŵ��ַ����DZ�ţ����������'begtext:'��
! һ��������ͨ���ɱ�ţ���ѡ����ָ�����Ƿ���ָ�������Ͳ����������ֶ���ɡ����λ��
! һ��ָ��ĵ�һ���ֶΡ�������������λ�õĵ�ַ��ͨ��ָ��һ����תָ���Ŀ��λ�á�
27 .globl begtext, begdata, begbss, endtext, enddata, endbss
28 .text ! �ı��Σ�����Σ���
29 begtext:
30 .data ! ���ݶΡ�
31 begdata:
32 .bss ! δ��ʼ�����ݶΡ�
33 begbss:
34 .text ! �ı��Σ�����Σ���
35
! ����Ⱥ�'='�����'EQU'���ڶ����ʶ��������������ֵ��
36 SETUPLEN = 4 ! nr of setup-sectors
! setup�������ռ�ô���������(setup-sectors)ֵ��
37 BOOTSEG = 0x07c0 ! original address of boot-sector
! bootsect���������ڴ�ԭʼ�ε�ַ��
38 INITSEG = DEF_INITSEG ! we move boot here - out of the way
! ��bootsect�Ƶ�λ��0x90000 - �ܿ�ϵͳģ��ռ�ô���
39 SETUPSEG = DEF_SETUPSEG ! setup starts here
! setup������ڴ�0x90200����ʼ��
40 SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536).
! systemģ����ص�0x10000��64 KB������
41 ENDSEG = SYSSEG + SYSSIZE ! where to stop loading
! ֹͣ���صĶε�ַ��
42
43 ! ROOT_DEV & SWAP_DEV are now written by "build".
! ���ļ�ϵͳ�豸��ROOT_DEV�ͽ����豸��SWAP_DEV ������toolsĿ¼�µ�build����д�롣
! �豸��0x306ָ�����ļ�ϵͳ�豸�ǵ�2��Ӳ�̵ĵ�1������������Linus���ڵ�2��Ӳ����
! ��װ��Linux 0.11ϵͳ����������ROOT_DEV������Ϊ0x306���ڱ�������ں�ʱ����Ը���
! �Լ����ļ�ϵͳ�����豸λ��������豸�š�����豸����Linuxϵͳ��ʽ��Ӳ���豸����
! ����ʽ��Ӳ���豸�ž���ֵ�ĺ������£�
! �豸��=���豸��*256 + ���豸�ţ�Ҳ��dev_no = (major<<8) + minor ��
! �����豸�ţ�1-�ڴ�,2-����,3-Ӳ��,4-ttyx,5-tty,6-���п�,7-�������ܵ���
! 0x300 - /dev/hd0 - ����������1��Ӳ�̣�
! 0x301 - /dev/hd1 - ��1���̵ĵ�1��������
! ��
! 0x304 - /dev/hd4 - ��1���̵ĵ�4��������
! 0x305 - /dev/hd5 - ����������2��Ӳ�̣�
! 0x306 - /dev/hd6 - ��2���̵ĵ�1��������
! ��
! 0x309 - /dev/hd9 - ��2���̵ĵ�4��������
! ��Linux�ں�0.95�����Ѿ�ʹ���������ں���ͬ�����������ˡ�
44 ROOT_DEV = 0 ! ���ļ�ϵͳ�豸ʹ����ϵͳ����ʱͬ�����豸��
45 SWAP_DEV = 0 ! �����豸ʹ����ϵͳ����ʱͬ�����豸��
46
! αָ��entry��ʹ���ӳ��������ɵ�ִ�г���a.out���а���ָ���ı�ʶ�����š�������
! ����ִ�п�ʼ�㡣49 -- 58�������ǽ�����(bootsect)��Ŀǰ��λ�� 0x07c0(31KB) �ƶ���
! 0x9000(576KB) ������256�֣�512�ֽڣ���Ȼ����ת���ƶ�������go��Ŵ���Ҳ������
! �����һ��䴦��
47 entry start ! ��֪���ӳ������start��ſ�ʼִ�С�
48 start:
49 mov ax,#BOOTSEG ! ��ds�μĴ�����Ϊ0x7C0��
50 mov ds,ax
51 mov ax,#INITSEG ! ��es�μĴ�����Ϊ0x9000��
52 mov es,ax
53 mov cx,#256 ! �����ƶ�����ֵ=256�֣�512�ֽڣ���
54 sub si,si ! Դ��ַ ds:si = 0x07C0:0x0000
55 sub di,di ! Ŀ�ĵ�ַ es:di = 0x9000:0x0000
56 rep ! �ظ�ִ�в��ݼ�cx��ֵ��ֱ��cx = 0Ϊֹ��
57 movw ! ��movsָ����ڴ�[si]���ƶ�cx���ֵ�[di]����
58 jmpi go,INITSEG ! �μ���ת��Jump Intersegment��������INITSEG
! ָ����ת���Ķε�ַ�����go�Ƕ���ƫ�Ƶ�ַ��
59
! �����濪ʼ��CPU�����ƶ���0x90000λ�ô��Ĵ�����ִ�С�
! ��δ������ü����μĴ���������ջ�Ĵ���ss��sp��ջָ��spֻҪָ��Զ����512�ֽ�ƫ��
! ������ַ0x90200���������ԡ���Ϊ��0x90200��ַ��ʼ����Ҫ����setup������ʱsetup
! �����ԼΪ4�����������spҪָ����ڣ�0x200 + 0x200 * 4 +��ջ��С��λ�ô�������sp
! ����Ϊ 0x9ff00 - 12�����������ȣ�����sp = 0xfef4���ڴ�֮��λ�û���һ���Խ�������
! ����������������˵����ʵ����BIOS�������������ص�0x7c00 ������ִ��Ȩ������������ʱ��
! ss = 0x00��sp = 0xfffe��
! ���⣬��65����pushָ�����������������ʱ�Ѷ�ֵ������ջ�У�Ȼ�������ִ�����жϴŵ�
! ���������ٵ���ջ�������μĴ��� fs��gs��ֵ����109�У����������ڵ�67��68�������
! ��ջ�ε�λ�ã���˳�����ִ��ջ��������֮ǰ��ջ�λָ���ԭλ�ã�����������ƾ��Ǵ���ġ�
! ����������һ��bug�������ķ���֮һ��ȥ����65�У����ѵ�109���ijɡ�mov ax,cs����
60 go: mov ax,cs ! ��ds��es��ss���ó��ƶ���������ڵĶδ�(0x9000)��
61 mov dx,#0xfef4 ! arbitrary value >>512 - disk parm size
62
63 mov ds,ax
64 mov es,ax
65 push ax ! ��ʱ�����ֵ��0x9000������109��ʹ�á�����ͷ!��
66
67 mov ss,ax ! put stack at 0x9ff00 - 12.
68 mov sp,dx
69 /*
70 * Many BIOS's default disk parameter tables will not
71 * recognize multi-sector reads beyond the maximum sector number
72 * specified in the default diskette parameter tables - this may
73 * mean 7 sectors in some cases.
74 *
75 * Since single sector reads are slow and out of the question,
76 * we must take care of this by creating new parameter tables
77 * (for the first disk) in RAM. We will set the maximum sector
78 * count to 18 - the most we will encounter on an HD 1.44.
79 *
80 * High doesn't hurt. Low does.
81 *
82 * Segments are as follows: ds=es=ss=cs - INITSEG,
83 * fs = 0, gs = parameter table segment
84 */
/*
* ���ڶ���������������������������Ĭ�ϴ��̲�������ָ�������������ʱ��
* �ܶ�BIOS�����ܽ�����ȷʶ����ijЩ�������7��������
*
* ���ڵ�����������̫���������Կ��ǣ�������DZ���ͨ�����ڴ����ش����µ�
* ��������Ϊ��1���������������������⡣���ǽ��������������������Ϊ
* 18 -- ����1.44MB�����ϻ������������ֵ��
*
* �����ֵ���˲�������⣬����̫С�Ͳ����ˡ�
*
* �μĴ����������óɣ�ds=es=ss=cs - ��ΪINITSEG��0x9000����
* fs = 0��gs = ���������ڶ�ֵ��
*/
85 ! BIOS���õ��ж�0x1E���ж�����ֵ��������������ַ��������ֵλ���ڴ�0x1E * 4 = 0x78
! ������δ������ȴ��ڴ�0x0000:0x0078������ԭ������������0x9000:0xfef4����Ȼ����
! ���е�ÿ�ŵ����������Ϊ18��
86
87 push #0 ! �öμĴ���fs = 0��
88 pop fs ! fs:bxָ�����������������ַ����ָ���ָ�룩��
89 mov bx,#0x78 ! fs:bx is parameter table address
! ����ָ���ʾ��һ�����IJ�������fs�μĴ�����ָ�Ķ��С���ֻӰ������һ����䡣����
! �� fs:bx ��ָ�ڴ�λ�ô��ı���ַ�ŵ��Ĵ����� gs:si ����Ϊԭ��ַ���Ĵ����� es:di =
! 0x9000:0xfef4 ΪĿ�ĵ�ַ��
90 seg fs
91 lgs si,(bx) ! gs:si is source
93 mov di,dx ! es:di is destination ! dx=0xfef4����61�б����á�
94 mov cx,#6 ! copy 12 bytes
95 cld ! �巽���־������ʱָ�������
97 rep ! ����12�ֽڵ�������������0x9000:0xfef4����
98 seg gs
99 movw
100
101 mov di,dx ! es:diָ���±����ı���ƫ��4�������������Ϊ18��
102 movb 4(di),*18 ! patch sector count
103
104 seg fs ! ���ж�����0x1E��ֵָ���±���
105 mov (bx),di
106 seg fs
107 mov 2(bx),es
108
109 pop ax ! ��ʱax���������65�б��������Ķ�ֵ��0x9000����
110 mov fs,ax ! ����fs = gs = 0x9000��
111 mov gs,ax
112
113 xor ah,ah ! reset FDC ! ��λ���̿���������������²�����
114 xor dl,dl ! dl = 0����1��������
115 int 0x13
116
117 ! load the setup-sectors directly after the bootblock.
118 ! Note that 'es' is already set up.
! ��bootsect����������ż���setupģ��Ĵ������ݡ�
! ע��es�Ѿ����ú��ˡ������ƶ�����ʱes�Ѿ�ָ��Ŀ�Ķε�ַ��0x9000����
! 121--137�е���;������ROM BIOS�ж�INT 0x13 ��setup ģ��Ӵ��̵�2��������ʼ����
! 0x90200 ��ʼ�������� 4���������ڶ��������������������������ʾ�����ϳ�������λ�ã�
! Ȼ��λ�����������ԣ�û����·��
! INT 0x13������ʹ�õ��ò����������£�
! ah = 0x02 - �������������ڴ棻al = ��Ҫ����������������
! ch = �ŵ�(����)�ŵĵ�8λ�� cl = ��ʼ����(λ0-5)���ŵ��Ÿ�2λ(λ6-7)��
! dh = ��ͷ�ţ� dl = �������ţ������Ӳ����λ7Ҫ��λ����
! es:bx ��ָ�����ݻ������� ���������CF��־��λ��ah���dz����롣
120 load_setup:
121 xor dx, dx ! drive 0, head 0
122 mov cx,#0x0002 ! sector 2, track 0
123 mov bx,#0x0200 ! address = 512, in INITSEG
124 mov ax,#0x0200+SETUPLEN ! service 2, nr of sectors
125 int 0x13 ! read it
126 jnc ok_load_setup ! ok - continue
127
128 push ax ! dump error code ! ��ʾ������Ϣ����������ջ��
129 call print_nl ! ��Ļ���س���
130 mov bp, sp ! ss:bpָ������ʾ���֣�word����
131 call print_hex ! ��ʾʮ������ֵ��
132 pop ax
133
134 xor dl, dl ! reset FDC ! ��λ���̿����������ԡ�
135 xor ah, ah
136 int 0x13
137 j load_setup ! j ��jmpָ�
138
139 ok_load_setup:
140
141 ! Get disk drive parameters, specifically nr of sectors/track
! ��δ���ȡ�����������IJ�����ʵ������ȡÿ�ŵ�����������������λ��sectors����
! ȡ��������������INT 0x13���ø�ʽ�ͷ�����Ϣ���£�
! ah = 0x08 dl = �������ţ������Ӳ����Ҫ��λ7Ϊ1����
! ������Ϣ��
! ���������CF��λ������ah = ״̬�롣
! ah = 0�� al = 0�� bl = ���������ͣ�AT/PS2��
! ch = ���ŵ��ŵĵ�8λ�� cl = ÿ�ŵ����������(λ0-5)�����ŵ��Ÿ�2λ(λ6-7)
! dh = ����ͷ���� dl = ������������
! es:di -�� �������̲�������
142
143 xor dl,dl
144 mov ah,#0x08 ! AH=8 is get drive parameters
145 int 0x13
146 xor ch,ch
! ����ָ���ʾ��һ�����IJ������� cs�μĴ�����ָ�Ķ��С���ֻӰ������һ����䡣ʵ��
! �ϣ����ڱ������������ݶ������ô���ͬһ�����У����μĴ���cs��ds��es��ֵ��ͬ����
! �˱������д˴����Բ�ʹ�ø�ָ�
147 seg cs
! �¾䱣��ÿ�ŵ�������������������˵��dl=0���������ŵ��Ų��ᳬ��256��ch�Ѿ��㹻��
! ʾ�������cl��λ6-7�϶�Ϊ0����146������ch=0����˴�ʱcx����ÿ�ŵ���������
148 mov sectors,cx
149 mov ax,#INITSEG
150 mov es,ax ! ��Ϊ����ȡ���̲����жϸ���esֵ���������¸Ļء�
151
152 ! Print some inane message
! ��ʾ��Ϣ����'Loading'+�س�+���С�������ʾ�����س��ͻ��п����ַ����ڵ�9���ַ���
! BIOS�ж�0x10���ܺ� ah = 0x03�������λ�á�
! ���룺bh = ҳ��
! ���أ�ch = ɨ�迪ʼ�ߣ�cl = ɨ������ߣ�dh = �к�(0x00����)��dl = �к�(0x00�����)��
!
! BIOS�ж�0x10���ܺ� ah = 0x13����ʾ�ַ�����
! ���룺al = ���ù��ķ�ʽ���涨���ԡ�0x01-��ʾʹ��bl�е�����ֵ�����ͣ���ַ�����β����
! es:bp �˼Ĵ�����ָ��Ҫ��ʾ���ַ�����ʼλ�ô���cx = ��ʾ���ַ����ַ�����bh = ��ʾҳ��ţ�
! bl = �ַ����ԡ�dh = �кţ�dl = �кš�
153
154 mov ah,#0x03 ! read cursor pos
155 xor bh,bh ! ���ȶ����λ�á����ع��λ��ֵ��dx�С�
156 int 0x10 ! dh - ��0--24����dl - ��(0--79)��
157
158 mov cx,#9 ! ����ʾ9���ַ���
159 mov bx,#0x0007 ! page 0, attribute 7 (normal)
160 mov bp,#msg1 ! es:bpָ��Ҫ��ʾ���ַ�����
161 mov ax,#0x1301 ! write string, move cursor
162 int 0x10 ! д�ַ������ƶ���굽����β����
163
164 ! ok, we've written the message, now
165 ! we want to load the system (at 0x10000)
! ���ڿ�ʼ��systemģ����ص�0x10000��64KB����ʼ����
166
167 mov ax,#SYSSEG
168 mov es,ax ! segment of 0x010000 ! es = ���system�Ķε�ַ��
169 call read_it ! ��������systemģ�飬esΪ���������
170 call kill_motor ! �ر���������������Ϳ���֪����������״̬�ˡ�
171 call print_nl ! ���س����С�
172
173 ! After that we check which root-device to use. If the device is
174 ! defined (!= 0), nothing is done and the given device is used.
175 ! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending
176 ! on the number of sectors that the BIOS reports currently.
! �˺����Ǽ��Ҫʹ���ĸ����ļ�ϵͳ�豸����Ƹ��豸��������Ѿ�ָ�����豸(!=0)��
! ��ֱ��ʹ�ø������豸���������Ҫ����BIOS�����ÿ�ŵ���������ȷ������ʹ��/dev/PS0
! (2,28)������ /dev/at0 (2,8)��
!! ����һ���������豸�ļ��ĺ��壺
!! ��Linux�����������豸����2(�μ���43�е�ע��)�����豸�� = type*4 + nr������
!! nrΪ0-3�ֱ��Ӧ����A��B��C��D��type�����������ͣ�2��1.2MB��7��1.44MB�ȣ���
!! ��Ϊ7*4 + 0 = 28������ /dev/PS0 (2,28)ָ����1.44MB A������,���豸����0x021c
!! ͬ�� /dev/at0 (2,8)ָ����1.2MB A�����������豸����0x0208��
! ����root_dev��������������508��509�ֽڴ���ָ���ļ�ϵͳ�����豸�š�0x0306ָ��2
! ��Ӳ�̵�1������������Ĭ��Ϊ0x0306����Ϊ��ʱ Linus ����Linuxϵͳʱ���ڵ�2��Ӳ
! �̵�1�������д�Ÿ��ļ�ϵͳ�����ֵ��Ҫ�������Լ����ļ�ϵͳ����Ӳ�̺ͷ���������
! �ġ����磬�����ĸ��ļ�ϵͳ�ڵ�1��Ӳ�̵ĵ�1�������ϣ���ô��ֵӦ��Ϊ0x0301����
! ��0x01, 0x03����������ļ�ϵͳ���ڵ�2��Bochs�����ϣ���ô��ֵӦ��Ϊ0x021D����
! ��0x1D,0x02�����������ں�ʱ���������Makefile�ļ�������ָ�����Լ���ֵ���ں�ӳ��
! �ļ�Image�Ĵ�������tools/build��ʹ����ָ����ֵ��������ĸ��ļ�ϵͳ�����豸�š�
177
178 seg cs
179 mov ax,root_dev ! ȡ508,509�ֽڴ��ĸ��豸�Ų��ж��Ƿ��ѱ����塣
180 or ax,ax
181 jne root_defined
! ȡ�����148�б����ÿ�ŵ������������sectors=15��˵����1.2MB�������������
! sectors=18����˵����1.44MB��������Ϊ�ǿ������������������Կ϶���A����
182 seg cs
183 mov bx,sectors
184 mov ax,#0x0208 ! /dev/ps0 - 1.2Mb
185 cmp bx,#15 ! �ж�ÿ�ŵ��������Ƿ�=15
186 je root_defined ! ������ڣ���ax�о����������������豸�š�
187 mov ax,#0x021c ! /dev/PS0 - 1.44Mb
188 cmp bx,#18
189 je root_defined
190 undef_root: ! �������һ��������ѭ������������
191 jmp undef_root
192 root_defined:
193 seg cs
194 mov root_dev,ax ! ���������豸�ű��浽root_dev�С�
195
196 ! after that (everyting loaded), we jump to
197 ! the setup-routine loaded directly after
198 ! the bootblock:
! ���ˣ����г�������ϣ����Ǿ���ת����������bootsect�����setup����ȥ��
! ����μ���תָ�Jump Intersegment������ת��0x9020:0000(setup.s����ʼ��)ȥִ�С�
199
200 jmpi 0,SETUPSEG !!!! ���˱�����ͽ����ˡ�!!!!
! �����Ǽ����ӳ���read_it���ڶ�ȡ�����ϵ�systemģ�顣kill_moter���ڹر��������
! ����һЩ��Ļ��ʾ�ӳ���
201
202 ! This routine loads the system at address 0x10000, making sure
203 ! no 64kB boundaries are crossed. We try to load it as fast as
204 ! possible, loading whole tracks whenever we can.
205 !
206 ! in: es - starting address segment (normally 0x1000)
207 !
! ���ӳ���ϵͳģ����ص��ڴ��ַ0x10000������ȷ��û�п�Խ64KB���ڴ�߽硣
! ������ͼ����ؽ��м��أ�ֻҪ���ܣ���ÿ�μ��������ŵ������ݡ�
! ���룺es �C ��ʼ�ڴ��ַ��ֵ��ͨ����0x1000��
!
! ����α������.word����һ��2�ֽ�Ŀ�ꡣ�൱��C���Գ����ж���ı�������ռ�ڴ�ռ��С��
! '1+SETUPLEN'��ʾ��ʼʱ�Ѿ�����1������������setup������ռ��������SETUPLEN��
208 sread: .word 1+SETUPLEN ! sectors read of current track !��ǰ�ŵ����Ѷ���������
209 head: .word 0 ! current head !��ǰ��ͷ�š�
210 track: .word 0 ! current track !��ǰ�ŵ��š�
211
212 read_it:
! ���Ȳ�������Ķ�ֵ�������϶�������ݱ�������λ���ڴ��ַ 64KB �ı߽翪ʼ��������
! ������ѭ������bx�Ĵ��������ڱ�ʾ��ǰ���ڴ�����ݵĿ�ʼλ�á�
! 153���ϵ�ָ��test�Ա���λ������������������������������Ӧ�ı���λ��Ϊ1������
! ֵ�Ķ�Ӧ����λΪ1������Ϊ0���ò������ֻӰ���־�����־ZF�ȣ���������AX=0x1000��
! ��ôtestָ���ִ�н����(0x1000 & 0x0fff) = 0x0000������ZF��־��λ����ʱ����һ��
! ָ��jne ������������
213 mov ax,es
214 test ax,#0x0fff
215 die: jne die ! es must be at 64kB boundary ! esֵ����λ��64KB�߽�!
216 xor bx,bx ! bx is starting address within segment! bxΪ����ƫ�ơ�
217 rp_read:
! �����ж��Ƿ��Ѿ�����ȫ�����ݡ��Ƚϵ�ǰ�������Ƿ����ϵͳ����ĩ�������Ķ�(#ENDSEG)��
! ������Ǿ���ת������ok1_read��Ŵ����������ݡ������˳��ӳ��ء�
218 mov ax,es
219 cmp ax,#ENDSEG ! have we loaded all yet? ! �Ƿ��Ѿ�������ȫ�����ݣ�
220 jb ok1_read
221 ret
222 ok1_read:
! Ȼ��������֤��ǰ�ŵ���Ҫ��ȡ��������������ax�Ĵ����С�
! ���ݵ�ǰ�ŵ���δ��ȡ���������Լ����������ֽڿ�ʼƫ��λ�ã��������ȫ����ȡ��Щδ��
! �������������ֽ����Ƿ�ᳬ��64KB�γ��ȵ����ơ����ᳬ��������ݴ˴�����ܶ�����ֽ�
! �� (64KB �C����ƫ��λ��)��������˴���Ҫ��ȡ����������
223 seg cs
224 mov ax,sectors ! ȡÿ�ŵ���������
225 sub ax,sread ! ��ȥ��ǰ�ŵ��Ѷ���������
226 mov cx,ax ! cx = ax = ��ǰ�ŵ�δ����������
227 shl cx,#9 ! cx = cx * 512 �ֽ� + ���ڵ�ǰƫ��ֵ(bx)��
228 add cx,bx ! = �˴ζ��������ڹ�������ֽ�����
229 jnc ok2_read ! ��û�г���64KB�ֽڣ�����ת��ok2_read��ִ�С�
230 je ok2_read
! �����ϴ˴ν����ŵ�������δ������ʱ�ᳬ��64KB��������ʱ����ܶ�����ֽ�����
! (64KB�C���ڶ�ƫ��λ��)����ת�������ȡ��������������0��ij������ȡ����64KB�IJ�ֵ��
231 xor ax,ax
232 sub ax,bx
233 shr ax,#9
234 ok2_read:
! ����ǰ�ŵ���ָ����ʼ������cl���������������al�������ݵ� es:bx��ʼ����Ȼ��ͳ�Ƶ�ǰ
! �ŵ����Ѿ���ȡ������������ŵ���������� sectors���Ƚϡ����С��sectors˵����ǰ��
! ���ϵĻ�������δ����������ת��ok3_read������������
235 call read_track ! ����ǰ�ŵ���ָ����ʼ��������������������ݡ�
236 mov cx,ax ! cx = �ôβ����Ѷ�ȡ����������
237 add ax,sread ! ���ϵ�ǰ�ŵ����Ѿ���ȡ����������
238 seg cs
239 cmp ax,sectors ! ����ǰ�ŵ��ϵĻ�������δ��������ת��ok3_read����
240 jne ok3_read
! ���ôŵ��ĵ�ǰ��ͷ�����������Ѿ���ȡ������ôŵ�����һ��ͷ�棨1�Ŵ�ͷ���ϵ����ݡ�
! ����Ѿ���ɣ���ȥ����һ�ŵ���
241 mov ax,#1
242 sub ax,head ! �жϵ�ǰ��ͷ�š�
243 jne ok4_read ! �����0��ͷ������ȥ��1��ͷ���ϵ��������ݡ�
244 inc track ! ����ȥ����һ�ŵ���
245 ok4_read:
246 mov head,ax ! ���浱ǰ��ͷ�š�
247 xor ax,ax ! �嵱ǰ�ŵ��Ѷ���������
248 ok3_read:
! �����ǰ�ŵ��ϵĻ���δ�������������ȱ��浱ǰ�ŵ��Ѷ���������Ȼ�����������ݴ��Ŀ�
! ʼλ�á���С��64KB�߽�ֵ������ת��rp_read(217��)�������������ݡ�
249 mov sread,ax ! ���浱ǰ�ŵ��Ѷ���������
250 shl cx,#9 ! �ϴ��Ѷ�������*512�ֽڡ�
251 add bx,cx ! ������ǰ�������ݿ�ʼλ�á�
252 jnc rp_read
! ����˵���Ѿ���ȡ64KB���ݡ���ʱ������ǰ�Σ�Ϊ����һ������������
253 mov ax,es
254 add ah,#0x10 ! ���λ�ַ����Ϊָ����һ��64KB�ڴ濪ʼ����
255 mov es,ax
256 xor bx,bx ! ��������ݿ�ʼƫ��ֵ��
257 jmp rp_read ! ��ת��rp_read(217��)�������������ݡ�
258
! read_track �ӳ�����ǰ�ŵ���ָ����ʼ��������������������ݵ� es:bx ��ʼ�����μ�
! ��67���¶�BIOS���̶��ж�int 0x13��ah=2��˵����
! al �C �����������es:bx �C ��������ʼλ�á�
259 read_track:
! ���ȵ���BIOS�ж�0x10������0x0e���Ե紫��ʽд�ַ��������ǰ��һλ�á���ʾһ��'.'��
260 pusha ! ѹ�����мĴ�����push all����
261 pusha ! Ϊ������ʾ�ж�ѹ�����мĴ���ֵ��
262 mov ax, #0xe2e ! loading... message 2e = .
263 mov bx, #7 ! �ַ�ǰ��ɫ���ԡ�
264 int 0x10
265 popa
! Ȼ����ʽ���дŵ�������������
267 mov dx,track ! ȡ��ǰ�ŵ��š�
268 mov cx,sread ! ȡ��ǰ�ŵ����Ѷ���������
269 inc cx ! cl = ��ʼ��������
270 mov ch,dl ! ch = ��ǰ�ŵ��š�
271 mov dx,head ! ȡ��ǰ��ͷ�š�
272 mov dh,dl ! dh = ��ͷ�ţ�dl = ��������(Ϊ0��ʾ��ǰA������)��
273 and dx,#0x0100 ! ��ͷ�Ų�����1��
274 mov ah,#2 ! ah = 2���������������ܺš�
276 push dx ! save for error dump
277 push cx ! Ϊ�����������һЩ��Ϣ��
278 push bx
279 push ax
281 int 0x13
282 jc bad_rt ! ������������ת��bad_rt��
283 add sp,#8 ! û�г�������˶���Ϊ��������������Ϣ��
284 popa
285 ret
! �����̲���������������ʾ������Ϣ��Ȼ��ִ����������λ�����������жϹ��ܺ�0��������ת
! ��read_track�����ԡ�
287 bad_rt: push ax ! save error code
288 call print_all ! ah = error, al = read
291 xor ah,ah
292 xor dl,dl
293 int 0x13
296 add sp, #10 ! ����Ϊ��������������Ϣ��
297 popa
298 jmp read_track
300 /*
301 * print_all is for debugging purposes.
302 * It will print out all of the registers. The assumption is that this is
303 * called from a routine, with a stack frame like
304 * dx
305 * cx
306 * bx
307 * ax
308 * error
309 * ret <- sp
310 *
311 */
/*
* �ӳ���print_all���ڵ���Ŀ�ġ�������ʾ���мĴ��������ݡ�ǰ����������Ҫ��
* һ���ӳ����е��ã�����ջ֡�ṹΪ������ʾ���������棩
*/
! ����־�Ĵ�����CF=0������ʾ�Ĵ������ơ�
313 print_all:
314 mov cx, #5 ! error code + 4 registers ! ��ʾֵ������
315 mov bp, sp ! ���浱ǰջָ��sp��
317 print_loop:
318 push cx ! save count left ! ������Ҫ��ʾ��ʣ�������
319 call print_nl ! nl for readability ! Ϊ�ɶ������ù��س����С�
320 jae no_reg ! see if register name is needed
321 ! ��FLAGS�ı�־CF=0����ʾ�Ĵ�������������ת��
! ��Ӧ��ջ�Ĵ���˳��ֱ���ʾ���ǵ����ơ�AX�����ȡ�
322 mov ax, #0xe05 + 0x41 - 1 ! ah =���ܺţ�0x0e����al =�ַ���0x05 + 0x41 -1����
323 sub al, cl
324 int 0x10
326 mov al, #0x58 ! X ! ��ʾ�ַ�'X'��
327 int 0x10
329 mov al, #0x3a ! : ! ��ʾ�ַ�':'��
330 int 0x10
! ��ʾ�Ĵ���bp��ָջ�����ݡ���ʼʱbpָ�ص�ַ��
332 no_reg:
333 add bp, #2 ! next register ! ջ����һ��λ�á�
334 call print_hex ! print it ! ��ʮ��������ʾ��
335 pop cx
336 loop print_loop
337 ret
! ����BIOS�ж�0x10���Ե紫��ʽ��ʾ�س����С�
339 print_nl:
340 mov ax, #0xe0d ! CR
341 int 0x10
342 mov al, #0xa ! LF
343 int 0x10
344 ret
346 /*
347 * print_hex is for debugging purposes, and prints the word
348 * pointed to by ss:bp in hexadecmial.
349 */
/*
* �ӳ���print_hex���ڵ���Ŀ�ġ���ʹ��ʮ����������Ļ����ʾ��
* ss:bpָ����֡�
*/
! ����BIOS�ж�0x10���Ե紫��ʽ��4��ʮ����������ʾss:bpָ����֡�
351 print_hex:
352 mov cx, #4 ! 4 hex digits ! Ҫ��ʾ4��ʮ���������֡�
353 mov dx, (bp) ! load word into dx ! ��ʾֵ����dx�С�
354 print_digit:
! ����ʾ���ֽڣ������Ҫ��dx��ֵ����4���أ���ʱ��4������dx�ĵ�4λ�С�
355 rol dx, #4 ! rotate so that lowest 4 bits are used
356 mov ah, #0xe ! �жϹ��ܺš�
357 mov al, dl ! mask off so we have only next nibble
358 and al, #0xf ! ����al�в�ֻȡ��4���أ�1��ֵ����
! ����'0' ��ASCII��ֵ0x30������ʾֵת���ɻ�������'0' ���ַ�������ʱal ֵ���� 0x39��
! ��ʾ����ʾֵ��������9�������Ҫʹ��'A'--'F'����ʾ��
359 add al, #0x30 ! convert to 0 based digit, '0'
360 cmp al, #0x39 ! check for overflow
361 jbe good_digit
362 add al, #0x41 - 0x30 - 0xa ! 'A' - '0' - 0xa
364 good_digit:
365 int 0x10
366 loop print_digit ! cx--����cx>0��ȥ��ʾ��һ��ֵ��
367 ret
370 /*
371 * This procedure turns off the floppy drive motor, so
372 * that we enter the kernel in a known state, and
373 * don't have to worry about it later.
374 */
/* ����ӳ������ڹر�����������������ǽ����ں˺����
* ֪����������״̬���Ժ�Ҳ�����뵣�����ˡ�
*/
! �����377���ϵ�ֵ0x3f2�����̿�������һ���˿ڣ�����Ϊ��������Ĵ�����DOR���˿ڡ�����
! һ��8λ�ļĴ�������λ7--λ4�ֱ����ڿ���4��������D--A���������رա�λ3--λ2����
! ����/��ֹDMA���ж������Լ�����/��λ���̿�����FDC�� λ1--λ0����ѡ��ѡ�������������
! ��378������al�����ò������0ֵ����������ѡ��A���������ر�FDC����ֹDMA���ж�����
! �ر�����й��������ƿ���̵���ϸ��Ϣ��μ�kernel/blk_drv/floppy.c��������˵����
375 kill_motor:
376 push dx
377 mov dx,#0x3f2 ! �������ƿ�����������Ĵ����˿ڣ�ֻд��
378 xor al, al ! A���������ر�FDC����ֹDMA���ж����ر����
379 outb ! ��al�е����������dxָ���Ķ˿�ȥ��
380 pop dx
381 ret
383 sectors:
384 .word 0 ! ��ŵ�ǰ��������ÿ�ŵ�����������
386 msg1: ! ��������BIOS�ж���ʾ����Ϣ����9���ַ���
387 .byte 13,10 ! �س������е�ASCII�롣
388 .ascii "Loading"
! ��ʾ�������ӵ�ַ508(0x1FC)��ʼ������root_dev�����������ĵ�508��ʼ��2���ֽ��С�
390 .org 506
391 swap_dev:
392 .word SWAP_DEV ! �����Ž���ϵͳ�����豸��(init/main.c�л���)��
393 root_dev:
394 .word ROOT_DEV ! �����Ÿ��ļ�ϵͳ�����豸��(init/main.c�л���)��
! �����������̾�����Ч���������ı�־������BIOS�еij��������������ʱʶ��ʹ�á�������
! λ��������������������ֽ��С�
395 boot_flag:
396 .word 0xAA55
398 .text
399 endtext:
400 .data
401 enddata:
402 .bss
403 endbss: