Created
October 31, 2016 20:06
-
-
Save anonymous/74c951c2a45ca498c05652c8debcdf18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.set ALIGN, 1<<0 | |
.set MEMINFO, 1<<1 | |
.set FLAGS, ALIGN | MEMINFO | |
.set MAGIC, 0x1BADB002 | |
.set CHECKSUM, -(MAGIC + FLAGS) | |
.section .multiboot | |
.align 4 | |
.long MAGIC | |
.long FLAGS | |
.long CHECKSUM | |
.section .bss | |
.align 16 | |
stack_bottom: | |
.skip 16384 | |
stack_top: | |
.section .text | |
.global _start | |
.type _start, @function | |
_start: | |
mov $stack_top, %esp | |
call fbosmain | |
cli | |
1: hlt | |
jmp 1b | |
.size _start, . - _start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SCREEN_W 80 | |
#define SCREEN_H 25 | |
#define VMEM_MAX SCREEN_W * SCREEN_H | |
unsigned short *VMEM = (unsigned short *) 0xb8000; | |
struct { | |
int x, y; | |
} CURSOR; | |
void clrscr(void) | |
{ | |
int i; | |
for (i = 0; i < VMEM_MAX; i++) { | |
VMEM[i] = 0; | |
} | |
} | |
void scrollup(void) | |
{ | |
int x, y; | |
for (x = 0; x < SCREEN_W; x++) { | |
for (y = 0; y < SCREEN_H - 1; y++) { | |
VMEM[x + y * SCREEN_W] = VMEM[x + (y + 1) * SCREEN_W]; | |
} | |
} | |
CURSOR.x = 0; | |
CURSOR.y = SCREEN_H - 1; | |
for (x = 0; x < SCREEN_W; x++) VMEM[x + CURSOR.y * SCREEN_W] = 0; | |
} | |
void writec(char c) | |
{ | |
if (CURSOR.x > SCREEN_W - 1) { | |
CURSOR.x = 0; | |
++CURSOR.y; | |
} | |
if (CURSOR.y > SCREEN_H - 1) { | |
scrollup(); | |
} | |
VMEM[CURSOR.x + CURSOR.y * SCREEN_W] = c | 7 << 8; | |
++CURSOR.x; | |
} | |
void writes(char *s) | |
{ | |
while (*s) writec(*s++); | |
} | |
int revi(int i) | |
{ | |
int r = 0; | |
while (i > 0) { | |
r = r * 10 + i % 10; | |
i /= 10; | |
} | |
return r; | |
} | |
void writei(int i) | |
{ | |
if (i < 0) { | |
writec('-'); | |
i = -i; | |
} | |
i = revi(i); | |
do { | |
writec(i % 10 + '0'); | |
i /= 10; | |
} while (i != 0); | |
} | |
void newln(void) | |
{ | |
while (CURSOR.x < SCREEN_W) { | |
writec(0); | |
} | |
} | |
void writesln(char *s) | |
{ | |
writes(s); | |
newln(); | |
} | |
void writeiln(int i) | |
{ | |
writei(i); | |
newln(); | |
} | |
void delay(void) | |
{ | |
int i; | |
for (i = 0; i < 10000000; i++); | |
} | |
void fizzbuzz(void) | |
{ | |
int i; | |
for (i = 1; i <= 100; i++) { | |
if (i % 15 == 0) { | |
writesln("Fizzbuzz"); | |
} else if (i % 3 == 0) { | |
writesln("Fizz"); | |
} else if (i % 5 == 0) { | |
writesln("Buzz"); | |
} else { | |
writeiln(i); | |
} | |
delay(); | |
} | |
} | |
int fbosmain(void) | |
{ | |
CURSOR.x = 0; | |
CURSOR.y = 0; | |
clrscr(); | |
fizzbuzz(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
menuentry "FizzbuzzOS" { | |
multiboot /boot/fbos.obj | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENTRY(_start) | |
SECTIONS | |
{ | |
. = 1M; | |
.text BLOCK(4K) : ALIGN(4K) | |
{ | |
*(.multiboot) | |
*(.text) | |
} | |
.rodata BLOCK(4K) : ALIGN(4K) | |
{ | |
*(.rodata) | |
} | |
.data BLOCK(4K) : ALIGN(4K) | |
{ | |
*(.data) | |
} | |
.bss BLOCK(4K) : ALIGN(4K) | |
{ | |
*(COMMON) | |
*(.bss) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=i686-elf-gcc | |
CFLAGS=-c | |
AS=i686-elf-as | |
all: build | |
build: | |
$(AS) boot.s -o boot.o | |
$(CC) $(CFLAGS) fbos.c -o fbos.o | |
$(CC) -T linker.ld -o fbos.obj -ffreestanding -O2 -nostdlib boot.o fbos.o -lgcc | |
clean: | |
rm -f *.o *.obj | |
rm -rf iso *.iso | |
iso: build | |
mkdir -p iso/boot/grub | |
cp fbos.obj iso/boot/ | |
cp grub.cfg iso/boot/grub/ | |
grub-mkrescue -o fbos.iso iso |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment