Far jump in assembly
Posted: Tue Nov 11, 2008 10:42 am
Alright, I know I'll probably get flamed for this but I'm having some trouble with far jumps. I understand how they work, but I'm having trouble actually implementing one. I'm writing part of a boot program that executes a far jump into 32 bit code after entering protected mode. The problem is that I have no idea what segment number to use. The code segment being used by the second stage boot program is 0x0050 and the label for the 32 bit code section is clear_pipe so I'm just doing this:
jmp 0x0050:clear_pipe
but bochs keeps giving me an error
3rd (13) exception with no resolution. I'll post the code with some modifications to shorten it.
Thanks for any help
jmp 0x0050:clear_pipe
but bochs keeps giving me an error
3rd (13) exception with no resolution. I'll post the code with some modifications to shorten it.
Code: Select all
[BITS 16] ;16 bit code generation
[ORG 0x0000]
START:
;Adjust segments
cli
mov ax, 0x0050
mov es, ax
mov ds, ax
mov fs, ax
mov gs, ax
;Print status message
mov si, msgLoading
call WriteMessage
;Check for compatible processor
call detect_cpu
;Enable A20 Line
call enableA20
;Enter protected mode
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0
mov cr0, eax ; Copy the contents of EAX into CR0
;Far jump to 32 bit code
jmp 0x0050:clear_pipe
;********************Check CPU for 386 or higher************************
detect_cpu:
;Omitted
;**********************Enable A20 Line*******************************
enableA20:
;Omitted
;**********************Message Procedure*****************************
;Omitted
;*************************Protected Mode Code************************
[BITS 32] ; We now need 32-bit instructions
clear_pipe:
jmp $
mov ax, 10h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
mov byte [ds:0B8000h], 'P' ; Move the ASCII-code of 'P' into first video memory
mov byte [ds:0B8001h], 1Bh ; Assign a color code
hang:
jmp hang ; Loop, self-jump
;**********************Global Descriptor Table***********************
;Omitted