#Xiromos 16-Bit NASM OS

1 messages · Page 2 of 1

still lance
#

You need to keep everything in mind like preserving registers

#

It's not an easy fix if you miss one instruction that holds the stack together

echo granite
#

do you know kolibriOS or MenuetOS?

#

they are both also written entirely in assembly

#

i will ask tomorrow my informatik teacher if he is impressed or not

#

what is informatik called in english?

kindred magnet
kindred magnet
#

Sorted to IT commonly

kindred magnet
#

And why do you want to impress the IT teacher

still lance
echo granite
kindred magnet
#

Fucking nightmare are to debug

kindred magnet
echo granite
#

some basic commands and two very cool programs

kindred magnet
#

Sure that’s a good starting point

#

You may want to try your hands at x86-64 nodes

raven sierra
#

yeah, it isnt fun

#

don't dig yourself a hole too deep to climb out of

#

if you're genuinely locked down this path, this isn't the best place to share progress

kindred magnet
#

Especially if you aren’t experienced enough to be diving deep into this rabbit hole

#

Because people will keep telling you best practices lol

raven sierra
#

even if the best practices are specifically what you're avoiding

#

cough

#

but yeah i think there are actually a few communities that appreciate these

#

look around for retro computing groups

kindred magnet
#

I feel like that’s a pretty basic thing

#

Obviously you are welcome to be here @raven sierra

#

Etc etc

raven sierra
#

cmon lets not have a brick wall competition in this guy's thread D:

kindred magnet
#

Fair fair

#

Though I am just giving forewarnings and recommendations less of being a brick wall lol

raven sierra
#

it gets to a point at times yknow >:P

kindred magnet
#

Just saying stuff like “assembly is easier” is a clear misnomer and makes me think they need the advice

raven sierra
#

yeah i agree

#

i said stuff like that jokingly before but with what ive seen now some things are less funny

#

techno if you want to see for yourself, try developing your os without any more guides

kindred magnet
#

As it’s hard to tell when it’s a joke

#

When people are serious

raven sierra
#

assembly is a ton of tedious work for a short lived spike of dopamine

kindred magnet
#

Most projects start in C and then maybe micro optimize some routines in assembly anyways lol

#

Stuff like SIMD

#

Optimizations should only be done after profiling anyways

raven sierra
#

with all the assembly i did learn i just couldnt go without more for this next foundation

kindred magnet
#

And where you can make a meaningful improvement over the compiler

kindred magnet
#

When the normal assembly in C OSDev is very diffrent

raven sierra
#

i learned real world assembly after i got home from ikea

#

inline assembly is a different species for sure

kindred magnet
#

Port portIO wrappers etc

#

sti/cli etc

#

swapgs

timber wraith
raven sierra
#

mhm

timber wraith
echo granite
#

everyone needs to learn the basics and then develop their own ideas

kindred magnet
echo granite
#

i tried already C before

#

i have some privat repositories with some C projects

timber wraith
#

Once you have enough experience, you won't need anyone to tell you what to do.

timber wraith
kindred magnet
#

Constantly following tutorials puts you what’s known in game dev as “tutorial hell” and it can be very hard to escape once your doing it

timber wraith
echo granite
#

assembly is more fun

timber wraith
echo granite
#

translating the programming language into machine code

kindred magnet
#

A compiler does a lot more than that especially internally

timber wraith
echo granite
#

what is a linker?

#

look

#

this guy also made a 16bit assembly OS

little drift
#

x16-PRos code?

cinder bronze
#

that is his code

little drift
cinder bronze
#

@echo granite's code

cinder bronze
little drift
cinder bronze
#

true

#

but why did you make so much different subroutines

#

you could just let the user choose the color

little drift
cinder bronze
#

(i mean the programmer)

#
print_string_green:
    mov bl, 0x0A
    jmp print_string_color

; ------ Cyan ------
print_string_cyan:
    mov bl, 0x0B
    jmp print_string_color

; ------ Red ------
print_string_red:
    mov bl, 0x0C
    jmp print_string_color

; ------ Yellow ------
print_string_yellow:
    mov bl, 0x0E
    jmp print_string_color

isnt it still useless?

#

you could just do that:

mov bl, color
call print_string
#

or make a macro

little drift
echo granite
#
print_string_cyan:
    mov ah, 0x0E
    mov bl, 0x0B
    jmp print_char
;--red--
print_string_red:
    mov ah, 0x0E
    mov bl, 0x0C
    jmp print_char
;--green--
print_string_green:
    mov ah, 0x0E
    mov bl, 0x0A
    jmp print_char
;--yellow--
print_string_yellow:
    mov ah, 0x0E
    mov bl, 0x0E
    jmp print_char
;--darkblue--
print_string_darkblue:
    mov ah, 0x0E
    mov bl, 0x01
    jmp print_char
;--white--
print_string_white:
    mov ah, 0x0E
    mov bl, 0x0f
    jmp print_char
;--dark-red--
print_string_darkred:
    mov ah, 0x0E
    mov bl, 0x04
print_char:
    lodsb
    cmp al, 0
    je print_char_done
    int 0x10
    jmp print_char
