Printing ticks doesn't work

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.
Post Reply
jpacanowski
Posts: 10
Joined: Sun May 29, 2016 11:23 am
Location: Poland
Contact:

Printing ticks doesn't work

Post by jpacanowski »

Hello,

https://github.com/jpacanowski/GekonOS/ ... imer.c#L12

I want to print out the ticks on the screen and I don't know why this kprintf() function doesn't work...
It looks like something crashed.

It's been 2 weeks I've been trying to figure it out...

Could you help me, please?

Best regards
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: Printing ticks doesn't work

Post by Octocontrabass »

It looks like you're following James Molloy's tutorial, which is known to have bugs. Here's a list of the bugs we know about. (This list may not be complete.)

In particular, take a look at the section titled "Interrupt handlers corrupt interrupted state". That's usually the first one people run into.
jpacanowski
Posts: 10
Joined: Sun May 29, 2016 11:23 am
Location: Poland
Contact:

Re: Printing ticks doesn't work

Post by jpacanowski »

Thanks for the reply.

I modified the interrupt.asm file according to the "James Molloy's Tutorial Known Bugs", but still the same... ;(

The rest of my code looks like it's OK.. Especially when I compare my code to this one:
https://github.com/cfenollosa/os-tutorial

Somebody, help me please...

I want to start further OS development, but I'm stuck with it...
It's been 2 weeks... ;(
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: Printing ticks doesn't work

Post by thomtl »

Your call to

Code: Select all

void register_interrupt_handler(u8 n, isr_t handler)
in timer.c shouln't do &timer_callback but just timer_callback since functions are all already pointers, and timer_callback should have registers_t in its arguments. Also you should do 23-fixes from https://github.com/cfenollosa/os-tutorial
jpacanowski
Posts: 10
Joined: Sun May 29, 2016 11:23 am
Location: Poland
Contact:

Re: Printing ticks doesn't work

Post by jpacanowski »

I have done all the fixes according to the 23-fixes and your advice, but it still doesn't work...
I fixed interrupt.asm, created mem* functions, changed registers_t r into registers_t *t, and so on...
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: Printing ticks doesn't work

Post by thomtl »

I've just cloned your repo and it seems to be working for me, so the one thing I could think about is compile eviroment changes. You should compile with a cross-compiler GCC_Cross-Compiler

edit: Here's a link to my compiled ISO https://mega.nz/#!lLhlFKKD!j_dt023QdXBT ... pKT93b02YI
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Printing ticks doesn't work

Post by MichaelPetch »

thomtl is making a good suggesting about making a cross compiler rather than use you the native compiler on your OS. The problem is in how you are building and linking your code. The issue is that your native compiler is defaulting to position independent code and position independent executable code generation. You are hiding the problem(not fixing it) by adding --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_ to your linking command. Remove this from the linking step, and add the `-fno-PIE` option instead. You will also have to compile the .c files without position independent code as well so you'll need to add the `-fno-PIC` flag to the C flags you are using. The changedlines in your build file could look like:

Code: Select all

# default variables
CFLAGS="-m32 -c -g -O2 -W -Wall -Wextra -Werror -fno-PIC "\
"-ffreestanding -std=gnu99 -fno-builtin -Ikernel/include -Ilibc/include"

CFLAGS_LIBC="-m32 -c -g -O2 -W -Wall -Wextra -Werror -fno-PIC "\
"-ffreestanding -std=gnu99 -fno-builtin -Ikernel/include -Ilibc/include"
then:

Code: Select all

ld -g -m elf_i386 -T kernel/link.ld -no-PIE -o kernel.bin kentry.o kernel.o video.o gdt.o idt.o isr.o timer.o x86.o interrupt.o vbe.o gui.o libc.a
I am curious where you might have learned to use --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_? Someone else in the past few weeks had the same problem in a question on this forum.
jpacanowski
Posts: 10
Joined: Sun May 29, 2016 11:23 am
Location: Poland
Contact:

Re: Printing ticks doesn't work

Post by jpacanowski »

Thanks! Building own cross-compiler really helped. Now everything is working well...

But compiling big projects (like GCC) is what I really hate doing by myself... Why? Lots of code and lots of warning when compiling... My heart is beating faster when I type "make all". That's why I stayed away from compiling my own cross-compiler... It all happened for the first time when I wanted to compile the Linux kernel from sources... ;)

I will also do what MichaelPetch wrote by fixing how I am linking the code by adding --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_
Where did I find that? Well, on Stack overflow ;)

Thank you, guys...
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Printing ticks doesn't work

Post by MichaelPetch »

In the context of making shared libraries it can make sense, but not here. Can you post a link to the StackOverflow post?
jpacanowski
Posts: 10
Joined: Sun May 29, 2016 11:23 am
Location: Poland
Contact:

Re: Printing ticks doesn't work

Post by jpacanowski »

I'm sorry, it was not Stack Overflow...
https://github.com/cfenollosa/os-tutorial/issues/16
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Printing ticks doesn't work

Post by MichaelPetch »

Thanks, I had a suspicion it was that. Last week I posted a warning there not to use it in that way.
Post Reply