MOV AX, 0x0000 doesn't work.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
RGOS
Member
Member
Posts: 38
Joined: Sat Feb 13, 2010 10:52 am
Location: Buurmalsen, The Netherlands
Contact:

Re: MOV AX, 0x0000 doesn't work.

Post by RGOS »

Hello,

Thanks for the information, the base-address in my VS project is indeed 1MB, and the KERNEL.EXE (the VS project) is correctly called, so the bootloader stage is over (for the 32 bit OS). I've found out now that calling the InitMem is exactly where the crash occurs, and one strange thing is that before calleng the function a constant is substracted from esp, 0x00180010 to be precise, the output from bochs, I made a screenshot from it, because I couldn't let bochs put it in a log. This is uploaded. The InitMem function looks like this:

Code: Select all

void InitMem(void)
{
	__asm{
		cli
		hlt
		mov		ecx, 0x00007E00
		mov		eax, [ecx]
		cmp		eax, 'SOGR'
			jne		checkag
tochok:
		add		ecx, 4
		mov		ax, [ecx]
		mov		K64blocks, ax
		add		ecx, 2
		mov		ax, [ecx]
		mov		M1M16, ax
		add		ecx, 2
		mov		ax, [ecx]
		mov		EntryCount, ax
		add		ecx, 2
		mov		ax, [ecx]
		mov		MemLoEntry, ax
		add		ecx, 2
		mov		ax, [ecx]
		mov		MemHiEntry, ax
		add		ecx, 2
		mov		eax, [ecx]
		mov		OK, 0x01
		cmp		eax, 'RGOS'
			je		ready
			jmp		ready
checkag:
		cmp		eax, 'RGOS'
			je		tochok
			mov		OK, 0x00
ready:
	}

	if(K64blocks == 0 || M1M16 == -1 || EntryCount == 0 || OK == 0){
		panicrsod("MEMORY AMOUNT ERROR", "Something went wrong while checking the amount of RAM in the system.\nThis can be caused by a faulty BIOS or broken memory or if you have only 16MB of memory.");
	}
KBTotal = (K64blocks * 64) + M1M16;
memSize = KBTotal;
MemLinEntry = (MemHiEntry * 16) + MemLoEntry;
unsigned long long BaseAddress[65535];
unsigned long long Length[65535];
unsigned Type[65535];
unsigned ACPINull[65535];
for(unsigned int i = 0; i <= EntryCount; ++i)
{
	unsigned char BAFFI = 0;
	unsigned char BAFFII = 0;
	unsigned char BAFFIII = 0;
	unsigned char BAFFIV = 0;
	unsigned char LFFI = 0;
	unsigned char LFFII = 0;
	unsigned char LFFIII = 0;
	unsigned char LFFIV = 0;
	unsigned char TFFI = 0;
	unsigned char TFFII = 0;
	unsigned char ACPINFFI = 0;
	unsigned char ACPINFFII = 0;
	unsigned int MEMADRFF = (i * 24) + MemLinEntry;
	__asm
	{
		mov		eax, MEMADRFF
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		BAFFI, bl
		mov		BAFFII, bh
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		BAFFIII, bl
		mov		BAFFIV, bh
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		LFFI, bl
		mov		LFFII, bh
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		LFFIII, bl
		mov		LFFIV, bh
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		TFFI, bl
		mov		TFFII, bh
		mov		bl, [eax]
		inc		eax
		mov		bh, [eax]
		inc		eax
		mov		ACPINFFI, bl
		mov		ACPINFFII, bh
	}
	BaseAddress[i] = (BAFFI * 16777216) + (BAFFII * 65536) + (BAFFIII * 256) + BAFFIV;
	Length[i] = (LFFI * 16777216) + (LFFII * 65536) + (LFFIII * 256) + LFFIV;
	Type[i] = (TFFI * 256) + TFFII;
	ACPINull[i] = (ACPINFFI * 256) + ACPINFFII;
}
But it's not even called, do any of you know why the constant is substracted from esp? Or why it crashes, because I don't think it's a real stack error, altough I'm going to check that right now. I'll post when I find something.

Thanks.
Attachments
Bochs.part2.rar
Part 2 of the image wth output from bochs.
(2.42 KiB) Downloaded 110 times
Bochs.part1.rar
Part 1 of the image wth output from bochs.
(62.5 KiB) Downloaded 86 times
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: MOV AX, 0x0000 doesn't work.

Post by Gigasoft »

That's no wonder. This is the reason:

Code: Select all

unsigned long long BaseAddress[65535];
unsigned long long Length[65535];
unsigned Type[65535];
unsigned ACPINull[65535];
If you want these to be used later, you should declare them outside the function so they won't be allocated on the stack. And they don't need to be so large. There's no computer with 65535 memory regions in the BIOS memory map.

The code which reads the entries into the 4 tables is wrong as it swaps the bytes and doesn't read from the correct offsets. If MemLinEntry points to the BIOS memory map, it should be:

BaseAddress = *(int*)(MemLinEntry);
Length = *(int*)(MemLinEntry+8);
Type = *(int*)(MemLinEntry+16);
ACPINull = *(int*)(MemLinEntry+20);
User avatar
RGOS
Member
Member
Posts: 38
Joined: Sat Feb 13, 2010 10:52 am
Location: Buurmalsen, The Netherlands
Contact:

Re: MOV AX, 0x0000 doesn't work.

Post by RGOS »

Hello,

Thanks for the information, but how big do you advice to make the tables (I forgot that I made them so large)? I thought maybe 15? And I think with your table reading code you ment:

Code: Select all

BaseAddress[i] = *(int*)(MEMADRFF);
Length[i] = *(int*)(MEMADRFF+8);
Type[i] = *(int*)(MEMADRFF+16);
ACPINull[i] = *(int*)(MEMADRFF+20);
Because thats every time the loop loops updated and MemLineEntry keeps to be the base-address of the memory map structure?

Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
User avatar
RGOS
Member
Member
Posts: 38
Joined: Sat Feb 13, 2010 10:52 am
Location: Buurmalsen, The Netherlands
Contact:

Re: MOV AX, 0x0000 doesn't work.

Post by RGOS »

Hello,

I found out that the code came to:

Code: Select all

   if(K64blocks == 0 || M1M16 == -1 || EntryCount == 0 || OK == 0){
      panicrsod("MEMORY AMOUNT ERROR", "Something went wrong while checking the amount of RAM in the system.\nThis can be caused by a faulty BIOS or broken memory or if you have only 16MB of memory.");
   }
But probably the memory amount information isn't read properly, because I get my RSOD, but also there's something wrong:

Code: Select all

void panicbsod(char* error, char* code)
{
	setfgcol(0x04);
	setbgcol(0x01);
	prtbgcol();
	movcur(0, 0);
	prtstr("Error:\n\n\n\n\nAn error occurred, please reboot.\nSorry for the inconvenience.\nUnsaved work might be lost.\n\n\nError: ");
	prtstr(error);
	prtstr(".\nCode: ");
	prtstr(code);
	prtstr("\n\nThis can be caused by an interrupt or an error generated by a program running.\n");
	for(;;);
}
I only see the cursor at random places on screen, do you know what that's about?
The prtstr function:

Code: Select all

void prtstr(char* str)
{
	char testchar;
	int lenie = 0;
	int eln = strleng(str);
	while (lenie<=eln)
	{
		testchar=str[lenie];
		if (testchar==10||testchar==13||testchar=='\n')
		{
			prtnl();
		}
		if (testchar == 0x08) {
			if(curx) {
        		curx--;
			}
			else {
				cury--;
				curx = SCRWIDTH;
			}
		}
		else if (testchar == 0x09) {
        	curx = (curx+8) & ~(8-1);
		}

		else if (testchar == '\r') {
			curx = 0;
		}

		else if (testchar == '\n') {
			curx = 0;
			cury++;
		}
		else
		{
			prtctje(testchar);
		}
	movcur(curx, cury);
	lenie++;
	}
}
Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: MOV AX, 0x0000 doesn't work.

Post by Solar »

@ RGOS:

In the last 14 days, 34 posts and ~25 questions, you turned this thread into your personal StackOverflow, showing a perfect example for what I call "Trial, Error, Ask" programming. Effectively, you are trying to write your OS as a community project, using this thread as a platform.

You are not doing yourself a favor by working this way. You do not learn how to carefully read documentation, break down your problems to manageable bits, and debug your code yourself. Instead, whenever a problem occurs, you post here, usually along the lines of "I have no idea what is going on", hoping to draw on the experience of others.

This is not intended to be insulting, or telling you to get off this board. But you should seriously consider tuning it down a bit, and working long enough on your problems yourself so that you can ask precise, to-the-point questions. Many of the questions you asked here point toward you not having the Required Knowledge (a link Combuster already posted a couple of pages ago), or toward you not really making an effort beyond "tried it, didn't work, help" cycle.

Have a long, hard look at your chosen signature. There's a truth in there, and it is thus: OSDev isn't that different from program development, just in a more hostile environment.
Every good solution is obvious once you've found it.
User avatar
RGOS
Member
Member
Posts: 38
Joined: Sat Feb 13, 2010 10:52 am
Location: Buurmalsen, The Netherlands
Contact:

Re: MOV AX, 0x0000 doesn't work.

Post by RGOS »

Hello,

Yes you are right, I'm going to examine my 'OS' really carefully and try very hard to solve all the problems, and if I have a problem I really can't work out, then I'll open a new thread. Thanks for all of your reply's.

Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Locked