flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Simple protected mode OS |
Author |
|
Ralph 12 Feb 2004, 07:18
Hey,
I'm currently too lazy to look at the code, but why don't you run it through bochs? If you have windows, the win32 version comes with dochsdbg which has a debugger compiled in. Under Linux you can attach gdb. See where it's erroring out (step through if you have to, it's not a lot of code) and go from there. http://bochs.sourceforge.net/ if you didn't know already. |
|||
12 Feb 2004, 07:18 |
|
Gomer73 12 Feb 2004, 08:42
Need to change your way of thing about segments, still stuck in real mode thinking.
GDT base address is wrong. The GDT base address(which is the dword right after your GDT: label) should be the linear physical address. To correct this you could put in the following lines: gdt: dw 0x0017 ; GDT table dd gdt + 0x7c00 Once you are in protected mode, you need to use your protected mode segments. You only have two of these. They can simply be addressed as 0x08 for code segment and 0x10 for data segment. So your jump to protected mode should be something like this: jump 8:0x10000 ; base of segment is 0 Here is the kernel code that should work: mov eax,0x10 mov es,eax ; only thing we need for a stosw instruction mov ss,eax mov esp,0x7C00 ; initialize return stack ; no need to at this point since interrupts ; are disabled and we aint making any calls mov edi,0xB8000 mov ah,4 mov al,4 stosw ; show character on screen hang_loop inc word [0xB8002] ; just to give us something nice to look at jmp $ ; hang One other really useful hint I found that somebody else came up with(can't remember exactly who) is you can track your steps in your coding. Basically initialize the GS to 0xB800 and then write something to the screen at every step. For example: mov ax,0xB800 mov gs,ax mov word [gs:4], 0x1731 ; I've always liked the color blue .reset: xor ax,ax xor dx,dx int 0x13 ; reset disk system jc boot.reset mov word [gs:4], 0x1732 This even works in protected mode. |
|||
12 Feb 2004, 08:42 |
|
Gomer73 12 Feb 2004, 08:45
There should actualy be a colon after the hang loop. It should be:
hang_loop: inc word [0xB8002] ; just to give us something nice to look at jmp hang_loop |
|||
12 Feb 2004, 08:45 |
|
Tommy 12 Feb 2004, 09:22
Thanks Gomer! I'll test it when I get home from school...
Ralph: yes, I know about Bochs... I use Connecix Virtual PC... Maybe I should try Bochs... |
|||
12 Feb 2004, 09:22 |
|
Tommy 12 Feb 2004, 10:24
Well, I have a short beak now, so I tested it, but it doesn't work... :'( (attaching the code from A20 gate is enabled...)
Code: ... lgdt [gdt] ; load GDT table mov eax,cr0 or al,1 ; set protected mode bit mov cr0,eax jmp 0x0008:0x1000 ; jump to kernel align 8 gdt: dw 0x0017 ; GDT table dd 0x7C00+gdt dw 0x0000 dw 0xFFFF,0x0000,0x9A00,0x00CF dw 0xFFFF,0x0000,0x9200,0x00CF times 510-$ db 0 ; empty space dw 0xAA55 ; signature use32 ; kernel (in protected mode) org 0x0000 kernel: mov eax,0x10 mov es,eax ; only thing we need for a stosw instruction mov ss,eax mov esp,0x7C00 ; initialize stack mov edi,0xB8000 mov ah,4 mov al,4 stosw ; show character on screen .hang_loop: inc word [0xB8002] jmp .hang_loop ; hang |
|||
12 Feb 2004, 10:24 |
|
Gomer73 12 Feb 2004, 11:25
The jump is wrong.
It should be: jmp 0x0008:0x10000 not jmp 0x0008:0x1000 Real mode segment registers are multiplied by 0x10 to get the physical address. With the 0x0008 segment, it starts at physical address 0, so in order to jump to real mode adress 0x1000:0 in protected mode, you need to jump to 0x0008:0x10000. PS: John Fine is the one that I got the GS stuff from(I think) |
|||
12 Feb 2004, 11:25 |
|
Gomer73 12 Feb 2004, 11:29
Whups,
Forgot, you might also want to initialize the ds or es: the code I added at the end. kernel: mov eax,0x10 mov es,eax ; only thing we need for a stosw instruction mov ds,eax mov ss,eax or .hang_loop: inc word [es:0xB8002] jmp .hang_loop ; hang Sorry about that. |
|||
12 Feb 2004, 11:29 |
|
Tommy 12 Feb 2004, 13:39
Ok, I see... Thanks! I'll test it again tonight... I'm at school now... Take care!
Best regards, Tommy |
|||
12 Feb 2004, 13:39 |
|
Ralph 12 Feb 2004, 18:15
I know nothing about Connecix, but if it doesn't let you set break points, trace instructions, etc, you're missing out big.
|
|||
12 Feb 2004, 18:15 |
|
Tommy 12 Feb 2004, 19:49
Connectix doesn't.... so I better try Bochs...
Thanks for all help Gomer! Finally it works!!! JIPPI! |
|||
12 Feb 2004, 19:49 |
|
Crunch 13 Apr 2004, 21:50
Tommy,
I'm really a newbie and enjoyed this thread even though I didn't understand as much as I should. It would be a big help if you wouldn't mind posting your debugged code for me to fumble through experiment with and see if I can learn something in the process Thanks |
|||
13 Apr 2004, 21:50 |
|
thomasantony 18 Aug 2004, 10:59
Hi,
Its my first post here. . I use Bochs regulerly to test my OS. But is it possible to put breakpoints in Bochs(in Windows). Thomas Antony |
|||
18 Aug 2004, 10:59 |
|
Tommy 18 Aug 2004, 13:18
Hi Crunch!
I'm posting my working code... I haven't done anything on it for months... So it's just a demo on how to get into PM... Best regards, Tommy
|
|||||||||||
18 Aug 2004, 13:18 |
|
Crunch 18 Aug 2004, 15:03
Thanks Tommy!
I know I'll learn a lot stumbling through it. |
|||
18 Aug 2004, 15:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.