INIT_PIC stops text output!

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.
Post Reply
AltexPape
Posts: 9
Joined: Sat May 16, 2009 4:30 pm

INIT_PIC stops text output!

Post by AltexPape »

So,

I have been working on my hobby OS for a while now and it has been only in the last couple of weeks that I actually got everything working.

OK, I am using NASM and GCC on Vista and testing it using a Virtual Floppy Drive and VirtualBox.

So here is where I am in the code:
I got everything working and I am outputting to the screen directly using 0xb8000.
I have been working on getting keyboard input.

So, when I create my Keyboard driver in my kernel, it calls the method INIT_PICS from http://osdever.net/tutorials.php?cat=5&sort=1.

I have implemented all of the assembly routines already.


So here is the issue:
Whenever I test the OS, if I call INIT_PICS then none of my screen output works! There is no error, but the program just hangs.

Is there an issue with PIC and using 0xb8000?
Is there an issue with PIC in VirtualBox?

Do you have any ideas?
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: INIT_PIC stops text output!

Post by 01000101 »

Do you enable interrupts during your init routine? if so, you may be hanging in an ISR.
I'd use the BOCHS debugger to see where you're idling.
AltexPape
Posts: 9
Joined: Sat May 16, 2009 4:30 pm

Re: INIT_PIC stops text output!

Post by AltexPape »

Thanks!

Sorry,

This was really stupid of me... Somewhere my OutPort functions don't work.

I wrote them not with inline code, and I must have made a mistake changing it from AT&T to Intel...

So I just have a simpler question, what would the following inline function be if separated (assume NASM)?

Inline C

Code: Select all

inline static void outportb(int port, unsigned char data)
{
	asm volatile
	(
		"outb %%al, %%dx\n\t" 
		:
		: "a" (data), "d" (port)
	);
}
C:

Code: Select all

extern "C" void writeOutB(int port, unsigned char data);
Why doesn't this work?
ASM:

Code: Select all

segment .text
_writeOutC:
	out dx, al
I must be forgetting to move the argument into dx. I'm not so good at assembly.

Could

Code: Select all

segment .text
_writeOutC:
        pop al
        pop dx
	out dx, al
work?
Last edited by AltexPape on Sat May 16, 2009 5:40 pm, edited 1 time in total.
User avatar
scgtrp
Member
Member
Posts: 30
Joined: Sat Mar 28, 2009 7:32 pm

Re: INIT_PIC stops text output!

Post by scgtrp »

Why doesn't this work?
ASM:

Code: Select all

segment .text
_writeOutC:
	out dx, al
I must be forgetting to move the argument into dx. I'm not so good at assembly.
That, and you're not loading al, and you're not returning from it, you're just going off and executing some stuff. (Or is this called with some kind of regparm magic?)

Known working outportb-equivalent function:

Code: Select all

	void write8(uint16 port, uint8 data)
	{
		asm volatile
		(
			"outb %0, %1"
			::"a" (data), "Nd" (port)
		);
	}
AltexPape
Posts: 9
Joined: Sat May 16, 2009 4:30 pm

Re: INIT_PIC stops text output!

Post by AltexPape »

Well,

I think I am making an assembly mistake.
So where would the two arguments be stored? I need to move something to AL, but where from?
User avatar
scgtrp
Member
Member
Posts: 30
Joined: Sat Mar 28, 2009 7:32 pm

Re: INIT_PIC stops text output!

Post by scgtrp »

Are you referring to the inline assembly version or the NASM version? The "a" and "d" in the inline assembly input list automatically put the values in al and dx. Those are substituted in by the compiler for %0 and %1.
AltexPape
Posts: 9
Joined: Sat May 16, 2009 4:30 pm

Re: INIT_PIC stops text output!

Post by AltexPape »

scgtrp wrote:Are you referring to the inline assembly version or the NASM version? The "a" and "d" in the inline assembly input list automatically put the values in al and dx. Those are substituted in by the compiler for %0 and %1.
I am referring to the NASM version. I already have separate code and I understand Intel better than AT&T syntax.

What is the code that I should have in my .ASM file?


Can I

Code: Select all

pop al
pop dx
out al, dx
?
Last edited by AltexPape on Sat May 16, 2009 5:58 pm, edited 1 time in total.
User avatar
scgtrp
Member
Member
Posts: 30
Joined: Sat Mar 28, 2009 7:32 pm

Re: INIT_PIC stops text output!

Post by scgtrp »

Try this:

Code: Select all

outportb:
	mov word dx, [esp+0x08]
	mov byte al, [esp+0x04]
	out dx, al
	ret
Untested, but written based on what GCC generated given my function at -O1.
AltexPape
Posts: 9
Joined: Sat May 16, 2009 4:30 pm

Re: INIT_PIC stops text output!

Post by AltexPape »

Thanks all,

That worked, but since I suck at this, I am also trying to make the inport thing as well.

Same concept as the last question, what would the NASM code for inport?

Code: Select all

extern "C" char readInC(int port);
This doesn't work:

Code: Select all

_readInC:
	mov word dx, [esp+0x08]
	in al, dx
	ret
Any ideas?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: INIT_PIC stops text output!

Post by Combuster »

What is ESP pointing to?
What is your calling convention?
Where are your arguments?

Right now you seem to be programming blind.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: INIT_PIC stops text output!

Post by whowhatwhere »

Altex, I'd suggest you go back and understand how assembly works.
Post Reply