Page 1 of 1
Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 5:13 am
by q6z4k
Hi!
I'm a real newbie, I wan't to create very primitive OS! I can't seem to get it how to output character by writing to memory in real mode. I did it like this:
But nothing happens! Whats wrong?
Is it posible to "mount" ethernet device into memory and then send some data packet? For example I wan't to send ARP packet, I just fill the buffer with this ethernet+ARP header:
Code: Select all
00 01 00 01 00 06 00 00 39 13 31 b6 00 00 08 06
00 01 08 00 06 04 00 01 00 00 39 13 31 b6 c3 7f
00 00 01 02 b3 dc 64 c4 7f 00 00 01
And send it! How can I "mount" network card into memory so I can send data!! Does different network cards have different hardware interupts? How can I control thous hardware interupts? Thank you!
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 5:19 am
by AR
In realmode segmentation only allows you to access chunks of memory that are 64KB in size, you have to move the segment around. In realmode you may as well use the BIOS for writing to the screen as it's just easier.
It is not possible to "mount" hardware, the hardware does not operate on the UNIX level of thinking, you have to detect the card on the PCI bus, determine it's IRQ, IO Ports and/or memory mapped registers then you need a driver that understands how to manipulate those 3 things to drive the card.
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 6:23 am
by q6z4k
Thank you!
Can you please show me how to write in real mode to memory! I know its not as easy as it would be with BIOS, but I want to get the basic idea how to do it, so I can later learn how to enter PMODE and then write to memory!
you have to detect the card on the PCI bus, determine it's IRQ, IO Ports and/or memory mapped registers then you need a driver that understands how to manipulate those 3 things to drive the card.
So is it posible to do this in real mode? But when I write to memory to output character I don't have to detect anything right? And do you know any very simle example how to do this three things? Thank you!
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 6:24 am
by Pype.Clicker
AR wrote:
It is not possible to "mount" hardware, the hardware does not operate on the UNIX level of thinking, you have to detect the card on the PCI bus, determine it's IRQ, IO Ports and/or memory mapped registers then you need a driver that understands how to manipulate those 3 things to drive the card.
i suggest you look at
the FAQ for a quick understanding of network cards (at least those for which we have enough information available).
What you call "mounting" in the hardware world is called "memory-mapped registers". Sometimes available, sometimes it's not (for instance, with the NE2000 network card, you need to send every byte of your packet through a "data port" to make it available to the card).
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 6:25 am
by AxelDominatoR
q6z4k wrote:
But nothing happens! Whats wrong?
First of all you're moving to 0xB80000 ... it's 0xB8000.
Remember that every character has two bytes. First is the char, second is the attributes. So to write your char you should write 0x66 to 0xB8000 and attributes at 0xB8001 ( for example 0x02 or 0x20 )
Axel
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 6:32 am
by Pype.Clicker
AxelDominatoR wrote:
q6z4k wrote:
But nothing happens! Whats wrong?
Ouch. i didn't notice it was even that bad. I suggest you got yourself a small book about assembler programming, or print and study the "Art of Assembly" (should be in the FAQ's links or in QuickLinkz)
what you want to do is
Code: Select all
mov al,0x66 ; the caracter
mov ah,7 ; grey-on-black
mov bx,0xb800 ; real mode segment
mov es,bx
mov [es:0],ax ; finally write to video memory at B800:0000 == B8000
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 9:29 am
by CopperMan
Case 1. If you're in real mode you need something like this
Code: Select all
/* C version */
#define MK_FP(s, o) (void far *)(((unsigned long)s << 16) | o)
putch( int row, int column, char c, char attr )
{
unsigned char far * vmem = MK_FP( 0xB800, 0 );
*(vmem + row*160 + column*2) = c;
*(vmem + row*160 + column*2 + 1) = attr;
}
Code: Select all
; ASM version
global _putch
_putch:
push es
mov ax, 0B800h
mov es, ax
mov bx, 160
mov ax, [sp + 4]
mul bx
mov bx, [sp + 6]
shl bx, 1
add bx, ax
mov al, [sp + 8]
mov ah, [sp + 10]
mov [es:bx], ax
pop es
ret
Case 2: if you're in Protected mode
Code: Select all
/* C version */
void putch( int row, int column, char c, char attr )
{
char * vmem = (char*)(0xB8000 + row*160 + column*2);
*vmem = c;
*(vmem + 1) = attr;
}
Re:Q. Writting directly to memory!
Posted: Wed Jul 06, 2005 11:57 pm
by kerim
Code: Select all
; using BIOS to display character
mov al, 0x40 ; ASCII code of the character
mov bl, 0x07 ; Text attribute
mov ah, 0x0E ; Teletype function
mov bh, 0x00 ; Page number
; Call the BIOS interrupt
int 0x10
Code: Select all
(* Pascal version *)
begin
mem[$b800:0000] := ord('H'); ; ASCII code
mem[$b800:0001] := 7; ; attribute
end.