Commit b604ee6a authored by Ian Seyler's avatar Ian Seyler

Remove newlib support

parent 9a5faacd
MIT License
Copyright (c) 2018 Ian Seyler
Copyright (c) 2019 Ian Seyler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -7,11 +7,13 @@ This needs to be run on a Linux machine with root access - ideally on a network
This also runs on top of the BareMetal exokernel.
Goals
--------
Provide enough of a stack to serve a simple static webpage.
Building
--------
......@@ -19,16 +21,13 @@ Linux:
make
BareMetal (with newlib):
gcc -I PATH_TO_NEWLIB_HEADERS -c minIP.c -o minIP.o -DBAREMETAL
gcc -c -m64 -Wall -W -pedantic -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o libBareMetal.o libBareMetal.c
ld -T app.ld -o minIP.app crt0.o minIP.o libc.a libBareMetal.o
BareMetal:
BareMetal (standalone - it uses hardcoded IP addresses)
This version uses hardcoded IP addresses. Make sure to update them if needed in main().
./build.sh
Usage
--------
......@@ -36,14 +35,11 @@ Linux:
./minIP eth1 192.168.0.99 255.255.255.0 192.168.0.1
BareMetal (with newlib):
minIP.app en0 192.168.0.99 255.255.255.0 192.168.0.1
BareMetal (standalone - it uses hardcoded addresses, no arguments):
BareMetal:
minIP.app
Why
--------
......@@ -51,6 +47,7 @@ If this can be done in Python (see [teeceepee](https://github.com/jvns/teeceepee
Also, its a great proof of concept to learn the fundamentals in preparation for an x86-64 assembly re-write I plan on doing in the future.
What works
--------
......@@ -64,6 +61,7 @@ UDP | no
TCPv6 | no
UDPv6 | no
Todo
--------
- Resending dropped packets
......
#!/bin/sh
gcc -c -m64 -Wall -W -pedantic -std=c99 -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o minIP.o minIP.c -DBAREMETAL_STANDALONE
gcc -c -m64 -Wall -W -pedantic -std=c99 -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o minIP.o minIP.c -DBAREMETAL
gcc -c -m64 -Wall -W -pedantic -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o libBareMetal.o libBareMetal.c
objcopy --remove-section .comment minIP.o
objcopy --remove-section .eh_frame minIP.o
......
......@@ -4,25 +4,19 @@
// Linux compile: gcc minIP.c -o minIP
// Linux usage: ./minIP eth1 192.168.0.99 255.255.255.0 192.168.0.1
// BareMetal compile (with newlib):
// gcc -I newlib-2.4.0/newlib/libc/include/ -c minIP.c -o minIP.o -DBAREMETAL
// ld -T app.ld -o minIP.app crt0.o minIP.o libc.a libBareMetal.o
// BareMetal compile (standalone):
// ./build.sh
// BareMetal compile: ./build.sh
// BareMetal usage: minIP.app
#define __USE_MISC
/* Global Includes */
#if defined(BAREMETAL) || defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
#include "libBareMetal.h"
#endif
#if defined(BAREMETAL) || defined(LINUX)
#if defined(LINUX)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#if defined(LINUX)
#include <unistd.h>
#include <netinet/in.h>
#include <net/if.h>
......@@ -33,7 +27,7 @@
#endif
/* Typedefs */
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
......@@ -48,7 +42,7 @@ typedef uint64_t u64;
/* Global functions */
u16 checksum(u8* data, u16 bytes);
u16 checksum_tcp(u8* data, u16 bytes, u16 protocol, u16 length);
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
int net_init();
#else
int net_init(char *interface);
......@@ -58,7 +52,7 @@ int net_send(unsigned char* data, unsigned int bytes);
int net_recv(unsigned char* data);
u16 swap16(u16 in);
u32 swap32(u32 in);
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
void* memset( void* s, int c, int n );
void* memcpy( void* d, const void* s, int n );
int strlen( const char* s );
......@@ -197,13 +191,13 @@ const char webpage[] =
const char version_string[] = "minIP v0.6.0 (2018 07 05)\n";
/* Main code */
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
int main()
#else
int main(int argc, char *argv[])
#endif
{
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
b_output(version_string, (unsigned long)strlen(version_string));
src_IP[0] = 10;
src_IP[1] = 0;
......@@ -251,7 +245,7 @@ int main(int argc, char *argv[])
printf("SN: %u.%u.%u.%u\n", src_SN[0], src_SN[1], src_SN[2], src_SN[3]);
#endif
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
net_init();
#else
net_init(argv[1]); // Get us a socket that can handle raw Ethernet frames
......@@ -496,7 +490,7 @@ int main(int argc, char *argv[])
}
}
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
b_output("\n", 1);
#else
printf("\n");
......@@ -552,13 +546,13 @@ u16 checksum_tcp(u8* data, u16 bytes, u16 protocol, u16 length)
/* net_init - Initialize a raw socket */
#if defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
int net_init()
#else
int net_init(char *interface)
#endif
{
#if defined(BAREMETAL) || defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
/* Populate the MAC Address */
/* Pulls the MAC from the OS sys var table... so gross */
char * os_MAC = (void*)0x110050;
......@@ -640,7 +634,7 @@ int net_init(char *interface)
/* net_exit - Clean up and exit */
int net_exit()
{
#if !defined(BAREMETAL) && !defined(BAREMETAL_STANDALONE)
#if !defined(BAREMETAL)
close(s);
#endif
return 0;
......@@ -651,7 +645,7 @@ int net_exit()
// Returns number of bytes sent
int net_send(unsigned char* data, unsigned int bytes)
{
#if defined(BAREMETAL) || defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
b_ethernet_tx(data, bytes, 0);
return bytes;
#else
......@@ -665,7 +659,7 @@ int net_send(unsigned char* data, unsigned int bytes)
// Returns number of bytes read
int net_recv(unsigned char* data)
{
#if defined(BAREMETAL) || defined(BAREMETAL_STANDALONE)
#if defined(BAREMETAL)
return b_ethernet_rx(data, 0);
#else
return (recvfrom(s, data, ETH_FRAME_LEN, 0, 0, 0));
......@@ -690,7 +684,7 @@ u32 swap32(u32 in)
return out;
}
#ifdef BAREMETAL_STANDALONE
#ifdef BAREMETAL
void* memset( void* s, int c, int n )
{
char* _src;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment