Permalink
Browse files

Files for part 1, https://www.youtube.com/watch?v=1rnA6wpF0o4

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 37e2927 commit 7eb9f8a1d5089cf7587e553e601c42db34dc94a2
Showing with 117 additions and 0 deletions.
  1. +28 −0 kernel.cpp
  2. +32 −0 linker.ld
  3. +34 −0 loader.s
  4. +23 −0 makefile
View
@@ -0,0 +1,28 @@
void printf(char* str)
{
static unsigned short* VideoMemory = (unsigned short*)0xb8000;
for(int i = 0; str[i] != '\0'; ++i)
VideoMemory[i] = (VideoMemory[i] & 0xFF00) | str[i];
}
typedef void (*constructor)();
extern "C" constructor start_ctors;
extern "C" constructor end_ctors;
extern "C" void callConstructors()
{
for(constructor* i = &start_ctors; i != &end_ctors; i++)
(*i)();
}
extern "C" void kernelMain(const void* multiboot_structure, unsigned int /*multiboot_magic*/)
{
printf("Hello World! --- http://www.AlgorithMan.de");
while(1);
}
View
@@ -0,0 +1,32 @@
ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x0100000;
.text :
{
*(.multiboot)
*(.text*)
*(.rodata)
}
.data :
{
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
*(.data)
}
.bss :
{
*(.bss)
}
/DISCARD/ : { *(.fini_array*) *(.comment) }
}
View
@@ -0,0 +1,34 @@
.set MAGIC, 0x1badb002
.set FLAGS, (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern kernelMain
.extern callConstructors
.global loader
loader:
mov $kernel_stack, %esp
call callConstructors
push %eax
push %ebx
call kernelMain
_stop:
cli
hlt
jmp _stop
.section .bss
.space 2*1024*1024; # 2 MiB
kernel_stack:
View
@@ -0,0 +1,23 @@
# sudo apt-get install g++ binutils libc6-dev-i386
GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = loader.o kernel.o
%.o: %.cpp
gcc $(GCCPARAMS) -c -o $@ $<
%.o: %.s
as $(ASPARAMS) -o $@ $<
mykernel.bin: linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)
install: mykernel.bin
sudo cp $< /boot/mykernel.bin

4 comments on commit 7eb9f8a

@serup

This comment has been minimized.

Show comment
Hide comment
@serup

serup Apr 17, 2018

How would you do this example on windows 10 using CygWin environment ?

I ran into issue with the ld - something like this :
ld: unrecognised emulation mode: elf_i386
https://www.reddit.com/r/osdev/comments/5ry3y5/how_to_link_o_files_elf32i386_on_windows/

Any suggestions to how I can setup Cygwin so I can continue this fine example ?

serup replied Apr 17, 2018

How would you do this example on windows 10 using CygWin environment ?

I ran into issue with the ld - something like this :
ld: unrecognised emulation mode: elf_i386
https://www.reddit.com/r/osdev/comments/5ry3y5/how_to_link_o_files_elf32i386_on_windows/

Any suggestions to how I can setup Cygwin so I can continue this fine example ?

@harryovers

This comment has been minimized.

Show comment
Hide comment
@harryovers

harryovers Jun 15, 2018

@serup @Wayn0 I had no issues getting this to run on the 'Windows Subsystem for Linux'

harryovers replied Jun 15, 2018

@serup @Wayn0 I had no issues getting this to run on the 'Windows Subsystem for Linux'

@Jachdich

This comment has been minimized.

Show comment
Hide comment
@Jachdich

Jachdich Sep 12, 2018

I'm having some issues with the "multiboot magic" stuff:
When I try to boot it says something about "incorrect multiboot header"
Any suggestions?

Jachdich replied Sep 12, 2018

I'm having some issues with the "multiboot magic" stuff:
When I try to boot it says something about "incorrect multiboot header"
Any suggestions?

Please sign in to comment.