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.
osdf_1
Posts: 20 Joined: Sun Nov 25, 2007 7:55 pm
Post
by osdf_1 » Mon Jul 28, 2008 3:46 am
I set up my IDT and ISRs with C and ASM. When I call:
the exception message is displayed and everything seems to work perfectly. But, should the exception be thrown if I put:
in my main function? Because it isn't.
Thanks
c0x
Member
Posts: 26 Joined: Sun Apr 20, 2008 2:16 am
Post
by c0x » Mon Jul 28, 2008 3:56 am
You should check the disassembled output of your binary because if I'm right, GCC will "optimize" this stuff out..
To really trigger a division by zero exception you should do the division with variables instead of constants
Last edited by
c0x on Mon Jul 28, 2008 4:00 am, edited 1 time in total.
octa
Member
Posts: 50 Joined: Sat Jun 28, 2008 9:15 am
Post
by octa » Mon Jul 28, 2008 3:57 am
is there a triple fault !!!!!
AJ
Member
Posts: 2646 Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:
Post
by AJ » Mon Jul 28, 2008 3:59 am
Hi,
If you do not use the variable x, this line will be optimised out of your code. Memory writes, however, cannot be optimised out, so:
..or similar should give you the exception still.
Cheers,
Adam
[edit]too slow
[/edit]
osdf_1
Posts: 20 Joined: Sun Nov 25, 2007 7:55 pm
Post
by osdf_1 » Mon Jul 28, 2008 4:08 am
Well it didn't give me an exception.. How do I check the disassembled output?
JamesM
Member
Posts: 2935 Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:
Post
by JamesM » Mon Jul 28, 2008 4:13 am
AJ wrote: Hi,
If you do not use the variable x, this line will be optimised out of your code. Memory writes, however, cannot be optimised out, so:
..or similar should give you the exception still.
Cheers,
Adam
[edit]too slow
[/edit]
However, it can optimise out writes to stack-local variables. 'x' is never used except in the write, so both lines can be optimised out.
A global variable however, could be referenced from anywhere and so the compiler should never optimise away a write:
Code: Select all
int x;
int myfunc()
{
x = 3 / 0;
}
This works for my kernel, for testing purposes!
AJ
Member
Posts: 2646 Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:
Post
by AJ » Mon Jul 28, 2008 4:16 am
Whoops - sorry. That's what comes of trying to write an example (even if it's that simple) off the top of your head without testing
. Apologies to OP.
Cheers,
Adam
Korona
Member
Posts: 1000 Joined: Thu May 17, 2007 1:27 pm
Contact:
Post
by Korona » Mon Jul 28, 2008 4:17 am
AJ wrote: If you do not use the variable x, this line will be optimised out of your code. Memory writes, however, cannot be optimised out, so:
Actually, Memory writes can be optimized if you don't use the volatile keyword:
Code: Select all
volatile int x[10];
x[0] = 1;
x[1] = 0;
x[2] = x[0] / x[1];
managarm : Microkernel-based OS capable of running a Wayland desktop (Discord:
https://discord.gg/7WB6Ur3 ). My OS-dev projects: [
mlibc : Portable C library for managarm, qword, Linux, Sigma, ...] [
LAI : AML interpreter] [
xbstrap : Build system for OS distributions].
osdf_1
Posts: 20 Joined: Sun Nov 25, 2007 7:55 pm
Post
by osdf_1 » Mon Jul 28, 2008 4:27 am
Wow, finally I got it to work using Korona's example, thanks to everyone.
xlq
Member
Posts: 36 Joined: Mon Dec 11, 2006 7:51 am
Post
by xlq » Thu Jul 31, 2008 8:09 am
Regardless of what context you use (5 / 1) in, (5 / 1) is still a constant and can still be calculated at compile time. I'm surprised that (5 / 0) didn't produce a compiler error, though.
AJ
Member
Posts: 2646 Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:
Post
by AJ » Thu Jul 31, 2008 8:19 am
Hi,
I've just checked my cross-compiled GCC and it just gives a warning (unless, of course, -Werror is specified, which it always should be!).
Cheers,
Adam