Q. Writting directly to memory!

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.
Post Reply
q6z4k

Q. Writting directly to memory!

Post 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:

Code: Select all

mov ah, 0x66
mov 0xb80000, ah
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!
AR

Re:Q. Writting directly to memory!

Post 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.
q6z4k

Re:Q. Writting directly to memory!

Post 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!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Q. Writting directly to memory!

Post 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).
AxelDominatoR

Re:Q. Writting directly to memory!

Post by AxelDominatoR »

q6z4k wrote:

Code: Select all

mov ah, 0x66
mov 0xb80000, ah
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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Q. Writting directly to memory!

Post by Pype.Clicker »

AxelDominatoR wrote:
q6z4k wrote:

Code: Select all

mov ah, 0x66
mov 0xb80000, ah
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
CopperMan

Re:Q. Writting directly to memory!

Post 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;
}
kerim

Re:Q. Writting directly to memory!

Post 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.
Post Reply