Building an OS - 2 - Reading from the disk

Поділитися
Вставка
  • Опубліковано 25 січ 2021
  • Part 2 of a multipart series about making operating systems. In this part, we write the part of the bootloader that reads from the disk using the BIOS INT 0x13.
    Part 1: • Building an OS - 1 - H...
    Patreon: / nanobyte
    Source code: github.com/nanobyte-dev/nanob...
    Discord: / discord
    Tools:
    - Bochs: bochs.sourceforge.net/
    - mtools: www.gnu.org/software/mtools/
    - VSCode: code.visualstudio.com/
    - Okteta (Linux): apps.kde.org/en/okteta
    - HxD hex editor (Windows): mh-nexus.de/en/hxd/
    Documentation:
    - INT 13h: www.stanislavs.org/helppc/int...
    - x86 instruction reference: c9x.me/x86/
    - CHS addressing: en.wikipedia.org/wiki/Cylinde...
    - CHS to LBA conversion: en.wikipedia.org/wiki/Logical...
    - FAT12 file system: wiki.osdev.org/FAT
  • Наука та технологія

КОМЕНТАРІ • 178

  • @tom-on
    @tom-on Рік тому +90

    Amazing Video!
    The only bad thing was that there is no mkfs.fat command on mac so it took me 3 hours to find a replacement, but i did.
    For anyone that is on mac just replace this line in the Makefile:
    15 | mkfs.fat -F 12 -n "NBOS" $(BUILD_DIR)/main_floppy.img
    with:
    15 | newfs_msdos -F 12 -f 2880 $(BUILD_DIR)/main_floppy.img

    • @rapske50
      @rapske50 Рік тому +2

      Thanks!

    • @cirkulx
      @cirkulx Рік тому +1

      later on the choices once again kill mac so now I'm on my own... just entered protected mode and now only just got lld to start making a C kernel for it

    • @andreitircavu64
      @andreitircavu64 Рік тому +1

      what about the mcopy command?

    • @spacefishaviation276
      @spacefishaviation276 Рік тому +1

      @@andreitircavu64 That comes from mtools.

    • @RayBellis
      @RayBellis 11 місяців тому +5

      if you've installed mtools then you can use that to create your floppy image: mformat -C -v NBOS -f 1440 -i $(BUILD_DIR)/main_floppy.img
      You don't even need to use dd to create the empty image file first.

  • @alexanderbuchler4048
    @alexanderbuchler4048 3 роки тому +57

    biggest comeback in history

  • @ecosta
    @ecosta 2 роки тому +47

    Rowing rowing your boat... Down the memory lane... That video brings me so many memories. Imagine troubleshooting that without QEMU or BOCHS, using a real floppy disk!

    • @alxvt77
      @alxvt77 2 роки тому +24

      and going through a pile of docs to understand all the specs instead of googling it in 3 seconds.. 😭 early programmers were truly pioneers..

    • @logangraham2956
      @logangraham2956 2 роки тому +2

      you could still do it, just not with floppy disks .
      most desktop computers still have at least 1 serial port so if you setup com1 port you should be able to diagnose the same as they use to.

    • @ecosta
      @ecosta 2 роки тому +3

      @@logangraham2956 What I tried to say was how I did it with floppy disks decades ago, using nothing more than Brown's interrupt list and a lot of reboots.

    • @JtagSheep
      @JtagSheep 11 місяців тому

      @@ecosta I am doing it in much a similar way, I do have youtube and google to help but I often find it much easier to just read Brown's interrupt list and figure it out from there. GDB has been a life saver allowing me to step through the bootloader and kernel in qemu and see if the code to execute is what is meant to happen, a lot of reboots indeed! Thank for for qemu! I did have it booting on real hardware too but currently ripping apart the bootloader and improving it to include a real file system, i grew tried of writing the kernel directly to disk its time for a better aproach!

  • @numberformat
    @numberformat 10 місяців тому +4

    Thanks for putting in the hard work to get these videos posted. I liked how you used multiple tools to trace thru the code and really explained the theory behind it. Really informative.

  • @aaroncirillo
    @aaroncirillo 2 роки тому +6

    great videos, I'm loving working through this series

  • @ari_archer
    @ari_archer 2 роки тому +1

    Your content is amazing, thanks for showing up in my recommended :)

  • @RegisMichelLeclerc
    @RegisMichelLeclerc 11 місяців тому +4

    Thank you for this. I used to play with that in the early 90s...
    To pass parameters to a function, "high-level" languages use the stack:
    my_function proc near
    param1 equ [bp+4]
    param2 equ [bp+6]
    push bp
    mov bp,sp
    ...
    mov ax,param1
    ...
    pop bp
    ret 2 ; 2 words
    my_function endp
    and
    push param1
    push param 2
    call my_function
    Now, to be fair, this is pure 8086, as they add "bound" instructions since 80286 (long ago) to avoid the "ret 2" and needing to calculate the number of words to unstack, but that's more than enough in a 16bit real mode bootloader.
    Also, function 41h of int 13h seems to take LBA values for read, which is more appropriate if you're using a different media (such as an empty hard disk or an ISO), so you don't need to bother calculating the CHS. Also, there are bitwise ways of filtering and calculating CHS (with and+shr and shl if you're using ecx/edx) and "or dl,dl" seems to be the fastest way to check for carry in dl (rather that "test dl").
    I know "hlt" is short, but for a reboot, you can also do:
    xor ax,ax
    dec ax
    push ax
    inc ax
    push ax
    retf
    ...or simply
    jmp 0ffffh:0000h
    So you're sure everything is done properly at processor level, whatever "variant" of x86 you have (including Cyrix and AMD).
    Also, for the teletype function to output a string, you can have a function that starts with "pop si", reads the string until it finds a '\0\ and "jmp si" (push si before calling if required) and thus have your messages directly inline, like:
    write_string proc near
    pop si
    mov ah,0eh ; int 10h:teletype
    xor bl,bl ; screen 0
    loop:
    lodsb
    or al,al
    jz eos
    int 10h
    jmp loop
    eos:
    jmp si
    write_string endp
    /* ... some code... */
    push si
    call write_string
    db 'hello world',0
    ; code continues here...
    pop si
    ...
    That's a lot of jumps at the beginning, wouldn't it be better to have your first instruction as just "jmp start" and all functions before/after the main block instead of having "jmp start/jmp main"?

  • @programtrue
    @programtrue 7 місяців тому

    This is amazing tutorial! I've not found another one more in depth than this!

  • @catalingoga6002
    @catalingoga6002 4 місяці тому +2

    This series is a gold mine, please continue! Thank you for your hard work, it really helps when starting to learn more in-depth about OSs.

  • @legacywolf443
    @legacywolf443 11 місяців тому +29

    These tutorials are amazing so far!
    I've written all of these on floppy disc and run it on a Pentium and they work fine :3

    • @XXxerom
      @XXxerom 10 місяців тому

      I'm currently do this on a Pentium D 945😄

    • @potatoman5070
      @potatoman5070 4 місяці тому

      thats what im coding this on 🤣

  • @llytaii1108
    @llytaii1108 Рік тому +9

    These tutorials are really nice, very good explanations. When starting bochs it helped me using "display_library: x", otherwise it wouldnt start. But everything else works as shown! :D

  • @cristianhoger
    @cristianhoger Рік тому +7

    Thank you for the video, I think that every CS student should be subscribed to this channel!

  • @kennethlooney6769
    @kennethlooney6769 3 роки тому +8

    You are awesome! Your teaching style is so amazing! keep it up! :)

  • @mehrdad-mixtape7970
    @mehrdad-mixtape7970 10 місяців тому +1

    It was very cool. I was programming with you and it was a good experience that I came to the same conclusion as you. 😍

  • @user-gc6bb1tk9h
    @user-gc6bb1tk9h 10 місяців тому

    Thank you so much for this.. Your content is amazing, thanks for showing up in my recommended :).

  • @damouze
    @damouze 8 місяців тому +1

    I am enjoying this series a lot, so keep them coming!
    As for the boot loader... Personally, I would actually simply use the standard boot sector for a FAT12 filesystem and patch this to load a custom file. This file would then be the boot loader and would in turn set things up and load the actual kernel. This ensures some compatibility with anything existing and also saves me from having to write a new boot sector every time I start a new experiment.

  • @WistrelChianti
    @WistrelChianti 2 роки тому

    Thanks so much! Really informative!

  • @Learnerofthings
    @Learnerofthings Рік тому

    Thank you so much for this.

  • @joedew4183
    @joedew4183 2 роки тому

    i really like your voice. its very calm

  • @kinars8160
    @kinars8160 3 роки тому +1

    this was very helpful, thank you

  • @creeperthecat9120
    @creeperthecat9120 2 місяці тому +1

    Important note to those using WSL:
    If you're having trouble getting bochs to work, it's because of the weird nature of WSL not being able to access everything.
    Bochs by default tries to access the sound cards during initialisation, which WSL has no support for. This results in a really annoying error when you try to run it.
    The fix is adding this line to the bochs_config:
    plugin_ctrl: speaker=0
    If bochs is screaming about memory issues, check the address. In my case I had to change it to 0xffff0000.

  • @amadlover
    @amadlover Рік тому +5

    using the boch config shown here, I encountered the could not read physical memory on clicking continue on the box gui.
    Changed the romimage to legacy, and removed the address argument, and it worked as expected.

  • @programmingmindset
    @programmingmindset 13 днів тому

    This is called programming. 😍😍

  • @H4K0N42
    @H4K0N42 11 місяців тому

    I dont want to learn assembly but this video is very intresting.

  • @Baconinged
    @Baconinged Рік тому +1

    good video! i had trouble using MSWIN4.1 for my bpb oem string, however mkdosfs worked for anyone else having this problem

  • @victoryfile
    @victoryfile 8 місяців тому

    Thanks! Out of curiosity, what theme do you use? It's quite beautiful.

  • @Nightwulf1269
    @Nightwulf1269 11 місяців тому

    Great video series! I stumbled upon the "test di, di" instruction. Shouldn't "dec di" already set the zero flag?

  • @danielvarga4395
    @danielvarga4395 10 місяців тому

    Thanks for this tutorial series. Unfortunately QEMU tells me that this is not a bootable disk when it tries to boot from floppy and I don't know where to look for a mistake. Does anyone have a suggestion?

  • @studiocodex7808
    @studiocodex7808 7 місяців тому

    I wish you used NTFS stead of Fat12 other than that great video!

  • @ofekn
    @ofekn Рік тому +1

    Does anyone know what i should use instead of mkfs.fat and mcopy in windows?

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

    I am using a docker image with linux, and it keep saying there is no mkfs.fat? what should I do?

  • @bollybigglo
    @bollybigglo 11 місяців тому

    Hey! I am trying to continue on the bochs debugger but it comes up with a bus error. Is there a fix for this?

  • @trungkieu
    @trungkieu 10 місяців тому

    thanks for the content, i learnt very much, just want to ask that in 7:46 ,the term " : : kernel.bin ", what does it mean?

    • @nanobyte-dev
      @nanobyte-dev  5 місяців тому

      :: is just the way you specify the "root" folder in mtools (mcopy, mdir etc). "::kernel.bin" means the file kernel.bin on the root of the disc (in Windows, that would be A:\kernel.bin).

  • @wiktordiy6033
    @wiktordiy6033 10 місяців тому +1

    Hi, I ma getting the "Makefile:6: *** missing separator. Stop." error. Any Idea what could be a problem?

    • @ruinenlust_
      @ruinenlust_ 4 місяці тому +2

      Makefile uses tabs not spaces

  • @Ahm3dTantawy
    @Ahm3dTantawy Рік тому

    For me it fails reading disk on physical machine.
    Is there a way to fix it? Thanks.

  • @danielmosner5802
    @danielmosner5802 Рік тому +1

    Question.
    In function lba_to_chs we are modifying the whole dx (xor dx, dx) bcs of division, but in the end we are restoring only lover part of dx. Are we not losing dh by doing this?
    The division may not change dh, but our clearing of dx will delete anything in dh. What am I missing?

    • @kojonek2
      @kojonek2 11 місяців тому

      dh is used as return value so you do not want to restore it

    • @ruinenlust_
      @ruinenlust_ 4 місяці тому

      16 bit mode

  • @bro-fi4gc
    @bro-fi4gc 2 роки тому +2

    man these videos are amazing, may I use your code to develop my own operating system and post it?
    with your permission

    • @nanobyte-dev
      @nanobyte-dev  2 роки тому +10

      Yes, of course. Check the github repo for license information (I used the "Unlicense" license, granting you the right to basically do anything you want).

    • @Nunya58294
      @Nunya58294 2 роки тому

      @@nanobyte-dev Absolutely wonderful video!

    • @IlliaZhdanov
      @IlliaZhdanov Рік тому

      first time seeing someone use it (except me, but lets just not talk about that)

  • @ethanrushbrook3314
    @ethanrushbrook3314 10 місяців тому

    I managed to get myself a The devil is in the details: zero number of heads or sectors error. Does that count as an easter egg?

  • @thecwd8919
    @thecwd8919 11 місяців тому

    Having difficulties using mcopy (choco and pacman cant find mtools for windows lol)
    Are there any alternatives that might work?
    Good guide by the way. Its very interesting!

    • @nanobyte-dev
      @nanobyte-dev  11 місяців тому

      I recommend using WSL, windows tools aren't as good as Linux. You could try to find some software that can mount disk images and use system tools (like format)

  • @lj-musictech
    @lj-musictech 8 місяців тому

    i'm looking for a linux distro to code this on, what distro are you using in this video?

  • @unmeinks5907
    @unmeinks5907 8 місяців тому

    is there any reason you didnt just seek 62 bytes in when you copied the bootloader into the main_floppy.img?

  • @ailphaune
    @ailphaune Рік тому

    I need help !! I'm using kali linux. In bochs, when I set the breakpoint at 0x7c00 and click on continue it says
    bx_dbg_read_linear: physical memory read error (phy=0x0000322f3130, lin=0x00000000322f3130)
    and the address stays at 0xFFFFFFF0 :(

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      It is probably the BIOS, i had issues with it as well. Try some other BIOSes from some other versions. Debugging with qemu and gdb might work better, in the last version of the nanobyte-os repository, there is a file scripts/debug.sh, you can use that as a starting point for debugging directly in qemu and gdb.

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

    when i try to start my OS, it says "no bootable device". how do i fix this?

  • @imalaia8033
    @imalaia8033 Рік тому

    Hello! I am using windows (since my linux pc fried itself) and when i try to run bochs with sdl2 it still says that sdl2 is not found! Do you know what is the problem? Thanks in advance!

    • @nanobyte-dev
      @nanobyte-dev  Рік тому +1

      Try a different display_library. On windows you should have "win32". I think "wx" might also work on Windows.

    • @imalaia8033
      @imalaia8033 Рік тому

      @tacitmarmot the motherboard sorted

  • @-sterbent-5591
    @-sterbent-5591 4 місяці тому

    I do not have a floppy disc how can I boot system on another form? To rephrase when running the make file qemu responds with no bootable decide how do I find a device to boot from?

    • @shahzaibhassan6504
      @shahzaibhassan6504 3 місяці тому

      i spent like days on this
      the problem is with the makefile
      he is using linux while most ppl are prob using windows
      its not generating the main_floppy.img properly

  • @whtiequillBj
    @whtiequillBj 10 місяців тому

    while your description for a head as the platter side does make sense I think the head has to do with the "read head" on the arm.
    But as far as the video is concerned it is pretty much an issue of six of one, half a dozen of another.

  • @pilottim136
    @pilottim136 2 місяці тому

    can someone help me, i can't execute the makefile code :(
    it doesnt give any output in the log either why it wont work

  • @OriGDash
    @OriGDash Рік тому

    i got an error, the fat file isnt found. what can i do?

    • @OriGDash
      @OriGDash Рік тому

      ok wait a sec i didnt install it

  • @XXxerom
    @XXxerom 10 місяців тому

    Amazing video! But I have a problem when I want to make the imagefile. When I run the makefile, it gave me an error (dd if=build/bootloader.bin of=build/main_floppy.img conv=notrunc
    dd: failed to open 'build/bootloader.bin': No such file or directory
    make: *** [Makefile:16: build/main_floppy.img] Error 1)
    I rewrote like 2x, but still gave me this error. How coud I fix this?

    • @nanobyte-dev
      @nanobyte-dev  10 місяців тому

      Did you create the build directory?

    • @XXxerom
      @XXxerom 10 місяців тому

      @@nanobyte-dev Oh i forgot that one, now it works! Thank you!

  • @sergeykholkhunov1888
    @sergeykholkhunov1888 Рік тому

    Why don't you use gdb instead of bochs?

  • @shouma1234
    @shouma1234 Рік тому

    After testing a bit, I found that QEMU already seems to be loading sector 2 of the floppy disk into 0x7e00 before we even read the data with int 0x13. Didn't you say that we only have access to the first sector of the floppy disk, which is why we need this read function early on?
    (Also btw I couldn't get Bochs to work with WSL which is why I settled on QEMU+GDB, which seems to work if you do a workaround for a bug with its interpretation of i8086.)

    • @shouma1234
      @shouma1234 Рік тому +1

      Nevermind, I think I made a mistake using GDB which led me to believe this. Yes only sector 1 is loaded in by the BIOS

    • @cyrusheick8135
      @cyrusheick8135 Рік тому +3

      Did you try adding "sound: waveoutdrv=dummy, waveindrv=dummy, midioutdrv=dummy" to your bochs_config file? I think WSL is lacking sound output and so Bochs doesn't know how to handle it by default. Adding that line was the big modification I needed to make nanobyte's code work in WSL.

    • @cheeseplated
      @cheeseplated 6 місяців тому

      ​@@cyrusheick8135 Thank you so much! I had the same problem a while back which kind of made me stop because I could never find an answer, now I can (finally) get back to coding

  • @AhsanAli-dw8iv
    @AhsanAli-dw8iv Рік тому

    which operating system are you using yourself ?
    its quite beautiful

    • @oriyadid
      @oriyadid Рік тому

      They're using Linux with the KDE Desktop Environment, presumably some extension installed to make it look MacOS-like

    • @nanobyte-dev
      @nanobyte-dev  Рік тому +2

      If i remember correctly, I was using Kubuntu with either the default dark theme or the Arc theme... can't remember exactly.

  • @Learnerofthings
    @Learnerofthings Рік тому +1

    I would use ; and not # for comments in .asm files. Make gave me some issues with those.

    • @troywest1987
      @troywest1987 Рік тому

      Thanks Abby, I had the same issue and your comment saved me some debugging time that will be better spent on more complicated bugs later I'm sure

  • @Grab-Deals
    @Grab-Deals 5 місяців тому

    is this a linux or windows or mac operating system?

  • @foxfirefive
    @foxfirefive 10 місяців тому

    Im following this tutorial and so far its very good, but im stuck cause i cant figure out what to do about makefile saying that mkfs.fat isnt a command. help!

    • @ArnaudMEURET
      @ArnaudMEURET 10 місяців тому

      Are you on a Mac?

    • @foxfirefive
      @foxfirefive 10 місяців тому

      no, im on windows :)@@ArnaudMEURET

    • @lucaspedro7272
      @lucaspedro7272 10 місяців тому

      Did you run this on the subsystem of Linux for windows?

    • @foxfirefive
      @foxfirefive 10 місяців тому

      @@lucaspedro7272 no

  • @Sebwazhere
    @Sebwazhere 6 місяців тому

    I'm at 12:24 and when I run make, it says I don't have permissions for mcopy, and when I run sudo make, it says mcopy not found. I am on Windows 11 using WSL Ubuntu.
    EDIT - Turns out I didn't have mtools installed, now I can use make.

  • @guillaumepotier9334
    @guillaumepotier9334 Рік тому +1

    Amazing Video thx for all of that knowledge, I simply have one question :
    When we run the fnc "lba_to_chs" we take in enty:
    -> AX (The value of LBA address)
    And I suposed to get my answer as :
    -> CX -> Bit16 to Bit6 => my CYLINDER (Cy)
    -> CX -> Bit5 to Bit1 => my SECTOR (Sc)
    -> DH => my HEAD (Hd) -> 0 or 1
    There is what I don't understand :
    CX (16bits) should be like that : Cy10 - Cy09 - Cy08 - Cy07 - Cy06 - Cy05 - Cy04 - Cy03 - Cy02 - Cy01 - Sc06 - Sc05 - Sc04 - Sc03 - Sc02 - Sc01
    DX (16bits) should be : X X X X X X X X - X X X X X X X Hd01 Because Head can only be 1 or 0
    You save in CH the value of AL (mov CH, AL) so :
    CX = Cy08 Cy07 Cy06 Cy05 Cy04 Cy03 Cy02 Cy01 - X X Sec06 Sec05 Sec04 Sec03 Sec02 Sec01
    After You do : (shl AH, 6) : you get In AH Registry the value of Cy10 & Cy09
    AX = Cy10 - Cy09 - 0 - 0 - 0 - 0 - 0 - 0 Cy08 - Cy07 - Cy06 - Cy05 - Cy04 - Cy03 - Cy02 - Cy01
    Then after : (or CL, AH) You put the 2 byte of AH in CL, so you get :
    CX = Cy08 Cy07 Cy06 Cy05 Cy04 Cy03 Cy02 Cy01 - Cy10 Cy09 Sec06 Sec05 Sec04 Sec03 Sec02 Sec01
    And this is the final value you return :
    So How Can It work If the 9th & 10th bit of the cylinder value are not at the good place in the registry ?
    Maybe you explain it in your next video, but for now I try to understand all the step for reading a disk with ASM.
    Great series of video, thx for your work.

    • @nanobyte-dev
      @nanobyte-dev  Рік тому +3

      If you check the documentation of INT 13h, AH=02h on wikipedia, it gives a diagram of the bits in CX. They look in fact like this:
      CX = Cy7 Cy6 Cy5 Cy4 Cy3 Cy2 Cy1 Cy0 --- Cy9 Cy8 Sec5 Sec4 Sec3 Sec2 Sec1 Sec0
      (in other words, bits 0-7 of the cylinder are set in CH, bits 8 and 9 of the cylinder are set as the upper bits of CL)
      The reason why it's like this is probably backwards compatibility... older drives that had smaller capacities used CH for the cylinder and CL for the sector, but at some point the cylinder didn't fit in 1 byte anymore... so how could they fix it without breaking compatibility? Just reuse the upper bits of the sector for the extra bits.
      HDDs can have more than 2 heads.

    • @marcomorozzi4501
      @marcomorozzi4501 8 місяців тому

      @@nanobyte-dev it took me hours to understand hahaha. I touguth it was a bug in your code and so i fixed it. With my "fixed version" wasn't working and i coudn't uderstand why

  • @alejandroalzatesanchez
    @alejandroalzatesanchez Рік тому

    mine wasn't working because i placed way to much text and that overflowed the 512 byte limit lol

  • @bestbixel
    @bestbixel 2 роки тому

    what linux is that

  • @andredeoliveira8986
    @andredeoliveira8986 4 місяці тому

    What Linux distribution is he using?

  • @Bl0xxy
    @Bl0xxy 5 місяців тому

    8:20
    somewhere aroudn that, i'm still stuck on Cannot initialize '::'

    • @nanobyte-dev
      @nanobyte-dev  5 місяців тому

      If you get the size of even 1 field wrong, the header will not work. I recommend checking your code against the github repo and make sure it is correct.

    • @Bl0xxy
      @Bl0xxy 5 місяців тому

      @@nanobyte-dev I pasted the code multiple times to test from the github. No luck. Is it related to the info inside of the hex editor or smth? I feel like I'm missing something

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

    this is my error. Can you help me ? Thank you so much

  • @larslindner6491
    @larslindner6491 Рік тому

    I set all the header in boot.asm but mcopy still would complain 12:09

  • @Oxey405
    @Oxey405 Рік тому

    Hey ! Thanks for the tutorial series I'm learning a lot and it's quite fun to slowly understand how assembly works and how to write advanced logic with it by creating a tiny tiny OS.
    However I ran into a problem when using Bochs...
    It seems like in newer versions of Bochs, the config file is broken (or the BIOS) because whatever I do, I cannot get Bochs to actually launch my image whilst QEMU does the job perfectly. I'vhe looked into errors and yes I can confirm that the problem comes from the latest version of Bochs (2.7+) Any idea on how to fix ?
    What happens is : the BIOS starts but looks like it finds nothing and crashes. An error is reported telling me "bx_dbg_read_linear: physical memory read error" but I suspect this is not the only problem as my "t" counter is far below yours...
    Thanks

    • @fabianmahdi7281
      @fabianmahdi7281 Рік тому

      a workaround is to set the romimage to legacy and remove the address argument

    • @cyrusheick8135
      @cyrusheick8135 Рік тому

      I'm glad I'm not the only one dealing with this... I'm hours deep trying to figure out what the heck is going on. I'm brand new to this, but I'm trying to work my way through this and am thinking that somehow the stack pointer is getting messed up and pointing to the last line of the BIOS. The memory location it's trying to access (0x322f3130) is actually a portion of the ASCII code showing the date on the BIOS file. If you use xxd to look at the BIOS file you'll see 08/01/21... the stack pointer is set to the "01/2" portion of that string and so when it tries to grab the address to put into BX is grabs the 4 bytes for that ASCII representation (it treats 2 as the MSB so it gets reversed). Look at an ASCII table and you'll see "2"=0x32, "/"=0x2f, "1"=0x31, "0"=0x30.
      Now as for why this is occurring... I've noticed that if I step to t=320322 there is a "mov esp, 0xfffffff0" instruction. I didn't keep tabs on the stack pointer for all the subsequent instructions but I'm guessing it's related. Maybe someone knows a reason for why you would want this instruction, but I can't think of a reason why you'd want to set the stack pointer to the end of the BIOS file? I'm not sure what to do from here, hopefully someone smarter than me stumbles upon this comment and can help make sense of it all :)

    • @cyrusheick8135
      @cyrusheick8135 Рік тому

      Which now that I'm looking, that 08/01/21 date is also the release date of Version 2.7. So you mentioned that the problem comes from version 2.7... how did you differentiate between the Bochs version and the BIOS file that was released on that same day? I'm wondering if it's an issue with the BIOS instructions itself or the way that Bochs is handling the offending instruction.

    • @nanobyte-dev
      @nanobyte-dev  11 місяців тому

      I had a lot of trouble with it myself, it's usually the bios or vbios. Trying out a couple of different versions (e.g. from the master branch, or from a newer/older release) I would eventually find one that works. Lately I gave up on bochs and just use qemu+gdb. I have a section in my discord faq channel where I describe how to set it up.

  • @EggerMan69
    @EggerMan69 Рік тому

    5:04

  • @EggerMan69
    @EggerMan69 Рік тому

    23:54

  • @oamioxmocliox8082
    @oamioxmocliox8082 11 місяців тому

    ;)

  • @amadlover
    @amadlover Рік тому

    @8:07: i tried to copy the bootloader file into the img file with an offset of 62 (obs=1, seek=62)2). Also inside the boot.asm the padding of zeros is 448-($-$$) instead of 510-($-$$). in the final image however, the bytes after the BPB is altered at a few places. which is the "code". vs the image which is created the BPB inlined in the asm file.
    should i upload the two images somewhere for reference
    Edit: the mkfs bpb image prints garbage, where as the inline bpb prints Hello World

    • @amadlover
      @amadlover Рік тому

      Image files, boot.asm and a Makefile
      drive.google.com/drive/folders/1c1UPaixiypr2PZ60LyDtL1_S8vtGwkbw?usp=sharing
      thank you

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

    "Hello World!"
    then nothing... nothing.
    help me

  • @homeopathicfossil-fuels4789
    @homeopathicfossil-fuels4789 10 місяців тому

    512 bytes aint enough for an operating system? Is this a challenge? :D

  • @cubomusic6659
    @cubomusic6659 2 роки тому +3

    why are you doing everything so fast? I can't keep up with you

    • @nanobyte-dev
      @nanobyte-dev  2 роки тому +2

      Coding part is sped up, because otherwise I would end up with 2-3 hour long videos... I agree that I might have overdone it a bit in this one, I'm sorry about that, I'm still learning how to make videos, and hope the newer ones are better. You can pause at any time, or slow the video down, or use the Github repository.

    • @cubomusic6659
      @cubomusic6659 2 роки тому

      ​@@nanobyte-devWhen you did the terminal at 24:00, I slowed down the video a lot of the time but still couldn't keep up with you. I give up now 😥😥😥.

    • @nanobyte-dev
      @nanobyte-dev  2 роки тому +1

      @@cubomusic6659 Don't give up :(
      The commands I write aren't that important, I recorded myself doing all the steps to figure out what needs to be installed, and then the text shown on top of the video shows the steps I already found. If you're curious what each command I did meant, here it is:
      Add execution permission to debug.sh: chmod +x debug.sh
      Run debug.sh: ./debug.sh
      Bochs not found. Install bochs (after getting error it's not installed): sudo apt install bochs
      Check if bios file exists: file /usr/share/bochs/BIOS-bochs-latest
      Error, it doesn't exist. Try to find it using "locate", so first I update the locate database: sudo updatedb
      Then try to locate: locate BIOS-bochs-latest
      File doesn't exist, so maybe it's another package: apt search bochs
      See that there are some additional Bochs packages, proceed to install them: sudo apt install bochsbios bochs-sdl
      Check if bios exists: file /usr/share/bochs/BIOS-bochs-latest
      No error, meaning it exists. Now check if the video bios exists: file /usr/share/bochs/VGABIOS-lgpl-latest
      Error, so it doesn't exist. Install it: sudo apt install vgabios
      Now both file exist, try running: ./debug.sh

    • @nanobyte-dev
      @nanobyte-dev  2 роки тому

      @@cubomusic6659 Using bochs from the ubuntu repositories didn't work properly for me, you can see it in this video as well that I'm not getting any video output, just a black screen. In this video I finally solved the problem, by using a prerelease version of the ROMs: ua-cam.com/video/7CrUM8Uf9ho/v-deo.html (at around 55:00 i debug the bochs issues).

    • @cubomusic6659
      @cubomusic6659 2 роки тому

      @@nanobyte-dev oh thanks, i'll start over

  • @TanjoGalbi
    @TanjoGalbi 11 місяців тому

    Because of a layout fault in the first video the bootloader you have does two jumps at the start which is a waste! What layout fault do I refer to? You have defaulted to the C/C++ convention of putting functions above the main in the code! In Assembly you put them after the main block of code so the main block starts at the start, no need to do a jump instruction past the functions. The assembler does not need to see the functions before they are used, or rather they do not have to be defined first like in C/C++. Basically the assembler does a number of passes over the code with the pass that converts labels to addresses being after interpreting the instructions in the code so it will know exactly where the functions are by that time.

    • @nanobyte-dev
      @nanobyte-dev  11 місяців тому

      You are correct.
      Old habits die hard.

  • @dosdows5732
    @dosdows5732 2 роки тому

    nothing seems to be working, followed all the steps properly and nothing is working

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      What exactly are you having trouble with? You can check the github repo to see if you made any mistakes.

    • @dosdows5732
      @dosdows5732 Рік тому

      @@nanobyte-dev yeah I check it lol I made a number of mistake. I didn’t see you change the hashtags to a semicolon and so nasm was spewing errors bc it didn’t detect as a comment

  • @mastergamer4335
    @mastergamer4335 Рік тому

    why did you just from nowhere start whispering something like 4-5 minutes in the video?

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      Sometimes I don't record everything at once, or I have to go back and re-record parts that don't end up that good. It's interesting and annoying at the same time that how my voice sounds can change from a day to another.
      At that time, I recorded late at night when the kids just fell asleep and didn't want to wake them up.

    • @mastergamer4335
      @mastergamer4335 Рік тому

      @@nanobyte-dev ohh ok.

  • @Shadowblitz16
    @Shadowblitz16 Рік тому

    I like your videos but you sound really depressed

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      I frequently record at night, after my kids are asleep. Sometimes I'm tired. I do my best to not show it in the videos, but doesn't always work. I even rerecorded long recording sessions because of that.

    • @Shadowblitz16
      @Shadowblitz16 Рік тому

      @@nanobyte-dev no as long as your ok i'm ok it might have a little to do with your accent too

  • @resolvn
    @resolvn Рік тому

    Help! im always getting ''getcwd: input output error' in makefile
    Thanks for answering in replies

  • @AnimeWorld572
    @AnimeWorld572 4 місяці тому

    Hey there, I was trying to run the debug.sh file but bochs showed that -
    00000000000i [ ] LDTL_LIBRARY_PATH not set. using compile time default '/usr/lib/x86_64-linux-gnu/bochs/plugins'
    ================================================================
    Bochs x86 Emulator 2.7
    Built from SVN snapshot on August 1, 2021
    Timestamp: Sun Aug 1 10:07:00 CEST 2021
    ================================================================
    00000000000i [ ] BXSHARE not set. using compile time default '/usr/share/bochs'
    00000000000i [ ] lt_dlhandle is 0x56356714a070
    00000000000i [Plugin ] loaded plugin libbx_unmapped.so
    00000000000i [ ] lt_dlhandle is 0x5624b87bca40
    00000000000i [Plugin ] loaded plugin libbx_serial.so
    00000000000i [ ] lt_dlhandle is 0x5642b87c0c0
    00000000000i [Plugin ] loaded plugin libbx_extfpuirq.so
    00000000000i [ ] lt_dlhandle is 0x5642b87c1550
    00000000000i [Plugin ] loaded plugin libxx_gameport.so
    00000000000i [ ] lt_dlhandle is 0x5642b87c1dd0
    00000000000i [Plugin ] loaded plugin libbx_biosdev.so
    00000000000i [ ] lt_dlhandle 0x5642b87c2740
    00000000000i [Plugin ] loaded plugin libbx_iodebug.so
    00000000000i [ ] lt_dlhandle is 0x5642b87c2fa0
    00000000000i [Plugin ] loaded plugin libbx_speaker.so
    00000000000i [ ] lt_dlhandle is 0x5642b87c5010
    00000000000i [Plugin ] loaded plugin libbx_parallel.so
    00000000000i [ ] reading configuration from bochs_config
    00000000000e [ ] bochs_config:6: incorrect parameter format
    00000000000p [ ] >>PANIC

  • @miitchel
    @miitchel Рік тому

    i keep getting this issue when running debug.sh on my WSL ubuntu and i also followed your other WSL os dev tutorial
    00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so
    shared memfd open() failed: Function not implemented
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
    * buffer overflow detected ***: terminated
    ./debug.sh: line 1: 3434 Aborted (core dumped) bochs -f bochs_config
    this is my bochs_config:
    megs: 128
    romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xfffe0000
    vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
    floppya: 1_44=build/main_floppy.img, status=inserted
    boot: floppy
    mouse: enabled=0
    display_library: sdl2, options="gui_debug"

    • @cyrusheick8135
      @cyrusheick8135 Рік тому

      try adding the line "sound: waveoutdrv=dummy, waveindrv=dummy, midioutdrv=dummy" to your bochs_config file

  • @user-il4ux8ml5p
    @user-il4ux8ml5p Рік тому

    is it just me or have i watched this like 5 times, and still don't fully understand

  • @its_forzy
    @its_forzy Рік тому

    at 12:13 when i try to run my os, i get this:
    forz@forzLaptop:~/Desktop/Splash$ make && qemu-system-i386 -fda build/main_floppy.img
    nasm src/bootloader/boot.asm -f bin -o build/bootloader.bin
    src/bootloader/boot.asm:22: error: expression syntax error
    src/bootloader/boot.asm:28: error: `#' expects line number
    src/bootloader/boot.asm:32: error: expression syntax error
    src/bootloader/boot.asm:88: warning: label alone on a line without a colon might be in error [-w+label-orphan]
    make: *** [Makefile:23: bootloader] Error 1

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      I linked the github repo in the description, verify if you missed something

    • @its_forzy
      @its_forzy Рік тому

      @@nanobyte-dev i figured out how to fix that, but now im getting :
      forz@forzLaptop:~/Desktop/Splash$ make
      make: *** No rule to make target 'build/bootloader.bin', needed by 'bootloader'. Stop.

  • @wazt2732
    @wazt2732 Рік тому

    i had a problem running command "make", this give me this error;;
    mkdir -p build
    nasm src/bootloader/boot.asm -f bin -o build/bootloader.bin
    nasm src/kernel/main.asm -f bin -o build/kernel.bin
    dd if=/dev/zero of=build/main_floppy.img bs=512 count=2880
    2880+0 registros leídos
    2880+0 registros escritos
    1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,00450724 s, 327 MB/s
    mkfs.fat -F 12 -n "NBOS" build/main_floppy.img
    mkfs.fat 4.2 (2021-01-31)
    dd if=build/bootloader.bin of=build/main_floppy.img conv=notrunc
    1+0 registros leídos
    1+0 registros escritos
    512 bytes copied, 8,9188e-05 s, 5,7 MB/s
    mcopy -i build/main_floppy.img build/kernel.bin "::kernel.bin"
    /bin/sh: 1: mcopy: not found
    make: *** [Makefile:17: build/main_floppy.img] Error 127

  • @craigbenjamin4556
    @craigbenjamin4556 Рік тому

    This is the error I keep getting and I dont know what to do. I cant go any farther without figuring this out. I am on macosx linux, and after research I used homebrew to install dsfstools but this still wont work. Any Help?
    Thank you!
    mkfs.fat -F 12 -n "NBOS" build/main_floppy.img
    /bin/sh: mkfs.fat: command not found
    make: *** [build/main_floppy.img] Error 127

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      As far as I'm aware, the tools on MacOS are a bit different, more similar to BSD than Linux. Checking the FreeBSD documentation might be a lot more helpful for MacOS issues than the Linux one. There are a couple of different names for the command, including mkfs.msdos, mkfs.vfat, mkdosfs. Maybe one of them works for you. If none of them works, you can try the mformat command from the mtools bundle.

    • @programmingdunce8573
      @programmingdunce8573 10 місяців тому

      I'm on a mac too and I found a solution that works for me.
      I replaced the first _dd_ and the _mkfs_ command with
      hdiutil create -size 1440k -fs "MS-DOS FAT12" -layout NONE -ov $(BUILD_DIR)/main_floppy.img
      mv $(BUILD_DIR)/main_floppy.img.dmg $(BUILD_DIR)/main_floppy.img
      The second command is used because _hdiutil_ automatically appends dmg at the end of the output file.

  • @IlliaZhdanov
    @IlliaZhdanov Рік тому

    well i'm stuck in the fs thing.
    "
    rm -rf build/
    mkdir build/
    nasm src/btldr.asm -f bin -o build/btldr.bin
    nasm src/krnl.asm -f bin -o build/krnl.bin
    dd if=/dev/zero of=build/flp.img bs=512 count=2880
    2880+0 records in
    2880+0 records out
    1474560 bytes transferred in 0.014754 secs (99942681 bytes/sec)
    newfs_msdos -F 12 -f 2880 build/flp.img
    newfs_msdos: warning: build/flp.img is not a character device
    ioctl(DKIOCGETPHYSICALBLOCKSIZE) not supported
    build/flp.img: 5726 sectors in 2863 FAT12 clusters (1024 bytes/cluster)
    bps=512 spc=2 res=1 nft=2 rde=240 sec=5760 mid=0xf0 spf=9 spt=36 hds=2 hid=0 drv=0x00
    dd if=build/btldr.bin of=build/flp.img conv=notrunc
    1+0 records in
    1+0 records out
    512 bytes transferred in 0.000021 secs (24403223 bytes/sec)
    mcopy -i build/flp.img build/krnl.bin "::krnl.bin"
    Cannot initialize '::'
    Bad target ::krnl.bin
    make: *** [build] Error 1
    "
    do you know what is the error caused by??
    EDIT: I did fix the issue but tbh idk what caused it and how i fixed it so sry.

    • @KasenGroth
      @KasenGroth Рік тому

      Did you ever find out how to fix this issue?

    • @IlliaZhdanov
      @IlliaZhdanov Рік тому

      well i did fix the issue but i still dont really understand how i fixed it. Maybe just make sure that the names of the headers are right. Are you experiencing the same issue? If so, what os are you using? I'm using mac, and idk maybe the issue was related to macos or something.

    • @IlliaZhdanov
      @IlliaZhdanov Рік тому

      @@KasenGroth sorry but i can't help you that much if you're experiencing the same problem

    • @jaredheidt785
      @jaredheidt785 11 місяців тому

      I ran into this as well. Would be great if someone could share a solution

  • @KryllyxOfficial
    @KryllyxOfficial Рік тому +1

    Bochs does not like the option "gui_debug" for the SDL2 library. Any way to fix that? I'm on Fedora Workstation.

    • @IlliaZhdanov
      @IlliaZhdanov Рік тому

      bochs doesn't like the option "gui_debug" for me as well, but i'm on mac, maybe it's just outdated?

    • @nanobyte-dev
      @nanobyte-dev  Рік тому

      I've had a ton of problems with Bochs myself, so I no longer recommend using it. I recommend debugging with qemu and gdb. I have a guide in the #faq section in my Discord channel where I show how to use qemu + gdb.