diff --git a/FAQ.md b/FAQ.md index 23702d4..d253399 100644 --- a/FAQ.md +++ b/FAQ.md @@ -14,3 +14,11 @@ Nope. You can install [multiple versions](https://go.dev/doc/manage-install#inst ```bash $ GOROOT=$(go1.16.13 env GOROOT) egg build ``` + +### How do I disable mouse/ network/ filesystem support? + +By default, running `egg build` will transparently load a set of well tested, useful drivers and kernel components into your application by generating an init function which configures things. + +This works wonderfully for turning any application into a useful, and usable, unikernel but is not without drawbacks- especially where things like mice, or filesystem support is not needed. + +You can run `egg generate` at the root of your project and then edit the file `zz_load_eggos.go` accordingly. The presence of this file will stop `egg build` generating anything its self. diff --git a/app/cmd/cat.go b/app/cmd/cat.go index d2200b0..9dab2c2 100644 --- a/app/cmd/cat.go +++ b/app/cmd/cat.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/spf13/afero" ) diff --git a/app/cmd/cd.go b/app/cmd/cd.go index 4ede274..13a7e6b 100644 --- a/app/cmd/cd.go +++ b/app/cmd/cd.go @@ -3,7 +3,7 @@ package cmd import ( "errors" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func cdmain(ctx *app.Context) error { diff --git a/app/cmd/cpuinfo.go b/app/cmd/cpuinfo.go index 99e287c..de24795 100644 --- a/app/cmd/cpuinfo.go +++ b/app/cmd/cpuinfo.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/klauspost/cpuid" ) diff --git a/app/cmd/date.go b/app/cmd/date.go index a97d23b..7b8dd09 100644 --- a/app/cmd/date.go +++ b/app/cmd/date.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/drivers/clock" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/drivers/clock" ) func datemain(ctx *app.Context) error { diff --git a/app/cmd/echo.go b/app/cmd/echo.go index 0e87a88..7e756f7 100644 --- a/app/cmd/echo.go +++ b/app/cmd/echo.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func echomain(ctx *app.Context) error { diff --git a/app/cmd/ls.go b/app/cmd/ls.go index e9fec8a..3db2647 100644 --- a/app/cmd/ls.go +++ b/app/cmd/ls.go @@ -6,7 +6,7 @@ import ( "os" "text/tabwriter" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func printfiles(w io.Writer, files ...os.FileInfo) { diff --git a/app/cmd/memtest.go b/app/cmd/memtest.go index a0478cc..232d059 100644 --- a/app/cmd/memtest.go +++ b/app/cmd/memtest.go @@ -6,7 +6,7 @@ import ( "math/rand" "time" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func memtestmain(ctx *app.Context) error { diff --git a/app/cmd/mount.go b/app/cmd/mount.go index ebd3b73..a768c78 100644 --- a/app/cmd/mount.go +++ b/app/cmd/mount.go @@ -4,10 +4,10 @@ import ( "errors" "net/url" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/fs" - "github.com/icexin/eggos/fs/smb" - "github.com/icexin/eggos/fs/stripprefix" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/fs" + "github.com/jspc/eggos/fs/smb" + "github.com/jspc/eggos/fs/stripprefix" ) func mountmain(ctx *app.Context) error { diff --git a/app/cmd/nes.go b/app/cmd/nes.go index 15dfb21..ef0a0d4 100644 --- a/app/cmd/nes.go +++ b/app/cmd/nes.go @@ -10,10 +10,10 @@ import ( "io" "time" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/drivers/vbe" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/vbe" + "github.com/jspc/eggos/log" "github.com/fogleman/nes/nes" "golang.org/x/image/draw" diff --git a/app/cmd/nssh.go b/app/cmd/nssh.go index fbfbe0b..2939a87 100644 --- a/app/cmd/nssh.go +++ b/app/cmd/nssh.go @@ -4,7 +4,7 @@ import ( "fmt" "net" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func nsshmain(ctx *app.Context) error { diff --git a/app/cmd/pstack.go b/app/cmd/pstack.go index daeb6f8..0e89c48 100644 --- a/app/cmd/pstack.go +++ b/app/cmd/pstack.go @@ -3,7 +3,7 @@ package cmd import ( "runtime" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func gostack() []byte { diff --git a/app/cmd/sleep.go b/app/cmd/sleep.go index 69f09b2..90acac6 100644 --- a/app/cmd/sleep.go +++ b/app/cmd/sleep.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func sleepmain(ctx *app.Context) error { diff --git a/app/cmd/top.go b/app/cmd/top.go index bd145ac..d3e6fb0 100644 --- a/app/cmd/top.go +++ b/app/cmd/top.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/kernel" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/kernel" ) func printstat(ctx *app.Context) { diff --git a/app/cmd/win.go b/app/cmd/win.go index 7c75939..28918f4 100644 --- a/app/cmd/win.go +++ b/app/cmd/win.go @@ -1,3 +1,4 @@ +//go:build nk // +build nk package cmd @@ -9,12 +10,12 @@ import ( "unsafe" "github.com/fogleman/fauxgl" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/drivers/ps2/mouse" - "github.com/icexin/eggos/drivers/vbe" "github.com/icexin/nk/cnk" "github.com/icexin/nk/libc" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/ps2/mouse" + "github.com/jspc/eggos/drivers/vbe" "golang.org/x/image/draw" ) diff --git a/app/context.go b/app/context.go index 2b38411..3e000ad 100644 --- a/app/context.go +++ b/app/context.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - "github.com/icexin/eggos/fs" - "github.com/icexin/eggos/fs/chdir" + "github.com/jspc/eggos/fs" + "github.com/jspc/eggos/fs/chdir" "github.com/peterh/liner" ) diff --git a/app/cowsay/cowsay.go b/app/cowsay/cowsay.go index f8f22d5..ef24209 100644 --- a/app/cowsay/cowsay.go +++ b/app/cowsay/cowsay.go @@ -15,8 +15,8 @@ import ( "github.com/dj456119/go-cowsay/gocowsay" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/app/cowsay/animal" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/app/cowsay/animal" ) var animalTempalteMap = make(map[string]AnimalTemplate) diff --git a/app/examples/graphic/main.go b/app/examples/graphic/main.go index 6342584..78cec10 100644 --- a/app/examples/graphic/main.go +++ b/app/examples/graphic/main.go @@ -8,7 +8,7 @@ import ( "math/rand" "time" - "github.com/icexin/eggos/drivers/vbe" + "github.com/jspc/eggos/drivers/vbe" ) var palette = []color.Color{color.White, color.Black} diff --git a/app/examples/syscall/main.go b/app/examples/syscall/main.go index 0d0731a..60a4387 100644 --- a/app/examples/syscall/main.go +++ b/app/examples/syscall/main.go @@ -5,7 +5,7 @@ import ( "os" "syscall" - "github.com/icexin/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/isyscall" ) var handler isyscall.Handler diff --git a/app/gin/server.go b/app/gin/server.go index 1279116..41e12e1 100644 --- a/app/gin/server.go +++ b/app/gin/server.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) func main(ctx *app.Context) error { diff --git a/app/go.mod b/app/go.mod index 8a2be26..935c725 100644 --- a/app/go.mod +++ b/app/go.mod @@ -1,4 +1,4 @@ -module github.com/icexin/eggos/app +module github.com/jspc/eggos/app go 1.16 @@ -10,9 +10,9 @@ require ( 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/jspc/eggos v0.0.0-00010101000000-000000000000 github.com/klauspost/cpuid v1.3.1 github.com/mattn/go-shellwords v1.0.12 github.com/peterh/liner v1.2.1 @@ -29,5 +29,5 @@ require ( 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 => ../ + github.com/jspc/eggos => ../ ) diff --git a/app/httpd/httpd.go b/app/httpd/httpd.go index 209151c..4b52803 100644 --- a/app/httpd/httpd.go +++ b/app/httpd/httpd.go @@ -3,8 +3,8 @@ package httpd import ( "net/http" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/fs" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/fs" "github.com/spf13/afero" ) diff --git a/app/js/autocomplete.go b/app/js/autocomplete.go index fd94aa9..2c5c478 100644 --- a/app/js/autocomplete.go +++ b/app/js/autocomplete.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/peterh/liner" "github.com/robertkrimen/otto" ) diff --git a/app/js/js.go b/app/js/js.go index 5dc392c..38b9fe4 100644 --- a/app/js/js.go +++ b/app/js/js.go @@ -1,7 +1,7 @@ package js import ( - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/robertkrimen/otto" "github.com/spf13/afero" ) diff --git a/app/js/repl.go b/app/js/repl.go index d838bad..3d0f111 100644 --- a/app/js/repl.go +++ b/app/js/repl.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/robertkrimen/otto" ) diff --git a/app/js/vm.go b/app/js/vm.go index 0d8245a..6a6dc5f 100644 --- a/app/js/vm.go +++ b/app/js/vm.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "net/http" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/sys" "github.com/robertkrimen/otto" ) diff --git a/app/kmain/apps.go b/app/kmain/apps.go index 8c5cbcd..c881de7 100644 --- a/app/kmain/apps.go +++ b/app/kmain/apps.go @@ -1,13 +1,13 @@ package main import ( - _ "github.com/icexin/eggos/app/cmd" - // _ "github.com/icexin/eggos/app/gin" - _ "github.com/icexin/eggos/app/cowsay" - _ "github.com/icexin/eggos/app/httpd" - _ "github.com/icexin/eggos/app/js" - _ "github.com/icexin/eggos/app/phy" + _ "github.com/jspc/eggos/app/cmd" + // _ "github.com/jspc/eggos/app/gin" + _ "github.com/jspc/eggos/app/cowsay" + _ "github.com/jspc/eggos/app/httpd" + _ "github.com/jspc/eggos/app/js" + _ "github.com/jspc/eggos/app/phy" - // _ "github.com/icexin/eggos/app/sshd" - _ "github.com/icexin/eggos/app/uidemo" + // _ "github.com/jspc/eggos/app/sshd" + _ "github.com/jspc/eggos/app/uidemo" ) diff --git a/app/kmain/main.go b/app/kmain/main.go index afbeb83..77e5004 100644 --- a/app/kmain/main.go +++ b/app/kmain/main.go @@ -6,10 +6,10 @@ import ( "os" "runtime" - _ "github.com/icexin/eggos" - "github.com/icexin/eggos/app/sh" - "github.com/icexin/eggos/console" - "github.com/icexin/eggos/log" + _ "github.com/jspc/eggos" + "github.com/jspc/eggos/app/sh" + "github.com/jspc/eggos/console" + "github.com/jspc/eggos/log" ) func main() { diff --git a/app/phy/game.go b/app/phy/game.go index 4f83b01..02d22bf 100644 --- a/app/phy/game.go +++ b/app/phy/game.go @@ -10,9 +10,9 @@ import ( "math/rand" "time" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/drivers/vbe" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/vbe" "github.com/jakecoffman/cp" ) diff --git a/app/sh/autocomplete.go b/app/sh/autocomplete.go index f0918d8..3ec69d4 100644 --- a/app/sh/autocomplete.go +++ b/app/sh/autocomplete.go @@ -4,7 +4,7 @@ import ( "path" "strings" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" "github.com/spf13/afero" ) diff --git a/app/sh/sh.go b/app/sh/sh.go index a8247ea..969ae2a 100644 --- a/app/sh/sh.go +++ b/app/sh/sh.go @@ -5,8 +5,8 @@ import ( "log" "strings" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/console" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/console" "github.com/mattn/go-shellwords" ) diff --git a/app/shiny/event.go b/app/shiny/event.go index b992f38..cbe4f8e 100644 --- a/app/shiny/event.go +++ b/app/shiny/event.go @@ -1,8 +1,8 @@ package shiny import ( - "github.com/icexin/eggos/console" - imouse "github.com/icexin/eggos/drivers/ps2/mouse" + "github.com/jspc/eggos/console" + imouse "github.com/jspc/eggos/drivers/ps2/mouse" "golang.org/x/mobile/event/key" "golang.org/x/mobile/event/mouse" "golang.org/x/sys/unix" diff --git a/app/shiny/window.go b/app/shiny/window.go index f9384e7..92200fa 100644 --- a/app/shiny/window.go +++ b/app/shiny/window.go @@ -6,10 +6,10 @@ import ( "image/draw" "image/png" - "github.com/icexin/eggos/assets" - imouse "github.com/icexin/eggos/drivers/ps2/mouse" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/drivers/vbe" + "github.com/jspc/eggos/assets" + imouse "github.com/jspc/eggos/drivers/ps2/mouse" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/drivers/vbe" "golang.org/x/exp/shiny/screen" "golang.org/x/image/math/f64" ) diff --git a/app/sshd/sshd.go b/app/sshd/sshd.go index 8ee9e64..843155a 100644 --- a/app/sshd/sshd.go +++ b/app/sshd/sshd.go @@ -6,7 +6,7 @@ import ( "net" "github.com/gliderlabs/ssh" - "github.com/icexin/eggos/app" + "github.com/jspc/eggos/app" ) var rsaContent = ` diff --git a/app/uidemo/demo.go b/app/uidemo/demo.go index 224830a..8ac0eaf 100644 --- a/app/uidemo/demo.go +++ b/app/uidemo/demo.go @@ -14,8 +14,8 @@ import ( "github.com/aarzilli/nucular/rect" nstyle "github.com/aarzilli/nucular/style" styled "github.com/aarzilli/nucular/style-editor" - "github.com/icexin/eggos/app" - "github.com/icexin/eggos/app/shiny" + "github.com/jspc/eggos/app" + "github.com/jspc/eggos/app/shiny" "golang.org/x/mobile/event/key" ) diff --git a/cmd/egg/build/builder.go b/cmd/egg/build/builder.go index aa540d9..f14409e 100644 --- a/cmd/egg/build/builder.go +++ b/cmd/egg/build/builder.go @@ -4,7 +4,8 @@ import ( "io/ioutil" "os" "os/exec" - "path/filepath" + + "github.com/jspc/eggos/cmd/egg/util" ) type Config struct { @@ -19,11 +20,13 @@ type Config struct { type Builder struct { cfg Config basedir string + gobin string } func NewBuilder(cfg Config) *Builder { return &Builder{ - cfg: cfg, + cfg: cfg, + gobin: util.GoBin(), } } @@ -34,6 +37,7 @@ func (b *Builder) Build() error { return err } b.basedir = basedir + defer os.RemoveAll(basedir) } else { b.basedir = b.cfg.Basedir @@ -47,13 +51,6 @@ func (b *Builder) Build() error { return b.buildPkg() } -func (b *Builder) gobin() string { - if b.cfg.GoRoot == "" { - return "go" - } - return filepath.Join(b.cfg.GoRoot, "bin", "go") -} - func (b *Builder) fixGoTags() bool { args := b.cfg.GoArgs for i, arg := range args { @@ -73,7 +70,7 @@ func (b *Builder) fixGoTags() bool { func (b *Builder) buildPkg() error { var buildArgs []string - ldflags := "-E github.com/icexin/eggos/kernel.rt0 -T 0x100000" + ldflags := "-E github.com/jspc/eggos/kernel.rt0 -T 0x100000" if !b.cfg.BuildTest { buildArgs = append(buildArgs, "build") } else { @@ -84,7 +81,11 @@ func (b *Builder) buildPkg() error { buildArgs = append(buildArgs, "-tags", "eggos") } buildArgs = append(buildArgs, "-ldflags", ldflags) - buildArgs = append(buildArgs, "-overlay", b.overlayFile()) + + if !b.localImportFileExists() { + buildArgs = append(buildArgs, "-overlay", b.overlayFile()) + } + buildArgs = append(buildArgs, b.cfg.GoArgs...) env := append([]string{}, os.Environ()...) @@ -94,7 +95,7 @@ func (b *Builder) buildPkg() error { "CGO_ENABLED=0", }...) - cmd := exec.Command(b.gobin(), buildArgs...) + cmd := exec.Command(b.gobin, buildArgs...) cmd.Env = env cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout diff --git a/cmd/egg/build/patch.go b/cmd/egg/build/patch.go index d7c50f7..5748bdc 100644 --- a/cmd/egg/build/patch.go +++ b/cmd/egg/build/patch.go @@ -3,29 +3,21 @@ package build import ( "bytes" "encoding/json" + "errors" "log" "os" "os/exec" "path/filepath" "strings" - "text/template" + + "github.com/jspc/eggos/cmd/egg/generate" ) const ( - eggosModulePath = "github.com/icexin/eggos" - eggosImportFile = "import_eggos.go" + eggosModulePath = "github.com/jspc/eggos" overlayFile = "overlay.json" ) -var ( - eggosImportTpl = template.Must(template.New("eggos").Parse(` - //+build eggos - - package {{.name}} - import _ "github.com/icexin/eggos" - `)) -) - type gomodule struct { Module struct { Path string `json:"Path"` @@ -45,16 +37,27 @@ type buildOverlay struct { } func (b *Builder) eggosImportFile() string { - return filepath.Join(b.basedir, eggosImportFile) + return filepath.Join(b.basedir, generate.ImportFile) +} + +func (b Builder) localImportFileExists() bool { + _, err := os.Stat(generate.ImportFile) + if err == nil { + return true + } + + if errors.Is(err, os.ErrNotExist) { + return false + } + + panic(err) } func (b *Builder) overlayFile() string { return filepath.Join(b.basedir, overlayFile) } -func (b *Builder) buildPrepare() error { - var err error - +func (b *Builder) buildPrepare() (err error) { if !b.modHasEggos() { log.Printf("eggos not found in go.mod") err = b.editGoMod() @@ -63,12 +66,16 @@ func (b *Builder) buildPrepare() error { } } - err = b.writeImportFile(b.eggosImportFile()) + if b.localImportFileExists() { + return + } + + err = b.writeImportFile() if err != nil { return err } - err = writeOverlayFile(b.overlayFile(), eggosImportFile, b.eggosImportFile()) + err = writeOverlayFile(b.overlayFile(), generate.ImportFile, b.eggosImportFile()) if err != nil { return err } @@ -87,7 +94,7 @@ func writeOverlayFile(overlayFile, dest, source string) error { func (b *Builder) readGomodule() (*gomodule, error) { var buf bytes.Buffer - cmd := exec.Command(b.gobin(), "mod", "edit", "-json") + cmd := exec.Command(b.gobin, "mod", "edit", "-json") cmd.Stdout = &buf err := cmd.Run() if err != nil { @@ -129,23 +136,15 @@ func (b *Builder) editGoMod() error { "GOARCH=amd64", } env = append(env, os.Environ()...) - cmd := exec.Command(b.gobin(), "get", getPath) + cmd := exec.Command(b.gobin, "get", getPath) cmd.Env = env cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() } -func (b *Builder) currentPkgName() string { - out, err := exec.Command(b.gobin(), "list", "-f", `{{.Name}}`).CombinedOutput() - if err != nil { - log.Panicf("get current package name:%s", out) - } - return strings.TrimSpace(string(out)) -} - func (b *Builder) currentModulePath() string { - out, err := exec.Command(b.gobin(), "list", "-f", `{{.Module.Path}}`).CombinedOutput() + out, err := exec.Command(b.gobin, "list", "-f", `{{.Module.Path}}`).CombinedOutput() if err != nil { log.Panicf("get current module path:%s", out) } @@ -153,16 +152,11 @@ func (b *Builder) currentModulePath() string { } -func (b *Builder) writeImportFile(fname string) error { - pkgname := b.currentPkgName() - var rawFile bytes.Buffer - err := eggosImportTpl.Execute(&rawFile, map[string]interface{}{ - "name": pkgname, - }) +func (b *Builder) writeImportFile() (err error) { + g, err := generate.NewGenerator(b.basedir) if err != nil { - return err + return } - err = os.WriteFile(fname, rawFile.Bytes(), 0644) - return err + return g.Generate() } diff --git a/cmd/egg/cmd/build.go b/cmd/egg/cmd/build.go index b4ee0ec..d9a8fb0 100644 --- a/cmd/egg/cmd/build.go +++ b/cmd/egg/cmd/build.go @@ -18,14 +18,10 @@ package cmd import ( "log" - "github.com/icexin/eggos/cmd/egg/build" + "github.com/jspc/eggos/cmd/egg/build" "github.com/spf13/cobra" ) -var ( - output string -) - // buildCmd represents the build command var buildCmd = &cobra.Command{ Use: "build", diff --git a/cmd/egg/cmd/generate.go b/cmd/egg/cmd/generate.go new file mode 100644 index 0000000..af02069 --- /dev/null +++ b/cmd/egg/cmd/generate.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "log" + "os" + + "github.com/jspc/eggos/cmd/egg/generate" + "github.com/spf13/cobra" +) + +// generateCmd represents the generate command +var generateCmd = &cobra.Command{ + Use: "generate", + Short: "generate an eggos loader file in this project", + Long: `generate the zz_load_eggos.go file in this projetc directly +in order to affect the components which are built into the unikernel. + +Should this file not exist, running 'egg build' will generate a temporary one.`, + Run: func(*cobra.Command, []string) { + err := runGenerate() + if err != nil { + log.Fatal(err) + } + }, +} + +func runGenerate() (err error) { + wd, err := os.Getwd() + if err != nil { + return + } + + g, err := generate.NewGenerator(wd) + if err != nil { + return + } + + return g.Generate() +} + +func init() { + rootCmd.AddCommand(generateCmd) +} diff --git a/cmd/egg/cmd/pack.go b/cmd/egg/cmd/pack.go index b7439d1..e3248df 100644 --- a/cmd/egg/cmd/pack.go +++ b/cmd/egg/cmd/pack.go @@ -25,8 +25,8 @@ import ( "os/exec" "path/filepath" - "github.com/icexin/eggos/cmd/egg/assets" - "github.com/icexin/eggos/cmd/egg/build" + "github.com/jspc/eggos/cmd/egg/assets" + "github.com/jspc/eggos/cmd/egg/build" "github.com/spf13/cobra" ) diff --git a/cmd/egg/cmd/run.go b/cmd/egg/cmd/run.go index 5e4b55d..6642f98 100644 --- a/cmd/egg/cmd/run.go +++ b/cmd/egg/cmd/run.go @@ -25,8 +25,8 @@ import ( "strings" "github.com/google/shlex" - "github.com/icexin/eggos/cmd/egg/assets" - "github.com/icexin/eggos/cmd/egg/build" + "github.com/jspc/eggos/cmd/egg/assets" + "github.com/jspc/eggos/cmd/egg/build" "github.com/spf13/cobra" ) @@ -122,15 +122,6 @@ func runKernel(args []string) error { } } -func fileExists(name string) bool { - if _, err := os.Stat(name); err != nil { - if os.IsNotExist(err) { - return false - } - } - return true -} - func mustLoaderFile(fname string) { content, err := assets.Boot.ReadFile("boot/multiboot.elf") if err != nil { diff --git a/cmd/egg/cmd/test.go b/cmd/egg/cmd/test.go index 1817b5b..1a1c11a 100644 --- a/cmd/egg/cmd/test.go +++ b/cmd/egg/cmd/test.go @@ -21,7 +21,7 @@ import ( "os" "path/filepath" - "github.com/icexin/eggos/cmd/egg/build" + "github.com/jspc/eggos/cmd/egg/build" "github.com/spf13/cobra" ) diff --git a/cmd/egg/generate/generate.go b/cmd/egg/generate/generate.go new file mode 100644 index 0000000..6bdea87 --- /dev/null +++ b/cmd/egg/generate/generate.go @@ -0,0 +1,62 @@ +package generate + +import ( + "bytes" + "log" + "os" + "os/exec" + "path/filepath" + "strings" + + "github.com/jspc/eggos/cmd/egg/util" +) + +const ( + ImportFile = "zz_load_eggos.go" +) + +type Generator struct { + gobin string + basedir string +} + +func NewGenerator(basedir string) (g Generator, err error) { + g = Generator{ + gobin: util.GoBin(), + basedir: basedir, + } + + return +} + +func (g Generator) Generate() error { + return g.writeImportFile(g.eggosImportFile()) +} + +func (g *Generator) eggosImportFile() string { + return filepath.Join(g.basedir, ImportFile) +} + +func (b *Generator) currentPkgName() string { + out, err := exec.Command(b.gobin, "list", "-f", `{{.Name}}`).CombinedOutput() + if err != nil { + log.Panicf("get current package name:%s", err) + } + + return strings.TrimSpace(string(out)) +} + +func (g *Generator) writeImportFile(fname string) error { + pkgname := g.currentPkgName() + var rawFile bytes.Buffer + + err := eggosImportTpl.Execute(&rawFile, map[string]interface{}{ + "name": pkgname, + }) + + if err != nil { + return err + } + + return os.WriteFile(fname, rawFile.Bytes(), 0644) +} diff --git a/cmd/egg/generate/template.go b/cmd/egg/generate/template.go new file mode 100644 index 0000000..f8458db --- /dev/null +++ b/cmd/egg/generate/template.go @@ -0,0 +1,49 @@ +package generate + +import ( + "text/template" +) + +var ( + eggosImportTpl = template.Must(template.New("eggos").Parse(`//+build eggos +package {{.name}} + +import ( + "runtime" + + "github.com/jspc/eggos/console" + "github.com/jspc/eggos/drivers/cga/fbcga" + _ "github.com/jspc/eggos/drivers/e1000" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/pci" + "github.com/jspc/eggos/drivers/ps2/mouse" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/drivers/vbe" + "github.com/jspc/eggos/fs" + "github.com/jspc/eggos/inet" + "github.com/jspc/eggos/kernel" +) + +func kernelInit() { + // trap and syscall threads use two Ps, + // and the remainings are for other goroutines + runtime.GOMAXPROCS(6) + + kernel.Init() + uart.Init() + kbd.Init() + mouse.Init() + console.Init() + + fs.Init() + vbe.Init() + fbcga.Init() + pci.Init() + inet.Init() +} + +func init() { + kernelInit() +} +`)) +) diff --git a/cmd/egg/main.go b/cmd/egg/main.go index 39945ca..8da449f 100644 --- a/cmd/egg/main.go +++ b/cmd/egg/main.go @@ -15,7 +15,7 @@ limitations under the License. */ package main -import "github.com/icexin/eggos/cmd/egg/cmd" +import "github.com/jspc/eggos/cmd/egg/cmd" func main() { cmd.Execute() diff --git a/cmd/egg/util/util.go b/cmd/egg/util/util.go new file mode 100644 index 0000000..170e631 --- /dev/null +++ b/cmd/egg/util/util.go @@ -0,0 +1,15 @@ +package util + +import ( + "os" + "path/filepath" +) + +func GoBin() string { + gr, ok := os.LookupEnv("GOROOT") + if !ok { + return "go" + } + + return filepath.Join(gr, "bin", "go") +} diff --git a/cmd/go.mod b/cmd/go.mod index e3b11d3..2a4f45f 100644 --- a/cmd/go.mod +++ b/cmd/go.mod @@ -1,4 +1,4 @@ -module github.com/icexin/eggos/cmd +module github.com/jspc/eggos/cmd go 1.16 diff --git a/console/console.go b/console/console.go index 8701ebe..e866aab 100644 --- a/console/console.go +++ b/console/console.go @@ -6,9 +6,9 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/drivers/cga" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/drivers/uart" + "github.com/jspc/eggos/drivers/cga" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/uart" ) const ( diff --git a/drivers/cga/backend.go b/drivers/cga/backend.go index b3aef9a..f9e66dc 100644 --- a/drivers/cga/backend.go +++ b/drivers/cga/backend.go @@ -3,9 +3,9 @@ package cga import ( "unsafe" - "github.com/icexin/eggos/drivers/cga/fbcga" - "github.com/icexin/eggos/drivers/vbe" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/drivers/cga/fbcga" + "github.com/jspc/eggos/drivers/vbe" + "github.com/jspc/eggos/kernel/sys" ) type Backend interface { @@ -17,6 +17,14 @@ type Backend interface { WriteByte(ch byte) } +type EraseMethod uint8 + +const ( + EraseMethod_Unknown EraseMethod = iota + EraseMethod_Line + EraseMethod_All +) + const ( CRTPORT = 0x3d4 bs = '\b' @@ -88,7 +96,7 @@ func (c *cgabackend) WriteByte(ch byte) { } } c.SetPos(pos) - crt[pos] = ' ' | 0x0700 + //crt[pos] = ' ' | 0x0700 } func getbackend() Backend { diff --git a/drivers/cga/cga.go b/drivers/cga/cga.go index 9bfa04d..64e86ae 100644 --- a/drivers/cga/cga.go +++ b/drivers/cga/cga.go @@ -21,15 +21,25 @@ func setCursorColumn(n int) { getbackend().SetPos(pos) } -func eraseLine(method int) { +func setCursorHome() { + getbackend().SetPos(0) +} + +func eraseLine(method EraseMethod) { backend := getbackend() pos := backend.GetPos() switch method { - case 0: + case EraseMethod_Line: end := (pos/80 + 1) * 80 for i := pos; i < end; i++ { backend.WritePos(i, ' ') } + + case EraseMethod_All: + for i := 0; i < 25*80; i++ { + backend.WritePos(i, ' ') + } + default: panic("unsupported erase line method") } @@ -38,7 +48,7 @@ func eraseLine(method int) { func writeCSI(action byte, params []string) { // fmt.Fprintf(os.Stderr, "action:%c, params:%v\n", action, params) switch action { - // set cursor + // set cursor column case 'G': if len(params) == 0 { setCursorColumn(1) @@ -49,13 +59,24 @@ func writeCSI(action byte, params []string) { // erase line case 'K': if len(params) == 0 { - eraseLine(0) + eraseLine(EraseMethod_Line) } else { - n, _ := strconv.Atoi(params[0]) - eraseLine(n) + //n, _ := strconv.Atoi(params[0]) + eraseLine(EraseMethod_Unknown) } + + // Erase screen - note; this action *looks* like it ought + // to be just [J - which is 'erase from current line to + // bottom of screen', but I actually want it to mimic [2J + // which is 'erase screen and return to top' + // + // Hopefully nobody ever uses my fork if they expect that functionality + case 'J': + eraseLine(EraseMethod_All) + setCursorHome() + default: - panic("unsupported CSI action") + // ignore } } @@ -87,6 +108,7 @@ func WriteByte(ch byte) { case errInvalidChar: parser.Reset() default: + getbackend().WriteByte(ch) // ignore } } diff --git a/drivers/cga/fbcga/fbcga.go b/drivers/cga/fbcga/fbcga.go index 55808f0..0f7a6ee 100644 --- a/drivers/cga/fbcga/fbcga.go +++ b/drivers/cga/fbcga/fbcga.go @@ -5,7 +5,7 @@ import ( "image/color" "image/draw" - "github.com/icexin/eggos/drivers/vbe" + "github.com/jspc/eggos/drivers/vbe" "golang.org/x/image/font" "golang.org/x/image/font/basicfont" diff --git a/drivers/clock/cmos.go b/drivers/clock/cmos.go index 96bae35..50f131b 100644 --- a/drivers/clock/cmos.go +++ b/drivers/clock/cmos.go @@ -3,7 +3,7 @@ package clock import ( "time" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/sys" ) type CmosTime struct { diff --git a/drivers/e1000/e1000.go b/drivers/e1000/e1000.go index bfe0564..60394de 100644 --- a/drivers/e1000/e1000.go +++ b/drivers/e1000/e1000.go @@ -6,12 +6,12 @@ import ( "time" "unsafe" - "github.com/icexin/eggos/drivers/pci" - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/inet" - "github.com/icexin/eggos/kernel/mm" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/pci" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/inet" + "github.com/jspc/eggos/kernel/mm" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/log" "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/stack" diff --git a/drivers/kbd/kbd.go b/drivers/kbd/kbd.go index a7750d4..6754dbf 100644 --- a/drivers/kbd/kbd.go +++ b/drivers/kbd/kbd.go @@ -1,9 +1,9 @@ package kbd import ( - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/kernel/trap" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/trap" ) const ( diff --git a/drivers/pci/addr.go b/drivers/pci/addr.go index e15d88d..d36ad87 100644 --- a/drivers/pci/addr.go +++ b/drivers/pci/addr.go @@ -1,6 +1,6 @@ package pci -import "github.com/icexin/eggos/kernel/sys" +import "github.com/jspc/eggos/kernel/sys" const ( configAddrPort = 0xcf8 diff --git a/drivers/pci/pci.go b/drivers/pci/pci.go index efe3b91..6aecfa4 100644 --- a/drivers/pci/pci.go +++ b/drivers/pci/pci.go @@ -1,9 +1,9 @@ package pci import ( - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/trap" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/trap" + "github.com/jspc/eggos/log" ) type Identity struct { diff --git a/drivers/pic/pic.go b/drivers/pic/pic.go index b476278..90a5858 100644 --- a/drivers/pic/pic.go +++ b/drivers/pic/pic.go @@ -1,6 +1,6 @@ package pic -import "github.com/icexin/eggos/kernel/sys" +import "github.com/jspc/eggos/kernel/sys" const ( PIC1_CMD = 0x20 diff --git a/drivers/ps2/mouse/mouse.go b/drivers/ps2/mouse/mouse.go index 25db9d3..352e92b 100644 --- a/drivers/ps2/mouse/mouse.go +++ b/drivers/ps2/mouse/mouse.go @@ -1,9 +1,9 @@ package mouse import ( - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/drivers/ps2" - "github.com/icexin/eggos/kernel/trap" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/drivers/ps2" + "github.com/jspc/eggos/kernel/trap" ) const ( diff --git a/drivers/ps2/ps2.go b/drivers/ps2/ps2.go index d13b9c7..2e230bf 100644 --- a/drivers/ps2/ps2.go +++ b/drivers/ps2/ps2.go @@ -1,6 +1,6 @@ package ps2 -import "github.com/icexin/eggos/kernel/sys" +import "github.com/jspc/eggos/kernel/sys" const ( _CMD_PORT = 0x64 diff --git a/drivers/qemu/qemu.go b/drivers/qemu/qemu.go index b041546..cfa2d5c 100644 --- a/drivers/qemu/qemu.go +++ b/drivers/qemu/qemu.go @@ -1,6 +1,6 @@ package qemu -import "github.com/icexin/eggos/kernel/sys" +import "github.com/jspc/eggos/kernel/sys" const ( qemuExitPort = 0x501 diff --git a/drivers/uart/uart.go b/drivers/uart/uart.go index 4bb4e49..a2c268c 100644 --- a/drivers/uart/uart.go +++ b/drivers/uart/uart.go @@ -1,9 +1,9 @@ package uart import ( - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/kernel/trap" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/trap" ) const ( diff --git a/drivers/vbe/fb.go b/drivers/vbe/fb.go index 00bf434..fea6926 100644 --- a/drivers/vbe/fb.go +++ b/drivers/vbe/fb.go @@ -4,9 +4,9 @@ import ( "image" "unsafe" - "github.com/icexin/eggos/drivers/multiboot" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/kernel/mm" + "github.com/jspc/eggos/drivers/multiboot" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/kernel/mm" ) const bootloaderMagic = 0x2BADB002 diff --git a/eggos.go b/eggos.go deleted file mode 100644 index 4240d24..0000000 --- a/eggos.go +++ /dev/null @@ -1,39 +0,0 @@ -package eggos - -import ( - "runtime" - - "github.com/icexin/eggos/console" - "github.com/icexin/eggos/drivers/cga/fbcga" - _ "github.com/icexin/eggos/drivers/e1000" - "github.com/icexin/eggos/drivers/kbd" - "github.com/icexin/eggos/drivers/pci" - "github.com/icexin/eggos/drivers/ps2/mouse" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/drivers/vbe" - "github.com/icexin/eggos/fs" - "github.com/icexin/eggos/inet" - "github.com/icexin/eggos/kernel" -) - -func kernelInit() { - // trap and syscall threads use two Ps, - // and the remainings are for other goroutines - runtime.GOMAXPROCS(6) - - kernel.Init() - uart.Init() - kbd.Init() - mouse.Init() - console.Init() - - fs.Init() - vbe.Init() - fbcga.Init() - pci.Init() - inet.Init() -} - -func init() { - kernelInit() -} diff --git a/fs/vfs.go b/fs/vfs.go index b53bad9..0646ea9 100644 --- a/fs/vfs.go +++ b/fs/vfs.go @@ -8,10 +8,10 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/console" - "github.com/icexin/eggos/fs/mount" - "github.com/icexin/eggos/kernel/isyscall" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/console" + "github.com/jspc/eggos/fs/mount" + "github.com/jspc/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/sys" "github.com/spf13/afero" ) @@ -215,8 +215,8 @@ func sysUname(c *isyscall.Request) { } buf := (*syscall.Utsname)(unsafe.Pointer(c.Arg(0))) copy(unsafebuf(&buf.Machine), "x86_32") - copy(unsafebuf(&buf.Domainname), "icexin.com") - copy(unsafebuf(&buf.Nodename), "icexin.local") + copy(unsafebuf(&buf.Domainname), "jspc.com") + copy(unsafebuf(&buf.Nodename), "jspc.local") copy(unsafebuf(&buf.Release), "0") copy(unsafebuf(&buf.Sysname), "eggos") copy(unsafebuf(&buf.Version), "0") diff --git a/go.mod b/go.mod index 2534a37..9f78d82 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/icexin/eggos +module github.com/jspc/eggos go 1.16 diff --git a/inet/dhcp/client.go b/inet/dhcp/client.go index 376eade..8d239dc 100644 --- a/inet/dhcp/client.go +++ b/inet/dhcp/client.go @@ -14,7 +14,7 @@ import ( "sync" "time" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/log" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/adapters/gonet" diff --git a/inet/socket.go b/inet/socket.go index 254272a..eb0aba3 100644 --- a/inet/socket.go +++ b/inet/socket.go @@ -3,7 +3,7 @@ package inet import ( "syscall" - "github.com/icexin/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/isyscall" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/network/ipv4" diff --git a/inet/sockfile.go b/inet/sockfile.go index 535ff5c..bc73bb3 100644 --- a/inet/sockfile.go +++ b/inet/sockfile.go @@ -8,15 +8,15 @@ import ( "time" "unsafe" - "github.com/icexin/eggos/fs" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/fs" + "github.com/jspc/eggos/log" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/waiter" ) -//go:linkname evnotify github.com/icexin/eggos/kernel.epollNotify +//go:linkname evnotify github.com/jspc/eggos/kernel.epollNotify func evnotify(fd, events uintptr) type sockFile struct { diff --git a/inet/stack.go b/inet/stack.go index 5873306..d97044f 100644 --- a/inet/stack.go +++ b/inet/stack.go @@ -5,8 +5,8 @@ import ( "errors" "time" - "github.com/icexin/eggos/inet/dhcp" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/inet/dhcp" + "github.com/jspc/eggos/log" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/header" diff --git a/kernel/env.go b/kernel/env.go index 530925a..b43f28f 100644 --- a/kernel/env.go +++ b/kernel/env.go @@ -3,8 +3,8 @@ package kernel import ( "unsafe" - "github.com/icexin/eggos/drivers/multiboot" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/drivers/multiboot" + "github.com/jspc/eggos/kernel/sys" "gvisor.dev/gvisor/pkg/abi/linux" ) diff --git a/kernel/epoll.go b/kernel/epoll.go index bb9bcba..feb9aa4 100644 --- a/kernel/epoll.go +++ b/kernel/epoll.go @@ -4,8 +4,8 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/kernel/isyscall" - "github.com/icexin/eggos/kernel/mm" + "github.com/jspc/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/mm" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/abi/linux/errno" ) diff --git a/kernel/init.go b/kernel/init.go index 5ca7822..f493a19 100644 --- a/kernel/init.go +++ b/kernel/init.go @@ -1,6 +1,6 @@ package kernel -import "github.com/icexin/eggos/drivers/clock" +import "github.com/jspc/eggos/drivers/clock" // called when go runtime init done func Init() { diff --git a/kernel/isyscall/syscall.go b/kernel/isyscall/syscall.go index acd7269..8461318 100644 --- a/kernel/isyscall/syscall.go +++ b/kernel/isyscall/syscall.go @@ -13,7 +13,7 @@ var ( handlers [512]Handler ) -//go:linkname wakeup github.com/icexin/eggos/kernel.wakeup +//go:linkname wakeup github.com/jspc/eggos/kernel.wakeup func wakeup(lock *uintptr, n int) type Handler func(req *Request) diff --git a/kernel/mm/mm.go b/kernel/mm/mm.go index 6a8a64f..d0f4bc2 100644 --- a/kernel/mm/mm.go +++ b/kernel/mm/mm.go @@ -3,8 +3,8 @@ package mm import ( "unsafe" - "github.com/icexin/eggos/drivers/multiboot" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/drivers/multiboot" + "github.com/jspc/eggos/kernel/sys" ) const ( @@ -36,7 +36,7 @@ func pageEnable() //go:nosplit func lcr3(topPage *entryPage) -//go:linkname throw github.com/icexin/eggos/kernel.throw +//go:linkname throw github.com/jspc/eggos/kernel.throw func throw(msg string) //go:nosplit diff --git a/kernel/mm/pool.go b/kernel/mm/pool.go index eb76ac1..f07e2d1 100644 --- a/kernel/mm/pool.go +++ b/kernel/mm/pool.go @@ -3,7 +3,7 @@ package mm import ( "unsafe" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/sys" ) //go:notinheap diff --git a/kernel/panic.go b/kernel/panic.go index f48c01d..c4fd0e2 100644 --- a/kernel/panic.go +++ b/kernel/panic.go @@ -3,10 +3,10 @@ package kernel import ( "unsafe" - "github.com/icexin/eggos/drivers/qemu" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/qemu" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/log" ) var ( diff --git a/kernel/pipe.go b/kernel/pipe.go index 115b148..eb5597a 100644 --- a/kernel/pipe.go +++ b/kernel/pipe.go @@ -4,7 +4,7 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/isyscall" ) // Timer depends on epoll and pipe. diff --git a/kernel/rt0.go b/kernel/rt0.go index bf5674c..f6cf22a 100644 --- a/kernel/rt0.go +++ b/kernel/rt0.go @@ -1,10 +1,10 @@ package kernel import ( - "github.com/icexin/eggos/drivers/multiboot" - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/kernel/mm" + "github.com/jspc/eggos/drivers/multiboot" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/kernel/mm" ) //go:nosplit diff --git a/kernel/seg_amd64.go b/kernel/seg_amd64.go index 5312092..c886609 100644 --- a/kernel/seg_amd64.go +++ b/kernel/seg_amd64.go @@ -3,7 +3,7 @@ package kernel import ( "unsafe" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/sys" ) const ( diff --git a/kernel/syscall.go b/kernel/syscall.go index a537c81..5d6100d 100644 --- a/kernel/syscall.go +++ b/kernel/syscall.go @@ -4,13 +4,13 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/drivers/qemu" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/kernel/isyscall" - "github.com/icexin/eggos/kernel/mm" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/kernel/trap" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/qemu" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/mm" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/trap" + "github.com/jspc/eggos/log" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/abi/linux/errno" diff --git a/kernel/syscall_thread.go b/kernel/syscall_thread.go index c737763..82df42f 100644 --- a/kernel/syscall_thread.go +++ b/kernel/syscall_thread.go @@ -5,9 +5,9 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/kernel/isyscall" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/log" ) var ( diff --git a/kernel/thread.go b/kernel/thread.go index c9f334e..fa0a980 100644 --- a/kernel/thread.go +++ b/kernel/thread.go @@ -3,8 +3,8 @@ package kernel import ( "unsafe" - "github.com/icexin/eggos/kernel/mm" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/mm" + "github.com/jspc/eggos/kernel/sys" ) const ( diff --git a/kernel/timer.go b/kernel/timer.go index d437d2a..622bd6c 100644 --- a/kernel/timer.go +++ b/kernel/timer.go @@ -1,9 +1,9 @@ package kernel import ( - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/kernel/trap" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/trap" "gvisor.dev/gvisor/pkg/abi/linux" ) diff --git a/kernel/trap.go b/kernel/trap.go index d9666cb..4b80137 100644 --- a/kernel/trap.go +++ b/kernel/trap.go @@ -3,11 +3,11 @@ package kernel import ( "unsafe" - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/isyscall" - "github.com/icexin/eggos/kernel/sys" - "github.com/icexin/eggos/kernel/trap" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/isyscall" + "github.com/jspc/eggos/kernel/sys" + "github.com/jspc/eggos/kernel/trap" + "github.com/jspc/eggos/log" ) var ( diff --git a/kernel/trap_thread.go b/kernel/trap_thread.go index 12bce71..459ac43 100644 --- a/kernel/trap_thread.go +++ b/kernel/trap_thread.go @@ -6,9 +6,9 @@ import ( "syscall" "unsafe" - "github.com/icexin/eggos/drivers/pic" - "github.com/icexin/eggos/kernel/trap" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/drivers/pic" + "github.com/jspc/eggos/kernel/trap" + "github.com/jspc/eggos/log" ) var ( diff --git a/log/log.go b/log/log.go index 85d05f6..29e3750 100644 --- a/log/log.go +++ b/log/log.go @@ -5,9 +5,9 @@ import ( "fmt" "os" - "github.com/icexin/eggos/console" - "github.com/icexin/eggos/drivers/uart" - "github.com/icexin/eggos/kernel/sys" + "github.com/jspc/eggos/console" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/kernel/sys" ) type LogLevel int8 diff --git a/log/log_test.go b/log/log_test.go index 7e0a3de..60e29e3 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -3,7 +3,7 @@ package log_test import ( "testing" - "github.com/icexin/eggos/log" + "github.com/jspc/eggos/log" ) func ExampleSetLogLevel() { diff --git a/magefile.go b/magefile.go index 3185c7f..45c4876 100644 --- a/magefile.go +++ b/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main @@ -157,6 +158,11 @@ func Egg() error { return nil } +func Includes() error { + mg.Deps(Egg) + return sh.RunV(eggBin, "generate") +} + func Clean() { rmGlob("*.o") rmGlob("kernel.elf") diff --git a/tests/net_test.go b/tests/net_test.go index 7df5227..672cc93 100644 --- a/tests/net_test.go +++ b/tests/net_test.go @@ -4,8 +4,6 @@ import ( "net" "net/http" "testing" - - _ "github.com/icexin/eggos" ) func TestHTTP(t *testing.T) { diff --git a/zz_load_eggos.go b/zz_load_eggos.go new file mode 100644 index 0000000..5b2359d --- /dev/null +++ b/zz_load_eggos.go @@ -0,0 +1,40 @@ +//+build eggos +package eggos + +import ( + "runtime" + + "github.com/jspc/eggos/console" + "github.com/jspc/eggos/drivers/cga/fbcga" + _ "github.com/jspc/eggos/drivers/e1000" + "github.com/jspc/eggos/drivers/kbd" + "github.com/jspc/eggos/drivers/pci" + "github.com/jspc/eggos/drivers/ps2/mouse" + "github.com/jspc/eggos/drivers/uart" + "github.com/jspc/eggos/drivers/vbe" + "github.com/jspc/eggos/fs" + "github.com/jspc/eggos/inet" + "github.com/jspc/eggos/kernel" +) + +func kernelInit() { + // trap and syscall threads use two Ps, + // and the remainings are for other goroutines + runtime.GOMAXPROCS(6) + + kernel.Init() + uart.Init() + kbd.Init() + mouse.Init() + console.Init() + + fs.Init() + vbe.Init() + fbcga.Init() + pci.Init() + inet.Init() +} + +func init() { + kernelInit() +}