flat assembler
Message board for the users of flat assembler.

Index > OS Construction > I am finishing the last portion of my OS

Author
Thread Post new topic Reply to topic
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
I want to post this OS code up here to show the forum what my work has created. Feel free to try this code at home and give suggestions if any issues come up. I personally have gotten this to work under bochs (DOSemu just quits spontaneusly when I set up the IVT for int 21h... sigh). If you cannot get it to work, let me know!

Source (made with emacs):
Code:
use16
mov ax, 9ch
mov ss, ax
mov sp, 4096d
mov ax, 7c0h
mov ds, ax
mov ah, 02h
mov dx, 0000h
int 10h
;----------------------------------------
loadup:

        mov ah, 00h
        mov dl, 00h
        int 13h
        mov ah, 01h
        mov dl, 00h
        int 13h
        cmp al, 00h
        jne stop
        ;; Load the int 21h code (For later implementation)
        mov ah, 02h
        mov al, 01h
        mov ch, 00h
        mov dh, 00h
        mov cl, 01h
        mov dl, 00h
        mov bx, 1400h
        mov es, bx
        mov bx, 0000h
        int 13h
        mov ah, 01h
        mov dl, 00h
        int 13h
        cmp al, 00h
        jne stop
        ;; Set up the IVT to recognize my int 21h
        mov ax, 0000h
        mov es, ax
        mov al, 21h
        mov bl, 04h
        mul bl
        add ax, 02h
        mov bx, ax
        mov dx, 1400h
        mov [es:bx], dx
        mov al, 21h
        mov bl, 04h
        mul bl
        mov bx, ax
        mov dx, 0000h
        mov [es:bx], dx
        ;; Clear the screen
        mov ah, 02h
        mov dh, 00h
        mov dl, 00h
        int 10h
        mov ah, 07h
        mov al, 00h
        mov ch, 00h
        mov cl, 00h
        mov dh, 80d
        mov dl, 25d
        int 10h
        mov cx, 01h
        ;; Display 'NOS 1.0' message
        mov ah, 09h
        mov al, 4Eh
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 4Fh
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov ah, 53h
        int 10h
        mov ah, 02h
        inc dl
        mov ah, 09h
        mov al, 20h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 31h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 2Eh
        int 10h
        mov ah, 02h
        inc dl
        mov ah, 09h
        mov al, 30h
        int 10h
        mov ah, 02h
        mov dl, 00h
        add dh, 01h
        int 10h
        ;; Begin setting up the environment in which the user will type
typer:
        mov ah, 00h
        int 16h
        cmp al, 0Dh
        je  print_enter
        cmp al, 08h
        je  print_back
        mov ah, 09h
        int 10h
        push ax
        cmp dl, 80d
        je  mcdn
        pop ax
        mov ah, 09h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        jmp typer
print_enter:
        cmp dh, 25d
        je  scr_dn
        mov ah, 02h
        add dh, 01h
        mov dl, 00h
        int 10h
        jmp typer
print_back:
        mov ah, 02h
        dec dl
        int 10h
        mov ah, 09h
        mov al, 20h
        int 10h
        jmp typer
scr_dn:
        mov ah, 07h
        mov al, 01h
        int 10h
        ret
mcdn:
        cmp dh, 25d
        je  scr_dn
        mov ah, 02h
        add dh, 01h
        mov dl, 00h
        int 10h
        ret

stop:
hlt
;----------------------------------------
times 510-($-$$) db 0
dw 0xAA55
    


Also have attatched the .asm file.


Description: The source for my operating system - called NOS
Download
Filename: myos.asm
Filesize: 2.01 KB
Downloaded: 298 Time(s)


_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 14 Jun 2015, 21:59
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek
You should always disable interrupts before reprogramming the IVT. That might be what's upsetting DOSemu.
Post 15 Jun 2015, 01:06
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
I will try that. DOSemu also seems to think video mode 03h is bad as well, when I try this:

Code:
mov ah, 00h
mov al, 03h
int 10h
    


DOSemu stops because of a segmentation fault. I think it is a problem with DOSemu, I built it from the source instead of the RPM.
Post 15 Jun 2015, 01:16
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek
I've been trying to get this thing to work in DOSbox, and you've got a lot more problems than you think you have.

