-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
amd64 "port" boots and prints "Hello World" to debug
- Loading branch information
1 parent
7b8d06d
commit af7c1f3
Showing
7 changed files
with
316 additions
and
23 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ ARCH ?= amd64 | |
RUSTC ?= rustc | ||
ifeq ($(ARCH),amd64) | ||
LD := x86_64-elf-ld | ||
LD := x86_64-elf-ld | ||
AS := x86_64-elf-as | ||
OBJDUMP := x86_64-elf-objdump | ||
else ifeq ($(ARCH),x86) | ||
LD := i586-elf-ld | ||
|
@@ -22,31 +22,45 @@ OBJDIR := .obj/$(ARCH)/ | |
# Compiler Options | ||
LINKFLAGS := -T arch/$(ARCH)/link.ld | ||
LINKFLAGS += -Map $(OBJDIR)map.txt | ||
LINKFLAGS += -z max-page-size=0x1000 | ||
RUSTFLAGS := -O --cfg arch__$(ARCH) --target=arch/$(ARCH)/target.json | ||
|
||
# Objects | ||
LIBCORE := $(OBJDIR)libcore.rlib | ||
OBJS := start.o kernel.o libcore.rlib | ||
|
||
OBJS := $(OBJS:%=$(OBJDIR)%) | ||
BIN := ../kernel.$(ARCH).bin | ||
|
||
.PHONY: all clean | ||
|
||
all: ../kernel.$(ARCH).bin | ||
|
||
clean: | ||
$(RM) -rf ../kernel.$(ARCH).bin $(OBJDIR) | ||
$(RM) -rf $(BIN) $(BIN).dsm $(OBJDIR) | ||
|
||
../kernel.$(ARCH).bin: $(OBJS) arch/$(ARCH)/link.ld | ||
# Final link command | ||
$(BIN): $(OBJS) arch/$(ARCH)/link.ld | ||
$(LD) -o $@ $(LINKFLAGS) $(OBJS) | ||
$(OBJDUMP) -S $@ > $@.dsm | ||
ifeq ($(ARCH),amd64) | ||
@mv $@ [email protected] | ||
@x86_64-elf-objcopy [email protected] -F elf32-i386 $@ | ||
endif | ||
|
||
$(OBJDIR)libcore.rlib: ../libcore/lib.rs | ||
# Compile libcore from ../libcore/ | ||
$(OBJDIR)libcore.rlib: ../libcore/lib.rs Makefile | ||
@mkdir -p $(dir $@) | ||
$(RUSTC) $(RUSTFLAGS) -o $@ --crate-type=lib $< | ||
$(RUSTC) $(RUSTFLAGS) -o $@ --crate-type=lib --emit=link,dep-info $< | ||
|
||
$(OBJDIR)kernel.o: main.rs $(LIBCORE) | ||
# Compile rust kernel object | ||
$(OBJDIR)kernel.o: main.rs $(LIBCORE) Makefile | ||
@mkdir -p $(dir $@) | ||
$(RUSTC) $(RUSTFLAGS) -o $@ --emit=obj $< --extern core=$(LIBCORE) | ||
$(RUSTC) $(RUSTFLAGS) -o $@ --emit=obj,dep-info $< --extern core=$(LIBCORE) | ||
|
||
$(OBJDIR)start.o: arch/$(ARCH)/start.S | ||
# Compile architecture's assembly stub | ||
$(OBJDIR)start.o: arch/$(ARCH)/start.S Makefile | ||
@mkdir -p $(dir $@) | ||
$(AS) $(ASFLAGS) -o $@ $< | ||
|
||
# Include dependency files | ||
-include $(OBJ:%=%.d) |
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,43 @@ | ||
/* | ||
* Rust BareBones OS | ||
* - By John Hodge (Mutabah/thePowersGang) | ||
* | ||
* arch/amd64/debug.rs | ||
* - Debug output channel | ||
* | ||
* Writes debug to the standard PC serial port (0x3F8 .. 0x3FF) | ||
* | ||
* == LICENCE == | ||
* This code has been put into the public domain, there are no restrictions on | ||
* its use, and the author takes no liability. | ||
*/ | ||
use prelude::*; | ||
|
||
/// Write a string to the output channel | ||
/// | ||
/// This method is unsafe because it does port accesses without synchronisation | ||
pub unsafe fn puts(s: &str) | ||
{ | ||
for b in s.bytes() | ||
{ | ||
putb(b); | ||
} | ||
} | ||
|
||
/// Write a single byte to the output channel | ||
/// | ||
/// This method is unsafe because it does port accesses without synchronisation | ||
pub unsafe fn putb(b: u8) | ||
{ | ||
// Wait for the serial port's fifo to not be empty | ||
while (::arch::x86_io::inb(0x3F8+5) & 0x20) == 0 | ||
{ | ||
// Do nothing | ||
} | ||
// Send the byte out the serial port | ||
::arch::x86_io::outb(0x3F8, b); | ||
|
||
// Also send to the bochs 0xe9 hack | ||
::arch::x86_io::outb(0xe9, b); | ||
} | ||
|
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
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,18 @@ | ||
/* | ||
* Rust BareBones OS | ||
* - By John Hodge (Mutabah/thePowersGang) | ||
* | ||
* arch/amd64/mod.rs | ||
* - Top-level file for amd64 architecture | ||
* | ||
* == LICENCE == | ||
* This code has been put into the public domain, there are no restrictions on | ||
* its use, and the author takes no liability. | ||
*/ | ||
|
||
// x86 port IO | ||
mod x86_io; | ||
|
||
// Debug output channel (uses serial) | ||
pub mod debug; | ||
|
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
Oops, something went wrong.