]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/ia32/jdb-ia32-ux.cpp
Inital import
[l4.git] / kernel / fiasco / src / jdb / ia32 / jdb-ia32-ux.cpp
1 INTERFACE[ia32,amd64,ux]:
2
3 #include "jdb_core.h"
4 #include "jdb_handler_queue.h"
5 #include "jdb_entry_frame.h"
6 #include "trap_state.h"
7
8 class Space;
9 class Thread;
10
11
12 IMPLEMENTATION[ia32,amd64,ux]:
13
14 #include "config.h"
15 #include "div32.h"
16 #include "kernel_console.h"
17 #include "paging.h"
18
19 PUBLIC static
20 void
21 Jdb::write_tsc_s(Signed64 tsc, char *buf, int maxlen, bool sign)
22 {
23   Unsigned64 uns = Cpu::boot_cpu()->tsc_to_ns(tsc < 0 ? -tsc : tsc);
24   Unsigned32 ums = div32(uns, 1000000);
25
26   if (tsc < 0)
27     uns = -uns;
28
29   if (ums >= 3600000000U)
30     {
31       snprintf(buf, maxlen, ">999 h ");
32       return;
33     }
34
35   if (sign)
36     {
37       *buf++ = (tsc < 0) ? '-' : (tsc == 0) ? ' ' : '+';
38       maxlen--;
39     }
40
41   if (ums >= 60000000)
42     {
43       // 1:00...999:00 h
44       Mword _h  = ums / 3600000;
45       Mword _m  = (ums - 3600000 * _h) / 60000;
46       snprintf(buf, maxlen, "%3lu:%02lu     h ", _h, _m);
47       return;
48     }
49
50   if (ums >= 1000000)
51     {
52       // 1:00...999:00 min
53       Mword _m  = ums / 60000;
54       Mword _s  = (ums - 60000 * _m) / 1000;
55       snprintf(buf, maxlen, "%3lu:%02lu    min", _m, _s);
56       return;
57     }
58
59   if (ums >= 1000)
60     {
61       // 1.000000...999.000000 s
62       Mword _s  = ums / 1000;
63       Mword _us = div32(uns, 1000) - 1000000 * _s;
64       snprintf(buf, maxlen, "%3lu.%06lu s ", _s, _us);
65       return;
66     }
67
68   if (uns == 0)
69     {
70       snprintf(buf, maxlen, "  0          ");
71       return;
72     }
73
74   // 1.000000...999.000000 ms
75   Mword _ms = ums;
76   Mword _ns = ((Mword)uns - 1000000 * _ms);
77   snprintf(buf, maxlen, "%3lu.%06lu ms", _ms, _ns);
78 }
79
80 PUBLIC static
81 void
82 Jdb::write_tsc(Signed64 tsc, char *buf, int maxlen, bool sign)
83 {
84   Unsigned64 ns = Cpu::boot_cpu()->tsc_to_ns(tsc < 0 ? -tsc : tsc);
85   if (tsc < 0)
86     ns = -ns;
87   write_ll_ns(ns, buf, maxlen, sign);
88 }
89