Stop using DOSemu, first of all. Segmentation faults should never happen in real mode, unless you mean that DOSemu itself is segfaulting. In either case, it's a pile of smelly garbage. Second, look over your code very carefully. For example, you are supposed to check AH for the returned floppy drive status code, not AL, for your AH=0x01; INT 0x13 calls.
Post 15 Jun 2015, 01:50
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
I always learned that AL is where INT 13h - 01h stores its result, I will check that out.

Also, am now switching over to bochs, DOSemu's segfault is actually a bug with the HLT instruction.

Also, am adding appropriate CLI/STI instructons as suggested before and after modifying the IVT.

Thanks for the feedback!
Post 15 Jun 2015, 14:33
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
Code is now modified as follows:

Code:
use16
org 7C00h
mov ax, 9ch
mov ss, ax
mov sp, 4096d
mov ax, 7c0h
mov ds, ax
mov ah, 02h
mov dx, 0000h
int 10h
;----------------------------------------
loadup:

        mov ah, 00h
        mov dl, 00h
        int 13h
        mov ah, 01h
        mov dl, 00h
        int 13h
        cmp al, 00h
        jne stop
        ;; Load the int 21h code (For later implementation)
        mov ah, 02h
        mov al, 01h
        mov ch, 00h
        mov dh, 00h
        mov cl, 01h
        mov dl, 00h
        mov bx, 1400h
        mov es, bx
        mov bx, 0000h
        int 13h
        mov ah, 01h
        mov dl, 00h
        int 13h
        cmp al, 00h
        jne stop
        ;; Set up the IVT to recognize my int 21h
        cli
        mov ax, 0000h
        mov es, ax
        mov al, 21h
        mov bl, 04h
        mul bl
        add ax, 02h
        mov bx, ax
        mov dx, 1400h
        mov [es:bx], dx
        mov al, 21h
        mov bl, 04h
        mul bl
        mov bx, ax
        mov dx, 0000h
        mov [es:bx], dx
        sti
        ;; Clear the screen
        mov ah, 02h
        mov dh, 00h
        mov dl, 00h
        int 10h
        mov ah, 07h
        mov al, 00h
        mov ch, 00h
        mov cl, 00h
        mov dh, 80d
        mov dl, 25d
        int 10h
        mov cx, 01h
        ;; Display 'NOS 1.0' message
        mov ah, 09h
        mov al, 4Eh
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 4Fh
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov ah, 53h
        int 10h
        mov ah, 02h
        inc dl
        mov ah, 09h
        mov al, 20h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 31h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        mov ah, 09h
        mov al, 2Eh
        int 10h
        mov ah, 02h
        inc dl
        mov ah, 09h
        mov al, 30h
        int 10h
        mov ah, 02h
        mov dl, 00h
        add dh, 01h
        int 10h
        ;; Begin setting up the environment in which the user will type
typer:
        mov ah, 00h
        int 16h
        cmp al, 0Dh
        je  print_enter
        cmp al, 08h
        je  print_back
        mov ah, 09h
        int 10h
        push ax
        cmp dl, 80d
        je  mcdn
        pop ax
        mov ah, 09h
        int 10h
        mov ah, 02h
        inc dl
        int 10h
        jmp typer
print_enter:
        cmp dh, 25d
        je  scr_dn
        mov ah, 02h
        add dh, 01h
        mov dl, 00h
        int 10h
        jmp typer
print_back:
        mov ah, 02h
        dec dl
        int 10h
        mov ah, 09h
        mov al, 20h
        int 10h
        jmp typer
scr_dn:
        mov ah, 07h
        mov al, 01h
        int 10h
        ret
mcdn:
        cmp dh, 25d
        je  scr_dn
        mov ah, 02h
        add dh, 01h
        mov dl, 00h
        int 10h
        ret

stop:
hlt
;----------------------------------------
times 510-($-$$) db 0
dw 0xAA55
    


And when I do so, bochs is complaining that there is an HLT instruction when IF=0. I see no issues here unless there is an issue loading the 512 bytes of INT 21h code (which does not yet exist and is actually filled with 00h on the disk)?
Post 15 Jun 2015, 14:39
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
The new INT 21h has one function for now - to print a string. The code loaded for INT 21h is as follows:

Code:
        use16
        ;; This is the int 21h code used in NOS.
        ;; Begin by checking the function and its parameters...
        cmp ah, 00h
        je  print_string
        ;; Set the invalid function register (BL) to FF and return
        mov bl, 0FFh
        ret
