diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/mb1/main.c | 15 | ||||
-rw-r--r-- | example/mb2/entry.asm | 51 | ||||
-rw-r--r-- | example/mb2/link.ld | 33 | ||||
-rw-r--r-- | example/mb2/main.c | 31 | ||||
-rw-r--r-- | example/mb2/makefile | 16 | ||||
-rw-r--r-- | example/segelboot.cfg | 2 |
6 files changed, 147 insertions, 1 deletions
diff --git a/example/mb1/main.c b/example/mb1/main.c index 0174803..d572977 100644 --- a/example/mb1/main.c +++ b/example/mb1/main.c @@ -1,6 +1,16 @@ // MIT License, Copyright (c) 2021 Marvin Borner typedef unsigned int u32; +typedef unsigned short u16; +typedef unsigned char u8; + +static void draw(u8 color, u8 data) +{ + u16 *out = (u16 *)0xb8000; + for (u16 i = 0; i < 80 * 25; i++) { + out[i] = data | (color << 8); + } +} int kernel_main(u32 magic, u32 addr, u32 esp); // Decl int kernel_main(u32 magic, u32 addr, u32 esp) @@ -9,6 +19,11 @@ int kernel_main(u32 magic, u32 addr, u32 esp) (void)addr; (void)esp; + if (magic == 0x2badb002) + draw(0x02, 'y'); + else + draw(0x04, 'n'); + while (1) ; diff --git a/example/mb2/entry.asm b/example/mb2/entry.asm new file mode 100644 index 0000000..063ac74 --- /dev/null +++ b/example/mb2/entry.asm @@ -0,0 +1,51 @@ +; MIT License, Copyright (c) 2021 Marvin Borner + +bits 32 + +MAGIC equ 0xe85250d6 +ARCHITECHTURE equ 0 +HEADER_LENGTH equ multiboot_header_end - multiboot_header_start +CHECKSUM equ 0x100000000 - (MAGIC + ARCHITECHTURE + HEADER_LENGTH) + +multiboot_header_start: + dd MAGIC + dd ARCHITECHTURE + dd HEADER_LENGTH + dd CHECKSUM +entry_address_tag_start: + dw 3 + dw 0 + dd entry_address_tag_end - entry_address_tag_start + dd 0 ; low + dd boot_entry ; high +entry_address_tag_end: +framebuffer_tag_start: + dw 5 + dw 0 + dd framebuffer_tag_end - framebuffer_tag_start + dd 1920 + dd 1200 + dd 32 +framebuffer_tag_end: + dw 0 + dw 0 + dd 8 +multiboot_header_end: + +global boot_entry +extern kernel_main +boot_entry: + mov esp, stack_top + push esp + push ebx + push eax + cli + call kernel_main + hlt + jmp $ + +section .bss +align 32 +stack_bottom: + resb 0x4000 +stack_top: diff --git a/example/mb2/link.ld b/example/mb2/link.ld new file mode 100644 index 0000000..0d79ef4 --- /dev/null +++ b/example/mb2/link.ld @@ -0,0 +1,33 @@ +/* MIT License, Copyright (c) 2021 Marvin Borner */ + +OUTPUT_ARCH(i386) +ENTRY(boot_entry) +phys = 0x00100000; + +SECTIONS +{ + . = phys; + + .text BLOCK(4K) : ALIGN(4K) + { + *(.text*) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata*) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data*) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } + + end = .; +} diff --git a/example/mb2/main.c b/example/mb2/main.c new file mode 100644 index 0000000..3c7b064 --- /dev/null +++ b/example/mb2/main.c @@ -0,0 +1,31 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +typedef unsigned int u32; +typedef unsigned short u16; +typedef unsigned char u8; + +static void draw(u8 color, u8 data) +{ + u16 *out = (u16 *)0xb8000; + for (u16 i = 0; i < 80 * 25; i++) { + out[i] = data | (color << 8); + } +} + +int kernel_main(u32 magic, u32 addr, u32 esp); // Decl +int kernel_main(u32 magic, u32 addr, u32 esp) +{ + (void)magic; + (void)addr; + (void)esp; + + if (magic == 0x36d76289) + draw(0x02, 'y'); + else + draw(0x04, 'n'); + + while (1) + ; + + return 1; +} diff --git a/example/mb2/makefile b/example/mb2/makefile new file mode 100644 index 0000000..0976447 --- /dev/null +++ b/example/mb2/makefile @@ -0,0 +1,16 @@ +# MIT License, Copyright (c) 2021 Marvin Borner +# Gets called by main makefile (their variables are exported) + +OBJS = entry_asm.o main.o + +all: compile + +%.o: %.c + @$(CC) -c $(CFLAGS) $< -o $@ + +%_asm.o: %.asm + @$(AS) $(ASFLAGS) $< -o $@ + +compile: $(OBJS) + @mkdir -p $(BLD)/examples/ + @$(LD) -N -z max-page-size=0x1000 -eboot_entry -Tlink.ld -o $(BLD)/examples/mb2.elf $+ diff --git a/example/segelboot.cfg b/example/segelboot.cfg index 65938eb..d30fc0d 100644 --- a/example/segelboot.cfg +++ b/example/segelboot.cfg @@ -4,4 +4,4 @@ TIMEOUT=10 PATH=hda0:/boot/mb1.elf # Multiboot 2 (TODO) -PATH=hda0:/boot/mb1.elf +PATH=hda0:/boot/mb2.elf |