Jumping to protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
B.E

Jumping to protected mode

Post by B.E »

My second stage is at 8001:0000

to jump to protected mode I use

Code: Select all

      jmp 08:DWORD 80010h + Start32
[bits 32]

      Start32:
      mov eax,016 ; 
      mov es,eax
      mov bh,'D'
      mov [es:0b8000h],bh      
      jmp $
it restarts just after i the jmp to prtected mode
what it wrong
AR

Re:Jumping to protected mode

Post by AR »

I can't say about the jump instruction as you haven't shown the ORG statement. Aside from that you haven't shown the GDT either.
B.E

Re:Jumping to protected mode

Post by B.E »

ORG stat:

Code: Select all

[org 0]
GDT :

Code: Select all



GDTR:
   GDTSize DW GDTEND-GDT
   GDTBase DD GDT+080010h

GDT:
NULLSEL   equ $-GDT
???DD 0h
???DD 0h
???
CODESEL   equ $-GDT
???dw 0xFFFF
???dw 0
???db 0
???db 9ah
???db 0cfh
???db 0???
DATASEL   equ $-GDT
???dw 0xFFFF
???dw 0
???db 0
???db 92h
???db 0cfh
???db 0
GDTEND:
AR

Re:Jumping to protected mode

Post by AR »

I may not be looking hard enough but I can't see anything wrong. The only thing left is the LGDT instruction.
B.E

Re:Jumping to protected mode

Post by B.E »

lgdt [GDTR]
mov eax,cr0
or ax,1
mov cr0,eax
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Jumping to protected mode

Post by bubach »

Why do you use:
80010h + Start32 ?

Even if your org is 0, you have set up the segments so that it can handle var/function addresses, right?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
B.E

Re:Jumping to protected mode

Post by B.E »

80010h + Start32 is the phisical address of my second stage
B.E

Re:Jumping to protected mode

Post by B.E »

bubach wrote: you have set up the segments so that it can handle var/function addresses, right?
I'm still in the boot loader.
B.E

Re:Jumping to protected mode

Post by B.E »

