LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-01-2009, 03:54 PM   #16
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106

The "disassembly" of your startup code (second stage after the loader) looks like this
Code:
		db  8Ch	; Œ
		db 0C8h	; 
		db  8Eh	; Ž
		db 0D0h	; 
		db  8Eh	; Ž
		db 0D8h	; 
		db 0E9h	; 
		db 0B6h	; 
		db  0Bh
At any time ten through twenty years ago, I could have looked at that and known what the instructions were without any noticeable effort. But I haven't worked on such things more recently and the above means little more to me than it does to most programmers.
Without that key part, it's hard to guess where you went wrong.

But I really doubt you wanted "small" memory model. I think you wanted "tiny" (use the -mt switch on the tcc line). I can see by the reference and definition of word_C5A in your disassembly that you have not ended up with "tiny" memory model, so getting the right value for DS and SS would be tricky.

In your other thread, I asked about the disassembly of a specific function, because your mixture of C and asm in that function was done in a way I didn't recognize. Your attachment above included that:
Code:
sub_425		proc near		; CODE XREF: seg000:0471p seg000:0ED0p ...

arg_0		= byte ptr  4

		push	bp
		mov	bp, sp
		mov	ah, 0Eh
		mov	al, [bp+arg_0]
		mov	bl, 0Fh
		int	10h		; - VIDEO - WRITE CHARACTER AND	ADVANCE	CURSOR (TTY WRITE)
					; AL = character, BH = display page (alpha modes)
					; BL = foreground color	(graphics modes)
		pop	bp
		retn
sub_425		endp
That function is correct, so that method of mixing C and asm must be OK. Of course we had already deduced by symptoms that function was working and the memory model is not consistent with the value in the DS register.

Last edited by johnsfine; 10-01-2009 at 04:04 PM.
 
Old 10-01-2009, 03:58 PM   #17
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
i ran it thru again:
Code:
 nop
seg000:02FB                 nop
seg000:02FC                 nop
seg000:02FD                 nop
seg000:02FE                 push    bp
seg000:02FF                 stosb
seg000:0300                 mov     ax, cs
seg000:0302                 mov     ss, ax
seg000:0304                 assume ss:nothing
seg000:0304                 mov     ds, ax
seg000:0306                 jmp     loc_EBF
you could actually know what the instructions were by looking at it?
are you the human disassembler?
 
Old 10-01-2009, 04:12 PM   #18
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Code:
seg000:0300                 mov     ax, cs
seg000:0302                 mov     ss, ax
seg000:0304                 mov     ds, ax
That is the right segment register initialization for tiny memory model. So when you change your tcc command to include the -mt switch, it might work. I'm still not sure whether the .com offset of 0x100 is properly considered everywhere, so that might also make data references wrong. But I think your results are closer to working they would be with a 0x100 offset error.

BTW, there is a very strange instruction
mov si, cs
after the code that displays "Hello world!" one character at a time. Is that from mixing in asm code or did the C compiler generate it? Anyway, I really don't think it is correct at that point.

Last edited by johnsfine; 10-01-2009 at 04:18 PM.
 
Old 10-01-2009, 04:21 PM   #19
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
ok i want it to print :
Code:
Hello World!
            Hey!
but its printing
Code:
Hello World!
            V.
the Hello World! is loaded into the registers directally as should be seen on the last
procedure in the disasm
btw are you the same johnsfine as the one that made the johnsfine bootloader?

Last edited by smeezekitty; 10-01-2009 at 04:22 PM. Reason: question mark
 
Old 10-01-2009, 04:25 PM   #20
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by smeezekitty View Post
btw are you the same johnsfine as the one that made the johnsfine bootloader?
Probably, but I don't remember! Do you have a URL?

I wrote several different bootloaders (long ago), but I don't recall which (if any) were made public on the internet.
 
Old 10-01-2009, 04:30 PM   #21
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
http://joelgompert.com/OS/lesson6.htm
btw i wrote this kernel without a tutoral
the mov si,cs was the compilers doing
 
Old 10-01-2009, 04:52 PM   #22
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by smeezekitty View Post
Now that I look at it, I remember it. I'm having trouble believing that was just ten years ago. It feels like longer. Maybe Joel M. Gompert changed the date when making other minor changes when reposting my code (but his tutorial is dated in 2001 and his copy of my code is dated 1999, so maybe it just feels like longer).
 
Old 10-01-2009, 05:00 PM   #23
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
i'm still confused
the data is at the end of the disassembly yet i just cant read it
also how do you get the address of and hook interrupt vectors without dos
 
Old 10-01-2009, 05:13 PM   #24
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by smeezekitty View Post
i'm still confused
the data is at the end of the disassembly yet i just cant read it
Because you aren't compiling with tiny memory model.

Quote:
how do you get the address of and hook interrupt vectors without dos
Interrupt vectors are at fixed and documented addresses at the beginning of memory. Read any x86 processor manual for all the specifics. You don't need dos.

If you want to hook them using C code, you need far pointers. I don't recall how you declare and use far pointers in Turbo C in small or tiny memory model. Maybe you can find that in the documentation.

If you know asm, then you can use asm code rather than C code to hook the interrupt vectors.

BTW, are you trying to write a 16 bit kernel? That's an odd choice.
If you want to write a 32 or 64 bit kernel, the 16 bit code loaded by the bootstrap shouldn't do much more than create the environment for the 32 or 64 bit code. That shouldn't involve hooking any interrupts in 16 bit mode. Interrupts vectors work a different way in 32 bit and 64 bit modes.

