How Linux Kernel Prints Text on Screen

Поділитися
Вставка
  • Опубліковано 22 сер 2024
  • In this video we will dive into a simple call to the printf function and see what happens in the kernel and how it gets eventually printed on screen.
    For more information about setting up an environment for kernel dev, checkout the welcome link on my channel.
    Docs used in video:
    - docs.kernel.or...
    - wiki.osdev.org...

КОМЕНТАРІ • 218

  • @nirlichtman
    @nirlichtman  Місяць тому +100

    - The display mechanism the kernel chooses depends on the setup, this is what it chose in the case of standard QEMU config & x86_64, but on other machines it may use something else for example a framebuffer. VGA mode 3 is a common x86/x64 choice, especially for older machines, but modern ones may not support it at all.
    - The reason it printed 3 "H" letters and not "Hel" is that I recycled the same command that I used to modify the first letter to red, and only changed the color so it brought over the same first letter each time.

    • @user-il3uq6cx4e
      @user-il3uq6cx4e Місяць тому

      @@nirlichtman Pls Make Linux OS But With Debian-Based

    • @MrMassaraksh
      @MrMassaraksh Місяць тому +1

      Thank you for explaining why H is printed 3 times, because it can be understood as you run over the same char, but in reality you just moved further in “array of letters”.

  • @FernandoMumbach
    @FernandoMumbach Місяць тому +466

    This video is a tutorial on:
    - How printf works in the kernel
    - How to the debug the kernel with GDB
    - An intro into how to to use GDB
    - A guide on how to look up kernel documentation
    And several things more. Condensed in 12 minutes. This is perfect!! I've never seen a video as good as this one explaining anything!

    • @Henrix1998
      @Henrix1998 Місяць тому +6

      I have used GDB for about a year now every week and learned new commands

    • @thescroogemcduck
      @thescroogemcduck Місяць тому +5

      This is more than an intro on how to use GDB lol, I thought I was decent with it but this is next level.

  • @ericlindell3777
    @ericlindell3777 Місяць тому +248

    ”we’re gonna have to dive in a little bit to the assembly”. What a madlad ❤

  • @Scoopta
    @Scoopta Місяць тому +221

    You're making one of the nerdiest linux videos I've seen on windows using MS edge...saying I'm confused is an understatement

    • @marsovac
      @marsovac Місяць тому +31

      What you use doesn't matter. It is how well you use it...
      On Windows at least he doesn't have to deal with Wayland issues :D
      What I was wondering the most is why didn't he turn off the search box in the taskbar :P

    • @Scoopta
      @Scoopta Місяць тому +20

      @@marsovac ...as someone who runs wayland without Xwayland or X11 compatibility at all...and as a developer of reasonably widely used wayland software...I take issue to that remark lol =D...that aside the search box is terrible.

    • @ddthegr8
      @ddthegr8 Місяць тому +16

      He's under three VMs

    • @LordDoucheBags
      @LordDoucheBags Місяць тому

      @@marsovac wayland on newest nvidia drivers works well right now. Fedora btw

    • @MrEdrftgyuji
      @MrEdrftgyuji Місяць тому +1

      A lot of corporate environments demand you use Edge.

  • @namanchhabra4136
    @namanchhabra4136 Місяць тому +105

    I always wanted to know kernel that deep 🙂

    • @MrLarossi
      @MrLarossi Місяць тому +2

      we all like it deeper

  • @matthias7534
    @matthias7534 Місяць тому +27

    no unnecessary talking, straight to the point, extremely well explained, this is why I pay for internet, thank you brother

  • @katiagalkina4607
    @katiagalkina4607 Місяць тому +35

    The rabbit hole is much deeper than I was thinking!

  • @krnick0000
    @krnick0000 Місяць тому +4

    The magic behind a standard library function-and the POSIX system calls-is what every CS student would have wondered about for once. Thank you for making this video. It brought back memories of being curious about how a computer works.

  • @CornThatLefty
    @CornThatLefty Місяць тому +9

    This series of videos is awesome. Just explains and explores a low-level topic quickly and without any fluff.

  • @nickdaria
    @nickdaria Місяць тому +9

    Excellent video as always. Love seeing well-made low level computing content that does deep dives into while keeping it just dense enough to watch in your free time.
    I feel like many videos on this topic are always either way too short/simplified or way too long and drawn out. You always hit it on the head.

  • @ismbks
    @ismbks Місяць тому +32

    this feels like i'm watching paid content for free

  • @timeimp
    @timeimp Місяць тому +5

    This is like a whole subject at uni in less than 15 minutes. Subscribed!

  • @CookieGod24
    @CookieGod24 Місяць тому +8

    I don’t know why but the way you say ‘config’ sounds satisfying

  • @KovalenkoYT
    @KovalenkoYT Місяць тому +2

    I just discovered this channel today, and with two videos that I have seen I feel that in half an hour I have learned more than what I learned in many classes at the university. Subscribed!

  • @GrittyMaholmes
    @GrittyMaholmes Місяць тому +3

    I love the confidence in your voice , i wana be this confidence when coding .

  • @patrickprucha5522
    @patrickprucha5522 Місяць тому +8

    I like the way you explain things. I also noticed that you are very good and very at ease with programming languages. I will look into more of your videos / media when i jump into c programming. thanks again

  • @piano_arts_2007
    @piano_arts_2007 3 дні тому

    I didn't know untill now that there's a lot of stuff under the hood just to print something on the screen but with all of this it really makes sense on why is this.
    Really cool video btw.

  • @stevep5759
    @stevep5759 Місяць тому +2

    Really fast paced and right to the point. New sub 🎉

  • @OrangeDied
    @OrangeDied Місяць тому +86

    kys_write?? how rude...

    • @nyvyme
      @nyvyme Місяць тому +3

      oh

    • @nyvyme
      @nyvyme Місяць тому +7

      oh "kms" exist

    • @jackkendall6420
      @jackkendall6420 Місяць тому +49

      You should write text to the screen NOW!

    • @adama7752
      @adama7752 Місяць тому +7

      I agree, the side effects of this function are wild.

    • @kipchickensout
      @kipchickensout Місяць тому +1

      ​@@jackkendall6420 xD

  • @shahriarmorabi8945
    @shahriarmorabi8945 12 днів тому

    i have longed for this exact video for years. Thank you.

  • @r4co351
    @r4co351 12 годин тому

    Just found out about your channel and I'm already hooked with it!
    שמח לראות שאתה מישראל 😊.
    Keep up the great work!

  • @someone5781
    @someone5781 4 дні тому

    This was super dope! Loved this technical deep dive! I learned a ton!

  • @eitantal726
    @eitantal726 Місяць тому +16

    What happens when you have a console window, rather than raw VGA as your tty? How does it "know" that stdout is mapped to VGA in this case? is it done during process creation?

    • @thebuggerdev
      @thebuggerdev Місяць тому +14

      When a process writes to stdout (file descriptor = 1) typically it is managed by a parent process. Parent process can catch this data (like for example console window process) or pass through to it's parent. Init is a special process, that starts all other proceses, so it's stdout is rendered by a kernel (also it can pass through data from a process, that is it's child)

    • @eitantal726
      @eitantal726 Місяць тому +5

      @@thebuggerdev So the is full process something like this? (let's say, XTerm) printf -> kernel -> parent process -> x11

    • @thebuggerdev
      @thebuggerdev Місяць тому +3

      @@eitantal726 yes, in this example XTerm is a parent process

    • @thebuggerdev
      @thebuggerdev Місяць тому +8

      @@eitantal726 and to be precise: communication of xterm with x11 is also done by kernel's functions

  • @autistadolinux5336
    @autistadolinux5336 День тому

    clicked for the kernel, stayed for the gdb tutorial

  • @cocogus
    @cocogus 9 годин тому

    Short and descriptive. Great video.

  • @yonatanelizarov6747
    @yonatanelizarov6747 Місяць тому +3

    Thanks man, really useful. Keep up the great work!

  • @khazarhajiyev7710
    @khazarhajiyev7710 Місяць тому +2

    Have been looking for a channel like that for a long time, thank you!

  • @waldmensch2010
    @waldmensch2010 Місяць тому +1

    these videos are so cool and nerdy and the best of it you learn so much

  • @sanderbos4243
    @sanderbos4243 Місяць тому

    This is such a good reference video for anyone wanting to dive into the kernel

  • @BorderKeeper
    @BorderKeeper 18 днів тому

    Programmer of 10 years here. This is straight up black magic.

  • @golarac6433
    @golarac6433 Місяць тому +2

    I use gdb a lot but somehow didn't know about the 'advance' command, I would put a breakpoint when I wanted to advance forward (that I had to delete or disable later). So that's nice, thanks :)
    It might be worth adding that the vga text mode is a very legacy functionality. Qemu still supports it since its very easy to use from software but I'm not even sure if modern gpus support that. I think all modern gpus support only a normal linear pixel frame buffer where you'd have to blit your font characters manually.

    • @nirlichtman
      @nirlichtman  Місяць тому +1

      That's a good point, added information about this in the pinned comment.

  • @orestissabethai830
    @orestissabethai830 Місяць тому

    We are going to need some more of that gdb magic you are doing. Nice video!

  • @MyWatermelonz
    @MyWatermelonz Місяць тому +1

    Dang breh aside from just screen printing, I learned some gdb and vim. Lots of good stuff.

  • @Akronymus_
    @Akronymus_ Місяць тому

    Finally found this vid. I clicked on a different one when seeing this in the periphery and was searching for it ever since.

  • @JohnnySacc
    @JohnnySacc Місяць тому

    That was awesome, I'd love a full series of this

  • @ciCCapROSTi
    @ciCCapROSTi 28 днів тому

    Came here to learn about the kernel, but instead got an intermediate GDB tutorial. I'm thankful, I'm a lot more interested in GDB than the Linux kernel, actually.
    As for the video mode, yeah, I remember programming assembly as a child, I know how that mode works. I produced several full screen vomits of blinking colors.

  • @notyourfox
    @notyourfox Місяць тому

    Thanks a lot! I'm trying to grasp system calls and standard library for my own OS. I am always shocked by the complexity of the code in Linux kernel and the amount of knowledge and talent it required to write.

  • @Samstercraft77
    @Samstercraft77 16 днів тому

    Now THIS is top quality content

  • @yahiaghadiry9885
    @yahiaghadiry9885 Місяць тому +7

    Amazing video
    But I have a question, all those boot logs before printing the H, how are those printed.

    • @jameskuo2822
      @jameskuo2822 Місяць тому +1

      printk(); in kernel space, in (very, very) shorts. I do believe they use different ways to printf() to implement printk().

  • @whamer100
    @whamer100 Місяць тому

    wow i didnt expect displaying text to be so complicated, that's interesting

  • @saurabhrajguru1636
    @saurabhrajguru1636 День тому

    beautifully broken down. thanks!

  • @atharvakamble5785
    @atharvakamble5785 Місяць тому

    This video is insanely good, not many like these!

  • @MadMathMike
    @MadMathMike Місяць тому

    You're a freaking wizard, Nic. Great video! 👍😊

  • @valerys.219
    @valerys.219 Місяць тому +1

    essential things, nicely done. But IMHO you missed one point, how vga works (logical level), ie what the kernel write to the vga memory in order to see an 'H' on the screen. Anyway thanks for sharing.

  • @Samstercraft77
    @Samstercraft77 16 днів тому

    THE HELLO WORLD TYPING SPEED IS CRAZY

  • @pal-v3d
    @pal-v3d 8 днів тому

    Hoping more videos like this. ❤

  • @skylarmorknerbrown
    @skylarmorknerbrown Місяць тому

    This man is making some of the most informative and interesting Linux videos on all of youtube... using Windows 10

  • @Joker9586
    @Joker9586 Місяць тому

    Very interesting insight! Great content, thank you sir

  • @eliphazbouye
    @eliphazbouye Місяць тому +3

    Nir please I want to know what you way to learn efficiently ? can you give me our method ? some tips ? . Great video thanks

    • @nirlichtman
      @nirlichtman  Місяць тому +3

      Thanks! Check out my welcome page for more information and recommended resources (link on my channel)

    • @eliphazbouye
      @eliphazbouye Місяць тому

      @@nirlichtman Very awesome thank you 🙏

  • @ElPikacupacabra
    @ElPikacupacabra Місяць тому +3

    Why did it print 3 "H"? I tought it would continue with the other letters...

    • @nirlichtman
      @nirlichtman  Місяць тому +6

      Reason it printed 3 "H"s is that when I changed to the other colors, I reused the command in which I modified the "H" to red, and only changed the color, so it kept the same character as before.

    • @ElPikacupacabra
      @ElPikacupacabra Місяць тому +2

      @@nirlichtman Ah, right. You did not update just the top byte.

  • @LeandroCoutinho
    @LeandroCoutinho Місяць тому

    Amazing video!
    Linux kernel + gdb + qemu = ❤
    I hope you manage to build more videos like this. =D
    Hardware and software interaction would be great. 😃

  • @ricozhuang7625
    @ricozhuang7625 Місяць тому

    That is deeper than I thought

  • @iflux8821
    @iflux8821 8 днів тому

    This is great! Thank you very much!

  • @MO-fg2cm
    @MO-fg2cm Місяць тому

    Damn the knowledge I got through this video is amazing

  • @AK-vx4dy
    @AK-vx4dy Місяць тому

    Excellent job and crazy skills 🤯

  • @iyar220
    @iyar220 Місяць тому +12

    Yayyy

  • @cosmiclattemusic
    @cosmiclattemusic Місяць тому

    this is why I love UA-cam

  • @callummacleod2177
    @callummacleod2177 Місяць тому

    Excellent information presentation 👌

  • @gustawitresh
    @gustawitresh Місяць тому

    idk why, but this is fun to watch.

  • @coshvjicujmlqef6047
    @coshvjicujmlqef6047 7 днів тому +1

    how does kernel printk work? i do not want to use format string but just write

  • @theforeskinsnatcher373
    @theforeskinsnatcher373 Місяць тому

    some cool gdb tricks I didn't know. But I think I'll use the tui/disassembly view instead of jumping to addresses

  • @doug9000
    @doug9000 Місяць тому

    would be cool to show how graphical virtual terminals work in low level too.

  • @ghostsdefeated4078
    @ghostsdefeated4078 Місяць тому

    this channel is cracked

  • @nathanielthomas4437
    @nathanielthomas4437 Місяць тому

    Driver devs can get a lot of hate sometimes, but if it weren't for them, we wouldn't get to see the hard work of printf()!

  • @user-dv9dl2cl1p
    @user-dv9dl2cl1p 25 днів тому

    learns a lot, thanks!

  • @ecuas_7
    @ecuas_7 25 днів тому

    This is so cool, thank you

  • @la.zanmal.
    @la.zanmal. Місяць тому

    0:56 For the record: the `-j` flag stands for "jobs", and tells `make` how many actions it may run in parallel. It can generally make a complex build faster, up to the limit of the number of CPU cores you have. At least for me, the numeric argument isn't necessary and by just passing `-j`, "make will not limit the number of jobs that can run simultaneously".

  • @pablote325
    @pablote325 Місяць тому

    this is an insanely good video.... thanks

  • @umikaliprivate
    @umikaliprivate Місяць тому

    Could you make a video about how to make a simple wayland-based window manager?

  • @MrMassaraksh
    @MrMassaraksh Місяць тому

    Thank you!
    Good stuff

  • @YRBYD
    @YRBYD Місяць тому +1

    Great video!

  • @muhammadmahad
    @muhammadmahad Місяць тому

    Thanks for such an amazing video.

    • @muhammadmahad
      @muhammadmahad Місяць тому

      Could you please share the tips to become good in low level things just like you?

    • @nirlichtman
      @nirlichtman  Місяць тому +1

      Yes, there are a bunch of tips on my welcome page, link in the channel description

    • @muhammadmahad
      @muhammadmahad Місяць тому

      @@nirlichtman Thank you Nir :)

  • @Jonathan-ru9zl
    @Jonathan-ru9zl Місяць тому +2

    You back!

  • @kaankarakoc7680
    @kaankarakoc7680 Місяць тому

    thanks for another great video!

  • @Swampdragon102
    @Swampdragon102 Місяць тому

    I still don't know why the random modified memory appears on the terminal, but I've learned the basics of GDB, so that's something

    • @nirlichtman
      @nirlichtman  Місяць тому +2

      On VGA text mode 3 (the display mode the kernel decided to use in this case), the text on screen is manipulated through memory, so when writing to a specific memory address we can change the contents on the screen. (more info on the OSDev wiki article link in description)

    • @clonkex
      @clonkex Місяць тому

      That memory was about to be printed anyway. It was H to start with because that was the beginning of Hello World. He just found where it was about to happen and changed the memory just before it did. Then because he kept using the same second byte and only changing the colour byte, it printed more H characters instead of the e and l it would have otherwise printed.

  • @gustawitresh
    @gustawitresh Місяць тому +11

    WTF, bro just said. "I don't really like AT&T *assembly* syntax, so I'm going to intel *syntax*"
    This man is crazy

    • @gustawitresh
      @gustawitresh Місяць тому +3

      "it's more fun to read" omg

    • @szaszm_
      @szaszm_ 20 днів тому +1

      what's crazy about that? You pretty much have your preference if you ever worked with x86 assembly.

  • @sezarstarscourge7368
    @sezarstarscourge7368 Місяць тому

    wonderful explaination ,

  • @cyberbiosecurity
    @cyberbiosecurity Місяць тому

    Awesome, thank you

  • @VaibhavSharma-zj4gk
    @VaibhavSharma-zj4gk Місяць тому

    Thats a knowledge packed video. I understood it in parts. Is there any past video i need to see to better inderstand this one?

    • @sanderbos4243
      @sanderbos4243 Місяць тому

      Depends on which parts you were and weren't able to follow. Any GDB tutorial will be a good place to start

    • @nirlichtman
      @nirlichtman  Місяць тому +1

      I would recommend checking out my videos about making a simple distro, Linux system calls explained, and generally my Linux playlists. Also, welcome to check out my welcome page for recommended resources, link on my channel

  • @BudgiePanic
    @BudgiePanic 20 днів тому

    Very cool. How do you get so comfortable with CLI tools? It's like you don't even need a mouse.

    • @nirlichtman
      @nirlichtman  18 днів тому

      Check the welcome link on my channel for recommended learning resources and additional information, I indeed prefer using the keyboard over mouse control in a lot of cases, but I wouldn't say a mouse is completely unneeded, for example for graphical stuff it is very useful.

  • @sierra991
    @sierra991 21 день тому

    i feel like i am linus torvalds after watching this video

  • @mickolesmana5899
    @mickolesmana5899 Місяць тому +4

    Noob arch user : nooo you can't just run both windows and linux
    Chad Kernel dev : anyway I just opened Qemu on Linux from ssh windows

  • @justinnamilee
    @justinnamilee Місяць тому

    Oh damn, I'm coming in for another "Neat!"

  • @app3264
    @app3264 Місяць тому

    Love your videos!

  • @Nop_Nop_0x90
    @Nop_Nop_0x90 Місяць тому

    Can you start a series on deeo dive into Linux kernal ? (A real detailed one)

    • @nirlichtman
      @nirlichtman  Місяць тому

      More kernel videos are planned :)

  • @abdelrahmanyasser5720
    @abdelrahmanyasser5720 Місяць тому

    Great job, Thanks bro

  • @dovonun
    @dovonun Місяць тому

    You are an absolute legend 🤯

  • @Libellisth
    @Libellisth 11 днів тому

    How did I end up on this side of youtube again? You know.. that side of youtube where we change ANSI escape codes in the register live from the debugger.
    So we can have a prettyier color in our terminal emulator...

  • @evildragon1774
    @evildragon1774 Місяць тому +1

    i'm not judging you but, why are you using windows when you're very interested in linux?

    • @nirlichtman
      @nirlichtman  Місяць тому +4

      I am also interested in Windows :)

  • @MykolaTheVaultDweller
    @MykolaTheVaultDweller Місяць тому +8

    based

  • @David-wh8zs
    @David-wh8zs Місяць тому

    This is such a good video

  • @chrisking1017
    @chrisking1017 Місяць тому

    How does this change in a terminal app in a desktop environment?

  • @soleroks
    @soleroks Місяць тому

    Well done.

  • @jayhanjaelee
    @jayhanjaelee 26 днів тому

    It’s so interesting👍

  • @mzg147
    @mzg147 10 днів тому

    Why does it print "H" 3 times? At 12:15 you hit continue execution, so it should go to the next letter, "e" right? I would expect red "H" and green "e".

    • @TildaAzrisk
      @TildaAzrisk 5 годин тому

      It would have been an e, but in modifiying the byte for the color, the byte for the character was overwritten as well.
      At 12:32, The original value of 0x765 (Light Gray 'e') was changed to be 0x248 (Green 'H').
      For Green 'e', the value would of have had to have been set to 0x265. 0x2 being the color Green, and 0x65 being the ASCII code for 'e'.

  • @GreeneThumbs
    @GreeneThumbs Місяць тому

    This is fantastic

  • @matematikaadit
    @matematikaadit Місяць тому

    I guess if you wanna keep the character value but only change the color, you do bitwise AND to the value, for example $r10w=$r10w & 0x2FF (for green color) right? Did GDB support this expression?

  • @ethical-not-evil
    @ethical-not-evil 16 днів тому

    pls do videos about v8 engine debug or idk things like that

  • @binux5592
    @binux5592 Місяць тому

    Can yolu create 64 bit bootloader with c and asm

  • @conandoyle1859
    @conandoyle1859 Місяць тому

    great!