Add D barebones sources and Makefile
This commit is contained in:
parent
5d7081cf44
commit
9cc2436d33
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,3 +3,7 @@
|
||||
/build-*/
|
||||
/gcc-*/
|
||||
/binutils-*/
|
||||
/*.o
|
||||
/*.elf
|
||||
/image/
|
||||
/image.img
|
||||
|
21
Makefile
Normal file
21
Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
.PHONY: kernel
|
||||
kernel:
|
||||
./i686-elf-gcc/bin/i686-elf-gcc -c -o boot.o -ffreestanding boot.S
|
||||
ldc2 -march=x86 -mcpu=i686 --betterC -c -of=kernel_main.o kernel_main.d
|
||||
./i686-elf-gcc/bin/i686-elf-gcc -o kernel.elf -ffreestanding -nostdlib -T link.ld boot.o kernel_main.o
|
||||
|
||||
.PHONY: image
|
||||
image: kernel
|
||||
rm -rf image
|
||||
mkdir -p image/iso/boot/grub
|
||||
echo 'set default="0"' >image/iso/boot/grub/grub.cfg
|
||||
echo 'set timeout=1' >>image/iso/boot/grub/grub.cfg
|
||||
echo 'menuentry "MyKernel" {' >>image/iso/boot/grub/grub.cfg
|
||||
echo ' insmod multiboot' >>image/iso/boot/grub/grub.cfg
|
||||
echo ' multiboot /kernel.elf' >>image/iso/boot/grub/grub.cfg
|
||||
echo '}' >>image/iso/boot/grub/grub.cfg
|
||||
cp kernel.elf image/iso
|
||||
grub-mkrescue -o image.img image/iso
|
||||
|
||||
run: image
|
||||
qemu-system-x86_64 -hda image.img
|
28
boot.S
Normal file
28
boot.S
Normal file
@ -0,0 +1,28 @@
|
||||
#define MAGIC 0x1BADB002
|
||||
#define FLAGS 0x3
|
||||
|
||||
.section .multiboot
|
||||
MultiBootHeader:
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long -(MAGIC + FLAGS)
|
||||
|
||||
.section .text
|
||||
.global mykernel_start
|
||||
.type mykernel_start, @function
|
||||
mykernel_start:
|
||||
/* Set stack pointer. */
|
||||
mov $_stack_end, %esp
|
||||
|
||||
/* Jump to C. */
|
||||
push $0
|
||||
push $0
|
||||
push $0
|
||||
push %ebx
|
||||
call mykernel_main
|
||||
|
||||
cli
|
||||
1: hlt
|
||||
jmp 1b
|
||||
|
||||
.size mykernel_start, . - mykernel_start
|
5
kernel_main.d
Normal file
5
kernel_main.d
Normal file
@ -0,0 +1,5 @@
|
||||
extern (C) void mykernel_main() {
|
||||
ubyte * vidmem = cast(ubyte *) 0xB8000u;
|
||||
vidmem[0] = 'D';
|
||||
vidmem[1] = 0x7u;
|
||||
}
|
38
link.ld
Normal file
38
link.ld
Normal file
@ -0,0 +1,38 @@
|
||||
ENTRY(mykernel_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 1M;
|
||||
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.multiboot)
|
||||
*(.text)
|
||||
}
|
||||
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
||||
_stack_size = 16K;
|
||||
.stack (NOLOAD) : ALIGN(4K)
|
||||
{
|
||||
_stack_start = .;
|
||||
. = . + _stack_size;
|
||||
_stack_end = .;
|
||||
}
|
||||
|
||||
.bss BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
}
|
||||
|
||||
. = ALIGN(4K);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user