CS350 COS
COS
Loading...
Searching...
No Matches
kdebug.h File Reference

Go to the source code of this file.

Data Structures

struct  DebugCommand
 

Macros

#define REGISTER_DBGCMD(_NAME, _DESC, _FUNC)
 

Typedefs

typedef struct DebugCommand DebugCommand
 

Functions

void Debug_PrintHex (const char *data, size_t length, off_t off, size_t limit)
 
uintptr_t db_disasm (uintptr_t loc, bool altfmt)
 
void Debug_Prompt ()
 
uint64_t Debug_GetValue (uintptr_t addr, int size, bool isSigned)
 
void Debug_PrintSymbol (uintptr_t off, int strategy)
 
uint64_t Debug_StrToInt (const char *s)
 
uint64_t Debug_SymbolToInt (const char *s)
 

Macro Definition Documentation

◆ REGISTER_DBGCMD

#define REGISTER_DBGCMD (   _NAME,
  _DESC,
  _FUNC 
)
Value:
__attribute__((section(".kdbgcmd"))) \
DebugCommand cmd_##_NAME = { #_NAME, _DESC, _FUNC }
struct multiboot_mod_list __attribute__

Definition at line 11 of file kdebug.h.

Typedef Documentation

◆ DebugCommand

typedef struct DebugCommand DebugCommand

Function Documentation

◆ db_disasm()

uintptr_t db_disasm ( uintptr_t  loc,
bool  altfmt 
)

Definition at line 1186 of file disasm.c.

