Now the Stage 1 of the bootloader loads Stage 2 in memory.

I already wrote this but my computer crashed, so I won't write as much as before.
Now the bootloader is divided in stage1 and stage2, I added and edited some makefiles, stage 2 is written in Asm and C, the kernel isn't loaded into memory.

PS: after this commit I'll add another branch called "coding", the code in that branch won't work 100% because it's missing something, but I don't want to do a "mega commit" every time (those commits will still be in the main branch).
To everyone who wants to try XanvicOS or """using""" it, use the main branch, because the main branch's code is working.
I'll write this in the README.md right after this commit.
This commit is contained in:
Vincenzo Aleksey Brocato 2024-07-28 00:08:48 +02:00 committed by VinceAle7082
parent c5a3efb225
commit bf3b0283c4
13 changed files with 104 additions and 56 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build/ build/
.mailmap

View File

@ -15,11 +15,10 @@ immagine_floppy: $(BUILD_DIR)/main_floppy.img
$(BUILD_DIR)/main_floppy.img: bootloader kernel $(BUILD_DIR)/main_floppy.img: bootloader kernel
dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880 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 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 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)/stage2.bin "::stage2.bin"
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin" mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin"
mcopy -i $(BUILD_DIR)/main_floppy.img test.txt "::test.txt"
#Kernel #Kernel

View File

@ -3,7 +3,7 @@ ASM?=nasm
ASMFLAGS?=-f obj ASMFLAGS?=-f obj
CC?=gcc CC?=gcc
CC16?=/usr/bin/watcom/binl/wcc CC16?=/usr/bin/watcom/binl/wcc
CFLAGS16?= CFLAGS16?= -4 -d3 -s -wx -ms -zl -zq
LD16?=/usr/bin/watcom/binl/wlink LD16?=/usr/bin/watcom/binl/wlink
SOURCES_C=$(wildcard *.c) SOURCES_C=$(wildcard *.c)
@ -11,14 +11,14 @@ SOURCES_ASM=$(wildcard *.asm)
OBJECTS_C=$(patsubst %.c, $(BUILD_DIR)/stage2/c/%.obj, $(SOURCES_C)) OBJECTS_C=$(patsubst %.c, $(BUILD_DIR)/stage2/c/%.obj, $(SOURCES_C))
OBJECTS_ASM=$(patsubst %.asm, $(BUILD_DIR)/stage2/asm/%.obj, $(SOURCES_ASM)) OBJECTS_ASM=$(patsubst %.asm, $(BUILD_DIR)/stage2/asm/%.obj, $(SOURCES_ASM))
.PHONY: all stage2 clean always .PHONY: all clean always
all: stage2 all: stage2
stage2: $(BUILD_DIR)/stage2.bin stage2: $(BUILD_DIR)/stage2.bin
$(BUILD_DIR)/stage2.bin: $OBJECTS_ASM $OBJECTS_C $(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 $(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 $(BUILD_DIR)/stage2/c/%.obj: %.c always
$(CC16) $(CFLAGS16) -fo=$@ $< $(CC16) $(CFLAGS16) -fo=$@ $<

View 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

View 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 (;;);
}

View 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

View File

@ -1,56 +1,21 @@
org 0x0
bits 16 bits 16
section _ENTRY class=CODE
%define ENDL 0x0D, 0x0A extern _cstart_
global entry
;Codice del kernel entry:
start: cli
mov si, msg_helloworld mov ax, ds
call puts mov ss, ax
call premi_per_riavviare mov sp, 0
mov bp, sp
sti
xor dh, dh
push dx
call _cstart_
.halt:
cli cli
hlt hlt
puts:
; save registers we will modify
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
;Stringhe
msg_helloworld:
db 'Hello World dallo stage2 del Bootloader!', ENDL, 0
msg_premi_per_riavviare:
db 'Premi un tasto per riavviare...', ENDL, 0
;Errori
;Variabili
;Cose che non so dove mettere
premi_per_riavviare:
mov si, msg_premi_per_riavviare
call puts
mov ah, 0
int 16h
jmp 0FFFFh:0

View 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;

View 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++;
}
}

View 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

View File

@ -0,0 +1,4 @@
#pragma once
void putc(char c);
void puts(const char *str);

View 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

View File

@ -0,0 +1,4 @@
#pragma once
#include "stdint.h"
void _cdecl x86_Video_WriteCharTeletype(char c, uint8_t page);