Skip to content

Commit

Permalink
Boot2Snow: Now work kernel load
Browse files Browse the repository at this point in the history
  • Loading branch information
ANEP-ET committed Mar 29, 2018
0 parents commit d9044b0
Show file tree
Hide file tree
Showing 61 changed files with 61,218 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/
target/
**/*.rs.bk
Cargo.lock
.DS_Store
**/.DS_Store
virtual.log
bc_flags
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files.associations": {
"*.inc": "cpp",
"*.def": "cpp",
"array": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"optional": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"bitset": "cpp",
"list": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
53 changes: 53 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "make run",
"type": "shell",
"command": "make run",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "make run-debug",
"type": "shell",
"command": "make run-debug",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "make clean",
"type": "shell",
"command": "make clean",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "make all",
"type": "shell",
"command": "make all",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "x86_64-linux env",
"type": "shell",
"command": "sh x86_64-linux_env.sh",
},
{
"taskName": "gdb",
"type": "shell",
"command": "rust-gdb build/kernel/kernel.bin.sym -ex 'target remote :1234'",
}
]
}
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017, SnowWhiteOS
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
arch ?= x86_64
target ?= $(arch)-snowflake
boot2snow := build/arch/$(arch)/boot2snow/bootx64.efi
kernel := build/kernel/kernel.bin
img := build/snowflake-$(arch).img

CARGO = cargo
NASM = nasm

LD = $(arch)-elf-ld
AS = $(arch)-elf-as
OBJCOPY = $(arch)-elf-objcopy
STRIP = $(arch)-elf-strip

.PHONY: all clean run run-debug img
all: $(img)

clean:
@rm -r build #target

run: $(img)
@qemu-system-x86_64 -bios ovmf.fd $(img)

run-debug: $(img)
@qemu-system-x86_64 -s -S -bios ovmf.fd $(img)

img: $(img)

$(img):
@make -C arch/$(arch)/boot2snow
@make -C kernel
@dd if=/dev/zero of=$(img).tmp bs=512 count=98304
@mkfs.vfat $(img).tmp
@mmd -i $(img).tmp ::/boot2snow
@mmd -i $(img).tmp ::/efi
@mmd -i $(img).tmp ::/efi/boot
@mcopy -i $(img).tmp $(kernel) ::/boot2snow
@mcopy -i $(img).tmp res/only_logo.bmp ::/boot2snow
@mcopy -i $(img).tmp res/full_logo.bmp ::/boot2snow
@mcopy -i $(img).tmp res/boot2snow.conf ::/boot2snow
@mcopy -i $(img).tmp $(boot2snow) ::/efi/boot
@dd if=/dev/zero of=$@ bs=512 count=100352
@parted $@ -s -a minimal mklabel gpt
@parted $@ -s -a minimal mkpart EFI FAT32 2048s 93716s
@parted $@ -s -a minimal toggle 1 boot
@dd if=$@.tmp of=$@ bs=512 count=98304 seek=2048 conv=notrunc
@rm -rf $@.tmp
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# ![SnowFlake](./logo.png)

[![BSD-3-Clause][s1]][li]

[s1]: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg

[li]: LICENSE

Technology is free, SnowFlakeOS

