Migrated first 6 gists.
This commit is contained in:
12
kernel.c/Makefile
Normal file
12
kernel.c/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
.PHONY: all
|
||||
all: kernel-1989
|
||||
qemu-system-i386 -kernel kernel-1989 -d guest_errors
|
||||
|
||||
kernel-1989: boot.s kmain.c
|
||||
gcc -m32 -c boot.s -o boot.o
|
||||
gcc -m32 -std=c99 -c kmain.c -o kmain.o
|
||||
ld -m elf_i386 -T link.ld -o kernel-1989 boot.o kmain.o
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.o kernel-1989
|
||||
2
kernel.c/README.md
Normal file
2
kernel.c/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
Hello, Kernel! - An absolutely minimal barebones x86 OS kernel, based on this tutorial https://arjunsreedharan.org/post/82710718100/kernel-101-lets-write-a-kernel
|
||||
|
||||
47
kernel.c/kernel.c
Normal file
47
kernel.c/kernel.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void kmain(void) {
|
||||
const char * str = "Hello, Kernel!";
|
||||
const char colors[16] = { 0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B,
|
||||
0x0C, 0x0D, 0x0E, 0x0F
|
||||
};
|
||||
char * vidptr = (char *)0xB8000;
|
||||
uint32_t i = 0;
|
||||
uint32_t j = 0;
|
||||
uint32_t k = 0;
|
||||
uint32_t l = 0;
|
||||
|
||||
while (true) {
|
||||
while (j < 80 * 25 * 2) {
|
||||
vidptr[j] = ' ';
|
||||
vidptr[j + 1] = 0x00;
|
||||
j = j + 2;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
i = 0;
|
||||
while (k < 80 * 25) {
|
||||
j = 0;
|
||||
while (str[j]) {
|
||||
vidptr[i] = str[j];
|
||||
vidptr[i + 1] = colors[l];
|
||||
j++;
|
||||
i += 2;
|
||||
l = (l + 1) % 16;
|
||||
}
|
||||
vidptr[i] = ' ';
|
||||
vidptr[i + 1] = colors[l];
|
||||
i += 2;
|
||||
k += 14;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
while (k < 1500000)
|
||||
k++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
21
kernel.c/kernel.s
Normal file
21
kernel.c/kernel.s
Normal file
@@ -0,0 +1,21 @@
|
||||
.section .text
|
||||
|
||||
// Multiboot header
|
||||
.align 4
|
||||
.long 0x1BADB002
|
||||
.long 0x00
|
||||
.long -0x1BADB002
|
||||
|
||||
// Entry point
|
||||
.globl start
|
||||
|
||||
start:
|
||||
cli
|
||||
mov $stack_top, %esp
|
||||
call kmain
|
||||
hlt
|
||||
|
||||
.section .bss
|
||||
|
||||
.comm stack_bottom, 8192, 4
|
||||
stack_top:
|
||||
9
kernel.c/link.ld
Normal file
9
kernel.c/link.ld
Normal file
@@ -0,0 +1,9 @@
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
ENTRY(start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x100000;
|
||||
.text : { *(.text) }
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss) }
|
||||
}
|
||||
Reference in New Issue
Block a user