Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to write an OS.. Help me a bit? 1

Status
Not open for further replies.

DevPortal

Programmer
Jul 8, 2005
40
0
0
US
I'm utilizing a bootloader I found online which I modified. It can load a COM file after booting, and supports minimal error handling. It is copyrighted, so if anyone has a bootloader which I can have that can load a .com file or any other file type that can be made in C or assembly, please tell me. Also: My current problem (while utilizing the bootloader i have) is that I am trying to write a kernel. I am trying to program for keyboard support so that the user can type things in, and then I can have the OS jump to different code based on what they type in. It will be a very simple setup, but this is what i'd like for now. Currently I have this: (i'm new to assembly, so there may well be errors, and the output of this SHOULD [but doesn't] allow the user to display one keypress at a time.)

inputloop:
int 9
in al, 60h
msg db, al
bios_print_string msg
jmp inputloop
 
I've tried using loaders like GRUB in the past, but unfortunately for me I build from Windows XP, and it has no DD command. Without DD I can only write one floppy image at a time to a floppy. Only Linux DD has this functionality.

Anyway, I need only one more piece of code to have a functional OS and be able to start writing COM programs for it. I need to know how to execute a COM program from assembly language. I hope to achieve the following with this:

1.
Accept Keyboard Input from the user, and put it into a register (and display it on the screen at the same time)

2.
Upon the user pressing enter, execute the com file that they have typed the name of.

3.
The com files I and others write for this OS will have to have code, that on pressing escape, will restart the main COM file of the OS, which will again query them for a COM file.

This is a simple setup, but it should work. Can you help me to fill in the code for the steps?
 
I'm sorry but I really don't quite understand your problem.
If you want to boot from floppy (or anything else for that matter), you just need to create a "boot sector" which you can create as a file and then write directly to floppy using something like rawrite (for windoze!!!).
As for creating COM programs, you can simply write whatever assembly code you want and connect it to the end of the boot sector. You just have to make the boot sector point to it and it will then execute directly on boot.
I'm sure you could learn lots about all this from the documentation and even the source code on the GRUB website that I gave you.

Also, GRUB has menus and handles the keyboard for user input.


Trojan.
 
Ok ok.. I'll try to put this into simpler terms.

I have a boot sector. It works. I have it boot the computer, show a "booting the kernel" thing, and then start the kernel, which is in the form of a .COM file.

I need to write the kernel. This is where I need help. I need the kernel to do the following, in this order:

1. Display "Command: "
2. Display keyboard input and record it into a register or variable after the prompt.
3. When the user presses Enter, execute the .COM file with the name specified in the register or variable mentioned in step 2.

Understand now? I need help writing the kernel, and only have a light grasp on assembly, enough to modify code. I haven't found a tutorial that goes into the areas I need to learn for this, and so I turned to human help. I need you to give me code for steps 1, 2, and 3, shown above. Thanks!
 
We can't write complete kernels for you. That is way too complex. That is why I pointed you to sample code that others have developed over many years.
You can look at the source and see how others have done it.
I realise that what you want appears to be simple but you are making many assumptions with that. When you look at how others have done it you will see some of the issues.
Also, if you have only a light grasp on assembly language, it is going to be much tougher for anyone to explain it all to you.
I suggest you look at other code that works and come back with simpler questions like "how do I make this code [blah blah] do that", rather than "can someone teach me how to write an operating system".



Trojan.
 
Yea, its easy for you to continually point me away to tutorials that don't exist. I have yet to find a single tutorial on the internet that does anything but basic assembly. I get basic assembly, and it doesn't work for what I need. I need to know how to execute an external file. If you can get me that single piece of code, or point me to one of these magical tutorials and code snippets that explain to me how to execute a COM file from assembly code, point away.
 
To execute an external COM (by which I assume you mean binary image) file, simply load it into memory at any convenient address - since its a COM file the first byte should be executable. Once you've loaded it call that address.

Your OS code will probably be something like

GetUserInput:
Read & Process Keys
Load Requested Program into 1234:0000
Call 1234:0000
Jmp GetUserInput

Hope this helps.
 
Yes. This does help, this is more what I wanted. I'll go check my "Complete 8086 instruction set" and see how to load the programs into memory... I'll post again if I run into anything, thanks.
 
You will need to Int 13h, Function 2, the BIOS disk IO Read function to read the file into a buffer.

Hope this helps.
 
After inspecting every command in the reference I have, the closest thing to loading a program into memory I could find was this:
Load Effective Address.

Algorithm:

* REG = address of memory (offset)


Generally this instruction is replaced by MOV when assembling when possible.

Example:


ORG 100h

LEA AX, m

RET

m DW 1234h

END

AX is set to: 0104h.
LEA instruction takes 3 bytes, RET takes 1 byte, we start at 100h, so the address of 'm' is 104h.

Needless to say, this doesn't seem to do it... Which command should I be using?
 
Oops, I didn't recheck before posting again, I apologeize, thank you.
 
Ok I've got my code all prepared to read from the proper sectors and such, however, I've a problem.

In order to read from a specific sector of the floppy, I must be able to write from a specific sector of the floppy. I am operating out of Windows, and hence have no DD (DD for windows I have tried to use, but cannot get it to work properly). Rawrite (to my knowledge) cannot write to a specific spot on the floppy. Know of any tools to do this?
 
I don't think you can do direct disk access through Windows. You would probably be better off woth an old DOS machine to work on.
 
After searching for a bit, I've found a utility called SecWrite, which can do what I asked. It, coincidentally, is written in ASM.. I'll be converting it into a utility for my OS as well.
 
I've just had a quick look at SecWrite and a couple of things spring to mind:

It's dated 1998
It uses Int 21h - the DOS services interrupt

It is unlikely to run under protected mode Windows and your operating system wont have access to DOS services.
 
You can write to the floppy with rawrite to specific sectors by padding the file in 512 byte chunks.

Simply create your binary file with the boot sector at the start of the file and pad to where you want the next block of data to go. Then write the whole file to floppy as one stream.

For example. If your boot sector is sector 0 and your code is at sector 1, create a file with your boot sector (say 36 bytes) and pad with null chars or whatever you like until you have written 512 bytes. The add the rest of your binary code to the file and write the whole file in one chunk using rawrite.


Trojan.
 
TrojanWarBlade, DevPortal is envisaging having more than one "COM" file, so some sort of Filing or Indexing system would be required to identify the Name, Start and Size of each "COM" file.

 
Ok two things.

1. Secwrite works just fine, and I'm running WinXP. WinXP likely has initiated a compatibility mode, so there shouldn't have been a problem anyway.

2. I'm having issues with my loading code. I have two .com applets atm, one is calc.com and one is snake.com.

Calc.com is a calculator, and snake is a game. Calc is at C/H/S 0/0/18, and snake is 0/0/17. (both track 0)

I have this code in a COM file which is loaded after it boots (And i know it is being loaded properly, cuz i have tested it in many ways):

MOV AH, 02h ; read function.
MOV AL, 10 ; sectors to read.
MOV CH, 0 ; cylinder.
MOV CL, 18 ; sector.
MOV DH, 0 ; head.
MOV BX, 0800h
MOV ES, BX
MOV BX, 0
INT 13h
JMP 0800h:0000h

When it loads it shows my loading message for the bootloader, and then it hangs...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top