Page 4 of 6

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 12:21 am
by pvc
-shared is not needed. -fno-stack-protector is needed for every .c file. You may have something not recompiled with new flags. You also need -fno-pic flag for .c files. PIC code will make some weird crashes when you implement paging and may trash EBX register in some cases. BTW. just look at 'make clean all' output of non modified demo. It shows you exactly what it's doing.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 6:34 am
by alberinfo
when i try to pass -fno-stack-protector flag in LD, it says that it can be done without -shared flag.could be that it was in gcc and not in ld?

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 6:47 am
by pvc
You use -fno-stack-protector and -fno-pic for gcc.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 6:49 am
by alberinfo
ok.will see if it works

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 6:53 am
by alberinfo
not crashing, and can work fine. now the last step; see if i can call a bios interrupt

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 7:01 am
by alberinfo
ld cant recognize vm86int. actually hating LD

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 7:06 am
by pvc
Post your build script. I would help a lot.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 7:12 am
by alberinfo
its a .sh file.

Code: Select all

nasm -f elf32 bootloader.asm -o bootloader.bin
nasm -f elf32 bootloader.asm -o bootloader.o
gcc -m32 -fno-stack-protector -fno-pic -c kernel.c -o kc.o
cd include
cd VM86
nasm -f elf32 isrs.asm -o isrs.o
nasm -f elf32 cpu.asm -o cpu.o
nasm -f elf32 vm86asm.asm -o vm86asm.o
gcc -m32 -c ints.c -o ints.o
gcc -m32 -c vm86.c -o vm86.o ; don't used 'cause ld gives a lot of undefined references
cp isrs.o (the kernel dir)
cp cpu.o (the kernel dir)
cp ints.o (the kernel dir)
cp vm86asm.o (the kernel dir)
cd ..
cd ..
ld -m elf_i386 -T link.ld -o bootloader.bin bootloader.o kc.o isrs.o cpu.o ints.o vm86asm.o
cp bootloader.bin OS/boot/
grub-mkrescue -o OS.iso OS/
qemu-system-x86_64 -hda OS.iso

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 7:30 am
by pvc
you're missing gcc -m32 -c idt.c -o idt.o and you're not linking idt.o and vm86.o. Also first line is not needed because you overwrite bootloader.bin with ld command anyway. You should also use my boot.asm instead since it sets up TSS which is needed tof V86 mode to work.

I would try this:

Code: Select all

nasm -f elf32 boot.asm -o boot.o
gcc -m32 -fno-stack-protector -fno-pic -c kernel.c -o kc.o
cd include
cd VM86
nasm -f elf32 isrs.asm -o isrs.o
nasm -f elf32 cpu.asm -o cpu.o
nasm -f elf32 vm86asm.asm -o vm86asm.o
gcc -m32 -fno-stack-protector -fno-pic -c ints.c -o ints.o
gcc -m32 -fno-stack-protector -fno-pic -c idt.c -o idt.o
gcc -m32 -fno-stack-protector -fno-pic -c vm86.c -o vm86.o ; you have to use it
cp boot.o (the kernel dir)
cp ints.o (the kernel dir)
cp idt.o (the kernel dir)
cp cpu.o (the kernel dir)
cp ints.o (the kernel dir)
cp vm86.o (the kernel dir)
cp vm86asm.o (the kernel dir)
cd ..
cd ..
ld -m elf_i386 -T link.ld -o bootloader.bin boot.o kc.o isrs.o idt.o cpu.o ints.o vm86.o vm86asm.o
cp bootloader.bin OS/boot/
grub-mkrescue -o OS.iso OS/
qemu-system-x86_64 -hda OS.iso
If you really want to use your bootloader.asm you have to set up GDT and TSS just as I do in boot.asm.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 7:35 am
by alberinfo
multiple definitions of 'vm86Initialize', 'vm86Enter', 'vm86Int', and undefined reference to 'vm86Int' --> in LD. how do i fix it?i dont know where is the multiple definition!!

also your boot.asm is the same of my bootloader.asm

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 8:16 am
by pvc
I've recreated what I think is your directory structure and compiled it just fine. BIOS interrupt gets called ok but there is a problem with exiting. When I run it with -kernel option for QEMU it works just fine but when I try using GRUB ISO then there is still something wrong with my code. Let me fix it and I'll let you know later today.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 8:18 am
by alberinfo
ok.. but i can't link with LD it says the undefined reference and multiple definitions described above

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 8:42 am
by Schol-R-LEA
I know I tend to harp on this a lot, but: do you have an offsite repo hosted on someplace such as GitHub, Gitlab, or CloudForge? Aside from everything else you would get from one, it would make it a lot easier for us to look at your current code, and review what you've done over time, so you wouldn't need to paste large pieces of your code into your posts here - you can just put a link to the repo in your user signature.

You'd still probably want to paste some code here, to make things easier when you are pointing out a specific piece of code, but overall, having us view it from a repo would save us and you a lot of trouble.

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 8:55 am
by alberinfo
no, i dont have github or other types of repo

Re: x86 asm bios interrupts in C

Posted: Sat Sep 15, 2018 9:18 am
by pvc
Ok, I've fixed the problem with exiting from V86 mode back to protected mode. I forgot to initialize segment registers in boot.asm. And QEMU internal loader and GRUB do things a little bit different when it comes to GDT.

I've made a version for you that works with your build script. I've tried to guess your directory structure based on the script, so it may be wrong.
I've also uploaded fixed version of my previous archive.