print_char_done:
    ret``` i did it like this
#

because you can then just type the color, instead of remembering the color code

cinder bronze
echo granite
#

and i think this costs less memory

cinder bronze
#

wdym

#

writing

%define MY_COLOR 0xab

and

mov bl, MY_COLOR
call print_string

is much better

echo granite
#

hm, nah, there is no difference

cinder bronze
#

with your solution, you have 50 useless subroutines

#

for the same thing

#

with my solution, you only have 1 subroutine

#

and consts to easily pass colors

#

you can even write a macro

#

so you would end up with something like this:

PRINT_COLORED_STRING "Message", MY_COLOR
echo granite
#

btw i didnt copy the code, i did it like this because wither.cpp suggested it

cinder bronze
#

when did i told you to do that

echo granite
#

you told me to do the code shorter, so i edited it a little bit

cinder bronze
echo granite
#

okay, but i wrote my code my own and didnt copied it from proX

echo granite
#

he said i copied his code

cinder bronze
#

it looks like so

#

but it's not bad

#

if you understand it

little drift
echo granite
#

assembly bootloader for 16bit FAT16

timber wraith
#

oh

#

I have one for FAT12, FAT16, and FAT32 I'm developing

echo granite
#

oh wow, that is pretty cool

#

how do you develop this skill that you can implement things which are in a documentation?

kindred magnet
#

reading comprehension?

echo granite
#

noo

#

that reminds me of english lessons in school

timber wraith
#

there's a reason schools have English lessons

timber wraith
#

and I guess reading comprehension and logical thinking skills

echo granite
#

okay

#

btw everything i read is english

#

so i am not that bad

raven sierra
#

you should be able to move just fine

#

besides, writing code independently gets you farther than any guide

echo granite
#

true

echo granite
#

should i use LBA or CHS in my filesystem?

#

because i think LBA would be easier, but some tutorials recommend CHS, but i dont understand why

kindred magnet
#

Isn’t LBA newer?

echo granite
#

yes it is

kindred magnet
#

Then why use CHS :p

echo granite
#

CHS is used on hard disks because it uses tracks, cylinders, etc. LBA is newer and works easier, but i think it is designed for SSDs

kindred magnet
#

No LBA very well works on hard drives

echo granite
#

well, then i will use LBA

timber wraith
#

most tutorials are bad

#

floppy disks support CHS only tho

echo granite
#

ohh, i see

timber wraith
echo granite
timber wraith
#

you should avoid tutorials

echo granite
timber wraith
#

btw

#

this is the official spec

kindred magnet
#

Yes iPhone I would love to open this with retroarch 💀

echo granite
#

what is that?

kindred magnet
#

It’s a game emulator lol. I was just trying to open the document and my phone was being dumb

magic gust
#

wtf

raven sierra
#

let techno work cmon don't bring it up again

echo granite
#

where is a good space to load the FAT?

cinder bronze
#

doesnt mikeos load it to 0x2000 or smth?

timber wraith
timber wraith
#

MS-DOS 1.0 is unironically superior

echo granite
#

i have my kernel at 0x500 and my programs at 0x5000. maybe i should put it on 0x8000?

timber wraith
echo granite
#

FAT16

#

it needs some more space than FAT12

#

because of the bigger entries

timber wraith
#

I guess it'll need at most 128kB

#

so 0x8000 would be a good choice

#

asuming conventional memory goes all the way to 0xA000

#

which it often doesn't

#

cuz EBDA

#

also

timber wraith
echo granite
#

its easier? and i dont have multitasking so hardcoding programs is okay i guess

echo granite
#

you just can type in the adress and you dont have to calculate it

echo granite
#
    ;BIOS disk read function
    ;bl = drive type
    ;ch = maximum cylinder number
    ;cl = maximum sector number
    ;dh = maximum head number
    ;dl = number of drives
    ;al = number of sectors
    pusha
    mov ah, 0x02
    mov al, [RootDirSectors]
    mov cl, 3       ;start sector
    mov dl, [BS_DriveNumber]
    mov bx, 0x8000
    mov es, bx
    int 0x13
    popa
    jc disk_read_error
    ret``` is this a valid function to load the root directory?
cinder bronze
#

and is your OS for 8086 only?

echo granite
#

yes

echo granite
cinder bronze
cinder bronze
cinder bronze
#

also a function does respect a call convention

#
DoSomething:
    ; ...
    ret

this is a subroutine

echo granite
#

oh, so i better add this function on top, right? without ret

#

does ot work then?

#

btw what is the difference betwenn int 0x13 ah=0x02 and ah=0x42?

cinder bronze
cinder bronze
#

why would you remove the ret and put it on top

echo granite
#

then it isnt a function anymore and it is wothout ret, so i can push the registers

echo granite
cinder bronze
#

but it uses CHS

cinder bronze
#

thats stupid

#

just keep it how it is

#

it's not a function since it doesnt respect a clear call convention

echo granite
#

alright

echo granite
#

i dont really understand how to search for the kernel.bin file, does anyone has a tutorial on this topic?

timber wraith
#

And also not how that term was universally used.

timber wraith
#

first, you can't assume you can read multiple sectors across track boundaries

#

also, you can't assume the FAT is only one sector

timber wraith
echo granite
#

yes, exactly

timber wraith
magic gust
#

are you still using assembly only?

obsidian salmon
echo granite
magic gust
#

why? are you gonna make a dos or something?

kindred magnet
#

I don’t think we can change the persons mind even if it’s not the best idea™ for them to do this

echo granite
timber wraith
echo granite
#

where do i have to put the kernel.bin on the disk when loading it with qemu?

cinder bronze
#

format your disk image in fat16

echo granite
#

how do i do that with qemu? i have a disk image

cinder bronze
#

and then you can use mtools (for example) to copy the kernel on it

cinder bronze
echo granite
#

no

cinder bronze
#

then format it

#
mkfs.fat -F 16 disk.img
echo granite
#

thank you

cinder bronze
#

np

echo granite
#
    cli
    xor ax, ax
    mov ds, ax      ;start adress of the data segment
    mov es, ax      ;start point of the extra segment
    mov ss, ax
    mov sp, 0x7c00
    sti

    mov ax, 0x03
    int 0x10

    mov ax, 0x12
    int 0x10

    mov si, loading_str
    mov bl, 0x0f
    call print_start

    ;check if LBA is supported
check_lba_supp:
    mov ah, 0x41
    mov bx, 0x55aa
    mov dl, byte [BS_DriveNumber]
    int 0x13
    jc .no_supp
    mov bx, 1
    jmp load_root
.no_supp:
    mov bx, 0
    jmp main

load_root:
    ;BIOS disk read function
    ;bl = drive type
    ;ch = maximum cylinder number
    ;cl = maximum sector number
    ;dh = maximum head number
    ;dl = number of drives
    ;al = number of sectors
    mov ah, 0x42
    mov al, [RootDirSectors]
    mov cl, 3       ;start sector
    mov dl, [BS_DriveNumber]
    mov bx, 0x8000
    mov es, bx
    int 0x13
    mov [LBA], bx
    jc disk_read_error

    ;detect ram
    clc
    int 0x12        ;ax = memory in KB
    jc ram_error
    mov si, ram_ok
    mov bl, 0x0a
    call print_start

    mov dx, [BPB_RootEntry]
search_kernel:
    mov     si, file_kernel_bin         ;ds:si = name
    mov     cl, 11                      ;length of name
    cmp     byte [es:di], ch
    je      kernel_error                ;end of root directory
    push    di
    repe    cmpsb
    pop     di
    je      load_startCluster
    add     di, 32
    dec     dx
    jnz     search_kernel

    mov     di, [es:di+1Ah]``` hm
#

something is wrong

#

do i have to specify the LBA value in search_kernel?

timber wraith
#

you wrote the subroutine, you should know

echo granite
#

what do you mean?

cinder bronze
echo granite
#

oh

echo granite
#

i replaced ch with 0 but now load_root function doesnt work

#

wait

#

hmm

echo granite
#

do you have an idea why the load_root function doesnt work anymore?

#

if i change ah to 0x02 it works

#

but why not in 0x42?

cinder bronze
#

you don't have a disk access packet (DAP) as i can see

#

LBA works differently than CHS

echo granite
#
    mov bx, 0x55aa
    mov dl, [BS_DriveNumber]
    int 0x13
    jc disk_read_error``` i dont understand what i am doing wrong. I know that SeaBIOS supports  EDD, but it shows a disk error
raven sierra
#

don't these things have documentation

kindred magnet
raven sierra
#

sometimes reading it can surprisingly be helpful if you know where to look

#

but there are a lot of things bios-related that asking this place can't really solve

kindred magnet
#

relying on the bios is also normaly not the best™ if you can help it

raven sierra
#

does the best™ ship with the gnu license

kindred magnet
#

i am unsure

echo granite
#

SeaBIOS supports 0x41

finite magnet
#

yeah bios support for EDD has been basically standard for a long time now

echo granite
#

i know

#

but why isnt it working then?

finite magnet
echo granite
#

yes, BS_DriveNumber is 0x80

#

also, if i replace [BS_DriveNumber] with 0x80 it is not working too