Last edited by johnsfine; 10-01-2009 at 05:17 PM.
 
Old 10-01-2009, 05:16 PM   #25
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
if i compile with -mt switch i get a linker error:
Undefine symbol DGROUP
 
Old 10-01-2009, 05:23 PM   #26
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by smeezekitty View Post
if i compile with -mt switch i get a linker error:
Undefine symbol DGROUP
Any idea where in your code you use DGROUP?

In tiny model, there is no reason to use DGROUP and it isn't normally defined. Since tcc can normally compile tiny model code, I assume there is something unusual in your code to make it need DGROUP.

Even if you wanted to stay with "small" memory model (which would require loading a different value into DS and SS than you code now loads) any reference to DGROUP in your code would still be wrong, because DGROUP requires the DOS .exe loader.

Apparently exetobin just ignores anything in the code that won't run right except in a .exe. Other methods of producing the .bin or .com give error messages for things like use of DGROUP that would make the resulting .com run incorrectly.

Last edited by johnsfine; 10-01-2009 at 05:25 PM.
 
Old 10-01-2009, 05:49 PM   #27
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
how do it remove the dgroup?
and yes this is a 16bit kernel i see no reason not to use 16bit as i want it to run
on really really old hardware
also the interrupt vector setting system did not work
Code:
void setvector(unsigned char inter, unsigned long ptr){
long far *p = 0;
p[inter] = ptr;
}
unsigned long getvector(unsigned char inter){
long far *p = 0;
return p[inter];
}
note: a long is 4 bytes in size in turbo C++
 
Old 10-01-2009, 05:54 PM   #28
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
this is thhe code generated by the compiler
with -mt switch
this:
Code:
kernel_print("Hey!");
turns to this
Code:
  mov     ax,offset DGROUP:s@+18
  push    ax
  call    near ptr @kernel_print$qpzc
  pop     cx
 
Old 10-01-2009, 05:59 PM   #29
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by smeezekitty View Post
how do it remove the dgroup?
"it" ??

Quote:
also the interrupt vector setting system did not work
How did you test it? I don't see the error. I think those routines would correctly set and get vectors.

Can you disassemble those two routines? Maybe Turbo C doesn't interpret "long far *" the way I would expect. I would see that in the asm code.

But more likely those routines are correct and you tested them incorrectly.

Quote:
note: a long is 4 bytes in size in turbo C++
Yes, but the value you want to use when hooking a vector typically isn't a long. You would need an interesting cast to convert that value to a long.
 
Old 10-01-2009, 06:08 PM   #30
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,227

Original Poster
Rep: Reputation: 170Reputation: 170
Quote:
"it" ??
i meant to say how do it keep it from generating the DGROUP?
as for the interrupts:
this is how it is used:
Code:
old_clock=(void interrupt (*)(...))getvector(0x1C);
setvector(0x1C, (unsigned long)clock_hook);
and the disasm of the functions:
Code:
   ;	
   ;	void setvector(unsigned char inter, unsigned long ptr){
   ;	
	assume	cs:_TEXT
@setvector$qucul	proc	near
	push	bp
	mov	bp,sp
	sub	sp,4
   ;	
   ;	long far *p = 0;
   ;	
	mov	word ptr [bp-2],0
	mov	word ptr [bp-4],0
   ;	
   ;	p[inter] = ptr;
   ;	
	mov	al,byte ptr [bp+4]
	mov	ah,0
	shl	ax,1
	shl	ax,1
	les	bx,dword ptr [bp-4]
	add	bx,ax
	mov	ax,word ptr [bp+8]
	mov	dx,word ptr [bp+6]
	mov	word ptr es:[bx+2],ax
	mov	word ptr es:[bx],dx
   ;	
   ;	}
   ;	
	mov	sp,bp
	pop	bp
	ret	
@setvector$qucul	endp
   ;	
   ;	unsigned long getvector(unsigned char inter){
   ;	
	assume	cs:_TEXT
@getvector$quc	proc	near
	push	bp
	mov	bp,sp
	sub	sp,4
   ;	
   ;	long far *p = 0;
   ;	
	mov	word ptr [bp-2],0
	mov	word ptr [bp-4],0
   ;	
   ;	return p[inter];
   ;	
	mov	al,byte ptr [bp+4]
	mov	ah,0
	shl	ax,1
	shl	ax,1
	les	bx,dword ptr [bp-4]
	add	bx,ax
	mov	dx,word ptr es:[bx+2]
	mov	ax,word ptr es:[bx]
	jmp	short @41@58
@41@58:
   ;	
   ;	}
   ;	
	mov	sp,bp
	pop	bp
	ret	
@getvector$quc	endp
 
  


Reply

Tags
asm, assembler, boot, data, find, kernel, loader


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
missing/lost data - where is it, how do I find it ????? bigjohn Linux - General 10 10-05-2008 02:34 PM
Reiserfs - how to find which file contains data in a block Vrajgh Linux - Software 8 09-14-2007 03:04 AM
Retrieving semi-formatted data: Kernel Panic (cannot find file or dir /dev/root) majorGrey Linux - General 2 09-05-2007 04:02 AM
Kernel Panic: Resume Machine: Unable to find suspended-data signature ( - mispelled? ToddM Linux - General 1 09-30-2004 10:59 AM
can't find data mcd Linux - Software 1 08-12-2003 12:12 AM


All times are GMT -5. The time now is 01:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration