-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 14d7544
Showing
92 changed files
with
11,988 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#set architecture i386:x86-64:intel | ||
set architecture i386 | ||
#file kernel.elf | ||
#set architecture i386:x86-64 | ||
#target remote :1234 | ||
|
||
define xbt | ||
set $tid=$arg0 | ||
set $save_pc = $pc | ||
set $save_sp = $sp | ||
select-frame 0 | ||
set $pc = 'github.com/icexin/eggos/kernel.threads'[$tid].tf.IP | ||
set $sp = 'github.com/icexin/eggos/kernel.threads'[$tid].tf.SP | ||
bt | ||
|
||
set $pc = $save_pc | ||
set $sp = $save_sp | ||
end | ||
|
||
define xps | ||
set $i = 0 | ||
while $i < 20 | ||
set $t = 'github.com/icexin/eggos/kernel.threads'[$i] | ||
set $addr = 0 | ||
if $t.tf != 0 | ||
set $addr = $t.tf.IP | ||
end | ||
printf "thread[%d]={state=%d, counter=%d, pc=0x%x lock=0x%x}", $i, $t.state, $t.counter, $addr, $t.sleepKey | ||
if $t.sleepKey != 0 | ||
x $t.sleepKey | ||
end | ||
set $i = $i+1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.o | ||
*.elf | ||
*.log | ||
*.pcap | ||
*.img | ||
*.hdd | ||
|
||
bootblock | ||
serial | ||
trace.txt | ||
sync.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "gdb", | ||
"request": "attach", | ||
"name": "Attach to qemu", | ||
"executable": "./kernel.elf", | ||
"target": ":1234", | ||
"remote": true, | ||
"cwd": "${workspaceRoot}", | ||
"valuesFormatting": "parseText", | ||
"gdbpath": "gdb", | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"go.toolsEnvVars": { | ||
"GOOS": "linux", | ||
"GOARCH": "386", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#TOOLPREFIX=i386-elf- | ||
ifndef TOOLPREFIX | ||
TOOLPREFIX := $(shell if i386-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \ | ||
then echo 'i386-elf-'; \ | ||
elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \ | ||
then echo ''; \ | ||
else echo "***" 1>&2; \ | ||
echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \ | ||
echo "*** Is the directory with i386-elf-gcc in your PATH?" 1>&2; \ | ||
echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \ | ||
echo "*** prefix other than 'i386-elf-', set your TOOLPREFIX" 1>&2; \ | ||
echo "*** environment variable to that prefix and run 'make' again." 1>&2; \ | ||
echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \ | ||
echo "***" 1>&2; exit 1; fi) | ||
endif | ||
|
||
CC = $(TOOLPREFIX)gcc | ||
AS = $(TOOLPREFIX)gas | ||
LD = $(TOOLPREFIX)ld | ||
OBJCOPY = $(TOOLPREFIX)objcopy | ||
OBJDUMP = $(TOOLPREFIX)objdump | ||
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -ggdb -m32 -Werror -fno-omit-frame-pointer | ||
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) | ||
ASFLAGS = -m32 -gdwarf-2 -Wa,-divide | ||
# FreeBSD ld wants ``elf_i386_fbsd'' | ||
LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null | head -n 1) | ||
|
||
# Disable PIE when possible (for Ubuntu 16.10 toolchain) | ||
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),) | ||
CFLAGS += -fno-pie -no-pie | ||
endif | ||
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),) | ||
CFLAGS += -fno-pie -nopie | ||
endif | ||
|
||
QEMU_OPT = -m 256M -no-reboot -serial mon:stdio \ | ||
-netdev user,id=eth0,hostfwd=tcp::8080-:80,hostfwd=tcp::8081-:22 \ | ||
-device e1000,netdev=eth0 \ | ||
|
||
|
||
QEMU_DEBUG_OPT = $(QEMU_OPT) -d int -D qemu.log \ | ||
-object filter-dump,id=f1,netdev=eth0,file=qemu.pcap \ | ||
-s -S | ||
|
||
# TAGS = "gin sshd nes jsapp" | ||
TAGS = "jsapp" | ||
|
||
.PHONY: all clean kernel.elf | ||
|
||
all: multiboot.elf | ||
|
||
kernel.elf: | ||
GOOS=linux GOARCH=386 go build -o kernel.elf -tags $(TAGS) -ldflags '-E github.com/icexin/eggos/kernel.rt0 -T 0x100000' ./kmain | ||
|
||
multiboot.elf: boot/multiboot_header.S boot/multiboot.c kernel.elf | ||
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c boot/multiboot.c | ||
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c boot/multiboot_header.S | ||
$(LD) $(LDFLAGS) -N -e _start -Ttext 0x3200000 -o multiboot.elf multiboot.o multiboot_header.o -b binary kernel.elf | ||
|
||
qemu-debug: | ||
qemu-system-i386 $(QEMU_DEBUG_OPT) -nographic -kernel multiboot.elf | ||
|
||
qemu: | ||
qemu-system-x86_64 $(QEMU_OPT) -nographic -M accel=hvf -kernel multiboot.elf | ||
|
||
grub: multiboot.elf | ||
mount -t msdos /dev/disk2s1 osimg | ||
cp multiboot.elf osimg/grub/ | ||
sync | ||
sleep 2 | ||
umount osimg | ||
qemu-system-x86_64 $(QEMU_OPT) -M accel=hvf /dev/disk2 | ||
|
||
grub-debug: multiboot.elf | ||
mount -t msdos /dev/disk2s1 osimg | ||
cp multiboot.elf osimg/grub/ | ||
sync | ||
sleep 2 | ||
umount osimg | ||
qemu-system-i386 $(QEMU_DEBUG_OPT) /dev/disk2 | ||
|
||
clean: | ||
rm -f *.o *.log kernel.elf multiboot.elf qemu.pcap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package app | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"sort" | ||
|
||
"github.com/icexin/eggos/fs" | ||
"github.com/peterh/liner" | ||
) | ||
|
||
type Context struct { | ||
Args []string | ||
Stdin io.Reader | ||
Stdout io.Writer | ||
Stderr io.Writer | ||
|
||
flag *flag.FlagSet | ||
liner *liner.State | ||
} | ||
|
||
func (c *Context) Printf(fmtstr string, args ...interface{}) { | ||
fmt.Fprintf(c.Stdout, fmtstr, args...) | ||
} | ||
|
||
func (c *Context) Flag() *flag.FlagSet { | ||
if c.flag != nil { | ||
return c.flag | ||
} | ||
c.flag = flag.NewFlagSet(c.Args[0], flag.ContinueOnError) | ||
return c.flag | ||
} | ||
|
||
func (c *Context) ParseFlags() error { | ||
return c.Flag().Parse(c.Args[1:]) | ||
} | ||
|
||
func (c *Context) LineReader() LineReader { | ||
_, ok := c.Stdin.(fs.Ioctler) | ||
if !ok { | ||
return newSimpleLineReader(c.Stdin, c.Stdout) | ||
} | ||
return newLineEditor() | ||
} | ||
|
||
type AppEntry func(ctx *Context) error | ||
|
||
var apps = map[string]AppEntry{} | ||
|
||
func Register(name string, app AppEntry) { | ||
apps[name] = app | ||
} | ||
|
||
func Get(name string) AppEntry { | ||
return apps[name] | ||
} | ||
|
||
func AppNames() []string { | ||
var l []string | ||
for name := range apps { | ||
l = append(l, name) | ||
} | ||
sort.Strings(l) | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/icexin/eggos/app" | ||
) | ||
|
||
func echomain(ctx *app.Context) error { | ||
if len(ctx.Args) == 1 { | ||
fmt.Fprintf(ctx.Stdout, "\n") | ||
return nil | ||
} | ||
fmt.Fprintf(ctx.Stdout, "%s\n", strings.Join(ctx.Args[1:], " ")) | ||
return nil | ||
} | ||
|
||
func init() { | ||
app.Register("echo", echomain) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/icexin/eggos/app" | ||
"github.com/peterh/liner" | ||
) | ||
|
||
func linemain(ctx *app.Context) error { | ||
fmt.Println(os.Environ()) | ||
fmt.Println(liner.TerminalSupported()) | ||
|
||
r := liner.NewLiner() | ||
defer r.Close() | ||
for { | ||
line, err := r.Prompt(">>> ") | ||
if err != nil { | ||
break | ||
} | ||
fmt.Println(line) | ||
r.AppendHistory(line) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
app.Register("line", linemain) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/icexin/eggos/app" | ||
) | ||
|
||
func memtestmain(ctx *app.Context) error { | ||
if len(ctx.Args) < 2 { | ||
fmt.Fprintln(ctx.Stderr, "usage: memtest $duration") | ||
return nil | ||
} | ||
|
||
dura, err := time.ParseDuration(ctx.Args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
deadline := time.Now().Add(dura) | ||
for { | ||
if time.Now().After(deadline) { | ||
return nil | ||
} | ||
|
||
buf := make([]byte, 1024) | ||
rand.Read(buf) | ||
fmt.Fprintf(ioutil.Discard, "%v", buf) | ||
} | ||
} | ||
|
||
func init() { | ||
app.Register("memtest", memtestmain) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
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" | ||
) | ||
|
||
func mountmain(ctx *app.Context) error { | ||
if len(ctx.Args) < 3 { | ||
return errors.New("usage: mount $uri target") | ||
} | ||
uristr, target := ctx.Args[1], ctx.Args[2] | ||
uri, err := url.Parse(uristr) | ||
if err != nil { | ||
return err | ||
} | ||
switch uri.Scheme { | ||
case "smb": | ||
return mountsmb(uri, target) | ||
default: | ||
return errors.New("unsupported scheme " + uri.Scheme) | ||
} | ||
} | ||
|
||
func mountsmb(uri *url.URL, target string) error { | ||
passwd, _ := uri.User.Password() | ||
smbfs, err := smb.New(&smb.Config{ | ||
Host: uri.Host, | ||
User: uri.User.Username(), | ||
Password: passwd, | ||
Mount: uri.Path[1:], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return fs.Mount(target, stripprefix.New("/", smbfs)) | ||
} | ||
|
||
func init() { | ||
app.Register("mount", mountmain) | ||
} |
Oops, something went wrong.