## Library used
- utf16_literal (https://github.com/thepowersgang/rust_os/tree/master/Bootloaders/libuefi/utf16_literal)
- uefi (forked, https://github.com/SnowFlakeOS/rust-uefi)
- x86 (https://github.com/gz/rust-x86)

## TODO
### Boot2Snow (x86_64, UEFI)
- [x] Basical UI (from https://github.com/system76/firmware-update)
- [x] Load kernel from disk
### SnowKernel (ExoKernel)
- [ ] Load kernel as higher half (0xffffffff80000000)
- [ ] Better GUI library support
- [ ] Write I/O drivers (keyboard, mouse, etc.)
- [ ] Multitasking support
- [ ] Write syscall
- [ ] Write init process
### FlakeOS (LibOS)

## Building
Requirements to build
- Rust (https://www.rust-lang.org)
- NASM (http://www.nasm.us/)
- GCC Toolchain or GCC (https://gcc.gnu.org/)

### Windows
Will be added later

### Mac
The default linker of the macOS is BSD linker so it can't linked Snowflake.
If you want build SnowFlake on macOS
- Need HomeBrew (https://brew.sh/)
- Need Xcode Command Line Tools (This will install both HomeBrew)
- Need NASM (can install in HomeBrew)
- Need QEMU (if you want run SnowFlake)
```
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ homebrew install nasm qemu crystal
$ git clone https://github.com/SnowFlake/mac-binutils-script.git
$ cd mac-binutils-script
$ sudo ./compile.sh
$ git clone https://github.com/SnowFlake/SnowFlake.git
$ cd SnowWhite
$ make run
```

### Linux
To build SnowFlake as an x86_64 target, x86_64-elf cross-compilation is required.
If you do not have the x86_64-elf compiler, and your system is x86_64, you can use the 'x86_64-linux_env.sh' script.
```
$ sh x86_64-linux_env.sh
```
#### Arch Linux
```
$ pacman -S qemu nasm mtools
$ git clone https://github.com/SnowFlake/SnowFlake.git
$ cd SnowWhite
$ make run
```

## Thanks to
- https://github.com/phil-opp/blog_os
- https://github.com/beevik/MonkOS
- https://github.com/thepowersgang/rust_os
- https://github.com/wichtounet/thor-os
- https://github.com/anchovieshat/cathode
- https://github.com/TheKernelCorp/NuummiteOS
- https://github.com/redox-os/orbclient
- https://github.com/redox-os/uefi
- https://github.com/system76/firmware-update
14 changes: 14 additions & 0 deletions arch/x86_64/boot2snow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "Boot2Snow"
version = "0.1.0"
authors = ["xuserwhat <[email protected]>"]

[dependencies]
uefi = {path = "../../../share/libuefi"}
rlibc = "1.0"
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins" }
utf16_literal = "0.1.0"

[lib]
name = "Boot2Snow"
crate-type = ["staticlib"]
36 changes: 36 additions & 0 deletions arch/x86_64/boot2snow/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
arch ?= x86_64
target_arch ?= $(arch)-boot2snow

LD = $(arch)-efi-pe-ld
AS = $(arch)-efi-pe-as
AR = $(arch)-efi-pe-ar
STRIP = $(arch)-efi-pe-strip
OBJDUMP = $(arch)-efi-pe-objdump

CARGO = xargo
CARGOFLAGS = --target $(target_arch) --release -- -C soft-float

BUILD_DIR = ../../../build/arch/x86_64/boot2snow

boot2snow = $(BUILD_DIR)/bootx64.efi
boot2snow_obj = $(BUILD_DIR)/target/$(target_arch)/release/libBoot2Snow.a

objs = $(boot2snow_obj).o

.PHONY: all

all: $(boot2snow)

$(boot2snow): $(objs)
@mkdir -p $(shell dirname $@)
@$(LD) --gc-sections --oformat pei-x86-64 --subsystem 10 -pie -e _start $< -o $@
@$(OBJDUMP) -d $@ > $@.dsm
@$(STRIP) $@

$(boot2snow_obj).o: $(boot2snow_obj)
@cd $(shell dirname $<) && $(AR) x libBoot2Snow.a
@$(LD) -r $(shell dirname $<)/*.o -o $@

$(boot2snow_obj):
@mkdir -p $(shell dirname $@)
@RUST_TARGET_PATH=$(abspath .) CARGO_TARGET_DIR=$(BUILD_DIR)/target $(CARGO) rustc --lib $(CARGOFLAGS) -C lto --emit link=$@
1 change: 1 addition & 0 deletions arch/x86_64/boot2snow/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[dependencies.alloc]
Loading

0 comments on commit d9044b0

Please sign in to comment.