#Xiromos 16-Bit NASM OS

1 messages · Page 3 of 1

echo granite
#

and i changed, that programs doesnt reload the whole kernel, but instead they return back and restore the previous kernel state

cinder bronze
#

nice

echo granite
#

👍

#

i updated everything on github

echo granite
#

lets gooo, i fixed the write command, now you can actually write things into a file

#

this is the 2000 message of this channel

echo granite
#

my arch linux crashed

echo granite
#

qemu-system-i386 -hda disk.img -hdb disk2.img -fda floppy.img -fdb floppy2.img -m 2M

#

multiple disk support is coming

echo granite
#

if i look in a texteditor into my disk.img i see somtimes random these numbers: F8 FF FF FF

#

what do they mean?

cinder bronze
#

these are hexadecimal values

#

which probably correspond to the bytes of disk.img

echo granite
#

no look, there are somtimes these random bytes, but they do not belong to the root directory or the FAT

cinder bronze
#

like garbage bytes or smth

#

maybe some of your kernel data?

echo granite
cinder bronze
#

idk

echo granite
#

i think this belongs to the disk formatting tool,

#

maybe this are cluster markers?

echo granite
#

yes, i asked my good old friend chatgpt

echo granite
#

I MADE ITTT LETS GOOOOOO

#

muttiple disk support!!!!!

#

it took me a whole day..

#

whohooooo

#

cd = change disk

kindred magnet
#

cd normally means change directory. Then you may do
cd d:/
to change disks or
cd d:/folder
etc

echo granite
#

but change disk is a funny name

#

of course i will rename it because i want to implement directories soon

raven phoenix
#

last cluster in chain

echo granite
cinder bronze
#

cd = change disk isnt very intuitive

echo granite
#

alright i changed it to cdisk

#

because soon i want to implement directories

#

btw there is a command calles lsdisk, which shows you available disks

cinder bronze
#

thats cool

echo granite
#

my OS supports arguments!!!

#

yayyy

echo granite
echo granite
echo granite
#

btw my system supports FAT12, i can read and write files on a FAT12 disk

grand falcon
#

thats very impressive, is this your first os?

echo granite
#

yes

cinder bronze
echo granite
cinder bronze
#

a virtual filesystem

#

because your kernel supports 2 fs right?

echo granite
#

no, FAT12 and FAT16 are nearly indentic so i can use both

#

the only difference is the amount of clusters

cinder bronze
#

ok but let's imagine that you want to add support for another completely different fs

#

for some reason

#

then you would need a vfs

echo granite
#

true

cinder bronze
#

i suggest you write one now

echo granite
#

no

cinder bronze
#

but why

echo granite
#

i dont need it, FAT12 and FAT16 are enough

#

well, i will think about it

cinder bronze
#

ok, but i would make your fs handling architecture cleaner

pulsar delta
cinder bronze
#

why?

pulsar delta
#

why would you

cinder bronze
#

it'd be better than having a function for every fs

pulsar delta
#

sure

cinder bronze
#

like
fs1_read
fs2_read

#

vfs_read is better

pulsar delta
#

well ofc u would have to abstract the two fs's through some common layer

#

but idk if that really constitutes a vfs

cinder bronze
#

hm ig you're right

#

ig it depends on the level of abstraction you want?

pulsar delta
#

it's semantics ig

#

lol

echo granite
#

making a better and simpler texteditor

echo granite
#

