Help with code

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

Re:Help with code

Post by beyondsociety »

Here's the modified code that I'm having problems with. Could someone look over my code and tell me whats wrong with it. Thanks in advance.

Code: Select all

[BITS 16]
[ORG 0x7C00]

              ; Initialize Segment Regs

              xor ax, ax
              mov ds, ax

              mov es, ax
              mov fs, ax
              mov gs, ax

              mov [bootdrv],dl

              ; Setup a Real Mode Stack
              
              cli
              mov ax, 0x9000
              mov ss, ax              
              mov sp, 0xFFFE
              sti

              cli

              lgdt [gdtr_ptr]

              mov eax,cr0
              or  eax,1
              mov cr0,eax

              jmp 0x08:enter_pmode

[bits 32]
enter_pmode:

              mov ax,0x10
              mov ds, ax
              mov es, ax
              mov fs, ax
              mov gs, ax
              mov ss, ax

              jmp $

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

; The GDTR Limit and Base
gdtr_ptr:
              dw 0xFFFF
              dd 0

; The GDT Setup Entries
gdt_start:
              ; Null Segment Descriptor, 0x00

              dd 0         
              dd 0

              ; Code Segment Descriptor, 0x08

              db 11111111b   ; 4GB Limit
              db 11111111b   ; 4GB limit
              db 00000000b   ; Base 0
              db 00000000b   ; Base 0
              db 00000000b   ; Base 0
              db 10011010b   ; Present : Ring 0 : Code\Exec : Non-Conforming : Readable
              db 11001111b   ; 4KB Granularity : 32Bit : 4GB Limit
              db 00000000b   ; Base 0

              ; Data Segment Descriptor, 0x10

              db 11111111b   ; 4GB Limit
              db 11111111b   ; 4GB limit
              db 00000000b   ; Base 0
              db 00000000b   ; Base 0
              db 00000000b   ; Base 0
              db 10010010b   ; Present : Ring 0 : Data : Expand Up : Writable
              db 11001111b   ; 4KB Granularity : 32Bit : 4GB Limit
              db 00000000b   ; Base 0

gdt_end:

;----------------------------------------------------------------------
; DATA
;----------------------------------------------------------------------

              bootdrv   db 0

              times 510-($-$$) db 0           
              dw 0xAA55                       
Curufir

Re:Help with code

Post by Curufir »

You've setup gdt_ptr wrong.

Curufir
Tom

Re:Help with code

Post by Tom »

you could try my GDT ( actually, frank made it for me )
PlayOS

Re:Help with code

Post by PlayOS »

Simple solution, just change this

Code: Select all

; The GDTR Limit and Base
gdtr_ptr:
              dw 0xFFFF
              dd 0
to this

Code: Select all

; The GDTR Limit and Base
gdtr_ptr:
              dw 0xFFFF
              dd gdt_start
Problem Solved, Good Luck!
beyondsociety

Re:Help with code

Post by beyondsociety »

Thanks for the help playOS. It works! :D
Post Reply