Hi All,
There is a complicated issue here. I have downloaded
fasm source of a driver and want to integrate it to my kernel.
However, there is a problem:
1. If i call a FASM function from within C code (kernel), it is not
able to return back to the next line in C Code
2. If i call a NASM function from within C Code, it works properly (it
returns back to next line in C Code)
Here are the code snippets:
NASM:
global <func name>
<func name>:
ret
FASM:
public <func name>
<func name>:
ret
Is there a global keyword or similar stuff in FASM?
|
|
0
|
|
|
|
Reply
|
spamtrap2 (1628)
|
3/22/2008 8:18:36 AM |
|
suchi_01 wrote:
> Hi All,
> There is a complicated issue here. I have downloaded
> fasm source of a driver and want to integrate it to my kernel.
> However, there is a problem:
>
> 1. If i call a FASM function from within C code (kernel), it is not
> able to return back to the next line in C Code
What *does* it do?
> 2. If i call a NASM function from within C Code, it works properly (it
> returns back to next line in C Code)
>
> Here are the code snippets:
>
> NASM:
>
> global <func name>
>
> <func name>:
> ret
>
>
> FASM:
>
> public <func name>
>
> <func name>:
> ret
>
>
> Is there a global keyword or similar stuff in FASM?
"public", AFAIK. We need to tell Fasm a "format", too (in the source,
not on the command line like Nasm). As a test, I just "converted" a Nasm
demo I had to Fasm (just added "format elf", changed "global" to
"public" and fixed up the section declaration). Worked fine. The only
issue I can see is that I don't think Fasm supports OMF. What format are
you using?
Best,
Frank
;---------------
format elf
public getvendor
section ".text" executable
getvendor:
pusha
xor eax, eax
cpuid
mov eax, [esp + 36]
mov [eax], ebx
mov [eax + 4], edx
mov [eax + 8], ecx
mov byte [eax + 12], 0
popa
xor eax, eax
ret
;-----------------
And the C caller...
#include <stdio.h>
void getvendor(char *vendorbuf);
int main(void)
{char vendorbuf[13];
getvendor(vendorbuf);
puts(vendorbuf);
return 0;
}
|
|
0
|
|
|
|
Reply
|
Frank
|
3/22/2008 10:24:31 AM
|
|
Hi Frank,
Thanks for the reply. Will try it and let you know. This
is precisely what i want to do, but the problem is that the bootsector
code does not have an elf loader yet, so i don't know whether .text
part will be identified and put in the right place or not during boot
process
Suchindra Chandrahas
On Mar 22, 3:24 pm, Frank Kotler <spamt...@crayne.org> wrote:
> suchi_01 wrote:
> > Hi All,
> > There is a complicated issue here. I have downloaded
> > fasm source of a driver and want to integrate it to my kernel.
> > However, there is a problem:
>
> > 1. If i call a FASM function from within C code (kernel), it is not
> > able to return back to the next line in C Code
>
> What *does* it do?
>
>
>
> > 2. If i call a NASM function from within C Code, it works properly (it
> > returns back to next line in C Code)
>
> > Here are the code snippets:
>
> > NASM:
>
> > global <func name>
>
> > <func name>:
> > ret
>
> > FASM:
>
> > public <func name>
>
> > <func name>:
> > ret
>
> > Is there a global keyword or similar stuff in FASM?
>
> "public", AFAIK. We need to tell Fasm a "format", too (in the source,
> not on the command line like Nasm). As a test, I just "converted" a Nasm
> demo I had to Fasm (just added "format elf", changed "global" to
> "public" and fixed up the section declaration). Worked fine. The only
> issue I can see is that I don't think Fasm supports OMF. What format are
> you using?
>
> Best,
> Frank
>
> ;---------------
> format elf
>
> public getvendor
>
> section ".text" executable
> getvendor:
> pusha
> xor eax, eax
> cpuid
> mov eax, [esp + 36]
> mov [eax], ebx
> mov [eax + 4], edx
> mov [eax + 8], ecx
> mov byte [eax + 12], 0
> popa
> xor eax, eax
> ret
> ;-----------------
>
> And the C caller...
>
> #include <stdio.h>
>
> void getvendor(char *vendorbuf);
>
> int main(void)
> {char vendorbuf[13];
> getvendor(vendorbuf);
>
> puts(vendorbuf);
> return 0;
> }
|
|
0
|
|
|
|
Reply
|
suchi_01
|
3/24/2008 5:00:36 AM
|
|
Hi Frank,
I am sorry i was not clear about the environment. The code
(assembly language function) is called during boot time by a
bootsector code (after enabling protected mode). I am successful in
calling the function but it does not return back to the C code back
(ie., next line after the call in C Code). At boot time there is no
elf loader and it is difficult to point it to where it has to return.
Mysteriously, using global in nasm does the stuff!
Suchindra Chandrahas
On Mar 22, 3:24 pm, Frank Kotler <spamt...@crayne.org> wrote:
> suchi_01 wrote:
> > Hi All,
> > There is a complicated issue here. I have downloaded
> >fasmsource of a driver and want to integrate it to my kernel.
> > However, there is a problem:
>
> > 1. If i call aFASMfunction from within C code (kernel), it is not
> > able to return back to the next line in C Code
>
> What *does* it do?
>
>
>
> > 2. If i call aNASMfunction from within C Code, it works properly (it
> > returns back to next line in C Code)
>
> > Here are the code snippets:
>
> >NASM:
>
> >global<func name>
>
> > <func name>:
> > ret
>
> >FASM:
>
> >public<func name>
>
> > <func name>:
> > ret
>
> > Is there aglobalkeyword or similar stuff inFASM?
>
> "public", AFAIK. We need to tellFasma "format", too (in the source,
> not on the command line likeNasm). As a test, I just "converted" aNasm
> demo I had toFasm(just added "format elf", changed "global" to
> "public" and fixed up the section declaration). Worked fine. The only
> issue I can see is that I don't thinkFasmsupports OMF. What format are
> you using?
>
> Best,
> Frank
>
> ;---------------
> format elf
>
> publicgetvendor
>
> section ".text" executable
> getvendor:
> pusha
> xor eax, eax
> cpuid
> mov eax, [esp + 36]
> mov [eax], ebx
> mov [eax + 4], edx
> mov [eax + 8], ecx
> mov byte [eax + 12], 0
> popa
> xor eax, eax
> ret
> ;-----------------
>
> And the C caller...
>
> #include <stdio.h>
>
> void getvendor(char *vendorbuf);
>
> int main(void)
> {char vendorbuf[13];
> getvendor(vendorbuf);
>
> puts(vendorbuf);
> return 0;
> }
|
|
0
|
|
|
|
Reply
|
suchi_01
|
3/24/2008 5:52:50 AM
|
|
suchi_01 wrote:
> Hi Frank,
> Thanks for the reply. Will try it and let you know. This
> is precisely what i want to do, but the problem is that the bootsector
> code does not have an elf loader yet, so i don't know whether .text
> part will be identified and put in the right place or not during boot
> process
Hi Suchindra,
Doesn't sound like a Fasm/Nasm problem, really. You might want to look
at GRUB, rather than write your own.
http://www.gnu.org/software/grub/
Best,
Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
3/24/2008 7:10:39 AM
|
|
On Mar 24, 12:10 pm, Frank Kotler <spamt...@crayne.org> wrote:
> suchi_01 wrote:
> > Hi Frank,
> > Thanks for the reply. Will try it and let you know. This
> > is precisely what i want to do, but the problem is that the bootsector
Hi Frank,
I do agree with grub. It makes things easier. But looking at
the problem,i feel we would still have to call the assembly part from
C when it comes to loading the initial part to Kernel
Suchindra Chandrahas
> > code does not have an elf loader yet, so i don't know whether .text
> > part will be identified and put in the right place or not during boot
> > process
>
> Hi Suchindra,
>
> Doesn't sound like a Fasm/Nasm problem, really. You might want to look
> at GRUB, rather than write your own.
>
> http://www.gnu.org/software/grub/
>
> Best,
> Frank
|
|
0
|
|
|
|
Reply
|
suchi_01
|
3/24/2008 7:54:37 AM
|
|
oops! worked fine. Sorry i forgot another fasm file where i had to
insert the same. Sorry for the confusion. What you say is right
On Mar 24, 10:52 am, suchi_01 <spamt...@crayne.org> wrote:
> Hi Frank,
> I am sorry i was not clear about the environment. The code
> (assembly language function) is called during boot time by a
> bootsector code (after enabling protected mode). I am successful in
> calling the function but it does not return back to the C code back
> (ie., next line after the call in C Code). At boot time there is no
> elf loader and it is difficult to point it to where it has to return.
> Mysteriously, using global in nasm does the stuff!
>
> Suchindra Chandrahas
>
> On Mar 22, 3:24 pm, Frank Kotler <spamt...@crayne.org> wrote:
>
> > suchi_01 wrote:
> > > Hi All,
> > > There is a complicated issue here. I have downloaded
> > >fasmsource of a driver and want to integrate it to my kernel.
> > > However, there is a problem:
>
> > > 1. If i call aFASMfunction from within C code (kernel), it is not
> > > able to return back to the next line in C Code
>
> > What *does* it do?
>
> > > 2. If i call aNASMfunction from within C Code, it works properly (it
> > > returns back to next line in C Code)
>
> > > Here are the code snippets:
>
> > >NASM:
>
> > >global<func name>
>
> > > <func name>:
> > > ret
>
> > >FASM:
>
> > >public<func name>
>
> > > <func name>:
> > > ret
>
> > > Is there aglobalkeyword or similar stuff inFASM?
>
> > "public", AFAIK. We need to tellFasma "format", too (in the source,
> > not on the command line likeNasm). As a test, I just "converted" aNasm
> > demo I had toFasm(just added "format elf", changed "global" to
> > "public" and fixed up the section declaration). Worked fine. The only
> > issue I can see is that I don't thinkFasmsupports OMF. What format are
> > you using?
>
> > Best,
> > Frank
>
> > ;---------------
> > format elf
>
> > publicgetvendor
>
> > section ".text" executable
> > getvendor:
> > pusha
> > xor eax, eax
> > cpuid
> > mov eax, [esp + 36]
> > mov [eax], ebx
> > mov [eax + 4], edx
> > mov [eax + 8], ecx
> > mov byte [eax + 12], 0
> > popa
> > xor eax, eax
> > ret
> > ;-----------------
>
> > And the C caller...
>
> > #include <stdio.h>
>
> > void getvendor(char *vendorbuf);
>
> > int main(void)
> > {char vendorbuf[13];
> > getvendor(vendorbuf);
>
> > puts(vendorbuf);
> > return 0;
> > }
|
|
0
|
|
|
|
Reply
|
suchi_01
|
3/24/2008 11:19:06 AM
|
|
suchi_01 wrote:
> Hi Frank,
> I am sorry i was not clear about the environment. The code
> (assembly language function) is called during boot time by a
> bootsector code (after enabling protected mode). I am successful in
> calling the function but it does not return back to the C code back
> (ie., next line after the call in C Code). At boot time there is no
> elf loader and it is difficult to point it to where it has to return.
> Mysteriously, using global in nasm does the stuff!
Very mysterious. I'm still not sure where the C code begins and ends,
but in any case, the call puts a return address on the stack. If it
finds your assembly function, the "ret" ought to return to the same
place, whether it was generated by Nasm or Fasm. Possible issue with
"bitness"?
If all else fails, converting Fasm source to Nasm shouldn't be too
difficult... but you really shouldn't have to!
Best,
Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
3/24/2008 11:41:15 AM
|
|
|
7 Replies
181 Views
(page loaded in 0.106 seconds)
Similiar Articles: Fast bit-reverse on an x86? - comp.dspI'm kind of rusty at FASM so I should I might as well time a couple of algorithms ... about it since then it seems to me that it's more realistic, since the problem arose ... convert Decimal to Hexa - comp.lang.asm.x86... every body I want to display Hexa numbers less 256 Here is my code, The actual problem ... ; fasm assembler - flat binary ; the following assembled binary requires aeBIOS ... How to use Inline assembly on C64x+ - comp.dsp... asm.x86 icc inline assembly - comp.lang.asm.x86 Inline Assembly, use-msasm and fasm ... Assembly Code in x64 - comp.lang.asm.x86 I'm very new to this & now facing problems with ... Using labels as immediate operands in GAS with intel syntax - comp ...... call number (sys_exit) int 0x80 #call kernel The problem is ... NASM and FASM use Intel syntax ... Immediate Operands: are prefixed ... [amd64] Mutex code - comp.lang.asm.x86Problem solved. JKB -- Si votre demande me parvient sur carte perforée, je ... mentioned above assume destination, source order like used by Intel,AMD,FASM,NASM ... icc inline assembly - comp.lang.asm.x86... B1.3:: ; Preds .B1.2 ML64 also assembles it without problem ... asm.x86 icc inline assembly - comp.lang.asm.x86 Inline Assembly, use-msasm and fasm ... HLA for AMD64 (X86-64)? - comp.lang.asm.x86... came within a couple of days of school starting (when I discovered whatever problem it ... A86/A386 · FASM · GAS · HLA · MASM · NASM · TASM · WASM · YASM programming device driver for win32 - comp.lang.asm.x86MASM/TASM, HLA, FASM, NASM, etc., all have reasonable sets of converted header ... IOCTL_DISK_GET_PARTITION_INFO and the PartitionType field problem ..... trying to ... Size of "Hello world" - comp.lang.c++... size of mono not included) haskell hello 436496 bytes (seriously) fasm ... What's the problem? -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding ... call tree - comp.lang.fortranThis is a > real threat: FASM comes in also a *.dll format, although only in > 32 ... html Fortran presents the details with different syntax but not different problems. FASM - Wikipedia, the free encyclopediaHowever, there exists a Win32 wrapper called FA, which mitigates this problem. FASM projects can be built from one source file directly into an executable file without a ... problem printing to screen in OS kernel with fasm | DaniWebalright I am trying to develop an operating system with assembly. I have written the boot loader and the beginnings of a kernel-however I am having a problem printing ... 7/6/2012 11:07:24 PM
|