I have one last question
After I move onto the second stage I try to enter protected mode and what happens is that It crashes when I try and make the jump to the protected mode here is what I have done:
Code: Select all
main:
;first stage of bootloader is loaded at the address 0x07c0:0x0FFFE
;second stage of bootloader is loaded at address 0x9000:0x0FFFF
cli
mov ax, 0x200 ;adjust the segment registers
mov ds, ax
mov gs, ax
mov fs, ax
Create_Stack:
xor ax, ax
mov es, ax
mov ss, ax
mov sp ,0x0FFFF
sti
mov [CDDriveNumber], dl
call clear
Print LOAD_SUCCESS, TEAL
call Print_ln
SwitchToProtectedMode:
cli
lgdt [GDT]
mov eax, cr0
or eax, 1
mov cr0, eax
;enable 32 bit mode
jmp 0x8:Protected_Mode
[BITS 32]
Protected_Mode:
;set up stack
xor ax, ax
MOV AX, 0x10 ; 0x10 points at the new data selector
MOV DS, AX
MOV ES, AX
MOV FS, AX
MOV GS, AX
MOV SS, AX
MOV ESP, 0x900000
mov edi, VIDEO_MEM
mov BYTE[edi], 'A'
mov BYTE[edi+1], TEAL
cli
hlt
Entered_PMODE: db "YOu have succcessfully entered Protected Mode :D", 0
LOAD_SUCCESS: db "Stage 2 Loaded Successfully",0
CDDriveNumber: db 0
GDT_START:
;null descriptor
dd 0
dd 0
;data descriptor
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
;code descriptor
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
GDT_END:
GDT:
dw GDT_END - GDT_START - 1
dd GDT_START
I was looking at the disassembly of the code and It looks like it jumps but it doesent stop after the cli hlt Why would that be???
here it is :
Code: Select all
00000200 EA8D000002 jmp word 0x200:0x8d
00000205 0000 add [bx+si],al
00000207 60 pushaw
00000208 8A360600 mov dh,[0x6]
0000020C B402 mov ah,0x2
0000020E B700 mov bh,0x0
00000210 FEC6 inc dh
00000212 B200 mov dl,0x0
00000214 CD10 int 0x10
00000216 88360600 mov [0x6],dh
0000021A C606050000 mov byte [0x5],0x0
0000021F 61 popaw
00000220 C3 ret
00000221 EB0C jmp short 0x22f
00000223 F7D8 neg ax
00000225 50 push ax
00000226 B02D mov al,0x2d
00000228 B40E mov ah,0xe
0000022A CD10 int 0x10
0000022C 58 pop ax
0000022D EB0A jmp short 0x239
0000022F 31DB xor bx,bx
00000231 B90A00 mov cx,0xa
00000234 83F800 cmp ax,byte +0x0
00000237 7CEA jl 0x223
00000239 31D2 xor dx,dx
0000023B F7F1 div cx
0000023D 52 push dx
0000023E 43 inc bx
0000023F 85C0 test ax,ax
00000241 75F6 jnz 0x239
00000243 58 pop ax
00000244 83C030 add ax,byte +0x30
00000247 B40E mov ah,0xe
00000249 CD10 int 0x10
0000024B 4B dec bx
0000024C 83FB00 cmp bx,byte +0x0
0000024F 75F2 jnz 0x243
00000251 C3 ret
00000252 B409 mov ah,0x9
00000254 B90100 mov cx,0x1
00000257 AC lodsb
00000258 84C0 test al,al
0000025A 740C jz 0x268
0000025C CD10 int 0x10
0000025E B402 mov ah,0x2
00000260 B700 mov bh,0x0
00000262 FEC2 inc dl
00000264 CD10 int 0x10
00000266 EBEA jmp short 0x252
00000268 C3 ret
00000269 B40F mov ah,0xf
0000026B B000 mov al,0x0
0000026D CD10 int 0x10
0000026F B400 mov ah,0x0
00000271 CD10 int 0x10
00000273 B402 mov ah,0x2
00000275 B701 mov bh,0x1
00000277 B600 mov dh,0x0
00000279 B200 mov dl,0x0
0000027B CD10 int 0x10
0000027D 88360600 mov [0x6],dh
00000281 88160500 mov [0x5],dl
00000285 C3 ret
00000286 E492 in al,0x92
00000288 0C02 or al,0x2
0000028A E692 out 0x92,al
0000028C C3 ret
0000028D FA cli
0000028E B80002 mov ax,0x200
00000291 8ED8 mov ds,ax
00000293 8EE8 mov gs,ax
00000295 8EE0 mov fs,ax
00000297 31C0 xor ax,ax
00000299 8EC0 mov es,ax
0000029B 8ED0 mov ss,ax
0000029D BCFFFF mov sp,0xffff
000002A0 FB sti
000002A1 88165001 mov [0x150],dl
000002A5 E8C1FF call word 0x269
000002A8 60 pushaw
000002A9 31C0 xor ax,ax
000002AB 31D2 xor dx,dx
000002AD 8A360600 mov dh,[0x6]
000002B1 8A160500 mov dl,[0x5]
000002B5 31DB xor bx,bx
000002B7 B303 mov bl,0x3
000002B9 BE3401 mov si,0x134
000002BC E893FF call word 0x252
000002BF 88160500 mov [0x5],dl
000002C3 61 popaw
000002C4 E840FF call word 0x207
000002C7 FA cli
000002C8 0F01166901 lgdt [0x169]
000002CD E8B6FF call word 0x286
000002D0 0F20C0 mov eax,cr0
000002D3 6683C801 or eax,byte +0x1
000002D7 0F22C0 mov cr0,eax
000002DA EADF000800 jmp word 0x8:0xdf
000002DF 6631C0 xor eax,eax
000002E2 66B810008ED8 mov eax,0xd88e0010
000002E8 8EC0 mov es,ax
000002EA 8EE0 mov fs,ax
000002EC 8EE8 mov gs,ax
000002EE 8ED0 mov ss,ax
000002F0 BC0000 mov sp,0x0
000002F3 90 nop
000002F4 00BF0080 add [bx-0x8000],bh
000002F8 0B00 or ax,[bx+si]
000002FA C60741 mov byte [bx],0x41
000002FD C6470103 mov byte [bx+0x1],0x3
00000301 FA cli
00000302 F4 hlt
00000303 59 pop cx
00000304 4F dec di
00000305 7520 jnz 0x327
00000307 686176 push word 0x7661
0000030A 65207375 and [gs:bp+di+0x75],dh
0000030E 636363 arpl [bp+di+0x63],sp
00000311 657373 gs jnc 0x387
00000314 66756C o32 jnz 0x383
00000317 6C insb
00000318 7920 jns 0x33a
0000031A 656E gs outsb
0000031C 7465 jz 0x383
0000031E 7265 jc 0x385
00000320 64205072 and [fs:bx+si+0x72],dl
00000324 6F outsw
00000325 7465 jz 0x38c
00000327 637465 arpl [si+0x65],si
0000032A 64204D6F and [fs:di+0x6f],cl
0000032E 6465203A and [gs:bp+si],bh
00000332 44 inc sp
00000333 005374 add [bp+di+0x74],dl
00000336 61 popaw
00000337 67652032 and [gs:edx],dh
0000033B 204C6F and [si+0x6f],cl
0000033E 61 popaw
0000033F 646564205375 and [fs:bp+di+0x75],dl
00000345 636365 arpl [bp+di+0x65],sp
00000348 7373 jnc 0x3bd
0000034A 66756C o32 jnz 0x3b9
0000034D 6C insb
0000034E 7900 jns 0x350
00000350 0000 add [bx+si],al
00000352 0000 add [bx+si],al
00000354 0000 add [bx+si],al
00000356 0000 add [bx+si],al
00000358 00FF add bh,bh
0000035A FF00 inc word [bx+si]
0000035C 0000 add [bx+si],al
0000035E 9ACF00FFFF call word 0xffff:0xcf
00000363 0000 add [bx+si],al
00000365 0092CF00 add [bp+si+0xcf],dl
00000369 17 pop ss
0000036A 005101 add [bx+di+0x1],dl
0000036D 0000 add [bx+si],al