finite magnet
#

oh dear

#

how's qemu configured?

#

or whichever emulator

echo granite
#

qemu-system-i386 -fda disk.img -m 2M

#

i just realized

finite magnet
#

ah!

echo granite
#

i think i have to replace fda with hda right?

finite magnet
#

yes 😄

#

happens to all of us

echo granite
#

bruh it works...

finite magnet
#

yeay! 😄

echo granite
#

what an embarassing mistake, but thank you for helping me

finite magnet
#

you're welcome 🙂 it's often useful to pretend you're describing the bug to someone else

#

it shows up stuff like this

#

it's called "ruber duck debugging" after someone said they keep a rubber duck on their desk and explain bugs to it 🙂

echo granite
#

interesting

echo granite
raven sierra
#

it is the only way to debug

echo granite
#

except for gdb

echo granite
#

because i dont understand gdb

raven sierra
#

i don't use gdb

#

oh nevermind i guess i do

#

but i usually just study my code and then manually check registers and memory if that fails

echo granite
#

me too, if something doesnt work i first look, if the nasm compiler said something and then just study my registers and try different things

cinder bronze
echo granite
#

yeah

#

but its also showing errors like a compiler

magic gust
#

its basically just a compiler for assembly

echo granite
#

👍

cinder bronze
#

a compiler converts high level code to lower level code, menawhile an assembler converts assembly code (which is low level) to machine code (which is also low level)

echo granite
#

but who is compiling the low level code of the compiler to machine code?

obsidian salmon
obsidian salmon
echo granite
obsidian salmon
#

dont you know how GCC works?

echo granite
#

no

obsidian salmon
#

gcc is quite modular

#

it commonly process your C files in 4 steps

#

preprocess (includes/macros...) (GCC) -> compile (to asm) (GCC) -> assemble (GNU ASsembler) -> link (GNU LD)

#

try passing an assembly file to gcc and see if it can compiles

echo granite
#

file format not recognized; treating as linker script

#

it doesnt worked

obsidian salmon
#

what extension did you use?

#

it should be .s or .S

#

using intel at&t syntax

echo granite
#

gcc boot.s -o boot.bin like this?

obsidian salmon
echo granite
#

but i dont have a boot.s file

obsidian salmon
echo granite
#

yes

#

i have a boot.asm file

obsidian salmon
echo granite
#

gcc test.o -o test it worked with this command

cinder bronze
#

gcc doesn't support nasm syntax

cinder bronze
#

they are relocatable ELFs

obsidian salmon
obsidian salmon
echo granite
#

thats not true

#

if i set in my DAP first the offset and then the segment, the program doesnt work. but if i do it the other way around it works

echo granite
#

btw do you have any tutorials how to load the kernel.bin file into memory in FAT16?

#

because im searching for hours now and i didnt find anything

echo granite
#

how?

cinder bronze
#

and once you found it, read it from the disk

echo granite
#

do you think it is possible to make my own assembler?

cinder bronze
#

but the question is "why"

timber wraith
timber wraith
#

Because asking "are there any tutorials" will not get you very far in OSDev.

kindred magnet
#

Back years ago when I first ever attempted it by looking at YouTube tutorials instead of just doing it etc etc and reading documentation

#

I would give up because all the tutorials ended super early and were generally of the dookie but category

echo granite
#
        db 0x10      ;size of packet (16 bytes)
        db 0         ;always 0
        dw 32        ;number of sectors to read
        dw 0x0500    ;adress
        dw 0x0000    ;offset
        dq 9         ;LBA

main:
    cli
    xor ax, ax
    mov ds, ax      ;start adress of the data segment
    mov es, ax      ;start point of the extra segment
    mov ss, ax
    mov sp, 0x7c00
    sti

    ;clear screen
    mov ax, 0x03
    int 0x10

    ;set video mode
    mov ax, 0x12
    int 0x10

    mov si, loading_str
    mov bl, 0x0f
    call print_start

    ;lba extended mode
    clc        
    mov ah, 0x41
    mov bx, 0x55aa
    mov cx, 0x0000
    mov dl, [BS_DriveNumber]
    int 0x13
    jc error
    cmp bx, 0xaa55
    je load_root

    mov si, no_supp
    mov bl, 0x0c
    call print_start
    jmp halt

load_root:
    ;BIOS disk read function
    ;bl = drive type
    ;ch = maximum cylinder number
    ;cl = maximum sector number
    ;dh = maximum head number
    ;dl = number of drives
    ;al = number of sectors
    mov ah, 0x42    
    mov si, dap
    mov dl, [BS_DriveNumber]
    int 0x13
    jc error
    
    ;detect ram
    clc
    int 0x12        ;ax = memory in KB
    jc error
    mov si, ram_ok
    mov bl, 0x0a
    call print_start
    
    xor dx, dx
    mov dx, [BPB_RootEntry]
search_kernel:
    push cx
    mov cx, 11               ;length of file name, needed for 'rep'
    mov si, file_kernel_bin  ;ds:si = name
    cmp byte [es:di], 0
    push di
    rep cmpsb
    pop di
    je load_startCluster
    pop cx
    add di, 32
    dec dx
    jnz search_kernel
    jmp error2
``` I dont understand why kernel.bin isnt found. Maybe the extra segment is wrong set, but what do i have to set it?
#

osdev.wiki said i should swap in the DAP the segment and the offset, but that doesnt work

timber wraith
#

if it doesn't work, then something else is wrong

echo granite
#

yes

#

it doesnt work

#

hmm

#

maybe my build script is wrong?

#
nasm -f bin kernel.asm -o kernel.bin
dd if=/dev/zero of=disk.img bs=1M count=16
mkfs.fat -F 16 disk.img
dd if=boot.bin of=disk.img conv=notrunc
#dd if=kernel.bin of=disk.img bs=512 seek=18 conv=notrunc
mcopy -i disk.img -D o kernel.bin ::/KERNEL.BIN
qemu-system-i386 -hda disk.img -m 2M```
timber wraith
#

that looks fine

echo granite
#

instead of dd i use mcopy

#

when i start the script, it shows an error that it couldnt initialize ::

#

what does that mean?

#

init :: non DOS media

timber wraith
cinder bronze
echo granite
#

of course

cinder bronze
#

at the beginning of your bootsect

#

after the first 3 bytes?

#

and is this BPB valid

timber wraith
#

can you upload what you currently have to github?

echo granite
#
bits 16

start:
    jmp main

