Compare commits
2 Commits
79798d9bbb
...
075f7ab4ca
Author | SHA1 | Date | |
---|---|---|---|
075f7ab4ca | |||
7a1c92972f |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
build/
|
||||
build/
|
||||
.mailmap
|
26
Makefile
26
Makefile
@ -1,9 +1,12 @@
|
||||
ASM=nasm
|
||||
CC=gcc
|
||||
CC16=/usr/bin/watcom/binl/wcc
|
||||
LD16=/usr/bin/watcom/binl/wlink
|
||||
|
||||
SRC_DIR=src
|
||||
BUILD_DIR=build
|
||||
|
||||
.PHONY: all floppy_image kernel bootloader clean always
|
||||
.PHONY: all immagine_floppy kernel bootloader clean always
|
||||
|
||||
|
||||
#Immagine floppy
|
||||
@ -12,8 +15,9 @@ 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
|
||||
mkfs.fat -F 12 -n "XANVOS" $(BUILD_DIR)/main_floppy.img
|
||||
dd if=$(BUILD_DIR)/stage1.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/stage2.bin "::stage2.bin"
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin"
|
||||
|
||||
|
||||
@ -22,15 +26,23 @@ $(BUILD_DIR)/main_floppy.img: bootloader kernel
|
||||
kernel: $(BUILD_DIR)/kernel.bin
|
||||
|
||||
$(BUILD_DIR)/kernel.bin: always
|
||||
$(ASM) $(SRC_DIR)/kernel/kernel.asm -f bin -o $(BUILD_DIR)/kernel.bin
|
||||
$(MAKE) -C $(SRC_DIR)/kernel BUILD_DIR=$(abspath $(BUILD_DIR))
|
||||
|
||||
|
||||
#Bootloader
|
||||
|
||||
bootloader: $(BUILD_DIR)/bootloader.bin
|
||||
bootloader: stage1 stage2
|
||||
|
||||
$(BUILD_DIR)/bootloader.bin: always
|
||||
$(ASM) $(SRC_DIR)/bootloader/boot.asm -f bin -o $(BUILD_DIR)/bootloader.bin
|
||||
stage1: $(BUILD_DIR)/stage1.bin
|
||||
|
||||
$(BUILD_DIR)/stage1.bin: always
|
||||
$(MAKE) -C $(SRC_DIR)/bootloader/stage1 BUILD_DIR=$(abspath $(BUILD_DIR))
|
||||
|
||||
|
||||
stage2: $(BUILD_DIR)/stage2.bin
|
||||
|
||||
$(BUILD_DIR)/stage2.bin: always
|
||||
$(MAKE) -C $(SRC_DIR)/bootloader/stage2 BUILD_DIR=$(abspath $(BUILD_DIR))
|
||||
|
||||
|
||||
#Always
|
||||
|
15
src/bootloader/stage1/Makefile
Normal file
15
src/bootloader/stage1/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
BUILD_DIR?=build/
|
||||
ASM?=nasm
|
||||
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: stage1
|
||||
|
||||
stage1: $(BUILD_DIR)/stage1.bin
|
||||
|
||||
$(BUILD_DIR)/stage1.bin:
|
||||
$(ASM) stage1.asm -f bin -o $(BUILD_DIR)/stage1.bin
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/stage1.bin
|
@ -101,28 +101,28 @@ start:
|
||||
xor bx, bx
|
||||
mov di, buffer
|
||||
|
||||
.cerca_kernel:
|
||||
mov si, file_kernel_bin
|
||||
.cerca_stage2:
|
||||
mov si, file_stage2_bin
|
||||
mov cx, 11
|
||||
push di
|
||||
repe cmpsb
|
||||
pop di
|
||||
je .kernel_trovato
|
||||
je .stage2_trovato
|
||||
|
||||
add di, 32
|
||||
inc bx
|
||||
cmp bx, [dir_entries_count]
|
||||
jl .cerca_kernel
|
||||
jl .cerca_stage2
|
||||
|
||||
;Kernel non trovato
|
||||
jmp errore_kernel_non_trovato
|
||||
jmp errore_stage2_non_trovato
|
||||
|
||||
.kernel_trovato:
|
||||
mov si, msg_kernel_trovato
|
||||
.stage2_trovato:
|
||||
mov si, msg_stage2_trovato
|
||||
call puts
|
||||
|
||||
mov ax, [di + 26]
|
||||
mov [kernel_cluster], ax
|
||||
mov [stage2_cluster], ax
|
||||
|
||||
mov ax, [reserved_sectors]
|
||||
mov bx, buffer
|
||||
@ -130,12 +130,12 @@ start:
|
||||
mov dl, [ebr_drive_number]
|
||||
call lettura_disco
|
||||
|
||||
mov bx, KERNEL_LOAD_SEGMENT
|
||||
mov bx, STAGE2_LOAD_SEGMENT
|
||||
mov es, bx
|
||||
mov bx, KERNEL_LOAD_OFFSET
|
||||
mov bx, STAGE2_LOAD_OFFSET
|
||||
|
||||
.carica_kernel:
|
||||
mov ax, [kernel_cluster]
|
||||
.carica_stage2:
|
||||
mov ax, [stage2_cluster]
|
||||
add ax, 31
|
||||
|
||||
mov cl, 1
|
||||
@ -144,7 +144,7 @@ start:
|
||||
|
||||
add bx, [bytes_per_sector]
|
||||
|
||||
mov ax, [kernel_cluster]
|
||||
mov ax, [stage2_cluster]
|
||||
mov cx, 3
|
||||
mul cx
|
||||
mov cx, 2
|
||||
@ -168,18 +168,17 @@ start:
|
||||
cmp ax, 0x0FF8
|
||||
jae .fine_lettura
|
||||
|
||||
mov [kernel_cluster], ax
|
||||
jmp .carica_kernel
|
||||
mov [stage2_cluster], ax
|
||||
jmp .carica_stage2
|
||||
|
||||
.fine_lettura:
|
||||
mov dl, [ebr_drive_number]
|
||||
|
||||
mov ax, KERNEL_LOAD_SEGMENT
|
||||
mov ax, STAGE2_LOAD_SEGMENT
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
jmp KERNEL_LOAD_SEGMENT:KERNEL_LOAD_OFFSET
|
||||
jmp premi_per_riavviare
|
||||
jmp STAGE2_LOAD_SEGMENT:STAGE2_LOAD_OFFSET
|
||||
|
||||
;Trasforma/Converte un indirizzo LBA in uno CHS
|
||||
|
||||
@ -280,11 +279,11 @@ msg_caricamento:
|
||||
msg_errore_lettura:
|
||||
db 'Errore del disco', ENDL, 0
|
||||
|
||||
msg_kernel_non_trovato:
|
||||
db 'Kernel non trovato', ENDL, 0
|
||||
msg_stage2_non_trovato:
|
||||
db 'Stage 2 non trovato', ENDL, 0
|
||||
|
||||
msg_kernel_trovato:
|
||||
db 'Kernel trovato', ENDL, 0
|
||||
msg_stage2_trovato:
|
||||
db 'Stage 2 trovato', ENDL, 0
|
||||
|
||||
;Errori
|
||||
|
||||
@ -293,17 +292,17 @@ errore_floppy:
|
||||
call puts
|
||||
jmp premi_per_riavviare
|
||||
|
||||
errore_kernel_non_trovato:
|
||||
mov si, msg_kernel_non_trovato
|
||||
errore_stage2_non_trovato:
|
||||
mov si, msg_stage2_non_trovato
|
||||
call puts
|
||||
jmp premi_per_riavviare
|
||||
|
||||
;Variabili
|
||||
|
||||
file_kernel_bin: db 'KERNEL BIN'
|
||||
kernel_cluster: dw 0
|
||||
KERNEL_LOAD_SEGMENT equ 0x2000
|
||||
KERNEL_LOAD_OFFSET equ 0
|
||||
file_stage2_bin: db 'STAGE2 BIN'
|
||||
stage2_cluster: dw 0
|
||||
STAGE2_LOAD_SEGMENT equ 0x2000
|
||||
STAGE2_LOAD_OFFSET equ 0
|
||||
|
||||
;Cose che non so dove mettere
|
||||
|
34
src/bootloader/stage2/Makefile
Normal file
34
src/bootloader/stage2/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
BUILD_DIR?=build/
|
||||
ASM?=nasm
|
||||
ASMFLAGS?=-f obj
|
||||
CC?=gcc
|
||||
CC16?=/usr/bin/watcom/binl/wcc
|
||||
CFLAGS16?= -4 -d3 -s -wx -ms -zl -zq
|
||||
LD16?=/usr/bin/watcom/binl/wlink
|
||||
|
||||
SOURCES_C=$(wildcard *.c)
|
||||
SOURCES_ASM=$(wildcard *.asm)
|
||||
OBJECTS_C=$(patsubst %.c, $(BUILD_DIR)/stage2/c/%.obj, $(SOURCES_C))
|
||||
OBJECTS_ASM=$(patsubst %.asm, $(BUILD_DIR)/stage2/asm/%.obj, $(SOURCES_ASM))
|
||||
|
||||
.PHONY: all clean always
|
||||
|
||||
all: stage2
|
||||
|
||||
stage2: $(BUILD_DIR)/stage2.bin
|
||||
|
||||
$(BUILD_DIR)/stage2.bin: $(OBJECTS_ASM) $(OBJECTS_C)
|
||||
$(LD16) NAME $(BUILD_DIR)/stage2.bin FILE \{ $(OBJECTS_ASM) $(OBJECTS_C) \} OPTION MAP=$(BUILD_DIR)/stage2.map @linker.lnk
|
||||
|
||||
$(BUILD_DIR)/stage2/c/%.obj: %.c always
|
||||
$(CC16) $(CFLAGS16) -fo=$@ $<
|
||||
|
||||
$(BUILD_DIR)/stage2/asm/%.obj: %.asm always
|
||||
$(ASM) $(ASMFLAGS) -o $@ $<
|
||||
|
||||
always:
|
||||
mkdir -p $(BUILD_DIR)/stage2/c
|
||||
mkdir -p $(BUILD_DIR)/stage2/asm
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/stage2.bin
|
12
src/bootloader/stage2/linker.lnk
Normal file
12
src/bootloader/stage2/linker.lnk
Normal file
@ -0,0 +1,12 @@
|
||||
FORMAT RAW BIN
|
||||
OPTION QUIET,
|
||||
NODEFAULTLIBS,
|
||||
START=entry,
|
||||
VERBOSE,
|
||||
OFFSET=0,
|
||||
STACK=0X200
|
||||
ORDER
|
||||
CLNAME CODE
|
||||
SEGMENT _ENTRY
|
||||
SEGMENT _TEXT
|
||||
CLNAME DATA
|
8
src/bootloader/stage2/main.c
Normal file
8
src/bootloader/stage2/main.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void _cdecl cstart_(uint16_t bootDrive)
|
||||
{
|
||||
puts("Hello World from the Stage 2 of the bootloader written in C!");
|
||||
for (;;);
|
||||
}
|
3
src/bootloader/stage2/main.err
Normal file
3
src/bootloader/stage2/main.err
Normal file
@ -0,0 +1,3 @@
|
||||
stdio.h(4): Warning! W138: No newline at end of file
|
||||
main.c(8): Warning! W138: No newline at end of file
|
||||
main.c(4): Warning! W303: Parameter 'bootDrive' has been defined, but not referenced
|
21
src/bootloader/stage2/stage2.asm
Normal file
21
src/bootloader/stage2/stage2.asm
Normal file
@ -0,0 +1,21 @@
|
||||
bits 16
|
||||
|
||||
section _ENTRY class=CODE
|
||||
|
||||
extern _cstart_
|
||||
global entry
|
||||
|
||||
entry:
|
||||
cli
|
||||
mov ax, ds
|
||||
mov ss, ax
|
||||
mov sp, 0
|
||||
mov bp, sp
|
||||
sti
|
||||
|
||||
xor dh, dh
|
||||
push dx
|
||||
call _cstart_
|
||||
|
||||
cli
|
||||
hlt
|
12
src/bootloader/stage2/stdint.h
Normal file
12
src/bootloader/stage2/stdint.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int int32_t;
|
||||
typedef unsigned long int uint32_t;
|
||||
typedef signed long int int64_t;
|
||||
typedef unsigned long int uint64_t;
|
||||
|
||||
|
15
src/bootloader/stage2/stdio.c
Normal file
15
src/bootloader/stage2/stdio.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include "stdio.h"
|
||||
#include "x86.h"
|
||||
|
||||
void putc(char c)
|
||||
{
|
||||
x86_Video_WriteCharTeletype(c, 0);
|
||||
}
|
||||
void puts(const char *str)
|
||||
{
|
||||
while(*str)
|
||||
{
|
||||
putc(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
2
src/bootloader/stage2/stdio.err
Normal file
2
src/bootloader/stage2/stdio.err
Normal file
@ -0,0 +1,2 @@
|
||||
stdio.h(4): Warning! W138: No newline at end of file
|
||||
x86.h(4): Warning! W138: No newline at end of file
|
4
src/bootloader/stage2/stdio.h
Normal file
4
src/bootloader/stage2/stdio.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void putc(char c);
|
||||
void puts(const char *str);
|
23
src/bootloader/stage2/x86.asm
Normal file
23
src/bootloader/stage2/x86.asm
Normal file
@ -0,0 +1,23 @@
|
||||
bits 16
|
||||
|
||||
section _TEXT class=CODE
|
||||
|
||||
global _x86_Video_WriteCharTeletype
|
||||
|
||||
_x86_Video_WriteCharTeletype:
|
||||
push bp
|
||||
mov bp, sp
|
||||
|
||||
push bx
|
||||
mov ah, 0Eh
|
||||
mov al, [bp + 4]
|
||||
mov bh, [bp + 6]
|
||||
|
||||
int 10h
|
||||
|
||||
pop bx
|
||||
|
||||
mov sp, bp
|
||||
pop bp
|
||||
|
||||
ret
|
4
src/bootloader/stage2/x86.h
Normal file
4
src/bootloader/stage2/x86.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
void _cdecl x86_Video_WriteCharTeletype(char c, uint8_t page);
|
17
src/kernel/Makefile
Normal file
17
src/kernel/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
BUILD_DIR?=build/
|
||||
ASM?=nasm
|
||||
CC?=gcc
|
||||
CC16?=/usr/bin/watcom/binl/wcc
|
||||
LD16?=/usr/bin/watcom/binl/wlink
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: kernel
|
||||
|
||||
kernel: $(BUILD_DIR)/kernel.bin
|
||||
|
||||
$(BUILD_DIR)/kernel.bin:
|
||||
$(ASM) kernel.asm -f bin -o $(BUILD_DIR)/kernel.bin
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/kernel.bin
|
Loading…
x
Reference in New Issue
Block a user