;拷贝内核代码 从 0x1000:0000 到 0x0000:0000
;需要保证内核代码小于64KBytes
mov ax, #0x0000
cld
do_move:
mov es, ax
mov ax, #0x1000
mov ds, ax
sub di, di
sub si, si
mov cx, #0x8000 ;32768,每次2个字节
rep
movsw
;重新恢复 ds 寄存器为0x9020以便后面访问gdt和gdt_48数据
mov ax, cs
mov ds, ax
;准备切换到32bits保护模式
;关中断
cli
;加载idt表
lidt idt_48
;加载gdt表
lgdt gdt_48
;在配置好8259a后开启保护模式以下代码直接使用linux 0.11代码
setup_8295:
mov al,#0x11 ! initialization sequence
out #0x20,al ! send it to 8259A-1
.word 0x00eb,0x00eb ! jmp $+2, jmp $+2
out #0xA0,al ! and to 8259A-2
.word 0x00eb,0x00eb
mov al,#0x20 ! start of hardware int's (0x20)
out #0x21,al
.word 0x00eb,0x00eb
mov al,#0x28 ! start of hardware int's 2 (0x28)
out #0xA1,al
.word 0x00eb,0x00eb
mov al,#0x04 ! 8259-1 is master
out #0x21,al
.word 0x00eb,0x00eb
mov al,#0x02 ! 8259-2 is slave
out #0xA1,al
.word 0x00eb,0x00eb
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!
;跳转到cs:0000地址, 根据gdt表配置,保护模式下的CS寄存器为0x8,DS寄存器为0x10
jmpi 0,8
;打印msg
print_msg:
push ax
mov ah, #0x0e
disp_next_ch:
lodsb
cmp al, #0
jz quit
int 0x10
jmp #disp_next_ch
quit:
pop ax
ret
;打点
print_dot:
push ax
mov ax, #0x0e2e
int 0x10
pop ax
ret
msg:
.byte 13,10
.ascii "Loading kernel ..."
.byte 0
msg_ok:
.ascii "ok"
.byte 0