Help with activating pmode

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.
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

It still create this exception in Bochs:
00002589342e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
My OS: SOS (Simple Operating System).
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Post by svdmeer »

I think I made a mistake. That 500h is not always right. It depends also on your realmode-segments. Is it true in realmode your segment-registers are 0 and your code is loaded at address 0x500? If that's true, what I told you about adding 0x500 is not true, in that case you need to remove the +500h.

And that print-function?

Did you try without it?

I see you don't use int 10h which is good. The problem is your print-function is part of the 16-bit code. Move your print-function in the 32-bit part, otherwise it won't work.

Code: Select all

;;;; ========16 bit part ===========
; put your 16 bit stuff here

;being 32 bit stuff	
bits 32
Kernel:

	;-------------------------------;
	;   Set registers		;
	;-------------------------------;

	mov ax, 0x10 
	mov ds, ax 
	mov ss, ax 
	mov es, ax 
	mov fs, ax 
	mov gs, ax
	mov		esi, msg
	mov		edi, 0xb8000
	call	Print
	hlt
	
msg db "HELLO WORLD!", 0
; (control chars like 0x0A and 0x0D make no
; sense when writing directly to video memory)

Print:    cld            
            mov ah,0x0f  ; color 
nextchar:   lodsb ; get char and increase si
            or al,al  ; if char= 0 then stop print. 
            jz screen.print.finish 
            stosw  ; put the char+color on the screen and increase di with 2
            jmp short nextchar  ; countione (sry for my bad spelling) 
screen.print.finish: 
             ret
Last edited by svdmeer on Sun May 25, 2008 5:32 pm, edited 1 time in total.
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

other then the fact that it won't print to the screen the error has been fixed. Now it loads and doesn't create an error. It is sitting there happily saying nothing for I took out the loading msgs.

Thank you very much.
My OS: SOS (Simple Operating System).
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Post by svdmeer »

Do you get something on screen if you replace "call Print" with "mov word [0xb8000],0x5050"?

Are you sure you are in textmode? If not try in your realmode part "MOV AX,3", "INT 10h".
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

It prints "loading the kernel" in all its glory under realmode but It won't print anything under pmode.
My OS: SOS (Simple Operating System).
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

tadada wrote:It prints "loading the kernel" in all its glory under realmode but It won't print anything under pmode.
Please answer svdmeer's question, and do not call your routine.

Also, it may not work if the routine is 16 bit not 32 bit. i.e., If the routine is within the 16 bit code segment, it may not work. (I had hit and mess with this before.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

sorry about that. No when I replace the call line with the line you supplied nothing happened. Also I moved the "bits 32" so it comes before the routine.
My OS: SOS (Simple Operating System).
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

Maybe the error is in the GTD you posted, I counted only 2 dwords for the first entry (null entry) isn't there supposed to be 3?
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

I thought the GDT was supposed to total 8 bytes for each entry. and with
2 DWs and 4 DBs it totals 8 bytes (unless I don't know my DWs and such) I know it has just as many bytes as the other entries and the jmp works so that means at leaast the SYS_CODE_SEL is alligned properly.
My OS: SOS (Simple Operating System).
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

My bad, i'm tired.

I read the dw as meaning DWord not Data: Word

try using the bochs debugger, add a breakpoint at the Pmode code start and use the step function ('s') to trace each instruction until you hit the error.
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Post by svdmeer »

tadada wrote:sorry about that. No when I replace the call line with the line you supplied nothing happened. Also I moved the "bits 32" so it comes before the routine.
`

It becomes weird..it looks like 0xb8000 isn't your videosegment.
Are you in textmode?

The function cannot work in realmode, because address 0xb8000 isn't addressable with only a offset-register. You must have a segment-register set, for example es=b800, es:[0] -> first char.

Does:
mov ax,0xb800
mov es,ax
mov word es:[0],0x5050
work in realmode?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

iirc, the text mode video segment can begin at either 0xb8000 or 0xb0000--Try both of them and see what happens.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post by tadada »

the video ram is 0xb800 in real mode. Moving 0x5050 into the ram during real mode works (a black "P" on a purple background appears), but in pmode it doesn't.

I was using the code:

Code: Select all

mov ax,0xb800 
mov es,ax 
mov word [es:0],0x5050
with this code:

Code: Select all

mov ax,0xb800 
mov es,ax 
mov word es:[0],0x505
nasm gives me an error

In real mode none of the following works: b800, b000, b8000, b0000

BTW: How do I insert a break point?
My OS: SOS (Simple Operating System).
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

I haven't read much of this post, but if you are using BOCHS then stick a 'hlt' where you want it to break and then check the debugging logs.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Both code snippets you posted means the same thing--use the first method as it works in NASM.
tadada wrote:the video ram is 0xb800 in real mode. Moving 0x5050 into the ram during real mode works (a black "P" on a purple background appears), but in pmode it doesn't.
Can you please rephrase this? I assume that it works with 0xb800, but then you say it doesn't... :/

/me thinks we need to see more code. More specifically your PMode and printing routine.

Are you using svdmeer's code?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply