���� 6‑2 linux/boot/setup.S


  1 !

  2 !       setup.s         (C) 1991 Linus Torvalds

  3 !

  4 ! setup.s is responsible for getting the system data from the BIOS,

  5 ! and putting them into the appropriate places in system memory.

  6 ! both setup.s and system has been loaded by the bootblock.

  7 !

  8 ! This code asks the bios for memory/disk/other parameters, and

  9 ! puts them in a "safe" place: 0x90000-0x901FF, ie where the

 10 ! boot-block used to be. It is then up to the protected mode

 11 ! system to read them from there before the area is overwritten

 12 ! for buffer-blocks.

 13 !

    ! setup.s�����BIOS�л�ȡϵͳ���ݣ�������Щ���ݷŵ�ϵͳ�ڴ���ʵ�

    ! �ط�����ʱsetup.s��system�Ѿ���bootsect��������ص��ڴ��С�

    !

    ! ��δ���ѯ��bios�й��ڴ�/����/����������������Щ�����ŵ�һ��

    ! ����ȫ�ġ��ط���0x90000-0x901FF��Ҳ��ԭ��bootsect�����������

    ! �ĵط���Ȼ���ڱ�����鸲�ǵ�֮ǰ�ɱ���ģʽ��system��ȡ��

 14

 15 ! NOTE! These had better be the same as in bootsect.s!

    ! ������Щ������ú�bootsect.s�е���ͬ��

 16 #include <linux/config.h>

    ! config.h�ж�����DEF_INITSEG = 0x9000��DEF_SYSSEG = 0x1000��DEF_SETUPSEG = 0x9020��

 17

 18 INITSEG  = DEF_INITSEG  ! we move boot here - out of the way ! ԭ��bootsect�����ĶΡ�

 19 SYSSEG   = DEF_SYSSEG   ! system loaded at 0x10000 (65536).  ! system��0x10000����

 20 SETUPSEG = DEF_SETUPSEG ! this is the current segment        ! ���������ڵĶε�ַ��

 21

 22 .globl begtext, begdata, begbss, endtext, enddata, endbss

 23 .text

 24 begtext:

 25 .data

 26 begdata:

 27 .bss

 28 begbss:

 29 .text

 30

 31 entry start

 32 start:

 33

 34 ! ok, the read went well so we get current cursor position and save it for

 35 ! posterity.

    ! ok�����������̹��̶����������ڽ����λ�ñ����Ա����ʹ�ã���ش�����59--62�У���

 36

    ! �¾佫ds�ó�INITSEG(0x9000)�����Ѿ���bootsect���������ù�������������setup����

    ! Linus������Ҫ����������һ�¡�

 37         mov     ax,#INITSEG

 38         mov     ds,ax

 39

 40 ! Get memory size (extended mem, kB)

    ! ȡ��չ�ڴ�Ĵ�Сֵ��KB����

    ! ����BIOS�ж�0x15 ���ܺ�ah = 0x88 ȡϵͳ������չ�ڴ��С���������ڴ�0x90002����

    ! ���أ�ax = ��0x100000��1M������ʼ����չ�ڴ��С(KB)����������CF��λ��ax = �����롣

 41

 42         mov     ah,#0x88

 43         int     0x15

 44         mov     [2],ax             ! ����չ�ڴ���ֵ����0x90002����1���֣���

 45

 46 ! check for EGA/VGA and some config parameters

    ! �����ʾ��ʽ��EGA/VGA����ȡ������

    ! ����BIOS�ж�0x10�����ӹ���ѡ��ʽ��Ϣ�����ܺţ�ah = 0x12��bl = 0x10

    ! ���أ�bh =��ʾ״̬��0x00 -��ɫģʽ��I/O�˿�=0x3dX��0x01 -��ɫģʽ��I/O�˿�=0x3bX��

    ! bl = ��װ����ʾ�ڴ档0x00 - 64k��0x01 - 128k��0x02 - 192k��0x03 = 256k��

    ! cx = ��ʾ�����Բ���(�μ�������BIOS��Ƶ�ж�0x10��˵��)��

 47

 48         mov     ah,#0x12

 49         mov     bl,#0x10

 50         int     0x10

 51         mov     [8],ax           ! 0x90008 = ??

 52         mov     [10],bx          ! 0x9000A =��װ����ʾ�ڴ棻0x9000B=��ʾ״̬(��/��ɫ)

 53         mov     [12],cx          ! 0x9000C =��ʾ�����Բ�����

    ! �����Ļ��ǰ����ֵ������ʾ����VGA��ʱ�������û�ѡ����ʾ����ֵ�������浽0x9000E����

 54         mov     ax,#0x5019       ! ��ax��Ԥ����ĻĬ������ֵ��ah = 80�У�al=25�У���

 55         cmp     bl,#0x10         ! ���жϷ���blֵΪ0x10�����ʾ����VGA��ʾ������ת��

 56         je      novga

 57         call    chsvga           ! �����ʾ�����Һ����ͣ��޸���ʾ����ֵ����215�У���

 58 novga:  mov     [14],ax          ! ������Ļ��ǰ����ֵ��0x9000E��0x9000F����

 

    ! ��δ���ʹ��BIOS�ж�ȡ��Ļ��ǰ���λ�ã��С��У������������ڴ�0x90000����2�ֽڣ���

    ! ����̨��ʼ������ᵽ�˴���ȡ��ֵ��

    ! BIOS�ж�0x10���ܺ� ah = 0x03�������λ�á�

    ! ���룺bh = ҳ��

    ! ���أ�ch = ɨ�迪ʼ�ߣ�cl = ɨ������ߣ�dh = �к�(0x00����)��dl = �к�(0x00�����)��

 59         mov     ah,#0x03         ! read cursor pos

 60         xor     bh,bh

 61         int     0x10             ! save it in known place, con_init fetches

 62         mov     [0],dx           ! it from 0x90000.

 63        

 64 ! Get video-card data:

    ! �����������ȡ��ʾ����ǰ��ʾģʽ��

    ! ����BIOS�ж�0x10�����ܺ� ah = 0x0f

    ! ���أ�ah = �ַ�������al = ��ʾģʽ��bh = ��ǰ��ʾҳ��

    ! 0x90004(1��)��ŵ�ǰҳ��0x90006�����ʾģʽ��0x90007����ַ�������

 65        

 66         mov     ah,#0x0f

 67         int     0x10

 68         mov     [4],bx          ! bh = display page

 69         mov     [6],ax          ! al = video mode, ah = window width

 70

 71 ! Get hd0 data

    ! ȡ��һ��Ӳ�̵���Ϣ������Ӳ�̲���������

    ! ��1��Ӳ�̲��������׵�ַ��Ȼ���ж�����0x41������ֵ������2��Ӳ�̲����������ڵ�1��

    ! ���ĺ��棬�ж�����0x46������ֵҲָ���2��Ӳ�̵IJ�������ַ�����ij�����16���ֽڡ�

    ! �������γ���ֱ���ROM BIOS���й�����Ӳ�̵IJ�������0x90080����ŵ�1��Ӳ�̵ı���

    ! 0x90090����ŵ�2��Ӳ�̵ı���

 72

    ! ��75�������ڴ�ָ��λ�ô���ȡһ����ָ��ֵ������ds��si�Ĵ����С�ds�зŶε�ַ��

    ! si�Ƕ���ƫ�Ƶ�ַ�������ǰ��ڴ��ַ4 * 0x41��= 0x104���������4���ֽڶ�������4��

    ! �ڼ���Ӳ�̲���������λ�õĶκ�ƫ��ֵ��

 73         mov     ax,#0x0000

 74         mov     ds,ax

 75         lds     si,[4*0x41]        ! ȡ�ж�����0x41��ֵ����hd0�������ĵ�ַ��ds:si

 76         mov     ax,#INITSEG

 77         mov     es,ax

 78         mov     di,#0x0080         ! �����Ŀ�ĵ�ַ: 0x9000:0x0080 �� es:di

 79         mov     cx,#0x10           ! ������16�ֽڡ�

 80         rep

 81         movsb

 82

 83 ! Get hd1 data

 84

 85         mov     ax,#0x0000

 86         mov     ds,ax

 87         lds     si,[4*0x46]        ! ȡ�ж�����0x46��ֵ����hd1�������ĵ�ַ��ds:si

 88         mov     ax,#INITSEG

 89         mov     es,ax

 90         mov     di,#0x0090         ! �����Ŀ�ĵ�ַ: 0x9000:0x0090 �� es:di

 91         mov     cx,#0x10

 92         rep

 93         movsb

 94

 95 ! Check that there IS a hd1 :-)

    ! ���ϵͳ�Ƿ��е�2��Ӳ�̡����û����ѵ�2�������㡣

    ! ����BIOS�жϵ���0x13��ȡ�����͹��ܣ����ܺ� ah = 0x15��

    ! ���룺dl = �������ţ�0x8X��Ӳ�̣�0x80ָ��1��Ӳ�̣�0x81��2��Ӳ�̣�

    ! �����ah = �����룻00 - û������̣�CF��λ��01 - ��������û��change-line֧�֣�

    !                    02 - ������(���������ƶ��豸)����change-line֧�֣� 03 - ��Ӳ�̡�

 96

 97         mov     ax,#0x01500

 98         mov     dl,#0x81

 99         int     0x13

