str_hello db 'hello!',13,10,0
align 4
-gdtlim dw 23
+gdtlim dw 31
gdtbase dq gdt
align 8
; 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
dd 0x0000ffff
dd 0x00cf9200
-
+ ; 3: code16
+ dd 0x0000ffff
+ dd 0x00009a00
bits 32
start32:
and eax, 0fffffeffh
wrmsr
- mov edi, 0a0000h
- mov ecx, 16000
- mov eax, 00ff0000h
- rep stosd
-
- mov esi, str_hello
- call ser_putstr
+ ; load 16bit code segment and jump to 16bit code
+ jmp 0x18:start16
.hang: hlt
jmp .hang
align 4
+ ; real mode IDTR pseudo-descriptor pointing to the IVT at addr 0
+ dw 0
+rmidt: dw 3ffh
+ dd 0
+
+ bits 16
+start16:
+ ; disable protection
+ mov eax, cr0
+ and eax, 0fffffffeh
+ mov cr0, eax
+ ; load cs <- 0
+ jmp 0:.loadcs0
+.loadcs0:
+ ; zero data segments
+ xor ax, ax
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ ; move stack to the top of 640k
+ mov ax, 9000h
+ mov ss, ax
+ xor sp, sp
+
+ ; run 16bit video bios test
+ mov ax, 13h
+ ;int 10h
+
+ mov ax, 0a000h
+ mov es, ax
+ xor di, di
+ mov cx, 32000
+ mov ax, 6767h
+ rep stosw
+
+.hang: hlt
+ jmp .hang
+
+ align 4
end: