Page 1 of 1
INIT_PIC stops text output!
Posted: Sat May 16, 2009 4:40 pm
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?
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:29 pm
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.
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:36 pm
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?
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:38 pm
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)
);
}
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:41 pm
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?
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:44 pm
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.
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:47 pm
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
?
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 5:56 pm
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.
Re: INIT_PIC stops text output!
Posted: Sat May 16, 2009 7:16 pm
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?
Re: INIT_PIC stops text output!
Posted: Sun May 17, 2009 4:36 am
by Combuster
What is ESP pointing to?
What is your calling convention?
Where are your arguments?
Right now you seem to be programming blind.
Re: INIT_PIC stops text output!
Posted: Sun May 17, 2009 11:30 am
by whowhatwhere
Altex, I'd suggest you go back and understand how assembly works.