I write a kernel example that active A20, go to Protected Mode (initialize a GDT and IDT). This kernel have some ISRs and work very well.
Now, I like to put the ISRs in another file and then link the files.
How I must do it? (The kernel is write for NASM)
I have benn tried but I can't do it!
Thank you very much.
How can I mix two NASM files using LD?
RE:How can I mix two NASM files using LD?
Read the nasm docs, dude!
Any functions/data you wish to access from another file must be defined as global.
Any functions/data in other files you wish to access from the current file must be defined as extern.
That's about it.
Assemble the two files, and link with ld.
What problems have you been having? What error msgs?
Jeff
PS: http://www.neuraldk.org/cgi-bin/download.pl?ndk contains source code to a kernel which uses a few different asm files (pmode.asm, for example, is accessable by C programs as well).
Any functions/data you wish to access from another file must be defined as global.
Any functions/data in other files you wish to access from the current file must be defined as extern.
That's about it.
Assemble the two files, and link with ld.
What problems have you been having? What error msgs?
Jeff
PS: http://www.neuraldk.org/cgi-bin/download.pl?ndk contains source code to a kernel which uses a few different asm files (pmode.asm, for example, is accessable by C programs as well).
RE:How can I mix two NASM files using LD?
Thank you for your soon response!
I use the keywords GLOBAL and EXTERN yet!
I give you some details about the instructions I use to compile the files
and the error messages I get:
If I complie the files with the following instructions:
nasmw -f coff inicio.asm -o inicio.o
nasmw -f coff video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
video.asm:27: error: COFF format does not support non-32-bit relocations
video.asm:85: error: COFF format does not support non-32-bit relocations
---
If I complie the files with the following instructions:
nasmw -f bin inicio.asm -o inicio.o
nasmw -f bin video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
video.asm:27: error: binary output does not suport external references
video.asm:85: error: binary output does not suport external references
(From LD)
inicio.o: file not recognized: File format not recognized
---
If I complie the files with the following instructions:
nasmw -f obj inicio.asm -o inicio.o
nasmw -f obj video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
(From LD)
inicio.o: file not recognized: File format not recognized
---
If I complie the files with the following instructions:
nasmw -f oaut inicio.asm -o inicio.o
nasmw -f oaut video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
---
In the cases where the [ORG] directive cause an error if I disable it then I get the folowing error message:
(From LD)
inicio.o: file not recognized: File format not recognized
Any idea?
Thank you again.
I use the keywords GLOBAL and EXTERN yet!
I give you some details about the instructions I use to compile the files
and the error messages I get:
If I complie the files with the following instructions:
nasmw -f coff inicio.asm -o inicio.o
nasmw -f coff video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
video.asm:27: error: COFF format does not support non-32-bit relocations
video.asm:85: error: COFF format does not support non-32-bit relocations
---
If I complie the files with the following instructions:
nasmw -f bin inicio.asm -o inicio.o
nasmw -f bin video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
video.asm:27: error: binary output does not suport external references
video.asm:85: error: binary output does not suport external references
(From LD)
inicio.o: file not recognized: File format not recognized
---
If I complie the files with the following instructions:
nasmw -f obj inicio.asm -o inicio.o
nasmw -f obj video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
(From LD)
inicio.o: file not recognized: File format not recognized
---
If I complie the files with the following instructions:
nasmw -f oaut inicio.asm -o inicio.o
nasmw -f oaut video.asm -o video.o
ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
I get the folowing error messages:
(From NASM)
inicio.asm:31: error: unrecognised directive [ORG]
---
In the cases where the [ORG] directive cause an error if I disable it then I get the folowing error message:
(From LD)
inicio.o: file not recognized: File format not recognized
Any idea?
Thank you again.
RE:How can I mix two NASM files using LD?
: nasmw -f coff inicio.asm -o inicio.o
: nasmw -f coff video.asm -o video.o
: ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
: (From NASM)
: inicio.asm:31: error: unrecognised directive [ORG]
IIRC the org directive is only applicable to certain output formats... perhaps only binary files.
: video.asm:27: error: COFF format does not support non-32-bit relocations
: video.asm:85: error: COFF format does not support non-32-bit relocations
It's true If you want to output COFF objects, your asm file must be defined "bits 32"
: nasmw -f bin inicio.asm -o inicio.o
: nasmw -f bin video.asm -o video.o
: ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
: video.asm:27: error: binary output does not suport external references
: video.asm:85: error: binary output does not suport external references
Also true The binary file format is just that; a flat, binary file. There is absolutely no formatting imposed on it, which means the binary file cannot have linking information in it (which means your global and extern are useless in binary files).
You can't (easily) link flat binaries together.
: inicio.o: file not recognized: File format not recognized
Not even ld can link flat binaries
:nasmw -f obj inicio.asm -o inicio.o
:nasmw -f obj video.asm -o video.o
:ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
:inicio.asm:31: error: unrecognised directive [ORG]
I would suggest getting rid of your org statements and using another mechanism (such as setting DS) to offset your code. Org's problematic, and unsupported by many object file formats.
: inicio.o: file not recognized: File format not recognized
ld doesn't support obf format objects.
Depending on your version of ld, it'll support coff, aout and/or elf. Since you seem to be compiling in windoze (yuck! your version of ld will probably only support coff, but perhaps also a.out... it's been a while since I've crossed the m$ line
:nasmw -f oaut inicio.asm -o inicio.o
:nasmw -f oaut video.asm -o video.o
:ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
:inicio.asm:31: error: unrecognised directive [ORG]
Again, get rid of org. What do you intend to use it for?
And, since you got not ld warnings, obviously your ld supports a.out objects as well
:In the cases where the [ORG] directive cause an error if I disable it then I :get the folowing error message:
: (From LD)
: inicio.o: file not recognized: File format not recognized
That's not cause-and-effect... even if the org would've assembled, you still would've gotten the ld error. Your ld will only link coff or a.out objects, therefore, stick to assembling those objects types, and set DS instead of using ORG and you should be alright.
Jeff
: nasmw -f coff video.asm -o video.o
: ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
: (From NASM)
: inicio.asm:31: error: unrecognised directive [ORG]
IIRC the org directive is only applicable to certain output formats... perhaps only binary files.
: video.asm:27: error: COFF format does not support non-32-bit relocations
: video.asm:85: error: COFF format does not support non-32-bit relocations
It's true If you want to output COFF objects, your asm file must be defined "bits 32"
: nasmw -f bin inicio.asm -o inicio.o
: nasmw -f bin video.asm -o video.o
: ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
: video.asm:27: error: binary output does not suport external references
: video.asm:85: error: binary output does not suport external references
Also true The binary file format is just that; a flat, binary file. There is absolutely no formatting imposed on it, which means the binary file cannot have linking information in it (which means your global and extern are useless in binary files).
You can't (easily) link flat binaries together.
: inicio.o: file not recognized: File format not recognized
Not even ld can link flat binaries
:nasmw -f obj inicio.asm -o inicio.o
:nasmw -f obj video.asm -o video.o
:ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
:inicio.asm:31: error: unrecognised directive [ORG]
I would suggest getting rid of your org statements and using another mechanism (such as setting DS) to offset your code. Org's problematic, and unsupported by many object file formats.
: inicio.o: file not recognized: File format not recognized
ld doesn't support obf format objects.
Depending on your version of ld, it'll support coff, aout and/or elf. Since you seem to be compiling in windoze (yuck! your version of ld will probably only support coff, but perhaps also a.out... it's been a while since I've crossed the m$ line
:nasmw -f oaut inicio.asm -o inicio.o
:nasmw -f oaut video.asm -o video.o
:ld -i -e inicio -Ttext 0x0500 --oformat binary -o kernel.bin inicio.o video.o
:inicio.asm:31: error: unrecognised directive [ORG]
Again, get rid of org. What do you intend to use it for?
And, since you got not ld warnings, obviously your ld supports a.out objects as well
:In the cases where the [ORG] directive cause an error if I disable it then I :get the folowing error message:
: (From LD)
: inicio.o: file not recognized: File format not recognized
That's not cause-and-effect... even if the org would've assembled, you still would've gotten the ld error. Your ld will only link coff or a.out objects, therefore, stick to assembling those objects types, and set DS instead of using ORG and you should be alright.
Jeff