Networking in x86 Assembly (try not to laugh at me)

This is a discussion on Networking in x86 Assembly (try not to laugh at me) within the Networking/Device Communication forums, part of the General Programming Boards category; In addition to the many OS-specific version of my server program I'm developing, I've also decided to do a very ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Networking in x86 Assembly (try not to laugh at me)

    In addition to the many OS-specific version of my server program I'm developing, I've also decided to do a very simple Server OS. All is going better than I would've thought. I've written the bootstrap loader (though I'll want to redo it at the end, and upgrade to a better FS), and the kernel currently has a functioning shell.

    So far everything has been written in pure, x86 Assembly (NASM), but now I can start on the actual SERVER part of it. How the heck do I do networking at the ASM level?

    I apologize for not consulting Google. Actually I did consult Google, but got really irrelevant results.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    How the heck do I do networking at the ASM level?
    Well if you are creating an ASM program which runs on an OS like windows or Linux, then it is pretty easy. You would just call the winsock or BSD functions by pushing the parameters to the stack, then calling the appropriate function (the same way you would call any C function from ASM).

    If you are not running your ASM program on any OS, then it is quite a bit more complicated. First you would have to write a driver for whatever network card you are using. If you wanted to support different kinds of network cards, then you would have to write multiple drivers. You can look at the linux source code for network card drivers to get an idea on how to do this. The easiest way would be to just build them into your own kernel. The Tulip or Realtek 8139 cards are probably the most common, so they might be a good place to start.

    After you have written the driver, you still have to write code to implement the networking protocols (most notably TCP and UDP via IP). While UDP is fairly easy, TCP is actually kind of difficult. I've had to code the TCP protocol before, and it took me a solid week (and I never did quite finish the sliding window aspect of the protocol).

    Last of all there is the network stack (If you are familiar with the OSI layers, then you know what I'm talking about here). You need to get the data from the application layer to the transport layer, and vice versa.

    Good luck to you.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    bithub answered precisely what I was going to say. Hardware issues aside, you'll need to create your own protocol stack, and that will not be an easy feat (especially in assembly!), but if you decide to go at it, keep us informed of your progress. It'd be quite interesting.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I'm gonna have to go and change into a new pair of pants... and then start coding like crazy.

    if you decide to go at it, keep us informed of your progress. It'd be quite interesting.
    Will do. Thanks for the help!

    (In the words of Captain Jack Sparrow, "You need to get yourself a girl, mate").

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Exactly what I was going to say. You essentially need to create your own type of sockets system and then call those functions from your asm code. I see no reason though why this all could not be in C. My advice to you is get to C as fast as possible as it will help a lot in coding the rest of the OS. Only do the things in pure assembly that absolutely require pure assembly. For instance a bootstrap absolutely cannot be written in C and so that should be in assembly. As well when you load the kernel into memory this should be done in the 2nd or 3rd sector of your boot disk - jumped to and loaded by your bootstrap code.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    keep us informed
    Update: Yeah... not much has happened... I haven't given up though. I'm keeping it around to work on when I get frustrated with my other projects but still want to code something. Until I can find the source code for the Network drivers in Linux (little help, anyone) I'm just working on some of the c functions so I can write everything for the server but the networking part. I'll let you know when I reach the major milestones.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    The networking drivers will be in the drivers/net/ directory of your kernel source tree. This will most likely be located at /usr/src/linux/drivers/net/.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A good tutorial for x86 assembly?
    By cyberfish in forum Tech Board
    Replies: 3
    Last Post: 05-10-2009, 12:56 PM
  2. x86 assembly emulator
    By maxorator in forum Tech Board
    Replies: 5
    Last Post: 12-01-2008, 08:21 AM
  3. Arrays In Inline x86 Assembly
    By saxman in forum C Programming
    Replies: 17
    Last Post: 07-07-2004, 03:38 PM
  4. x86 assembly
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 02-18-2003, 02:29 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21