Initial commit.

This commit is contained in:
bʰedoh₂ swé 2024-10-19 22:09:19 +05:00
commit 61600952c4
6 changed files with 71 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
bin
*.o

5
LICENSE Normal file
View File

@ -0,0 +1,5 @@
Copyright (C) 2024 by bedohswe bedohswe@firemail.cc
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

12
Makefile Normal file
View File

@ -0,0 +1,12 @@
SRCS = boot.c
LDFLAGS = -melf_i386 -nostdlib --oformat binary -T linker.ld
CFLAGS = -fno-pie -Wall -std=c2x -m16 -nostdlib -Os -nostartfiles
%.o: %.c
$(CC) $(CFLAGS) $^ -c -o $@
all: $(SRCS:.c=.o)
$(LD) $(LDFLAGS) -o bin $^
clean:
$(RM) $(SRCS:.c=.o) bin

2
README Normal file
View File

@ -0,0 +1,2 @@
MBR boot sector Hello world written in c.
Note: this thing does not work with GCC.

24
boot.c Normal file
View File

@ -0,0 +1,24 @@
void putchar(char);
void write(char*);
void _start(void) {
write("Hello World!\r\n\0");
while(1)
;
}
void write(char *out) {
for (char *i = out; *i != 0; i++)
putchar(*i);
}
void putchar(char out) {
__asm__ volatile (
"movb $0x0e, %%ah;"
"movb %0, %%al;"
"int $0x10;"
:
:"r"(out)
:"%ax"
);
}

26
linker.ld Normal file
View File

@ -0,0 +1,26 @@
ENTRY (_start)
OUTPUT_FORMAT (binary)
SECTIONS
{
. = 0x7c00;
.text : { boot.o(.text)
*(.text)
}
.rodata : { *(.rodata)
}
.data : { *(.data)
}
. = 0x7DFE;
.bootsig : {
SHORT(0xaa55);
}
.bss : { *(.bss)
}
. = ALIGN (0x200);
lit = .;
/DISCARD/ : { *(.eh_frame)
*(.comment)
*(.note.GNU-stack)
}
}