first commit
This commit is contained in:
commit
8494925192
12
Makefile
Normal file
12
Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
CFLAGS= -m32 -Wfatal-errors -nostdlib -Wno-builtin-declaration-mismatch
|
||||
ASFLAGS= --32
|
||||
LDFLAGS= -melf_i386 -nostdlib -e loader -T link.ld
|
||||
OBJS=kernel.bin
|
||||
|
||||
all: $(OBJS)
|
||||
kernel.bin: loader.o kernel.o
|
||||
$(LD) $(LDFLAGS) $^ -o $@
|
||||
install:
|
||||
cp ./kernel.bin /boot/mykernel.bin
|
||||
clean:
|
||||
$(RM) *.o kernel.bin
|
12
kernel.c
Normal file
12
kernel.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#define SPACE " "
|
||||
void puts(char*s)
|
||||
{
|
||||
static unsigned short*vram=(unsigned short*)0xb8000;
|
||||
for(int i=0;s[i];++i)
|
||||
vram[i]=(vram[i]&0xff00)|s[i];
|
||||
}
|
||||
|
||||
void kernelmain(void*multiboot_structure,unsigned magicnumber)
|
||||
{
|
||||
puts("Hello and welcome to my first operating system, yo!"SPACE);
|
||||
}
|
34
link.ld
Normal file
34
link.ld
Normal file
|
@ -0,0 +1,34 @@
|
|||
ENTRY(loader)
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
OUTPUT_ARCH(i386:i386)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x0100000;
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.multiboot )
|
||||
*(.text* )
|
||||
*(.rodata )
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
start_ctors = .;
|
||||
KEEP(*(.init_array ));
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ) ));
|
||||
end_ctors = .;
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss )
|
||||
}
|
||||
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.fini_array* )
|
||||
*(.comment )
|
||||
}
|
||||
}
|
30
loader.s
Normal file
30
loader.s
Normal file
|
@ -0,0 +1,30 @@
|
|||
.set MAGIC, 0x1badb002
|
||||
.set FLAGS, (1<<0 | 1<<1)
|
||||
.set CHECKSUM, -(MAGIC + FLAGS)
|
||||
|
||||
|
||||
.section .multiboot
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long CHECKSUM
|
||||
|
||||
|
||||
.section .text
|
||||
.extern kernelmain
|
||||
.global loader
|
||||
|
||||
loader:
|
||||
mov $kernel_stack, %esp
|
||||
push %eax
|
||||
push %ebx
|
||||
call kernelmain
|
||||
.L1:
|
||||
cli
|
||||
hlt
|
||||
jmp .L1
|
||||
|
||||
|
||||
.section bss
|
||||
.space 2*1024*1024 ; # 2 MiB
|
||||
kernel_stack:
|
||||
|
Loading…
Reference in New Issue
Block a user