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 »

jal wrote:Didn't think it would, given that it's the linker that gives the error, but still it's better to have a working memset.
I was afraid already...
jal wrote:Could you give the exact linker error output (sorry, too lazy to check the previous pages to see whether you already did).
Don't mind, the exact error:

Code: Select all

Error	16	error LNK2019: unresolved external symbol __aullshr referenced in function "int __cdecl install_ir(unsigned int,unsigned short,unsigned short,void (__cdecl*)(void))" (?install_ir@@YAHIGGP6AXXZ@Z)	IDT.obj	main
Error	17	error LNK2019: unresolved external symbol _memset referenced in function "int __cdecl idt_initialize(unsigned short)" (?idt_initialize@@YAHG@Z)	IDT.obj	main
Error	18	error LNK2001: unresolved external symbol _memset	MemManagePhys.obj	main
Error	19	error LNK2001: unresolved external symbol _memset	MemManageVirt.obj	main
Error	20	error LNK1120: 2 unresolved externals
The 15 items before this are warnings, but those aren't important (I think, if you do want to see them, say it).
jal wrote:A simple Google reveals this. But why would you want to shift 64-bit variables in 32-bit code?
I don't use aullshr myself, but I do use 'uiBase >> 16', and apparently that's replaced by the linker or compiler or whatever, that's why I'm afraid the solution Gigasoft posted isn't going to work, but more on that later.
jal wrote:And why does the linker complain about memset, if you don't use memset yourself? Are you sure you aren't linking some standard libraries?
I'm using memset myself, it's even a function inside my own code (is that maybe just the problem?).

@Gigasoft: Is this (the attachment) right then? And do I need to make a function in my C++
code to implement aullshr (with inline assembley) or don't I get you?

Thanks.
Attachments
KERNEL.ASM
The new KERNEL.ASM.
(2.75 KiB) Downloaded 165 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 »

You don't need the code from CopyImage up to and including the rep movsd since the header is accessed at IMAGE_RMODE_BASE and the sections are copied by the code below.

The __aullshr can be placed in a separate ASM file which you assemble (using the -f win32 option in the NASM command line), and then you can add the result OBJ file to the project. Be sure to have a bits 32 at the start of the ASM file. Then it should work. _memset and _strlen are also simple, the most basic versions look like this:

Code: Select all