1187{
1188 int inst;
1189 int size;
1190 int short_addr;
1191 const char * seg;
1192 const struct inst * ip;
1193 const char * i_name;
1194 int i_size;
1195 int i_mode;
1196 int rex = 0;
1197 int regmodrm = 0;
1198 bool first;
1199 int displ;
1200 int prefix;
1201 int rep;
1202 int imm;
1203 int imm2;
1204 long imm64;
1205 int len;
1206 struct i_addr address;
1207
1208 get_value_inc(inst, loc, 1, FALSE);
1209 short_addr = FALSE;
1210 size = LONG;
1211 seg = 0;
1212
1213 /*
1214 * Get prefixes
1215 */
1216 rep = FALSE;
1217 prefix = TRUE;
1218 do {
1219 switch (inst) {
1220 case 0x66: /* data16 */
1221 size = WORD;
1222 break;
1223 case 0x67:
1224 short_addr = TRUE;
1225 break;
1226 case 0x26:
1227 seg = "%es";
1228 break;
1229 case 0x36:
1230 seg = "%ss";
1231 break;
1232 case 0x2e:
1233 seg = "%cs";
1234 break;
1235 case 0x3e:
1236 seg = "%ds";
1237 break;
1238 case 0x64:
1239 seg = "%fs";
1240 break;
1241 case 0x65:
1242 seg = "%gs";
1243 break;
1244 case 0xf0:
1245 kprintf("lock ");
1246 break;
1247 case 0xf2:
1248 kprintf("repne ");
1249 break;
1250 case 0xf3:
1251 rep = TRUE;
1252 break;
1253 default:
1254 prefix = FALSE;
1255 break;
1256 }
1257 if (inst >= 0x40 && inst < 0x50) {
1258 rex = inst;
1259 prefix = TRUE;
1260 }
1261 if (prefix) {
1262 get_value_inc(inst, loc, 1, FALSE);
1263 }
1264 } while (prefix);
1265
1266 if (inst >= 0xd8 && inst <= 0xdf) {
1267 loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
1268 kprintf("\n");
1269 return (loc);
1270 }
1271
1272 ip = &db_inst_table[inst];
1273 while (ip->i_size == ESC) {
1274 get_value_inc(inst, loc, 1, FALSE);
1275 ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
1276 if (ip == 0) {
1277 ip = &db_bad_inst;
1278 }
1279 else {
1280 ip = &ip[inst&0xf];
1281 }
1282 }
1283
1284 if (ip->i_has_modrm) {
1285 get_value_inc(regmodrm, loc, 1, FALSE);
1286 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1287 }
1288
1289 i_name = ip->i_name;
1290 i_size = ip->i_size;
1291 i_mode = ip->i_mode;
1292
1293 if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1294 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1295 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1296 ip->i_extra == db_Grp15) {
1297 i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
1298 }
1299 else if (ip->i_extra == db_Grp3) {
1300 ip = ip->i_extra;
1301 ip = &ip[f_reg(rex, regmodrm)];
1302 i_name = ip->i_name;
1303 i_mode = ip->i_mode;
1304 }
1305 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1306 ip = ip->i_extra;
1307 ip = &ip[f_reg(rex, regmodrm)];
1308 i_name = ip->i_name;
1309 i_mode = ip->i_mode;
1310 i_size = ip->i_size;
1311 }
1312
1313 /* Special cases that don't fit well in the tables. */
1314 if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1315 switch (regmodrm) {
1316 case 0xc1:
1317 i_name = "vmcall";
1318 i_size = NONE;
1319 i_mode = 0;
1320 break;
1321 case 0xc2:
1322 i_name = "vmlaunch";
1323 i_size = NONE;
1324 i_mode = 0;
1325 break;
1326 case 0xc3:
1327 i_name = "vmresume";
1328 i_size = NONE;
1329 i_mode = 0;
1330 break;
1331 case 0xc4:
1332 i_name = "vmxoff";
1333 i_size = NONE;
1334 i_mode = 0;
1335 break;
1336 case 0xc8:
1337 i_name = "monitor";
1338 i_size = NONE;
1339 i_mode = 0;
1340 break;
1341 case 0xc9:
1342 i_name = "mwait";
1343 i_size = NONE;
1344 i_mode = 0;
1345 break;
1346 case 0xd0:
1347 i_name = "xgetbv";
1348 i_size = NONE;
1349 i_mode = 0;
1350 break;
1351 case 0xd1:
1352 i_name = "xsetbv";
1353 i_size = NONE;
1354 i_mode = 0;
1355 break;
1356 case 0xf8:
1357 i_name = "swapgs";
1358 i_size = NONE;
1359 i_mode = 0;
1360 break;
1361 case 0xf9:
1362 i_name = "rdtscp";
1363 i_size = NONE;
1364 i_mode = 0;
1365 break;
1366 }
1367 }
1368 if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1369 i_name = db_Grp15b[f_reg(rex, regmodrm)];
1370 i_size = NONE;
1371 i_mode = 0;
1372 }
1373
1374 /* Handle instructions identified by mandatory prefixes. */
1375 if (rep == TRUE) {
1376 if (inst == 0x90) {
1377 i_name = "pause";
1378 i_size = NONE;
1379 i_mode = 0;
1380 rep = FALSE;
1381 } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1382 f_reg(rex, regmodrm) == 0x6) {
1383 i_name = "vmxon";
1384 rep = FALSE;
1385 }
1386 }
1387 if (size == WORD) {
1388 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1389 f_reg(rex, regmodrm) == 0x6) {
1390 i_name = "vmclear";
1391 }
1392 }
1393 if (rex & REX_W) {
1394 if (strcmp(i_name, "cwde") == 0)
1395 i_name = "cdqe";
1396 else if (strcmp(i_name, "cmpxchg8b") == 0)
1397 i_name = "cmpxchg16b";
1398 }
1399
1400 if (rep == TRUE)
1401 kprintf("repe "); /* XXX repe VS rep */
1402
1403 if (i_size == SDEP) {
1404 if (size == LONG)
1405 kprintf("%s", i_name);
1406 else
1407 kprintf("%s", (const char *)ip->i_extra);
1408 } else if (i_size == ADEP) {
1409 if (short_addr == FALSE)
1410 kprintf("%s", i_name);
1411 else
1412 kprintf("%s", (const char *)ip->i_extra);
1413 }
1414 else {
1415 kprintf("%s", i_name);
1416 if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1417 i_size = NONE;
1418 kprintf("q");
1419 }
1420 if (i_size != NONE) {
1421 if (i_size == BYTE) {
1422 kprintf("b");
1423 size = BYTE;
1424 }
1425 else if (i_size == WORD) {
1426 kprintf("w");
1427 size = WORD;
1428 }
1429 else if (size == WORD)
1430 kprintf("w");
1431 else {
1432 if (rex & REX_W)
1433 kprintf("q");
1434 else
1435 kprintf("l");
1436 }
1437 }
1438 }
1439 kprintf("\t");
1440 for (first = TRUE;
1441 i_mode != 0;
1442 i_mode >>= 8, first = FALSE)
1443 {
1444 if (!first)
1445 kprintf(",");
1446
1447 switch (i_mode & 0xFF) {
1448
1449 case E:
1450 db_print_address(seg, size, rex, &address);
1451 break;
1452
1453 case Eind:
1454 kprintf("*");
1455 db_print_address(seg, size, rex, &address);
1456 break;
1457
1458 case El:
1459 db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
1460 break;
1461
1462 case EL:
1463 db_print_address(seg, LONG, 0, &address);
1464 break;
1465
1466 case Ew:
1467 db_print_address(seg, WORD, rex, &address);
1468 break;
1469
1470 case Eb:
1471 db_print_address(seg, BYTE, rex, &address);
1472 break;
1473
1474 case R:
1475 kprintf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
1476 break;
1477
1478 case Rw:
1479 kprintf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
1480 break;
1481
1482 case Rq:
1483 kprintf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1484 break;
1485
1486 case Ri:
1487 kprintf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
1488 break;
1489
1490 case Ril:
1491 kprintf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
1492 break;
1493
1494 case S:
1495 kprintf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
1496 break;
1497
1498 case Si:
1499 kprintf("%s", db_seg_reg[f_reg(rex, inst)]);
1500 break;
1501
1502 case A:
1503 kprintf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
1504 break;
1505
1506 case BX:
1507 if (seg)
1508 kprintf("%s:", seg);
1509 kprintf("(%s)", short_addr ? "%bx" : "%ebx");
1510 break;
1511
1512 case CL:
1513 kprintf("%%cl");
1514 break;
1515
1516 case DX:
1517 kprintf("%%dx");
1518 break;
1519
1520 case SI:
1521 if (seg)
1522 kprintf("%s:", seg);
1523 kprintf("(%s)", short_addr ? "%si" : "%rsi");
1524 break;
1525
1526 case DI:
1527 kprintf("%%es:(%s)", short_addr ? "%di" : "%rdi");
1528 break;
1529
1530 case CR:
1531 kprintf("%%cr%d", f_reg(rex, regmodrm));
1532 break;
1533
1534 case DR:
1535 kprintf("%%dr%d", f_reg(rex, regmodrm));
1536 break;
1537
1538 case TR:
1539 kprintf("%%tr%d", f_reg(rex, regmodrm));
1540 break;
1541
1542 case I:
1543 len = db_lengths[size];
1544 get_value_inc(imm, loc, len, FALSE);
1545 kprintf("$%d", imm);
1546 break;
1547
1548 case Is:
1549 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1550 get_value_inc(imm, loc, len, FALSE);
1551 kprintf("$%d", imm);
1552 break;
1553
1554 case Ib:
1555 get_value_inc(imm, loc, 1, FALSE);
1556 kprintf("$%d", imm);
1557 break;
1558
1559 case Iba:
1560 get_value_inc(imm, loc, 1, FALSE);
1561 if (imm != 0x0a)
1562 kprintf("$%d", imm);
1563 break;
1564
1565 case Ibs:
1566 get_value_inc(imm, loc, 1, TRUE);
1567 if (size == WORD)
1568 imm &= 0xFFFF;
1569 kprintf("$%d", imm);
1570 break;
1571
1572 case Iw:
1573 get_value_inc(imm, loc, 2, FALSE);
1574 kprintf("$%d", imm);
1575 break;
1576
1577 case Ilq:
1578 len = db_lengths[rex & REX_W ? QUAD : LONG];
1579 get_value_inc(imm64, loc, len, FALSE);
1580 kprintf("$%#lr", imm64);
1581 break;
1582
1583 case O:
1584 len = (short_addr ? 2 : 4);
1585 get_value_inc(displ, loc, len, FALSE);
1586 if (seg)
1587 kprintf("%s:%d",seg, displ);
1588 else
1590 break;
1591
1592 case Db:
1593 get_value_inc(displ, loc, 1, TRUE);
1594 displ += loc;
1595 if (size == WORD)
1596 displ &= 0xFFFF;
1598 break;
1599
1600 case Dl:
1601 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1602 get_value_inc(displ, loc, len, FALSE);
1603 displ += loc;
1604 if (size == WORD)
1605 displ &= 0xFFFF;
1607 break;
1608
1609 case o1:
1610 kprintf("$1");
1611 break;
1612
1613 case o3:
1614 kprintf("$3");
1615 break;
1616
1617 case OS:
1618 len = db_lengths[size];
1619 get_value_inc(imm, loc, len, FALSE); /* offset */
1620 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1621 kprintf("$%d,%d", imm2, imm);
1622 break;
1623 }
1624 }
1625 kprintf("\n");
1626 return (loc);
1627}
#define E
Definition: disasm.c:74
#define Iw
Definition: disasm.c:97
#define BX
Definition: disasm.c:85
#define ADEP
Definition: disasm.c:58
#define Ib
Definition: disasm.c:95
static const char *const db_Grp1[]
Definition: disasm.c:583
#define REX_R
Definition: disasm.c:67
#define Is
Definition: disasm.c:94
static const char *const db_reg[2][4][16]
Definition: disasm.c:949
#define OS
Definition: disasm.c:104
#define DR
Definition: disasm.c:91
#define O
Definition: disasm.c:99
#define DX
Definition: disasm.c:87
int i_mode
Definition: disasm.c:118
static const struct inst db_Grp4[]
Definition: disasm.c:616
static void db_print_address(const char *seg, int size, int rex, struct i_addr *addrp)
Definition: disasm.c:1067
static uintptr_t db_disasm_esc(uintptr_t loc, int inst, int rex, int short_addr, int size, const char *seg)
Definition: disasm.c:1095
static const char *const db_Grp15[]
Definition: disasm.c:217
#define ESC
Definition: disasm.c:59
#define WORD
Definition: disasm.c:51
#define TR
Definition: disasm.c:92
#define Db
Definition: disasm.c:100
static const struct inst db_inst_table[256]
Definition: disasm.c:638
short i_size
Definition: disasm.c:117
static const char *const db_Grp7[]
Definition: disasm.c:184
#define Ibs
Definition: disasm.c:96
#define R
Definition: disasm.c:78
static const struct inst db_Grp5[]
Definition: disasm.c:627
static const char *const db_Grp15b[]
Definition: disasm.c:228
#define I
Definition: disasm.c:93
#define NONE
Definition: disasm.c:60
static const char *const db_Grp2[]
Definition: disasm.c:594
#define SDEP
Definition: disasm.c:57
#define f_rm(rex, byte)
Definition: disasm.c:935
#define Eb
Definition: disasm.c:77
#define DB_STGY_ANY
Definition: disasm.c:41
#define Ew
Definition: disasm.c:76
#define El
Definition: disasm.c:109
#define Ilq
Definition: disasm.c:98
#define EL
Definition: disasm.c:112
#define REX_W
Definition: disasm.c:68
#define Dl
Definition: disasm.c:101
static const char *const db_Grp8[]
Definition: disasm.c:195
const void * i_extra
Definition: disasm.c:119
#define Si
Definition: disasm.c:83
#define Eind
Definition: disasm.c:75
#define CR
Definition: disasm.c:90
#define Ri
Definition: disasm.c:81
#define CL
Definition: disasm.c:86
#define DB_STGY_XTRN
Definition: disasm.c:42
short i_has_modrm
Definition: disasm.c:116
#define A
Definition: disasm.c:84
#define Rw
Definition: disasm.c:79
#define Ril
Definition: disasm.c:110
#define f_reg(rex, byte)
Definition: disasm.c:934
#define SI
Definition: disasm.c:88
#define f_mod(rex, byte)
Definition: disasm.c:933
#define get_value_inc(result, loc, size, is_signed)
Definition: disasm.c:987
#define o3
Definition: disasm.c:103
#define TRUE
Definition: disasm.c:44
#define FALSE
Definition: disasm.c:45
static uintptr_t db_read_address(uintptr_t loc, int short_addr, int rex, int regmodrm, struct i_addr *addrp)
Definition: disasm.c:1004
static const int db_lengths[]
Definition: disasm.c:977
#define QUAD
Definition: disasm.c:53
const char * i_name
Definition: disasm.c:115
#define LONG
Definition: disasm.c:52
#define DI
Definition: disasm.c:89
#define Rq
Definition: disasm.c:80
static const char *const db_seg_reg[8]
Definition: disasm.c:970
static const struct inst db_Grp3[]
Definition: disasm.c:605
static const char *const db_Grp6[]
Definition: disasm.c:173
#define o1
Definition: disasm.c:102
static const char *const db_Grp9[]
Definition: disasm.c:206
#define BYTE
Definition: disasm.c:50
#define Iba
Definition: disasm.c:111
static const struct inst db_bad_inst
Definition: disasm.c:929
#define S
Definition: disasm.c:82
Definition: disasm.c:941
Definition: disasm.c:114
int kprintf(const char *fmt,...)
Definition: printf.c:210
void Debug_PrintSymbol(uintptr_t off, int strategy)
Definition: debug.c:118
uint32_t size
Definition: multiboot.h:0
uint64_t len
Definition: multiboot.h:2
int strcmp(const char *s1, const char *s2)
Definition: string.c:81
uint64_t uintptr_t
Definition: types.h:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_GetValue()

