CLOSE

 

section .data
    msg db 'EAX = ', 0
    crlf db 0x0D, 0x0A, 0

section .bss
    regval resb 9  ; buffer to store register value as string

section .text
global _start
_start:
    ; Example: Move a value into EAX and print it
    mov eax, 0x12345678
    call print_eax

    ; Hang the system (infinite loop)
    cli
.hang:
    hlt
    jmp .hang

; Print EAX register value
print_eax:
    push eax       ; Save EAX to stack
    mov eax, [esp] ; Copy EAX to itself for printing
    call print_register_value
    pop eax        ; Restore EAX
    ret

; Convert a 32-bit register value to a string and print it
print_register_value:
    pusha

    ; Prepare to print 'EAX = '
    mov edx, msg
    call print_string

    ; Convert the register value in EAX to a hex string
    mov esi, eax
    lea edi, [regval+8]
    mov ecx, 8
convert_loop:
    mov eax, esi
    and eax, 0x0F
    add al, '0'
    cmp al, '9'
    jle digit_ok
    add al, 7
digit_ok:
    stosb
    shr esi, 4
    loop convert_loop

    ; Print the converted value
    lea edx, [regval]
    call print_string

    ; Print newline
    mov edx, crlf
    call print_string

    popa
    ret

; Routine to print a null-terminated string to video memory
print_string:
    pusha

    mov ebx, 0xb8000 ; Video memory address for VGA text mode
    mov ah, 0x0F     ; Attribute byte (white on black)

.next_char:
    lodsb
    test al, al
    jz .done
    ; Write character and attribute to video memory
    mov [ebx], ax
    add ebx, 2
    jmp .next_char

.done:
    popa
    ret
 
 
 
 
 
 
 
 
 

 

 

 

https://github.com/Meulengracht/MollenOS/commit/0691798d736cfe3da16cea2471241a19c9f164ad
print_register:
    mov cl, 4            ; Loop counter for nibbles
    .next_nibble:
        rol ax, 4         ; Rotate left to get next nibble in AL
        and al, 0xF       ; Mask out all but the lowest 4 bits
        add al, '0'       ; Convert nibble to ASCII character
        cmp al, '9'       ; Check if it's a digit greater than 9
        jbe .print_digit  ; If not, print it directly
        add al, 7         ; Convert digit to letter (A-F)
    .print_digit:
        stosw             ; Store the character and attribute byte (ax) in video memory
        loop .next_nibble ; Repeat for the next nibble
    ret

LFLAGS = -nostdlib -Ttext 0x100000 -e kentry ../librt/build/libcrt.a ../librt/build/libk.a ../librt/build/libdsk.a build/acpica.a build/$(arch) .a

 

Added toolchain to makefile

 - october 5 2017
https://github.com/Meulengracht/MollenOS/commit/b5818342340c76ec1f4e552e5cfaa40b3c164655











https://github.com/Meulengracht/MollenOS/blob/6ab7da663b0cbd587152cd6efd49870830a9b4ea/config/common.mk









BITS 16
ORG 0x7C00

; Define constants for BIOS interrupts
INT13_READ_SECTORS equ 0x02
BIOS_DISK_ERROR equ 0x01

start:
    cli
    xor ax, ax
    mov ss, ax
    mov sp, 0x7C00
    sti

    ; Set data segment registers
    mov ds, ax
    mov es, ax

    ; Print a message
    mov si, boot_msg
    call print_string

    ; Load FAT32 BPB (BIOS Parameter Block)
    mov bx, 0x7E00
    mov dl, [boot_drive]
    call read_sectors

    ; Extract necessary BPB fields
    mov ax, [bx + BPB_BytsPerSec]
    mov [BytesPerSector], ax
    mov ax, [bx + BPB_SecPerClus]
    mov [SectorsPerCluster], ax
    mov eax, [bx + BPB_RsvdSecCnt]
    mov [ReservedSectors], eax
    mov eax, [bx + BPB_NumFATs]
    mov [NumberOfFATs], eax
    mov eax, [bx + BPB_FATSz32]
    mov [SectorsPerFAT], eax
    mov eax, [bx + BPB_RootClus]
    mov [RootCluster], eax

    ; Find the kernel file "KERNEL.BIN"
    call find_kernel_file

    ; Load the kernel into memory
    call load_kernel

    ; Jump to the kernel
    jmp 0x2000:0x0000

disk_error:
    hlt

; Function to read sectors using BIOS interrupt 0x13
read_sectors:
    push ax
    push dx
    push cx
    push bx

    mov ah, INT13_READ_SECTORS
    mov al, 0x01
    int 0x13
    jc disk_error

    pop bx
    pop cx
    pop dx
    pop ax
    ret

; Function to find "KERNEL.BIN" in the root directory
find_kernel_file:
    ; Set up the root directory reading
    mov eax, [RootCluster]
    call cluster_to_lba
    mov bx, 0x7E00
    call read_sectors

    ; Find the file
    mov di, 0x7E00