guys, i need your help. I have a systemcall (int 0x20) for loading and executing a program. it expects the filename in SI. if i just put a regular variable with the filename (eg: name db "TEST BIN), it works fine, but if i put a buffer in there, it doesnt work. I use cmpsb in my syscall, does it have problems with buffers? i checked the buffer and it has the correct filename in it, so i dont understand why rep cmpsb doesnt find it

echo granite
#
    mov di, command_buffer+8
    mov al, 'B'
    stosb
    mov al, 'I'
    stosb
    mov al, 'N'
    stosb
    
    mov si, command_buffer
    mov di, read_buffer
    mov cx, 11
    rep movsb
    mov si, read_buffer
    call print_buffer
    int 0x20
    ret
print_buffer:
    mov cx, 11
    mov ah, 0x0e
.loop:
    lodsb
    int 0x10
    loop .loop
    ret```
#

the print_buffer function shows, that the filename is in the correct format, but the interrupt doesnt find it in the root directory

#

but when i pass instead of the buffer a normal variable: calc_bin: db "CALC BIN", then it works fine

echo granite
#

oh yeah guys, my system now supports floppies too!!

#

now you can use A and B as a floppy, C as the root disk and D and E as external or additional drives

#

you have basically unlimited space

#

thats so cool

echo granite
#

made a new syscall for file operations on floppy disks

echo granite
#
  • if you type a program name into the terminal, the command interpreter searches in the root directory for this name and if found, it will execute it.
#

this is better than the previous version, because there the start of the programs were hardcoded in the kernel and you couldnt add new programs from extern drives

#

but now you can just copy a program onto the disk or if you have a FAT12/FAT16 disk with programs and files you can just read from it, because of multi disk support

kindred magnet
echo granite
kindred magnet
#

direcotories are important

echo granite
#

im not sure if im experienced enough to implement directories

cinder bronze
#

(at least in C, I never tried in asm tbh)

echo granite
#

alright, my OS has now FAT12 floppy disk support, so you can do file operations on floppy disks too

#

there are some bugs but i am trying to fix them

echo granite
#

it uses CHS reading and writing instead of LBA

echo granite
#

is it bad for FAT12 that i am loading my fat on a odd offset?

echo granite
#

wait

#

that doesnt make sense

#

why did someone invented something like FAT12??

#

use FAT16 instead, it is much easier and gives you more disk space

still lance
echo granite
#

but they could use FAT16 for floppies, too

#

thats possible

still lance
#

floppies are tiny

#

disks are bigger

echo granite
#

finally! now you can switch between floppy and hard disks without any bugs.
some commands on the floppy disk doesnt work properly, but i will try fix them.

#

but FAT12 is really hard in comparison to FAT16

pulsar delta
#

Yeah its obnoxious

#

I mean 90% of the logic is the exact same

echo granite
pulsar delta
#

yeah its a bit annoying

#

I mean it's only like 4 lines tbf

echo granite
#

the coolest part of my system: red screen of death

pulsar delta
#

possibly but there is no reason to write it in assembly so like

echo granite
arctic token
little drift
echo granite
little drift
echo granite
#

кроме калькулятора программы я сам писал. и его я тоже ещё перепишу

echo granite
#

i use xiromos btw

echo granite
echo granite
echo granite
#

there are a lot of bugs but i already implemented CD and mkdir for floppies

echo granite
#

little program to format a disk

cinder bronze
#

or store a list of the drives to format in memory (you add one using a f <drive> command for example)

#

and the user can decide to apply the changes with a command

#

or to cancel them

echo granite
#

good idea

raven phoenix
echo granite
#

you can type y or Y

#

btw if you press q you can quit this program

echo granite
#

the help command is now a program

#

and my OS has officially FAT8 support!!

#

my own filesystem

#

because FAT8 doesnt exists officially

timber wraith
#

Microsoft did have an 8-bit FAT file system in Stand-Alone Disk BASIC-80

#

it was infact the original incarnation of FAT

#

but was never supported by DOS, and is very different from FAT12, FAT16, and FAT32

cinder bronze
echo granite
echo granite
#

i think i should use VESA mode more often

#

it gives me a much better resolution

echo granite
#

finally the programs are in a directory

kindred magnet
#

Yoooo

#

GG

echo granite
#

thank you

echo granite
#

now the LS command works in directories too

echo granite
#

and sub-sub directories also work

echo granite
#

i implemented directories for hard disks now

#

and the file operation commands word in directories

echo granite
echo granite
#

finally you can create directories

#

and support for sub-sub directories

cinder bronze
#

there are only 3 levels of dirs?

#

or infinite levels

echo granite
cinder bronze
#

ok

echo granite
#

also i have a debug mode where i see more information than in the normal mode

echo granite
#

i think i will work on implementing multi-tasking now

#

this will take a while

cinder bronze
#

multi taksing in real mode?

#

interesting

echo granite
#

oh yeah guys, i made that 2 programs work now at the same time

#

now i will try that more programs work

#

i will make it so, that the kernel and max. 4 other programs can work at the same time because of memory limits

raven phoenix
echo granite
# raven phoenix how does it work

i hooked int 0x8 (timer) and now the cpu jumps every 18ms from the one program (shell) to the other program (eg. HELP.BIN). this all happens in the timer interrupt where the cpu first saves all the registers, then loads the stack of the other program and jumps to it

raven phoenix
#

do you save regs?

#

ah yes you already said

#

so basically it's preemptive without protection

#

nice

echo granite
raven phoenix
#

how do programs decide what addresses they load

#

do you have an executable format that allows relocation

#

like dos .exe

echo granite
raven phoenix
#

so they are all relocatable and aligned?

#

like .com

#

with a max size of 64k?

echo granite
#

yes, true

raven sierra
#

how's this project going

echo granite
#

very good

raven sierra
#

that's awesome to hear

echo granite
#

thank you

raven sierra
#

is it still 16 bit

echo granite
#

yes, but i plan to make a 32bit OS on top of this, like microsoft did it with windows 3.1 and windows 95. but it will be in assembly too

raven sierra
#

ah

#

operating system as system software approach?

echo granite
#

yeah

cinder bronze
raven sierra
#

the more assembly the better

cinder bronze
#

so maybe, just maybe, there is a reason to that

echo granite
#

to what?

cinder bronze
#

the fact they removed the msdos base from windows

raven sierra
#

evolution and advancement...

echo granite
cinder bronze
#

btw all your routines that use BIOS interrupts will not work in protected mode

echo granite
cinder bronze
raven sierra
echo granite
cinder bronze
raven sierra
#

C will not run on my analytical engine prototype

cinder bronze
#

if you write a C compiler which targets your engine...

#

then it will run

raven sierra
#

suuure

#

just wait until E comes out

echo granite
#
bits 16

start:
    cli
    xor ax, ax
    mov es, ax
    mov ds, ax

    lgdt [gdt_descriptor]   ;load GDT
    mov eax, cr0
    or eax, 1        ;set PE
    mov cr0, eax
    jmp code_off:main

gdt_start:
    dq 0

    ;code segment
    dw 0xffff
    dw 0x0000
    db 0x00
    db 0b10011010   ;access byte
    db 0b11001111   ;flags
    db 0x00

    dw 0xffff
    dw 0x0000
    db 0x00
    db 0b10010010
    db 0b11001111
    db 0x00
.end:

gdt_descriptor: dw gdt_start.end - gdt_start - 1
                dd gdt_start

idt_start:
    times 256 dq 0
.end:
idt_descriptor:
    dw idt_start.end - idt_start - 1
    dd idt_start

bits 32
main:
    mov ax, data_off
    mov es, ax
    mov ds, ax
    mov ss, ax
    mov esp, 0x90000

    call set_idt

    mov edi, 0xb8000
    mov eax, 0x07410741   ; 'AA'
    mov [edi], eax
    mov esi, msg
    call print_string
halt:
    hlt
    jmp halt

set_idt:
    mov ecx, 256
    mov edi, idt_start
    xor eax, eax
    rep stosd
    rep stosd

    mov ecx, 256
    xor ebx, ebx

.setidt_loop:
    mov eax, isr_default
    push ecx
    call set_idt_entry
    pop ecx
    inc ebx
    loop .setidt_loop

    lidt [idt_descriptor]
    ret
isr_default:
    cli
    iret

print_string:
    pusha
    mov edi, 0xb8000
.next:
    lodsb
    cmp al, 0
    je .done

    mov ah, 0x07
    stosw
    jmp .next
.done:
    popa
    ret
#

guys i have a problem

#

the CPU doesnt triple fault, but why does it not print a text? i am in 0x03 text mode

#
    mov eax, 0x07410741   ; 'AA'
    mov [edi], eax``` even this doesnt work
#

am i stupid?

#

btw code_off is 0x08 and data_off is 0x10

#

protected mode is very complicated

cinder bronze
echo granite
#

yeah, i set 0x03 befor jumping to the kernel

cinder bronze
cinder bronze
echo granite
#

hm, but i was int 0x12 video mode, which already starts at 0xa0000

cinder bronze
#

each character in vga text mode is 2 bytes

#

1 byte for the character and another byte for its attributes

echo granite
#

okay

echo granite
cinder bronze
echo granite
#

yeah...

cinder bronze
#

where does it crash

echo granite
#

maybe there is an error loading the GDT

cinder bronze
#

and send the output here

#

and btw when reloading your segments you need to fill FS and GS

echo granite
#

because i do CLI

cinder bronze
echo granite
#

no

cinder bronze
#

hm

#

weird

echo granite
#

yes..

echo granite
cinder bronze
#

what about this GDT?

gdt:
    dw .size - 1 + 8  ; GDT size
    dd .start - 8     ; GDT start address

  .start:
    ; 32-bit code
    dw 0xffff       ; Limit
    dw 0x0000       ; Base (low 16 bits)
    db 0x00         ; Base (mid 8 bits)
    db 10011011b    ; Access
    db 11001111b    ; Granularity
    db 0x00         ; Base (high 8 bits)

    ; 32-bit data
    dw 0xffff       ; Limit
    dw 0x0000       ; Base (low 16 bits)
    db 0x00         ; Base (mid 8 bits)
    db 10010011b    ; Access
    db 11001111b    ; Granularity
    db 0x00         ; Base (high 8 bits)

  .end:

  .size: equ .end - .start
#

i got it from the limine source code

#

some flags are different than yours

#

maybe it is the issue

#

also you don't need an idt for now

echo granite
#

thats very strange

#

i am in 0x03 text mode and i see the cursor blinking, but no chars

cinder bronze
#

forget about BIOS text mode

echo granite
#

okay

cinder bronze
#

if you try to use BIOS interrupts in protected mode it will crash

echo granite
#

i know, i set video mode before jumping to the new kernel

cinder bronze
#

run qemu, then go to "compartmonitor0" and type info registers

cinder bronze
#

you are in vga anyways

echo granite
cinder bronze
#

CS is null

#

you are in protected mode

echo granite
cinder bronze
#

in your halt label

#

hm...

#

can you send your current code

echo granite
#
bits 16

start:
    cli
    xor ax, ax
    mov es, ax
    mov ds, ax

    lgdt [gdt_descriptor]   ;load GDT
    mov eax, cr0
    or eax, 1        ;set PE
    mov cr0, eax
    jmp code_off:main

gdt_start:
    dq 0

    ;code segment
    dw 0xffff
    dw 0x0000
    db 0x00
    db 0b10011010   ;access byte
    db 0b11001111   ;flags
    db 0x00

    dw 0xffff
    dw 0x0000
    db 0x00
    db 0b10010010
    db 0b11001111
    db 0x00
.end:

gdt_descriptor: dw gdt_start.end - gdt_start - 1
                dd gdt_start

idt_start:
    times 256 dq 0
.end:
idt_descriptor:
    dw idt_start.end - idt_start - 1
    dd idt_start

bits 32
main:
    mov ax, data_off
    mov es, ax
    mov ds, ax
    mov ss, ax
    mov esp, 0x90000
    mov fs, ax
    mov gs, ax

    call set_idt

    mov edi, 0xb8000
    mov byte [edi], 'A'
    mov byte [edi+1], 0x0f

    mov esi, msg
    call print_string
halt:
    hlt
    jmp halt

set_idt:
    mov ecx, 256
    mov edi, idt_start
    xor eax, eax
    rep stosd
    rep stosd

    mov ecx, 256
    xor ebx, ebx

.setidt_loop:
    mov eax, isr_default
    push ecx
    call set_idt_entry
    pop ecx
    inc ebx
    loop .setidt_loop

    lidt [idt_descriptor]
    ret
isr_default:
    cli
    iret

print_string:
    pusha
    mov edi, 0xb8000
.next:
    lodsb
    cmp al, 0
    je .done

    mov ah, 0x07
    stosw
    jmp .next
.done:
    popa
    ret

#

here it is

#

CS should be 0x08, right?

cinder bronze
#

yes

#

try without the IDT and print_string

#

also set up a stack in real mode

echo granite
#

it worked!!

#
    times 256 dq 0
.end:
idt_descriptor:
    dw idt_start.end - idt_start - 1
    dd idt_start``` these lines were the problem
#

if i remove it i get an 'A' printed!

#

maybe there was something wrong with the offset

cinder bronze
#

you don't need an IDT in your bootloader

echo granite
#

this isnt the bootloader

#

its the kernel, loaded by the program loader

cinder bronze
#

ohhh i see

#

you arent rewriting the os from scratch

#

okkk

echo granite
#

thank you so much, you helped a lot

#

i dont know if i would have fixed this alone

echo granite
#

check_exception old: 0xffffffff new 0x6 what does that mean?

cinder bronze
#

so you're probably executing incomplete instructions or even data

echo granite
#

thats shown if i put the IDT back

#

in qemu: -d int

cinder bronze
#

it would be like

echo granite
#

i dont know C

cinder bronze
#

so easier

cinder bronze
#

you learnt x86 asm, why couldnt you learn C

echo granite
#

isnt assembly much easier than C? because its just simple instructions

cinder bronze
#

it is simpler, not easier

#

you can write complex code faster in C

echo granite
#

okay

cinder bronze
#

and you can still write inline assembly

#

but with the at&t syntax 🤮

echo granite
#

but i dont understand what pointers are

cinder bronze
#

this allows you to use memory directly

echo granite
#

so in ASM this would be this?: mov ax, [ptr] this doesnt move the adress into AX but the value

#

ah, you mean: mov [0x0000], ax

cinder bronze
#

an example in C would look like this:

int x = 5; // variable x with a value of 5
int *p = &x; // pointer p which stores the address of x
#

ig it's like

mov dword [x], 5
mov edi, x
#

where edi points to x

echo granite
#

okay, i think i understand it a little bit

cinder bronze
#

nice

echo granite
#

how can i use higher resolutions in PM, like eg. 1024x720?

cinder bronze
#

idk i never did that

#

i think you can remap the vga memory

echo granite
#

hmm

#

okay

raven sierra
#

depends on the target though

echo granite
#

i have already print function, print_newline, scroll and colored print functions

#

i have a question, why is ring 1 and ring 2 not used? i asked chatgpt and he said, i should use ring 0 for the kernl and ring 3 for shell, programs, etc... but what is about ring 1 and 2?

little drift
#

This is your OS, you are its creator, you should know this, unless of course you did everything using AI

echo granite
#

youre right, but somtimes im just asking AI about facts

#

its the same like searching the internet i guess, unless you write your code yourself

little drift
little drift
cinder bronze
#

@echo granite are you using C now?

echo granite
echo granite
cinder bronze
echo granite
little drift
cinder bronze
echo granite
#

okay, i will try it

cinder bronze
cinder bronze
#

if you wish to use C

echo granite
#

okay

pliant yew
#

Technodon, check issues

#

on you repo

pliant yew
echo granite
#

what code did i steal?

#

haha, i know you're trolling

#

btw the output functions are the same in every 16bit OS. because there are no other ways to make them

#

and binaries are in the zprograms/ folder

echo granite
#

btw ProX, why isnt your post in the project-specific-no-ai channel?

cinder bronze
echo granite
#

yeah but he said in one of his youtube videos that he dont use any AI

cinder bronze
#

but maybe he is open to the use of AI

echo granite
#

hm, maybe

pliant yew
#

bro, ahahaha

little drift
little drift
cinder bronze
little drift
cinder bronze
little drift
timber wraith
echo granite
#

ohh, okay

echo granite
#

because of the linker i guess

cinder bronze
#

if you wanna link with C

timber wraith
cinder bronze
#

really?

raven sierra
timber wraith
#

Why wouldn't you be able do that?

cinder bronze
#

do relocatable ELFs support 16-bit code mixed with 32-bit code?

raven sierra
#

vbe took me a bit to get working but it's not too hard when you know where things go

timber wraith
cinder bronze
timber wraith
#

I mean

timber wraith
#

You made the claim

#

So I'm asking where that came from

raven sierra
#

you should also make sure a mode is actually available before you try to switch to it

cinder bronze
#

it seemed normal to me

timber wraith
cinder bronze
#

mb

timber wraith
raven sierra
cinder bronze
timber wraith
#

And anyway, you can also use other formats with C

echo granite
#
mov bx, 0x4118
int 0x10``` i do this, before executing the new kernel
#

but i dont know where the video memory is

raven sierra
#

video memory can be fetched by calling mode information and reading certain bits

#

hold on

#

offset 0x40 of the mode information block is a pointer to video buffer

echo granite
#

okay

echo granite
#

hm, i get 0x0d exception (general protection fault) when i do STI. but why is this if i am in ring 0?

#

this is not the error, because im doing: jmp far code_off:main

#

interesting

echo granite
#

@little drift

little drift
echo granite
#

no problem

cinder bronze
echo granite
cinder bronze
echo granite
#

i got vesa mode working but its actually very hard to write a print function for it

#

@raven sierra how do you print chars in VESA?

raven sierra
#

which vesa

#

I never used a terminal vbe mode so I'm not sure what interrupt

#

you might be better off writing your own character printing routine

#

with that comes the difficulty of a font however

kindred magnet
raven sierra
#

yes the rendering routine is the easy part

#

the hard part is the font part

#

unless you do it the boring way and use someone elses'ss's''s

echo granite
#

yes, i will just use someone elses's font

echo granite
#

1024x768

#

thats much better than VGAs 640x480

raven sierra
#

vgas 640x480 is 1-bit anyway

#

im still sticking with that resolution but vbe lets me get it in 16 bit color

#

wow 0x118 has a lot of color are you sure you need that much

echo granite
#

not really, but i want to use it because of the resolution. but i dont know how to render a font

echo granite
#
    pusha
    movzx esi, al
    sub esi, 32
    imul esi, 16
    add esi, font8x8

    mov edi, [cur]
    mov ecx, [rows]     ;8
.row:
    mov dl, [esi]
    inc esi
    push edi
    mov ebp, 8      ;8 pixel
.col:
    test dl, 0x80
    jz .skip

    cmp byte [bpp], 4
    je .write32

    mov byte [edi], 0xff
    mov byte [edi+1], 0xff
    mov byte [edi+2], 0xff
    add edi, [bpp]
    jmp .skip
.write32:
    mov dword [edi], 0xffffffff
.skip:
    shl dl, 1
    dec ebp
    jnz .col
    pop edi

    add edi, [pitch]
    loop .row
    popa
    ret
``` hmm, i have this problem that only the first pixel row is drawn
#

i have a 8x8 font

#

and [cur] is the adress in the frame buffer where to write

echo granite
#

this happens if i try to draw a '['

echo granite
#

and this is if i try to print a message

#

i dont know why but everything is printed twice

#

and the '!' is printed correct

raven phoenix
echo granite
#

but im in 32bit mode

raven phoenix
#

or are you entirely only using 16 bit opcodes

#

if you have a 64 bit CPU you can use 64 bit regs in 32 bit mode

#

if

echo granite
#

hm. no, my OS is designed for the i386

raven phoenix
#

you should still use rep movsd

#

32 bit writes

#

instead of inc

echo granite
#

okay, i will do that

#

it took me 2 days but FINALLY i can write in vesa mode 0x118

#

uhm yeah, the font is pretty ugly...

echo granite
#

and IDT too

raven sierra
#

interesting text drawing

#

whered you get the font

echo granite
#

from github

#

i coulndt find a better one

#

i think i have to do it myself

raven phoenix
#

they're plain binary where each bit set is an on pixel

#

same as flanterm uses

#

this one is similar, called YES-T

echo granite
#

thank you very much

#

but how do i use them? they are not .inc files

arctic token
echo granite
#

yes true, you can use incbin "filename"

#

but i use the default VGA font now

raven phoenix
#

according to flanterm if the right hand column has a 1-bit it's duplicated to the 9th spacing column, so that characters like box drawing and _ don't have gaps

#

take a look at XMO in XMODE

echo granite
#

oh, yes you true

echo granite
#

whoho, now the shell is in usermode

#

btw the D is a GP error

echo granite
#

lets goo, now there is a real shell with input and commands

#

unfortunately there are some graphical bugs

#

and i added CLEAR command

echo granite
#

okay, now i will try to implement disk I/O, Int 0x13 style. Should i support CHS reading or only use LBA?

echo granite
#

i implemented a syscall for reading an ATA disk

#

now i will try to implement writing onto the disk

echo granite
#

writing to the disk is implemented, too

echo granite
#

and extended read and write also

#

tomorrow i will start implement FAT16

echo granite
#

lets goo, LS command works

echo granite
#

better LS command and READ command

cinder bronze
#

cool

echo granite
#

thanks

raven sierra
#

beautiful

echo granite
echo granite
#

btw, my OS is ~30KB big

#

is this much?

arctic token
raven sierra
#

such numbers are unheard of

#

blame the font

#

but honestly as long as it can fit on a 1.44mb floppy its okay

cinder bronze
arctic token
timber wraith
#

DOS 2.0 was 20k

echo granite
#

oh

echo granite
echo granite
raven sierra
#

wait this is all asm right how much data do you have in there

echo granite
#

~7KB of text files

echo granite
raven sierra
#

this is amazing

echo granite
#

umm

raven sierra
#

oh gosh

#

it will be fixed in 27H1

cinder bronze
#

hmmm...

echo granite
#

i tried...

cinder bronze
#

you can't compile it?

echo granite
#

yes

#

i get an error

cinder bronze
echo granite
echo granite
spare nova
echo granite
#

aah

#

btw programs work now in the OS

#

but the ouput API doesnt

cinder bronze
#

and your linker script if you have one

#

btw why arent the build scripts in the repository

echo granite
cinder bronze
#

how do you want people to build your OS

#

or help you to fix your build scripts

#

if you don't push them

echo granite
#

aah

#

wait

#

thats a serious problem

#
ENTRY(_start)

SECTIONS
{
    . = 0x20000;

    .text :
    {
        *(.text*)
    }

    .rodata :
    {
        *(.rodata*)
    }

    .data :
    {
        *(.data*)
    }

    .bss :
    {
        *(.bss*)
        *(COMMON)
    }
}``` this is my linker script
#

and flags for the compiler were -m32, -ffreestanding and -c

kindred magnet
#

you probably need to add the GOT to the linker script after .data

    .got : {
        *(.got)
        *(.got.plt)
        *(.igot.plt)
    }

that or you probally need more compiler flags for things

#

also should like push things to git

kindred magnet
echo granite
echo granite
#

write function works

echo granite
#

i really dont know why there are this lines

echo granite
kindred magnet
#

Hey Ty

silver bridge
echo granite
#

i have a folder now which contains the file autostrt.sys. if this file contains the number 1, my 32bit OS will be started automatic. for that i implemented a function which can load a directory, search a file in it and load it to a specific adress in memory

echo granite
#

xasm.bin is btw the Xiromos Assembler, which i now will code

echo granite
#

@cinder bronze finally C code

magic gust
#

isnt it supposed to be fully assembly tho

#

is this a new project?

cinder bronze
echo granite
#

the OS itself is fully written in assembly

magic gust
#

ah

echo granite
#

how do i emulate a drive in QEMU with DMA controller?

echo granite
#

i am trying to find a mass storage device with IDE controller because i try to implement DMA driver

silver bridge
#

emulate it in qemu

echo granite
#

i try this command but it doesnt seem to work

silver bridge
#

why a .img...

#

that is prob gonna be readonly

#

you need a virtual disk

echo granite
#

whats that?

#

i only used .img...

silver bridge
#

google it, it will explain it better

echo granite
#

isnt that basically the same like a .img file?

#

both emulate a hard disk

silver bridge
#

no

#

i believe img is somewhat read only?

echo granite
echo granite
echo granite
#

lets goo, i found the device finally

#

now i can write DMA driver

#

then my OS will be much faster because of faster disk read

magic gust
echo granite
#

@cinder bronze I'm afraid I have to disappoint you

#

but i think i will code the assembler in assembly

#

because C is too compilacted

timber wraith
cinder bronze
echo granite
#

i dont know, i would have to learn the whole language. i had problems with just calling a syscall. also there is this compiler which always tries to optimize your code. i like assembly more, its just so much easier

silver bridge
silver bridge
#

(you can disable it for debug)

cinder bronze
#

almost every C compiler allows you to write inline assembly

#

it is like asm you embed in your C code

#

you can also call your asm functions from C

#

like this

; functions.asm

use_syscallX:
    ; do something
    ret
// kernel.c
extern void use_syscallX(void);
#

and then you can call it as a normal C function

echo granite
#

okay, thank you

echo granite
#

whohoo, mov instruction work

echo granite
#

CLC /CLD / CLI work also

#

and STC / STD / STI

#

but that was the easy part

#

and you can do comments

magic gust
echo granite
#

yes but i have to call syscalls in this language

#

and that is harder than in assembly

kindred magnet
#

You can also very well link assembly code with C

#

And have an assembly function to invoke a syscall

#

And that function can be invoked from C

echo granite
kindred magnet
#

Well then make a function in assembly and call it from C

#

And assembly can even call functions made in C

echo granite
#

okay i will try that

magic gust
#

wat

#

like

#

inline assembly?

magic gust
#

try rust

#

although you will have to fight the borrow checker and other bs

echo granite
#

i never coded in rust

kindred magnet
echo granite
#

LETS GOOO

#

my assembler can now assemble in 16bit or 32bit mode

#

and the TEST.BIN program actually worked because i added RETF instruction

#

you can set the bits via $b

#

for example $b32 says the assembler it must compile for 32bit mode

raven sierra
#

hooray

cinder bronze
echo granite
#

i changed it and i added SI, DI, SP, BP registers and the INT instruction

echo granite
#

i made a real installer for my OS

echo granite
#

and i have a test branch for both projects now on github

cinder bronze
echo granite
#

thanks

echo granite
#

i improved it

#

now it copys actually every single item instead of copying cluster for cluster

#

this allows you to copy the OS to disks with a completly different geometry and different sec_per_cluster

magic gust
#

did you test it in real hardware?

echo granite
#

yes i tested it but it just freezed. this always happens when i try do disk I/O. i think the error is something with the drive number because the usb stick is marked as drive 0x00, but my disk I/O is extended LBA

#

which is for hard disks

#

but if i can fix that it should work perfectly on real hardware, too

echo granite
#

fixed the LSDISK program

#

now it actually shows available drives and its size

#

btw B:/ is only 128KB because it is formatted with my own FAT8 and 128KB is the limit

#

My installer supports up to 512MB big disks, but unfortunately right now it doesnt work properly with large directories like A/B/C/D/E

echo granite
#

it works fine with copying only root and root/subdir

raven phoenix
# echo granite

what is D detected as? it doesn't seem to show in floppies or disks

echo granite
#

D is a hard disk

#

floppies are A and B

#

there can be only 2 floppies active at a time

echo granite
#

LETS GOO

#

i can now create windows in different sizes and i can write in them

#

here is a bigger window for example

#

you can create it in the size you want and you can specify the background color and the text color

echo granite
#

i added a title

cinder bronze
#

great job

echo granite
echo granite
#

making a shell in an extra window

echo granite
#

this is the start of multitasking

#

i pushed everything to the dev branch on github

cinder bronze
#

cool

echo granite
#

now the syscall for drawing a window saves the content, which is overwritten by a window, in a buffer and restores it, when the window is deleted

cinder bronze
#

wait

#

you have a syscall for drawing a window??

silver bridge
#

💀

echo granite
#

and a syscall for deleting it

echo granite
#

hmm

#

i see the problem...

cinder bronze
#

you shouldn't use syscalls for that

echo granite
#

my idea was, that at a start the program could either run in the shell or draw a window and run in it

cinder bronze
#

i've never designed a gui in an OS before but i think that everything related to windows should run in userspace

#

your window manager should be a program for example

#

and ig the framebuffer should be accessed via a file (like /dev/fbX)?

#

please someone say if I'm wrong

#

btw do you have userspace @echo granite

kindred magnet
echo granite
cinder bronze
#

@echo granite so basically you should use syscall write on /dev/fbX

#

i guess

timber wraith
#

e.g. Windows NT 4.0 and later has it in the kernel as win32k.sys

#

tho it started out in userspace and was moved to kernel space for performance reasons

cinder bronze
#

k i see

timber wraith
#

tho they probably regretted that decision

echo granite
#

what is fbX?

#

i think i will keep the syscall for drawing a window but i will limit it to 2 windows per process

#

when i have multitasking

little drift
echo granite
#

aah, okay

#

but the frame buffer is just an adress in memory, how can it be a file?

timber wraith
#

e.g. /dev/fb0

#

/dev/fb1

#

etc ...

timber wraith
#

Or more likely, mmap it into its own address space.

echo granite
#

okay, but how does the program then draw a window?

#

this should do the kernel for the program right?

#

because the program could destroy the framebuffer

timber wraith
timber wraith
echo granite
#

but if you create in windows a window you dont draw every pixel

#

you can create it via a function i guess, but im not sure

#

for example if you use tkinter in python you call a function and give it x, y, width and height to draw a window

timber wraith
echo granite
#

yes, thats a good idea, but what is the difference between the kernel drawing the window or the userpace program drawing the window?

timber wraith
#

This in turn probably calls the kernel-side backend implemented in win32k.sys.

timber wraith
echo granite
#

implementing multitasking isnt that hard i guess

timber wraith
#

But for a simple framebuffer, the kernel typically exposes it as something similar to Linux' fbdev, and userspace takes it from there.

#

For input on Linux, look up evdev.

echo granite
#
    cli
    pushad
    push ds
    push es
    push fs
    push gs

    cmp word [task_count], 2
    jb .done

    movzx eax, word [current_task]
    imul eax, 4
    mov edi, tasks_esp
    add edi, eax
    mov [edi], esp

    mov ax, [current_task]
    inc ax
    cmp ax, [task_count]
    jbe .load_next
    
    mov ax, 1
    
.load_next:
    mov [current_task], ax
    
    ;load next task context
    movzx eax, word [current_task]
    imul eax, 4
    mov edi, tasks_esp
    add edi, eax

    mov esp, [edi]

.done:
    mov al, 0x20
    out 0x20, al

    pop gs
    pop fs
    pop es
    pop ds
    popad
    iret```
#
    mov ax, [max_tasks]
    cmp word [task_count], ax
    jae .too_much_tasks

    ;save shell context
    mov eax, 1
    imul eax, 4
    mov edi, tasks_esp
    add edi, eax
    mov [edi], esp
    
    inc word [task_count]
    
    mov esi, read_buffer2
    mov esp, program_stack

    push ss
    push esp
    pushf
    push code_off_user
    push program_addr
    pushad
    push ds
    push es
    push fs
    push gs

    movzx eax, word [task_count]
    imul eax, 4
    mov edi, tasks_esp
    add edi, eax
    mov [edi], esp

    jmp program_addr
    mov ecx, 100
.loop:
    mov al, '#'
    call print_char
    dec ecx
    jnz .loop
    ret```
#
max_tasks: dw 2
current_task: dw 0

tasks_esp:
    dd 0        ;task 0 (reserved)
    dd 0        ;task 1 (shell)
    dd 0        ;task 2 (program)
    dd 0        ;task 3 (program future)```
#

when the shell is started by switching to ring 3 the task_count is incremented by 1

#

and if i start another program the taskcount should be incremented again, so the scheduler can switch between the tasks

#

in theorie the whole multi-tasking process should work like this: i start a program, it pushes the context and increments task_count, then the program is executed because IRQ0 switches between the two different tasks, so the program works while '#' is printed

#

but unfortunately the program just starts and nothing happens then, the '#' isnt printed.

#

and i dont understand why this is so

#

i dont use TSS because shell and program are both in ring 3 so there is no ring switch

cinder bronze
#

dont you need a TSS for multitasking?

silver bridge
#

or well, it's not required

#

(you can do it without, but it's a PITA)

kindred magnet
silver bridge
#

but you have to handle it very carefully

kindred magnet
#

The CPU pushes shit to the stack

#

You don’t want that on a userspace controlled stack

echo granite
#

i have a tss but i dont think you need it when switching between two ring 3 programs

#

or do i need it?

kindred magnet
#

This is also why you want SMEP/SMAP to prevent this

kindred magnet
#

And you need a kernel controlled stack for that

silver bridge
#

bc the switcher is an interrupt

#

or well, you still have to go back to kernel

echo granite
#

okay you right, but i have a TSS

#

for interrupts

kindred magnet
#

You can use the TSS for task switching but that’s stupid imo

#

And iirc it’s slower than normal software switching

kindred magnet
#

Task switching does not have to be from an interrupt

#

You should be able to task switch at any moment in the kernel with a few exceptions

silver bridge
kindred magnet
#

I’m still going to be very explicit here because this is a common topic for people to be confused by and you aren’t helping with some of the stuff you are saying lol

echo granite
#

LETS GOOOOOO

#

MULTI TASKING

#

i dont know why the window is so buggy

#

anyways

#

i can type in the window while in the background there are printed the '#'!!!!!!!

#

this means the CPU switches between the program and the shell

#

whohoooooooo

#

but there is still a problem

#

when i type somthing the CPU generates a ton of exceptions so it triplefaults

#

you can even see the GP in the corner

echo granite
#

x16-PRos is a little bit compatible with my OS. i do the command qemu-system-x86_64 -fda x16pros.img -hda disk.img

#

you can read, write, delete files from x16-Pros in my OS and switch directories.

#

@ProX

cinder bronze
#

because both OSes use the same filesystem ig

timber wraith
echo granite
cinder bronze
#

the OSes are not compatible

#

but they can parse the same filesystems

echo granite
#

no, i can change some adresses in my OS and then even the programs of x16-PRos will run

#

because we both use the same format

#

flat binary

#

@timber wraith why is ProX banned from the server?

silver bridge
cinder bronze
kindred magnet
#

iirc Mach-O does this?

echo granite
#

they can run on my OS if i change some adresses

cinder bronze
#

and filesystems

timber wraith
#

I mean

#

there's more to it than just the format

#

like the API

echo granite
#

guys, if a program is in ring 3 and an interrupt appears, does it push only EIP, flags and CS onto the stack or does it push also ESP and SS?

#

because for my multi tasking i use the timer interrupt

silver bridge
#

it's a normal interrupt

timber wraith
echo granite
timber wraith
echo granite
#

oohh, now i see the problem in my task switching

echo granite
#

FINALLY I GOT MULTITASKING WORKING

#

you see that i type in the shell in the background and in the window

#

this is because the CPU switches between shell and program

#

multitasking!!!!!

#

it took me 4 days....

timber wraith
#

nice!

echo granite
#

thanks!

cinder bronze
#

great

echo granite
#

thank you!

echo granite
#

@cinder bronze what is your current project?

cinder bronze
echo granite
#

isnt your project benix?

cinder bronze
#

it wasnt fun anymore

#

and i wanted to experiment with c++

echo granite
#

you cant see it but there are 3 windows stacked. i improved the scheduler so now 4 tasks (3 programs + shell) can run at the same time

#

also, when i finish the multi tasking i want to make a window tiling manager for my OS like i3 wm

echo granite
#

if the E in EAX stands for extended, what does the R in RAX mean?

spare nova
#

register :^)

wicked ridge
#

considering theres a REX prefix trl

echo granite
wicked ridge
#

Its an Intel word

echo granite
#

i see

echo granite
wicked ridge
#

I made it up btw

echo granite
#

i improved the keyboard handler. now it checks current task with foreground_task, and if equal it returns the key

#

now only the foreground task has the keyboard, which is much better

#

you can see, that i can type text in the window but not in the shell

echo granite
raven sierra
#

woah that's a window up there

echo granite
#

Yes

#

i worked a lot last month

#

i think i make a break soon

#

but first i want to do window managment

#

window tiling manager

echo granite
#

look at my progress, in 3 months i upgraded my first OS a lot + made a second multitasking + window managment kernel

cinder bronze
#

do you have memory management

#

?

silver bridge
#

if it even has GUI / multitasking

echo granite
#

currently i have no paging

#

but i want to use it

silver bridge
echo granite
#

look, no you can switch between tasks. you can see that there are 3 window tasks running and im typing in the shell because i switched to the shell and started new programs

#

Now it is real multitasking

echo granite
#

i think i will make a seperate UEFI bootloader for my 32bit OS, so it can run on newer machines, too

#

because now it is started only trough the BIOS, which is nice and easy, but CSM support disapears and i want my OS compatible with newer computers

#

then the user can chose if he uses Xiromos (legacy BIOS) as bootloader or my new bootloader for UEFI

#

so my OS is compatible with the i386 and new computers

#

i hope

silver bridge
#

just go 64 bit

cinder bronze
cinder bronze
echo granite
cinder bronze
#

you can also go 64-bit

#

which is better

echo granite
#

noo

#

my OS is designed to be compatible with the i386

#

while it should also be able to run on newer machines

#

can you load a .efi file from a FAT16 partition?

#

Gemini said its possible but i dont trust it

cinder bronze
#

for both x86 and x86_64

echo granite
cinder bronze
#

multi-architecture

#

like it supports several architectures

echo granite
#

how is that possible?

cinder bronze
#

it is easy

#

because both architectures have similar mecanics

#

(it would be a lot easier in C tbh)

#

if you keep using asm you would need to write 2 kernels instead of one

echo granite
#

why does it work with C?

#

does the C compiler compiles the code for 2 different architectures?

cinder bronze
#

because C allows you to abstract things

cinder bronze
echo granite
#

ohh, i see

#

hm, yeah thats not possible in assembly

cinder bronze
#

please just use C 😭

echo granite
#

nooo

cinder bronze
#

why

echo granite
#

its so complicated

cinder bronze
#

no 😭

#

it is not

#

it is wayyyy easier to write complicated stuff in c than in asm

#

you just dont wanna learn the language

echo granite
cinder bronze
#

why

echo granite
#

i got used to assembly and its easy to work with

cinder bronze
#

no

#

it isnt

#

try to write high level stuff with it

#

you would struggle for a while

echo granite
#

okay, i will resume coding my OS in Assembly but i will learn C on the side so later i can implement stuff in it, too

#

deal?

cinder bronze
#

deal

echo granite
#

my UEFI bootloader is almost done, then the system supports BIOS and UEFI and is able to run on newer machines without BIOS

echo granite
#

what do you think guys, should i make a documentation about my OSes?

#

because i dont know, on the one hand only i am working on it and no one would need it, but on the other hand, maybe its interesting to read and someone could learn something

echo granite
#

GUYS I MADE IT

#

my OS supports UEFI and BIOS booting

#
  • look how much cleaner my screen looks when i use UEFI
#

there are no yellow pixels anymore, this is a BIOS bug i think, idk

#

but now it looks so much cleaner

#

this is how it looks with BIOS

#

there are these stupid yellow things

echo granite
#

maybe i will try implement multicore soon

silver bridge
#

(and maybe a lot of race conditions that will randomly pop up)

echo granite
silver bridge
echo granite
#

okay

#

btw i implemented busmastering DMA disk I/O, so now my OS supports ATA PIO mode and IDE DMA read

#

now i want to take a look at AHCI

silver bridge
#

i'm starting with NVMe

echo granite
#

what, really?

#

thats cool

#

so you know how AHCI works?

silver bridge
#

huuh, not tried yet

#

NVMe works in a completely diff way

#

and i think it's simpler too

echo granite
#

yes its different but i dont think its simpler

silver bridge
#

NVMe is just about sending commands

#

in a ring buffer

echo granite
#

arent there queues and stuff like this?

silver bridge
#

queues are ring buffers

echo granite
#

what are ring buffers?

silver bridge
#

buffers that when you reach the end, they wrap around to the start

echo granite
#

how does that work?

silver bridge
#

just reset the index to 0

#

lol

echo granite
#

i didnt get it

silver bridge
#

like, if an array is 5 long

#

when you reach index 4

#

the next iteration you set index back to 0

echo granite
#

ohh, now i understand

#

does the i386 support PCIe?

silver bridge
#

huuh

#

not PCIe i think

#

no machine came with that

#

but maybe PCI?

echo granite
#

it supports PCI, but im not sure about PCIe

silver bridge
#

tho in emulation you can do anything

echo granite
#

thats true

silver bridge
#

in real hardware you will 99% not find pcie in a i386 pc

#

and for sure not NVMe

echo granite
#

yeah, okay

echo granite
#

Guys, i have a problem

#

if i emulate an AHCI device in QEMU, then disk I/O on my 16Bit OS part doesnt work properly

#

when i try read i file, the BIOS just hangs

#

if i emulate an IDE device, everything works

#

the most interesting part is that the kernel is loaded, but the kernel itself cant do anything then

#

this is exactly the same problem i have on real hardware

#

but how do i fix this? its a BIOS issue i guess

pulsar delta
#

could be

#

probably is

#

need more context

echo granite
#

what context?

pulsar delta
#

the code would suffice

echo granite
#

just a normal INT 0x13h read (extended):

    mov ah, 0x42
    mov dl, [drive_number]
    int 0x13```
pulsar delta
#

show dap

echo granite
#

here it is:

    mov [file_dap+6], word 0x8000

.load:
    mov ax, [program_cluster]
    call cluster_to_sec
    mov [file_dap+8], ax

    xor cx, cx
    mov cl, [sec_per_cluster]
    mov [file_dap+2], cx

file_dap:
    db 0x10                        ;size of packet (16 bytes)      [program_dap+0]
    db 0                           ;always 0                       [program_dap+1]
    dw 0                           ;number of sectors to read      [program_dap+2]
    dw 0x0000                      ;offset                         [program_dap+4]
    dw 0x0000                      ;segment                        [program_dap+6]
    dq 0                           ;LBA                            [program_dap+8]```
#

there is also the code how i fill it

#

program cluster is a valid number, something like ~40

pulsar delta
#

I meant can I see the values you pass that fail

echo granite
#
mov [file_dap+2], word 1
mov [file_dap+4], word 0
mov [file_dap+6], word 0x2000
mov [file_dap+8], word 4

mov si, file_dap
mov ah, 0x42
mov dl, [drive_number]
int 0x13```
#

all reads fail, no matter what values i use

#

drive_number is 0x80

pulsar delta
#

assuming si is zero it looks valid yeah

#

sounds like a bios issue but cant really comment further without testing myself

echo granite
#

yes, it only appears when emulating an AHCI device, classic IDE works fine. Also, when i test it on real hardware i use an USB stick which is a xHCI device, which has the same problem - the BIOS reads freeze the system

echo granite
#

bruh, i edited a text file in a hexeditor and added at offset 510 the bytes 0x55 and 0xAA and now im booting from a text file

magic gust
echo granite
#

i have multidisk support now

#

AHCI driver isnt working right now but im working on it

#

but my OS already supports PIO Mode and Busmastering DMA

echo granite
#

how hard is it to make a GPU driver for the NVIDIA Riva or TNT?

silver bridge
#

you have better chances to just port an existing one

echo granite
#

interesting

#

no, i want to try to do my own

silver bridge
#

anything gpu driver related is hell on earth

silver bridge