forked from dicksites/KUtrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It fixes dicksites#5
- Loading branch information
Showing
84 changed files
with
57,331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
The 3-Clause BSD License | ||
|
||
Copyright <YEAR> <COPYRIGHT HOLDER> | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This directory contains all the source files used in the book. | ||
The compile_all_user.sh script compiles everything. | ||
|
||
The kutrace_control.cc program is used to create traces, while other programs | ||
are used to postprocess those traces into HTML display files. The postproc3.sh | ||
script takes a tracefile stem (no ".trace") and produces the corresponding JSON | ||
and HTML files. | ||
|
||
Yet other programs are part of the book content or are used in the exercises. | ||
|
||
All the code is open sourced under the BSD three-clause license. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Little program to turn input strings into base40 values | ||
// Copyright 2021 Richard L. Sites | ||
// | ||
// compile with g++ -O2 base40.cc -o base40 | ||
// | ||
|
||
// Example output: | ||
#define BASE40_a 1 // "a" | ||
#define BASE40__a 79 // "/a" | ||
#define BASE40_cow 37403 // "cow" | ||
#define BASE40__cow 1496159 // "/cow" | ||
#define BASE40_zero 989026 // "zero" | ||
#define BASE40__zero 39561079 // "/zero" | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
typedef unsigned long int u64; | ||
|
||
// Uppercase mapped to lowercase | ||
// All unexpected characters mapped to '-' | ||
// - = 0x2D . = 0x2E / = 0x2F | ||
// Base40 characters are _abcdefghijklmnopqrstuvwxyz0123456789-./ | ||
// 0 1 2 3 | ||
// 0123456789012345678901234567890123456789 | ||
// where the first is NUL. | ||
static const char kToBase40[256] = { | ||
0,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,37,38,39, | ||
27,28,29,30, 31,32,33,34, 35,36,38,38, 38,38,38,38, | ||
|
||
38, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, 12,13,14,15, | ||
16,17,18,19, 20,21,22,23, 24,25,26,38, 38,38,38,38, | ||
38, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, 12,13,14,15, | ||
16,17,18,19, 20,21,22,23, 24,25,26,38, 38,38,38,38, | ||
|
||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
|
||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
38,38,38,38, 38,38,38,38, 38,38,38,38, 38,38,38,38, | ||
}; | ||
|
||
static const char kFromBase40[40] = { | ||
'\0','a','b','c', 'd','e','f','g', 'h','i','j','k', 'l','m','n','o', | ||
'p','q','r','s', 't','u','v','w', 'x','y','z','0', '1','2','3','4', | ||
'5','6','7','8', '9','-','.','/', | ||
}; | ||
|
||
// Unpack six characters from 32 bits. | ||
// str must be 8 bytes. We somewhat-arbitrarily capitalize the first letter | ||
char* Base40ToChar(u64 base40, char* str) { | ||
base40 &= 0x00000000fffffffflu; // Just low 32 bits | ||
memset(str, 0, 8); | ||
bool first_letter = true; | ||
// First character went in last, comes out first | ||
int i = 0; | ||
while (base40 > 0) { | ||
u64 n40 = base40 % 40; | ||
str[i] = kFromBase40[n40]; | ||
base40 /= 40; | ||
if (first_letter && (1 <= n40) && (n40 <= 26)) { | ||
str[i] &= ~0x20; // Uppercase it | ||
first_letter = false; | ||
} | ||
++i; | ||
} | ||
return str; | ||
} | ||
|
||
// Pack six characters into 32 bits. Only use a-zA-Z0-9.-/ | ||
u64 CharToBase40(const char* str) { | ||
int len = strlen(str); | ||
// If longer than 6 characters, take only the first 6 | ||
if (len > 6) {len = 6;} | ||
u64 base40 = 0; | ||
// First character goes in last, comes out first | ||
for (int i = len - 1; i >= 0; -- i) { | ||
base40 = (base40 * 40) + kToBase40[str[i]]; | ||
} | ||
return base40; | ||
} | ||
|
||
|
||
|
||
static const int kBuffersize = 128; | ||
// Allowed in C variable names; others replaced with underscore | ||
static const char* kAllowed = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
|
||
int main (int argc, const char** argv) { | ||
char buffer[kBuffersize]; | ||
char buffer2[kBuffersize]; | ||
while (fgets(buffer, kBuffersize, stdin) != NULL) { | ||
if (buffer[strlen(buffer) - 1] == '\n') {buffer[strlen(buffer) - 1] = '\0';} | ||
if (buffer[strlen(buffer) - 1] == '\r') {buffer[strlen(buffer) - 1] = '\0';} | ||
for (int i = 0; i < strlen(buffer); ++i) { | ||
buffer2[i] = (strchr(kAllowed, buffer[i]) != NULL) ? buffer[i] : '_'; | ||
} | ||
buffer2[strlen(buffer)] = '\0'; | ||
//printf("%ld // %s\n", CharToBase40(buffer), buffer); | ||
printf("#define BASE40_%s %ld\t// \"%s\"\n", buffer2, CharToBase40(buffer), buffer); | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Base types to use thoughout class | ||
// Copyright 2021 Richard L. Sites | ||
|
||
#ifndef __BASETYPES_H__ | ||
#define __BASETYPES_H__ | ||
|
||
#include <stdint.h> | ||
|
||
typedef int8_t int8; | ||
typedef uint8_t uint8; | ||
typedef int16_t int16; | ||
typedef uint16_t uint16; | ||
typedef int32_t int32; | ||
typedef uint32_t uint32; | ||
|
||
#ifdef __ARM_ARCH_ISA_ARM | ||
|
||
typedef long long int int64; | ||
typedef long long unsigned int uint64; | ||
#define FUINTPTRX "%08lx" | ||
#define FLX "%016llx" | ||
#define FLD "%lld" | ||
#define CL(x) x##LL | ||
#define CLU(x) x##LLU | ||
|
||
#elif defined(__aarch64__) | ||
typedef long long int int64; | ||
typedef long long unsigned int uint64; | ||
#define FUINTPTRX "%016lx" | ||
#define FLX "%016llx" | ||
#define FLD "%lld" | ||
#define CL(x) x##LL | ||
#define CLU(x) x##LLU | ||
|
||
#elif defined(__x86_64) | ||
/* make almost the same as ARM-32 */ | ||
typedef long long int int64; | ||
typedef long long unsigned int uint64; | ||
#define FUINTPTRX "%016lx" | ||
#define FLX "%016llx" | ||
#define FLD "%lld" | ||
#define CL(x) x##LL | ||
#define CLU(x) x##LLU | ||
|
||
#elif 0 | ||
/* actual 64-bit types */ | ||
typedef long int int64; | ||
typedef long unsigned int uint64; | ||
#define FUINTPTRX "%016lx" | ||
#define FLX "%016lx" | ||
#define FLD "%ld" | ||
#define CL(x) x##L | ||
#define CLU(x) x##LU | ||
|
||
#else | ||
#error Need type defines for your architecture | ||
#endif | ||
|
||
#endif // __BASETYPES_H__ |
Oops, something went wrong.