Skip to content

Commit

Permalink
Merge pull request #61 from icexin/pkg
Browse files Browse the repository at this point in the history
eggos as a pkg
  • Loading branch information
icexin authored Aug 1, 2021
2 parents 565bb8c + 72a71dd commit 5ee716d
Show file tree
Hide file tree
Showing 9 changed files with 1,289 additions and 286 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
"GOOS": "linux",
"GOARCH": "amd64",
},
"files.associations": {
"multiboot.h": "c"
},
}
31 changes: 31 additions & 0 deletions app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module github.com/icexin/eggos/app

go 1.16

require (
github.com/aarzilli/nucular v0.0.0-20210408133902-d3dd7b05a80a
github.com/fogleman/fauxgl v0.0.0-20200818143847-27cddc103802
github.com/fogleman/gg v1.3.0
github.com/fogleman/nes v0.0.0-20210605215016-0aace4b1814a
github.com/gin-gonic/gin v1.7.2
github.com/gliderlabs/ssh v0.3.3
github.com/icexin/eggos v0.0.0-00010101000000-000000000000
github.com/icexin/nk v0.1.0
github.com/jakecoffman/cp v1.1.0
github.com/klauspost/cpuid v1.3.1
github.com/mattn/go-shellwords v1.0.12
github.com/peterh/liner v1.2.1
github.com/robertkrimen/otto v0.0.0-20210614181706-373ff5438452
github.com/spf13/afero v1.4.0
golang.org/x/exp v0.0.0-20210729172720-737cce5152fc
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
gopkg.in/sourcemap.v1 v1.0.5 // indirect
)

replace (
github.com/aarzilli/nucular => github.com/icexin/nucular v0.0.0-20210713192454-c3f236ca56cb
github.com/fogleman/nes => github.com/icexin/nes v0.0.0-20200906065456-8ff789fac016
github.com/icexin/eggos => ../
)
1,235 changes: 1,235 additions & 0 deletions app/go.sum

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions boot/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ typedef unsigned long long uint64;
#include "elf.h"
#include "multiboot.h"

extern char _binary_kernel_elf_start[];
extern char _binary_boot64_elf_start[];

void memcpy(char *dst, char *src, int count);
void memset(char *addr, char data, int cnt);
uint64 loadelf(char *image);
uint64 loadKernelElf(multiboot_info_t *info);
typedef void (*boot64_entry_t)(uint32, uint32, uint32);

void multibootmain(unsigned long magic, multiboot_info_t *mbi)
Expand All @@ -35,7 +35,7 @@ void multibootmain(unsigned long magic, multiboot_info_t *mbi)
}
boot64_entry = (boot64_entry_t)((uint32)entry_addr);

entry_addr = loadelf(_binary_kernel_elf_start);
entry_addr = loadKernelElf(mbi);
if (entry_addr == 0)
{
return;
Expand Down Expand Up @@ -70,6 +70,16 @@ uint64 loadelf(char *image)
return elf->entry;
}

uint64 loadKernelElf(multiboot_info_t *info)
{
if (info->mods_count < 1)
{
return 0;
}
multiboot_module_t *mod = (multiboot_module_t *)(info->mods_addr);
return loadelf((char *)(mod->mod_start));
}