uint64_t Debug_GetValue ( uintptr_t  addr,
int  size,
bool  isSigned 
)

Definition at line 81 of file debug.c.

82{
83 switch (size)
84 {
85 case 1: {
86 uint8_t *val = (uint8_t *)addr;
87 if (isSigned && ((*val & 0x80) == 0x80)) {
88 return (uint64_t)*val | 0xFFFFFFFFFFFFFF00ULL;
89 }
90 return *val;
91 }
92 case 2: {
93 uint16_t *val = (uint16_t *)addr;
94 if (isSigned && ((*val & 0x8000) == 0x8000)) {
95 return (uint64_t)*val | 0xFFFFFFFFFFFF0000ULL;
96 }
97 return *val;
98 }
99 case 4: {
100 uint32_t *val = (uint32_t *)addr;
101 if (isSigned && ((*val & 0x80000000) == 0x80000000)) {
102 return (uint64_t)*val | 0xFFFFFFFF00000000ULL;
103 }
104 return *val;
105 }
106 case 8: {
107 uint64_t *val = (uint64_t *)addr;
108 return *val;
109 }
110 default: {
111 kprintf("Debug_GetValue: Unknown size parameter '%d'\n", size);
112 return (uint64_t)-1;
113 }
114 }
115}
uint64_t addr
Definition: multiboot.h:1
unsigned short uint16_t
Definition: types.h:11
unsigned int uint32_t
Definition: types.h:12
unsigned long uint64_t
Definition: types.h:13
unsigned char uint8_t
Definition: types.h:10
Here is the call graph for this function:

