cli /*關掉所有中斷*/
mov ax,#0x0000
cld /*DF清零,使串操作為增加*/
do_move: mov es,ax /*移動的目標段地址,即移到第0段*/
add ax,#0x1000
cmp ax,#0x9000 /*移動9段***/
jz end_move /***移動結束***********/
mov ds,ax
sub di,di
sub si,si
mov cx,#0x8000 /***壹次移動的大小為32K字,即64K字節***/
rep movsw
jmp do_move
/**********上面這段代碼是把0001H:0000H開始的核心代碼移動到0000H:0000H處**/
end_move: mov ax,cs
mov ds,ax /**由於前面使用了DS,所以應重新設置回來,不然是錯誤的*/
lidt idt_48 /***加載中斷描述符表,3個字長48位*/
lgdt gdt_48 /***加載全局描述符表,3個字長48位*/
call empty_8042
mov al,#0xD1
out #0x64,al
call empty_8042
mov al,#0xDF
out #0x60,al /*********打開A20地址線***********/
call empty_8042
out #0x20,al
.word 0x00eb,0x00eb | jmp $+2, jmp $+2
2. out #0xA0,al | and to 8259A-2
.word 0x00eb,0x00eb
3. mov al,#0x20 | 向主8259A寫入ICW2.
out #0x21,al | 硬件中斷入口地址0x20, 並由ICW1
| 得知中斷向量長度 = 8 bytes.
.word 0x00eb,0x00eb
4. mov al,#0x28 | start of hardware int's 2 (0x28)
out #0xA1,al | 第二塊8259A的中斷入口是0x28.
.word 0x00eb,0x00eb
5. mov al,#0x04 | 8259-1 is master
out #0x21,al | Interrupt Request 2有級聯處理.
.word 0x00eb,0x00eb
mov al,#0x02 | 8259-2 is slave
out #0xA1,al | 於上面對應,告訴大家我就是IR2對應
| 級聯處理器.
.word 0x00eb,0x00eb
6. mov al,#0x01 | 8086 mode for both
out #0x21,al
.word 0x00eb,0x00eb
out #0xA1,al
.word 0x00eb,0x00eb
mov al,#0xFF | mask off all interrupts for now
out #0x21,al
.word 0x00eb,0x00eb
out #0xA1,al
mov ax,#0x0001 | protected mode (PE) bit
lmsw ax | This is it!
jmpi 0,8 | jmp offset 0 of segment 8 (cs)
/********這個函數保證鍵盤命令列隊是空的************/
empty_8042:
.word 0x00eb,0x00eb
in al,#0x64
test al,#2
jnz empty_8042
ret