Coder Social home page Coder Social logo

os-series's Introduction

Write Your Own 64-bit Operating System Kernel From Scratch

This respository holds all the source code for this YouTube tutorial series.

You can find the revision for a specific episode on this page.

You can find pre-built ISO files for this kernel at this repository.

Considering supporting this work via my Patreon page.

Prerequisites

  • A text editor such as VS Code.
  • Docker for creating our build-environment.
  • Qemu for emulating our operating system.

Setup

Build an image for our build-environment:

  • docker build buildenv -t myos-buildenv

Build

Enter build environment:

  • Linux or MacOS: docker run --rm -it -v "$(pwd)":/root/env myos-buildenv
  • Windows (CMD): docker run --rm -it -v "%cd%":/root/env myos-buildenv
  • Windows (PowerShell): docker run --rm -it -v "${pwd}:/root/env" myos-buildenv
  • Please use the linux command if you are using WSL, msys2 or git bash
  • NOTE: If you are having trouble with an unshared drive, ensure your docker daemon has access to the drive you're development environment is in. For Docker Desktop, this is in "Settings > Shared Drives" or "Settings > Resources > File Sharing".

Build for x86 (other architectures may come in the future):

  • make build-x86_64
  • If you are using Qemu, please close it before running this command to prevent errors.

To leave the build environment, enter exit.

Emulate

