mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-23 21:22:59 +01:00
stuff
This commit is contained in:
1 parent
96cd1ac97d
commit
6dfe517094
33 files changed
+9970
-3177
No files matched your search
+9
-5
@@ -5,13 +5,17 @@ int __cmp_ge(int a, int b) { return a >= b; }
|
||||
int __cmp_eq(int a, int b) { return a == b; }
|
||||
int __cmp_ne(int a, int b) { return a != b; }
|
||||
int __mul(int a, int b) {
|
||||
int result; result = 0;
|
||||
if (b > 0) b = -b;
|
||||
else a = -a;
|
||||
while (b < 0) { result = result + a; b++; }
|
||||
int result; int bit; result = 0; bit = 1;
|
||||
/* The guest uses wrapping 16-bit words. Each bit contributes its shifted
|
||||
multiplicand; the mask wraps to zero after exactly sixteen steps. */
|
||||
while (bit) {
|
||||
if (b & bit) result = result + a;
|
||||
a = a + a; bit = bit + bit;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int __divneg(int a, int b) {
|
||||
if(b == -1)return -a;
|
||||
int q; q = 0;
|
||||
while (a <= b) { a = a - b; q++; }
|
||||
return q;
|
||||
@@ -19,7 +23,7 @@ int __divneg(int a, int b) {
|
||||
int __div(int a, int b) {
|
||||
int negative; int q;
|
||||
if (b == 0) return 0;
|
||||
negative = (a < 0) != (b < 0);
|
||||
negative = (a ^ b) < 0;
|
||||
if (a > 0) a = -a;
|
||||
if (b > 0) b = -b;
|
||||
q = __divneg(a, b);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* bob32 arithmetic helpers. All results use native 32-bit wraparound. */
|
||||
int __cmp_lt(int a, int b) { return a < b; }
|
||||
int __cmp_gt(int a, int b) { return a > b; }
|
||||
int __cmp_le(int a, int b) { return a <= b; }
|
||||
int __cmp_ge(int a, int b) { return a >= b; }
|
||||
int __cmp_eq(int a, int b) { return a == b; }
|
||||
int __cmp_ne(int a, int b) { return a != b; }
|
||||
int __mul(int a, int b) {
|
||||
int result=0, bit=1, i=0;
|
||||
while(i<32) {
|
||||
if(b & bit) result=result+a;
|
||||
a=a+a; bit=bit+bit; i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int __u_lt(int a, int b) {
|
||||
if(a<0) { if(b>=0) return 0; }
|
||||
else if(b<0) return 1;
|
||||
return a<b;
|
||||
}
|
||||
int __u_gt(int a, int b) { return __u_lt(b,a); }
|
||||
int __u_le(int a, int b) { return !__u_lt(b,a); }
|
||||
int __u_ge(int a, int b) { return !__u_lt(a,b); }
|
||||
int __u_div(int a, int b) {
|
||||
int q=0, r=0, i=0, carry, bit;
|
||||
if(b==0) return 0;
|
||||
while(i<32) {
|
||||
carry=r<0; bit=a<0;
|
||||
r=r+r+bit; a=a+a; q=q+q;
|
||||
if(carry || !__u_lt(r,b)) { r=r-b; q++; }
|
||||
i++;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
int __u_mod(int a, int b) {
|
||||
if(b==0) return 0;
|
||||
return a-__mul(__u_div(a,b),b);
|
||||
}
|
||||
int __div(int a, int b) {
|
||||
int negative=(a<0)!=(b<0), ua, ub, q;
|
||||
if(b==0) return 0;
|
||||
ua=a<0?0-a:a; ub=b<0?0-b:b;
|
||||
q=__u_div(ua,ub);
|
||||
return negative?0-q:q;
|
||||
}
|
||||
int __mod(int a, int b) {
|
||||
int ua, ub, r;
|
||||
if(b==0) return 0;
|
||||
ua=a<0?0-a:a; ub=b<0?0-b:b;
|
||||
r=__u_mod(ua,ub);
|
||||
return a<0?0-r:r;
|
||||
}
|
||||
int __or(int a, int b) { return ~(~a & ~b); }
|
||||
int __xor(int a, int b) { return __or(a,b) & ~(a & b); }
|
||||
int __shl(int a, int b) {
|
||||
if(b<0 || b>31) return 0;
|
||||
while(b>0) { a=a+a; b--; }
|
||||
return a;
|
||||
}
|
||||
int __shr(int a, int b) {
|
||||
int low;
|
||||
if(b<0 || b>31) return 0;
|
||||
while(b>0) {
|
||||
low=a&1;
|
||||
if(a<0) a=-1073741824+((a&2147483647)-low)/2;
|
||||
else a=(a-low)/2;
|
||||
b--;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
int __u_shr(int a, int b) {
|
||||
if(b<0 || b>31) return 0;
|
||||
while(b>0) { a=__shr(a,1)&2147483647; b--; }
|
||||
return a;
|
||||
}
|
||||
+987
-173
File diff suppressed because it is too large.
Load diff
+26
-9
@@ -2,44 +2,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define EXE ".exe"
|
||||
#define BUILD_DIR "build\\"
|
||||
#define BOB_COMMAND "bob.exe"
|
||||
#define BOB32_COMMAND "bob32.exe"
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#define EXE ""
|
||||
#define BUILD_DIR "./build/"
|
||||
#define BOB_COMMAND "./bob"
|
||||
#define BOB32_COMMAND "./bob32"
|
||||
#endif
|
||||
|
||||
static void run(const char *command) {
|
||||
if(system(command)!=0){fprintf(stderr,"Build failed: %s\n",command);exit(1);}
|
||||
}
|
||||
int main(int argc,char **argv) {
|
||||
if(argc>2||(argc==2&&strcmp(argv[1],"--run")&&strcmp(argv[1],"--test"))) {
|
||||
fprintf(stderr,"Usage: build [--run | --test] (from repository root)\n");return 1;
|
||||
if(argc>2||(argc==2&&strcmp(argv[1],"--run")&&strcmp(argv[1],"--run32")&&strcmp(argv[1],"--test"))) {
|
||||
fprintf(stderr,"Usage: build [--run | --run32 | --test] (from repository root)\n");return 1;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
_mkdir("build");
|
||||
FILE *gcc=fopen("C:/msys64/ucrt64/bin/gcc.exe","rb");
|
||||
if(gcc){fclose(gcc);const char *path=getenv("PATH");size_t size=(path?strlen(path):0)+64;
|
||||
char *value=malloc(size);if(!value)return 1;snprintf(value,size,"C:/msys64/ucrt64/bin;%s",path?path:"");_putenv_s("PATH",value);free(value);}
|
||||
int directory_result=_mkdir("build");
|
||||
#else
|
||||
mkdir("build",0777);
|
||||
int directory_result=mkdir("build",0777);
|
||||
#endif
|
||||
if(directory_result && errno!=EEXIST){perror("build");return 1;}
|
||||
struct stat directory;
|
||||
if(stat("build",&directory)) {perror("build");return 1;}
|
||||
#ifdef _WIN32
|
||||
int is_directory=(directory.st_mode&_S_IFMT)==_S_IFDIR;
|
||||
#else
|
||||
int is_directory=S_ISDIR(directory.st_mode);
|
||||
#endif
|
||||
if(!is_directory){
|
||||
fprintf(stderr,"build must be a directory\n");return 1;
|
||||
}
|
||||
run("gcc -std=gnu11 -O2 -Wall -Wextra -Werror main.c -o bob" EXE);
|
||||
run("gcc -std=gnu11 -O2 -Wall -Wextra -Werror main.c -o bob32" EXE);
|
||||
run("gcc -std=c11 -O2 -Wall -Wextra -Werror tools/bobcc.c -o build/bobcc" EXE);
|
||||
run("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel kernel/kernel.c -o build/kernel.i");
|
||||
run(BUILD_DIR "bobcc" EXE " build/kernel.i kernel.basm build/kernel.b16");
|
||||
run("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -DBOBC_WIDE=1 -I kernel kernel/kernel.c -o build/kernel32.i");
|
||||
run(BUILD_DIR "bobcc" EXE " build/kernel32.i build/kernel32.basm build/kernel32.b32 --wide-kernel");
|
||||
if(argc==2&&!strcmp(argv[1],"--test")) {
|
||||
run("gcc -std=c11 -O2 -Wall -Wextra -Werror tests/test_cpu.c -o build/test_cpu" EXE);
|
||||
run(BUILD_DIR "test_cpu" EXE);
|
||||
run("gcc -std=c11 -O2 -Wall -Wextra -Werror tests/test_os.c -o build/test_os" EXE);
|
||||
run(BUILD_DIR "test_os" EXE);
|
||||
#ifdef _WIN32
|
||||
run("gcc -std=c11 -O2 -Wall -Wextra -Werror tests/test_console.c -o build/test_console.exe");
|
||||
run("build\\test_console.exe");
|
||||
#endif
|
||||
} else if(argc==2) run(BOB_COMMAND " --boot build/kernel.b16");
|
||||
} else if(argc==2&&!strcmp(argv[1],"--run32")) run(BOB32_COMMAND " --boot build/kernel32.b32");
|
||||
else if(argc==2) run(BOB_COMMAND " --boot build/kernel.b16");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Native 16-bit unsigned operations, expressed in the signed C foundation. */
|
||||
int __u_lt(int a, int b) {
|
||||
if (a < 0) { if (b >= 0) return 0; }
|
||||
else if (b < 0) return 1;
|
||||
return a < b;
|
||||
}
|
||||
int __u_gt(int a, int b) { return __u_lt(b, a); }
|
||||
int __u_le(int a, int b) { return !__u_lt(b, a); }
|
||||
int __u_ge(int a, int b) { return !__u_lt(a, b); }
|
||||
int __u_div(int a, int b) {
|
||||
int q = 0, r = 0, i = 0, carry, bit;
|
||||
if (b == 0) return 0;
|
||||
while (i < 16) {
|
||||
carry = r < 0; bit = a < 0;
|
||||
r = r + r + bit; a = a + a; q = q + q;
|
||||
if (carry || !__u_lt(r, b)) { r = r - b; q++; }
|
||||
i++;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
int __u_mod(int a, int b) { if (b == 0) return 0; return a - __mul(__u_div(a, b), b); }
|
||||
int __u_shr(int a, int b) {
|
||||
if (b < 0 || b > 15) return 0;
|
||||
while (b > 0) { a = __shr(a, 1) & 32767; b--; }
|
||||
return a;
|
||||
}
|
||||
Reference in new issue
Block a user