100         jc      no_disk1

101         cmp     ah,#3              ! ��Ӳ����(���� = 3 ��)��

102         je      is_disk1

103 no_disk1:

104         mov     ax,#INITSEG        ! ��2��Ӳ�̲����ڣ���Ե�2��Ӳ�̱����㡣

105         mov     es,ax

106         mov     di,#0x0090

107         mov     cx,#0x10

108         mov     ax,#0x00

109         rep

110         stosb

111 is_disk1:

112

113 ! now we want to move to protected mode ...

    ! ��������Ҫ���뱣��ģʽ����...

114

115         cli                     ! no interrupts allowed !     ! �Ӵ˿�ʼ�������жϡ�

116

117 ! first we move the system to it's rightful place

    ! �������ǽ�systemģ���Ƶ���ȷ��λ�á�

    ! bootsect���������� system ģ����뵽�ڴ� 0x10000��64KB����ʼ��λ�á����ڵ�ʱ����

    ! systemģ����󳤶Ȳ��ᳬ��0x80000��512KB��������ĩ�˲��ᳬ���ڴ��ַ0x90000������

    ! bootsect����Լ��ƶ���0x90000��ʼ�ĵط�������setup���ص����ĺ��档������γ����

    ! ��;���ٰ�����systemģ���ƶ��� 0x00000λ�ã����Ѵ� 0x10000��0x8ffff ���ڴ����ݿ�

    ! ��512KB����������ڴ�Ͷ��ƶ���0x10000��64KB����λ�á�

118

119         mov     ax,#0x0000

120         cld                     ! 'direction'=0, movs moves forward

121 do_move:

122         mov     es,ax           ! destination segment ! es:di��Ŀ�ĵ�ַ(��ʼΪ0x0:0x0)

123         add     ax,#0x1000

124         cmp     ax,#0x9000      ! �Ѿ������һ�Σ���0x8000�ο�ʼ��64KB�������ƶ��ꣿ

125         jz      end_move        ! �ǣ�����ת��

126         mov     ds,ax           ! source segment  ! ds:si��Դ��ַ(��ʼΪ0x1000:0x0)

127         sub     di,di

128         sub     si,si

129         mov     cx,#0x8000      ! �ƶ�0x8000�֣�64KB�ֽڣ���

130         rep

131         movsw

132         jmp     do_move

133

134 ! then we load the segment descriptors

    ! �˺����Ǽ��ض���������

    ! �����↑ʼ������32λ����ģʽ�IJ����������ҪIntel 32λ����ģʽ��̷����֪ʶ�ˣ�

    ! �й��ⷽ�����Ϣ������б���ļ򵥽��ܻ�¼�е���ϸ˵�������������Ҫ˵�����ڽ���

    ! ����ģʽ������֮ǰ��������Ҫ�������ú���Ҫʹ�õĶ�����������������Ҫ����ȫ��������

    ! �����ж�����������

    !

    ! ����ָ��lidt���ڼ����ж�����������IDT���Ĵ��������IJ�������idt_48����6�ֽڡ�ǰ2

    ! �ֽڣ��ֽ�0-1���������������ֽڳ���ֵ����4�ֽڣ��ֽ�2-5��������������32λ���Ի�

    ! ��ַ������ʽ�μ�����218--220�к�222--224��˵�����ж����������е�ÿһ��8�ֽڱ���

    ! ָ�������ж�ʱ��Ҫ���õĴ�����Ϣ�����ж�������Щ���ƣ���Ҫ�����������Ϣ��

    !

    ! lgdtָ�����ڼ���ȫ������������GDT���Ĵ��������������ʽ��lidtָ�����ͬ��ȫ������

    ! �����е�ÿ���������8�ֽڣ������˱���ģʽ�����ݶκʹ���Σ��飩����Ϣ�� ���а���

    ! �ε���󳤶����ƣ�16λ�����ε����Ե�ַ��ַ��32λ�����ε���Ȩ�������Ƿ����ڴ桢��д

    ! ����Ȩ�Լ�����һЩ����ģʽ���еı�־���μ�����205--216�С�

135

136 end_move:

137         mov     ax,#SETUPSEG    ! right, forgot this at first. didn't work :-)

138         mov     ds,ax           ! dsָ�򱾳���(setup)�Ρ�

139         lidt    idt_48          ! load idt with 0,0                  ! ����IDT�Ĵ�����

140         lgdt    gdt_48          ! load gdt with whatever appropriate ! ����GDT�Ĵ�����

141

142 ! that was painless, now we enable A20

    ! ���ϵIJ����ܼ򵥣��������ǿ���A20��ַ�ߡ�

    ! Ϊ���ܹ����ʺ�ʹ��1MB���ϵ������ڴ棬������Ҫ���ȿ���A20��ַ�ߡ��μ��������б���

    ! �й�A20�ź��ߵ�˵�����������漰��һЩ�˿ں�����ɲο�kernel/chr_drv/keyboard.S

    ! �����Լ��̽ӿڵ�˵�������ڻ����Ƿ�����������A20��ַ�ߣ����ǻ���Ҫ�ڽ��뱣��ģʽ

    ! ֮���ܷ���1MB�����ڴ�֮���ڲ���һ�¡��������������head.S�����У�32--36�У���

143

144         call    empty_8042              ! ����8042״̬�Ĵ������ȴ����뻺�����ա�

                                            ! ֻ�е����뻺����Ϊ��ʱ�ſ��Զ���ִ��д���

145         mov     al,#0xD1                ! command write ! 0xD1������-��ʾҪд���ݵ�

146         out     #0x64,al                ! 8042��P2�˿ڡ�P2�˿�λ1����A20�ߵ�ѡͨ��

147         call    empty_8042              ! �ȴ����뻺�����գ��������Ƿ񱻽��ܡ�

148         mov     al,#0xDF                ! A20 on        ! ѡͨA20��ַ�ߵIJ�����

149         out     #0x60,al                ! ����Ҫд��0x60�ڡ�

150         call    empty_8042              ! ����ʱ���뻺����Ϊ�գ����ʾA20���Ѿ�ѡͨ��

151

