OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 11:48 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How can I make my kernel load files?
PostPosted: Wed Jan 25, 2017 8:48 am 
Offline

Joined: Wed Jan 25, 2017 8:16 am
Posts: 23
Hey guys. I'm new to the forum! 8)

I'm following a tutorial (only to start learning more about Assembly by playing around with code) which is DonkerOSYD. I want to make the kernel load a BIN file.

This is KERNEL.ASM

Code:
BITS   16

Main:

cli

mov   ax, 0x0000

mov   ss, ax

mov   sp, 0xFFFF

sti



mov   ax, 2000h

mov   ds, ax

mov   es, ax

mov   fs, ax

mov   gs, ax



mov   [BootDrive], dl



setup_bg:

mov   dx, 0

call   move_cursor



mov   ah, 09h

mov   al, ''

mov   bh, 0

mov   bl, 00000111b

mov   cx, 2400

int   10h



mov   si, version

call   Print



call   newline



mov   si, copyright

call   Print



cmd:

call newline



mov   si, prompt

call   Print



mov   di, input_buffer



mov   al, 0

mov   cx, 256

rep   stosb



mov   ax, input_buffer

mov   di, input_buffer



.loop:

call   keyboard



cmp   al, 13      ;ENTER

je   .done



cmp   al, 8      ;BACKSPACE

je   .backspace



jmp   .character



.backspace:

mov   ah, 0Eh

mov   al, 8

int   10h

mov   al, 32

int   10h

mov   al, 8

int   10h

dec   di

jmp   .loop



.character:

mov   ah, 0Eh

int   10h

stosb

jmp   .loop



.done:

mov   ax, 0

stosb



call   newline



mov   si, input_buffer

cmp   BYTE [si], 0



je   cmd



;All built-in commands

mov   di, help_string

call   compare

jc   help



mov   di, help_uc

call   compare

jc   help



mov   di, dir_string

call   compare

jc   dir



mov   di, dir_uc

call   compare

jc   dir



mov   di, exit_string

call   compare

jc   exit



mov   di, exit_uc

call   compare

jc   exit



;what if it's not a built-in command?

mov   si, input_buffer

call   Print



mov   si, no_command

call   Print



jmp   cmd



%INCLUDE "variables.asm"

%INCLUDE "functions.asm"

%INCLUDE "cli_commands.asm"


This is functions.asm
Code:
newline:

pusha

mov   ah, 0Eh

mov   al, 13

int   10h

mov   al, 10

int   10h

popa

ret



Print:

lodsb

cmp   al, 0

je   Done

mov   ah, 0eh

int   10h

jmp   Print



Done:

ret



move_cursor:

pusha

mov   ah, 02h

mov   bh, 0

int   10h

popa

ret



keyboard:

pusha

mov   ax, 0

mov   ah, 10h

int   16h

mov   [.buffer], ax

popa

mov   ax, [.buffer]

ret



.buffer   dw   0



compare:

pusha



.loop:

mov   al, [si]

mov   ah, [di]



cmp   al, ah

jne   .not_equal



cmp   al, 0

je   .equal



inc   si

inc   di

jmp   .loop



.not_equal:

popa

clc

ret



.equal:

popa

stc

ret



reset_floppy:

mov   ax, 0

mov   dl, BYTE [BootDrive]

int   13h

ret



convert_sector:

push   bx

push   ax

mov   bx, ax

mov   dx, 0

div   WORD [.SectorsPerTrack]

add   dl, 01h

mov   cl, dl

mov   ax, bx

mov   dx, 0

div   WORD [.SectorsPerTrack]

mov   dx, 0

div   WORD [.Sides]

mov   dh, dl

mov   ch, al

pop   ax

pop   bx

mov   dl, BYTE [BootDrive]

ret



.SectorsPerTrack   dw   18

.Sides   dw   2



os_string_uppercase:

   pusha



   mov si, ax         ; Use SI to access string



.more:

   cmp byte [si], 0      ; Zero-termination of string?

   je .done         ; If so, quit



   cmp byte [si], 'a'      ; In the lower case A to Z range?

   jb .noatoz

   cmp byte [si], 'z'

   ja .noatoz



   sub byte [si], 20h      ; If so, convert input char to upper case



   inc si

   jmp .more



