I cannot set the selector. It causing the system rebooting. GRUB, how to make it autorun my program?
Posted on 2003-06-12 05:02:51 by realvampire
actually i don't get it why you create a new thread, but um... ok.

first, i want to spot you on senseless code:


mov cx,#14 ;<---
mov dx,0e

out al,dx ;get a byte from port 0x0e (which one is that? what does it do?)
jcxz -3 ;and jump back if cx==0. but cx can't be zero, you've put 14 in this register before


second, it would be interresting how you test your code. do you boot it from a disk or do you launch it from dos? if so, you have to calculate the bases of the selectors differently. this is the most likely fault.

third, this part could also reset the system.


mov ax,cs
mov es,ax

cli
smsw ax ;<-- msw to ax, ax modified!!
or al,1
lmsw ax

prefix ;<-- what's that for?
cld
mov ss,ax

ax contains the msw, NOT the cs-value (marked). furthermore you don't set ds.

fourth, you have to do the far jump! this is to set cs:eip simultaneously. the code gets launched from 0000:7C00, i.e. cs is zero. if you then just set the pe-bit cs won't be used as a segment anymore, it will be a selector. since cs is still zero, the NULL-descriptor will be used, which is not valid.

debugging:
it's hard work to find out where's the fault. if you practice the direct way (i.e. you wrote a bootloader which loads up your kernel and executes it, as i did) you can set an endless slope on important places:


:
:
mov ax,bp
add ax,#46
call ax

mov ax,4f02
mov bx,118
int 10

jmp -2 ;endless slope, computer hangs

if the computer doesn't reset and reboot you know the code works to this spot.
another possibility is to write something on the textscreen:


mov ax,0xb800
mov es,ax
mov byte [es:0000],'1'

on the topleft corner a '1' appreas. note that the second char is at , the third on and so on.

hope this helps
Posted on 2003-06-13 13:47:24 by hartyl
When I try to use Jmp far ( I use EA C0 DE 08 00 ) It rebooted. LMSW ax doesnot rebooted, I think the GDT succesfully loaded, but it seem to be invalid. Can you tell me whats your mistake when you made a pmode switch?. I upload a new source, hope you can find me whats my mistake. Im not using it as my boot sector anymore, its too difficult, and it causing my diskette damaged rewriting it all the day





Prefix << This one mean, [use32] bits on NASM or FASM




I use MS-DOS to test it, I dont know how to use GRUB.
Posted on 2003-06-15 20:28:34 by realvampire
oh man, are you crazy?! when you write a bootloader, the first sector is loaded to 0000:7c00, but if you write a .com-file and test it with ms-dos it's loaded at cs:0100, where cs is assigned by dos (everytime different) and cs==ds. so you have to fix up all bases of your gdt.



mov cx,#31999 ; Still in Real segment
cld ; Tell our code are work 'till here
rep ; Only SS valid till here
movsb ;

what the hell does this code? you move 32000 bytes from ds:si to es:di - where do you set the values?
i told you that after setting you have a 16/32bit mix, you sould do a far jump immediately after setting the pe-bit. afterwards set the selectors.
i hope you know that the 0008:00DAC0DE-address was just an example - not the real address you should jump to.

i'm currently at school, so i can't rewrite your code - i'll do that at home if i have time.
Posted on 2003-06-16 04:23:52 by hartyl
I almost give-up. It really difficult. I dont know whats my mistakes. Yes DS and cs always changed.
Posted on 2003-06-16 09:54:47 by realvampire
ok, i'll cheer you up now. i have found a tutorial which is like made for you. here it comes:
Posted on 2003-06-16 11:22:31 by hartyl
I already have it. But thanks. Im still trying and trying. Its been a month I get stuck in Pmode switch. :alright: Im never give up.

I have Jump, but it still rebooted. I use jmp 0010:021a, because my next code put there. Can you rewrite my code, please?
Posted on 2003-06-16 21:48:49 by realvampire
I heard a BIOS Call can set it automatically. Int 0x15 ah=0x89. Can I have the sample or the site containing it?


Hi, it work. This is my mistakes.

GDT db FF,FF,0,0,0,9a,CF,0 ; It was not valid
GDT db FF,FF,0,0,0,9a,0F,0 ; Valid

I use linier jump with CF on it. I have changed it to 0F. :alright: Thank you hartyl.

BTW: Can I see your code? My GDT are not completely right. I need a working gdt.
Posted on 2003-06-16 23:40:20 by realvampire
:) I cant believe it, my 286 byte .com program control the whole computer. But why Call are not allowed? What selector should I use?The current selector code? But it containing a base. Maybe I must made a new selector.:alright: I love it.
Posted on 2003-06-18 09:36:09 by realvampire
Hi

I recently coded (from DOS prompt) a program that loads my GDT/IDT to XMS without any memory manager, full 32-bit... It was very hard to debug, but I learnt a lot from it, and I started with Alexei Frounze's tutorial (C is more understandable at the beginning ; now I translated the whole project to asm with Fasm 1.47).

Good luck
Posted on 2003-07-17 06:05:59 by valy
and use IRET
Posted on 2004-01-01 22:16:00 by mrgone