intermezzOS / book

The main docs for intermezzOS
http://intermezzos.github.io/book
367 stars 79 forks source link

Doesn't display "OKAY" on screen. #170

Closed violetastcs closed 6 years ago

violetastcs commented 7 years ago

Ok. So I have completed the book and, up until the rust, it was fine.

However, when I started implementing rust, it stopped working. I done everything needed for running the rust code, and there were no compilation errors. Here is my makefile (i'm using windows-ubuntu bash):

default: clean

.PHONY: clean

target/multiboot_header.o: src/asm/multiboot_header.asm
    mkdir -p target
    nasm -f elf64 src/asm/multiboot_header.asm -o target/multiboot_header.o

target/boot.o: src/asm/boot.asm
    mkdir -p target
    nasm -f elf64 src/asm/boot.asm -o target/boot.o

cargo:
    xargo.exe build --release --target x86_64-unknown-oxideos-gnu

target/kernel.bin: target/multiboot_header.o target/boot.o src/asm/linker.ld cargo
    mkdir -p target
    ld -n -o target/kernel.bin -T src/asm/linker.ld target/multiboot_header.o target/boot.o target/x86_64-unknown-oxideos-gnu/release/liboxideos.a

os.iso: target/kernel.bin src/asm/grub.cfg
    mkdir -p isofiles/boot/grub
    cp src/asm/grub.cfg isofiles/boot/grub
    cp target/kernel.bin isofiles/boot/
    grub-mkrescue -o os.iso isofiles

build: os.iso

run: build
    qemu-system-x86_64.exe -drive \format=raw,file=os.iso

clean: build run
    cargo.exe clean

My boot.asm:

extern kmain

global start

section .text
bits 32
start:
    ; Point the first entry of the level 4 page table to the first entry in the p3 table

    mov eax, p3_table
    or eax, 0b11
    mov dword [p4_table + 0], eax

    ; p2
    mov eax, p2_table
    or eax, 0b11
    mov dword [p3_table + 0], eax

    mov ecx, 0
.map_p2_table:
    mov eax, 0x200000       ; 2 MiB
    mul ecx
    or eax, 0b100000011
    mov [p2_table + ecx * 8], eax

    inc ecx
    cmp ecx, 512
    jmp .map_p2_table

    ; move page table address to cr3
    mov eax, p4_table
    mov cr3, eax

    ; enable PAE
    mov eax, cr4
    or eax, 1 << 5
    mov cr4, eax

    ; set the long mode bit
    mov ecx, 0xC0000080
    rdmsr
    or eax, 1 << 8
    wrmsr

    ; enable paging
    mov eax, cr0
    or eax, 1 << 31
    or eax, 1 << 16
    mov cr0, eax

    ; update selectors
    mov ax, gdt64.data
    mov ss, ax
    mov ds, ax
    mov es, ax

    ; jump to long mode
    jmp gdt64.code:kmain

section .bss

align 4096

p4_table:
    resb 4096
p3_table:
    resb 4096
p2_table:
    resb 4096

section .rodata
gdt64:
    dq 0

.code: equ $ - gdt64
    ;dq (1<<44) | (1<<47) | (1<<41) | (1<<43) | (1<<53)

.data: equ $ - gdt64
    ;dq (1<<44) | (1<<47) | (1<<41)

.pointer:
    dw .pointer - gdt64 - 1
    dq gdt64
    lgdt [gdt64.pointer]

section .text
bits 64

and my rust code:

#![feature(lang_items)]
#![no_std]

#[lang = "eh_personality"]
extern fn eh_personality() {

}

#[lang = "panic_fmt"]
extern fn rust_begin_panic() -> ! {
    loop {}
}

#[no_mangle]
pub extern fn kmain() -> ! {

    unsafe {
        let vga = 0xb8000 as *mut u64;

        *vga = 0x2f592f412f4b2f4f;
    };

    loop { }

}

All it does is print "GRUB", which I added back when the book was adding 64 bit.

Thanks in advance

steveklabnik commented 7 years ago

Hey @JacobSinclair ! Sorry this took me some time to look at.

One quick note:

xargo.exe build

are you running this on Windows?

EDIT: I can't read

Here is my makefile (i'm using windows-ubuntu bash):

So, I'm not entirely sure .exe is right here... as it'd be just a regular old Linux program.

violetastcs commented 7 years ago

@steveklabnik Well, for some reason I can't use the version of xargo I have for ubuntu on it, it just throws an error. But when I was to do other things with xargo.exe, it would work fine. There are only a few programs I don't use a windows version for.

steveklabnik commented 6 years ago

Hey @JacobSinclair , sorry we never got this resolved :( over the next few weeks, the second edition should be up to par with the first, and the build is much easier; give it a shot and it should work much better for you.