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

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

unix.superglobalmegacorp.com

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