Help wanted on reading/writing disk and writing your own OS 
Author Message
 Help wanted on reading/writing disk and writing your own OS

Hi All,

I'm trying to write my own Operating System. And I know how to
read/write the boot-sector with int 25/26. The bootsector is logical
sector 0. But what is the difference between a logical and a physical
sector.  Also, with the OS I want to have my own disk layout, my own
directory-structure. Which function is most appropriate for this task.
    Another question is that my program to load the bootstrap code and
the operating system doens't work. That is, the bootstrap code works
(ie. The 'loading' message is being printed and the OS is being loaded
into memory (I choose 0100h:0100h for now, but I've also tried higher
adresses)) but when I've actually read in the OS and jump to it (either
using a JMP or a RETF, with first pushing CS:IP) it hangs. When I debug
the program with DEBUG (I first move the program to offset 7C00) it
works fine. Who can help me?

p.s

How do I create a .COM like file (code without a header) that uses 7C00
as a origin. When I use the orgin command and link the file later I get a
'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
function to work correctly. When I use align 512 (to align to a sector) I get
a 'Segment alignment not strict enough' error. What does this mean?

--
---------------------------------------
Greetings by

Joris Weimar
The Hague, Holland


---------------------------------------



Tue, 19 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

Quote:

>Hi All,
>I'm trying to write my own Operating System. And I know how to
>read/write the boot-sector with int 25/26. The bootsector is logical
>sector 0. But what is the difference between a logical and a physical
>sector.  Also, with the OS I want to have my own disk layout, my own
>directory-structure. Which function is most appropriate for this task.

Go straight to the BIOS.  Do NOT use any DOS functions.  The address
you have chosen is quite safe; the lowest you can go is 50h:0000.  This
is where DOS starts loading.

In your boot code, use No DOS functions.  Using the BIOS int 13h is ok though,
this is what the DOS boot program does.  int 25/26 is a DOS function so
don't use it.

a physical sector is like an 'absolute' sector.  It is specified under
bios with a track, sector, head combinationn.  For convenience the DOS
functions may take a logical number in the range 0 - 36*80 (1.44mb floppy)
annd convnert it to a track sector head combinnationn.  Whenn loading
your OS from floppy you will either have to provide such a function or
write the code to work with the track,sector,head combinationn..

Quote:
>    Another question is that my program to load the bootstrap code and
>the operating system doens't work. That is, the bootstrap code works
>(ie. The 'loading' message is being printed and the OS is being loaded
>into memory (I choose 0100h:0100h for now, but I've also tried higher
>adresses)) but when I've actually read in the OS and jump to it (either
>using a JMP or a RETF, with first pushing CS:IP) it hangs. When I debug
>the program with DEBUG (I first move the program to offset 7C00) it
>works fine. Who can help me?
>p.s
>How do I create a .COM like file (code without a header) that uses 7C00
>as a origin. When I use the orgin command and link the file later I get a
>'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
>function to work correctly. When I use align 512 (to align to a sector) I get
>a 'Segment alignment not strict enough' error. What does this mean?

I think it has something to do with EXE2BIN.  If you are clever you can
create a .COM file and zero-fill the first 7b00h bytes... then write
a program to strip off the zero-filled bytes.

As for the align, you have to specify the maximum possible alignment
in the segmentn definitionn.  That means you can't used the simplified
segment directives... you have to go for the full thing.  I don't know
either if the linker is capable of settign up such alignments... it might
only be able to alignn to the nearest paragraph because of the way DOS
works.

But you don't have to worry about aligninng to a sector, the only thing
you have to be sure of is that the sector does not cross a 64K boundary
(like 64K, 128K,192K,256K, and so on).

David

Quote:
>--
>---------------------------------------
>Greetings by
>Joris Weimar
>The Hague, Holland

>---------------------------------------



Wed, 20 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

I'd try looking at some of the Linux groups, or better yet, get the Linux
source.
--
Chris Crabtree
Preferably I would just Know.
Failing that, I think it's better to Intuit.
If I can't use Intuition, I guess there's always Reason.
When Reason fails me, I resort to Foolish Confidence.
This appears remarkably similar to just Knowing.



Wed, 20 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

[comp.lang.c and comp.lang.c++ dropped]

Quote:

> I'm trying to write my own Operating System. And I know how to
> read/write the boot-sector with int 25/26.

I think you'll go in troubles.

Int 25/26 are handled by MS-DOS.  So if you use them, you are necessarily in a
MS-DOS programs, not in a new O.S.... (unless you rewrote MS-DOS, of course; but
I don't see where is the interest ;-)

Quote:
> The bootsector is logical
> sector 0. But what is the difference between a logical and a physical
> sector.

The logical scheme is the application programs view of the situation;
the physical one is what is really written on the disks.
The job of the O.S. is to handle the physical layout and to present a logicial
view to the application programs.
In your case, it means that application programs don't have to mess with 3D
coordinates (cylinder, head, sector), and only wants ONE number.

Quote:
> Also, with the OS I want to have my own disk layout, my own
> directory-structure. Which function is most appropriate for this task.

Effectively, his is usually an O.S. task.

I will advice you to read a good book in O.S. theory.
One very good that comes immediatly to my mind, is very well suited to yours
proccupations, and is written by a Dutch: Andy Tannenbaum (althought I don't
know of a Dutch translation and/or original).  I don't know the English title,
but it must looks like "Operating System Architecture".
It shows how to build an UNIX-like O.S., called Minix, in a PC.

Quote:
>     Another question is that my program to load the bootstrap code and
> the operating system doens't work. That is, the bootstrap code works
> (ie. The 'loading' message is being printed and the OS is being loaded
> into memory (I choose 0100h:0100h for now, but I've also tried higher
> adresses)) but when I've actually read in the OS and jump to it (either
> using a JMP or a RETF, with first pushing CS:IP) it hangs. When I debug
> the program with DEBUG (I first move the program to offset 7C00) it
> works fine. Who can help me?

Not me, this way works for me.
Please, show us a part of code where it hangs (if it is too big, try to bring it
in parts by echoing messages using for example BIOS interrupt to trace into the
program).

Quote:

> How do I create a .COM like file (code without a header) that uses 7C00
> as a origin.

The same way you create a .COM that uses 7C01 or 0 or 100 for origin :-)
Intel code is always relocatable while in a segment, so you will never have
troubles with the code unless you make intersegments (far) calls.
Data are mere problematic, as usually there are embedded in the .COM and
accessed by addresses (which are wrong if the file is loaded at 7C00 instead of
the more usual 0100).  So, in order to access Data in your program, you have
(usually, this is one of the first thing to do, for example in modifying the
startup code for a C program) to build a DS selector which points to 7B00 (so
DS: relative addresses will be corrects).

Quote:
> When I use the orgin command and link the file later I get a
> 'wrong CS:IP, cannot generate .COM file' error.

You need a ORIGIN 100h at the beginning of the program, whatever address your
program would really be, in order to use the logic of the linker.

Quote:
> Also I can get the align
> function to work correctly. When I use align 512 (to align to a sector) I get
> a 'Segment alignment not strict enough' error. What does this mean?

You are using TASM, aren't you?
You are trying to use the assembler directive ALIGN to tell the loader what to
do... and before it takes place, the linker will rearrange the segments at the
segment's alignment you have specified (probably by default), which are much
less (usually WORD or DWORD); so it can't handle the directive, because the
beginning of the segment isn't necessary at a sector boundary.
You need to indicate that the segment is at a sector boundary in the SEGMENT
directive.  Because SECTOR isn't a legal alignment parameter, you have to use a
more stringent one, in this case PAGE (4K alignment), which is the only one
which handle your requisites.

Hope it helps.



Fri, 22 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

Quote:

> >How do I create a .COM like file (code without a header) that uses 7C00
> >as a origin. When I use the orgin command and link the file later I get a
> >'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
> >function to work correctly. When I use align 512 (to align to a sector) I get
> >a 'Segment alignment not strict enough' error. What does this mean?

> I think it has something to do with EXE2BIN.  If you are clever you can
> create a .COM file and zero-fill the first 7b00h bytes... then write
> a program to strip off the zero-filled bytes.

TLink won't let you link an object file into a binary file unless it's
Org 100h, but as far as I know, Microsoft's linker will. So you can just
add an "Org 7b00h" to the top of it and then link with Microsoft's
linker.

Alternatively, you could add the line and assemble and link into an EXE
file, and then run EXE2BIN or EXE2COM. EXE2COM and EXE2BIN don't check
the org.

Hope it helps!

---
Venator



Fri, 22 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS



Quote:

> >Hi All,

> >I'm trying to write my own Operating System. And I know how to
> >read/write the boot-sector with int 25/26. The bootsector is logical
> >sector 0. But what is the difference between a logical and a physical
> >sector.  Also, with the OS I want to have my own disk layout, my own
> >directory-structure. Which function is most appropriate for this task.

> Go straight to the BIOS.  Do NOT use any DOS functions.  The address
> you have chosen is quite safe; the lowest you can go is 50h:0000.  This
> is where DOS starts loading.

I've discovered that. Now I use int 13h and everything works fine!

Quote:

> In your boot code, use No DOS functions.  Using the BIOS int 13h is ok though,
> this is what the DOS boot program does.  int 25/26 is a DOS function so
> don't use it.

> a physical sector is like an 'absolute' sector.  It is specified under
> bios with a track, sector, head combinationn.  For convenience the DOS
> functions may take a logical number in the range 0 - 36*80 (1.44mb floppy)
> annd convnert it to a track sector head combinnationn.  Whenn loading
> your OS from floppy you will either have to provide such a function or
> write the code to work with the track,sector,head combinationn..

Done it!

Quote:
> >    Another question is that my program to load the bootstrap code and
> >the operating system doens't work. That is, the bootstrap code works
> >(ie. The 'loading' message is being printed and the OS is being loaded
> >into memory (I choose 0100h:0100h for now, but I've also tried higher
> >adresses)) but when I've actually read in the OS and jump to it (either
> >using a JMP or a RETF, with first pushing CS:IP) it hangs. When I debug
> >the program with DEBUG (I first move the program to offset 7C00) it
> >works fine. Who can help me?

> >p.s

> >How do I create a .COM like file (code without a header) that uses 7C00
> >as a origin. When I use the orgin command and link the file later I get a
> >'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
> >function to work correctly. When I use align 512 (to align to a sector) I get
> >a 'Segment alignment not strict enough' error. What does this mean?

> I think it has something to do with EXE2BIN.  If you are clever you can
> create a .COM file and zero-fill the first 7b00h bytes... then write
> a program to strip off the zero-filled bytes.

Yes, I know but can't you prevent it (the trailing zero's)!

Quote:

> As for the align, you have to specify the maximum possible alignment
> in the segmentn definitionn.  That means you can't used the simplified
> segment directives... you have to go for the full thing.  I don't know
> either if the linker is capable of settign up such alignments... it might
> only be able to alignn to the nearest paragraph because of the way DOS
> works.

So I'll have to align 16 times!

- Show quoted text -

Quote:

> But you don't have to worry about aligninng to a sector, the only thing
> you have to be sure of is that the sector does not cross a 64K boundary
> (like 64K, 128K,192K,256K, and so on).

> David

> >--
> >---------------------------------------
> >Greetings by

> >Joris Weimar
> >The Hague, Holland


> >---------------------------------------

Thanks for your response. If you're interrested in my OS code, just mail and I'll
send it to you.

--
---------------------------------------
Greetings by

Joris Weimar
The Hague, Holland


(Buy Windows NoT)
---------------------------------------



Fri, 22 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS


Quote:

>> >How do I create a .COM like file (code without a header) that uses 7C00
>> >as a origin. When I use the orgin command and link the file later I get a
>> >'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
>> >function to work correctly. When I use align 512 (to align to a sector) I get
>> >a 'Segment alignment not strict enough' error. What does this mean?

>> I think it has something to do with EXE2BIN.  If you are clever you can
>> create a .COM file and zero-fill the first 7b00h bytes... then write
>> a program to strip off the zero-filled bytes.

>TLink won't let you link an object file into a binary file unless it's
>Org 100h, but as far as I know, Microsoft's linker will. So you can just
>add an "Org 7b00h" to the top of it and then link with Microsoft's
>linker.

>Alternatively, you could add the line and assemble and link into an EXE
>file, and then run EXE2BIN or EXE2COM. EXE2COM and EXE2BIN don't check
>the org.

>Hope it helps!

>---
>Venator

I believe TLINK will link a module with an origin of 0 if the target name is .bin


Sat, 23 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS



: : Hi All,

: : I'm trying to write my own Operating System. ....
: [snip]
: : p.s

: : How do I create a .COM like file (code without a header) that uses 7C00
: : as a origin. When I use the orgin command and link the file later I get a
: : 'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
: : function to work correctly. When I use align 512 (to align to a sector) I get
: : a 'Segment alignment not strict enough' error. What does this mean?

: You might try the shareware A86 Assembler.  It can assemble straight from
: source code to a .COM file or .BIN file with no messing around with
: EXE2BIN and LINK.

: The author's address is:

:             Eric Isaacson
:             416 E. University Avenue
:             Bloomington, IN  47401-4739
:             U. S. A.

: I don't know if he has a web site.  I'll have a look and try to get back
: to you if he has.

OK, I had a look in Yahoo.  Eric's A86 site is at:

                  http://www.*-*-*.com/

You can even download A86 and D86 (his de{*filter*}) from his site to try out.

: I hope this can help.

:                      Helpfully yours,

:                      Norman De Forest

:                       http://www.*-*-*.com/ ~af380/Profile.html

: ...........................................................................
: Q.  Wich is the greater problem in the world today, ignorance or apathy?
: A.  I don't know and I couldn't care less.
: ...........................................................................

I hope this can help.

                     Helpfully yours,

                     Norman De Forest

                      http://www.*-*-*.com/ ~af380/Profile.html

...........................................................................
Q.  Which is the greater problem in the world today, ignorance or apathy?
A.  I don't know and I couldn't care less.
...........................................................................

Hey, where'd that echo come from?

--



Sat, 23 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

: Hi All,

: I'm trying to write my own Operating System. ....
[snip]
: p.s

: How do I create a .COM like file (code without a header) that uses 7C00
: as a origin. When I use the orgin command and link the file later I get a
: 'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
: function to work correctly. When I use align 512 (to align to a sector) I get
: a 'Segment alignment not strict enough' error. What does this mean?

You might try the shareware A86 Assembler.  It can assemble straight from
source code to a .COM file or .BIN file with no messing around with
EXE2BIN and LINK.

The author's address is:

            Eric Isaacson
            416 E. University Avenue
            Bloomington, IN  47401-4739
            U. S. A.

I don't know if he has a web site.  I'll have a look and try to get back
to you if he has.

: ---------------------------------------
: Greetings by

: Joris Weimar
: The Hague, Holland


: ---------------------------------------

I hope this can help.

                     Helpfully yours,

                     Norman De Forest

                     http://www.ccn.cs.dal.ca/~af380/Profile.html

...........................................................................
Q.  Wich is the greater problem in the world today, ignorance or apathy?
A.  I don't know and I couldn't care less.
...........................................................................

--



Sat, 23 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

Quote:

> > >as a origin. When I use the orgin command and link the file later I get a
> > >'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
> > >function to work correctly. When I use align 512 (to align to a sector) I get
> > >a 'Segment alignment not strict enough' error. What does this mean?

This is a warning on my machine and hurts nothing. Set org to 7c00, And
assemble to an exe. Then use exe2bin or exe2com (from the free-dos code)
To convert it. Exe2com will warn you, but still convert it. Or, make sure
it is ok (no fixups) the strip the first 512 bytes (exe header)

Quote:
> > As for the align, you have to specify the maximum possible alignment
> > in the segmentn definitionn.  That means you can't used the simplified
> > segment directives... you have to go for the full thing.  I don't know
> > either if the linker is capable of settign up such alignments... it might
> > only be able to alignn to the nearest paragraph because of the way DOS
> > works.

> So I'll have to align 16 times!

Why do you want the code aligned (I missed th original post)?

Quote:
> Thanks for your response. If you're interrested in my OS code, just mail and I'll
> send it to you.

I would definately like a look, if you'd please email it to me. Check
mine (old, no axs 2 update it) at
http://www.pcug.org.au/~smcdonal/00jokerweb.html under os2000. Some of
the code has stupid bugs in it, but it's old. Still, some might be
interesting to look at.

Cia0, Joker/JAM Australia



Mon, 25 Jan 1999 03:00:00 GMT  
 Help wanted on reading/writing disk and writing your own OS

: I'm trying to write my own Operating System. And I know how to
: read/write the boot-sector with int 25/26. The bootsector is logical
: sector 0. But what is the difference between a logical and a physical
: sector.  Also, with the OS I want to have my own disk layout, my own
: directory-structure. Which function is most appropriate for this task.

If you are truly trying to develop your OWN operating system, you will run
into a problem using INT 25 and 26.  These are DOS functions.  Unless ou are
trying to emulate DOS, they will not be available to you.  You'll be
required to write handlers using the BIOS (INT 13).

You need to get away from the DOS thinking of things.  When writing your own
OS, there will be no functions available but the bare minimums.  Reading
sectors, writing sectors, verifying sectors, and formatting disks/tracks.
That's it.  Those come through the BIOS.  But, with such primitive tools,
you can create ANYTHING you wish.  If you want to have the directory on
track 80 of a high density disk, go right ahead.  If you want to have the
directory smack-dab in the middle of the disk, track 40 would just love you.

Remember:  you can have ANY design you want for your directory structure.
But you need to program the routines to handle it.  No DOS routines will be
available to you.  

:     Another question is that my program to load the bootstrap code and
: the operating system doens't work. That is, the bootstrap code works
: (ie. The 'loading' message is being printed and the OS is being loaded
: into memory (I choose 0100h:0100h for now, but I've also tried higher
: adresses)) but when I've actually read in the OS and jump to it (either
: using a JMP or a RETF, with first pushing CS:IP) it hangs. When I debug
: the program with DEBUG (I first move the program to offset 7C00) it
: works fine. Who can help me?

When you debug what program?  The program you're attempting to load and run?
That's great.  But you're running into a problem where you aren't getting to
that location.  What you need to debug is your bootstrap loader.

If you mean that you're debugging your bootstrap loader and it is able to
load your OS correctly, then I don't know what the problem is.  You may need
some sort of hardware de{*filter*}, or at least something more advanced than,
say, debug, CodeView and Turbo De{*filter*}.  I'm not sure what's out there,
though.  I've never tried writing my own OS.

: How do I create a .COM like file (code without a header) that uses 7C00
: as a origin. When I use the orgin command and link the file later I get a
: 'wrong CS:IP, cannot generate .COM file' error. Also I can get the align
: function to work correctly. When I use align 512 (to align to a sector) I get
: a 'Segment alignment not strict enough' error. What does this mean?

Again, you're thinking DOS here.  You cannot be thinking DOS at this point.
The program loader for DOS is preprogrammed to load a .COM file at 0100h.
That's it.  Short of using filler in the program, there's no way to get it
to start at 7C00h -- unless you modify the DOS loader code, which is not
advised.  This is why .EXE files have headers and .COM files don't.  .EXE
files are intended to be relocatable, whereas .COM files are not.  This is
also why they can only have one segment -- they are a direct memory image.
No processing is done on the data.  Therefore, DOS cannot relocate this to
another offset.      

--

Portland, OR  97212          | "Smoking areas in restaurants are like
                             |  peeing areas in swimming pools..."



Fri, 29 Jan 1999 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Help wanted on reading/writing disk and writing your own OS

2. OS writing: detecting which disk was used as boot disk

3. Need help reading/writing boot sector (floppy disk)

4. Clarification: read/write slow, and TCPSocket and sys{read,write}

5. read/write slow, and TCPSocket and sys{read,write}

6. Help OS/2-REXX read write position in file

7. Write your own OS (another update)

8. Write your own OS (update)

9. Writing my own toy OS - assembler advice.

10. writing my own OS

11. Write your own OS (another update)

12. Write your own OS (update)

 

 
Powered by phpBB® Forum Software