Page 1 of 1

Problems with .ASM files in MS VC++ 2012

Posted: Mon Oct 03, 2016 3:09 pm
by Ycep
Hi guys, recently I wanted to remove inline assembly from my OS and put them in normal files, beginning with I/O Ports:


io.asm

Code: Select all

PUBLIC _outb ;Making them visible in C++ Files
PUBLIC _inb
PUBLIC _outw
PUBLIC _inw
.386 ;Pentium 386
.MODEL FLAT, C
.CODE ;Code segment
_outb PROC
	push ebp
	mov ebp, esp
	mov dx, [ebp+4]
	mov al, [ebp+6]
	out dx, al
	pop ebp
	ret
_outb ENDP
_inb PROC
	push ebp
	mov ebp, esp
	mov dx, [ebp+4]
	in al, dx
	pop ebp
	ret
_inb ENDP
_outw PROC
	push ebp
	mov ebp, esp
	mov dx, [ebp+4]
	mov ax, [ebp+6]
	out dx, ax
	pop ebp
	ret
_outw ENDP
_inw PROC
	push ebp
	mov ebp, esp
	mov dx, [ebp+4]
	in ax, dx
	pop ebp
	ret
_inw ENDP

END
And defining them :

hal.h

Code: Select all

extern uint8 inb(uint16 id);
extern void outb(uint16 id, uint8 value);
extern uint16 inw(uint16 id);
extern void outw(uint16 id, uint16 value);
Now I get tons of unreferenced outb()'s, inb()'s, outw()'s and inw()'s, so I probably done something wrong above.
I have enabled Microsoft Macro ASM.

Any help would be welcome. :(

Re: Problems with .ASM files in MS VC++ 2012

Posted: Mon Oct 03, 2016 3:26 pm
by BenLunt
If you are using C++ and since you are using MS VC++ 2012, I am guessing so, the compiler will actually add the count of parameters to the name of the function.

inp(int x) becomes inp@1etcetcetc

To fix the problem, wrap your prototypes with

Code: Select all

extern "C" { 
  inp(int x);
}
This is my guess to what is happening.
Ben

Re: Problems with .ASM files in MS VC++ 2012

Posted: Tue Oct 04, 2016 12:29 pm
by Ycep
Now I done this:

Code: Select all

extern "C"
{
	extern uint8 inb(uint16 id);
	extern void outb(uint16 id, uint8 value);
	extern uint16 inw(uint16 id);
	extern void outw(uint16 id, uint16 value);
}
And it still won't compile. Thank you for trying to help, through.
If it is required, there's debug log of MSVC12:
1>pic.obj : error LNK2019: unresolved external symbol _outb referenced in function "bool __cdecl PitInit(void)" (?PitInit@@YA_NXZ)
1>Sound.obj : error LNK2001: unresolved external symbol _outb
1>serial.obj : error LNK2001: unresolved external symbol _outb
1>time.obj : error LNK2001: unresolved external symbol _outb
1>dma.obj : error LNK2001: unresolved external symbol _outb
1>floppy.obj : error LNK2001: unresolved external symbol _outb
1>keyb.obj : error LNK2001: unresolved external symbol _outb
1>mouse.obj : error LNK2001: unresolved external symbol _outb
1>Sound.obj : error LNK2001: unresolved external symbol _inb
1>serial.obj : error LNK2001: unresolved external symbol _inb
1>time.obj : error LNK2019: unresolved external symbol _inb referenced in function "char * __cdecl PrintDate(bool)" (?PrintDate@@YAPAD_N@Z)
1>floppy.obj : error LNK2001: unresolved external symbol _inb
1>keyb.obj : error LNK2001: unresolved external symbol _inb
1>mouse.obj : error LNK2001: unresolved external symbol _inb
1>pic.obj : error LNK2001: unresolved external symbol _inb

Re: Problems with .ASM files in MS VC++ 2012

Posted: Tue Oct 04, 2016 12:52 pm
by iansjack
Have you set up the appropriate custom build rules?

http://stackoverflow.com/questions/4548 ... ual-studio

Re: Problems with .ASM files in MS VC++ 2012

Posted: Tue Oct 04, 2016 1:54 pm
by Ycep
If you think on that, yes I did.

Re: Problems with .ASM files in MS VC++ 2012

Posted: Tue Oct 04, 2016 3:08 pm
by iansjack
It seems fairly clear that you haven't included these files in the list to be compiled and/or linked. Are the object files being produced?

Re: Problems with .ASM files in MS VC++ 2012

Posted: Tue Oct 04, 2016 9:08 pm
by BenLunt
As previously asked, do a directory listing and see if the corresponding .obj files have been created. If not, you have not told VC to include the .asm file(s) in the build. I use an older version of VC but it should be similar.

With the file listing in the left window, right click on the file in question, then click on "properties". Click on "Custom Build Setup". In the "Command line" field, type the command to assemble the file just as if you did it at the DOS prompt. Be sure to name the file in the "outputs" field so that VC knows what file to include in the Link process.

Again, I use an older version of VC but you should be able to follow along those instructions.

Also, I may be wrong here, but you shouldn't have to include the "extern" in front of the prototypes.

Ben
FYSOS - http://www.fysnet.net/fysos.htm

Re: Problems with .ASM files in MS VC++ 2012

Posted: Wed Oct 05, 2016 6:27 am
by Ycep
Yes there is io.obj.
I got message "Assembling ..\Repository\Kernel\Code\core\io.asm..."
My newest code:

Code: Select all

extern "C"
{
	uint8 inb(uint16 id);
	void outb(uint16 id, uint8 value);
	uint16 inw(uint16 id);
	void outw(uint16 id, uint16 value);
}
I don't know what to do; :(
Thanks a lot to iansjack, BenLunt and others for trying to help.

Re: Problems with .ASM files in MS VC++ 2012

Posted: Wed Oct 05, 2016 8:40 am
by iansjack
If the object files are there, and they define the required functions (check the object files to see this is so), then you are not including them in the link. You could always try linking them from the command line to verify this.

Re: Problems with .ASM files in MS VC++ 2012

Posted: Wed Oct 05, 2016 9:36 am
by Ycep
Fixed: Woohoo! Thanks to both of you! The problems were in underlines. Now removed and everything works perfectly.

Althrough, since these are my new IO ports functions coded in assembly, previously in C++, how could I test do they work? :?:

Re: Problems with .ASM files in MS VC++ 2012

Posted: Wed Oct 05, 2016 12:13 pm
by Ycep
Althrough, since these are my new IO ports functions coded in assembly, previously in C++, how could I test do they work? :?:

Re: Problems with .ASM files in MS VC++ 2012

Posted: Wed Oct 05, 2016 8:41 pm
by BenLunt
Lukand wrote:Althrough, since these are my new IO ports functions coded in assembly, previously in C++, how could I test do they work? :?:
Read and write to a port, see if it works. :-)

Read from the keyboard data port (PS2) and press some keys. Read from the PS2's Mouse port and move the mouse, etc.

Read from a port that you will know what the value read will be, say a CMOS port.

Best thing to do, is place a NOP instruction such as xchg ebx,ebx before the code in question, compile and link, then disassemble the binary, looking for the xchg instruction, then look to see if it was assembled correctly.

Just some thoughts,
Ben