--
Go depends on system calls. You currently have to have a kernel running in order for a go program to work. There used to be a "tiny" runtime that did not have this restriction, but it was removed (I believe because it was too hard to keep it up-to-date with the regular runtime). I know of no way to get around this restriction currently.
--
Yeah but all the project is to write a new kernel. I don't want to create THE new kernel, I just want to build A new kernel for my own purpose, for fun. I already write one in C and I know the Go team said the Go is really suitable for building operative systems so I try :D
But the runtime is a big issue so I don't understand why the Go is so suitable for operating systems.Maybe I misunderstand something during that conference.
My goals are to work on kernel not to build a new runtime. Can I just copy it ? Same architecture, same PC.
I have no assignment, just working on kernel programming. Choose whatever technology I want. I did it in C, now I try in Go :)
Any piece of advice to make it work is welcome ;)
--
Put all the information that you want to go into .grub_sig into onepackage, and don't put anything else into that package. Use a linkerscript to put that object file into the .grub_sig section.
I don't know why you aren't picking up the definitions. If you areusing explicit -l options (-lgcc, -lgo) make sure you put them at theend of the link line, and put -lgo before -lgcc. The ordering of -loptions and object files matters.
Change
.grub_sig 0xC0100000 : AT(0x100000)
{
*(.grub_sig)
}
to
.grub_sig 0xC0100000 : AT(0x100000)
{
grub_sig.o(*)
}
This isn't black magic, it's all documented at
http://sourceware.org/binutils/docs-2.23.1/ld/Scripts.html . This is
the kind of thing you are going to need to understand in order to
succeed with this project.
Don't link by running the program "ld". That is rarely correct.
Instead, run the program "gccgo". That is, set LD=gccgo in your
Makefile. Then change LDFLAGS to be -Wl,-T,linker.ld,-n. You may
also want to use -nostdlib, I don't know. See the GCC documentation
on -nostdlib and -nostartfiles.
Hi Guillaume,I looked into this a few months back, and managed to get some really basic code that will boot from grub and drop you into a Go function. As others have mentioned, without the runtime it's pretty useless, but it might be a fun project to try and get something useful running.
main.8g:(.rodata+0xcc): undefined reference to `__go_type_hash_identity'
main.8g:(.rodata+0xd0): undefined reference to `__go_type_equal_identity'
main.8g:(.rodata.__go_td_pN9_main.toto[__go_td_pN9_main.toto]+0xc): undefined reference to `__go_type_hash_identity'
main.8g:(.rodata.__go_td_pN9_main.toto[__go_td_pN9_main.toto]+0x10): undefined reference to `__go_type_equal_identity'
main.8g:(.rodata.__go_td_pN3_int[__go_td_pN3_int]+0xc): undefined reference to `__go_type_hash_identity'
main.8g:(.rodata.__go_td_pN3_int[__go_td_pN3_int]+0x10): undefined reference to `__go_type_equal_identity'
main.8g:(.rodata.__go_tdn_int[__go_tdn_int]+0xc): undefined reference to `__go_type_hash_identity'
main.8g:(.rodata.__go_tdn_int[__go_tdn_int]+0x10): undefined reference to `__go_type_equal_identity'
collect2: error: ld returned 1 exit status
make: *** [kernel] Error 1
And just for curiosity, did the garbage-collecting is disable when I don't link with standard library ? How manage memory ?
You more or less have to link with the Go library in order to link Gocode. It's not really optional. You can avoid specific parts of the
library, but you can't avoid the whole thing.
The function __go_type_hash_identity will be used as the equality
operator for a struct with no padding, each of whose fields can be
compared for equality using memcmp. This function will appear in the
type reflection structure for the struct. There is nothing similar
this concept in C.
/usr/bin/ld: kernel: could not find output section .gnu.hash
/usr/bin/ld: final link failed: Nonrepresentable section on output
$go kernel .
kernel.go :
---------------
package kernel // <- instead of main
void main() { // as usual, so the entry symbole is kernel.main
// your kernel here
}
boot.go :
-------------
package boot // <- the package to boot on
// here your signature
grub.go :
-------------
package grub
const (
GrubMagic = 0x1BADB002
GrubFlags = 0x0
GrubChecksum = (-1 * (grubMagic + grubFlags))
)
type Signature struct {
Magic uint
Flags uint
Checksum int
}
func NewSig() *Signature {
return &Signature{GrubMagic, GrubFlags, GrubChecksum}
}
boot.go :
-------------
package boot
import "boot/grub"
var (
sig = *grub.NewSignature()
)
This error message implies that you are building a dynamically linked
executable or shared library. You don't want that. You need to use
-static, as you were earlier.
/usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.22.90.20120924 assertion fail ../../bfd/elf.c:4115
/usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.22.90.20120924 assertion fail ../../bfd/elf.c:4115
/usr/bin/ld: kernel: section .ctors lma 0x1a0180 adjusted to 0x1a023c
Sorry, I don't know what is causing that. Are you using a linker
script? If so, the problem is most likely that your linker script
isn't doing anything with the .ctors section.
/usr/bin/ld: kernel: section .tdata lma 0x1a0158 adjusted to 0x1a0214
/usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.22.90.20120924 assertion fail ../../bfd/elf.c:4115
/usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.22.90.20120924 assertion fail ../../bfd/elf.c:4115
On Tue, Jan 15, 2013 at 9:24 AM, Guillaume Lescure
Is that possible to build in golang something like http://xen.openmirage.org/ ?
What we need to port/rewrite to use full golang runtime?
Is that possible to build in golang something like http://xen.openmirage.org/ ?
What we need to port/rewrite to use full golang runtime?
as xen provides a lot of hypercalls for the guest OS, I think targeting Go to itwon't be as hard as targeting Go to bare mental as necessary drivers arealready complete.
If you run GNU ld with the --verbose option it will show you thedefault linker script. I recommend starting from that and editing it.
error: overlap detected.error: no loaded kernel.
So I think, there is a safety that kill my kernel when someting's wrong so it's why the "no loaded kernel" is displayed but I don't get the "overlap" thing ... ideas ?The boot works great and the kernel is running. So I begin to write some packages but I found a weird problem (yeah sorry again) :/When I declare a pointer or an array, in a function scope or in the package (even the main package), I have an error :error: overlap detected.error: no loaded kernel.