Log from bochs

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.0.cvs
00000000000i[     ]   Build from CVS, after 2.0
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: no
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 5
00000000000i[     ]   fpu support: yes
00000000000i[     ]   paging support: yes, tlb enabled: yes
00000000000i[     ]   mmx support: yes
00000000000i[     ]   sse support: no
00000000000i[     ]   v8086 mode support: yes
00000000000i[     ]   PAE support: no
00000000000i[     ]   PGE support: no
00000000000i[     ]   PSE support: no
00000000000i[     ]   x86-64 support: no
00000000000i[     ]   SEP support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Host Asm support: yes
00000000000i[MEM0 ] 0.00MB
00000000000i[MEM0 ] allocated memory at 00D50020. after alignment, vector=00D51000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] rom at 0xf0000/65536 ('../BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/32769 ('../VGABIOS-elpin-2.40')
00000000000i[CMOS ] Setting initial clock to: Tue May 17 13:04:00 2005 (time0=1116299040)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'a:' ro=0, h=2,t=80,spt=18
00000000000i[VGA  ] interval=30000
00000000000i[VGA  ] VBE Bochs Display Extension Enabled
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Boot device will be 'a'
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x3f8/8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x378
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000003980i[BIOS ]  rombios.c,v 1.92 2003/03/08 22:59:17 cbothamy Exp $
00000330071i[KBD  ] reset-disable command received
00000506038e[HD   ] device set to 0 which does not exist
00000506331e[HD   ] device set to 1 which does not exist
00000560214i[BIOS ] int13_diskette: unsupported AH=7F
00000564645i[BIOS ] int13_diskette: unsupported AH=7F
00000569135i[BIOS ] int13_diskette: unsupported AH=7F
00000573566i[BIOS ] int13_diskette: unsupported AH=7F
00000578000i[BIOS ] int13_diskette: unsupported AH=7F
00000582431i[BIOS ] int13_diskette: unsupported AH=7F
00000610049p[CPU  ] >>PANIC<< exception(): 3rd (13) exception with no resolution
00000610049i[SYS  ] Last time is 1116299041
00000610049i[CPU  ] protected mode
00000610049i[CPU  ] CS.d_b = 32 bit
00000610049i[CPU  ] SS.d_b = 16 bit
00000610049i[CPU  ] | EAX=00000010  EBX=00004416  ECX=000d0000  EDX=00000100
00000610049i[CPU  ] | ESP=00000400  EBP=00000000  ESI=00000265  EDI=0000003c
00000610049i[CPU  ] | IOPL=0 NV UP EI PL NZ NA PE NC
00000610049i[CPU  ] | SEG selector     base    limit G D
00000610049i[CPU  ] | SEG sltr(index|ti|rpl)     base    limit G D
00000610049i[CPU  ] |  DS:8001( 0000| 0|  0) 00080010 0000ffff 0 0
00000610049i[CPU  ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00000610049i[CPU  ] |  FS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00000610049i[CPU  ] |  GS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00000610049i[CPU  ] |  SS:0100( 0000| 0|  0) 00001000 0000ffff 0 0
00000610049i[CPU  ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00000610049i[CPU  ] | EIP=00080080 (00080080)
00000610049i[CPU  ] | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000610049i[CPU  ] | CR3=0x00000000 CR4=0x00000000
00000610049i[     ] restoring default signal behavior
00000610049i[CTRL ] quit_sim called with exit code 1

User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Jumping to protected mode

Post by Brendan »

Hi,
B.E wrote: My second stage is at 8001:0000

to jump to protected mode I use

Code: Select all

??????jmp 08:DWORD 80010h + Start32
[bits 32]

??????Start32:
??????mov eax,016 ; 
??????mov es,eax
??????mov bh,'D'
??????mov [es:0b8000h],bh??????
??????jmp $
it restarts just after i the jmp to prtected mode
what it wrong

The actual jump works correctly, and (based on the register values in the error log from Bochs) it's getting past the "mov bh,'D'" instruction.

Also (based on the Bochs error log) ES is set for base=0, limit=4 Gb. I think the type for ES is correct, so it's impossible for the "mov [es:0b8000h],bh" instruction to cause a general protection exception (it can't exceed the limit, and at CPL=0 privilege levels won't matter).

This only leaves a single instruction - "jmp $". Because this should be encoded as a relative jump, your messed up ORG shouldn't matter (note: I say "messed up ORG" as normally CS base + ORG should equal the address the code is at to avoid the need to manually correct the assembler with "label+80010h").

Anyway the "jmp $" instruction should also work, so the only assumption I can make is that you've left interrupts enabled. If this is the case, the first IRQ that is generated (most likely IRQ0) would cause the general protection exception as there is no IDT or interrupt handlers.

Just insert a "CLI" somewhere before you enable protected mode with "mov cr0,eax", and hopefully it'll all work...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
B.E

Re:Jumping to protected mode

Post by B.E »

I have insterted CLI before entering protected mode. Do I reprogram the PIC before I enable interrupts?
AR

Re:Jumping to protected mode

Post by AR »

You should reprogram the PIC before enabling interrupts so that the hardware interrupts won't look like protected mode exceptions. (And you need an IDT either way of course)
B.E

Re:Jumping to protected mode

Post by B.E »

Questions:
Where should I remap the PIC to and why that location?
Where should I put the IDT in memory and why?
AR

Re:Jumping to protected mode

Post by AR »

How should you remap the PIC, however you like as long as you don't use anything below 0x20 (Interrupt 32) because those are reserved for internal processor exceptions (divide by 0, page faults, etc).

You can put the IDT anywhere you like as well, the only thing to keep in mind is that it must always be in the currently active virtual address space and must never be paged out (Same goes for the Interrupt Service Routines).

(32bit aligning for efficency would probably be a good idea as well)
B.E

Re:Jumping to protected mode

Post by B.E »

Thank you. I will remap to 20h-30h
Post Reply