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 »

You have to initialize GDT and TSS exactly as in my boot.asm because the rest of the code expects it to be exactly as it is. Otherwhise Triple fault of doom :) It was not supposed to be copypaste solution. It is just a demo.
And about that multiple definitions. You have kmain function somewhere in your code and you try to link in another one from my code. And you can't have two symbols with the same name in the same program.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

only for trying i've copied your boot.asm to my boot.asm so bootloader isn't the problem. i don't have a reference to kmain, 'cause i don't have any functions with that name excepting yours
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

ok. i know why it fails. i don't know why, but if i try to call asm functions from c, the OS crashes
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 »

Keep trying. Failing over and over again is integral part of learning process. But one time it will all come together :)
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

i'm trying, but with my dad hurrying me, it's a little crazy XD
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

ok, now it still crashig but dont make any compiling error. thats an advance. i've copied the main.c to my kernel.c
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 am going to sleep for today but here is a little tip for you (maybe you know it already).

Code: Select all

asm("cli\nhlt":: "a"(0xB16B00B2));
and ctrl+alt+2 then 'info registers' command in QEMU will let you know if your code reached the spot you put that snippet in. Of course you can use any easily recognizable pattern. It should show up in EAX register and halt the system. (Won't work that way for SMP)
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

i have a problem. LD makes a undefined reference to idtInitialize() when i call it also to vm86Initialize(). the proble is that if i quit the function and i compile the code. it still making error until for some reason the error dissapears. i've included idt.h and vm86.h so it shouldn't be needed to link them with the kernel(i think). So i don't know, but i'll keep trying, can anyone help me?
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 »

.h files are just declarations. You have to compile in .c files.
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 »

alberinfo wrote:i'm trying, but with my dad hurrying me, it's a little crazy XD
I'm puzzled by this comment. Do you mean you had to go do something else when you posted this, or was this regarding either your access to the computer (e.g., you are sharing the PC, and you only get to use it part of the time), or something to do with the project itself?

I have a sense that there is something we're missing about this that may be relevant.

What is your testing environment, that is to say, are you running the tests in an emulator/simulator such as QEMU, Bochs, or VirtualBox, or are you booting from live hardware?

Some more details about your development host environment might help as well. Are you developing under Windows, Mac OS X, Linux, FreeBSD, or something else? Have you set up a GCC Cross Compiler, and if not, would you be able to do so? Is this your personal system, or are you sharing it with someone (a possibility I mentioned above)? Are you using the same system for both development and testing?
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 »

it was something to help my dad, nothing special. the computer is only mine. i'm using linux in Virtual Box(my hard drive isn't enough for dual booting). it's the same for compiling and testing, but sometimes i test it in a real machine. i'm using gcc for compile it
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

hi,
the ld problem continues.i've included idt.c and vm86.c instead idt.h and vm86.h. but now in idt.c ld does not found asm isr, and gives me an undefined reference to each ISR(the total are 255). could be that they arent declared with global?. also in isrs.asm i didnt found the function 'isr' so, it can also be that. any idea?

Thanks!
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 »

isr0 to isr255 are defined in isrs.asm. They are defined using ISR_NOERRCODE and ISR_ERRCODE macros. You have to compile it using YASM (NASM should work too) and link in .o file it makes.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

good. then i'll try
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: x86 asm bios interrupts in C

Post by alberinfo »

i'm almost to do it. only ld(again :cry: ) gives me: undefined reference to '__stack_chk_fail', it comes out with -shared and -fno-stack-protector, but with it, the os crashes.why it comes?

PD: it comes from the function 'vm86EnterHandlerCallback'
Post Reply