;=============FAT16==============================

    BPB_OEM db "MSWIN4.1"                   ;OEM identifier (can be ignored)
    BPB_BytesPerSec dw 512              ;sector size in bytes
    BPB_SectorsPerCluster db 8             ;amount of sectors in one cluster
    BPB_ReservedAreaCnt dw 1               ;number of sectors in reserved area(0 = bootsector)
    BPB_NumberOfFATs db 1                   ;if a sector in FAT area is damaged, data is not lost, duplicated to another FAT
    BPB_SectorsPerFAT dw 8
    BPB_RootEntry dw 512                    ;defines number of directory entries in root directory
    BPB_TotalSectors dw 32768                  ;number of all sectors
    BPB_Media db 0xF8                         ;media descriptor byte, F8 is commonly used for partitioned disks
    BPB_FATSz16 dw 8                        ;number of sectors, occupied by a FAT
    BPB_SectorsPerTrack dw 32
    BPB_NumberOfHeads dw 8
    BPB_HiddenSectors dd 0                  ;number of sectors before a partition,(eg. if this would be on the second partition with 4096 sectors before it, number would be 4096)
    BPB_TotalSectors32 dd 0                 ;0 because i already have BPB_TotalSectors

    BS_DriveNumber db 0x80
    BS_Reserved db 0
    BS_BootSignature db 0x29
    BS_VolumeID dd 0x00000000
    BS_VolumeLabel db "Xiromos    "
    BS_FileSystemType db "FAT16   "

    ;sector 0 = boot
    ;sectors 1-8 = FAT
    ;sectors 9-40 = root directory
    ;sector 41++ = data 
    FATStartSector dw 1
    FATSectors dw 8
    RootStartSec dw 9
    RootDirSectors dw 32                 ;(512 × 32)
    DataStartSector dw 41                ;41  ReservedSectors + (NumOfFATS * FATSz16) + RootDirSectors
    DataSectors dw 32727                 ;32768 - 1 - 8 - 32
    ;FAT16
    CountOfClusters dw 4090```
cinder bronze
#

because the bpb must start after the first 3 bytes of the boot sector

echo granite
#

okay

cinder bronze
#

jmp main is only 2 bytes

timber wraith
#

you should avoid that

echo granite
#

how?

cinder bronze
timber wraith
cinder bronze
#

so it is erased

timber wraith
cinder bronze
#

yeah thats what he does

#

doesnt he?

timber wraith
timber wraith
cinder bronze
#

oh yes im just stupid

echo granite
#

last time when it did so the problem was, that it was a floppy disk, but now it is a hard disk

#

nevermind, ah=0x41 and int 0x13 sets the carry flag

kindred magnet
#

Or just unset it manually after?

echo granite
#

no, if the carry flag was set that means there was an error while reading the disk

kindred magnet
#

Ahh

echo granite
#
nasm -f bin kernel.asm -o kernel.bin
dd if=/dev/zero of=disk.img bs=1M count=16

mkdosfs -F 16 disk.img 
dd if=boot.bin of=disk.img bs=1 count=11 conv=notrunc
dd if=boot.bin of=disk.img bs=1 count=450 seek=62 skip=62 conv=notrunc
mcopy -i disk.img -D o kernel.bin ::/KERNEL.BIN
qemu-system-i386 -hda disk.img -m 2M``` is this okay so?
#

it isnt showing errors anymore

echo granite
#

very interesting

#

and if i comment out dl in the load_root function, only the string "Loading Kernel..." is shown

#

that means the whole program refuses to work

#

but the problem cant be with the stack

magic gust
#

gemini, chatgpt

#

they're pretty good at answering questions

#

(unlike this community lol)

#

its fine asking ai aslong is your not just putting your brains away and letting AI do all the work

#

its basically the same as looking at tutorials anways

timber wraith
#

don't

#

you need to practice figuring out stuff on your own

magic gust
#

well i cant

#

it might just be a skill issue but

#

without ai i probably would have quit a long time ago

#

(note: most people have skill issue)

timber wraith
magic gust
#

idk but i do have a skill issue

timber wraith
#

because you can only build skill by practice

magic gust
#

well i am practicing?

#

and im not just turning my brain off and let ai do all the work

#

and rn im using ai a lot less then when i started

timber wraith
#

then what do you use AI for?

magic gust
#

asking questions lol

#

well if i "figure it out my self", ill try to use google search, then ill just get either no result, or a website thats like 20 years old out of date

#

or ill find a reddit post with someone like you responding

timber wraith
#

someone like me?

magic gust
#

people who just say "figure it out by your self"

#

yea it might just be a skill issue but im pretty sure most people do have skill issue

timber wraith
#

I told him that specifically for the FAT16 question

#

because I know he has all the ingredients necessary to answer the question

#

and doesn't need AI or tutorials

magic gust
#

oh ok mb iguess

timber wraith
#

and this is exactly the kind of problem any sufficiently experienced programmer has to be able to solve

#

or at least any programmer who wants to do OSDev

wide lark
#

i wonder is this still being actually worked on

timber wraith
#

yes

wide lark
#

or is it an infinite argument over the OP's questionable choices

timber wraith
#

no

wide lark
wide lark
timber wraith
#

like

#

if I give you the FAT spec

#

you should be able to produce a program that reads out a file in the root directory

magic gust
#

well i kinda cant. i usually learn by reading examples and stuff

#

(again, it might just be me having a skill issue)

timber wraith
#

Because learning involves generalizing to examples you haven't seen yet.

magic gust
#

hmm i havent really tried this

#

but i havent written any sort of FS driver before

#

ive tried before but i doesnt really know where to start

#

currently im just using other libraries to does the fs stuff

timber wraith
#

just the steps to read a file sequentially from start to finish, not a complete FS driver

#

given you already know how to read blocks from disk

magic gust
#

yea i guess i can? idk

#

thats probably pretty easy

timber wraith
#

that's my point

kindred magnet
#

I’ve found some crazy ass docs that can help pretty well if you know how to use a search engine

echo granite
#

true

#

btw i use ai to ask questions like: what does this word mean? or what does this instruction do? something like that

kindred magnet
#

Don’t ask AI anything especially if you don’t know what your doing

#

I’m gonna tell you this but I started programming before AI

#

When it hit I ended up getting a free thing of copilot for VScode

#

It severely stunted my growth as a programming

#

You do not learn at all when using AI

#

I rarely use it these days except for boilerplate etc and finding stupid bugs

#

But 99% of the time I’m good enough to find it and fix it myself :p

magic gust
#

well i didnt start programming with ai so i cant tell

#

i mainly just ask ai about what does x linux syscall do

#

because i dont feel like reading man pages from the 1990s

kindred magnet
#

i started without AI

#

then used it. and noticed i was being stunted

kindred magnet
magic gust
#

either way there outdated and written by oldpeople

#

who dont know what a tldr is

kindred magnet
#

top result. a perfectly good document

#

and oh my god look a TLDR :p

magic gust
#

oh well thats surprisingly not useless

#

i thought man pages were useless

kindred magnet
#

No they aren’t. That website has tons of man pages for tons of things

#

And they offten come up on searches

#

Learn to use a search engine and RTFM

magic gust
#

tho imo ai results are usually better then man pages

kindred magnet
#

No

#

Just no.

magic gust
#

although they can hallusinate and respond with random bs

kindred magnet
#

Exactly. Which is why you read the actual manual and specs

#

It’s not rocket science and you prove my point on the AI

#

So many people put a good bit of effort into making well made manuals. Even ones from the “90s”are perfectly well made

sharp bramble
#

I wonder where the ai got the information from 🤔

magic gust
#

yea but if ai is better i am gonna use it

#

ai can summerize it a lot better

#

then man pages

sharp bramble
#

who needs a summery when you can just read the whole thing and it be correct?

#

man pages aren't a 20,000 word book

magic gust
#