print_string:
        ;; grab the char from RAM and process it
        mov al, [es:bx]
        cmp al, 24h
        je  line_done           ; We want the terminating character to be $
        cmp al, 00h             ; If null then print a $
        je  print_ds
        ;; Go ahead and print the character since it is not a handled char
        mov ah, 09h
        int 10h
        ;; Move the cursor to the right
        cmp dl, 80d
        je  line_dn             ; If the end of a line is reached, we want to scroll down one line
        inc dl                  ; If not, then move the cursor to the right
        mov ah, 02h
        int 10h
        ;; Increment the RAM address pointer and continue
        inc bx
        jmp print_string
print_ds:
        ;; Since the special char to terminate the line is a $, we want to print an actual $
        ;; if the stored char is null (00h)
        mov ah, 09h
        mov al, 24h
        int 10h
        cmp dl, 80d
        je  line_dn
        mov ah, 02h
        inc dl
        jmp print_string
line_dn:
        ;; Scroll down a line and move the cursor to the beginning of said line
        mov ah, 07h
        mov al, 01h
        int 10h
        mov ah, 02h
        mov dl, 00h
        inc dh
        int 10h
        jmp print_string
line_done:
        ret
;--------------------------------
times 512-($-$$) db 0

    


Am putting up the IMG file for the disk if you want it, other wise the .asm file for INT 21h is attatched.


Description: This is the INT 21h asm file.
Download
Filename: int21.asm
Filesize: 1.24 KB
Downloaded: 311 Time(s)


_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 15 Jun 2015, 15:54
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
The board will not let me put up the image, and so you will have to do the following (I use Linux, and so this is what i do to compile):

$ fasm myos.asm myos.bin
$ fasm int21.asm int21.bin
$ cat myos.bin int21.bin > NOS.img
$rm *.bin
Then, to write to a floppy disk:
$ dd if=NOS.img of=/dev/fd0

_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 15 Jun 2015, 16:04
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek
I read through myos.asm very carefully this time, and I added a lot of comments. I haven't read through int21.asm yet.

https://gist.github.com/Trinitek/7d305d66b15ba90d427e
Post 16 Jun 2015, 02:58
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
Thank you. Help is appreciated!
Post 16 Jun 2015, 03:01
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
I am going to modify myos.asm to include my INT 21h functions soon. I had never seen the 0x0E INT 10h function before, always learned that 0x09 puts a character and you had to move the cursor with 0x02. I wish I had better people teach me this stuff...
Post 16 Jun 2015, 03:09
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek
Feast your eyes on all of the interrupts you would ever want and more: http://ctyme.com/rbrown.htm
Post 16 Jun 2015, 03:10
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
I have never seen Ralf Brown's list on the interweb, thanks! This will definitely come in handy.
Post 17 Jun 2015, 02:13
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
Have started a Git repository for this OS on SourceForge. Latest code will remain here, updated whenever possible. Help is still accepted. Thank you Trinitek for pointing out the bug in DosBox, I have made an image.asm file to circumvent this. Very Happy

Git Repo is at: https://sourceforge.net/p/nosanopensourcefasmos/code/ci/master/tree/

_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 08 Jul 2015, 00:33
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable
The problem with operating systems, especially OS's like Microsoft Windows is that it takes one man about five thousand years just to maintain it. What Microsoft's developers achieve in one year is what one man can achieve in five thousand years. If you begin working on an operating system with the extent and diversity similar to that of windows, you wouldn't even be finished with it if you began writing it in the time of the great pharaoh's of Egypt.

Windows, all together from it's start and until today have over 25 thousand years worth of work for a single man. What Microsoft is doing all together in just one year, is worth 60,000 years worth of work for one man. From January 2014 to January 2015, 60 thousand years worth of work was done by Microsoft.

Even a simple game for windows, the amount of developers on that game is somewhere between 150 and 250 people. So even just a windows game takes 250 years to complete by a single man, and that is only if you're using very efficient tools. If you're using assembly, you can probably triple the amount of time. It takes about a thousand years for an assembly programmer to develope a hyper modern 3d shooter game with full content.

If you're lucky, you'll finish a very simple program during the course of your life, but chances are you're dead before you finish that simple program.


Last edited by PeExecutable on 17 Jul 2015, 19:52; edited 5 times in total
Post 17 Jul 2015, 19:34
View user's profile Send private message Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72
This topic is now closed. Thanks for the help! If I have any other questions, I will post them under their own threads.

_________________
It may look hard, but it won't take long if you take it one byte at a time.

NOS: www.github.com/nkeck720/nos
Post 17 Jul 2015, 19:45
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.