C code rebooting for no reason
Re: C code rebooting for no reason
You can't get GRUB to work, so you write your own bootloader.
You can't parse your ELF file, so you want to re-write all in assembly or write a C interpreter.
You keep running into problems that would take x effort to solve and you instead avoid the problem with solutions that take 50x effort
You can't parse your ELF file, so you want to re-write all in assembly or write a C interpreter.
You keep running into problems that would take x effort to solve and you instead avoid the problem with solutions that take 50x effort
-
- Posts: 8
- Joined: Tue Oct 25, 2016 1:57 am
- Libera.chat IRC: issamabd
- Location: Tunisia
- Contact:
Re: C code rebooting for no reason
Hi,
Possible causes of the Triple-Fault (infinite hardware reboot) that you have gotten:
1. You have loaded the GDTR with a non physical address, so that when you switch to protected mode the CPU will not
find the GDT and a stupid TF will be triggered ! Following is how I used to load GDTR in my bootloader (using GNU assembler):
NOTE: Here my bootloader program was moved from physical addresses 0x7c00 to 0x90000
2. You have not purged the instruction queue of the processor before switching to protected mode, so that the processor continue executing 16-bit
code in 32-bit mode. You can empty the queue by executing a long JMP from a 16-bit code segment to a 32-bit segment. And here you have to use
the 0x66 prefix. Somewaht like this (GNU assembler syntax):
So, please check your bootloader for those two points!
Advise: Use Qemu to test your OS instead of rebooting you PC several times!
If you want, you can study this example that I have written: https://github.com/issamabd/timeros
Possible causes of the Triple-Fault (infinite hardware reboot) that you have gotten:
1. You have loaded the GDTR with a non physical address, so that when you switch to protected mode the CPU will not
find the GDT and a stupid TF will be triggered ! Following is how I used to load GDTR in my bootloader (using GNU assembler):
Code: Select all
lgdt gdt_ptr
...
...
gdt_ptr: .word . - gdt - 1 # Limit = (8*3) - 1
.word gdt,0x9 # 0x9xxxx: a physical address!
2. You have not purged the instruction queue of the processor before switching to protected mode, so that the processor continue executing 16-bit
code in 32-bit mode. You can empty the queue by executing a long JMP from a 16-bit code segment to a 32-bit segment. And here you have to use
the 0x66 prefix. Somewaht like this (GNU assembler syntax):
Code: Select all
.byte 0x66,0xea # prefix (0x66) + ljmp opcode (0xea)
.word ok_pm,0x9 # offset: 32-bit size
.word 0x8 # CS = 0x8: GDT[1]
.code32
ok_pm:
ljmp $0x8, $0x0 # Long JAMP to kernel head (CS:EIP)
Advise: Use Qemu to test your OS instead of rebooting you PC several times!
If you want, you can study this example that I have written: https://github.com/issamabd/timeros
"try to learn something about everything and everything about something"
My personal website: http://issamabd.com
My personal website: http://issamabd.com
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: C code rebooting for no reason
QEMU refuses to boot any NASM media and BOCHS too, for some reason.issamabd wrote:Hi,
Possible causes of the Triple-Fault (infinite hardware reboot) that you have gotten:
1. You have loaded the GDTR with a non physical address, so that when you switch to protected mode the CPU will not
find the GDT and a stupid TF will be triggered ! Following is how I used to load GDTR in my bootloader (using GNU assembler):
NOTE: Here my bootloader program was moved from physical addresses 0x7c00 to 0x90000Code: Select all
lgdt gdt_ptr ... ... gdt_ptr: .word . - gdt - 1 # Limit = (8*3) - 1 .word gdt,0x9 # 0x9xxxx: a physical address!
2. You have not purged the instruction queue of the processor before switching to protected mode, so that the processor continue executing 16-bit
code in 32-bit mode. You can empty the queue by executing a long JMP from a 16-bit code segment to a 32-bit segment. And here you have to use
the 0x66 prefix. Somewaht like this (GNU assembler syntax):
So, please check your bootloader for those two points!Code: Select all
.byte 0x66,0xea # prefix (0x66) + ljmp opcode (0xea) .word ok_pm,0x9 # offset: 32-bit size .word 0x8 # CS = 0x8: GDT[1] .code32 ok_pm: ljmp $0x8, $0x0 # Long JAMP to kernel head (CS:EIP)
Advise: Use Qemu to test your OS instead of rebooting you PC several times!
If you want, you can study this example that I have written: https://github.com/issamabd/timeros
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
-
- Posts: 8
- Joined: Tue Oct 25, 2016 1:57 am
- Libera.chat IRC: issamabd
- Location: Tunisia
- Contact:
Re: C code rebooting for no reason
What you mean by "NASM media" ?
"try to learn something about everything and everything about something"
My personal website: http://issamabd.com
My personal website: http://issamabd.com
- Mikumiku747
- Member
- Posts: 64
- Joined: Thu Apr 16, 2015 7:37 am
Re: C code rebooting for no reason
That's likely because they're not bootable, or you're passing the incorrect options to qemu or using bochs with a bad config.NunoLava1998 wrote:QEMU refuses to boot any NASM media and BOCHS too, for some reason.
Try just running QEMU or bochs with a known working CD image (eg. a live CD or somebody else's kernel or whatever) and make sure that works first. You'll need to use an emulator eventually, there's no way around it, so it's better to start fixing your problems sooner than later.
At the very least, you can check for certain whether or not your C code is faulty by compiling the kernel and using qemu's -kernel option to run it. If it works, then you know something is definitely wrong with the bootloader. If not, well then, you know that the kernel is faulty, and you have one more thing to worry about.
As others have mentioned, it seems like you're escaping minor problems by creating major ones, just try to get the bare bones working with GRUB and an emulator like everyone else, you'll thank yourself later. Once you've mastered the basics, then you can start to become more independent.
I believe he just means something he compiled with NASM, which means it's probably not bootable for a number of reasons.issammabd wrote:What you mean by "NASM media" ?
- Mikumiku747
Re: C code rebooting for no reason
Nuno,
wouldn't be great idea to show us your bootloader code so we could speed up helping?
wouldn't be great idea to show us your bootloader code so we could speed up helping?
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: C code rebooting for no reason
I've deleted it already (only can get it with a decompiler since i still have the img file with the bootloader).Lukand wrote:Nuno,
wouldn't be great idea to show us your bootloader code so we could speed up helping?
I have made a new kernel that loads a file using my WaveFS file system in 16 bits real mode. I'll now implement a change to run in V8086 when i fix the 2 errors (C:\Users\#####\Desktop\WaveSystem\WaveSystem>nasm kernel.asm -o kernel.bin
kernel.asm:75: error: operand 1: expression is not simple or relocatable
kernel.asm:76: error: comma or end of line expected
)
Booted it. Suprisingly, ELF is not needed to be compiled. Here i go, correct!
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
Re: C code rebooting for no reason
Did you create an ELF file by hand or something?NunoLava1998 wrote:Booted it. Suprisingly, ELF is not needed to be compiled. Here i go, correct!
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
Compiler Development Forum
-
- Posts: 8
- Joined: Tue Oct 25, 2016 1:57 am
- Libera.chat IRC: issamabd
- Location: Tunisia
- Contact:
Re: C code rebooting for no reason
There is no ELF (Executable Linkable Format) files here ! Just a raw binary image, man !zenzizenzicube wrote:Did you create an ELF file by hand or something?NunoLava1998 wrote:Booted it. Suprisingly, ELF is not needed to be compiled. Here i go, correct!
"try to learn something about everything and everything about something"
My personal website: http://issamabd.com
My personal website: http://issamabd.com
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: C code rebooting for no reason
i meant ELF doesn't need to be translated into binary, it works fine.zenzizenzicube wrote:Did you create an ELF file by hand or something?NunoLava1998 wrote:Booted it. Suprisingly, ELF is not needed to be compiled. Here i go, correct!
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: C code rebooting for no reason
Hi,
Furthermore, unless your ELF binary is compiled as position-independent code, jumps and calls will be mangled and won't point to the correct addresses (since code will not start at 0x00007E00, but somewhere further, possibly just after the ELF header, or after data, or something).
Regards,
glauxosdever
So the CPU executes the ELF header? Unexpected things will happen this way.NunoLava1998 wrote:i meant ELF doesn't need to be translated into binary, it works fine.zenzizenzicube wrote:Did you create an ELF file by hand or something?NunoLava1998 wrote:Booted it. Suprisingly, ELF is not needed to be compiled. Here i go, correct!
Furthermore, unless your ELF binary is compiled as position-independent code, jumps and calls will be mangled and won't point to the correct addresses (since code will not start at 0x00007E00, but somewhere further, possibly just after the ELF header, or after data, or something).
Regards,
glauxosdever
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: C code rebooting for no reason
I think you never heard ofglauxosdever wrote:Hi,
So the CPU executes the ELF header? Unexpected things will happen this way.
Furthermore, unless your ELF binary is compiled as position-independent code, jumps and calls will be mangled and won't point to the correct addresses (since code will not start at 0x00007E00, but somewhere further, possibly just after the ELF header, or after data, or something).
Regards,
glauxosdever
Code: Select all
qemu-system-i386 -kernel myos.bin
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
Re: C code rebooting for no reason
QEMU is able to parse ELF executables. Now what?Code: Select all
qemu-system-i386 -kernel myos.bin
Don't pretend to be more knowledgable than someone else, especially when you're not.I think you never heard
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
- Member
- Posts: 273
- Joined: Sun Oct 09, 2016 4:38 am
- Libera.chat IRC: NunoLava1998
Re: C code rebooting for no reason
Tested on real hardware, same result.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.
https://github.com/NunoLava1998/DixiumOS
https://github.com/NunoLava1998/DixiumOS
-
- Posts: 10
- Joined: Tue Oct 25, 2016 6:44 pm
Re: C code rebooting for no reason
So firstly use QEMU as this will give you access to some debugging information, that you can use to identify what the problem is. Use either the qemu -d , or the QEMU monitor to checkout what problems you are facing ( http://wiki.qemu.org/download/qemu-doc.html for more information on how to use it correctly).
Secondly, can you provide the qemu log file so we can tell you exactly what your problem is (I will not detail how to fix it though). Also provide your boot loader, as 0x07E00 address looks suspicious.
From what you have posted it looks like a problem with your interrupts, it seems you haven't disabled interrupts before you jump into protected mode. This needs to be done as the default interrupts that the BIOS provides are only 16bit, and will not work in 32 bit mode.
Secondly, can you provide the qemu log file so we can tell you exactly what your problem is (I will not detail how to fix it though). Also provide your boot loader, as 0x07E00 address looks suspicious.
From what you have posted it looks like a problem with your interrupts, it seems you haven't disabled interrupts before you jump into protected mode. This needs to be done as the default interrupts that the BIOS provides are only 16bit, and will not work in 32 bit mode.