You can emulate your operating system using Qemu: (Don't forget to add qemu to your path!)

  • qemu-system-x86_64 -cdrom dist/x86_64/kernel.iso
  • Note: Close the emulator when finished, so as to not block writing to kernel.iso for future builds.

If the above command fails, try one of the following:

Alternatively, you should be able to load the operating system on a USB drive and boot into it when you turn on your computer. (I haven't actually tested this yet.)

Cleanup

Remove the build-evironment image:

  • docker rmi myos-buildenv -f

os-series's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

os-series's Issues

Simplify makefile

Make changes to simplify the make file.

  • Get rid of && \ from end of each line.
  • I think there was something else.

set xy funcion

in print.c we can do

void print_set_x_y(size_t Lcol , size_t Lrow){
    col = Lcol;
    row = Lrow;
}

and in our print.h

void print_set_x_y(size_t col , size_t row);

Now in kernel main.c

    print_set_x_y(10,10);
    print_str("Hello, world?");

this will put " Hello, world? " at 10 10

Unable to compile into iso

I wanted to compile the code into an iso and try running it on real hardware but I get an error like this:

docker: error during connect: This error may indicate that the docker daemon is not running.: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create": open //./pipe/docker_engine: The system cannot find the file specified.
See 'docker run --help'.

I don't know much about this stuff but if anyone can help I would really appreciate it.

Makefile not working (episode 1)

When I run make build-x86_64, I get this:

mkdir -p build/x86_64/boot/ && \ nasm -f elf64 src/impl/x86_64/boot/header.asm -o build/x86_64/boot/header.o src/impl/x86_64/boot/header.asm:9: error: comma expected after operand 1 Makefile:5: recipe for target 'build/x86_64/boot/header.o' failed make: *** [build/x86_64/boot/header.o] Error 1

How to boot on real hardware (Windows 10 example)

This is not an issue, but example how to boot this image on real hardware.

First open real Command Prompt (do not use Far or anything else). Then go to your local folder, where os-series is:

cd x:\app\os-series
x:
docker run --rm -it -v "%cd%":/root/env myos-buildenv
make build-x86_64

Now dist/x86_64/ will contain kernel.iso file

Insert USB flash drive
Download Rufus

image
image

UTF-8 Characters

Hi, I'm stuck at printing utf-8, does anybody know how to print UTF-8 chars?

Question

Has anyone tested on a VM? Maybe that would be better instead of testing on read hardware. Also, how to you build the ISO?

Fix readme commands for entering docker environment on linux

This resolves issue #1: no rule to make target

The commands should be the following when entering the docker build environment:

  • Linux: docker run --rm -it -v "$(pwd)":/root/env myos-buildenv
  • MacOS: docker run --rm -it -v "$(pwd)":/root/env myos-buildenv
  • Windows (CMD): docker run --rm -it -v "%cd%":/root/env myos-buildenv
  • Windows (PowerShell): docker run --rm -it -v "${pwd}:/root/env" myos-buildenv

If you are using git bash, WSL, or msys2 on windows, you'll probably need to use the linux command above.

Makefile wont run

whenever i run the make build-x86_64 command i get this this message

mkdir -p dist/x86_64 && \ x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld && \ cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin && \ grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso /usr/local/bin/x86_64-elf-ld: no input files Makefile:10: recipe for target 'build-x86_64' failed make: *** [build-x86_64] Error 1

Everything in the make file I'm pretty sure is exactly the same as the one in the video. Does anyone know what went wrong?

Qemu unable to boot from CD ROM

When I go to run the kernel, Qemu cannot find the file and gives me an error. I've narrowed the issue down to the grub.cfg file, but I cannot seem to find the right path to the kernal.bin file.

Screen Shot 2021-02-21 at 6 44 50 PM

edit: The file path in the image was me just testing. I've tried many different paths, including the one provided in master

x86_64-elf-ld => file format not recognized; treating as linker script

make build-x86_64
mkdir -p dist/x86_64 &&
x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld ./src/impl/x86_64/boot/header.asm ./src/impl/x86_64/boot/main.asm &&
cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin &&
grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso
x86_64-elf-ld:./src/impl/x86_64/boot/header.asm: file format not recognized; treating as linker script
x86_64-elf-ld:./src/impl/x86_64/boot/header.asm:1: syntax error
Makefile:12: recipe for target 'build-x86_64' failed
make: *** [build-x86_64] Error 1

A few ideas/questions?

  • What will it take to enable debugging/remote debugging? Is that a feasible feature to implement: remote debugging from within VSCode?
  • Use CMake to build and deploy from within VSCode.
  • Add support /examples for other languages C++/Rust, which should be basically the same as for C I guess.
  • Implement and use some standard libc-like, etc. functions, instead of a custom api.
  • A most simple command line/interpreter/programming language to facilitate the OS features.

No changes being updated

so I've been trying to change the string that we print out at the end of episode 2 but it refuses to change. yes qemu is closed when I build, I don't know what else to do.

qemu

could not read from boot disk

make fails

I didn't changed anything and runned the Dockerfile.
(Im using Ubuntu Mate)
I get this everytime:

mkdir -p build/kernel/ && \
x86_64-elf-gcc -c -I src/intf -ffreestanding  src/impl/kernel/main.c -o build/kernel/main.o
/bin/sh: 2: x86_64-elf-gcc: not found
make: *** [Makefile:13: build/kernel/main.o] Error 127

Episode 1 - make command fails

Followed the tutorial word by word, also created a backup where I did a git pull on this repo to make sure I got everything right.

Followed all the commands prior to this one.

When inside root@825d74b91757:~/env, I ran make build-x86_64 and I'm getting this error:

make: *** No rule to make target 'build-x86_64'. Stop.

Episode 2 - First make

I get this error the first time

root@eb48b894aae2:~/env# make build-x86_64
mkdir -p dist/x86_64 &&
x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld build/x86_64/boot/header.o build/x86_64/boot/main.o build/x86_64/boot/main64.o &&
cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin &&
grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso
x86_64-elf-ld: build/x86_64/boot/main.o: in function start': src/impl/x86_64/boot/main.asm:(.text+0x2a): relocation truncated to fit: R_X86_64_16 against .rodata'
Makefile:10: recipe for target 'build-x86_64' failed
make: *** [build-x86_64] Error 1

Text Flashing on Real Hardware

I flashed the ISO to a flash drive and booted it up on a few computers around my house. On all of them, the text flashes. Not the background color, but just the foreground. This only happens on real hardware, in qemu it works fine. It seems it happens on all backgrounds equal to and greater than 8, anything less works as expected. Foreground color doesn't matter, as long as background is greater than 7, text flashes. Don't take this seriously as I am big dumb, but it may be an issue with the memory size?? Again, I'm dumb so take it with a huge grain of salt. I should also mention 8 renders as black and not a dark gray, although I am not sure if that is specific to only my computers or something..

I'm not experienced enough with C to even attempt a fix to this, but I did just spend like an hour building, flashing, running across my house to the family PC, and testing so give me a break. XD

Issue with Makefile

I have an issue with the makefile thing. It always gives me
make: *** No rule to make target 'build-x86_64'. Stop.
image
Can somebody help me?
Btw I have cloned everything from branch ep1.

compiler error

When I try to compile the source it gives me this error:

x86_64/print.c:11:1: error: expected ';', identifier or '(' before 'struct'
 struct Char* buffer = (struct Char*) 0xb8000;

the command being run:

x86_64-elf-gcc -c -std=gnu99 -I include/ -ffreestanding  x86_64/print.c -o build/x86_64/print.o

the relevant contents of print.c:

struct Char {
        uint8_t character;
        uint8_t colour;
}

struct Char* buffer = (struct Char*) 0xb8000;

my gcc version is a cross-compiled 4.9.0, however i get the exact same error on non-cross-compiled versions 4.7, 7, 9 and 10.
any help would be appreciated!

Issue with booting on real hardware

It just gets stuck on this screen whenever I tried to boot on it on my laptop through a USB
IMG_20210616_182514_246
If you can't read the text it says
booting double r OS
warning no console will be available to OS

Help with qemu!

Hey I was at the end of this and I installed qemu but when I restart VS Code and use the command then this shows.

'qemu-system' is not recognized as an internal or external command,
operable program or batch file.

Docker destroy my OS

I need to enter safe mode in Windows 10 and do force delete of Docker Desktop

READ ME

Hey guys, I would just like to mention that it can take years to learn how to write a working OS. Before you comment about "it isn't working" or "teach us how to make " just remember to read the documentation or if you are not familiar with assembly, C, make or docker then take the time to learn before you start watching the tutorials.

Ps:-
CodePulse, you ok? I haven't seen any activity for a couple of months.

Adding a keyboard?

I tried copying a fork of this repo here to add keyboard support, but I still can't type. I cleaned it up a bit, but I don't think I'm reading the PS/2 controller correctly. Any help?

Can you link in the c library?

If you could link in libc (/lib64/libc.so.6) then you could use standard C functions like printf. I'll bet this isnt all that difficult and you could look at startup code for an ordinary C program to get the method/code/info on how to do it.
Plus it would make a great video!

Im trying to make input.

Is there any way I can include stdio.h or something just to get scanf func, or how to make it and include it like in print.h thanks in advance

Error

I get this error, when typing make build-x86_64
I'm on MacOS 12 Dev beta 4
Bildschirmfoto 2021-08-25 um 16 28 54

Update docker base image to correct version

This is the potential solution to #2 x86_64-elf-gcc: not found

The docker base image is the latest version of an image provided by another user. This image has likely since been updated, causing problems.

Todo: I will fork the correct version of this base image. I will then update the Dockerfile to reference this new base image.

failed to register layer

I was trying to build the buildenv for the first step and it says: failed to register layer: Error processing tar file(exit status 1): write /usr/local/share/info/as.info: read-only file system

Build error

I am facing this issue "docker build buildenv -t myos-buildenv
unable to prepare context: path "buildenv" not found" so any solution
Screenshot (188)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.