bare-metal

Relocation in assembly

走远了吗. 提交于 2019-11-27 15:44:20
I have a boot-up code for a bare-metal ARM written in assembly and I'm trying to understand how it works. The binary is written in some external Flash, and is copying parts of itself in RAM at boot-up. I still didn't exactly get the concept of relocation in this context, even though I read this wikipedia entry . The RAM is mapped to a low address window, and the flash in a high address window. Can someone explain to me why we test the value of the link register here? /* Test if we are running from an address, we are not linked at */ bl check_position check_position: mov r0, lr ldr r1, =check

How to produce a minimal BIOS hello world boot sector with GCC that works from a USB stick on real hardware?

人走茶凉 提交于 2019-11-27 14:44:22
I have managed to produce a minimal boot sector that works with QEMU 2.0.0 Ubuntu 14.04: .code16 .global _start _start: cli mov $msg, %si mov $0x0e, %ah loop: lodsb or %al, %al jz halt int $0x10 jmp loop halt: hlt msg: .asciz "hello world" .org 510 .word 0xaa55 Compiled with: as -o main.o main.S ld --oformat binary -o main.img -Ttext 0x7C00 main.o The example is available on this repo: https://github.com/cirosantilli/x86-bare-metal-examples/tree/2b79ac21df801fbf4619d009411be6b9cd10e6e0/no-ld-script Upon: qemu -hda main.img it shows hello world on the emulator screen as expected. But if I try

How do I write a bin file (512 bytes) to the first sector (sector 0) of a floppy disk?

China☆狼群 提交于 2019-11-27 14:10:51
How do I write a .bin file to be in the first sector of a floppy disk/virtual floppy disk/floppy image? I'm trying to boot a simple 512-byte bootloader. The size on everywhere says "512 bytes" so I should be good already. Additional Information: The bootloader simply displays a string, and I'm learning simple assembly. Some of the work is made in Windows and some in Ubuntu 14.04 (Trusty Tahr) (if this matters). It doesn't boot even though it has the bootloader sign. If you are on Linux you can do it with DD utility. There is a version of DD for Microsoft Windows as well. General DD usage If

How to format output to a byte array with no_std and no allocator?

霸气de小男生 提交于 2019-11-27 09:32:18
I want to do something like: let x = 123; let mut buf = [0 as u8; 20]; format_to!(x --> buf); assert_eq!(&buf[..3], &b"123"[..]); With #![no_std] and without any memory allocator. As I understand, there is an implementation of core::fmt::Display for u64 , and I want to use it if possible. In other words, I want to do something like format!(...) , but without a memory allocator. How can I do this? Let's start with the standard version: use std::io::Write; fn main() { let x = 123; let mut buf = [0 as u8; 20]; write!(&mut buf[..], "{}", x).expect("Can't write"); assert_eq!(&buf[0..3], b"123"); }

How to produce a minimal BIOS hello world boot sector with GCC that works from a USB stick on real hardware?

老子叫甜甜 提交于 2019-11-26 16:54:09
问题 I have managed to produce a minimal boot sector that works with QEMU 2.0.0 Ubuntu 14.04: .code16 .global _start _start: cli mov $msg, %si mov $0x0e, %ah loop: lodsb or %al, %al jz halt int $0x10 jmp loop halt: hlt msg: .asciz "hello world" .org 510 .word 0xaa55 Compiled with: as -o main.o main.S ld --oformat binary -o main.img -Ttext 0x7C00 main.o The example is available on this repo: https://github.com/cirosantilli/x86-bare-metal-examples/tree/2b79ac21df801fbf4619d009411be6b9cd10e6e0/no-ld

How to format output to a byte array with no_std and no allocator?

﹥>﹥吖頭↗ 提交于 2019-11-26 14:46:34
问题 I want to do something like: let x = 123; let mut buf = [0 as u8; 20]; format_to!(x --> buf); assert_eq!(&buf[..3], &b"123"[..]); With #![no_std] and without any memory allocator. As I understand, there is an implementation of core::fmt::Display for u64 , and I want to use it if possible. In other words, I want to do something like format!(...) , but without a memory allocator. How can I do this? 回答1: Let's start with the standard version: use std::io::Write; fn main() { let x = 123; let mut