Many things
Renamed main.asm in boot.asm and moved it into the bootloader directory, created an empty kernel.asm file, edited Makefile and edited the bootloader (boot.asm).
This commit is contained in:
parent
535aedd0ea
commit
f394eb42b4
44
Makefile
44
Makefile
@ -3,9 +3,43 @@ ASM=nasm
|
||||
SRC_DIR=src
|
||||
BUILD_DIR=build
|
||||
|
||||
$(BUILD_DIR)/main_floppy.img: $(BUILD_DIR)/main.bin
|
||||
cp $(BUILD_DIR)/main.bin $(BUILD_DIR)/main_floppy.img
|
||||
truncate -s 1440k $(BUILD_DIR)/main_floppy.img
|
||||
.PHONY: all floppy_image kernel bootloader clean always
|
||||
|
||||
$(BUILD_DIR)/main.bin: $(SRC_DIR)/main.asm
|
||||
$(ASM) $(SRC_DIR)/main.asm -f bin -o $(BUILD_DIR)/main.bin
|
||||
|
||||
#Immagine floppy
|
||||
|
||||
immagine_floppy: $(BUILD_DIR)/main_floppy.img
|
||||
|
||||
$(BUILD_DIR)/main_floppy.img: bootloader kernel
|
||||
dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880
|
||||
mkfs.fat -F 12 -n "XanvOS" $(BUILD_DIR)/main_floppy.img
|
||||
dd if=$(BUILD_DIR)/bootloader.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin"
|
||||
|
||||
|
||||
#Kernel
|
||||
|
||||
kernel: $(BUILD_DIR)/kernel.bin
|
||||
|
||||
$(BUILD_DIR)/kernel.bin: always
|
||||
$(ASM) $(SRC_DIR)/kernel/kernel.asm -f bin -o $(BUILD_DIR)/kernel.bin
|
||||
|
||||
|
||||
#Bootloader
|
||||
|
||||
bootloader: $(BUILD_DIR)/bootloader.bin
|
||||
|
||||
$(BUILD_DIR)/bootloader.bin: always
|
||||
$(ASM) $(SRC_DIR)/bootloader/boot.asm -f bin -o $(BUILD_DIR)/bootloader.bin
|
||||
|
||||
|
||||
#Always
|
||||
|
||||
always:
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
|
||||
#Clean
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)/*
|
BIN
build/main.bin
BIN
build/main.bin
Binary file not shown.
Binary file not shown.
182
src/bootloader/boot.asm
Normal file
182
src/bootloader/boot.asm
Normal file
@ -0,0 +1,182 @@
|
||||
org 0x7C00
|
||||
bits 16
|
||||
|
||||
%define ENDL 0x0D, 0x0A
|
||||
|
||||
;Headers di FAT12 (senza questa parte si sminchia il FAT12 e non si crea l'immagine floppy)
|
||||
|
||||
jmp short start
|
||||
nop
|
||||
|
||||
bdb_oem: db 'MSWIN4.1'
|
||||
bdb_bytes_per_sector: dw 512
|
||||
bdb_sectors_per_cluster: db 1
|
||||
bdb_reserved_sectors: dw 1
|
||||
bdb_fat_count: db 2
|
||||
bdb_dir_entries_count: dw 0E0h
|
||||
bdb_total_sectors: dw 2880
|
||||
bdb_media_descriptor_type: db 0F0h
|
||||
bdb_sectors_per_fat: dw 9
|
||||
bdb_sectors_per_track: dw 18
|
||||
bdb_heads: dw 2
|
||||
bdb_hidden_sectors: dd 0
|
||||
bdb_large_sector_count: dd 0
|
||||
|
||||
ebr_drive_number: db 0
|
||||
db 0
|
||||
ebr_signature: db 29h
|
||||
ebr_volume_id: db 12h, 34h, 56h, 78h
|
||||
ebr_volume_label: db 'XanvicOS '
|
||||
ebr_system_id: db 'FAT12 '
|
||||
|
||||
;Codice
|
||||
|
||||
start:
|
||||
jmp main
|
||||
|
||||
puts:
|
||||
push si
|
||||
push ax
|
||||
push bx
|
||||
|
||||
.loop:
|
||||
lodsb
|
||||
or al, al
|
||||
jz .fine
|
||||
|
||||
mov ah, 0x0E
|
||||
mov bh, 0
|
||||
int 0x10
|
||||
|
||||
jmp .loop
|
||||
|
||||
.fine:
|
||||
pop bx
|
||||
pop ax
|
||||
pop si
|
||||
ret
|
||||
|
||||
main:
|
||||
mov ax, 0
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
mov ss, ax
|
||||
mov sp, 0x7C00
|
||||
|
||||
mov si, msg_helloworld
|
||||
call puts
|
||||
|
||||
;Legge cose dal floppy
|
||||
mov [ebr_drive_number], dl
|
||||
|
||||
mov ax, 1
|
||||
mov cl, 1
|
||||
mov bx, 0x7E00
|
||||
call lettura_disco
|
||||
|
||||
cli
|
||||
hlt
|
||||
|
||||
;Errori
|
||||
|
||||
errore_floppy:
|
||||
mov si, msg_errore_lettura
|
||||
call puts
|
||||
jmp premi_per_riavviare
|
||||
|
||||
premi_per_riavviare:
|
||||
mov ah, 0
|
||||
int 16h
|
||||
jmp 0FFFFh:0
|
||||
|
||||
.halt:
|
||||
cli
|
||||
hlt
|
||||
|
||||
;Trasforma/Converte un indirizzo LBA in uno CHS
|
||||
|
||||
lba_to_chs:
|
||||
push ax
|
||||
push dx
|
||||
|
||||
xor dx, dx
|
||||
div word [bdb_sectors_per_track]
|
||||
|
||||
inc dx
|
||||
mov cx, dx
|
||||
|
||||
xor dx, dx
|
||||
div word [bdb_heads]
|
||||
|
||||
mov dh, dl
|
||||
mov ch, al
|
||||
shl ah, 6
|
||||
or cl, ah
|
||||
|
||||
pop ax
|
||||
mov dl, al
|
||||
pop ax
|
||||
|
||||
ret
|
||||
|
||||
;Legge i settori da un disco
|
||||
|
||||
lettura_disco:
|
||||
; push ax
|
||||
; push bx
|
||||
push cx
|
||||
; push dx
|
||||
; push di
|
||||
|
||||
call lba_to_chs
|
||||
pop ax
|
||||
|
||||
mov ah, 02h
|
||||
mov di, 3
|
||||
|
||||
.riprova:
|
||||
pusha
|
||||
stc
|
||||
int 13h
|
||||
jnc .fine
|
||||
|
||||
;Errore nella lettura del disco
|
||||
popa
|
||||
call disk_reset
|
||||
|
||||
dec di
|
||||
test di, di
|
||||
jnz .riprova
|
||||
|
||||
.errore:
|
||||
jmp errore_floppy
|
||||
|
||||
.fine:
|
||||
popa
|
||||
|
||||
; pop di
|
||||
; pop dx
|
||||
; pop cx
|
||||
; pop bx
|
||||
; pop ax
|
||||
ret
|
||||
|
||||
disk_reset:
|
||||
pusha
|
||||
mov ah, 0
|
||||
stc
|
||||
int 13h
|
||||
jc errore_floppy
|
||||
popa
|
||||
ret
|
||||
|
||||
;Mostra una stringa sullo schermo
|
||||
|
||||
msg_helloworld:
|
||||
db 'Hello World!', ENDL, 0
|
||||
msg_errore_lettura:
|
||||
db 'Errore nella lettura del disco!'
|
||||
|
||||
times 510-($-$$) db 0
|
||||
dw 0AA55h
|
0
src/kernel/kernel.asm
Normal file
0
src/kernel/kernel.asm
Normal file
51
src/main.asm
51
src/main.asm
@ -1,51 +0,0 @@
|
||||
org 0x7C00
|
||||
bits 16
|
||||
|
||||
%define ENDL 0x0D, 0x0A
|
||||
|
||||
start:
|
||||
jmp main
|
||||
|
||||
puts:
|
||||
push si
|
||||
push ax
|
||||
push bx
|
||||
|
||||
.loop:
|
||||
lodsb
|
||||
or al, al
|
||||
jz .done
|
||||
|
||||
mov ah, 0x0E
|
||||
mov bh, 0
|
||||
int 0x10
|
||||
|
||||
jmp .loop
|
||||
|
||||
.done:
|
||||
pop bx
|
||||
pop ax
|
||||
pop si
|
||||
ret
|
||||
|
||||
main:
|
||||
|
||||
mov ax, 0
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
mov ss, ax
|
||||
mov sp, 0x7C00
|
||||
|
||||
mov si, msg_hello
|
||||
call puts
|
||||
|
||||
hlt
|
||||
|
||||
.halt:
|
||||
jmp .halt
|
||||
|
||||
msg_hello: db 'Hello World!', ENDL, 0
|
||||
|
||||
times 510-($-$$) db 0
|
||||
dw 0AA55h
|
Loading…
x
Reference in New Issue
Block a user