x86 asm bios interrupts in C

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post 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.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post 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?
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post by pvc »

You use -fno-stack-protector and -fno-pic for gcc.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

ok.will see if it works
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

not crashing, and can work fine. now the last step; see if i can call a bios interrupt
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

ld cant recognize vm86int. actually hating LD
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post by pvc »

Post your build script. I would help a lot.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post 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
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post 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.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post 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
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post 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.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

ok.. but i can't link with LD it says the undefined reference and multiple definitions described above
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: x86 asm bios interrupts in C

Post 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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

no, i dont have github or other types of repo
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: x86 asm bios interrupts in C

Post 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.
Attachments
vm86.tar.gz
fixed version of previous vm86.tar.gz
(8.94 KiB) Downloaded 116 times
alberinfo_vm86.tar.gz
(8.67 KiB) Downloaded 122 times
Post Reply