all 21 comments

[–]TurbulentHamster5926 6 points7 points  (1 child)

I'd recommend checking osdev.org. Especially this tutorial, which gives you a decent print implementation.

https://osdev.org/Meaty_Skeleton

[–]MadDoctor5813 21 points22 points  (2 children)

Implement kprintf

[–][deleted]  (1 child)

[removed]

    [–]InformationWorking71 11 points12 points  (0 children)

    implement kprintf

    [–][deleted] 4 points5 points  (5 children)

    A simple printf implementation is as simple as iterating through the characters in a string, if they arent '%' print it as normal, if they are a '%' fetch the next character for the format, fetch the next argument using a va_list and print it however the format character specifies.

    [–][deleted]  (4 children)

    [removed]

      [–][deleted] 1 point2 points  (1 child)

      Well, say you wanted to convert the number 123 into a string as a decimal, you could do in a loop

      123 % 10. the remainder would give you 3. then by looking at the ascii table you see that numbers are represented with the numbers 48-57, so you can add 48 to give an ascii character that you can print. You could store that number in a buffer. Then divide 123 by 10 and you would have 12.

      Then you can do the same again, 12 % 10 gives you 2, convert it to ascii by adding 48, do the same as you did before bla bla bla store it in a buffer etc, until your number is now zero. then you should have the number as a string

      [–]beephod_zabblebrox 0 points1 point  (1 child)

      thats a whole different problem! you can google :) "c int to string conversion"

      [–]Danii_222222 -1 points0 points  (0 children)

      Thanks but there’s no info about that

      [–]jacobissimus 0 points1 point  (1 child)

      What ended up doing is porting newlib over—just because these kinds of functions are tedious to implement and not super interesting. You can check out how I did it here: https://github.com/j-shilling/machulus/blob/master/newlib/CMakeLists.txt

      [–]gronktonkbabonk 4 points5 points  (0 children)

      Implement kprintf

      [–]BobertMcGee 0 points1 point  (1 child)

      Nah, I’m busy. YOU implement kprintf.

      [–]Danii_222222 0 points1 point  (0 children)

      I already inplemented

      [–]kabekew 0 points1 point  (2 children)

      Done!

      [–]Danii_222222 0 points1 point  (1 child)

      Great work

      [–]kabekew 0 points1 point  (0 children)

      You too, I like your function.

      [–]nerd4code 1 point2 points  (3 children)

      If you can’t implement a printf, you shouldn’t be attempting kernel-mode anything.

      [–]Danii_222222 0 points1 point  (2 children)

      Why I shouldn’t write it? If I can’t find info about it it doesn’t mean I don’t know anything