Skip to content

Commit

Permalink
refactor: rename std::ostream with sk_std::
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Aug 7, 2024
1 parent 6449c2c commit 211f34f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 72 deletions.
26 changes: 13 additions & 13 deletions src/kernel/arch/riscv64/include/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ class Sstatus : public ReadWriteRegBase<reginfo::csr::SstatusInfo> {
virtual ~Sstatus() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Sstatus &sstatus) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sstatus &sstatus) {
auto sie = sstatus.sie.Get();
auto spie = sstatus.spie.Get();
auto spp = sstatus.spp.Get();
Expand Down Expand Up @@ -1222,7 +1222,7 @@ class Stvec : public ReadWriteRegBase<reginfo::csr::StvecInfo> {
virtual ~Stvec() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Stvec &stvec) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Stvec &stvec) {
auto mode = stvec.mode.Get();
auto base = stvec.base.Get();
printf("val: 0x%p, mode: %s, base: 0x%lX", (void *)stvec.Read(),
Expand Down Expand Up @@ -1254,7 +1254,7 @@ class Sip : public ReadWriteRegBase<reginfo::csr::SipInfo> {
virtual ~Sip() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Sip &sip) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sip &sip) {
auto ssip = sip.ssip.Get();
auto stip = sip.stip.Get();
auto seip = sip.seip.Get();
Expand Down Expand Up @@ -1288,7 +1288,7 @@ class Sie : public ReadWriteRegBase<reginfo::csr::SieInfo> {
virtual ~Sie() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Sie &sie) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sie &sie) {
auto ssie = sie.ssie.Get();
auto stie = sie.stie.Get();
auto seie = sie.seie.Get();
Expand All @@ -1312,7 +1312,7 @@ class Time : public ReadOnlyRegBase<reginfo::csr::TimeInfo> {
virtual ~Time() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Time &time) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Time &time) {
printf("val: 0x%p", (void *)time.Read());
return os;
}
Expand All @@ -1330,7 +1330,7 @@ class Cycle : public ReadOnlyRegBase<reginfo::csr::CycleInfo> {
virtual ~Cycle() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Cycle &cycle) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cycle &cycle) {
printf("val: 0x%p", (void *)cycle.Read());
return os;
}
Expand All @@ -1348,7 +1348,7 @@ class Instret : public ReadOnlyRegBase<reginfo::csr::InstretInfo> {
virtual ~Instret() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Instret &instret) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Instret &instret) {
printf("val: 0x%p", (void *)instret.Read());
return os;
}
Expand All @@ -1366,7 +1366,7 @@ class Sscratch : public ReadWriteRegBase<reginfo::csr::SscratchInfo> {
virtual ~Sscratch() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Sscratch &sscratch) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sscratch &sscratch) {
printf("val: 0x%p", (void *)sscratch.Read());
return os;
}
Expand All @@ -1384,7 +1384,7 @@ class Sepc : public ReadWriteRegBase<reginfo::csr::SepcInfo> {
virtual ~Sepc() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Sepc &sepc) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sepc &sepc) {
printf("val: 0x%p", (void *)sepc.Read());
return os;
}
Expand All @@ -1409,7 +1409,7 @@ class Scause : public ReadWriteRegBase<reginfo::csr::ScauseInfo> {
virtual ~Scause() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Scause &scause) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Scause &scause) {
auto exception_code = scause.exception_code.Get();
auto interrupt = scause.interrupt.Get();
printf("val: 0x%p, exception_code: 0x%lX, interrupt: %s, name: %s",
Expand All @@ -1433,7 +1433,7 @@ class Stval : public ReadWriteRegBase<reginfo::csr::StvalInfo> {
virtual ~Stval() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Stval &stval) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Stval &stval) {
printf("val: 0x%p", (void *)stval.Read());
return os;
}
Expand Down Expand Up @@ -1461,7 +1461,7 @@ class Satp : public ReadWriteRegBase<reginfo::csr::SatpInfo> {
virtual ~Satp() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Satp &satp) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Satp &satp) {
auto ppn = satp.ppn.Get();
auto asid = satp.asid.Get();
auto mode = satp.mode.Get();
Expand All @@ -1483,7 +1483,7 @@ class Stimecmp : public ReadOnlyRegBase<reginfo::csr::StimecmpInfo> {
virtual ~Stimecmp() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Stimecmp &stimecmp) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Stimecmp &stimecmp) {
printf("val: 0x%p", (void *)stimecmp.Read());
return os;
}
Expand Down
20 changes: 10 additions & 10 deletions src/kernel/arch/riscv64/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ Interrupt::InterruptFunc Interrupt::exception_handlers
[cpu::reginfo::csr::ScauseInfo::kExceptionMaxCount];

