flat assembler
Message board for the users of flat assembler.

Index > OS Construction > [HOW] Execute next file from boot sector?

Thread Post new topic Reply to topic

Joined: 25 Aug 2004
Posts: 619
Hi all!,

I've just started FASM and have written a very simple boot sector that basically just says "Hi" and reboots when ESC is pressed. I now have to execute the next file to start my OS - this is where I'm totally confused, anyone got any tips/links/source code that show me how to do this?

So far I got:

        mov ax,0x0003 ; Clear screen
        int 0x10


        ; init OS <<

        mov ax,0x1301
        mov bx,0x0007 ; write text
        mov cx,0x52 ; msg_ready length
        mov bp,msg_ready
        add bp,0x7C00
        int 0x10

        mov ah,0x00 ; wait keyboard input
        int 0x16

        cmp al,0x1B ; check if ESC is pressed
        jne Boot_Finished


        db 0xEA
        dw 0x7C00,0x0000 ; reboot


        ; Execute OS << 

msg_ready db '==== Welcome to MyOS! ====',13,10,'  Press any key to start  ',13,10,'=========================='



While I'm at it: (1) Can I use int's w/o DOS??? (2) Is any of the above the wrong way to do it?

Thanks in advance,

Post 25 Aug 2004, 01:41
View user's profile Send private message Reply with quote

Joined: 28 Apr 2004
Posts: 376
Location: UK
Hi cod3b453, The best advice i would give you is to go here: http://alexfru.chat.ru/epm.html
and get "bootprog.zip" it's a program that fits on the boot sector and lets you boot a com or mz exe from the floppy disk, so all you do is assemble your OS as a com or exe put it on the floppy like you would any other program and reboot,
and it will run your OS , do not use dos int's in your OS, as there is no dos, but you can use bios in realmode.
I use that program for my OS, if you want to try it and have windows, get my vesa demo from here http://board.flatassembler.net/topic.php?t=1940
(called VesaDemo.zip with code) and when finshed with demo, you can put your OS on the disk just by deleting the demo(the file on the disk called kernel32.exe) and renaming your OS "kernel32.exe" and put it on the disk and reboot.
Hope this helps.

Here is a example of how to make your own int's WITH OUT DOS.
Note: these are for realmode, also you can still use bios int's with out dos.

;----------------------------------------------------------------------------install_int:       push ds        cli        xor ax, ax        mov ds, ax                  ; set int 20h        mov word [ds:20h*4], int20   ; (terminate com files)        mov word [ds:20h*4+2], cs        mov word [ds:21h*4], int21        ; and int 21h (DOS)        mov word [ds:21h*4+2], cs        sti        pop ds     ret;----------------------------------------------------------------------------;----------------------------------------------------------------------------;* int 20H: terminate .COM program.;----------------------------------------------------------------------------int20:   push cs        pop ax        mov ds, ax        mov es, ax       jmp halt;----------------------------------------------------------------------------;* int 21H: DOS emulation;----------------------------------------------------------------------------int21:   sti                             ; enables interrupts        cmp ah, 0        je near _func00                      ; terminate program        cmp ah, 25h        je near _func25                 ; set int vec        cmp ah, 35h        je near _func35                       ; get int vec       cmp ah, 48h        je near _func48                    ; alloc ram memory        cmp ah, 4Ch        je near _func4C                      ; terminate program        jmp int21_error;----------------------------------------------------------------------------; terminate program_func00:    jmp near int20;----------------------------------------------------------------------------; write string; input es:dx = string (ended with '$')_func09:    push bx        mov bx, dx.next:       mov al, byte [es:bx]        cmp al, '$'        je .done        call chrout        inc bx        jmp .next.done: pop bx        mov al, '$'        jmp int21_exit;----------------------------------------------------------------------------; set interrupt vector_func25:  cmp al, 19h             ; do not allow to change int 19h (for rebooting)        je near int21_error        cli        xor ah, ah        shl ax, 2        push si        push bx        push es        mov si, ax        xor bx, bx        mov es, bx        mov word [es:si], dx              ; offset        mov bx, ds        mov word [es:si+2], bx                ; segment        pop es        pop bx        pop si        sti    jmp int21_exit;----------------------------------------------------------------------------; get interrupt vector_func35:        push ds        push si     xor ah, ah        shl ax, 2        mov si, ax        xor bx, bx        mov ds, bx             ; DS = 0        mov bx, word [ds:si+2]  ; segment        push bx        mov bx, word [ds:si]    ; offset        pop es                      ; get segment        pop si        pop ds   jmp int21_exit;----------------------------------------------------------------------------; alloc ram memory_func48:     mov ax, word [cs:end_memory]        add ax, bx        cmp ax, word [cs:top_memory]        jg .error        mov word [cs:top_memory], ax.error:    mov bx, word [cs:top_memory]        ; return in bx free paragraphs        sub bx, word [cs:end_memory]      stc   jmp int21_error;----------------------------------------------------------------------------_func4C:        jmp near int20int21_error:    mov ax, 0FFFFhint21_exit:       iret;----------------------------------------------------------------------------    

Also these are writen in nasm, so may need conveting for fasm.

Post 25 Aug 2004, 02:22
View user's profile Send private message Reply with quote

Joined: 25 Aug 2004
Posts: 619
Thanks for the quick reply! I'll try it ASAP.

Are int's 10 and 16 BIOS int's?


Post 25 Aug 2004, 03:00
View user's profile Send private message Reply with quote

Joined: 15 Dec 2003
Posts: 313
Yes, ints 0x10 and 0x16 are bios ints.

Post 25 Aug 2004, 05:27
View user's profile Send private message Reply with quote

Joined: 15 Jul 2004
Posts: 51
If all you want is to execute more code, load the sectors you want where you want and jump there.

Most simple is to load the next code right after your bootsector code. I've made it so that the whole boot stage is one program only which is written on sectors 1-18, the first sector loads sectors 2-18 immediately after the first sector and execution continues forward.

Use for example int 13h for loading the sectors from fdd. It's absolutely unnecessary to have things set up as files at this moment, just load raw sectors. You can use DEBUG for writing the sectors, or other specialized programs (I like John Fine's PARTCOPY).
Post 06 Sep 2004, 09:37
View user's profile Send private message 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.