1 ; 2012.6.30, Jinfeng @ SWUST
2 ; nasm boot.asm -o boot.bin
3
4 org 07c00h ; cs:ip = 07c00h
5 entry:
6 ; set env
7 mov ax,cs
8 mov ds,ax
9 mov es,ax
10 mov ss,ax
11 mov sp,0x400
12
13 load_system:
14 mov dx,0x0000
15 mov cx,0x0002
16
17 mov ax,0x1000
18 mov es,ax
19 xor bx,bx ; [es:bx]
20
21 mov ax,0x0200+2 ; 1024 bytes
22 int 0x13
23 jnc move_system
24 try_again:
25 jmp load_system
26
27 move_system:
28 cli ; don't need BIOS func
29 ; will open just before 'ret' to task 0 in new mode
30 cld
31 mov ax,0x1000
32 mov ds,ax
33 xor ax,ax
34 mov es,ax
35 mov cx,0x0200
36 sub si,si
37 sub di,di
38 rep movsb
39
40 load_gdtr:
41 mov ax,0x0000
42 mov ds,ax
43
44 mov ax,(gdtr-gdt)
45 mov word [gdtr],ax
46 mov dword [gdtr+2],gdt ; not 0x7c00+gdt ?
47
48 lidt [idtr] ; CPU request IDT before jump into new mode
49 lgdt [gdtr]
50
51 mov al,0x02
52 out 0x92,al ; open A20, enable 32-bit address
53
54 mov ax,0x0001
55 mov cr0,eax ; set PE flag in EFLAGS register
56
57 jmp dword 0x08:0 ; jmp to reset all registers in new mode
58
59 ;end!!!
60
61 gdt: dw 0,0,0,0
62 dw 0x1000,0x0000,0x9a00,0x00c0 ; 16Mb,0x0000,r/x
63 dw 0x1000,0x0000,0x9200,0x00c0 ; 10MB,0x0000,r/w
64 dw 0x0002,0x8000,0x920b,0x00c0 ; 8kb,0xb8000, 4kb<-swap->4kb
65
66 gdtr: dw 0x0000,0x0000,0x0000
67 idtr: dw 0x0000,0x0000,0x0000
68
69 times 510-($-$$) db 0
70 dw 0xaa55