Skip to content
Snippets Groups Projects
Commit ac38f229 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
*.img
*.o
*.bin
Makefile 0 → 100644
build:
cc -c boot.c -o boot.o -m32
ld -o boot.img -Ttext 0x0 --oformat binary boot.o -m elf_i386
# objcopy -O binary boot.o boot.img
# [[ $$(stat boot.img --printf='%s') -lt 510 ]]
truncate --size=510 boot.img
printf '\x55\xAA' >> boot.img
run: build
qemu-system-x86_64 boot.img
clean:
rm *.o
NOTE 0 → 100644
dd if=/dev/zero of=out.img bs=512K count=16
VBoxManage convertfromraw out.img out.vdi --format vdi
;
; A simple boot sector program that loops forever.
;
[org 0x7c00]
mov bx, str
call println_bios
println_bios:
; Arg0: addr in register bx
; while true:
; if [bx] != NULL:
; print [bx]; ++bx
mov ah, 0x0e
_loop_begin:
mov al, [bx]
cmp al, 0x0
je _loop_exit
int 0x10
inc bx
jmp _loop_begin
_loop_exit:
ret
println_vga:
; Arg0: addr in register eax
str:
db 'This is Recolic!', 0x0
jmp $
times 510-($-$$) db 0
dw 0xaa55
[bits 16]
[org 0x7c00]
jmp _enter_prot_mode
gdt_begin:
gdt_entry_0:
dd 0x0, 0x0
gdt_entry_1:
; code
dw 0xffff ; limit[16:0]
dw 0x0 ; base[16:0]
db 0x0 ; base[24:16]
db 10011010b ; flags
db 11001111b ; flags : limit[]
db 0x0 ; base[32:24]
gdt_entry_2:
; data
dw 0xffff ; limit[16:0]
dw 0x0 ; base[16:0]
db 0x0 ; base[24:16]
db 10010010b ; flags
db 11001111b ; flags : limit[]
db 0x0 ; base[32:24]
gdt_end:
gdt_desc:
dw gdt_end - gdt_begin - 1
dd gdt_begin
; Segment register values.
CODE_SEG_OFFSET equ gdt_entry_1 - gdt_begin
DATA_SEG_OFFSET equ gdt_entry_2 - gdt_begin
_enter_prot_mode:
cli
lgdt [gdt_desc]
mov eax, cr0
or eax, 0x1
mov cr0, eax
; We're almost in 32bit protected mode now. Flush the pipeline by far jump.
jmp CODE_SEG_OFFSET:_prot_begin
[bits 32]
_prot_begin:
mov ax, DATA_SEG_OFFSET
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000 ; 600KB free space here, until 0x7c00 + 0x200 byte (MBR sector 0)
mov esp, ebp
asm ("jmp 0x14");
//void print_char(char to_print) {
// asm inline (
// "mov $0x0e, %%ah\n\t"
// "mov %0, %%al\n\t"
// "int $0x10"
// :
// : "Ir" (to_print)
// : "ax"
// );
//}
//
//void println(char *s) {
// while(*s != 0) {
// print_char(*s);
// }
//}
void main() {
_start_p:
asm (
"mov $0x0e, %ah\n\t"
"mov $0x55, %al\n\t"
"int $0x10"
);
//print_char('X');
//println("Hello world!");
//println("Recolic Booting OS HERE...");
}
asm (
"jmp 0x-2\n\t"
);
boot.c 0 → 100644
void main();
void __entry() {
main();
}
void print_char(char to_print) {
asm inline (
"mov $0x0e, %%ah\n\t"
"mov %0, %%al\n\t"
"int $0x10"
:
: "Ir" (to_print)
: "ax"
);
}
void println(char *s) {
while(*s != 0) {
print_char(*s);
}
}
void main() {
asm (
"mov $0x0e, %ah\n\t"
"mov $0x55, %al\n\t"
"int $0x10"
);
//print_char('X');
//println("Hello world!");
//println("Recolic Booting OS HERE...");
asm (
"jmp 0x-2\n\t"
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment