我的学习之旅(5) setup.s

49 篇文章 0 订阅
49 篇文章 0 订阅
;拷贝内核代码 从 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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值