I want to print a string from the current cursor position in pmode,the following is the codes:
void delay()
{
???__asm__("movb $0,%%al;
?????? outb %%al,$0x80;"
?????? :::"%al");
}
unsigned int getcurpos()
{
???unsigned int uCurPos;
???unsigned char uHByte,uLByte;
???
???/*outb(0x3D4,0x0F);*/
???__asm__("movb $0x0F,%%al;
??? movw $0x3D4,%%dx;
?????? outb %%al,%%dx;"
?????? :::"%al","%dx");
???delay();
/*uLByte = inb(0x3D5);*/
???__asm__("movw $0x3D5,%%dx;
?????? inb %%dx,%0;"
?????? :"=r"(uLByte)
?????? ::"%dx");
???
???
???delay();
/*outb(0x3D4,0x0E);*/
???__asm__("movb $0x0E,%%al;
??? movw $0x3D4,%%dx
?????? outb %%al,%%dx;"
?????? :::"%al","%dx");
???delay();
/*uHByte = inb(0x3D5);*/
???__asm__("movw $0x3D5,%%dx;
?????? inb %%dx,%0;"
?????? :"=r"(uHByte)
?????? ::"%dx");
???
???uCurPos = uHByte;
???uCurPos = (uCurPos<<8)|uLByte;
???return uCurPos;
}
void printMsg(char *msg)
{
???unsigned int nCurPos;
???char *pVRAM = (char *)0xB8000;
???
???nCurPos = getcurpos();
???pVRAM = pVRAM + nCurPos;
???while(*msg!=0)
???{
?????? *pVRAM=*msg;
?????? msg++;
?????? pVRAM++;
?????? *pVRAM=0x07;
?????? pVRAM++;
???}???
}
any hint?
BTW:I want to write a function named outb() originally just like this:
void outb(unsigned int portaddr,unsigned char var)
{
???__asm__("movb %0,%%al;
movw %1,%%dx;
?????? outb %%al,%%dx";
?????? :
?????? :"r"(var),"r"(portaddr)
?????? :"%al","%dx");???
}
but compile it with gcc -c outb.c -o outb.o
will result in error: suffix or operands invalid for 'mov'
why?
Unexpected result about screen print in pmode,help!
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Unexpected result about screen print in pmode,help!
you can avoid explicit moves to al and dx by telling the compiler you want the values in those registers rather than in "r".
Code: Select all
static __inline__ void outb (unsigned char value, unsigned short port)
{
asm volatile ("outb %0,%1":: "a" (value), "Nd" (port));
}