Meaty Skeleton: Difference between revisions

no edit summary
[unchecked revision][unchecked revision]
(If you're going to add a hlt, you probably want it after the panic message.)
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1:
{{FirstPerson}}
{{You}}
{{BeginnersWarning}}
{{Rating|1}}{{Template:Kernel designs}}
{{Kernel designs}}
 
In thisThis tutorial we continuecontinues from [[Bare Bones]] and createcreates a minimal template
operating system in the [[Stan Dard]] style suitable for further modification or as inspiration for your
as inspiration for your initial operating system version. The [[Bare Bones]] tutorial only gives you the
tutorial only gives you the absolutely minimal code to demonstrate how to correctly cross-compile a kernel,
correctly cross-compile a kernel, however this is unsuitable as an example operating system. Additionally, this
operating system. Additionally, this tutorial implements neccesary ABI features needed to satisfy the ABI and
needed to satisfy the ABI and compiler contracts to prevent possible mysterious errors.
errors.
 
This tutorial also serves as the initial template tutorial on how to
Line 50 ⟶ 53:
 
== Building a Cross-Compiler ==
:''{{Main article: [[|GCC Cross-Compiler]], [[|Why do I need a Cross Compiler?]]}}
 
You ''must'' use a [[GCC Cross-Compiler]] in this tutorial as in the
Line 130 ⟶ 133:
mandatory options the project makefile requires:
 
<sourcesyntaxhighlight lang="make">
# Default CFLAGS:
CFLAGS?=-O2 -g
Line 136 ⟶ 139:
# Add mandatory options to CFLAGS:
CFLAGS:=$(CFLAGS) -Wall -Wextra
</syntaxhighlight>
</source>
 
== Architecture Directories ==
Line 222 ⟶ 225:
You can easily download the source code using [[Git]] from the [https://gitlab.com/sortie/meaty-skeleton Meaty Skeleton Git repository]. This is preferable to doing a manual error-prone copy, as you may make a mistake or whitespace may get garbled due to bugs in our syntax highlighting. To clone the git repository, do:
 
<sourcesyntaxhighlight lang="bash">
git clone https://gitlab.com/sortie/meaty-skeleton.git
</syntaxhighlight>
</source>
 
Check for differences between the git revision used in this article and what you cloned (empty output means there is no difference):
<sourcesyntaxhighlight lang="bash">
git diff 084d1624bedaa9f9e395f055c6bd99299bd97f58..master
</syntaxhighlight>
</source>
 
Operating systems development is about being an expert. Take the time to read the code carefully through and understand it. Please seek further information and help if you don't understand aspects of it. This code is minimal and almost everything is done deliberately, often to pre-emptively solve future problems.
Line 237 ⟶ 240:
==== kernel/include/kernel/tty.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef _KERNEL_TTY_H
#define _KERNEL_TTY_H
Line 249 ⟶ 252:
 
#endif
</syntaxhighlight>
</source>
 
==== kernel/Makefile ====
 
<sourcesyntaxhighlight lang="make">
DEFAULT_HOST!=../default-host.sh
HOST?=DEFAULT_HOST
Line 337 ⟶ 340:
 
-include $(OBJS:.o=.d)
</syntaxhighlight>
</source>
 
==== kernel/kernel/kernel.c ====
 
<sourcesyntaxhighlight lang="c">
#include <stdio.h>
 
Line 350 ⟶ 353:
printf("Hello, kernel World!\n");
}
</syntaxhighlight>
</source>
 
==== kernel/arch/i386/tty.c ====
 
<sourcesyntaxhighlight lang="c">
#include <stdbool.h>
#include <stddef.h>
Line 441 ⟶ 444:
terminal_write(data, strlen(data));
}
</syntaxhighlight>
</source>
 
==== kernel/arch/i386/crtn.S ====
Line 459 ⟶ 462:
==== kernel/arch/i386/vga.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef ARCH_I386_VGA_H
#define ARCH_I386_VGA_H
Line 493 ⟶ 496:
 
#endif
</syntaxhighlight>
</source>
 
==== kernel/arch/i386/make.config ====
 
<sourcesyntaxhighlight lang="make">
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
Line 506 ⟶ 509:
$(ARCHDIR)/boot.o \
$(ARCHDIR)/tty.o \
</syntaxhighlight>
</source>
 
==== kernel/arch/i386/crti.S ====
Line 632 ⟶ 635:
==== libc/include/string.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef _STRING_H
#define _STRING_H 1
Line 655 ⟶ 658:
 
#endif
</syntaxhighlight>
</source>
 
==== libc/include/stdio.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef _STDIO_H
#define _STDIO_H 1
Line 680 ⟶ 683:
 
#endif
</syntaxhighlight>
</source>
 
==== libc/include/sys/cdefs.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef _SYS_CDEFS_H
#define _SYS_CDEFS_H 1
Line 691 ⟶ 694:
 
#endif
</syntaxhighlight>
</source>
 
==== libc/include/stdlib.h ====
 
<sourcesyntaxhighlight lang="c">
#ifndef _STDLIB_H
#define _STDLIB_H 1
Line 713 ⟶ 716:
 
#endif
</syntaxhighlight>
</source>
 
==== libc/Makefile ====
 
<sourcesyntaxhighlight lang="make">
DEFAULT_HOST!=../default-host.sh
HOST?=DEFAULT_HOST
Line 811 ⟶ 814:
-include $(OBJS:.o=.d)
-include $(LIBK_OBJS:.o=.d)
</syntaxhighlight>
</source>
 
==== libc/stdlib/abort.c ====
 
<sourcesyntaxhighlight lang="c">
#include <stdio.h>
#include <stdlib.h>
Line 832 ⟶ 835:
__builtin_unreachable();
}
</syntaxhighlight>
</source>
 
==== libc/string/memmove.c ====
 
<sourcesyntaxhighlight lang="c">
#include <string.h>
 
Line 851 ⟶ 854:
return dstptr;
}
</syntaxhighlight>
</source>
 
==== libc/string/strlen.c ====
 
<sourcesyntaxhighlight lang="c">
#include <string.h>
 
Line 864 ⟶ 867:
return len;
}
</syntaxhighlight>
</source>
 
==== libc/string/memcmp.c ====
 
<sourcesyntaxhighlight lang="c">
#include <string.h>
 
Line 882 ⟶ 885:
return 0;
}
</syntaxhighlight>
</source>
 
==== libc/string/memset.c ====
 
<sourcesyntaxhighlight lang="c">
#include <string.h>
 
Line 895 ⟶ 898:
return bufptr;
}
</syntaxhighlight>
</source>
 
==== libc/string/memcpy.c ====
 
<sourcesyntaxhighlight lang="c">
#include <string.h>
 
Line 909 ⟶ 912:
return dstptr;
}
</syntaxhighlight>
</source>
 
==== libc/stdio/puts.c ====
 
<sourcesyntaxhighlight lang="c">
#include <stdio.h>
 
Line 919 ⟶ 922:
return printf("%s\n", string);
}
</syntaxhighlight>
</source>
 
==== libc/stdio/putchar.c ====
 
<sourcesyntaxhighlight lang="c">
#include <stdio.h>
 
Line 939 ⟶ 942:
return ic;
}
</syntaxhighlight>
</source>
 
==== libc/stdio/printf.c ====
 
<sourcesyntaxhighlight lang="c">
#include <limits.h>
#include <stdbool.h>
Line 1,024 ⟶ 1,027:
return written;
}
</syntaxhighlight>
</source>
 
==== libc/arch/i386/make.config ====
 
<sourcesyntaxhighlight lang="make">
ARCH_CFLAGS=
ARCH_CPPFLAGS=
Line 1,037 ⟶ 1,040:
 
ARCH_HOSTEDOBJS=\
</syntaxhighlight>
</source>
 
==== libc/.gitignore ====
Line 1,053 ⟶ 1,056:
==== build.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
set -e
Line 1,061 ⟶ 1,064:
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install)
done
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x build.sh
</syntaxhighlight>
</source>
 
==== clean.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
set -e
Line 1,082 ⟶ 1,085:
rm -rf isodir
rm -rf myos.iso
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x clean.sh
</syntaxhighlight>
</source>
 
==== config.sh ====
 
<sourcesyntaxhighlight lang="bash">
SYSTEM_HEADER_PROJECTS="libc kernel"
PROJECTS="libc kernel"
Line 1,120 ⟶ 1,123:
export CC="$CC -isystem=$INCLUDEDIR"
fi
</syntaxhighlight>
</source>
 
==== default-host.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
echo i686-elf
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x default-host.sh
</syntaxhighlight>
</source>
 
==== headers.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
set -e
Line 1,146 ⟶ 1,149:
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers)
done
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x headers.sh
</syntaxhighlight>
</source>
 
==== iso.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
set -e
Line 1,171 ⟶ 1,174:
EOF
grub-mkrescue -o myos.iso isodir
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x iso.sh
</syntaxhighlight>
</source>
 
==== qemu.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
set -e
Line 1,186 ⟶ 1,189:
 
qemu-system-$(./target-triplet-to-arch.sh $HOST) -cdrom myos.iso
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x qemu.sh
</syntaxhighlight>
</source>
 
==== target-triplet-to-arch.sh ====
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
if echo "$1" | grep -Eq 'i[[:digit:]]86-'; then
Line 1,202 ⟶ 1,205:
echo "$1" | grep -Eo '^[[:alnum:]_]*'
fi
</syntaxhighlight>
</source>
 
You should make this executable script executable by running:
<sourcesyntaxhighlight lang="bash">
chmod +x target-triplet-to-arch.sh
</syntaxhighlight>
</source>
 
==== .gitignore ====
Line 1,226 ⟶ 1,229:
the source tree by invoking:
 
<sourcesyntaxhighlight lang="bash">
./clean.sh
</syntaxhighlight>
</source>
 
You can install all the system headers into the system root without relying on
Line 1,234 ⟶ 1,237:
[[Hosted GCC Cross-Compiler]], by invoking:
 
<sourcesyntaxhighlight lang="bash">
./headers.sh
</syntaxhighlight>
</source>
 
You can build a bootable cdrom image of the operating system by invoking:
 
<sourcesyntaxhighlight lang="bash">
./iso.sh
</syntaxhighlight>
</source>
 
It's probably a good idea to create a quick ''build-and-then-launch'' short-cut
like used in this example to run the system in your favorite emulator quickly:
 
<sourcesyntaxhighlight lang="bash">
./qemu.sh
</syntaxhighlight>
</source>
 
== Troubleshooting ==
Line 1,294 ⟶ 1,297:
* [[topic:36584|A link error found & fixed]]
 
[[Category:Bare bones tutorialsTutorials]]
[[Category:C]]