Magic bytes on ld scrpit working. Failed UEFI attempt.

This commit is contained in:
Ciro Santilli
2015-09-07 16:27:49 +02:00
parent 7710c94f57
commit 2b79ac21df
12 changed files with 79 additions and 15 deletions

View File

@@ -5,11 +5,13 @@ Hello world examples of programs without an OS. A.K.A. bare bones.
1. Examples
1. [printf](printf/)
1. [min](min.S)
1. [no-ld-script](no-ld-script/)
1. [bios_one_char](bios_one_char.S)
1. [bios_hello_world](bios_hello_world.S)
1. [shutdown_apm](shutdown_apm.S)
1. TODO not working
1. [multiboot-c/](multiboot-c/)
1. [UEFI](uefi/)
1. [hajji](hajji)
1. [nasm](nasm/)
1. [BIOS](bios.md)

View File

@@ -3,8 +3,7 @@
- make work on real hardware
- ACPI
- get multiboot working
- UEFI
- reboot computer
- reboot computer. Would put QEMU into an infinite reboot loop. Awesome.
- multithreading: http://stackoverflow.com/questions/7308391/how-is-concurrency-done-in-intel-x86-assembly || http://stackoverflow.com/questions/980999/what-does-multicore-assembly-language-look-like || http://stackoverflow.com/questions/714905/threads-in-x86-assembler-using-the-gnu-assember-as
- transition to protected mode
- test the paging circuit

8
a.ld
View File

@@ -9,14 +9,8 @@ SECTIONS
Magic bytes. 0x1FE == 510.
We could add this on each Gas file.
TODO make them work here. Mentioned at: http://stackoverflow.com/a/9604338/895245
Another interesting example shows AT: http://dc0d32.blogspot.fr/2010/06/real-mode-in-c-with-gcc-writing.html
*/
/*
. = 0x1FE;
SHORT(0xAA55);
*/
SHORT(0xAA55)
}
}

View File

@@ -1,3 +1,2 @@
#define BEGIN .code16
#define END .org 510;\
.word 0xaa55
#define END

4
min.S
View File

@@ -8,7 +8,3 @@ cli
/* Stop the processor. */
hlt
/* Mandatory magic bytes 511 and 512. */
.org 510
.word 0xaa55

15
no-ld-script/Makefile Normal file
View File

@@ -0,0 +1,15 @@
.POSIX:
MAIN := main.img
.PHONY: clean run
$(MAIN): main.S
as -o main.o '$<'
ld --oformat binary -o '$@' -Ttext 0x7C00 main.o
clean:
rm -f '$(MAIN)'
run: $(MAIN)
qemu-system-i386 -hda '$(MAIN)'

9
no-ld-script/README.md Normal file
View File

@@ -0,0 +1,9 @@
# No ld script
Hello world using the default `ld` script, no explicit one set with `-T`. Uses:
- `-tText`
- `.org` inside each assembly file
- `_start` must be present to avoid a warning, since the default linker script expects it
Less convenient, but a little less code if you are using a single file.

18
no-ld-script/main.S Normal file
View File

@@ -0,0 +1,18 @@
.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

6
uefi/Makefile Normal file
View File

@@ -0,0 +1,6 @@
.POSIX:
.PHONY: run
run:
qemu-system-32 -bios ovmf.fd

13
uefi/README.md Normal file
View File

@@ -0,0 +1,13 @@
# UEFI
Successor for BIOS.
TODO get a hello world program working.
- http://wiki.osdev.org/UEFI
- https://fedoraproject.org/wiki/Using_UEFI_with_QEMU
- https://wiki.ubuntu.com/UEFI/OVMF
OVMF.fd IA32 r15214 downloaded from: https://sourceforge.net/projects/edk2/files/OVMF/OVMF-IA32-r15214.zip/download
Included in-source for convenience, even though it is ugly.

13
uefi/main.c Normal file
View File

@@ -0,0 +1,13 @@
#include <efi.h>
#include <efilib.h>
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
InitializeLib(ImageHandle, SystemTable);
conout = SystemTable->ConOut;
uefi_call_wrapper(conout->OutputString, 2, conout, (CHAR16 *)L"Hello World\n\r");
return EFI_SUCCESS;
}

BIN
uefi/ovmf.fd Normal file

Binary file not shown.