global _memset
_memset:
push edi
mov edi,[esp+8]
mov al,[esp+12]
mov ecx,[esp+16]
rep stosb
pop edi
ret
global _strlen
_strlen:
push edi
mov edi,[esp+8]
or ecx,-1
mov edx,edi
mov al,0
repnz scasb
sub edi,edx
dec edi
xchg edi,eax
pop edi
ret
They could probably also be written in the C file (then you wouldn't use the global statement or the labels) if you add the __declspec(naked) to the declaration of the functions. Then __aullshr would be named _aullshr and _memset would be named memset.
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've tried what you said, pasting the code of aullshr and memset in a .asm file and compile it with -f win32, all and well, I've added them to the VS2010 project, but do I need to add a reference or something (I don't know)? Because I get the linker errors still...

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.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

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

Post by Gigasoft »

Well if adding the OBJ to the project doesn't work, try putting the name of the OBJ in Linker => Input => Additional Dependencies instead.
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've tried adding the .obj file to the Additional Dependencies, but now I get these errors:

Code: Select all

Error	16	error LNK2001: unresolved external symbol _memset	memsetaullshr.obj	main
Error	17	error LNK2001: unresolved external symbol _memset	IDT.obj	main
Error	18	error LNK2001: unresolved external symbol _memset	MemManagePhys.obj	main
Error	19	error LNK2001: unresolved external symbol _memset	MemManageVirt.obj	main
Error	20	error LNK2001: unresolved external symbol __aullshr	memsetaullshr.obj	main
Error	21	error LNK2001: unresolved external symbol __aullshr	IDT.obj	main
Error	22	error LNK2001: unresolved external symbol aus_1	memsetaullshr.obj	main
Error	23	error LNK2001: unresolved external symbol aus_2	memsetaullshr.obj	main
Error	24	error LNK1120: 4 unresolved externals	C:\Users\Robke.WALHALLA\Desktop\RGOS\DevelopmentOfRGOS\FILES\NewTry\kernel\Debug\main.exe	main
I've to go get some sleep now, I go on tomorrow.
But do you know how this happens?

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
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

This thread is more and more looking like errors between the keyboard and chair. The asm as posted generates an object file with the desired symbols as exports, not imports, which basically means that I can not reproduce your error without deviating from the instructions.

And in general, you should not need to ask about how to fix undefined references, given that you are apparently good enough to write an OS?</sarcasm>
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

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

Post by Gigasoft »

There's a slight mistake in the __aullshr I posted (the aus_2: should be aus_0: ), but it shouldn't cause those error messages.
Try adding section .text at the top of the ASM file and reassemble it. If it still doesn't work, maybe you should post the generated OBJ file because it sounds like something's very wrong with 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,

@Combuster: I'm trying to develop an OS just because I want to learn how it works, and the best way is if you run into trouble to ask. And I do have the bare minimum knowledge, but I want to expand that knowledge, but I'm sorry if I sound stupid.

@Gigasoft: I've corrected the error, but also you wrote public instead of global, and nasm doesn't understand it, I've changed it to global and assembled it to an .obj. I'll also post the .asm, and .obj files I've got from it. But now I also get errors from VS that aus_1 and aus_0 are unresolved external symbols... :? :shock:

I'm goint to test .text at the top. EDIT: If I put .text at the top of the .asm then I get an error from NASM: attempt to define a local label before any non-local labels.

Thanks.
Attachments
memsetaullshr.rar
The .obj and .asm files with _memset and __aullshr.
(547 Bytes) Downloaded 227 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 »

Ok, I just tested it and it's strange that NASM doesn't report an error but makes this output file instead. Anyway, add section .text - not just .text and it should work.
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,

Great I don't get any errors from VS, but when I test it I still get a stack fault, but it can't be my MEMEM function, because everything I pushed in that function, I pop afer it and store it all in memory, and if I, before calling the kernel, move bytes 0xEB and 0xFE (jmp $) to where the kernel is (supposed to be), the code stops excecuting, to accomplish that move I've got this code:

Code: Select all

TestImage:
mov esi,IMAGE_RMODE_BASE
mov ebx,[esi+60]
mov eax,[esi+ebx+40]
add eax,[esi+ebx+52]

mov byte[eax], 0xEB
inc eax
mov byte[eax], 0xFE
dec eax

call eax
cli
hlt
But when I comment it out, then I get the stack fault, the only thing where I can come up with is that eax doesn't contain the right address. And that seems to be the problem, because when I use this code:

Code: Select all

push eax
mov	eax, IMAGE_PMODE_BASE
mov byte[eax], 0xEB
inc eax
mov byte[eax], 0xFE
dec eax
pop eax
I also get a stack fault, so probably eax doesn't contain the kernel's entry point. When I just call IMAGE_PMODE_BASE (without the code's from above), then the CPU is disabled, and when I just call IMAGE_RMODE_BASE, I get the stack fault, so I don't know what the problem is :? . Do any of you know?


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
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

RGOS wrote:@Combuster: I'm trying to develop an OS just because I want to learn how it works, and the best way is if you run into trouble to ask.
The best way to learn is to do something yourself, not having it done for you...
And I do have the bare minimum knowledge
I have never seen you debug, and I see you make all sorts of beginner mistakes that indicate otherwise, and especially the last one where I couldn't write it off as something else.

Speaking of which, that's what Bochs' debugger is for - it allows you to debug your OS as if it were an userspace application. Basically, what you really need to do is to start verifying your assumptions. At the very least stop using a virtualizer - they have only one message for system crashes (which might or might not be the real cause).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
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, I do use Bochs debugger, but also when I try to use a floppy with the OS in a real system, it doesn't even boot (I've to fix that to, but a later time).
I've found out that eax contains 0xC0000430 before calling, and I think that can be right, because in VS I've stated that base-address must be 0xC0000000, but maybe I must change that to 0x100000 (IMAGE_PMODE_BASE), I'm going to try that now.

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
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

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

Post by neon »

Hello,

The address that you call to execute the kernel must always be a virtual address do to paging being enabled. (However it must also be mapped memory as well.) You can have VS output a linker map file to obtain the RVA address of the entry point. Compare that address to see if its the entry point.

*edit: You mentioned that you are getting stack faults. Use the bochs debugger and check the stack is still intact right before the stack fault occurs.. Last time I personally ran into that issue was do to stack corruption.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
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've debugged it, with base-address set to 0x100000 and I've found out that KERNEL.EXE is finaly called and excecuting, but there the OS crashes. But I think I'm going to check if I myself can find out whats going wrong, and if I can't find out, Ill post.
EDIT:@neon: I get a stack fault from VMWare, and as you stated it can be that that's not the problem, and I found out the KERNEL.EXE is already called so I'm chekking where the error occurs... I'll post if I know more. But how would you advice to check for a corrupted stack? It probably isn't the MEMEM function, because what I already mensioned is that changed to moving the info to memory.

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
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

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

Post by neon »

Hello,

Bochs debugger comes with an option to display the contents of the stack. Verify its contents before and after the stack fault occurs. You know whats on the stack so only you can tell if the contents of the stack are fine.

*edit: Also, Check to insure that the base address of your kernel (Check your project properties) is indeed 1MB. If its not, it will not work with you calling it as if its base was 1MB.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Locked