__attribute__((interrupt("supervisor"))) alignas(4) static void TarpEntry() {
std::cout << std::endl;
std::cout << "sepc: " << cpu::kAllCsr.sepc << std::endl;
std::cout << "stval: " << cpu::kAllCsr.stval << std::endl;
std::cout << "stvec: " << cpu::kAllCsr.stvec << std::endl;
std::cout << "scause: " << cpu::kAllCsr.scause << std::endl;
std::cout << "sie: " << cpu::kAllCsr.sie << std::endl;
std::cout << "sip: " << cpu::kAllCsr.sip << std::endl;
std::cout << "sstatus: " << cpu::kAllCsr.sstatus << std::endl;
std::cout << "satp: " << cpu::kAllCsr.satp << std::endl;
std::cout << "sscratch: " << cpu::kAllCsr.sscratch << std::endl;
sk_std::cout << sk_std::endl;
sk_std::cout << "sepc: " << cpu::kAllCsr.sepc << sk_std::endl;
sk_std::cout << "stval: " << cpu::kAllCsr.stval << sk_std::endl;
sk_std::cout << "stvec: " << cpu::kAllCsr.stvec << sk_std::endl;
sk_std::cout << "scause: " << cpu::kAllCsr.scause << sk_std::endl;
sk_std::cout << "sie: " << cpu::kAllCsr.sie << sk_std::endl;
sk_std::cout << "sip: " << cpu::kAllCsr.sip << sk_std::endl;
sk_std::cout << "sstatus: " << cpu::kAllCsr.sstatus << sk_std::endl;
sk_std::cout << "satp: " << cpu::kAllCsr.satp << sk_std::endl;
sk_std::cout << "sscratch: " << cpu::kAllCsr.sscratch << sk_std::endl;

kInterrupt.GetInstance().Do((uint64_t)cpu::kAllCsr.scause.Read(), nullptr);
}
Expand Down
14 changes: 7 additions & 7 deletions src/kernel/arch/x86_64/arch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) {
cpu::kAllCr.cs.Write(sizeof(cpu::reginfo::GdtrInfo::SegmentDescriptor) *
cpu::reginfo::GdtrInfo::kKernelCodeIndex);

std::cout << "es: " << cpu::kAllCr.es << std::endl;
std::cout << "cs: " << cpu::kAllCr.cs << std::endl;
std::cout << "ss: " << cpu::kAllCr.ss << std::endl;
std::cout << "ds: " << cpu::kAllCr.ds << std::endl;
std::cout << "fs: " << cpu::kAllCr.fs << std::endl;
std::cout << "gs: " << cpu::kAllCr.gs << std::endl;
sk_std::cout << "es: " << cpu::kAllCr.es << sk_std::endl;
sk_std::cout << "cs: " << cpu::kAllCr.cs << sk_std::endl;
sk_std::cout << "ss: " << cpu::kAllCr.ss << sk_std::endl;
sk_std::cout << "ds: " << cpu::kAllCr.ds << sk_std::endl;
sk_std::cout << "fs: " << cpu::kAllCr.fs << sk_std::endl;
sk_std::cout << "gs: " << cpu::kAllCr.gs << sk_std::endl;

for (size_t i = 0; i < (cpu::kAllCr.gdtr.Read().limit + 1) /
sizeof(cpu::reginfo::GdtrInfo::SegmentDescriptor);
i++) {
printf("gdtr[%d] 0x%p\n", i, cpu::kAllCr.gdtr.Read().base + i);
std::cout << *(cpu::kAllCr.gdtr.Read().base + i) << std::endl;
sk_std::cout << *(cpu::kAllCr.gdtr.Read().base + i) << sk_std::endl;
}

log::Info("Hello x86_64 ArchInit\n");
Expand Down
61 changes: 31 additions & 30 deletions src/kernel/arch/x86_64/include/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ struct GdtrInfo : public RegInfoBase {
~SegmentDescriptor() = default;
/// @}

friend std::ostream &operator<<(
std::ostream &os, const SegmentDescriptor &segment_descriptor) {
friend sk_std::ostream &operator<<(
sk_std::ostream &os, const SegmentDescriptor &segment_descriptor) {
printf("val: 0x%p, type: 0x%X, s: %s, dpl: 0x%X, p: %s, avl: %s, l: %s",
(void *)segment_descriptor.val,
segment_descriptor.segment_descriptor.type,
Expand Down Expand Up @@ -911,8 +911,8 @@ struct IdtrInfo : public RegInfoBase {
uint32_t val;
};

friend std::ostream &operator<<(std::ostream &os,
const ErrorCode &error_code) {
friend sk_std::ostream &operator<<(sk_std::ostream &os,
const ErrorCode &error_code) {
printf(
"val: 0x%X, ext: %d, idt: %d, ti: %d, segment_selector_index: "
"0x%X",
Expand Down Expand Up @@ -984,7 +984,7 @@ struct IdtrInfo : public RegInfoBase {
~Idt() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Idt &idt) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Idt &idt) {
printf(
"val: 0x%p 0x%p, offset: 0x%p, selector: 0x%X, type: %d, dpl: 0x%X, "
"p: %s",
Expand Down Expand Up @@ -1697,7 +1697,7 @@ class Efer : public ReadWriteRegBase<reginfo::EferInfo> {
virtual ~Efer() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Efer &efer) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Efer &efer) {
auto sce = efer.sce.Get();
auto lme = efer.lme.Get();
auto lma = efer.lma.Get();
Expand Down Expand Up @@ -1728,7 +1728,8 @@ class Rflags : public ReadWriteRegBase<reginfo::RflagsInfo> {
virtual ~Rflags() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Rflags &Rflags) {
friend sk_std::ostream &operator<<(sk_std::ostream &os,
const Rflags &Rflags) {
auto interrupt_enable_flag = Rflags.interrupt_enable_flag.Get();
printf("val: 0x%p, if: %s", (void *)Rflags.Read(),
(interrupt_enable_flag == true ? "Enable" : "Disable"));
Expand All @@ -1743,7 +1744,7 @@ class Gdtr : public ReadWriteRegBase<reginfo::GdtrInfo> {
ReadWriteField<ReadWriteRegBase<reginfo::GdtrInfo>, reginfo::GdtrInfo::Base>
base;

friend std::ostream &operator<<(std::ostream &os, const Gdtr &gdtr) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Gdtr &gdtr) {
printf("base: 0x%p, limit: %d", (void *)gdtr.Read().base,
gdtr.Read().limit);
return os;
Expand All @@ -1752,7 +1753,7 @@ class Gdtr : public ReadWriteRegBase<reginfo::GdtrInfo> {

class Ldtr : public ReadWriteRegBase<reginfo::LdtrInfo> {
public:
friend std::ostream &operator<<(std::ostream &os, const Ldtr &ldtr) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Ldtr &ldtr) {
printf("val: 0x%p", (void *)ldtr.Read());
return os;
}
Expand All @@ -1765,7 +1766,7 @@ class Idtr : public ReadWriteRegBase<reginfo::IdtrInfo> {
ReadWriteField<ReadWriteRegBase<reginfo::IdtrInfo>, reginfo::IdtrInfo::Base>
base;

friend std::ostream &operator<<(std::ostream &os, const Idtr &idtr) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Idtr &idtr) {
printf("base: 0x%p, limit: %d", (void *)idtr.Read().base,
idtr.Read().limit);
return os;
Expand All @@ -1774,7 +1775,7 @@ class Idtr : public ReadWriteRegBase<reginfo::IdtrInfo> {

class Tr : public ReadWriteRegBase<reginfo::TrInfo> {
public:
friend std::ostream &operator<<(std::ostream &os, const Tr &tr) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Tr &tr) {
printf("val: 0x%p", (void *)tr.Read());
return os;
}
Expand All @@ -1801,7 +1802,7 @@ class Cr0 : public ReadWriteRegBase<reginfo::cr::Cr0Info> {
virtual ~Cr0() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Cr0 &cr0) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cr0 &cr0) {
auto pe = cr0.pe.Get();
auto pg = cr0.pg.Get();
printf("val: 0x%p, pe: %s, pg: %s", (void *)cr0.Read(),
Expand All @@ -1815,7 +1816,7 @@ class Cr0 : public ReadWriteRegBase<reginfo::cr::Cr0Info> {

class Cr2 : public ReadWriteRegBase<reginfo::cr::Cr2Info> {
public:
friend std::ostream &operator<<(std::ostream &os, const Cr2 &cr2) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cr2 &cr2) {
printf("val: 0x%p", (void *)cr2.Read());
return os;
}
Expand Down Expand Up @@ -1843,7 +1844,7 @@ class Cr3 : public ReadWriteRegBase<reginfo::cr::Cr3Info> {
virtual ~Cr3() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Cr3 &cr3) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cr3 &cr3) {
auto pwt = cr3.pwt.Get();
auto pcd = cr3.pcd.Get();
auto page_directory_base = cr3.page_directory_base.Get();
Expand All @@ -1870,7 +1871,7 @@ class Cr4 : public ReadWriteRegBase<reginfo::cr::Cr4Info> {
virtual ~Cr4() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Cr4 &cr4) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cr4 &cr4) {
auto pae = cr4.pae.Get();
printf("val: 0x%p, pae: %s", (void *)cr4.Read(),
(pae == true ? "Enable" : "Disable"));
Expand All @@ -1880,7 +1881,7 @@ class Cr4 : public ReadWriteRegBase<reginfo::cr::Cr4Info> {

class Cr8 : public ReadWriteRegBase<reginfo::cr::Cr8Info> {
public:
friend std::ostream &operator<<(std::ostream &os, const Cr8 &cr8) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cr8 &cr8) {
printf("val: 0x%p", (void *)cr8.Read());
return os;
}
Expand All @@ -1890,15 +1891,15 @@ class Cr8 : public ReadWriteRegBase<reginfo::cr::Cr8Info> {

class Cpuid : public ReadOnlyRegBase<reginfo::CpuidInfo> {
public:
friend std::ostream &operator<<(std::ostream &os, const Cpuid &cpuid) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cpuid &cpuid) {
printf("val: 0x%p", (void *)cpuid.Read());
return os;
}
};

class Xcr0 : public ReadWriteRegBase<reginfo::Xcr0Info> {
public:
friend std::ostream &operator<<(std::ostream &os, const Xcr0 &xcr0) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Xcr0 &xcr0) {
printf("val: 0x%p", (void *)xcr0.Read());
return os;
}
Expand Down Expand Up @@ -1929,7 +1930,7 @@ class Cs : public ReadWriteRegBase<reginfo::segment_register::CsInfo> {
virtual ~Cs() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Cs &cs) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Cs &cs) {
auto val = cs.Read();
auto rpl = cs.rpl.Get();
auto ti = cs.ti.Get();
Expand Down Expand Up @@ -1964,7 +1965,7 @@ class Ss : public ReadWriteRegBase<reginfo::segment_register::SsInfo> {
virtual ~Ss() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Ss &ss) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Ss &ss) {
auto val = ss.Read();
auto rpl = ss.rpl.Get();
auto ti = ss.ti.Get();
Expand Down Expand Up @@ -1999,7 +2000,7 @@ class Ds : public ReadWriteRegBase<reginfo::segment_register::DsInfo> {
virtual ~Ds() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Ds &ds) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Ds &ds) {
auto val = ds.Read();
auto rpl = ds.rpl.Get();
auto ti = ds.ti.Get();
Expand Down Expand Up @@ -2034,7 +2035,7 @@ class Es : public ReadWriteRegBase<reginfo::segment_register::EsInfo> {
virtual ~Es() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Es &es) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Es &es) {
auto val = es.Read();
auto rpl = es.rpl.Get();
auto ti = es.ti.Get();
Expand Down Expand Up @@ -2069,7 +2070,7 @@ class Fs : public ReadWriteRegBase<reginfo::segment_register::FsInfo> {
virtual ~Fs() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Fs &fs) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Fs &fs) {
auto val = fs.Read();
auto rpl = fs.rpl.Get();
auto ti = fs.ti.Get();
Expand Down Expand Up @@ -2104,7 +2105,7 @@ class Gs : public ReadWriteRegBase<reginfo::segment_register::GsInfo> {
virtual ~Gs() = default;
/// @}

friend std::ostream &operator<<(std::ostream &os, const Gs &gs) {
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Gs &gs) {
auto val = gs.Read();
auto rpl = gs.rpl.Get();
auto ti = gs.ti.Get();
Expand Down Expand Up @@ -2153,8 +2154,8 @@ struct InterruptContext {
uint64_t rsp;
uint64_t ss;

friend std::ostream &operator<<(std::ostream &os,
const InterruptContext &interrupt_context) {
friend sk_std::ostream &operator<<(
sk_std::ostream &os, const InterruptContext &interrupt_context) {
printf("rip: 0x%lX\n", interrupt_context.rip);
printf("cs: 0x%lX\n", interrupt_context.cs);
printf("rflags: 0x%lX\n", interrupt_context.rflags);
Expand All @@ -2174,11 +2175,11 @@ struct InterruptContextErrorCode {
uint64_t rsp;
uint64_t ss;

friend std::ostream &operator<<(
std::ostream &os,
friend sk_std::ostream &operator<<(
sk_std::ostream &os,
const InterruptContextErrorCode &interrupt_context_error_code) {
std::cout << std::endl
<< interrupt_context_error_code.error_code << std::endl;
sk_std::cout << sk_std::endl
<< interrupt_context_error_code.error_code << sk_std::endl;
printf("padding: 0x%X\n", interrupt_context_error_code.padding);
printf("rip: 0x%lX\n", interrupt_context_error_code.rip);
printf("cs: 0x%lX\n", interrupt_context_error_code.cs);
Expand Down
Loading

0 comments on commit 211f34f

Please sign in to comment.