Annotation of nono/vm/zram.cpp, revision 1.1.1.2

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #include "zram.h"
                      7: 
                      8: //
                      9: // 3ポート共有 RAM
                     10: //
                     11: // ZRAM はロングワード単位でホストバイトオーダ配置なので、
                     12: // バイトアクセス、ワードアクセス時は HLB(), HLW() マクロ使用のこと。
                     13: //
                     14: 
1.1.1.2 ! root       15: std::unique_ptr<ZRAMDevice> gZRAM;
1.1       root       16: 
                     17: ZRAMDevice::ZRAMDevice()
                     18: {
                     19:        logname = "zram";
                     20:        devname = "ZRAM";
                     21:        devaddr = 0x71000000;
                     22:        devlen = 128 * 1024;
                     23: 
1.1.1.2 ! root       24:        ram.reset(new uint8[devlen]);
1.1       root       25: }
                     26: 
                     27: ZRAMDevice::~ZRAMDevice()
                     28: {
                     29: }
                     30: 
1.1.1.2 ! root       31: // アドレスデコーダ
        !            32: inline uint64
        !            33: ZRAMDevice::Decoder(uint32 addr) const
        !            34: {
        !            35:        // たぶん 128KB で折り返しイメージが見えるはず。要確認。
        !            36:        return addr % devlen;
        !            37: }
1.1       root       38: 
                     39: uint64
                     40: ZRAMDevice::Read8(uint32 addr)
                     41: {
                     42:        std::unique_lock<std::mutex> lock(mtx);
                     43: 
1.1.1.2 ! root       44:        uint32 offset = Decoder(addr);
        !            45:        uint32 data = ram[HLB(offset)];
1.1       root       46:        return data;
                     47: }
                     48: 
                     49: uint64
                     50: ZRAMDevice::Read16(uint32 addr)
                     51: {
                     52:        std::unique_lock<std::mutex> lock(mtx);
                     53: 
1.1.1.2 ! root       54:        uint32 offset = Decoder(addr);
        !            55:        uint32 data = *(uint16 *)&ram[HLW(offset)];
1.1       root       56:        return data;
                     57: }
                     58: 
                     59: uint64
                     60: ZRAMDevice::Read32(uint32 addr)
                     61: {
                     62:        std::unique_lock<std::mutex> lock(mtx);
                     63: 
1.1.1.2 ! root       64:        uint32 offset = Decoder(addr);
        !            65:        uint32 data = *(uint32 *)&ram[offset];
1.1       root       66:        return data;
                     67: }
                     68: 
                     69: uint64
                     70: ZRAMDevice::Write8(uint32 addr, uint32 data)
                     71: {
                     72:        std::unique_lock<std::mutex> lock(mtx);
                     73: 
1.1.1.2 ! root       74:        uint32 offset = Decoder(addr);
        !            75:        ram[HLB(offset)] = data;
1.1       root       76:        return 0;
                     77: }
                     78: 
                     79: uint64
                     80: ZRAMDevice::Write16(uint32 addr, uint32 data)
                     81: {
                     82:        std::unique_lock<std::mutex> lock(mtx);
                     83: 
1.1.1.2 ! root       84:        uint32 offset = Decoder(addr);
        !            85:        *(uint16 *)&ram[HLW(offset)] = data;
1.1       root       86:        return 0;
                     87: }
                     88: 
                     89: uint64
                     90: ZRAMDevice::Write32(uint32 addr, uint32 data)
                     91: {
                     92:        std::unique_lock<std::mutex> lock(mtx);
                     93: 
1.1.1.2 ! root       94:        uint32 offset = Decoder(addr);
        !            95:        *(uint32 *)&ram[offset] = data;
1.1       root       96:        return 0;
                     97: }
                     98: 
                     99: uint64
                    100: ZRAMDevice::Peek8(uint32 addr)
                    101: {
                    102:        std::unique_lock<std::mutex> lock(mtx);
                    103: 
1.1.1.2 ! root      104:        uint32 offset = Decoder(addr);
        !           105:        return ram[HLB(offset)];
1.1       root      106: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.