◆ Debug_PrintHex()

void Debug_PrintHex ( const char *  data,
size_t  length,
off_t  off,
size_t  limit 
)

Definition at line 30 of file debug.c.

31{
32 const size_t row_size = 16;
33 bool stop = false;
34
35 size_t row;
36 for (row = 0; !stop; row++) {
37 size_t ix = row * row_size;
38 if (ix >= limit || ix >= length)
39 return;
40
41 kprintf("%08lx ", (uintptr_t)data+ix);
42 size_t col;
43 for (col = 0; col < row_size; col++) {
44 size_t ixc = ix + col;
45 if ((limit != 0 && ixc >= limit) || ixc >= length) {
46 stop = true;
47 for (; col < row_size; col++) {
48 kprintf(" ");
49 }
50 break;
51 }
52 ixc += off;
53
54 kprintf("%02X ", (unsigned char)data[ixc]);
55 }
56 kprintf(" |");
57
58 for (col = 0; col < row_size; col++) {
59 size_t ixc = ix + col;
60 if ((limit != 0 && ixc >= limit) || ixc >= length) {
61 stop = true;
62 for (; col < row_size; col++) {
63 kprintf(" ");
64 }
65 break;
66 }
67 ixc += off;
68
69 unsigned char c = (unsigned char)data[ixc];
70 if (c >= 0x20 && c < 0x7F)
71 kprintf("%c", c);
72 else
73 kprintf(".");
74 }
75 kprintf("|");
76 kprintf("\n");
77 }
78}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_PrintSymbol()

