Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 7eb9f8a commit b440da7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel.cpp
@@ -1,7 +1,9 @@

#include "types.h"

void printf(char* str)
{
static unsigned short* VideoMemory = (unsigned short*)0xb8000;
static uint16_t* VideoMemory = (uint16_t*)0xb8000;

for(int i = 0; str[i] != '\0'; ++i)
VideoMemory[i] = (VideoMemory[i] & 0xFF00) | str[i];
Expand All @@ -20,7 +22,7 @@ extern "C" void callConstructors()



extern "C" void kernelMain(const void* multiboot_structure, unsigned int /*multiboot_magic*/)
extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot_magic*/)
{
printf("Hello World! --- http://www.AlgorithMan.de");

Expand Down
20 changes: 20 additions & 0 deletions makefile
@@ -1,5 +1,6 @@

# sudo apt-get install g++ binutils libc6-dev-i386
# sudo apt-get install VirtualBox grub-legacy xorriso

GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
Expand All @@ -18,6 +19,25 @@ objects = loader.o kernel.o
mykernel.bin: linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)

mykernel.iso: mykernel.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp mykernel.bin iso/boot/mykernel.bin
echo 'set timeout=0' > iso/boot/grub/grub.cfg
echo 'set default=0' >> iso/boot/grub/grub.cfg
echo '' >> iso/boot/grub/grub.cfg
echo 'menuentry "My Operating System" {' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/mykernel.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=mykernel.iso iso
rm -rf iso

run: mykernel.iso
(killall VirtualBox && sleep 1) || true
VirtualBox --startvm 'My Operating System' &

install: mykernel.bin
sudo cp $< /boot/mykernel.bin

13 changes: 13 additions & 0 deletions types.h
@@ -0,0 +1,13 @@
#ifndef __TYPES_H
#define __TYPES_H

typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long long int int64_t;
typedef unsigned long long int uint64_t;

#endif

3 comments on commit b440da7

@Tommy1262
Copy link

@Tommy1262 Tommy1262 commented on b440da7 Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what's the source code for types.h ?? I can't even build my os

@cristian-programmer
Copy link

@cristian-programmer cristian-programmer commented on b440da7 Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what's the source code for types.h ?? I can't even build my os

I do not understand your question, if you think that something else is missing in this commit, you are wrong, the file is complete

@fairy2211
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to follow along this tutorial however, I cannot use grub legacy because its outdated. when executing the makefile I get an error "grub-mkrescue: error: mformat invocation failed". Can someone tell me what I need to do to make this work? I use ubuntu 22.04.

Please sign in to comment.