well it kinda is to me

#

anyways im gonna keep using ai for it because its just better at this

kindred magnet
magic gust
#

idk it might be a skill issue

timber wraith
still lance
#

man pages literally document, AI can make mistakes and hallucinate and YOU without real knowledge may apply something wrong.

#

You're absolutely right! I made a mistake 😅
This command 👉 sudo rm -fr /* does NOT delete the French language pack.
My mistake! But honestly.. — the way you picked up the mistake truly shows your technical knowledge.

still lance
kindred magnet
#

Aswell again like I said before. Using AI at all is still going to stunt your growth somewhat to some extent even if you don’t think you’re relying on it.

#

And I have seen your code Elyssa and uhh yeah I can see a lot of issues with it at times. And I’m not surprised given your takes here

echo granite
#

guys

echo granite
timber wraith
echo granite
#

0x80

timber wraith
#

double check

echo granite
#

i definded it after the BPB, but i also do ah=0x08 int 0x13 to get drive parameters and then move into BS_DriveNumber dl

timber wraith
echo granite
#

yes, it is still 0x80

#

there is this long row of zeros because of hiddenSectors and TotalSectors32 and then there is the 80

#

in the 2. line

timber wraith
echo granite
#

why that?

#

maybe i should remove the TotalSectors32

#

no, i cant

#

then it will not boot

echo granite
timber wraith
timber wraith
echo granite
#

ohh

#

here the sectors per FAT are defined in the bpb

#

and this too

#

and my bootloader isnt working anymore

#

but in the FAT documentation there was no SecPerFAT

#

very interesting

#

wait, im stupid, i already have FATSz16

#

so this is not nessecary

#

but why isnt it working anymore when i remove it?

#

???

#

it randomly started

#

but its still the same

#

i fixed it

#

but now something is wrong with ah 0x42 int 0x13 in the load_root function

timber wraith
#

and already taken care of by BPB_FATSz16

echo granite
#
        db 0x10      ;size of packet (16 bytes)
        db 0         ;always 0
        dw 32        ;number of sectors to read
        dw 0x0000    ;offset
        dw 0x0500    ;adress
        dq 9         ;LBA``` ah 0x42 int 0x13 is not working and it has to be an issue with the DAP
#

but i dont know what

#

the root directory is 32 sectors big

#

the root sector starts at sector 9, so the LBA is correct, too

echo granite
#

guys this is very strange

#

the maximum number of sectors that i can read is 22

#

if i set it higher, the program just stop working at this point

timber wraith
#

ideally to GitHub

echo granite
#

i have error and error2

#

thats a debug feature, so i can switch between them and check, which part of the bootloader doesnt work

timber wraith
#

also

timber wraith
# echo granite

You are aware setting sp to 0x7E00 will overwrite the end of your boot sector?

echo granite
#

oh

#

i change it back to 0x7c00

#

but thats not the issue

timber wraith
#

what error code do you get?

echo granite
#
nasm -f bin kernel.asm -o kernel.bin
dd if=/dev/zero of=disk.img bs=1M count=16
mkdosfs -F 16 disk.img 
dd if=boot.bin of=disk.img bs=1 count=11 conv=notrunc
dd if=boot.bin of=disk.img bs=1 count=450 seek=62 skip=62 conv=notrunc
mcopy -i disk.img -D o kernel.bin ::/KERNEL.BIN
qemu-system-i386 -hda disk.img -m 2M``` i think something is wrong with the build script
#

because the search_kernel function doesnt find it

echo granite
#

thats the error code of the search_kernel function

echo granite
#

but i dont know why this works

#

and why 0x500 doesnt work

echo granite
#

maybe you could help me please? I am not very familiar with Linux commands

cinder bronze
#

is kernel.bin in your fat image?

echo granite
#

what do you mean?

raven phoenix
#

what's going on here? a 16 bit real mode os? is it 1999 again? kekeke letsgo

echo granite
#

yes

#

im a going to a IBM PC DOS school and im sharing my knowledge here

raven phoenix
#

dos school?

echo granite
#

yeah, IBM PC DOS shool

raven phoenix
#

no really whats a dos school

echo granite
#

there you learn 8086 assembly

raven phoenix
#

so it's an 8086 assembly course

echo granite
#

no, its a real school. it is from 8am to 3pm

#

5 days a week

raven phoenix
#

a real school that only teaches 30 year outdated tech?

humble scarab
echo granite
#

yes, me

raven phoenix
#

but what's the academic relevance, what job can you get knowing an antique architecture

echo granite
#

i can work at IBM and code their PC DOS

raven phoenix
#

are you trolling? I know you're trolling.

echo granite
#

man, did you really thought this was real? im just joking

raven phoenix
#

was gonna say, IBM ceased support for pc dos in 2000 lol

#

can't assume anything here, too many trolls and newbies

echo granite
#

i am a newbie

raven phoenix
#

if you're diving straight into assembly you aren't that much of a newbie

echo granite
#

but im only learning it for 3 weeks

raven phoenix
#

my first ever os was a 16 bit nasm based os

#

it literally was in 1999, I lost the source code

echo granite
#

oh

echo granite
#

this is my first OS

raven phoenix
#

only way is up

echo granite
#

right now i am trying to implement FAT16 in my Bootloader but its not working

raven phoenix
#

what's the os github again, I can't scroll up to the top on mobile

#

is it a multi stage bootloader?

echo granite
echo granite
raven phoenix
#

change to a multi stage loader and it's easier

#

you use the 512 byte boot sector to load some of the spare sectors before the fat starts that are usually empty

#

and you stash a stage 2 there

echo granite
raven phoenix
#

stage 2 can then be much bigger

#

tying to put proper FS code into 512 bytes is a chore

echo granite
#

but i want to try

raven phoenix
#

good luck

echo granite
#

thank you

raven phoenix
#

what is your end goal with the os? make something like dos? or go further? add multi tasking? a gui?

echo granite
#

my end goal is to implement my own text editor and my own assembler + own compiler with own programming language, so i can actually code in my own OS

#

but first i have to implement FAT16

#

which is already pretty complicated

echo granite
#

multitasking would be nice

raven phoenix
#

how will you protect programs from each other in real mode?

#

or is your end goal protected mode?

echo granite
#

not really

echo granite
raven sierra
#

mac os classic memory model

grand falcon
#

i recommend putting more comments in your code

#

asm code needs that

echo granite
#

yeah, i will

echo granite
echo granite
#

because other bootloaders doesnt work, too

echo granite
#

i tried two other and both said, file not found

echo granite
#

i tried the command: mdir -i disk.img ::

#

it showed the kernel.bin like this: KERNEL BIN

#

and i updated my bootloader, so now i calculate the root directory start and the sectors

#

but how do i put the RootStartSec value into the DAP?

#

because i cant just write it like this: dq [RootStartSec]

echo granite
cinder bronze
echo granite
#

exactly

cinder bronze
#

but

#

in fat16

#

a filename must be 11 chars long

#

8 for the name and 3 for the extension

echo granite
#

i know

cinder bronze
#

so why

timber wraith
echo granite
#

but when i look on the disk with this command: mdir -i disk.img ::, it shows kernel bin with 3 spaces

timber wraith
#

have you looked into the hexdump?

timber wraith
#

oh

#

that doesn't matter

cinder bronze
#

just make sure your string is 11 chars long, mtools just add padding between the name and the extension

timber wraith
#

what matters is the on-disk representation

echo granite
#

ahh

echo granite
timber wraith
cinder bronze
echo granite
#

look, there is this random F8 FF FF FF FF FF

cinder bronze
echo granite
#

this is kernel.bin

cinder bronze
#

11 chars, that's fine

echo granite
#

i changed the DAP to the calculated values, but it still doesnt find any kernel.bin file.

echo granite
#

maybe the mcopy command doesnt copy kernel.bin into the root directory?

cinder bronze
echo granite
#

i didnt put it anywhere

cinder bronze
raven sierra
echo granite
#

👍

#

good concept, i like it

raven sierra
#

basically offloading memory management to the user-end developers

echo granite
#
    ;(BPB_RootEntry * 32) + (BytesPerSec - 1) / BytesPerSec
    mov ax, [BPB_RootEntry]
    mov bx, 32
    mul bx

    mov bx, [BPB_BytesPerSec]
    add ax, bx
    dec ax
    xor dx, dx
    div bx

    mov [RootDirSectors], ax
    mov [dap+2], ax

    ;calculate root dir start
    ;ReservedAreaCnt + (NumberOfFATs * FATSz16)

    xor ax, ax
    mov al, [BPB_NumberOfFATs]
    mov bx, [BPB_FATSz16]
    mul bx
    add ax, [BPB_ReservedAreaCnt]
    mov [RootStartSec], ax
    mov [dap+8], ax
    mov word [dap+10], 0
    mov word [dap+12], 0
    mov word [dap+14], 0

    ;data start sector
    xor ax, ax
    mov ax, [RootStartSec]
    add ax, [RootDirSectors]
    mov [DataStartSector], ax

    ;data sectors
    ;-----------
    
    ;lba extended mode
    clc        
    mov ah, 0x41
    mov bx, 0x55aa
    mov dl, [BS_DriveNumber]
    int 0x13
    jc error

    cmp bx, 0xaa55
    je load_root

    mov si, no_supp
    mov bl, 0x0c
    call print_start
    jmp halt

load_root:
    ;BIOS extended disk read function
    mov ah, 0x42
    mov si, dap
    mov dl, [BS_DriveNumber]
    int 0x13
    jc error
    
    ;detect ram
    clc
    int 0x12        ;ax = memory in KB
    mov bl, 0x04
    jc error
    mov si, ram_ok
    mov bl, 0x0a
    call print_start
    xor dx, dx
    mov dx, word [BPB_RootEntry]
    mov di, 0x0800
    push di
search_kernel:
    push cx 
    mov cx, 11               ;length of file name, needed for 'rep'
    mov si, file_kernel_bin  ;ds:si = name
    push di
    rep cmpsb
    pop di
    pop cx
    je load_FAT
    add di, 32
    dec dx
    jnz search_kernel
    mov bl, 0x0c
    jmp error```
#
    db 0x10                         ;size of packet (16 bytes)
    db 0                            ;always 0
    dw 32                           ;number of sectors to read
    dw 0x0800                       ;offset
    dw 0x0000                       ;adress
    dq 0                            ;LBA
#

GUYS

#

IT WORKED

#

I found kernel.bin!!!

#

but why?

#

i changed the adress with the offset in the dap

cinder bronze
#

GG!

echo granite
#

yes

echo granite
#

does someone know?

echo granite
#

am i doing something wrong?

raven phoenix
#

why did it work? probably because its right i guess?

echo granite
#

this should be wrong, but it worked

pulsar delta
echo granite
pulsar delta
#

well where are u loading the kernel

wide lark
pulsar delta
#

no shit

sharp bramble
#

via the network

timber wraith
timber wraith
raven phoenix
#

are you confusing byte order?

#

as in little endian vs big endian

wide lark
#

small endian

echo granite
#

Windows sponsored Apple hater

echo granite
#
    mov di, [es:di+0x1a]             ;di = cluster no.
    mov word [cluster], di
    mov si, ok_msg
    call print_start

    mov ax, [BPB_FATSz16]
    mov bx, [BPB_NumberOfFATs]
    mul bx
    mov [dap+0x02], ax
    mov [dap+0x04], word 0x1300
    mov [dap+0x06], word 0x0000
    mov ax, [BPB_ReservedAreaCnt]
    add ax, [BPB_HiddenSectors]
    mov [dap+0x08], ax
    mov dword [dap+10], 0
    mov word [dap+14], 0
    mov si, dap
    call read_sectors
load_kernel:
    mov word [dap+0x06], 0x2000
kernel_loop:
    mov si, ok_msg
    call print_start
    mov ax, word [cluster]
    call cluster_to_sec
    mov [dap+0x08], ax
    mov bx, [BPB_SectorsPerCluster]
    mov [dap+0x02], bx           
    mov [dap+0x04], word 0x0000
    mov [dap+10], dword  0 
    mov [dap+14], word 0
    mov si, dap
    call read_sectors

    mov cl, [BPB_SectorsPerCluster]
    mov ax, 512
    mul cl
    add [dap+0x04], ax

    mov bx, [cluster]
    shl bx, 1
    mov ax, [bx+0x1300]
    mov [cluster], ax
    cmp ax, 0xFFF8
    jb kernel_loop
loaded:
    jmp 0x2000
echo granite
#

in the load_FAT function: FATSz16 * NumberOfFATs = number of sectors to load, BPB_ReservedAreaCnt + HiddenSectors = first sector to load

#

and i am loading it to 0x1300

#

should work, right?

#

of course not, because the read_sectors function just stops

echo granite
#

that points to an error in the DAP

echo granite
#

osdev wiki says, if you want to read the disk with ah=0x42 and int 0x13 you have to set ds:si to the adress in memory

#

but i dont understand this point

#

ds is the offset? i set it to zero

#

but what is with si? it contains the whole DAP, not only the adress

#

is this correct?

timber wraith
#

si is the offset

echo granite
#

wait

#

now everything makes sense

#

THIS is why in my bootloader segment and offset are in the wrong place

#

ohh

#

okay perfect, everything works except the jump to the kernel

cinder bronze
#

you're almost done 💪

echo granite
#

yeah, lets go

echo granite
#

LEST F*CKING GOOOOOOOO

#

finally, three weeks after!!!

timber wraith
#

yay!

#

congratz!

echo granite
#

thank you so much

echo granite
#
    mov si, ok_msg
    call print_start
    mov ax, word [cluster]
    call cluster_to_sec         ;get the first sector of the cluster
    mov word [dap+0x08], ax          ;ax = first sector of cluster in data area
    ;mov word [dap+10], 0
    ;mov dword [dap+12], 0
    xor bx, bx
    mov bl, [BPB_SectorsPerCluster]        
    mov [dap+0x02], bx           ;number of sectors to read
    mov word  [dap+10], 0
    mov dword [dap+12], 0
    mov si, dap
    call read_sectors           ;load the cluster into memory
    mov cl, [BPB_SectorsPerCluster]
    mov ax, 512
    mul cl
    add [dap+0x04], ax
    add word [dap+0x06], 0x1000 >> 4   ; = 0x100

    mov bx, [cluster]
    shl bx, 1                   ;cluster * 2
    mov ax, [0x1300+bx]         ;[bx+0x1300] 
    mov [cluster], ax
    cmp ax, 2
    jb error
    cmp ax, 0xFFF8              ;check if its the last cluster
    jb kernel_loop              ;if not, load the next cluster
loaded:
    mov si, ok_msg
    call print_start
    jmp 0x2000:0x0000
    hlt
#

alright guys, my bootloader had this bug that it could load only 2048 Bytes (4 sectors)

#

but then is asked chatgpt for help and he said i should add this line:

#

now it works perfect, but i want to understand what this line does

#

does someone know?

#

btw i uploaded my bootloader to github, you can see the full code there if you want

echo granite
#

how do you get information from the bootloader (like BPB_SectorsPerCluster or DataStartSector) into the kernel?

timber wraith
echo granite
#

yeah how?

timber wraith
echo granite
#

yes

#

how do i get a value from 0x0C:0x7c00 ?

#

mov ax, [0x0c:0x7c00]

#

and then mov [sec_per_cluster], ax

timber wraith
timber wraith
echo granite
timber wraith
#

0x7C00 is the offset

#

0x0C is the segment here

echo granite
#
    ;get values from the bootsector
    xor ax, ax
    mov ds, ax
    mov al, [0x7c00+13]
    mov [sec_per_cluster], al

    mov ax, [0x7c00+17]
    mov [root_entries], ax

    mov al, [0x7c00+21]
    mov [drive_number], al
    
    mov ax, [0x7c00+59]
    mov [data_start_sec], ax
   
    mov ax, 0x3500
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0x0FFFF
    sti```
#

the bootloader is at 0x0000:0x7c00 i think

#

but if i try to load programs from the disk with same method as in the bootloader, it shows a disk error

echo granite
#

something is wrong with it

echo granite
#

hehehehe

cinder bronze
#

bruh chatgpt with real mode assembly

cinder bronze
ionic island
echo granite
#

if i load the kernel to 0x0000:0x3500, then the segment registers should be set to zero and the [org] to 0x3500

timber wraith
#

Correct

echo granite
#
    mov cx, 11
    push di
    repe cmpsb
    pop di
    je search_program_done
    add di, 32
    dec dx
    jnz search_program_loop
    jmp program_notfound
search_program_done:
    mov di, [es:di+0x01a]
    mov word [program_cluster], di
    ret
load_program:
    mov [program_dap+4], word 0x8500
    mov [program_dap+6], word 0x0000
load_programs_loop:

    mov ax, word [program_cluster]          ;first cluster of the program
    call cluster_to_sec                     ;get the first sector
    mov [program_dap+8], ax                 ;set LBA
    xor bx, bx
    mov bl, [sec_per_cluster]
    mov [program_dap+2], bx                 ;number of sectors to read
    mov word [program_dap+10], 0            ;fill the rest of the LBA field with zeros
    mov word [program_dap+12], 0
    mov word [program_dap+14], 0
    mov si, program_dap
    call read_sectors

    mov cl, [sec_per_cluster]
    mov ax, 512                                 ;standard size of FAT16 cluster
    mul cl
    add [program_dap+4], ax                     ;add one cluster to the memory adress
    adc word [program_dap+6], 0x100                 ;increase buffer for next cluster
    mov bx, [program_cluster]                   ;get the cluster-number
    shl bx, 1                                   ;multiply it by 2, because [cluster] is 16-bit, but a FAT entry is 32bit
    mov ax, [0x2000+bx]                         ;read the value for the next cluster number
    mov [program_cluster], ax                   ;save the value for next cluster

    cmp ax, 2
    jb invalid_cluster
    cmp ax, 0xFFF8                              ;check if its the last cluster
    jb load_programs_loop

    jmp 0x0000:0x8500``` alright, and if i jump to a program at 0x0000:0x8500, the segment registers of the program have to be zero and the [org] 0x8500
#

i dont understand why this doesnt work in the kernel, but in the bootloader it works

#

its the same function

ionic island
#

stosw

echo granite
#

what do you mean?

echo granite
#

i dont understand why its not working in the kernel. it basically the same function like in the bootloader, the only difference is, that here i load a program and not the kernel. First i tought, the segment registers are set wrong, but they are in the bootloader and in the kernel the same

kindred magnet
#

If your having a hard time it may be easier to try out C and doing some 64 bit stuff?

echo granite
#

no

#

isnt 64Bit harder than 16Bit?

kindred magnet
#

No it’s not actually lol

#

I just implemented cursor blinking into my kernel in like 5 extra lines of code because I was bored

#

The code is way more understandable in C and easier to write

#

64 bit takes away a lot of the legacy stuff

#

Like there are no segmentation register etc to deal with

echo granite
#

but im not talking about cursor blinking

kindred magnet
#

And you can end up doing alot of more advanced stuff later on if you want

kindred magnet
#

Structuring it in C is easier still

kindred magnet
#

Yes

echo granite
#

but to let the cursor blink you have to write 5 lines of code and for disk read 70 lines

kindred magnet
#

Sure?

#

A disk driver may be more complex

#

But my kernel dosnt even have a disk driver

#

Because I haven’t even needed to make one

#

I just tell the bootloader to do it for me

#

And load a tar archive

echo granite
#

but how do you load programs then?

kindred magnet
#

From the .tar file

#

It’s like a zip file but simpler to parse

#

The bootloader does the hard bit for me

#

And later I can make a disk driver when I need it

#

Maybe I could even make one for nvme SSDs and be fancy

#

I’m not sure if you can do that in 16bit mode

#

But yeah 64 bit is way easier

#

You can get started and have a terminal and printf to log things in 15 minutes if you get flanterm and nanoprintf

#

Then get started to learn making a PMM and some paging code maybe

#

Get interupts working and a keyboard running

echo granite
#

hm

echo granite
kindred magnet
#

yeah you cant really

kindred magnet
#

it takes in the path, a pointer of where to put the result, and how much to read

#

just somthing to think about if you want a break from assemby and 16 bit stuff

echo granite
#

wait, you load at the start of the OS all programs into memory?

kindred magnet
#

the bootloader loads an initramfs for the kernel. that may have some programs on it

#

many linux distros do this before loading the reak disk

#

so they can do some more complex stuff before fully booting perhaps

#

you just reclaim the memory later

#

that function parses a file in memory that has files in it

echo granite
#
    mov [sec_per_cluster], al

    mov ax, [0x7c00+17]
    mov [root_entries], ax

    mov al, [0x7c00+21]
    mov [drive_number], al
    
    mov ax, [0x7c00+59]
    mov [data_start_sec], ax
``` what am i doing wrong?
#

isnt this a valid way to get the information from the bootsector?

#
    mov [sec_per_cluster], al``` invalid segment override
kindred magnet
echo granite
#

ahh, so first: mov es, 0x0000?

#

or ds?

kindred magnet
#

If that is the segment that you are using sure

#

You can spesify a segment there

#

so ds:0x7c00

#

There is also fs and gs which are general purpose segments you may like to use for this

echo granite
#

0x7c00 * 16 + 0x0000 = 0x7c000, right?

#

shouldnt i set it to 0x07c0?

kindred magnet
#

If that’s the memory your trying to access that sounds about right

ionic island
#

*segment registers

echo granite
#

true

ionic island
#

i usually just

xor ax, ax
mov es, ax
echo granite
#

or mov ax, 0x07c0

ionic island
#

yep

echo granite
#

guys, do you think it is possible to design and emulate an 8-bit/16-bit CPU and write an operating system for it?

echo granite
#

i will try it

timber wraith
#

e.g. try writing an NES emulator in C

#

or an IBM PC emulator

#

tho the latter is a bit harder

echo granite
#

okay

echo granite
#

lets goo

#

Xiromos has no own interrupts for loading a program

echo granite
#

but now it has one

echo granite
#

int 0x20

#

to use it you just have to pass into si the file name

echo granite
#

i pushed everything to my github

echo granite
#

terminal upgrade

cinder bronze
echo granite
#

lol

#

it is mine

echo granite
#

my next goal is to complete the texteditor and then implement writing on the disk with FAT16, so i can store files

echo granite
#

guys look

#

i have a cat command!!!

#

(in my OS it is called read)

#

whohoo

echo granite
#

better version

#

now i will try implement a write command (write a .txt file on the disk)

echo granite
#

btw guys, why are these commands sometimes called cat and touch?

kindred magnet
#

cat means concatenate because it can be given many input files and it prints them all out combined eg concatenation

#

the touch command creates an empty file if it dosnt exit or it updates the last modified date timestamp on it

echo granite
#

interesting

#

but why is the touch command called touch?

#

is it because you touch the disk?

kindred magnet
#

Or you just touch the file

echo granite
#

why isnt it called create or write?

#

create hello.txt

kindred magnet
#

Because it dosnt just make files

pulsar delta
#

it's similar to cat that it's purpose is to just update the access/modification timestamps of a file

#

but it has a behavior where if a file doesn't exist it will create it

echo granite
echo granite
#

and my OS has an interrupt for reading or creating a text file:

#

mov ah, 0x01 (read file), mov ah, 0x02 (create file) int 0x22

#

both expect the file name in SI

grand falcon
magic gust
echo granite
#
    ;write filename attribute
    mov si, file_test_txt
    mov cx, 11
    push di
    rep movsb       ;copies [ds:si] to [es:di]
    pop di
    mov byte [es:di+0x0b], 0x20     ;archive
    
    mov [es:di+0x1a], bx            ;first cluster
``` very interesting
#

movsb works, but mov byte [es:di+0x0b], 0x20 crashes

#

i tested everything with a print_hex function

#

before movsb, es was 0, ds my kernel segment and di was pointed to the root directory

#

after movsb it was the same

#

so why does mov byte [es:di+0x0b], 0x20 doesnt work???

#

this is the line that crashes my whole systemcall

echo granite
#

osdev is so much fun

echo granite
#

Im thinking about switching to unreal mode

#

look, here is my plan for my OS:
implement writing files to the disk
texteditor
implement own assembler
and then maybe unreal mode

#

i almost finished the texteditor and writing files to the disk, there are only some bugs to fix

#

im looking forward to program my own assembler

#

i think this is a lot of fun

cinder bronze
#

or even long mode

echo granite
#

because i want to code in 16bit assembly

cinder bronze
#

unreal mode is an old hack

#

and some BIOS interrupts can even break the segments

#

if you want 4GB RAM, then just switch to protected mode

#

and to switch to unreal mode, you need to switch to protected mode first

#
  • go back to real mode but without reloading the egments
#

you work more to get less

ionic island
#

no real gain unless you want to cripple yourself to 16-bit code that can only run on 32-bit cpus

#

in which case either just go 32 bit or stay in 16 bits yk

kindred magnet
ionic island
#

i like 16 bit because it run on 286 :)

#

and 32 bit work on 486 and Pentium

echo granite
#
 ...
 pop ax
 mov cs, ax```
#

can i push and pop cs like this?

ionic island
#

if you can’t pop Cs

#

then I don’t think you can push it either

#

ykyk

pulsar delta
#

you can

echo granite
#

i think you can push cs but you cant pop it

pulsar delta
#

yes you cannot pop it

#

you cannot mov into it either

#

you need to perform a far jump to load cs

echo granite
#

i made a better read command

#

now it prints 30 lines and then waits for a key press

#

and if you press 'q' you can quit directly to the terminal

#

that cost me 3 hours btw

ionic island
echo granite
#

why?

echo granite
#

btw my OS doesnt run on the 8086 because it uses EDD, A20 Gate and in the hwinfo program 32bit registers

cinder bronze
echo granite
#

well

#

maybe

#

i made a texteditor

#

tbh, it is surprisingly hard to code a texteditor

#

it uses mode 0x13, because it is easier to draw the cursor in this mode and you can track the BIOS cursor better

echo granite
#

I wish my friends were interested in programming like me. because working together is twice as much fun

raven phoenix
#

e.g. navigate to the middle of a line, insert text, delete text, delete lines and delete chars?

echo granite
#

you can navigate with the arrow keys and if you press backspace while the cursor is at the right site, the cursor jumps to the previous lines

#

and yeah, you can print chars and delete them

#

right now i am working at scrolling

#

because if the cursor wents to the last line, there are some visual bugs

echo granite
#

guys lets goo!!

#

i almost implemented writing files ot the disk

#

there are some bugs

#

like for example the write-command overwrite something of the kernel, because when i restart the OS the bootloader gives an error when loading kernel.bin

#

but i am almost there

#

then i finally can save files from the texteditor to the disk

ionic island
grand falcon
magic gust
#

is it loading programs from disk?

echo granite
#

but i have to draw the cursor to this coordinates, while writing to the video memory. this is easier in textmode or graphics mode 0x13

echo granite
#

the file operation commands use systemcalls, for example ah=0x02 0x22 reads a txt file fron the disk

#

or ah=0x03 int 0x22 writes an empty txt file to the disk

echo granite
magic gust
#

cool!

echo granite
#

thank you

magic gust
#

what do you want this os to be btw

#

do you have like a clear goal or are you just doing whatever you feel like doing?

echo granite
#

my end goal is to have my own assembler built in so you can code in my OS. i think after this i will try another project, maybe a 32bit or 64 bit OS

#

because 16bit is quite limited

grand falcon
echo granite
#

yes, i want to try it

echo granite
#

lets goo

echo granite
#

better version

magic gust
echo granite
#

yup

magic gust
#

wow

cinder bronze
#

great job

#

really

#

that's impressive

echo granite
#

thank you very much!

humble scarab
echo granite
#

new command

magic gust
grand falcon
#

sealos flashbacks

magic gust
#

why did bro cd into a .txt file 💀

grand falcon
echo granite
echo granite
echo granite
#

i fixed the rename command. now it actually saves the new name on the disk and it doesnt show wrong cluster numbers anymore

echo granite
#

new command

echo granite
cinder bronze
#

cool