Skip to content

Commit

Permalink
add basic 32bit support for x86
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 11, 2024
1 parent 2a06e77 commit 6cf6233
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 210 deletions.
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ build-std-features = ["compiler-builtins-mem"]
[build]
target = "x86_64-eduos.json"

[target.aarch64-eduos]
[target.i686-eduos]
rustflags = [
"-C", "link-arg=-Tlink_aarch64.ld"
"-C", "link-arg=-Tsrc/arch/x86/link_i686.ld", "-C", "relocation-model=static"
]
runner = "qemu-system-aarch64 -display none -serial stdio -machine virt,gic-version=3 -cpu cortex-a72 -semihosting -smp 1 -m 256M --kernel"
runner = "qemu-system-x86_64 -display none -serial stdio -smp 1 -m 256M --kernel"

[target.x86_64-eduos]
runner = "bootimage runner"
4 changes: 2 additions & 2 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
- name: Build (x86_64)
run:
cargo build
- name: Build (aarch64)
- name: Build (i686)
run:
cargo build --target=aarch64-eduos.json
cargo build --target=i686-eduos.json
- name: run (ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: ./test.sh
Expand Down
141 changes: 0 additions & 141 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ run-args = []
[dependencies]
spinning_top = "0.3.0"

[target.'cfg(target_arch = "aarch64")'.dependencies]
semihosting = "0.1.9"

[target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = "0.9.29"
x86 = { version = "0.52", default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.92" }
web-sys = { version = "0.3.4", features = ['Document','Element','HtmlElement','Node','Window',] }
[target.'cfg(target_arch = "x86")'.dependencies]
x86 = { version = "0.52", default-features = false }
14 changes: 14 additions & 0 deletions i686-eduos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"llvm-target": "i686-unknown-none",
"target-endian": "little",
"target-pointer-width": "32",
"target-c-int-width": "32",
"os": "none",
"arch": "x86",
"data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
"features": "-mmx,-sse,+soft-float",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort"
}
40 changes: 0 additions & 40 deletions link_aarch64.ld

This file was deleted.

18 changes: 5 additions & 13 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// Export our platform-specific modules.
#[cfg(target_arch = "x86_64")]
pub use self::x86_64::{processor, serial};
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
pub use self::x86::{processor, serial};

// Implementations for x86_64.
#[cfg(target_arch = "x86_64")]
pub mod x86_64;

// Export our platform-specific modules.
#[cfg(target_arch = "x86")]
pub use self::x86_64::{processor, serial};

// Implementations for x86_64.
#[cfg(target_arch = "x86")]
pub mod x86_64;
// Implementations for x86.
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
pub mod x86;
53 changes: 53 additions & 0 deletions src/arch/x86/entry.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is the kernel's entry point. We could either call main here,
# or we can use this to setup the stack or other nice stuff, like
# perhaps setting up the GDT and segments. Please note that interrupts
# are disabled at this point: More on interrupts later!

.code32

.set BOOT_STACK_SIZE, 4096

# We use a special name to map this section at the begin of our kernel
# => Multiboot expects its magic number at the beginning of the kernel.
.section .mboot, "a"

# This part MUST be 4 byte aligned, so we solve that issue using '.align 4'.
.align 4
.global mboot
mboot:
# Multiboot macros to make a few lines more readable later
.set MULTIBOOT_PAGE_ALIGN, (1 << 0)
.set MULTIBOOT_MEMORY_INFO, (1 << 1)
.set MULTIBOOT_HEADER_MAGIC, 0x1BADB002
.set MULTIBOOT_HEADER_FLAGS, MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
.set MULTIBOOT_CHECKSUM, -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

# This is the GRUB Multiboot header. A boot signature
.4byte MULTIBOOT_HEADER_MAGIC
.4byte MULTIBOOT_HEADER_FLAGS
.4byte MULTIBOOT_CHECKSUM
.4byte 0, 0, 0, 0, 0 # address fields

.section .text
.align 4
.extern main
.global _start
_start:
cli # avoid any interrupt

# Initialize stack pointer
mov esp, OFFSET boot_stack
add esp, BOOT_STACK_SIZE - 16

call main
# eax has the return value of main
mov dx, 0xf4 # port to shutdown pc
out dx, eax
L0:
jmp L0

.section .data
.align 4096
.global boot_stack
boot_stack:
.fill BOOT_STACK_SIZE, 1, 0xcd
26 changes: 26 additions & 0 deletions src/arch/x86/link_i686.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ENTRY(_start)
phys = 0x000000100000;

SECTIONS
{
kernel_start = phys;
.mboot phys : AT(ADDR(.mboot)) {
*(.mboot)
}
.text ALIGN(4096) : AT(ADDR(.text)) {
*(.text)
*(.text.*)
}
.rodata ALIGN(4096) : AT(ADDR(.rodata)) {
*(.rodata)
*(.rodata.*)
}
.data ALIGN(4096) : AT(ADDR(.data)) {
*(.data)
*(.data.*)
}
.bss ALIGN(4096) : AT(ADDR(.bss)) {
*(.bss)
*(.bss.*)
}
}
4 changes: 4 additions & 0 deletions src/arch/x86/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub mod processor;
pub mod serial;
#[cfg(target_arch = "x86_64")]
pub mod start;

#[cfg(target_arch = "x86")]
core::arch::global_asm!(include_str!("entry.s"));
2 changes: 1 addition & 1 deletion src/arch/x86/start.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::arch::x86_64::processor::shutdown;
use crate::arch::x86::processor::shutdown;

extern "C" {
fn main() -> i32;
Expand Down
Loading

0 comments on commit 6cf6233

Please sign in to comment.