void Debug_PrintSymbol ( uintptr_t  off,
int  strategy 
)

Definition at line 118 of file debug.c.

119{
120 kprintf("0x%llx", off);
121}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_Prompt()

void Debug_Prompt ( )

Definition at line 248 of file debug.c.

249{
250 int argc;
251 char *argv[DEBUG_MAX_ARGS];
252 char *nextArg, *last;
253 char buf[DEBUG_MAX_LINE];
254
255 kprintf("Entered Debugger!\n");
256
257 /*
258 * DebugCommand must be 128 bytes for the Section array to align properly
259 */
260 ASSERT(sizeof(DebugCommand) == 128);
261
262 while (1) {
263 kprintf("kdbg> ");
264
265 // read input
267
268 // parse input
269 nextArg = strtok_r(buf, " \t\r\n", &last);
270 for (argc = 0; argc < DEBUG_MAX_ARGS; argc++) {
271 if (nextArg == NULL)
272 break;
273
274 argv[argc] = nextArg;
275 nextArg = strtok_r(NULL, " \t\r\n", &last);
276 }
277
278 if (strcmp(argv[0], "continue") == 0) {
279 return; // Continue
280 } else {
281 // execute command
282 int i;
284 commands /= sizeof(DebugCommand);
286 bool found = false;
287
288 for (i = 0; i < commands; i++)
289 {
290 if (strcmp(argv[0], cmds[i].name) == 0)
291 {
292 cmds[i].func(argc, (const char **)argv);
293 found = true;
294 }
295 }
296
297 if (strcmp(argv[0], "") == 0)
298 continue;
299
300 if (!found)
301 kprintf("Unknown command '%s'\n", argv[0]);
302 }
303 }
304}
void Console_Gets(char *str, size_t n)
Definition: console.c:88
static char buf[4096]
Definition: ethdump.c:10
#define ASSERT(_x)
Definition: kassert.h:8
DebugCommand __kdbgcmd_end[]
#define DEBUG_MAX_ARGS
Definition: debug.c:27
DebugCommand __kdbgcmd_start[]
#define DEBUG_MAX_LINE
Definition: debug.c:26
#define NULL
Definition: stddef.h:6
char * strtok_r(char *str, const char *delim, char **last)
Definition: string.c:122
void(* func)(int, const char **)
Definition: kdebug.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_StrToInt()

uint64_t Debug_StrToInt ( const char *  s)

Definition at line 124 of file debug.c.

125{
126 int i = 0;
127 int base = 10;
128 uint64_t val = 0;
129
130 if (s[0] == '0' && s[1] == 'x')
131 {
132 base = 16;
133 i = 2;
134 }
135
136 while (s[i] != '\0') {
137 if (s[i] >= '0' && s[i] <= '9') {
138 val = val * base + (uint64_t)(s[i] - '0');
139 } else if (s[i] >= 'a' && s[i] <= 'f') {
140 if (base != 16)
141 kprintf("Not base 16!\n");
142 val = val * base + (uint64_t)(s[i] - 'a' + 10);
143 } else if (s[i] >= 'A' && s[i] <= 'F') {
144 if (base != 16)
145 kprintf("Not base 16!\n");
146 val = val * base + (uint64_t)(s[i] - 'A' + 10);
147 } else {
148 kprintf("Not a number!\n");
149 }
150 i++;
151 }
152
153 return val;
154}
static uint16_t base
Definition: sercons.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_SymbolToInt()

uint64_t Debug_SymbolToInt ( const char *  s)

Definition at line 157 of file debug.c.

158{
159 if (*s >= '0' || *s <= '9')
160 return Debug_StrToInt(s);
161
162 kprintf("Unknown symbol '%s'\n");
163 return 0;
164}
uint64_t Debug_StrToInt(const char *s)
Definition: debug.c:124
Here is the call graph for this function:
Here is the caller graph for this function: