Commit 321fa2ee authored by Ian Seyler's avatar Ian Seyler

API cleanup

parent 527d2b46
#!/bin/sh
CC=${CROSS_COMPILE}gcc
CFLAGS="${CFLAGS} -Wall -Wextra -Werror -Wfatal-errors"
CFLAGS="${CFLAGS} -std=gnu11"
AR=${CROSS_COMPILE}ar
ARFLAGS=rcs
${CC} ${CFLAGS} -c libBareMetal.c -o libBareMetal.o
${AR} ${ARFLAGS} libBareMetal.a libBareMetal.o
#!/bin/sh
rm -f libBareMetal.o
rm -f libBareMetal.a
; =============================================================================
; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
; Copyright (C) 2008-2018 Return Infinity -- see LICENSE.TXT
;
; Version 1.0
; =============================================================================
b_input equ 0x0000000000100010 ; Scans keyboard for input. OUT: AL = 0 if no key pressed, otherwise ASCII code
b_output equ 0x0000000000100018 ; Displays a number of characters. IN: RSI = message location, RCX = number of characters
b_ethernet_tx equ 0x0000000000100020 ; Transmit a packet via Ethernet. IN: RSI = Memory location where data is stored, RDI = Pointer to 48 bit destination address, BX = Type of packet (If set to 0 then the EtherType will be set to the length of data), CX = Length of data
b_ethernet_rx equ 0x0000000000100028 ; Polls the Ethernet card for received data. IN: RDI = Memory location where packet will be stored. OUT: RCX = Length of packet
b_disk_read equ 0x0000000000100030 ; Read from the disk.
b_disk_write equ 0x0000000000100038 ; Write to the disk.
b_config equ 0x0000000000100040 ; View/modify configuration. IN: RCX = Function, RAX = Variable 1, RDX = Variable 2. OUT: RAX = Result
b_system equ 0x0000000000100048 ; Call a misc system function. IN: RCX = Function, RAX = Variable 1, RDX = Variable 2. Out: RAX = Result 1, RDX = Result 2
; Index for b_config calls
timecounter equ 0
networkcallback_get equ 3
networkcallback_set equ 4
clockcallback_get equ 5
clockcallback_set equ 6
mac equ 30
pci_read equ 0x40
pci_write equ 0x41
stdout_set equ 0x42
stdout_get equ 0x43
drive_id equ 0x50
; Index for b_system calls
smp_get_id equ 1
smp_lock equ 2
smp_unlock equ 3
debug_dump_mem equ 4
debug_dump_rax equ 5
get_argc equ 6
get_argv equ 7
; =============================================================================
; EOF
// =============================================================================
// BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
// Copyright (C) 2008-2018 Return Infinity -- see LICENSE.TXT
//
// Version 1.0
// =============================================================================
unsigned char b_input(void) {
unsigned char chr;
asm volatile ("call *0x00100010" : "=a" (chr));
return chr;
}
void b_output(const char *str, unsigned long nbr) {
asm volatile ("call *0x00100018" : : "S"(str), "c"(nbr));
}
void b_ethernet_tx(void *mem, unsigned long len, unsigned long iid) {
asm volatile ("call *0x00100020" : : "S"(mem), "c"(len), "d"(iid));
}
unsigned long b_ethernet_rx(void *mem, unsigned long iid) {
unsigned long tlong;
asm volatile ("call *0x00100028" : "=c"(tlong) : "D"(mem), "d"(iid));
return tlong;
}
unsigned long b_disk_read(void *mem, unsigned long start, unsigned long num, unsigned long disknum) {
unsigned long tlong;
asm volatile ("call *0x00100030" : "=c"(tlong) : "a"(start), "c"(num), "d"(disknum), "D"(mem));
return tlong;
}
unsigned long b_disk_write(void *mem, unsigned long start, unsigned long num, unsigned long disknum) {
unsigned long tlong = 0;
asm volatile ("call *0x00100038" : "=c"(tlong) : "a"(start), "c"(num), "d"(disknum), "S"(mem));
return tlong;
}
unsigned long b_config(unsigned long function, unsigned long var) {
unsigned long tlong;
asm volatile ("call *0x00100040" : "=a"(tlong) : "c"(function), "a"(var));
return tlong;
}
void b_system(unsigned long function, void* var1, void* var2) {
asm volatile ("call *0x00100048" : : "c"(function), "a"(var1), "d"(var2));
}
// =============================================================================
// EOF
// =============================================================================
// BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
// Copyright (C) 2008-2018 Return Infinity -- see LICENSE.TXT
//
// Version 1.0
// =============================================================================
#ifndef _LIBBAREMETAL_H
#define _LIBBAREMETAL_H
// Input/Output
unsigned char b_input(void);
void b_output(const char *str, unsigned long nbr);
// Network
void b_ethernet_tx(void *mem, unsigned long len, unsigned long iid);
unsigned long b_ethernet_rx(void *mem, unsigned long iid);
// Disk
unsigned long b_disk_read(void *mem, unsigned long start, unsigned long num, unsigned long disknum);
unsigned long b_disk_write(void *mem, unsigned long start, unsigned long num, unsigned long disknum);
// Misc
unsigned long b_config(unsigned long function, unsigned long var);
void b_system(unsigned long function, void *var1, void *var2);
// Index for b_system_config calls
#define TIMECOUNTER 0
#define NETWORKCALLBACK_GET 3
#define NETWORKCALLBACK_SET 4
#define CLOCKCALLBACK_GET 5
#define CLOCKCALLBACK_SET 6
#define MAC 30
#define PCI_READ 0x40
#define PCI_WRITE 0x41
#define STDOUT_SET 0x42
#define STDOUT_GET 0x43
#define DRIVE_ID 0x50
// Index for b_system_misc calls
#define SMP_GET_ID 1
#define SMP_LOCK 2
#define SMP_UNLOCK 3
#define DEBUG_DUMP_MEM 4
#define DEBUG_DUMP_RAX 5
#define DELAY 6
#define ETHERNET_STATUS 7
#define MEM_GET_FREE 8
#define SMP_NUMCORES 9
#define RESET 256
#endif
// =============================================================================
// EOF
#!/bin/sh
rm -rf api/
rm *.bin
#!/bin/sh
./clean.sh
mkdir api
cd api
git clone https://gitlab.com/ReturnInfinity/BareMetal.git
mv BareMetal/api/* .
rm -rf BareMetal/
cd ..
\ No newline at end of file
......@@ -6,7 +6,7 @@ ORG 0x001E0000
%include 'api/libBareMetal.asm'
start:
mov rcx, 10 ; API Code
mov rcx, smp_set ; API Code
mov rax, smp_task ; Code for CPU to run
xor edx, edx ; Start at ID 0
startloop:
......
......@@ -16,7 +16,7 @@ unsigned long outputlock = 0;
int main(void)
{
for (i=0; i<256; i++)
b_system(10, (void *)&smp_task, (void *)i);
b_system(SMP_SET, (void *)&smp_task, (void *)i);
smp_task();
return 0;
}
......
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