Another Test-Things-Then-Get-To-PM-code that doesn't work...

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.
Peter_Vigren

Another Test-Things-Then-Get-To-PM-code that doesn't work...

Post by Peter_Vigren »

[attachment deleted by admin]
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

Hm... I think that I know in what area the problem is...
I've been testing the code and come to the following result:

Everything works fine before this comment:

;;;;; Load the Global Descriptor Table and the Interrupt Descriptor Table ;;;;;

After that one, I load the GDT and IDT so I can't output any character to show where I am. My guess is that it is something with the jmp to Protected Mode. I came to this conclusion since I, directly after the code has gotten to PM, did put code to triple fault the processor (by loading Cs with an invalid selector). Normally, this would reset the computer but it doesn't. So it seems that the jmp is wrong. And it is probably nothing wrong with the GDT since a invalid GDT also triple fault the processor...

Please help... :-\
beyondsociety

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by beyondsociety »

I noticed this in your code:

Code: Select all

;;;;; Global Descriptor Table (GDT) ;;;;;

GlobalDescriptorTableRegister
dw   GlobalDescriptorTableEnding -GlobalDescriptorTableBeginning
dd   GlobalDescriptorTableBeginning
Shouldnt your gdt look like this: This is just an example.
I'm referring to the -1 that you left out of your code.

Code: Select all

gdt:
       dw gdt_end - gdt - 1
       db  gdt
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

Why should it be a -1?? In codes I've seen, I haven't noticed that...
pskyboy

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by pskyboy »

Yeah its minus 1 in mine as well.

Im not sure why this is though

Im not sure this matters anyway as this only specifys teh limit of the GDT and i have seen soem boot loaders where this has been set to 0xFFFF.

Peter
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

It didn't help... and I prefer to have the "- 1" removed from the code until I understand what it does and if it is needed...

But I really don't understand why the code doesn't work... :(
DynatOS

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by DynatOS »

It is -1 because that is the last byte. For example, an 8-byte descriptor starting at 0x00001000 doesn't end at 0x00001008, it ends at 0x00010007... 0-7 = 8 bytes.

Example of mine...

Code: Select all

GDT0 DW 0x0000,0x0000,0x0000,0x0000
GDT1 DW 0xFFFF,0x0000,0x9A00,0x00CF
GDT2 DW 0xFFFF,0x0000,0x9200,0x00CF
GDTR DW GDTR-GDT0-1,GDT0,0x0000

IDT:
DW IH0,0x0008,0xEE00,0x0000
DW IH1,0x0008,0xEE00,0x0000
DW IH2,0x0008,0x8E00,0x0000
DW IH3,0x0008,0xEE00,0x0000
DW IH4,0x0008,0xEE00,0x0000
DW IH5,0x0008,0xEE00,0x0000
DW IH6,0x0008,0xEE00,0x0000
DW IH7,0x0008,0xEE00,0x0000
DW IH8,0x0008,0xEE00,0x0000
DW IH9,0x0008,0xEE00,0x0000
DW IHA,0x0008,0xEE00,0x0000
DW IHB,0x0008,0xEE00,0x0000
DW IHC,0x0008,0xEE00,0x0000
DW IHD,0x0008,0xEE00,0x0000
DW IHE,0x0008,0xEE00,0x0000
DW IHF,0x0008,0x0E00,0x0000
DW IH10,0x0008,0xEE00,0x0000
DW IH11,0x0008,0xEE00,0x0000
DW IH12,0x0008,0xEE00,0x0000
DW IH13,0x0008,0xEE00,0x0000
DW IH14,0x0008,0x0E00,0x0000
DW IH15,0x0008,0x0E00,0x0000
DW IH16,0x0008,0x0E00,0x0000
DW IH17,0x0008,0x0E00,0x0000
DW IH18,0x0008,0x0E00,0x0000
DW IH19,0x0008,0x0E00,0x0000
DW IH1A,0x0008,0x0E00,0x0000
DW IH1B,0x0008,0x0E00,0x0000
DW IH1C,0x0008,0x0E00,0x0000
DW IH1D,0x0008,0x0E00,0x0000
DW IH1E,0x0008,0x0E00,0x0000
DW IH1F,0x0008,0x0E00,0x0000
IDTR DW IDTR-IDT-1,IDT,0x0001
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

DynatOS wrote: It is -1 because that is the last byte. For example, an 8-byte descriptor starting at 0x00001000 doesn't end at 0x00001008, it ends at 0x00010007... 0-7 = 8 bytes.
Okay... I think I understand... However, the code still doesn't work right... And I still think it is something wrong with the jmp to PM... But then again, it works perfectly to call a sub routine so the addressing may not be the problem... Oh God... ???
DynatOS

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by DynatOS »

Are you using bochs?
123abc

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by 123abc »

Bochs 2.0.pre2 is good.
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

DynatOS wrote: Are you using bochs?
Nope, I don't use any emulators.
DynatOS

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by DynatOS »

Try this...

Code: Select all

;;;;; Enter Protected Mode ;;;;;

mov eax,cr0
inc ax      ; This instead of Or Al,1 saves 1 byte
mov cr0,eax
jmp CLEAR               ;Clear instruction prefetch cache
CLEAR:
DB 0x66
DB 0xEA
DD EnterProtectedMode
DW SystemCodeSelector
nothing

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by nothing »

I think it's your IDT.
Peter_Vigren

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by Peter_Vigren »

DynatOS wrote: Try this...

Code: Select all

;;;;; Enter Protected Mode ;;;;;

mov eax,cr0
inc ax??????; This instead of Or Al,1 saves 1 byte
mov cr0,eax
jmp CLEAR               ;Clear instruction prefetch cache
CLEAR:
DB 0x66
DB 0xEA
DD EnterProtectedMode
DW SystemCodeSelector
I can try it... but I don't really get it... Is that opcodes for a far jmp or?
DynatOS

Re:Another Test-Things-Then-Get-To-PM-code that doesn't work

Post by DynatOS »

Yes, 0x66 is a 32-bit operand override, 0xEA is the far-jump code.
Post Reply