972
edits
[unchecked revision] | [unchecked revision] |
mNo edit summary |
m (Fix lint errors) |
||
(11 intermediate revisions by 4 users not shown) | |||
Line 1:
{{BeginnersWarning}}
In this tutorial you'll learn how to get started using the Go language to write your own OS. It will be an example of how to create a very minimal system to get text on the screen. It's in no way an example of how you should organize or structure your project.▼
{{Rating|2}}
▲In this tutorial you'll learn how to get started using the Go language to write your own OS. It will be an example of how to create a very minimal system to get text on the screen. It's in no way an example of how you should organize or structure your project.
== Preface ==
Line 10 ⟶ 11:
== Building a Cross-Compiler ==
The first thing you should do is set up a
So instead of
== Overview ==
Line 76 ⟶ 77:
# This is useful when debugging or when you implement call tracing.
.size _start, . - _start
# The Go runtime is a big problem when wanting to write a kernel in Go.
Line 96 ⟶ 83:
# goes way beyond the scope of this barebone.
#
# Beware that there are
# The linker will fail with missing symbols when you try to use them.
#
# You have to implement those missing symbols yourself to get things working.
# Sometimes you can get away with declaring them as an empty function.
# But this won't
#
# After you get this bare bone working, the first priority should be to write
Line 124 ⟶ 111:
You can then assemble boot.s using:
<
== Writing the Terminal package in Go ==
:''Please read [[Printing to Screen]] to understand what this code does.''
Now we'll create the file terminal.go. It's the package "terminal" our kernel will depend on for printing text to the screen.
<
import "unsafe"
/*
* Map the text mode video memory into a multi-dimensional array that can be safely
* used from Go.
*/
func get_vidMem(addr uint32) *[25][80][2]byte {
return buff
}
/*
Line 211 ⟶ 196:
vidMem[Row][Column][1] = Color
Column++
if Column >
Column = 0
Row++
Line 226 ⟶ 211:
}
}
</syntaxhighlight>
Compile using: <
== How imported packages are found ==
When you import a package with gccgo it will look for the import data in the following files and will use the first one it finds.
*
*
*
*
== Writing a kernel in Go ==
Now we create the file kernel.go that
<
import "terminal"
Line 260 ⟶ 247:
// Print our Hello, World!
terminal.Print("Hello, Kernel World!\n")
}</
Compile using: <
== Linking the Kernel ==
Line 314 ⟶ 301:
You can link your kernel using:
<
The file myos.bin is now your kernel. Note that we are linking against [[libgcc]], which implements various
== Testing your operating system (QEMU) ==
Virtual Machines are very useful for
QEMU supports booting multiboot kernels directly without using a bootable medium:
<
== External Links ==
Line 329 ⟶ 316:
* [https://www.gnu.org/software/grub/manual/multiboot/multiboot.html Multiboot Specification]
* [https://golang.org/doc/install/gccgo Setting up and using gccgo]
[[Category: Bare bones tutorials]]
|