.noatoz:

   inc si

   jmp .more



.done:

   popa

   ret


And cli_commands.asm
Code:
buffer   equ 24576



dir:

pusha

mov   di, dirlist



call   reset_floppy



mov   ch, 0

mov   cl, 2

mov   dh, 1

mov   bx, buffer

mov   al, 14

mov   ah, 2

pusha

load_root_dir:

int   13h

jnc   loaded_root_dir

call   reset_floppy

jmp   load_root_dir



loaded_root_dir:

popa

mov   si, buffer



compare_entry:

mov   al, [si+11]

cmp   al, 0Fh         ;Windows marker

je   .skip_entry

cmp   al, 18h         ;Directory marker

je   .skip_entry

cmp   al, 229         ;deleted file

je   .skip_entry

cmp   al, 0

je   .done



mov   dx, si

mov   cx, 0



.save_character:

mov   BYTE al, [si]

cmp   al, ' '

je   .space

mov   BYTE [di], al

inc   di

inc   si

inc   cx

cmp   cx, 8

je   .add_dot

cmp   cx, 11

je   .string_copied

jmp   .save_character



.add_dot:

mov   BYTE [di], '.'

inc   di

jmp   .save_character



.space:

inc   si

inc   cx

cmp   cx, 8

je   .add_dot

jmp   .save_character



.string_copied:

mov   BYTE [di], ','

inc   di

mov   si, dx



.skip_entry:

add   si, 32

jmp   compare_entry



.done:

mov   si, dirlist

mov ah, 0Eh

.print:

lodsb

cmp   al, 0

je   .done_printing

cmp   al, ','

je   .comma

int   10h

jmp   .print



.comma:

call   newline

jmp   .print



.done_printing:

popa

jmp   cmd





help:

mov   si, help_message

call   Print

jmp   cmd



exit:

mov   ax, 5307h

mov   cx, 3

mov   bx, 1

int   15h


How would I make it so it loads files?

Thanks
Steve.


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Wed Jan 25, 2017 8:59 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Since you're writing an application that uses BIOS, use BIOS to load files - load boot sector, detect the filesystem, load necessary sectors of the filesystem with file directory, find the file there and load file's sectors in memory, one after another.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Wed Jan 25, 2017 10:17 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
How To Ask Questions.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Wed Jan 25, 2017 10:51 am 
Offline
Member
Member

Joined: Sat Nov 07, 2015 3:12 pm
Posts: 145
Hi,
Linux can be booted by many protocols. However, multiboot is not the most common one.
You can look at https://github.com/torvalds/linux/blob/ ... 6/boot.txt for reference.

This may not be what you want for your kernel.


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Wed Jan 25, 2017 11:31 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
No one is going to review that code for you. If you have a bug you can't figure out, bring it down to a test case (which should be a few lines long and written in a clear style, unlike the mess above) and maybe someone will look over it. If you're not sure how to implement something or don't understand some piece of theory, ask specific questions about it. All we can do is try to guide you a little bit in the right direction but you have to do pretty much all of the work yourself (or pay someone to do it for you).

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Thu Jan 26, 2017 1:38 pm 
Offline

Joined: Wed Jan 25, 2017 8:16 am
Posts: 23
What code could I use to load a file?

_________________
One day in the future... computers will be holograms...


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Thu Jan 26, 2017 3:08 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
stevej150 wrote:
What code could I use to load a file?


Disk driver code and filesystem code. These two should be generally enough.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: How can I make my kernel load files?
PostPosted: Sun Jan 29, 2017 4:46 pm 
Offline
Member
Member

Joined: Sat Feb 27, 2010 8:55 pm
Posts: 147
stevej150 wrote:
What code could I use to load a file?


Look up FAT bootloaders; they're easy to find and easy to understand. If you don't want to use FAT or if you have trouble understanding it, make your own rudimentary file system. Just think through what you need: Your files need names, those names need to be stored somewhere, the files themselves need to be stored somewhere, upon finding the name of a file you're looking for, you have to have a way to find where that file is stored. Just think it through; if you know how to load sectors you can create your own filesystem and bootloader.

(And if you don't know how to load sectors, look into Ralf Brown's Interrupt List, int 13h. Be aware that LBA won't work on floppies or devices emulated as floppies).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 137 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group