152 ! well, that went ok, I hope. Now we have to reprogram the interrupts :-(

153 ! we put them right after the intel-reserved hardware interrupts, at

154 ! int 0x20-0x2F. There they won't mess up anything. Sadly IBM really

155 ! messed this up with the original PC, and they haven't been able to

156 ! rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f,

157 ! which is used for the internal hardware interrupts as well. We just

158 ! have to reprogram the 8259's, and it isn't fun.

    !

    ! ϣ������һ���������������DZ������¶��жϽ��б�� :-( ���ǽ����Ƿ�������

    ! ����Intel������Ӳ���жϺ��棬��int 0x20--0x2F�����������Dz��������ͻ��

    ! ���ҵ���IBM��ԭPC���и����ˣ��Ժ�Ҳû�о�������������PC��BIOS���ж�

    ! ������0x08--0x0f����Щ�ж�Ҳ�������ڲ�Ӳ���жϡ��������Ǿͱ������¶�8259

    ! �жϿ��������б�̣���һ�㶼û��˼��

    !

    ! PC��ʹ��2��8259AоƬ�����ڶԿɱ�̿�����8259AоƬ�ı�̷�����μ��������Ľ��ܡ�

    ! ��162���϶���������֣�0x00eb����ֱ��ʹ�û������ʾ�����������תָ�����ʱ���á�

    ! 0xeb��ֱ�ӽ���תָ��IJ����룬��1���ֽڵ����λ��ֵ�������ת��Χ��-127��127��CPU

    ! ͨ����������λ��ֵ�ӵ�EIP�Ĵ����о��γ�һ���µ���Ч��ַ����ʱEIPָ����һ����ִ��

    ! ��ָ�ִ��ʱ�����ѵ�CPUʱ����������7��10����0x00eb ��ʾ��תֵ��0��һ��ָ���

    ! �˻���ֱ��ִ����һ��ָ�������ָ����ṩ14--20��CPUʱ�����ڵ��ӳ�ʱ�䡣��as86

    ! ��û�б�ʾ��Ӧָ������Ƿ������Linus��setup.s��һЩ�������о�ֱ��ʹ�û���������

    ! ʾ����ָ����⣬ÿ���ղ���ָ��NOP��ʱ����������3���������Ҫ�ﵽ��ͬ���ӳ�Ч����

    ! ��Ҫ6��7��NOPָ�

159

    ! 8259оƬ��Ƭ�˿���0x20-0x21����Ƭ�˿���0xA0-0xA1�����ֵ0x11��ʾ��ʼ�����ʼ��

    ! ����ICW1�����֣���ʾ���ش�������Ƭ8259���������Ҫ����ICW4�����֡�

160         mov     al,#0x11                ! initialization sequence

161         out     #0x20,al                ! send it to 8259A-1  ! ���͵�8259A��оƬ��

162         .word   0x00eb,0x00eb           ! jmp $+2, jmp $+2    ! '$'��ʾ��ǰָ��ĵ�ַ��

163         out     #0xA0,al                ! and to 8259A-2      ! �ٷ��͵�8259A��оƬ��

164         .word   0x00eb,0x00eb

    ! LinuxϵͳӲ���жϺű����óɴ�0x20��ʼ���μ���3-2��Ӳ���ж������ź����жϺŶ�Ӧ����

165         mov     al,#0x20                ! start of hardware int's (0x20)

166         out     #0x21,al                ! ����оƬICW2�����֣�������ʼ�жϺţ�Ҫ����˿ڡ�

167         .word   0x00eb,0x00eb

168         mov     al,#0x28                ! start of hardware int's 2 (0x28)

169         out     #0xA1,al                ! �ʹ�оƬICW2�����֣���оƬ����ʼ�жϺš�

170         .word   0x00eb,0x00eb

171         mov     al,#0x04                ! 8259-1 is master

172         out     #0x21,al                ! ����оƬICW3�����֣���оƬ��IR2����оƬINT��

                                            ���μ������б����˵����

173         .word   0x00eb,0x00eb

174         mov     al,#0x02                ! 8259-2 is slave

175         out     #0xA1,al                ! �ʹ�оƬICW3�����֣���ʾ��оƬ��INT������о

                                            ! Ƭ��IR2�����ϡ�

176         .word   0x00eb,0x00eb

177         mov     al,#0x01                ! 8086 mode for both

178         out     #0x21,al                ! ����оƬICW4�����֡�8086ģʽ����ͨEOI���ǻ���

                                            ! ��ʽ���跢��ָ������λ����ʼ��������оƬ������

179         .word   0x00eb,0x00eb

180         out     #0xA1,al                ���ʹ�оƬICW4�����֣�����ͬ�ϡ�

181         .word   0x00eb,0x00eb

182         mov     al,#0xFF                ! mask off all interrupts for now

183         out     #0x21,al                ! ������оƬ�����ж�����

184         .word   0x00eb,0x00eb

185         out     #0xA1,al                �����δ�оƬ�����ж�����

186

187 ! well, that certainly wasn't fun :-(. Hopefully it works, and we don't

188 ! need no steenking BIOS anyway (except for the initial loading :-).

189 ! The BIOS-routine wants lots of unnecessary data, and it's less

190 ! "interesting" anyway. This is how REAL programmers do it.

191 !

192 ! Well, now's the time to actually move into protected mode. To make

193 ! things as simple as possible, we do no register set-up or anything,

194 ! we let the gnu-compiled 32-bit programs do that. We just jump to

195 ! absolute address 0x00000, in 32-bit protected mode.

    !

    ! �ߣ�������α�̵�Ȼû��:-(����ϣ�������ܹ�������������Ҳ������Ҫ��ζ��BIOS

    ! �ˣ����˳�ʼ����:-)��BIOS�ӳ���Ҫ��ܶ಻��Ҫ�����ݣ�������һ�㶼ûȤ������

    ! ���������ij���Ա�������¡�

    !

    ! ���ˣ�������������ʼ���뱣��ģʽ��ʱ���ˡ�Ϊ�˰��������þ����򵥣����Dz�����

    ! �Ĵ������ݽ����κ����á�������gnu�����32λ����ȥ������Щ�¡��ڽ���32λ��

    ! ��ģʽʱ���ǽ��Ǽ򵥵���ת�����Ե�ַ0x00000����

196

    ! �������ò�����32λ����ģʽ���С����ȼ��ػ���״̬��(lmsw-Load Machine Status Word)��

    ! Ҳ�ƿ��ƼĴ���CR0�������λ0��1������CPU�л�������ģʽ��������������Ȩ��0�У���

    ! ��ǰ��Ȩ��CPL=0����ʱ�μĴ�����Ȼָ����ʵ��ַģʽ����ͬ�����Ե�ַ������ʵ��ַģʽ��

    ! ���Ե�ַ�������ڴ��ַ��ͬ���������øñ���λ�����һ��ָ�������һ���μ���תָ����

    ! ����ˢ��CPU��ǰָ����С���ΪCPU����ִ��һ��ָ��֮ǰ���Ѵ��ڴ��ȡ��ָ��������

    ! ���롣Ȼ���ڽ��뱣��ģʽ�Ժ���Щ����ʵģʽ��Ԥ��ȡ�õ�ָ����Ϣ�ͱ�ò�����Ч����һ��

    ! �μ���תָ��ͻ�ˢ��CPU�ĵ�ǰָ����У���������Щ��Ч��Ϣ�����⣬��Intel��˾���ֲ�

    ! �Ͻ���80386������CPUӦ��ʹ��ָ����mov cr0,ax���л�������ģʽ��lmswָ������ڼ�����

    ! ǰ��286 CPU��

 

197         mov     ax,#0x0001      ! protected mode (PE) bit        ! ����ģʽ����λ(PE)��

198         lmsw    ax              ! This is it!                    ! ���������ػ���״̬��!

199         jmpi    0,8             ! jmp offset 0 of segment 8 (cs) ! ��ת��cs��ƫ��0����

    ! �����Ѿ���systemģ���ƶ���0x00000��ʼ�ĵط��������Ͼ��е�ƫ�Ƶ�ַ��0������ֵ8�Ѿ�

    ! �DZ���ģʽ�µĶ�ѡ����ˣ�����ѡ�����������������������Լ���Ҫ�����Ȩ������ѡ�����

    ! ��Ϊ16λ��2�ֽڣ���λ0-1��ʾ�������Ȩ��0--3����Linux����ϵͳֻ�õ�������0������

    ! �˼�����3�����û�������λ2����ѡ��ȫ������������0�����Ǿֲ���������(1)��λ3-15����

    ! ���������������ָ��ѡ��ڼ��������������Զ�ѡ���8��0b0000,0000,0000,1000����ʾ����

    ! ��Ȩ��0��ʹ��ȫ����������GDT�е�2���������������ָ������Ļ���ַ��0���μ�571�У���

    ! ����������תָ��ͻ�ȥִ��system�еĴ��롣���⣬

200

201 ! This routine checks that the keyboard command queue is empty

202 ! No timeout is used - if this hangs there is something wrong with

203 ! the machine, and we probably couldn't proceed anyway.

    ! ��������ӳ����������������Ƿ�Ϊ�ա����ﲻʹ�ó�ʱ���� -

    ! ���������������˵��PC�������⣬���Ǿ�û�а취�ٴ�����ȥ�ˡ�

    !

    ! ֻ�е����뻺����Ϊ��ʱ�����̿�����״̬�Ĵ���λ1 = 0���ſ��Զ���ִ��д���

204 empty_8042:

205         .word   0x00eb,0x00eb

206         in      al,#0x64        ! 8042 status port         ! ��AT���̿�����״̬�Ĵ�����

207         test    al,#2           ! is input buffer full?    ! ����λ1�����뻺��������

208         jnz     empty_8042      ! yes - loop

209         ret

210

211 ! Routine trying to recognize type of SVGA-board present (if any)

212 ! and if it recognize one gives the choices of resolution it offers.

213 ! If one is found the resolution chosen is given by al,ah (rows,cols).

    ! ����������ʶ��SVGA��ʾ�������еĻ������ӳ�����ʶ���һ������û�

    ! �ṩѡ��ֱ��ʵĻ��ᣬ���ѷֱ��ʷ���Ĵ���al��ah���С��У��з��ء�

    !

    ! ע������215--566�д���ǣ�浽�ڶ���ʾ���˿���Ϣ����˱Ƚϸ��ӡ���������δ������ں�

    ! ���й�ϵ������˿�������������

    ! ����������ʾ588���ϵ�msg1�ַ�����"��<�س���>�鿴���ڵ�SVGAģʽ�������������"����

    ! Ȼ��ѭ����ȡ���̿�����������������ȴ��û�����������û����»س�����ȥ���ϵͳ����

    ! ��SVGAģʽ������AL��AH�з����������ֵ����������Ĭ��ֵAL=25�С�AH=80�в����ء�

214

215 chsvga: cld

216         push    ds               ! ����dsֵ������231�У���490��492�У�������

217         push    cs               ! ��Ĭ�����ݶ����óɺʹ����ͬһ���Ρ�

218         pop     ds

219         mov     ax,#0xc000

220         mov     es,ax            ! es ָ��0xc000�Ρ��˴���VGA���ϵ�ROM BIOS����

221         lea     si,msg1          ! ds:siָ��msg1�ַ�����

222         call    prtstr           ! ��ʾ��NULL��β��msg1�ַ�����

223 nokey:  in      al,#0x60         ! ��ȡ���̿�������������������Լ��̵�ɨ����������

224         cmp     al,#0x82         ! ����յ���0x82С��ɨ�������ǽ�ͨɨ���룬��Ϊ0x82��

225         jb      nokey            ! ��С�Ͽ�ɨ����ֵ��С��0x82��ʾ��û�а����ɿ���

226         cmp     al,#0xe0         ! ���ɨ�������0xe0����ʾ�յ�������չɨ����ǰ׺��

227         ja      nokey

228         cmp     al,#0x9c         ! ����Ͽ�ɨ������0x9c����ʾ�û�����/�ɿ��˻س�����

229         je      svga             ! ���dz�����תȥ���ϵͳ�Ƿ����SVGAģʽ��

230         mov     ax,#0x5019       ! �����AX�з�������ֵĬ������ΪAL=25�С�AH=80�С�

231         pop     ds

232         ret

    ! �������VGA��ʾ���ϵ�ROM BIOSָ��λ�ô����������ݴ�����֧�ֵ��ر������жϻ�����

    ! ��װ����ʲô���ӵ���ʾ����������֧��10����ʾ������չ���ܡ�ע�⣬��ʱ�����Ѿ��ڵ�

    ! 220�а�esָ��VGA����ROM BIOS���ڵĶ�0xc000���μ���2�£���

    ! �����ж��Dz���ATI��ʾ�������ǰ� ds:siָ��595����ATI��ʾ���������ݴ�������es:siָ

    ! ��VGA BIOS��ָ��λ�ã�ƫ��0x31��������Ϊ������������9���ַ���"761295520"���������

    ! ��ѭ���Ƚ�����������������ͬ���ʾ�����е�VGA����ATI���ӵģ�������ds:siָ�����

    ! ʾ���������õ�����ģʽֵdscati����615�У�����diָ��ATI�������õ����и�����ģʽ��

    ! ����ת�����selmod��438�У�����һ���������á�

233 svga:   lea     si,idati         ! Check ATI 'clues'  ! ����ж� ATI��ʾ�������ݡ�

234         mov     di,#0x31         ! ��������0xc000:0x0031��ʼ��

235         mov     cx,#0x09         ! ��������9���ֽڡ�

236         repe

237         cmpsb

238         jne     noati            ! ����������ͬ���ʾ����ATI��ʾ������ת������⿨��

239         lea     si,dscati        ! ���9���ֽڶ���ͬ����ʾϵͳ����һ��ATI����ʾ����

240         lea     di,moati         ! ����siָ��ATI�����еĿ�ѡ����ֵ��diָ���ѡ����

241         lea     cx,selmod        ! ��ģʽ�б���Ȼ����ת��selmod��438�У�������������

242         jmp     cx

 

    ! �������ж��Dz���Ahead���ӵ���ʾ����������EGA/VGA ͼ�������Ĵ���0x3ceд������ʵ�

    ! �������Ĵ���������0x0f��ͬʱ��0x3cf�˿ڣ���ʱ��Ӧ�������Ĵ�����д�뿪����չ�Ĵ���

    ! ��־ֵ0x20��Ȼ��ͨ��0x3cf�˿ڶ�ȡ�������Ĵ���ֵ���Լ���Ƿ�������ÿ�����չ�Ĵ���

    ! ��־�����������˵����Ahead���ӵ���ʾ����ע��word���ʱal���˿�n��ah���˿�n+1��

243 noati:  mov     ax,#0x200f       ! Check Ahead 'clues'

244         mov     dx,#0x3ce        ! ���ݶ˿�ָ���������Ĵ�����0x0f��0x3ce�˿ڣ���

245         out     dx,ax            ! �����ÿ�����չ�Ĵ�����־��0x20��0x3cf�˿ڣ���

246         inc     dx               ! Ȼ���ٶ�ȡ�üĴ��������ñ�־�Ƿ������ϡ�

247         in      al,dx

248         cmp     al,#0x20         ! �����ȡֵ��0x20�����ʾ��Ahead A��ʾ����

249         je      isahed           ! �����ȡֵ��0x21�����ʾ��Ahead B��ʾ����

250         cmp     al,#0x21         ! ����˵������Ahead��ʾ����������ת����������࿨��

251         jne     noahed

252 isahed: lea     si,dscahead      ! si ָ��Ahead��ʾ����ѡ����ֵ����diָ����չģʽ��

253         lea     di,moahead       ! ������չģʽ���б���Ȼ����ת��selmod��438�У�����

254         lea     cx,selmod        ! ��������

255         jmp     cx

 

    ! ����������Dz���Chips & Tech��������ʾ����ͨ���˿�0x3c3��0x94��0x46e8������VGA����

    ! �Ĵ����Ľ�������ģʽ��־��λ4����Ȼ��Ӷ˿�0x104��ȡ��ʾ��оƬ����ʶֵ������ñ�ʶֵ

    ! ��0xA5����˵����Chips & Tech��������ʾ����

256 noahed: mov     dx,#0x3c3        ! Check Chips & Tech. 'clues'

257         in      al,dx            ! ��0x3c3�˿ڶ�ȡVGA�����Ĵ���ֵ�������Ͻ�������ģʽ

258         or      al,#0x10         ! ��־��λ4������д�ء�

259         out     dx,al

260         mov     dx,#0x104        ! ������ģʽʱ��ȫ�ֱ�ʶ�˿�0x104��ȡ��ʾ��оƬ��ʶֵ��

261         in      al,dx            ! ����ʱ�����bl�Ĵ����С�

262         mov     bl,al

263         mov     dx,#0x3c3        ! Ȼ���0x3c3�˿��еĽ�������ģʽ��־��λ��

264         in      al,dx

265         and     al,#0xef

266         out     dx,al

267         cmp     bl,[idcandt]     ! �ٰ�bl�б�ʶֵ��λ��idcandt������596�У���Chips &

268         jne     nocant           ! Tech�ı�ʶֵ0xA5���Ƚϡ������ͬ����ת�Ƚ���һ���Կ���

269         lea     si,dsccandt      ! ��siָ��������ʾ���Ŀ�ѡ����ֵ����diָ����չģʽ����

270         lea     di,mocandt       ! ����չģʽ���б���Ȼ����ת��selmod��438�У���������

271         lea     cx,selmod        ! ��ʾģʽ�IJ�����

272         jmp     cx

 

    ! ���ڼ���Dz���Cirrus��ʾ����������ʹ��CRT������������0x1f�Ĵ��������������Խ�ֹ��չ

    ! ���ܡ��üĴ�������Ϊӥ�꣨Eagle ID���Ĵ���������ֵ�ߵͰ��ֽڽ���һ�º�д��˿�0x3c4��

    ! ����6�ţ�����/��չ���Ĵ���Ӧ�û��ֹCirrus��ʾ������չ���ܡ����������˵������Cirrus

    ! ��ʾ������Ϊ�Ӷ˿�0x3d4������0x1fӥ��Ĵ����ж�ȡ��������ӥ��ֵ��0x0c�����Ŷ�Ӧ����

    ! ����ʼ��ַ���ֽڼĴ�������������֮���ֵ������ڶ�0x1f������֮ǰ������Ҫ�Ȱ��Դ���ʼ

    ! ���ֽڼĴ������ݱ�������㣬���ڼ���ָ�֮�����⣬��û�н�������Eagle IDֵд��0x3c4

    ! �˿�������6�Ŷ���/��չ�Ĵ��������¿�����չ���ܡ�

273 nocant: mov     dx,#0x3d4        ! Check Cirrus 'clues'

274         mov     al,#0x0c         ! ������CRT���ƼĴ����������Ĵ����˿�0x3d4д��Ҫ����

275         out     dx,al            ! �ļĴ���������0x0c����Ӧ�Դ���ʼ��ַ���ֽڼĴ�������

276         inc     dx               ! Ȼ���0x3d5�˿ڶ����Դ���ʼ��ַ���ֽڲ��ݴ���bl�У�

277         in      al,dx            ! �ٰ��Դ���ʼ��ַ���ֽڼĴ������㡣

278         mov     bl,al

279         xor     al,al

280         out     dx,al

281         dec     dx               ! ������0x3d4�˿��������0x1f��ָ������Ҫ��0x3d5�˿�

282         mov     al,#0x1f         ! ���ʶ�ȡ��Eagle ID���Ĵ������ݡ�

283         out     dx,al

284         inc     dx

285         in      al,dx            ! ��0x3d5�˿ڶ�ȡ��Eagle ID���Ĵ���ֵ�����ݴ���bh�С�

286         mov     bh,al            ! Ȼ��Ѹ�ֵ�ߵ�4���ػ���λ�ô�ŵ�cl�С�������8λ

287         xor     ah,ah            ! �����ch�У���cl�з�����ֵ6��

288         shl     al,#4

289         mov     cx,ax

290         mov     al,bh

291         shr     al,#4

292         add     cx,ax

293         shl     cx,#8

294         add     cx,#6            ! ����cxֵ�����ax�С���ʱah���ǻ�λ��ġ�Eagle

295         mov     ax,cx            ! ID��ֵ��al����������6����Ӧ����/��չ�Ĵ�������ah

296         mov     dx,#0x3c4        ! д��0x3c4�˿������Ķ���/��չ�Ĵ���Ӧ�ûᵼ��Cirrus

297         out     dx,ax            ! ��ʾ����ֹ��չ���ܡ�

298         inc     dx

299         in      al,dx            ! �����չ������ı���ֹ����ô��ʱ�����ֵӦ��Ϊ0��

300         and     al,al            ! �����Ϊ0���ʾ����Cirrus��ʾ������ת���������������

301         jnz     nocirr

302         mov     al,bh            ! ��Cirrus��ʾ���������õ�286�б�����bh�еġ�Eagle

303         out     dx,al            ! ID��ԭֵ�����¿���Cirrus����չ���ܡ���ʱ��ȡ�ķ���

304         in      al,dx            ! ֵӦ��Ϊ1�������ǣ�����Ȼ˵������Cirrus��ʾ����

305         cmp     al,#0x01

306         jne     nocirr

307         call    rst3d4           ! �ָ�CRT����������ʾ��ʼ��ַ���ֽڼĴ������ݡ�

308         lea     si,dsccirrus     ! siָ��Cirrus��ʾ���Ŀ�ѡ����ֵ��diָ����չģʽ����

309         lea     di,mocirrus      ! �Ͷ�Ӧģʽ�š�Ȼ����ת��selmod��ȥѡ����ʾģʽ��

310         lea     cx,selmod

311         jmp     cx

    ! ���ӳ������ñ�����bl�е�ֵ����278�У��ָ�CRT����������ʾ��ʼ��ַ���ֽڼĴ������ݡ�

312 rst3d4: mov     dx,#0x3d4

313         mov     al,bl

314         xor     ah,ah

315         shl     ax,#8

316         add     ax,#0x0c

317         out     dx,ax            ! ע�⣬����word������� al ��0x3d4��ah ��0x3d5��

318         ret    

 

    ! ���ڼ��ϵͳ���Dz���Everex��ʾ���������������ж�int 0x10����0x70��ax =0x7000��

    ! bx=0x0000������Everex����չ��ƵBIOS���ܡ�����Everes������ʾ�������жϵ���Ӧ��

    ! �᷵��ģ��״̬���������·�����Ϣ��

    ! al = 0x70�����ǻ���Trident��Everex��ʾ����

    ! cl = ��ʾ�����ͣ�00-��ɫ��01-CGA��02-EGA��03-���ֶ�Ƶ��04-PS/2��05-IBM 8514��06-SVGA��

    ! ch = ���ԣ�λ7-6��00-256K��01-512K��10-1MB��11-2MB��λ4-����VGA������λ0-6845ģ�⡣

    ! dx = �忨�ͺţ�λ15-4�������ͱ�ʶ�ţ�λ3-0����������ʶ�š�

    !      0x2360-Ultragraphics II��0x6200-Vision VGA��0x6730-EVGA��0x6780-Viewpoint��

    ! di = ��BCD���ʾ����ƵBIOS�汾�š�

319 nocirr: call    rst3d4           ! Check Everex 'clues'

320         mov     ax,#0x7000       ! ����ax = 0x7000, bx=0x0000������int 0x10��

321         xor     bx,bx

322         int     0x10

323         cmp     al,#0x70         ! ����Everes��ʾ����al��Ӧ�÷���ֵ0x70��

324         jne     noevrx

325         shr     dx,#4            ! ���ɰ������ţ�λ3-0����

326         cmp     dx,#0x678        ! �����ͺ���0x678��ʾ��һ��Trident��ʾ��������ת��

327         je      istrid

328         cmp     dx,#0x236        ! �����ͺ���0x236��ʾ��һ��Trident��ʾ��������ת��

329         je      istrid

330         lea     si,dsceverex     ! ��siָ��Everex��ʾ���Ŀ�ѡ����ֵ������diָ����չ

331         lea     di,moeverex      ! ģʽ������ģʽ���б���Ȼ����ת��selmodȥִ��ѡ��

332         lea     cx,selmod        ! ��ʾģʽ�IJ�����

333         jmp     cx

334 istrid: lea     cx,ev2tri        ! ��Trident���͵�Everex��ʾ��������ת��ev2tri������

335         jmp     cx

 

    ! ���ڼ���Dz���Genoa��ʾ������ʽ�Ǽ������ƵBIOS�е��������ִ���0x77��0x00��0x66��

    ! 0x99����ע�⣬��ʱes�Ѿ��ڵ�220�б����ó�ָ��VGA����ROM BIOS���ڵĶ�0xc000��

336 noevrx: lea     si,idgenoa       ! Check Genoa 'clues'

337         xor     ax,ax            ! ��ds:siָ���597���ϵ��������ִ���

338         seg es

339         mov     al,[0x37]        ! ȡVGA����BIOS��0x37����ָ�루��ָ������������

340         mov     di,ax            ! ��˴�ʱes:diָ���������ִ���ʼ����

341         mov     cx,#0x04

342         dec     si

343         dec     di

344 l1:     inc     si               ! Ȼ��ѭ���Ƚ���4���ֽڵ��������ִ���

345         inc     di

346         mov     al,(si)

347         seg es

348         and     al,(di)

349         cmp     al,(si)

350         loope   l1

351         cmp     cx,#0x00         ! ����������ִ���ȫ��ͬ�����ʾ��Genoa��ʾ����

352         jne     nogen            ! ������תȥ����������͵���ʾ����

353         lea     si,dscgenoa      ! ��siָ��Genoa��ʾ���Ŀ�ѡ����ֵ������diָ����չ

354         lea     di,mogenoa       ! ģʽ������ģʽ���б���Ȼ����ת��selmodȥִ��ѡ��

355         lea     cx,selmod        ! ��ʾģʽ�IJ�����

356         jmp     cx

 

    ! ���ڼ���Dz���Paradise��ʾ����ͬ���Dz��ñȽ���ʾ����BIOS������������VGA=�����ķ�ʽ��

357 nogen:  lea     si,idparadise    ! Check Paradise 'clues'

358         mov     di,#0x7d         ! es:diָ��VGA ROM BIOS��0xc000:0x007d�����ô�Ӧ����

359         mov     cx,#0x04         ! 4���ַ���VGA=����

360         repe

361         cmpsb

362         jne     nopara           ! ���в�ͬ���ַ�����ʾ����Paradise��ʾ����������ת��

363         lea     si,dscparadise   ! ������siָ��Paradise��ʾ���Ŀ�ѡ����ֵ������diָ

364         lea     di,moparadise    ! ����չģʽ������ģʽ���б���Ȼ����ת��selmod��ȥѡ

365         lea     cx,selmod        ! ����Ҫʹ�õ���ʾģʽ��

366         jmp     cx

 

    ! ���ڼ���Dz���Trident��TVGA����ʾ����TVGA��ʾ�������ģʽ���ƼĴ���1��0x3c4�˿�����

    ! ��0x0e����λ3--0��64K�ڴ�ҳ�����ֵ������ֶ�ֵ��һ�����ԣ���д��ʱ��������Ҫ���Ȱ�

    ! ֵ��0x02��������������д�룻����ȡ��ֵʱ����Ҫִ���������������ǰ��ֵӦ����д

    ! ����ٶ�ȡ��ֵ��ͬ���������������������������Dz���Trident��ʾ����

367 nopara: mov     dx,#0x3c4        ! Check Trident 'clues'

368         mov     al,#0x0e         ! �����ڶ˿�0x3c4���������0x0e������ģʽ���ƼĴ���1��

369         out     dx,al            ! Ȼ���0x3c5���ݶ˿ڶ���üĴ���ԭֵ�����ݴ���ah�С�

370         inc     dx

371         in      al,dx

372         xchg    ah,al

373         mov     al,#0x00         ! Ȼ��������üĴ���д��0x00���ٶ�ȡ��ֵ��al��

374         out     dx,al            ! д��0x00���൱�ڡ�ԭֵ��0x02���0x02���д��ֵ��

375         in      al,dx            ! �������Trident��ʾ������˺�����ֵӦ����0x02��

376         xchg    al,ah            ! ������al=ԭģʽ���ƼĴ���1��ֵ��ah=����ȡ��ֵ��

    ! �����������Ӣ��ע���ǡ������...���в�û��Ҫ��������������������ҵ�Trident��ʾ��

    ! �����á����������������Ļ�ͻ��ģ��...�����⼸�и�����Ӣ��ע�͵����ִ�����²�����

    ! ���bl��ԭģʽ���ƼĴ���1��λ1����λ״̬�Ļ��ͽ��临λ������ͽ�λ1��λ��

    ! ʵ�����⼸�������Ƕ�ԭģʽ���ƼĴ���1��ִֵ����� 0x02�IJ�����Ȼ���ý��ֵȥ����

    ! ���ָ���ԭ�Ĵ���ֵ��

377         mov     bl,al            ! Strange thing ... in the book this wasn't

378         and     bl,#0x02         ! necessary but it worked on my card which

379         jz      setb2            ! is a trident. Without it the screen goes

380         and     al,#0xfd         ! blurred ...

381         jmp     clrb2            !

382 setb2:  or      al,#0x02         !

383 clrb2:  out     dx,al

384         and     ah,#0x0f         ! ȡ375��������ֵ��ҳ������ֶΣ�λ3--0�������

385         cmp     ah,#0x02         ! ���ֶ�ֵ����0x02�����ʾ��Trident��ʾ����

386         jne     notrid

387 ev2tri: lea     si,dsctrident    ! ��Trident��ʾ����������siָ�����ʾ���Ŀ�ѡ����

388         lea     di,motrident     ! ֵ�б�����diָ���Ӧ��չģʽ������ģʽ���б���Ȼ

389         lea     cx,selmod        ! ����ת��selmodȥִ��ģʽѡ�������

390         jmp     cx

 

    ! ���ڼ���Dz���Tseng��ʾ����ET4000AX��ET4000/W32�ࣩ�������Ƕ�0x3cd�˿ڶ�Ӧ�Ķ�

    ! ѡ��Segment Select���Ĵ���ִ�ж�д�������üĴ�����4λ��λ7--4����Ҫ���ж�������

    ! 64KB�κţ�Bank number������4λ��λ3--0����ָ��Ҫд�Ķκš����ָ����ѡ��Ĵ�����

    ! ��ֵ�� 0x55����ʾ����д��6��64KB�Σ�����ô����Tseng��ʾ����˵���Ѹ�ֵд��Ĵ���

    ! ���ٶ���Ӧ�û���0x55��

391 notrid: mov     dx,#0x3cd        ! Check Tseng 'clues'

392         in      al,dx            ! Could things be this simple ! :-)

393         mov     bl,al            ! �ȴ�0x3cd�˿ڶ�ȡ��ѡ��Ĵ���ԭֵ����������bl�С�

394         mov     al,#0x55         ! Ȼ��������üĴ�����д��0x55���ٶ��벢����ah�С�

395         out     dx,al

396         in      al,dx

397         mov     ah,al

398         mov     al,bl            ! ���Żָ��üĴ�����ԭֵ��

399         out     dx,al

400         cmp     ah,#0x55         ! �����ȡ�ľ�������д���ֵ���������Tseng��ʾ����

401         jne     notsen

402         lea     si,dsctseng      ! ������siָ��Tseng��ʾ���Ŀ�ѡ����ֵ���б�����di

403         lea     di,motseng       ! ָ���Ӧ��չģʽ������ģʽ���б���Ȼ����ת��selmod

404         lea     cx,selmod        ! ȥִ��ģʽѡ�������

405         jmp     cx

 

    ! �������Dz���Video7��ʾ�����˿�0x3c2�ǻ������Ĵ���д�˿ڣ���0x3cc�ǻ������Ĵ�

    ! �����˿ڡ��üĴ�����λ0�ǵ�ɫ/��ɫ��־�����Ϊ0���ʾ�ǵ�ɫ�������Dz�ɫ���ж��Dz���

    ! Video7��ʾ���ķ�ʽ������������ʾ����CRT������չ��ʶ�Ĵ�������������0x1f�����üĴ���

    ! ��ֵʵ���Ͼ����Դ���ʼ��ַ���ֽڼĴ�����������0x0c�������ݺ�0xea�������������ֵ��

    ! �������ֻҪ���Դ���ʼ��ַ���ֽڼĴ�����д��һ���ض�ֵ��Ȼ��ӱ�ʶ�Ĵ����ж�ȡ��ʶֵ

    ! �����жϼ��ɡ�

    ! ͨ����������ʾ��������Video7��ʾ���ļ����������ǿ�֪������ͨ����Ϊ�����������衣

    ! ���ȶ�ȡ�����������Ҫ�õ��ļĴ���ԭֵ��Ȼ��ʹ���ض�����ֵ����д��Ͷ�������������

    ! ��ԭ�Ĵ���ֵ���Լ���������жϡ�

406 notsen: mov     dx,#0x3cc        ! Check Video7 'clues'

407         in      al,dx

408         mov     dx,#0x3b4        ! ������dxΪ��ɫ��ʾCRT���������Ĵ����˿ں�0x3b4��

409         and     al,#0x01         ! ����������Ĵ�����λ0����0����ɫ����ֱ����ת��

410         jz      even7            ! ����dx����Ϊ��ɫ��ʾCRT���������Ĵ����˿ں�0x3d4��

411         mov     dx,#0x3d4

412 even7:  mov     al,#0x0c         ! ���üĴ���������Ϊ0x0c����Ӧ�Դ���ʼ��ַ���ֽڼĴ�����

413         out     dx,al

414         inc     dx

415         in      al,dx            ! ��ȡ��ʾ�ڴ���ʼ��ַ���ֽڼĴ������ݣ���������bl�С�

416         mov     bl,al

417         mov     al,#0x55         ! Ȼ�����Դ���ʼ��ַ���ֽڼĴ�����д��ֵ0x55���ٶ�ȡ������

418         out     dx,al

419         in      al,dx

420         dec     dx               ! Ȼ��ͨ��CRTC�����Ĵ����˿�0x3b4��0x3d4ѡ����������

421         mov     al,#0x1f         ! 0x1f��Video7��ʾ����ʶ�Ĵ������üĴ�������ʵ���Ͼ���

422         out     dx,al            ! �Դ���ʼ��ַ���ֽں�0xea������������Ľ��ֵ��

423         inc     dx

424         in      al,dx            ! ��ȡVideo7��ʾ����ʶ�Ĵ���ֵ����������bh�С�

425         mov     bh,al

426         dec     dx               ! Ȼ����ѡ���Դ���ʼ��ַ���ֽڼĴ������ָ���ԭֵ��

427         mov     al,#0x0c

428         out     dx,al

429         inc     dx

430         mov     al,bl

431         out     dx,al

432         mov     al,#0x55         ! �����������֤��Video7��ʾ����ʶ�Ĵ���ֵ�����Դ���ʼ

433         xor     al,#0xea         ! ��ַ���ֽں�0xea������������Ľ��ֵ�������0x55

434         cmp     al,bh            ! ��0xea�����������Ľ����Ӧ�õ��ڱ�ʶ�Ĵ����IJ���ֵ��

435         jne     novid7           ! ������Video7��ʾ����������Ĭ����ʾ����ֵ��492�У���

436         lea     si,dscvideo7     ! ��Video7��ʾ����������siָ�����ʾ������ֵ������di

437         lea     di,movideo7      ! ָ����չģʽ������ģʽ���б���

 

    ! ����������������жϳ�����ʾ�������Լ�ȡ�õ������չģʽ��Ϣ��siָ�������ֵ�б���di

    ! ָ����չģʽ������ģʽ���б�������ʾ�û�ѡ����õ���ʾģʽ�������ó���Ӧ��ʾģʽ�����

    ! �ӳ��򷵻�ϵͳ��ǰ���õ���Ļ����ֵ��ah = ������al=�����������磬���ϵͳ����ATI��ʾ����

    ! ��ô��Ļ�ϻ���ʾ������Ϣ��

    ! Mode:  COLSxROWS:

    ! 0.     132 x 25

    ! 1.     132 x 44

    ! Choose mode by pressing the corresponding number.

    !

    ! ��γ�����������Ļ����ʾNULL��β���ַ�����Ϣ��Mode:  COLSxROWS:����

438 selmod: push    si

439         lea     si,msg2

440         call    prtstr

441         xor     cx,cx

442         mov     cl,(di)          ! ��ʱcl���Ǽ�������ʾ������չģʽ������

443         pop     si

444         push    si

445         push    cx

    ! Ȼ����ÿһ������ʾ����ǰ��ʾ����ѡ�����չģʽ����ֵ�����û�ѡ�á�

446 tbl:    pop     bx               ! bx = ��ʾ������չģʽ�ܸ�����

447         push    bx

448         mov     al,bl

449         sub     al,cl

450         call    dprnt            ! ��ʮ���Ƹ�ʽ��ʾal�е�ֵ��

451         call    spcing           ! ��ʾһ�����ٿ�4���ո�

452         lodsw                    ! ��ax�м���siָ�������ֵ�����siָ����һ��wordֵ��

453         xchg    al,ah            ! ����λ�ú�al = ������

454         call    dprnt            ! ��ʾ������

455         xchg    ah,al            ! ��ʱal��������ֵ��

456         push    ax

457         mov     al,#0x78         ! ��ʾһ��С��x�������˺š�

458         call    prnt1

459         pop     ax               ! ��ʱal��������ֵ��

460         call    dprnt            ! ��ʾ������

461         call    docr             ! �س����С�

462         loop    tbl              ! ����ʾ��һ������ֵ��cx����չģʽ����ֵ�ݼ�1��

    ! ����չģʽ����ֵ����ʾ֮����ʾ��Choose mode by pressing the corresponding number.����

    ! Ȼ��Ӽ��̿ڶ�ȡ�û�������ɨ���룬���ݸ�ɨ����ȷ���û�ѡ�������ֵģʽ�ţ�������ROM

    ! BIOS����ʾ�ж�int 0x10����0x00��������Ӧ����ʾģʽ��

    ! ��468�е���ģʽ����ֵ+0x80�����������ּ�-1���ɿ�ɨ���롣����0--9���ּ������ǵ��ɿ�

    ! ɨ����ֱ��ǣ�0 - 0x8B��1 - 0x82��2 - 0x83��3 - 0x84��4 - 0x85��

    !               5 - 0x86��6 - 0x87��7 - 0x88��8 - 0x89��9 - 0x8A��

    ! ��ˣ������ȡ�ļ����ɿ�ɨ����С��0x82�ͱ�ʾ�������ּ������ɨ�������0x8B���ʾ�û�

    ! ��������0����

463         pop     cx               ! cl������ʾ����չģʽ�ܸ���ֵ��

464         call    docr

465         lea     si,msg3          ! ��ʾ���밴��Ӧ���ּ���ѡ��ģʽ����

466         call    prtstr

467         pop     si               ! ����ԭ����ֵָ�루ָ����ʾ������ֵ����ʼ������

468         add     cl,#0x80         ! cl + 0x80 = ��Ӧ�����ּ�-1�����ɿ�ɨ���롣

469 nonum:  in      al,#0x60         ! Quick and dirty...

470         cmp     al,#0x82         ! �������ɿ�ɨ����С��0x82���ʾ�������ּ������ɸü���

471         jb      nonum

472         cmp     al,#0x8b         ! �������ɿ�ɨ�������0x8b����ʾ���������ּ�0��

473         je      zero

474         cmp     al,cl            ! ��ɨ���������չģʽ����ֵ��Ӧ�����ɨ����ֵ����ʾ

475         ja      nonum            ! �����ֵ������Χ�������ּ����ɿ�ɨ���롣�����ʾ

476         jmp     nozero           ! �û����²��ɿ���һ����0���ְ�����

    ! ������ɿ�ɨ����ת���ɶ�Ӧ�����ְ���ֵ��Ȼ�����ø�ֵ��ģʽ������ģʽ���б���ѡ���Ӧ��

    ! ��ģʽ�š����ŵ��û���ROM BIOS�ж�int 0x10����0����Ļ���ó�ģʽ��ָ����ģʽ�������

    ! ����ģʽ�Ŵ���ʾ������ֵ����ѡ����ax�з��ض�Ӧ������ֵ��

477 zero:   sub     al,#0x0a         ! al = 0x8b - 0x0a = 0x81��

478 nozero: sub     al,#0x80         ! �ټ�ȥ0x80�Ϳ��Եõ��û�ѡ���˵ڼ���ģʽ��

479         dec     al               ! ��0�������

480         xor     ah,ah            ! int 0x10��ʾ���ܺ�=0��������ʾģʽ����

481         add     di,ax

482         inc     di               ! diָ���Ӧ��ģʽ�ţ�������1��ģʽ�����ֽ�ֵ����

483         push    ax

484         mov     al,(di)          ! ȡģʽ����al�У�������ϵͳBIOS��ʾ�жϹ���0��

485         int     0x10

486         pop     ax

487         shl     ax,#1            ! ģʽ�ų�2��ת����Ϊ����ֵ���ж�Ӧֵ��ָ�롣

488         add     si,ax

489         lodsw                    ! ȡ��Ӧ����ֵ��ax�У�ah = ������al = ��������

490         pop     ds               ! �ָ���216�б����dsԭֵ����ax�з��ص�ǰ��ʾ����ֵ��

491         ret

 

    ! �����������������ʾ������ô����ֻ�ò���Ĭ�ϵ�80 x 25 �ı�׼����ֵ��

492 novid7: pop     ds               ! Here could be code to support standard 80x50,80x30

493         mov     ax,#0x5019     

494         ret

495

496 ! Routine that 'tabs' to next col.

    ! ����ƶ�����һ�Ʊ�λ���ӳ���

497

    ! ��ʾһ�����ַ�'.'��4���ո�

498 spcing: mov     al,#0x2e         ! ��ʾһ�����ַ�'.'��

499         call    prnt1

500         mov     al,#0x20

501         call    prnt1  

502         mov     al,#0x20

503         call    prnt1  

504         mov     al,#0x20

505         call    prnt1  

506         mov     al,#0x20

507         call    prnt1

508         ret    

509

510 ! Routine to print asciiz-string at DS:SI

    ! ��ʾλ��DS:SI����NULL��0x00����β���ַ�����

511

512 prtstr: lodsb

513         and     al,al

514         jz      fin

515         call    prnt1            ! ��ʾal�е�һ���ַ���

516         jmp     prtstr

517 fin:    ret

518

519 ! Routine to print a decimal value on screen, the value to be

520 ! printed is put in al (i.e 0-255).

    ! ��ʾʮ�������ֵ��ӳ�����ʾֵ���ڼĴ���al�У�0--255����

521

522 dprnt:  push    ax

523         push    cx

524         mov     ah,#0x00               

525         mov     cl,#0x0a

526         idiv    cl

527         cmp     al,#0x09

528         jbe     lt100

529         call    dprnt

530         jmp     skip10

531 lt100:  add     al,#0x30

532         call    prnt1

533 skip10: mov     al,ah

534         add     al,#0x30

535         call    prnt1  

536         pop     cx

537         pop     ax

538         ret

539

540 ! Part of above routine, this one just prints ascii al

    ! �����ӳ����һ���֡���ʾal�е�һ���ַ���

    ! ���ӳ���ʹ���ж�0x10��0x0E���ܣ��Ե紫��ʽ����Ļ��дһ���ַ��������Զ��Ƶ���һ��

    ! λ�ô������д��һ�й��ͻ��ƶ�����һ�п�ʼ��������Ѿ�д��һ�����һ�У���������Ļ

    ! �����Ϲ���һ�С��ַ�0x07��BEL����0x08��BS����0x0A(LF)��0x0D��CR������Ϊ�������ʾ��

    ! ���룺AL -- ��д�ַ���BH -- ��ʾҳ�ţ�BL -- ǰ����ʾɫ��ͼ�η�ʽʱ����

541

542 prnt1:  push    ax

543         push    cx

544         mov     bh,#0x00         ! ��ʾҳ�档

545         mov     cx,#0x01

546         mov     ah,#0x0e

547         int     0x10

548         pop     cx

549         pop     ax

550         ret

551

552 ! Prints <CR> + <LF>    ! ��ʾ�س�+���С�

553

554 docr:   push    ax

555         push    cx

556         mov     bh,#0x00

557         mov     ah,#0x0e

558         mov     al,#0x0a

559         mov     cx,#0x01

560         int     0x10

561         mov     al,#0x0d

562         int     0x10

563         pop     cx

564         pop     ax

565         ret    

566        

    ! ȫ������������ʼ�������������ɶ��8�ֽڳ�������������ɡ����������3���������

    ! ��1�����ã�568�У���������ڡ���2����ϵͳ�������������570-573�У�����3����ϵ

    ! ͳ���ݶ�������(575-578��)��

567 gdt:

568         .word   0,0,0,0         ! dummy   ! ��1�������������á�

569

    ! ��GDT���������ƫ������0x08�������ں˴����ѡ�����ֵ��

570         .word   0x07FF          ! 8Mb - limit=2047  (0--2047�������2048*4096=8Mb)

571         .word   0x0000          ! base address=0

572         .word   0x9A00          ! code read/exec         ! �����Ϊֻ������ִ�С�

573         .word   0x00C0          ! granularity=4096, 386  ! ������Ϊ4096��32λģʽ��

574

    ! ��GDT���������ƫ������0x10�������ں����ݶ�ѡ�����ֵ��

575         .word   0x07FF          ! 8Mb - limit=2047 (2048*4096=8Mb)

576         .word   0x0000          ! base address=0

577         .word   0x9200          ! data read/write        ! ���ݶ�Ϊ�ɶ���д��

578         .word   0x00C0          ! granularity=4096, 386  ! ������Ϊ4096��32λģʽ��

579

    ! �����Ǽ����ж����������Ĵ���idtr��ָ��lidtҪ���6�ֽڲ�������ǰ2�ֽ���IDT����

    ! �޳�����4�ֽ���idt�������Ե�ַ�ռ��е�32λ����ַ��CPUҪ���ڽ��뱣��ģʽ֮ǰ����

    ! ��IDT�����������������һ������Ϊ0�Ŀձ���

580 idt_48:

581         .word   0               ! idt limit=0

582         .word   0,0             ! idt base=0L

583

    ! ���Ǽ���ȫ�����������Ĵ���gdtr��ָ��lgdtҪ���6�ֽڲ�������ǰ2�ֽ���gdt������

    ! ������4�ֽ��� gdt�������Ի���ַ������ȫ�ֱ���������Ϊ 2KB��0x7ff���ɣ�����Ϊÿ8

    ! �ֽ����һ��������������Ա��й����� 256�4�ֽڵ����Ի���ַΪ 0x0009<<16 +

    ! 0x0200 + gdt����0x90200 + gdt��(����gdt��ȫ�ֱ��ڱ�������е�ƫ�Ƶ�ַ����205��)

584 gdt_48:

585         .word   0x800           ! gdt limit=2048, 256 GDT entries

586         .word   512+gdt,0x9     ! gdt base = 0X9xxxx

587

588 msg1:   .ascii  "Press <RETURN> to see SVGA-modes available or any other key to continue."

589                 db      0x0d, 0x0a, 0x0a, 0x00

590 msg2:           .ascii  "Mode:  COLSxROWS:"

591                 db      0x0d, 0x0a, 0x0a, 0x00

592 msg3:           .ascii  "Choose mode by pressing the corresponding number."

593                 db      0x0d, 0x0a, 0x00

594                

    ! ������4����ʾ�����������ݴ���

595 idati:          .ascii  "761295520"

596 idcandt:        .byte   0xa5                   ! ���idcandt��˼��ID of Chip AND Tech.

597 idgenoa:        .byte   0x77, 0x00, 0x66, 0x99

598 idparadise:     .ascii  "VGA="

599

    ! �����Ǹ�����ʾ����ʹ�õ���չģʽ�����Ͷ�Ӧ��ģʽ���б�������ÿһ�е�1���ֽ���ģʽ��

    ! ��ֵ������һЩֵ���ж�0x10����0��AH=0����ʹ�õ�ģʽ�š������602�п�֪������ATI

    ! ���ӵ���ʾ�������˱�׼ģʽ���⻹��ʹ��������չģʽ��0x23��0x33��

600 ! Manufacturer:   Numofmodes:   Mode:

    ! ���ң�          ģʽ������    ģʽ�б���

601

602 moati:          .byte   0x02,   0x23, 0x33

603 moahead:        .byte   0x05,   0x22, 0x23, 0x24, 0x2f, 0x34

604 mocandt:        .byte   0x02,   0x60, 0x61

605 mocirrus:       .byte   0x04,   0x1f, 0x20, 0x22, 0x31

606 moeverex:       .byte   0x0a,   0x03, 0x04, 0x07, 0x08, 0x0a, 0x0b, 0x16, 0x18, 0x21, 0x40

607 mogenoa:        .byte   0x0a,   0x58, 0x5a, 0x60, 0x61, 0x62, 0x63, 0x64, 0x72, 0x74, 0x78

608 moparadise:     .byte   0x02,   0x55, 0x54

609 motrident:      .byte   0x07,   0x50, 0x51, 0x52, 0x57, 0x58, 0x59, 0x5a

610 motseng:        .byte   0x05,   0x26, 0x2a, 0x23, 0x24, 0x22

611 movideo7:       .byte   0x06,   0x40, 0x43, 0x44, 0x41, 0x42, 0x45

612

    ! �����Ǹ�������VGA��ʾ����ʹ�õ�ģʽ��Ӧ���С���ֵ�б��������615�б�ʾATI��ʾ����

    ! ����չģʽ���С���ֵ�ֱ��� 132 x 25�� 132 x 44��

613 !                       msb = Cols   lsb = Rows:

    !                       ���ֽ�=����  ���ֽ�=������

614

615 dscati:         .word   0x8419, 0x842c                           ! ATI���������С���ֵ��

616 dscahead:       .word   0x842c, 0x8419, 0x841c, 0xa032, 0x5042   ! Ahead��������ֵ��

617 dsccandt:       .word   0x8419, 0x8432

618 dsccirrus:      .word   0x8419, 0x842c, 0x841e, 0x6425

619 dsceverex:      .word   0x5022, 0x503c, 0x642b, 0x644b, 0x8419, 0x842c, 0x501e, 0x641b, 0xa040, 0x841e

620 dscgenoa:       .word   0x5020, 0x642a, 0x8419, 0x841d, 0x8420, 0x842c, 0x843c, 0x503c, 0x5042, 0x644b

621 dscparadise:    .word   0x8419, 0x842b

622 dsctrident:     .word   0x501e, 0x502b, 0x503c, 0x8419, 0x841e, 0x842b, 0x843c

623 dsctseng:       .word   0x503c, 0x6428, 0x8419, 0x841c, 0x842c

624 dscvideo7:      .word   0x502b, 0x503c, 0x643c, 0x8419, 0x842c, 0x841c

625        

626 .text

627 endtext:

628 .data

629 enddata:

630 .bss

631 endbss: