Page 1 of 2
Help me a bit please?
Posted: Tue Mar 23, 2004 12:00 am
by Berry
Hello,
I'm going to write a bootloader, I will first make it real mode, test it and then will add pmode! I'm reading this
http://www.nondot.org/sabre/os/files/Bo ... otsect.txt but I and understand all the assembly... Why do they use mov [bootdrv], dl and not just mov bootdrv, dl?
how does this work?
; test if 8088/8086 is present (flag bits 12-15 will be set)
pushf ; save the flags original value
xor ah,ah ; ah = 0
push ax ; copy ax into the flags
popf ; with bits 12-15 clear
pushf ; Read flags back into ax
pop ax
and ah,0f0h ; check if bits 12-15 are set
cmp ah,0f0h
je no386
doesn't seem logic to me... why first put the flags on the register, put ah on top off it, get the flags out of it, get the flags back in it, get ax out of it??? Why? Ok its probably just because I don't understand assembly to well, but can anybody please explain? Or is there any good tutorial on asm, like NASM, so that I can use it with my os?
RE:Help me a bit please?
Posted: Tue Mar 23, 2004 12:00 am
by hartyl
what the code does, is to check if we have a 386 or not. to do that we know a property of the 8086, which differs it from the 386. whatever a value you put on the flags-register of the 8086, the bits 12-15 will be set.
so, you put a value into the flags-register where these bits are clear and check if they have become set. if so, we have a 8086.
to your other question: bootdrv is just an adress, a constant value which specifies the location of a value in the memory. with mov [bootdrv],dl you move dl to that memory location. mov bootdrv,dl is not possible as it would overwrite the constant value.
RE:Help me a bit please?
Posted: Wed Mar 24, 2004 12:00 am
by Berry
but we pushf and then push ah (=0) onto that. Then we popf. Does that popf take the 0 we push on it with it, so the flags get this value or something? Otherwise it can't now that we push 0 on it, can it?
And are there any good asm tutorials around?
RE:Help me a bit please?
Posted: Wed Mar 24, 2004 12:00 am
by Berry
oh and yes, I've decided to make my first os REAL MODE, this will be an good lessen
any tips?
RE:Help me a bit please?
Posted: Wed Mar 24, 2004 12:00 am
by hartyl
ya, that's exactly what it does.
backup the flags, push zero on it, pop it into the flags, get the value again and check it, then restore the backuped flags.
greets, hartyl
RE:Help me a bit please?
Posted: Wed Mar 24, 2004 12:00 am
by Anton
The next instruction is only to save the flags.
pushf ; save the flags original value
xor ah,ah ; ah = 0
push ax ; copy ax into the flags
popf ; with bits 12-15 clear
now we read 0 in to the flags
Now we need to check the actual value of flags
pushf ; Read flags back into ax
pop ax
ax cotains the actual value of flags
and ah,0f0h ; check if bits 12-15 are set
cmp ah,0f0h
there should be a
popf
je no386
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by ASHLEY4
Berry go and get "bootprog.zip" ,this boots a com or exe for the floppy, you can write your OS useing only bios int's (no dos int's) put it on the floppy as a com or exe and boot it.
You can get from here:
http://alexfru.chat.ru/epm.html
ASHLEY4.
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by Berry
hej, seems funnie
But can I write a program in Turbo C then? But it isn't an os then, is it?
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by Anton
You can also write an OS is C++.
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by Berry
yes I know that... But you will always need to know a bit of asm... so: is there any good Assembly tutorial around? I understand basics like mov, pop, push enz., know what registers are (but not exactly which one is for which thing), but thats al...
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by Karig
Actually that final "popf" should come immediately after the "pop ax." If you "popf" immediately before testing the zero flag with "je no386," you'll be testing the state of the zero flag AS IT WAS when you pushed the flags -- the "flags original value" as your comment says -- NOT the state of the zero flag as set by the "cmp" instruction. The "popf" overwrites the zero flag (and all the other flags of course).
So the code should be something like this:
; Save original flags
pushf
; Clear flag bits 8..15
xor ah, ah
push ax
popf
; Retrieve flag bits
pushf
pop ax
; See if bits 12..15 are set
and ah, 0xF0
cmp ah, 0xF0
je no386
; Do something for 386
; ...
jmp restore_flags
no386:
; Do something for non-386
restore_flags:
popf
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by Anton
I guess i did't think twice
RE:Help me a bit please?
Posted: Thu Mar 25, 2004 12:00 am
by JAAman
and your CMP is unneccessary since AND stores results to flags
RE:Help me a bit please?
Posted: Fri Mar 26, 2004 12:00 am
by Berry
ok, I begin to understand ik
. I wanna make a simple start in my os
So first I'm going to make a real mode bootloader, which loads a C++ kernel from the floppy
Do I have to make fat-support then, or can I make the fat driver in my kernel? Anyone other tips? Are there good references (like a pdf/html or something) on assembly, so I can find all things I wanna know? Anyone tips?
RE:Help me a bit please?
Posted: Fri Mar 26, 2004 12:00 am
by JAAman
if you make your boot-loader FAT compatible then your disk should work on any OS making it easy to copy other files to your test disk(including your kernel file)but that means your boot sector needs the proper data block and then you should serch the root dir for the file name of your kernel/second-stage and find its location on disk--its really not that hard to do and then you can just copy the files from dos/win/linux for your kernel/second-stage -- that way its easy to use and edit the rest of your OS without ever changing the boot code as you would if you were loading absolute disk sectors
but you dont need full FAT support just enough to do what you need to load the files