.find_loop:
    mov cx, 11
    mov si, kernel_name
    repe cmpsb
    je .file_found
    add di, 32
    cmp di, 0x7E00 + 512
    jb .find_loop

    jmp disk_error

.file_found:
    ; Get the starting cluster of the kernel file
    mov ax, [di + DIR_FstClusLO]
    mov dx, [di + DIR_FstClusHI]
    shl dx, 16
    or eax, dx
    mov [KernelCluster], eax
    ret

; Function to load the kernel file into memory
load_kernel:
    mov eax, [KernelCluster]
    mov bx, 0x2000
.load_loop:
    call cluster_to_lba
    call read_sectors
    add bx, 512
    call next_cluster
    test eax, eax
    jnz .load_loop
    ret

; Convert cluster number to LBA
cluster_to_lba:
    push ax
    push dx
    sub eax, 2
    mul word [SectorsPerCluster]
    add eax, [ReservedSectors]
    add eax, [SectorsPerFAT]
    add eax, [SectorsPerFAT]
    pop dx
    pop ax
    ret

; Get the next cluster in the chain
next_cluster:
    push ax
    push dx
    mov bx, eax
    mov ax, 0
    mov al, byte [SectorsPerCluster]
    mul bx
    add eax, [FATStart]
    mov bx, 0x7E00
    call read_sectors
    mov eax, [bx + (bx * 4) % 512]
    pop dx
    pop ax
    ret

; Print string function
print_string:
    lodsb
    test al, al
    jz .done
    mov ah, 0x0E
    int 0x10
    jmp print_string
.done:
    ret

; Boot sector signature
TIMES 510-($-$$) db 0
DW 0xAA55

boot_drive db 0
BytesPerSector dw 0
SectorsPerCluster db 0
ReservedSectors dw 0
NumberOfFATs db 0
SectorsPerFAT dd 0
RootCluster dd 0
KernelCluster dd 0

boot_msg db 'Loading kernel from FAT32...', 0
kernel_name db 'KERNEL  BIN'

%include 'fat32.inc'
; FAT32.inc - FAT32 helper functions and structures

; BIOS Parameter Block (BPB) offsets
BPB_BytsPerSec    equ 0x0B
BPB_SecPerClus    equ 0x0D
BPB_RsvdSecCnt    equ 0x0E
BPB_NumFATs       equ 0x10
BPB_FATSz32       equ 0x24
BPB_RootClus      equ 0x2C

; Directory entry offsets
DIR_Name          equ 0x00
DIR_Attr          equ 0x0B
DIR_NTRes         equ 0x0C
DIR_CrtTimeTenth  equ 0x0D
DIR_CrtTime       equ 0x0E
DIR_CrtDate       equ 0x10
DIR_LstAccDate    equ 0x12
DIR_FstClusHI     equ 0x14
DIR_WrtTime       equ 0x16
DIR_WrtDate       equ 0x18
DIR_FstClusLO     equ 0x1A
DIR_FileSize      equ 0x1C

FATStart          equ 0x7E00 + 512  ; Assuming FAT starts immediately after BPB
BITS 16
ORG 0x0000

start:
    ; Set up segments
    xor ax, ax
    mov ds, ax
    mov es, ax

    ; Set up stack
    mov ss, ax
    mov sp, 0x7C00

    ; Print message
    mov si, hello_msg
    call print_string

    ; Hang the system
hang:
    hlt
    jmp hang

print_string:
    lodsb
    test al, al
    jz .done
    mov ah, 0x0E
    int 0x10
    jmp print_string
.done:
    ret

hello_msg db 'Hello, Kernel loaded successfully!', 0

TIMES 512-($-$$) db 0
;;DW 0xAA55
nasm -f bin fat32_boot.asm -o bootloader.bin

nasm -f bin dummy_kernel.asm -o kernel.bin

dd if=/dev/zero of=disk.img bs=1M count=10
mkfs.vfat -F 32 disk.img

sudo mount -o loop disk.img /mnt
sudo dd if=bootloader.bin of=disk.img bs=512 count=1 conv=notrunc
sudo cp kernel.bin /mnt/KERNEL.BIN

sudo umount /mnt
qemu-system-x86_64 -drive format=raw,file=disk.img

 

 

; Get the next cluster in the chain
next_cluster:
    push ax
    push dx
    mov bx, eax
    mov ax, 0
    mov al, byte [SectorsPerCluster]
    mul bx
    add eax, [FATStart]
    call read_sectors

    ; Compute the offset in the FAT
    mov eax, [KernelCluster]
    mov ecx, eax
    shr ecx, 2
    add ecx, [FATStart]
    call read_sectors

    mov ebx, eax
    and eax, 0x03
    shl eax, 2
    mov eax, [bx + ebx]
    pop dx
    pop ax
    ret

 

 

 

 

 

https://github.com/Meulengracht/MollenOS/tree/b5818342340c76ec1f4e552e5cfaa40b3c164655
echo "# TheTaaJ" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:The-Jat/TheTaaJ.git
git push -u origin main