void memcpy(char *dst, char *src, int count)
{
int i = 0;
Expand Down
25 changes: 1 addition & 24 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
module github.com/icexin/eggos

go 1.13
go 1.16

require (
github.com/aarzilli/nucular v0.0.0-00010101000000-000000000000
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/fogleman/fauxgl v0.0.0-20200818143847-27cddc103802
github.com/fogleman/gg v1.3.0
github.com/fogleman/nes v0.0.0-20200820131603-8c4b9cf54c35
github.com/gin-gonic/gin v1.7.2
github.com/gliderlabs/ssh v0.3.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/hirochachacha/go-smb2 v1.0.3
github.com/icexin/nk v0.1.0
github.com/jakecoffman/cp v1.0.0
github.com/klauspost/cpuid v1.3.1
github.com/magefile/mage v1.11.0
github.com/mattn/go-shellwords v1.0.10
github.com/peterh/liner v1.2.0
github.com/prometheus/client_golang v1.7.1
github.com/rakyll/statik v0.1.7
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
github.com/spf13/afero v1.4.0
golang.org/x/exp v0.0.0-20210712160552-8235cf48b5f6
golang.org/x/image v0.0.0-20200801110659-972c09e46d76
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f
golang.org/x/sys v0.0.0-20210314195730-07df6a141424
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gvisor.dev/gvisor v0.0.0-20210716193733-566c23a60eea
)

replace (
github.com/aarzilli/nucular => github.com/icexin/nucular v0.0.0-20210713192454-c3f236ca56cb
github.com/fogleman/nes v0.0.0-20200820131603-8c4b9cf54c35 => github.com/icexin/nes v0.0.0-20200906065456-8ff789fac016
)
256 changes: 0 additions & 256 deletions go.sum

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (

var (
QEMU64 = "qemu-system-x86_64"
QEMU32 = "qemu-system-i386"

QEMU_OPT = initQemuOpt()
QEMU_DEBUG_OPT = initQemuDebugOpt()
Expand All @@ -51,12 +50,14 @@ const (
// Kernel target build the elf kernel for eggos, generate kernel.elf
func Kernel() error {
detectGoVersion()
os.Chdir("app")
defer os.Chdir("..")
env := map[string]string{
"GOOS": "linux",
"GOARCH": "amd64",
}
goLdflags := "-E github.com/icexin/eggos/kernel.rt0 -T 0x100000"
return sh.RunWithV(env, gobin(), "build", "-o", "kernel.elf", "-tags", GOTAGS,
return sh.RunWithV(env, gobin(), "build", "-o", "../kernel.elf", "-tags", GOTAGS,
"-ldflags", goLdflags, "-gcflags", GOGCFLAGS, "./kmain")
}

Expand Down Expand Up @@ -87,7 +88,7 @@ func Multiboot() error {
mg.Deps(kernelTarget)
compileCfile("boot/multiboot.c", "-m32")
compileCfile("boot/multiboot_header.S", "-m32")
ldflags := "-Ttext 0x3300000 -m elf_i386 -o multiboot.elf multiboot.o multiboot_header.o -b binary kernel.elf -b binary boot64.elf"
ldflags := "-Ttext 0x3300000 -m elf_i386 -o multiboot.elf multiboot.o multiboot_header.o -b binary boot64.elf"
ldArgs := append([]string{}, LDFLAGS...)
ldArgs = append(ldArgs, strings.Fields(ldflags)...)
return sh.RunV(LD, ldArgs...)
Expand Down Expand Up @@ -123,6 +124,7 @@ func Qemu() error {
detectQemu()
args := append([]string{}, QEMU_OPT...)
args = append(args, "-kernel", "multiboot.elf")
args = append(args, "-initrd", "kernel.elf")
args = append(args, "-append", os.Getenv("EGGOS_ENV"))
return sh.RunV(QEMU64, args...)
}
Expand All @@ -136,6 +138,7 @@ func QemuDebug() error {
detectQemu()
args := append([]string{}, QEMU_DEBUG_OPT...)
args = append(args, "-kernel", "multiboot.elf")
args = append(args, "-initrd", "kernel.elf")
args = append(args, "-append", os.Getenv("EGGOS_ENV"))
return sh.RunV(QEMU64, args...)
}
Expand Down Expand Up @@ -273,7 +276,7 @@ func accelArg() []string {
}

func initCflags() []string {
cflags := strings.Fields("-fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -ggdb -Werror -fno-omit-frame-pointer -I. -nostdinc")
cflags := strings.Fields("-fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -Werror -fno-omit-frame-pointer -I. -nostdinc")
if hasOutput("-fno-stack-protector", CC, "--help") {
cflags = append(cflags, "-fno-stack-protector")
}
Expand Down

0 comments on commit 5ee716d

Please sign in to comment.