Practical Application For the GDT
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
You're so right, I just got way ahead of myself, thanks,
Brodeur235
Brodeur235
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
The following code freezes my emulator (VBox):
I don't know if it's the emulator or me, but it freezes my bootloader, as well as the short one Xiphia wrote (which i padded, and made meet bootloader standards)...
Brodeur235
P.S. If I comment the line, the bootloader ocntinues to run, but in real mode
Code: Select all
mov cr0,eax
Brodeur235
P.S. If I comment the line, the bootloader ocntinues to run, but in real mode
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Practical Application For the GDT
I would highly suggest trying it out in Bochs. That way you can get the post-mortem Bochs log, and you can also use the debugger. It helps you find the problem quickly, without all the guesswork.
Re: Practical Application For the GDT
Whats the code for your gdt? There is probably something wrong with your gdt.brodeur235 wrote:The following code freezes my emulator (VBox):I don't know if it's the emulator or me, but it freezes my bootloader, as well as the short one Xiphia wrote (which i padded, and made meet bootloader standards)...Code: Select all
mov cr0,eax
Brodeur235
P.S. If I comment the line, the bootloader ocntinues to run, but in real mode
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Practical Application For the GDT
Do you set up DS and ES in real mode with real mode segments for your bootloader? That could be a problem, as well as ORG.
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
I think my GDT is fine now, but I know I did set up ds to equal 0 for my bootloader. If this is the problem, how do I fix it?
UPDATED bootloader code (all i changed is the gdt entries):
Brodeur235
UPDATED bootloader code (all i changed is the gdt entries):
Code: Select all
[ORG 0x7C00]
;procedures
main:
xor ax,ax
mov ds,ax
mov si,bl_loaded_msg
call print_si
call load_kernel
mov si,kl_loaded_msg
call print_si
lgdt [gdt_head]
mov si,gdt_loaded_msg
call print_si
mov eax, cr0
or eax, 1
mov cr0, eax ; <-- this line freezes my emulator's CPU. If I comment it out, the processor continues, but in real mode.
jmp 0x8:kernel ; I tried disabling (cli) and reenabling interrupts before and after the "mov", but nothing changed
print_si:
mov bh,0x00
mov bl,0x07
mov ah,0x0E
.next_char
lodsb
cmp al,0x00
jz .done
int 0x10
jmp .next_char
.done
ret
load_kernel:
mov dh,0x00
mov dl,0x00
mov ch,0x00
mov cl,0x02
xor bx,bx
mov es,bx
mov bx,kernel
mov ah,0x02
mov al,0x01
int 0x13
ret
;gdt
gdt_entries:
;null entry
dd 0x0,0x0
;code segment descriptor: OFFESET = 0x8
dw 0xFFFF,0x0000
db 0x00,10011010b
db 11001111b,0x0
;data segment descriptor: OFFSET = 0x10
dw 0xFFFF,0x0000
db 0x00,10010010b
db 11001111b,0x0
gdt_head:
size dw ($-gdt_entries)
offset dd gdt_entries
;data
bl_loaded_msg db "Bootloader loaded.",0xA,0xD,0
kl_loaded_msg db "Kernel loaded.",0xA,0xD,0
gdt_loaded_msg db "GDT setup.",0xA,0xD,0
pm_loaded_msg db "Protected mode entered.",0xA,0xD,0
;padding
times 512-2-($-$$) db 0x0000
bootable db 0xAA, 0x55
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Practical Application For the GDT
Are you certain that the emulator is freezing on the "mov cr0, eax" line? I personally think you will need to flush your segment registers when entering protected mode, a bit like this:
You probably also want to use "cli" when entering "main" (ie, before setting DS) so the CPU doesn't attempt to use the IDT until you're ready for it.
Code: Select all
mov cr0, eax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs,ax
mov ss, ax
jmp 0x8:kernel
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Practical Application For the GDT
Yeah, and I'm not sure if LGDT uses DS or ES... Try setting ES to zero as well.
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
Yeah, I'm pretty sure it's the "mov" line because when I comment it out, execution continues in real mode. If I don't comment it out, execution stops there. I tried what you said, refreshing the segment registers. Although it's a helpful tip that I will include in my bootloader, it didn't solve the problem. Here's an update of what I have changed (only the "main" proc):
Brodeur235
Code: Select all
[ORG 0x7C00]
;procedures
main:
cli
xor ax,ax
mov ds,ax
mov es,ax
sti
mov si,bl_loaded_msg
call print_si
call load_kernel
mov si,kl_loaded_msg
call print_si
lgdt [gdt_head]
mov si,gdt_loaded_msg
call print_si
cli
mov eax, cr0
or eax, 1
mov cr0, eax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs,ax
mov ss, ax
sti
jmp 0x8:kernel
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Practical Application For the GDT
Take the sti out. It should be cli.
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
My fault guys... My fault. I was trying to verify that I was in protected mode by moving a string offset into si and then calling a procedure that outputs the string 1 char at a time using int 10h only... in pm you can't use interrupts. Brilliant me, i saw no output and cried wolf: "my emulator froze!!!" Sorry. When I uncommented the thing ("mov cr0,eax"), that left me in real mode, and I got the output I expected. Every time I WAS actually making it into Pmode. Now that I'm COMPLETELY on my own, without even BIOS functions to call, I'm looking to write a procedure that will output to the monitor, picking up at where the last string written to the monitor stopped. Anyways, the purpose of this thread has been served and more. I understand the gdt and my bootloader has made it into protected mode. Your help never goes unappreciated ,
Brodeur235
Brodeur235
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
Re: Practical Application For the GDT
It's great that you got this solved and all, but I noticed you're not setting up a stack for your real mode code. Yet you're using call and ret, two instructions that do indeed use the stack. Your bootloader may work on in VirtualBox now, but fail mysteriously on real hardware later.
I'm surprised nobody else has pointed this out. Anyway, you should definitely fix this to prevent those types of mysterious failure later.
I'm surprised nobody else has pointed this out. Anyway, you should definitely fix this to prevent those types of mysterious failure later.
-
- Member
- Posts: 199
- Joined: Sat Jun 28, 2008 6:44 pm
Re: Practical Application For the GDT
There is an 80x25 character array starting at 0xB800, which coincides with (0,0) on the top left hand side of the screen. I forget the format, but each 'cell' is a short integer width (4 bytes). Two of them are for an ascii character code, and two of them dictate forgeround/background color.brodeur235 wrote:My fault guys... My fault. I was trying to verify that I was in protected mode by moving a string offset into si and then calling a procedure that outputs the string 1 char at a time using int 10h only... in pm you can't use interrupts. Brilliant me, i saw no output and cried wolf: "my emulator froze!!!" Sorry. When I uncommented the thing ("mov cr0,eax"), that left me in real mode, and I got the output I expected. Every time I WAS actually making it into Pmode. Now that I'm COMPLETELY on my own, without even BIOS functions to call, I'm looking to write a procedure that will output to the monitor, picking up at where the last string written to the monitor stopped. Anyways, the purpose of this thread has been served and more. I understand the gdt and my bootloader has made it into protected mode. Your help never goes unappreciated ,
Brodeur235
http://wiki.osdev.org/Drawing_In_Protected_Mode
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Practical Application For the GDT
syntropy: It's one byte for the ascii and one for the colour, not two each.
-
- Member
- Posts: 86
- Joined: Sat Jun 06, 2009 11:55 am
Re: Practical Application For the GDT
lol, as soon as he posted that I started looking up specs and wondering if they were wrong or he was. Yeah, it's one byte /ea. Anyways, thanks syntropy,
Brodeur235
Brodeur235
my website: http://67.11.191.209/
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS
my software: http://67.11.191.209/software
my OS: http://67.11.191.209/software/view.php? ... Synergy_OS